-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98604b9
commit 9757899
Showing
16 changed files
with
240 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
{} | ||
{ | ||
"ignore_dirs": [ | ||
"./node_modules/react-native-background-geolocation-android/ios/RNBackgroundGeolocation" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
'use strict'; | ||
|
||
const fs = require("fs"); | ||
const path = require('path'); | ||
|
||
const {CLIError, UnknownCommandError} = require('./lib'); | ||
|
||
const COMMAND_LINK = 'link'; | ||
const COMMAND_REINSTALL = 'reinstall'; | ||
|
||
const MENU = {}; | ||
|
||
function registerCommand(name, description, handler) { | ||
MENU[name] = { | ||
description: description, | ||
handler: handler | ||
}; | ||
} | ||
|
||
/// ACTION: link | ||
/// | ||
registerCommand(COMMAND_LINK, 'Symlink TSLocationManager.framework, tslocationmanager.aar', function() { | ||
link(); | ||
}); | ||
|
||
/// ACTION: reinstall | ||
/// | ||
registerCommand(COMMAND_REINSTALL, 'Re-install the currently installed background-geolocation plugin', function() { | ||
reinstall(); | ||
}); | ||
|
||
/// Symlink the [iOS] TSLocationManager.framework [Android] tslocationmanager.aar | ||
/// | ||
function link() { | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const rimraf = require("rimraf"); | ||
|
||
const SRC_ROOT = path.join('/Volumes/Glyph2TB/Users/chris/workspace/react/background-geolocation'); | ||
const MODULE_NAME = "react-native-background-geolocation"; | ||
const SRC_MODULE = path.join(SRC_ROOT, MODULE_NAME + "-android"); | ||
const NODE_MODULES = path.join('.', 'node_modules'); | ||
const PUBLIC_MODULE_PATH = path.join(NODE_MODULES, MODULE_NAME); | ||
const PRIVATE_MODULE_PATH = PUBLIC_MODULE_PATH + '-android'; | ||
|
||
const ANDROID_LIBS_DIR = "android/libs"; | ||
const IOS_LIBS_DIR = "ios/RNBackgroundGeolocation/TSLocationManager.framework"; | ||
|
||
var modulePath = null; | ||
|
||
// Determine which plugin is installed: public or private version. | ||
if (fs.existsSync(PUBLIC_MODULE_PATH)) { | ||
modulePath = PUBLIC_MODULE_PATH; | ||
} else if (fs.existsSync(PRIVATE_MODULE_PATH)) { | ||
modulePath = PRIVATE_MODULE_PATH; | ||
} else { | ||
console.error('ERROR: Failed to find ', MODULE_NAME); | ||
return -1; | ||
} | ||
console.log('- modulePath:', modulePath); | ||
|
||
var androidLibsPath = path.join(modulePath, ANDROID_LIBS_DIR); | ||
var iosLibsPath = path.join(modulePath, IOS_LIBS_DIR); | ||
|
||
// Destroy / unlink existing libs. | ||
[androidLibsPath, iosLibsPath].forEach(function(libs) { | ||
if (fs.existsSync(libs)) { | ||
var stats = fs.lstatSync(libs); | ||
console.log('[dir]', libs); | ||
console.log('- symlink?', stats.isSymbolicLink(), ', dir?', stats.isDirectory()); | ||
if (stats.isSymbolicLink()) { | ||
fs.unlinkSync(libs); | ||
} else if (stats.isDirectory()) { | ||
rimraf.sync(libs); | ||
} | ||
} | ||
}); | ||
|
||
// Symlink tslocationmanager.aar -> src project. | ||
var src = path.join(SRC_MODULE, ANDROID_LIBS_DIR); | ||
var dest = path.join(modulePath, ANDROID_LIBS_DIR); | ||
fs.symlinkSync(src, dest); | ||
|
||
// Symlink TSLocationManager.framework -> src project. | ||
src = path.join(SRC_MODULE, IOS_LIBS_DIR); | ||
dest = path.join(modulePath, IOS_LIBS_DIR); | ||
fs.symlinkSync(src, dest); | ||
} | ||
|
||
/// Re-install the currently installed plugin | ||
/// | ||
function reinstall() { | ||
console.log('- No implementation'); | ||
} | ||
|
||
module.exports = { | ||
actions: MENU | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const {CLIError} = require('./lib'); | ||
|
||
const {actions} = require('./actions'); | ||
const chalk = require('chalk'); | ||
|
||
const COMMAND_HELP = 'help'; | ||
|
||
var args = process.argv.slice(2); | ||
var cmd = args.shift(); | ||
|
||
console.log(chalk.green("+-----------------------------------------")); | ||
console.log(chalk.green(`| [Transitorsoft Demo CLI] cmd: ${cmd}`)); | ||
console.log(chalk.green("+-----------------------------------------")); | ||
|
||
// Launch Command interpretor | ||
const CLI = (function() { | ||
return { | ||
init: function() { | ||
try { | ||
if (cmd === undefined) { | ||
cmd = COMMAND_HELP; | ||
} | ||
if (cmd === COMMAND_HELP) { | ||
printMenu(actions); | ||
return; | ||
} else if (actions[cmd] === undefined) { | ||
console.log(chalk.red("Unknown command:", cmd)); | ||
printMenu(actions); | ||
return; | ||
} | ||
|
||
actions[cmd].handler(args); | ||
|
||
} catch(error) { | ||
if (error instanceof CLIError) { | ||
console.log(chalk.red(`[error]: ${cmd}:`), error.message, '\n'); | ||
} else { | ||
throw error; | ||
} | ||
} | ||
} | ||
} | ||
})().init(); | ||
|
||
function printMenu(menu) { | ||
console.log('Available commands:'); | ||
var table = [{ | ||
command: COMMAND_HELP, | ||
description: 'Print this menu' | ||
}]; | ||
for (var action in menu) { | ||
//table[action] = ACTIONS[action].description; | ||
table.push({ | ||
command: action, | ||
description: menu[action].description | ||
}); | ||
} | ||
console.table(table, ['command', 'description']); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const { exec, spawn} = require('child_process'); | ||
const chalk = require('chalk'); | ||
|
||
class CLIError extends Error {}; | ||
|
||
/** | ||
* Custom exec implemention with Promise | ||
* @return Promise | ||
*/ | ||
function _exec(cmd, args) { | ||
|
||
} | ||
|
||
/** | ||
* Custom spawn implementation with Promise | ||
* @return Promise | ||
*/ | ||
function _spawn(cmd, args=[]) { | ||
var message = cmd; | ||
args.forEach(function(arg) { message += ` ${arg}` }); | ||
|
||
console.log(chalk.yellow(`$ ${message}`)); | ||
|
||
return new Promise(function(resolve, reject) { | ||
|
||
const child = spawn(cmd, args, {shell: true, stdio: 'inherit'}); | ||
child.on('error', (chunk) => { | ||
console.log('error: ', chunk); | ||
}); | ||
|
||
child.on('close', (code) => { | ||
console.log(chalk.yellow(`child process exited with code ${code}`)); | ||
if (code == 0) { | ||
resolve(code); | ||
} else { | ||
reject(code); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
CLIError, | ||
exec: _exec, | ||
spawn: _spawn | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
open -a Xcode ios/RNBackgroundGeolocationSample.xcodeproj | ||
open -a Xcode ios/RNBackgroundGeolocationSample.xcworkspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters