Move `private-cli` commands to `local-cli`

Summary: public

We cannot remove `local-cli` because is referenced by the global cli explicitly. If we do so, people would have to upgrate this global thin cli which will cause some pain. So, lets move `private-cli` commands into `local-cli` instead.

Reviewed By: frantic

Differential Revision: D2571983

fb-gh-sync-id: 712c29430203660fb6f0d5f23813cb2a7156ee48
This commit is contained in:
Martín Bigio 2015-10-26 07:55:29 -07:00 committed by facebook-github-bot-3
parent 24537e3726
commit 849aa4dae6
33 changed files with 49 additions and 138 deletions

View File

@ -11,7 +11,7 @@
const log = require('../util/log').out('bundle');
const processBundle = require('./processBundle');
const Promise = require('promise');
const ReactPackager = require('../../../packager/react-packager');
const ReactPackager = require('../../packager/react-packager');
const saveBundleAndMap = require('./saveBundleAndMap');
function buildBundle(args, config) {

View File

@ -10,7 +10,7 @@
const buildBundle = require('./buildBundle');
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
const parseCommandLine = require('../../../packager/parseCommandLine');
const parseCommandLine = require('../../packager/parseCommandLine');
/**
* Builds the bundle starting to look for dependencies at the given entry path.

View File

@ -23,7 +23,7 @@ module.exports = [
command: 'transformer',
description: 'Specify a custom transformer to be used (absolute path)',
type: 'string',
default: require.resolve('../../../packager/transformer'),
default: require.resolve('../../packager/transformer'),
}, {
command: 'dev',
description: 'If false, warnings are disabled and the bundle is minified',

View File

@ -13,20 +13,28 @@ require('../packager/babelRegisterOnly')([
/local-cli/
]);
var bundle = require('../private-cli/src/bundle/bundle');
var bundle = require('./bundle/bundle');
var childProcess = require('child_process');
var Config = require('../private-cli/src/util/Config');
var Config = require('./util/Config');
var defaultConfig = require('./default.config');
var dependencies = require('./dependencies/dependencies');
var fs = require('fs');
var generate = require('../private-cli/src/generate/generate');
var library = require('../private-cli/src/library/library');
var generate = require('./generate/generate');
var library = require('./library/library');
var path = require('path');
var Promise = require('promise');
var runAndroid = require('../private-cli/src/runAndroid/runAndroid');
var server = require('../private-cli/src/server/server');
var runAndroid = require('./runAndroid/runAndroid');
var server = require('./server/server');
var TerminalAdapter = require('yeoman-environment/lib/adapter.js');
var yeoman = require('yeoman-environment');
var upgrade = require('../private-cli/src/upgrade/upgrade');
var upgrade = require('./upgrade/upgrade');
var fs = require('fs');
var gracefulFs = require('graceful-fs');
// graceful-fs helps on getting an error when we run out of file
// descriptors. When that happens it will enqueue the operation and retry it.
gracefulFs.gracefulify(fs);
var documentedCommands = {
'start': [server, 'starts the webserver'],
@ -38,6 +46,11 @@ var documentedCommands = {
'updating the react-native version in your package.json and running npm install']
};
var exportedCommands = {dependencies: dependencies};
Object.keys(documentedCommands).forEach(function(command) {
exportedCommands[command] = documentedCommands[command][0];
});
var undocumentedCommands = {
'init': [printInitWarning, ''],
};
@ -148,4 +161,5 @@ if (require.main === module) {
module.exports = {
run: run,
init: init,
commands: exportedCommands
};

View File

@ -10,10 +10,10 @@
const fs = require('fs');
const log = require('../util/log').out('dependencies');
const parseCommandLine = require('../../../packager/parseCommandLine');
const parseCommandLine = require('../../packager/parseCommandLine');
const path = require('path');
const Promise = require('promise');
const ReactPackager = require('../../../packager/react-packager');
const ReactPackager = require('../../packager/react-packager');
/**
* Returns the dependencies an entry path has.
@ -42,7 +42,7 @@ function _dependencies(argv, config, resolve, reject) {
}, {
command: 'transformer',
type: 'string',
default: require.resolve('../../../packager/transformer'),
default: require.resolve('../../packager/transformer'),
description: 'Specify a custom transformer to be used (absolute path)'
}, {
command: 'verbose',

View File

@ -8,7 +8,7 @@
*/
'use strict';
const parseCommandLine = require('../../../packager/parseCommandLine');
const parseCommandLine = require('../../packager/parseCommandLine');
const path = require('path');
const Promise = require('promise');
const yeoman = require('yeoman-environment');
@ -46,7 +46,7 @@ function _generate(argv, config, resolve, reject) {
process.chdir(args['project-path']);
const env = yeoman.createEnv();
env.register(path.join(__dirname, '../../../local-cli/generator'), 'react:app');
env.register(path.join(__dirname, '../generator'), 'react:app');
env.run(
['react:app', args['project-name']],
{

View File

@ -11,7 +11,7 @@
const copyAndReplace = require('../util/copyAndReplace');
const fs = require('fs');
const isValidPackageName = require('../util/isValidPackageName');
const parseCommandLine = require('../../../packager/parseCommandLine');
const parseCommandLine = require('../../packager/parseCommandLine');
const path = require('path');
const Promise = require('promise');
const walk = require('../util/walk');

View File

@ -12,7 +12,7 @@ const chalk = require('chalk');
const child_process = require('child_process');
const fs = require('fs');
const path = require('path');
const parseCommandLine = require('../../../packager/parseCommandLine');
const parseCommandLine = require('../../packager/parseCommandLine');
const isPackagerRunning = require('../util/isPackagerRunning');
const Promise = require('promise');

View File

@ -9,24 +9,21 @@
'use strict';
const connect = require('connect');
// TODO: move middlewares to private-cli/src/server
const cpuProfilerMiddleware = require('../../../packager/cpuProfilerMiddleware');
const getDevToolsMiddleware = require('../../../packager/getDevToolsMiddleware');
const cpuProfilerMiddleware = require('../../packager/cpuProfilerMiddleware');
const getDevToolsMiddleware = require('../../packager/getDevToolsMiddleware');
const http = require('http');
const isAbsolutePath = require('absolute-path');
const loadRawBodyMiddleware = require('../../../packager/loadRawBodyMiddleware');
const openStackFrameInEditorMiddleware = require('../../../packager/openStackFrameInEditorMiddleware');
const loadRawBodyMiddleware = require('../../packager/loadRawBodyMiddleware');
const openStackFrameInEditorMiddleware = require('../../packager/openStackFrameInEditorMiddleware');
const path = require('path');
const ReactPackager = require('../../../packager/react-packager');
const statusPageMiddleware = require('../../../packager/statusPageMiddleware.js');
const systraceProfileMiddleware = require('../../../packager/systraceProfileMiddleware.js');
const webSocketProxy = require('../../../packager/webSocketProxy.js');
const ReactPackager = require('../../packager/react-packager');
const statusPageMiddleware = require('../../packager/statusPageMiddleware.js');
const systraceProfileMiddleware = require('../../packager/systraceProfileMiddleware.js');
function runServer(args, config, readyCallback) {
var wsProxy = null;
const app = connect()
.use(loadRawBodyMiddleware)
.use(getDevToolsMiddleware(args, () => wsProxy && wsProxy.isChromeConnected()))
.use(getDevToolsMiddleware(args))
.use(openStackFrameInEditorMiddleware)
.use(statusPageMiddleware)
.use(systraceProfileMiddleware)
@ -41,15 +38,7 @@ function runServer(args, config, readyCallback) {
.use(connect.compress())
.use(connect.errorHandler());
const serverInstance = http.createServer(app).listen(
args.port,
'::',
function() {
wsProxy = webSocketProxy.attachToServer(serverInstance, '/debugger-proxy');
webSocketProxy.attachToServer(serverInstance, '/devtools');
readyCallback();
}
);
return http.createServer(app).listen(args.port, '::', readyCallback);
}
function getAppMiddleware(args, config) {
@ -69,7 +58,7 @@ function getAppMiddleware(args, config) {
resetCache: args.resetCache || args['reset-cache'],
polyfillModuleNames: [
require.resolve(
'../../../Libraries/JavaScriptAppEngine/polyfills/document.js'
'../../Libraries/JavaScriptAppEngine/polyfills/document.js'
),
],
verbose: args.verbose,

View File

@ -11,10 +11,11 @@
const chalk = require('chalk');
const checkNodeVersion = require('./checkNodeVersion');
const formatBanner = require('./formatBanner');
const parseCommandLine = require('../../../packager/parseCommandLine');
const parseCommandLine = require('../../packager/parseCommandLine');
const path = require('path');
const Promise = require('promise');
const runServer = require('./runServer');
const webSocketProxy = require('../../packager/webSocketProxy.js');
/**
* Starts the React Native Packager Server.
@ -47,7 +48,7 @@ function _server(argv, config, resolve, reject) {
}, {
command: 'transformer',
type: 'string',
default: require.resolve('../../../packager/transformer'),
default: require.resolve('../../packager/transformer'),
description: 'Specify a custom transformer to be used (absolute path)'
}, {
command: 'resetCache',
@ -137,9 +138,12 @@ function _server(argv, config, resolve, reject) {
}
function startServer(args, config) {
runServer(args, config, () =>
const serverInstance = runServer(args, config, () =>
console.log('\nReact packager ready.\n')
);
webSocketProxy.attachToServer(serverInstance, '/debugger-proxy');
webSocketProxy.attachToServer(serverInstance, '/devtools');
}
function argToArray(arg) {

View File

@ -17,7 +17,7 @@ module.exports = function upgrade(args, config) {
args = args || process.argv;
let env = yeoman.createEnv();
let name = JSON.parse(fs.readFileSync('package.json', 'utf8')).name;
let generatorPath = path.join(__dirname, '..', '..', '..', 'local-cli', 'generator');
let generatorPath = path.join(__dirname, '..', 'generator');
env.register(generatorPath, 'react:app');
let generatorArgs = ['react:app', name].concat(args);
return new Promise((resolve) => env.run(generatorArgs, {upgrade: true}, resolve));

View File

@ -33,7 +33,6 @@
"packager",
"cli.js",
"local-cli",
"private-cli",
"init.sh",
"LICENSE",
"PATENTS",

View File

@ -1,24 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
require('../packager/babelRegisterOnly')([
/private-cli\/src/,
/packager\/[^\/]*/
]);
var cli = require('./src/cli');
var fs = require('fs');
var gracefulFs = require('graceful-fs');
// graceful-fs helps on getting an error when we run out of file
// descriptors. When that happens it will enqueue the operation and retry it.
gracefulFs.gracefulify(fs);
module.exports = cli;

View File

@ -1,71 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
const bundle = require('./bundle/bundle');
const Config = require('./util/Config');
const dependencies = require('./dependencies/dependencies');
const Promise = require('promise');
const server = require('./server/server');
const upgrade = require('./upgrade/upgrade');
const documentedCommands = {
bundle: bundle,
dependencies: dependencies,
server: server,
upgrade,
};
const hiddenCommands = {
'-h': help,
'--help': help,
};
/**
* Programmatic entry point for the cli. This function runs the given
* command passing it the arguments array.
*/
function run(pwd, command, commandArgs) {
if (!command) {
throw new Error(helpMessage());
}
commandArgs = commandArgs || [];
const commandToExec = documentedCommands[command] || hiddenCommands[command];
if (!commandToExec) {
throw new Error(helpMessage(command));
}
commandToExec(commandArgs, Config.get(pwd)).done();
}
function helpMessage(command) {
const validCommands = Object
.keys(documentedCommands)
.map(c => '"' + c + '"')
.join(' | ');
if (command) {
return 'Unknown command "' + command + '". ' +
'Available commands: ' + validCommands;
} else {
return 'Must specify a command. Available commands: ' +
validCommands;
}
}
function help() {
console.log(helpMessage());
return Promise.resolve();
}
module.exports = {
commands: documentedCommands,
run: run,
};