react-native-scripts
Version:
Configuration and scripts for Create React Native App.
78 lines (65 loc) • 3.21 kB
JavaScript
;
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _crossSpawn = require('cross-spawn');
var _crossSpawn2 = _interopRequireDefault(_crossSpawn);
var _chalk = require('chalk');
var _chalk2 = _interopRequireDefault(_chalk);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var script = process.argv[2];
var args = process.argv.slice(3);
if (script === 'start' || script === 'eject') {
printDeprecationMessage();
runExpoCli.apply(undefined, [script].concat((0, _toConsumableArray3.default)(args)));
} else if (script === 'android' || script === 'ios') {
printDeprecationMessage();
runExpoCli.apply(undefined, ['start', '--' + script].concat((0, _toConsumableArray3.default)(args)));
} else {
console.log('Invalid command \'' + script + '\'. Please check if you need to update react-native-scripts.');
process.exit(1);
}
function printDeprecationMessage() {
console.warn(_chalk2.default.bold('Note: react-native-scripts is deprecated.\n'));
console.warn(_chalk2.default.underline('Upgrading your project to use Expo CLI:\n'));
console.warn('Make these changes to package.json:');
console.warn(_chalk2.default.bold("1) Replace 'react-native-scripts' with 'expo' in the 'scripts' config."));
console.warn(' Example:\n "scripts": {\n "start": "expo start",\n "eject": "expo eject",\n "android": "expo start --android",\n "ios": "expo start --ios",\n "test": "jest"\n }');
console.warn(_chalk2.default.bold('2) Remove react-native-scripts from devDependencies.\n'));
console.warn(_chalk2.default.bold("That's all! Expo CLI will install automatically when you run `npm start`.\n"));
}
function runExpoCli() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
(0, _crossSpawn2.default)('expo-cli', args, { stdio: 'inherit' }).on('exit', function (code) {
process.exit(code);
}).on('error', function () {
console.warn('This command requires Expo CLI.');
var rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Do you want to install it globally [Y/n]? ', function (answer) {
rl.close();
if (/^n/i.test(answer.trim())) {
process.exit(1);
} else {
console.log("Installing the package 'expo-cli'...");
(0, _crossSpawn2.default)('npm', ['install', '--global', '--loglevel', 'error', 'expo-cli@latest'], {
stdio: ['inherit', 'ignore', 'inherit']
}).on('close', function (code) {
if (code !== 0) {
console.error('Installing Expo CLI failed. You can install it manually with:');
console.error(' npm install --global expo-cli');
process.exit(code);
} else {
console.log('Expo CLI installed. You can run `expo --help` for instructions.');
runExpoCli.apply(undefined, args);
}
});
}
});
});
}
//# sourceMappingURL=react-native-scripts.js.map