remotedev-server/bin/remotedev.js
Zalmoxisus 86b6a32d30 v0.1.4
2016-08-04 17:30:28 +03:00

65 lines
1.7 KiB
JavaScript
Executable File

#! /usr/bin/env node
var fs = require('fs');
var path = require('path');
var argv = require('minimist')(process.argv.slice(2));
var chalk = require('chalk');
var getOptions = require('./getOptions');
var injectServer = require('./injectServer');
function readFile(filePath) {
return fs.readFileSync(path.resolve(process.cwd(), filePath), 'utf-8');
}
if (argv.protocol === 'https') {
argv.key = argv.key ? readFile(argv.key) : null;
argv.cert = argv.cert ? readFile(argv.cert) : null;
}
function log(pass, msg) {
var prefix = pass ? chalk.green.bgBlack('PASS') : chalk.red.bgBlack('FAIL');
var color = pass ? chalk.blue : chalk.red;
console.log(prefix, color(msg));
}
function getModuleName(type) {
switch (type) {
case 'desktop':
return 'react-native-desktop';
case 'reactnative':
default:
return 'react-native';
}
}
function getModulePath(moduleName) {
return path.join(process.cwd(), 'node_modules', moduleName);
}
if (argv.revert) {
var moduleName = getModuleName(argv.revert);
var pass = injectServer.revert(
getModulePath(moduleName),
moduleName
);
var msg = 'Revert injection of RemoteDev server from React Native local server';
log(pass, msg + (!pass ? ', the file `' + injectServer.fullPath + '` not found.' : '.'));
process.exit(pass ? 0 : 1);
}
if (argv.injectserver) {
var options = getOptions(argv);
var moduleName = getModuleName(argv.injectserver)
var pass = injectServer.inject(
getModulePath(moduleName),
options,
moduleName
);
var msg = 'Inject RemoteDev server into React Native local server';
log(pass, msg + (pass ? '.' : ', the file `' + injectServer.fullPath + '` not found.'));
process.exit(pass ? 0 : 1);
}
require('./server')(argv);