mirror of
https://github.com/zhigang1992/react-native-swiper.git
synced 2026-05-28 23:51:13 +08:00
merge PR & minor fixes
This commit is contained in:
86
examples/node_modules/react-native/local-cli/bundle.js
generated
vendored
86
examples/node_modules/react-native/local-cli/bundle.js
generated
vendored
@@ -1,86 +0,0 @@
|
||||
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 = 'iOS/main.jsbundle';
|
||||
|
||||
function getBundle(flags) {
|
||||
|
||||
var outPath = flags.out ? flags.out : OUT_PATH;
|
||||
|
||||
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: '2',
|
||||
blacklistRE: blacklist('ios'),
|
||||
};
|
||||
|
||||
var url = '/index.ios.bundle?dev=' + 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(err) {
|
||||
if (err) {
|
||||
console.log(chalk.red('Error saving bundle to disk'));
|
||||
throw err;
|
||||
} else {
|
||||
console.log('Successfully saved bundle to ' + outPath);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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',
|
||||
].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,
|
||||
assetRoots: args.indexOf('--assetRoots') !== -1 ? args[args.indexOf('--assetRoots') + 1] : false,
|
||||
out: args.indexOf('--out') !== -1 ? args[args.indexOf('--out') + 1] : false,
|
||||
}
|
||||
|
||||
if (flags.help) {
|
||||
showHelp();
|
||||
} else {
|
||||
getBundle(flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
189
examples/node_modules/react-native/local-cli/cli.js
generated
vendored
189
examples/node_modules/react-native/local-cli/cli.js
generated
vendored
@@ -1,69 +1,161 @@
|
||||
/**
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
* 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 spawn = require('child_process').spawn;
|
||||
require('../packager/babelRegisterOnly')([
|
||||
/private-cli\/src/,
|
||||
/local-cli/
|
||||
]);
|
||||
|
||||
var bundle = require('./bundle/bundle');
|
||||
var childProcess = require('child_process');
|
||||
var Config = require('./util/Config');
|
||||
var defaultConfig = require('./default.config');
|
||||
var dependencies = require('./dependencies/dependencies');
|
||||
var fs = require('fs');
|
||||
var generate = require('./generate/generate');
|
||||
var library = require('./library/library');
|
||||
var link = require('./library/link');
|
||||
var path = require('path');
|
||||
var Promise = require('promise');
|
||||
var runAndroid = require('./runAndroid/runAndroid');
|
||||
var server = require('./server/server');
|
||||
var TerminalAdapter = require('yeoman-environment/lib/adapter.js');
|
||||
var yeoman = require('yeoman-environment');
|
||||
var unbundle = require('./bundle/unbundle');
|
||||
var upgrade = require('./upgrade/upgrade');
|
||||
|
||||
var init = require('./init.js');
|
||||
var install = require('./install.js');
|
||||
var bundle = require('./bundle.js');
|
||||
var newLibrary = require('./new-library.js');
|
||||
var fs = require('fs');
|
||||
var gracefulFs = require('graceful-fs');
|
||||
|
||||
function printUsage() {
|
||||
console.log([
|
||||
'Usage: react-native <command>',
|
||||
'',
|
||||
'Commands:',
|
||||
' start: starts the webserver',
|
||||
' install: installs npm react components',
|
||||
' bundle: builds the javascript bundle for offline use',
|
||||
' new-library: generates a native library bridge'
|
||||
].join('\n'));
|
||||
process.exit(1);
|
||||
}
|
||||
// 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);
|
||||
|
||||
function printInitWarning() {
|
||||
console.log([
|
||||
'Looks like React Native project already exists in the current',
|
||||
'folder. Run this command from a different folder or remove node_modules/react-native'
|
||||
].join('\n'));
|
||||
process.exit(1);
|
||||
}
|
||||
var documentedCommands = {
|
||||
'start': [server, 'starts the webserver'],
|
||||
'bundle': [bundle, 'builds the javascript bundle for offline use'],
|
||||
'unbundle': [unbundle, 'builds javascript as "unbundle" for offline use'],
|
||||
'new-library': [library, 'generates a native library bridge'],
|
||||
'link': [link, 'Adds a third-party library to your project. Example: react-native link awesome-camera'],
|
||||
'android': [generateWrapper, 'generates an Android project for your app'],
|
||||
'run-android': [runAndroid, 'builds your app and starts it on a connected Android emulator or device'],
|
||||
'upgrade': [upgrade, 'upgrade your app\'s template files to the latest version; run this after ' +
|
||||
'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, ''],
|
||||
};
|
||||
|
||||
var commands = Object.assign({}, documentedCommands, undocumentedCommands);
|
||||
|
||||
/**
|
||||
* Parses the command line and runs a command of the CLI.
|
||||
*/
|
||||
function run() {
|
||||
var args = process.argv.slice(2);
|
||||
if (args.length === 0) {
|
||||
printUsage();
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
case 'start':
|
||||
spawn('sh', [
|
||||
path.resolve(__dirname, '../packager', 'packager.sh'),
|
||||
'--projectRoots',
|
||||
process.cwd(),
|
||||
], {stdio: 'inherit'});
|
||||
break;
|
||||
case 'install':
|
||||
install.init();
|
||||
break;
|
||||
case 'bundle':
|
||||
bundle.init(args);
|
||||
break;
|
||||
case 'new-library':
|
||||
newLibrary.init(args);
|
||||
break;
|
||||
case 'init':
|
||||
printInitWarning();
|
||||
break;
|
||||
default:
|
||||
const setupEnvScript = /^win/.test(process.platform)
|
||||
? 'setup_env.bat'
|
||||
: 'setup_env.sh';
|
||||
childProcess.execFileSync(path.join(__dirname, setupEnvScript));
|
||||
|
||||
var command = commands[args[0]];
|
||||
if (!command) {
|
||||
console.error('Command `%s` unrecognized', args[0]);
|
||||
printUsage();
|
||||
return;
|
||||
}
|
||||
// Here goes any cli commands we need to
|
||||
|
||||
command[0](args, Config.get(__dirname, defaultConfig)).done();
|
||||
}
|
||||
|
||||
function generateWrapper(args, config) {
|
||||
return generate([
|
||||
'--platform', 'android',
|
||||
'--project-path', process.cwd(),
|
||||
'--project-name', JSON.parse(
|
||||
fs.readFileSync('package.json', 'utf8')
|
||||
).name
|
||||
], config);
|
||||
}
|
||||
|
||||
function printUsage() {
|
||||
console.log([
|
||||
'Usage: react-native <command>',
|
||||
'',
|
||||
'Commands:'
|
||||
].concat(Object.keys(documentedCommands).map(function(name) {
|
||||
return ' - ' + name + ': ' + documentedCommands[name][1];
|
||||
})).join('\n'));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// The user should never get here because projects are inited by
|
||||
// using `react-native-cli` from outside a project directory.
|
||||
function printInitWarning() {
|
||||
return Promise.resolve().then(function() {
|
||||
console.log([
|
||||
'Looks like React Native project already exists in the current',
|
||||
'folder. Run this command from a different folder or remove node_modules/react-native'
|
||||
].join('\n'));
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
class CreateSuppressingTerminalAdapter extends TerminalAdapter {
|
||||
constructor() {
|
||||
super();
|
||||
// suppress 'create' output generated by yeoman
|
||||
this.log.create = function() {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the template for a React Native project given the provided
|
||||
* parameters:
|
||||
* - projectDir: templates will be copied here.
|
||||
* - argsOrName: project name or full list of custom arguments to pass to the
|
||||
* generator.
|
||||
*/
|
||||
function init(projectDir, argsOrName) {
|
||||
console.log('Setting up new React Native app in ' + projectDir);
|
||||
var env = yeoman.createEnv(
|
||||
undefined,
|
||||
undefined,
|
||||
new CreateSuppressingTerminalAdapter()
|
||||
);
|
||||
|
||||
env.register(
|
||||
require.resolve(path.join(__dirname, 'generator')),
|
||||
'react:app'
|
||||
);
|
||||
|
||||
// argv is for instance
|
||||
// ['node', 'react-native', 'init', 'AwesomeApp', '--verbose']
|
||||
// args should be ['AwesomeApp', '--verbose']
|
||||
var args = Array.isArray(argsOrName)
|
||||
? argsOrName
|
||||
: [argsOrName].concat(process.argv.slice(4));
|
||||
|
||||
var generator = env.create('react:app', {args: args});
|
||||
generator.destinationRoot(projectDir);
|
||||
generator.run();
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
@@ -73,4 +165,5 @@ if (require.main === module) {
|
||||
module.exports = {
|
||||
run: run,
|
||||
init: init,
|
||||
commands: exportedCommands
|
||||
};
|
||||
|
||||
133
examples/node_modules/react-native/local-cli/install.js
generated
vendored
133
examples/node_modules/react-native/local-cli/install.js
generated
vendored
@@ -1,133 +0,0 @@
|
||||
/**
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
var NODE_MODULE_PATH = path.resolve(__dirname, 'node_modules');
|
||||
|
||||
var PODFILE_PATH = path.resolve(__dirname, 'Podfile');
|
||||
|
||||
function addDependency(name, path) {
|
||||
console.log('Found dependency: ' + name);
|
||||
|
||||
var podfileText;
|
||||
try {
|
||||
podfileText = fs.readFileSync(PODFILE_PATH, 'utf8');
|
||||
} catch(e) {}
|
||||
|
||||
if (podfileText.indexOf('pod \'' + name + '\'') === -1) {
|
||||
var indexOfReactComponents = podfileText.indexOf('#</React-Native>') - 1;
|
||||
|
||||
var insertedDependency = '\npod \'' + name + '\', :path => \'' + path + '\'\n';
|
||||
var newPodfileText = [podfileText.slice(0, indexOfReactComponents),
|
||||
insertedDependency,
|
||||
podfileText.slice(indexOfReactComponents)].join('');
|
||||
|
||||
fs.writeFileSync(PODFILE_PATH, newPodfileText);
|
||||
console.log('Added ' + name + ' to Podfile.');
|
||||
} else {
|
||||
console.log(name + ' already in Podfile');
|
||||
}
|
||||
}
|
||||
|
||||
function installDependecies() {
|
||||
console.log('Installing dependencies...');
|
||||
exec('pod install', function(error, stdout, stderr) {
|
||||
if (!stderr) {
|
||||
console.log('Installed Pod dependencies.');
|
||||
} else {
|
||||
console.error('Error installing Pod dependencies.', stderr);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setupPodfile: function() {
|
||||
var returnArgs = {
|
||||
created: false
|
||||
};
|
||||
|
||||
var podfileText;
|
||||
try {
|
||||
podfileText = fs.readFileSync(PODFILE_PATH, 'utf8');
|
||||
} catch(e) {}
|
||||
|
||||
var openingReactTag = '#<React-Native>';
|
||||
var closingReactTag = '\n#</React-Native>';
|
||||
var reactPodfileBoilerplate = openingReactTag + closingReactTag;
|
||||
|
||||
if (!podfileText) {
|
||||
returnArgs.created = true;
|
||||
fs.appendFileSync(PODFILE_PATH, reactPodfileBoilerplate);
|
||||
} else {
|
||||
if (podfileText.indexOf(openingReactTag) === -1 || podfileText.indexOf(closingReactTag) === -1) {
|
||||
fs.appendFileSync(PODFILE_PATH, reactPodfileBoilerplate);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
podfileText = fs.readFileSync(PODFILE_PATH, 'utf8');
|
||||
returnArgs.podfileText = podfileText;
|
||||
} catch(e) {}
|
||||
|
||||
if (podfileText.indexOf('pod \'React\'') === -1) {
|
||||
var indexOfReactComponents = podfileText.indexOf(openingReactTag) + openingReactTag.length;
|
||||
|
||||
var insertedReactDependency = '\npod \'React\', :path => \'node_modules/react-native\'\n';
|
||||
try {
|
||||
var newPodfileText = [podfileText.slice(0, indexOfReactComponents),
|
||||
insertedReactDependency,
|
||||
podfileText.slice(indexOfReactComponents)].join('');
|
||||
|
||||
fs.writeFileSync(PODFILE_PATH, newPodfileText);
|
||||
returnArgs.podfileText = newPodfileText;
|
||||
} catch(e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return returnArgs;
|
||||
},
|
||||
init: function(arguement) {
|
||||
// arguement is available for future arguement commands
|
||||
console.log('Searching for installable React Native components...');
|
||||
this.setupPodfile();
|
||||
|
||||
var nodeModuleList = fs.readdirSync(NODE_MODULE_PATH);
|
||||
|
||||
if (nodeModuleList.length > 0) {
|
||||
nodeModuleList.forEach(function(nodeModule) {
|
||||
// Module would not start with '.' hidden file identifier
|
||||
if (nodeModule.charAt(0) !== '.') {
|
||||
var modulePath = './node_modules/' + nodeModule;
|
||||
|
||||
var nodeModulePackage;
|
||||
try {
|
||||
nodeModulePackage = fs.readFileSync(modulePath + '/package.json', 'utf8');
|
||||
} catch(error) {
|
||||
console.error('Error reading Node Module: `%s` package.json', nodeModule);
|
||||
throw error;
|
||||
}
|
||||
|
||||
var packageJSON = JSON.parse(nodeModulePackage);
|
||||
console.log(packageJSON.hasOwnProperty('react-native-component'));
|
||||
if (packageJSON.hasOwnProperty('react-native-component')) {
|
||||
addDependency(nodeModule, modulePath);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
installDependecies();
|
||||
} else {
|
||||
console.error('./node_modules directory contains 0 modules');
|
||||
console.log('No React Native components found.');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
10
examples/node_modules/react-native/local-cli/wrong-react-native.js
generated
vendored
10
examples/node_modules/react-native/local-cli/wrong-react-native.js
generated
vendored
@@ -1,4 +1,14 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
console.error([
|
||||
'\033[31mLooks like you installed react-native globally, maybe you meant react-native-cli?',
|
||||
'To fix the issue, run:\033[0m',
|
||||
|
||||
Reference in New Issue
Block a user