mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-14 09:16:34 +08:00
Kill unused files
Reviewed By: frantic Differential Revision: D2561113 fb-gh-sync-id: a81fece0a948485e12bff7ec146e39d890664887
This commit is contained in:
committed by
facebook-github-bot-3
parent
088c193a22
commit
8e7cfcd053
@@ -1,125 +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.
|
||||
*/
|
||||
var http = require('http');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var chalk = require('chalk');
|
||||
var blacklist = require('../packager/blacklist.js');
|
||||
var ReactPackager = require('../packager/react-packager');
|
||||
|
||||
var OUT_PATH = {
|
||||
android: 'android/app/src/main/assets/index.android.bundle',
|
||||
ios: 'ios/main.jsbundle'
|
||||
};
|
||||
var URL_PATH = {
|
||||
android: '/index.android.bundle?platform=android&dev=',
|
||||
ios: '/index.ios.bundle?platform=ios&dev='
|
||||
};
|
||||
var SOURCEMAP_OUT_PATH = {
|
||||
android: 'android/index.android.map',
|
||||
ios: 'ios/index.ios.map'
|
||||
};
|
||||
|
||||
function getBundle(flags) {
|
||||
var platform = flags.platform ? flags.platform : 'ios';
|
||||
var outPath = flags.out ? flags.out : OUT_PATH[platform];
|
||||
var sourceMapOutPath = SOURCEMAP_OUT_PATH[platform];
|
||||
|
||||
var projectRoots = [path.resolve(__dirname, '../../..')];
|
||||
if (flags.root) {
|
||||
projectRoots.push(path.resolve(flags.root));
|
||||
}
|
||||
|
||||
var assetRoots = [path.resolve(__dirname, '../../..')];
|
||||
if (flags.assetRoots) {
|
||||
assetRoots = assetRoots.concat(flags.assetRoots.split(",").map(function(root) {
|
||||
return path.resolve(root);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
var options = {
|
||||
projectRoots: projectRoots,
|
||||
transformModulePath: require.resolve('../packager/transformer.js'),
|
||||
assetRoots: assetRoots,
|
||||
cacheVersion: '3',
|
||||
blacklistRE: blacklist(platform),
|
||||
};
|
||||
|
||||
var url = flags.url ? flags.url.replace(/\.js$/i, '.bundle?dev=') : URL_PATH[platform];
|
||||
url = url.match(/^\//) ? url : '/' + url;
|
||||
url += flags.dev;
|
||||
|
||||
console.log('Building package...');
|
||||
ReactPackager.buildPackageFromUrl(options, url)
|
||||
.done(function(bundle) {
|
||||
console.log('Build complete');
|
||||
fs.writeFile(outPath, bundle.getSource({
|
||||
inlineSourceMap: false,
|
||||
minify: flags.minify
|
||||
}), function(bundleWriteErr) {
|
||||
if (bundleWriteErr) {
|
||||
console.log(chalk.red('Error saving bundle to disk'));
|
||||
throw bundleWriteErr;
|
||||
}
|
||||
|
||||
console.log('Successfully saved bundle to ' + outPath);
|
||||
|
||||
if (flags.writeSourcemap) {
|
||||
fs.writeFile(sourceMapOutPath, bundle.getSourceMap(), function(sourceMapWriteErr) {
|
||||
if (sourceMapWriteErr) {
|
||||
console.log(chalk.red('Error saving source map to disk'));
|
||||
throw sourceMapWriteErr;
|
||||
} else {
|
||||
console.log('Successfully saved source map to ' + sourceMapOutPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function showHelp() {
|
||||
console.log([
|
||||
'Usage: react-native bundle [options]',
|
||||
'',
|
||||
'Options:',
|
||||
' --dev\t\tsets DEV flag to true',
|
||||
' --minify\tminify js bundle',
|
||||
' --root\t\tadd another root(s) to be used in bundling in this project',
|
||||
' --assetRoots\t\tspecify the root directories of app assets',
|
||||
' --out\t\tspecify the output file',
|
||||
' --url\t\tspecify the bundle file url',
|
||||
' --platform\t\tspecify the platform(android/ios)',
|
||||
' --write-sourcemap\t\twrite bundle source map to disk'
|
||||
].join('\n'));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: function(args) {
|
||||
var flags = {
|
||||
help: args.indexOf('--help') !== -1,
|
||||
dev: args.indexOf('--dev') !== -1,
|
||||
minify: args.indexOf('--minify') !== -1,
|
||||
root: args.indexOf('--root') !== -1 ? args[args.indexOf('--root') + 1] : false,
|
||||
platform: args.indexOf('--platform') !== -1 ? args[args.indexOf('--platform') + 1] : false,
|
||||
assetRoots: args.indexOf('--assetRoots') !== -1 ? args[args.indexOf('--assetRoots') + 1] : false,
|
||||
out: args.indexOf('--out') !== -1 ? args[args.indexOf('--out') + 1] : false,
|
||||
url: args.indexOf('--url') !== -1 ? args[args.indexOf('--url') + 1] : false,
|
||||
writeSourcemap: args.indexOf('--write-sourcemap') !== -1,
|
||||
}
|
||||
|
||||
if (flags.help) {
|
||||
showHelp();
|
||||
} else {
|
||||
getBundle(flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +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';
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var utils = require('./generator-utils');
|
||||
|
||||
function showHelp() {
|
||||
console.log([
|
||||
'Usage: react-native new-library <LibraryName>',
|
||||
''
|
||||
].join('\n'));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function newLibrary(libraryName) {
|
||||
var root = process.cwd();
|
||||
var libraries = path.resolve(root, 'Libraries');
|
||||
var libraryDest = path.resolve(libraries, libraryName);
|
||||
var source = path.resolve('node_modules', 'react-native', 'Libraries', 'Sample') + '/';
|
||||
|
||||
if (!fs.existsSync(libraries)) {
|
||||
fs.mkdir(libraries);
|
||||
}
|
||||
|
||||
if (fs.existsSync(libraryDest)) {
|
||||
console.log('Library already exists in', libraryDest);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
utils.walk(source).forEach(function(f) {
|
||||
f = f.replace(source, ''); // Strip off absolute path
|
||||
if (f === 'project.xcworkspace' || f.indexOf('.xcodeproj/xcuserdata') !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var dest = f.replace(/Sample/g, libraryName).replace(/^_/, '.');
|
||||
utils.copyAndReplace(
|
||||
path.resolve(source, f),
|
||||
path.resolve(libraryDest, dest),
|
||||
{ 'Sample': libraryName }
|
||||
);
|
||||
});
|
||||
|
||||
console.log('Created library in', libraryDest);
|
||||
console.log('Next Steps:');
|
||||
console.log(' Link your library in Xcode:');
|
||||
console.log(' https://facebook.github.io/react-native/docs/linking-libraries-ios.html#content');
|
||||
console.log('');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: function(args) {
|
||||
var libraryName = args[1];
|
||||
if (!libraryName) {
|
||||
showHelp();
|
||||
}
|
||||
utils.validatePackageName(libraryName);
|
||||
|
||||
newLibrary(libraryName);
|
||||
}
|
||||
};
|
||||
@@ -1,80 +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';
|
||||
|
||||
var chalk = require('chalk');
|
||||
var child_process = require('child_process');
|
||||
var fs = require('fs');
|
||||
var http = require('http');
|
||||
var runPackager = require('./run-packager.js');
|
||||
|
||||
function checkAndroid() {
|
||||
return fs.existsSync('android/gradlew');
|
||||
}
|
||||
|
||||
function buildAndRun() {
|
||||
process.chdir('android');
|
||||
try {
|
||||
var cmd = process.platform.startsWith('win') ? 'gradlew.bat' : './gradlew';
|
||||
var gradleArgs = ['installDebug'].concat(process.argv.slice(3));
|
||||
console.log(chalk.bold('Building and installing the app on the device (cd android && ' + cmd + ' ' + gradleArgs.join(' ') + ')...'));
|
||||
child_process.execFileSync(cmd, gradleArgs, {
|
||||
stdio: [process.stdin, process.stdout, process.stderr]
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(chalk.red('Could not install the app on the device, see the error above.'));
|
||||
// stderr is automatically piped from the gradle process, so the user should see the error
|
||||
// already, there is no need to do console.log(e.stderr)
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var packageName = fs.readFileSync('app/src/main/AndroidManifest.xml', 'utf8').match(/package="(.+?)"/)[1];
|
||||
var adbPath = process.env.ANDROID_HOME ? process.env.ANDROID_HOME + '/platform-tools/adb' : 'adb';
|
||||
var adbArgs = ['shell', 'am', 'start', '-n', packageName + '/.MainActivity'];
|
||||
console.log(chalk.bold('Starting the app (' + adbPath + ' ' + adbArgs.join(' ') + ')...'));
|
||||
child_process.spawnSync(adbPath, adbArgs, {
|
||||
stdio: [process.stdin, process.stdout, process.stderr]
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(chalk.red('adb invocation failed. Do you have adb in your PATH?'));
|
||||
// stderr is automatically piped from the adb process, so the user should see the error already,
|
||||
// there is no need to do console.log(e.stderr)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
if (!checkAndroid()) {
|
||||
console.log(chalk.red('Android project not found. Maybe run react-native android first?'));
|
||||
return;
|
||||
}
|
||||
// is packager running?
|
||||
var statusReq = http.get('http://localhost:8081/status', function(res) {
|
||||
var response = '';
|
||||
res.on('data', function(chunk) {
|
||||
response += chunk;
|
||||
});
|
||||
res.on('end', function() {
|
||||
if (response === 'packager-status:running') {
|
||||
console.log(chalk.bold('JS server already running.'));
|
||||
} else {
|
||||
console.log(chalk.yellow('[warn] JS server not recognized, continuing with build...'));
|
||||
}
|
||||
buildAndRun();
|
||||
// make sure we don't wait around for the packager process
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
statusReq.on('error', function() {
|
||||
// start packager first so it warms up
|
||||
console.log(chalk.bold('Starting JS server...'));
|
||||
runPackager(true);
|
||||
buildAndRun();
|
||||
});
|
||||
};
|
||||
@@ -1,56 +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';
|
||||
|
||||
var chalk = require('chalk');
|
||||
var path = require('path');
|
||||
var child_process = require('child_process');
|
||||
|
||||
/**
|
||||
* Main entry point to starting the packager from JS.
|
||||
* @param {boolean} newWindow If true, will start the packager in a new shell window.
|
||||
*/
|
||||
module.exports = function(newWindow) {
|
||||
if (newWindow) {
|
||||
var launchPackagerScript =
|
||||
path.resolve(__dirname, '..', 'packager', 'launchPackager.command');
|
||||
if (process.platform === 'darwin') {
|
||||
child_process.spawnSync('open', [launchPackagerScript]);
|
||||
} else if (process.platform === 'linux') {
|
||||
child_process.spawn(
|
||||
'xterm',
|
||||
['-e', 'sh', launchPackagerScript],
|
||||
{detached: true});
|
||||
} else if (/^win/.test(process.platform)) {
|
||||
console.log(chalk.yellow('Starting the packager in a new window ' +
|
||||
'is not supported on Windows yet.\nPlease start it manually using ' +
|
||||
'\'react-native start\'.'));
|
||||
console.log('We believe the best Windows ' +
|
||||
'support will come from a community of people\nusing React Native on ' +
|
||||
'Windows on a daily basis.\n' +
|
||||
'Would you be up for sending a pull request?');
|
||||
} else {
|
||||
console.log('Cannot start the packager. Unknown platform ' + process.platform);
|
||||
}
|
||||
} else {
|
||||
if (/^win/.test(process.platform)) {
|
||||
child_process.spawn('node', [
|
||||
path.resolve(__dirname, '..', 'packager', 'packager.js'),
|
||||
'--projectRoots',
|
||||
process.cwd(),
|
||||
], {stdio: 'inherit'});
|
||||
} else {
|
||||
child_process.spawn('sh', [
|
||||
path.resolve(__dirname, '..', 'packager', 'packager.sh'),
|
||||
'--projectRoots',
|
||||
process.cwd(),
|
||||
], {stdio: 'inherit'});
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user