Skip to content

Commit 69fa26f

Browse files
fsonbrentvatne
authored andcommitted
Delegate commands to Expo CLI (expo#751)
* Delegate commands to Expo CLI * Add a deprecation warning and upgrade instructions. * Remove now unnecessary dependencies
1 parent 1808872 commit 69fa26f

39 files changed

+142
-4865
lines changed

create-react-native-app/src/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ async function createApp(name: string, verbose: boolean, version: ?string): Prom
8686

8787
const packageToInstall = getInstallPackage(version);
8888
const packageName = getPackageName(packageToInstall);
89+
90+
if (packageToInstall === 'react-native-scripts') {
91+
// The latest version of react-native-scripts is just a wrapper for expo-cli,
92+
// so we can skip installing it and just run expo-cli directly.
93+
runExpoCli('init', name);
94+
return;
95+
}
96+
8997
checkAppName(appName, packageName);
9098

9199
if (!await pathExists(name)) {
@@ -275,3 +283,37 @@ async function isSafeToCreateProjectIn(root: string): Promise<boolean> {
275283
return validFiles.indexOf(file) >= 0;
276284
});
277285
}
286+
287+
function runExpoCli(...args) {
288+
spawn('expo-cli', args, { stdio: 'inherit' })
289+
.on('exit', function(code) {
290+
process.exit(code);
291+
})
292+
.on('error', function() {
293+
console.warn('This command requires Expo CLI.');
294+
var rl = require('readline').createInterface({
295+
input: process.stdin,
296+
output: process.stdout,
297+
});
298+
rl.question('Do you want to install it globally [Y/n]? ', function(answer) {
299+
rl.close();
300+
if (/^n/i.test(answer.trim())) {
301+
process.exit(1);
302+
} else {
303+
console.log("Installing the package 'expo-cli'...");
304+
spawn('npm', ['install', '--global', '--loglevel', 'error', 'expo-cli@latest'], {
305+
stdio: ['inherit', 'ignore', 'inherit'],
306+
}).on('close', function(code) {
307+
if (code !== 0) {
308+
console.error('Installing Expo CLI failed. You can install it manually with:');
309+
console.error(' npm install --global expo-cli');
310+
process.exit(code);
311+
} else {
312+
console.log('Expo CLI installed. You can run `expo --help` for instructions.');
313+
runExpoCli(...args);
314+
}
315+
});
316+
}
317+
});
318+
});
319+
}

react-native-scripts/__mocks__/fs.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

react-native-scripts/package.json

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,10 @@
2525
"build": "taskr build"
2626
},
2727
"dependencies": {
28-
"@expo/bunyan": "1.8.10",
2928
"babel-runtime": "^6.9.2",
3029
"chalk": "^2.0.1",
3130
"cross-spawn": "^5.0.1",
32-
"fs-extra": "^3.0.1",
33-
"indent-string": "^3.0.0",
34-
"inquirer": "^3.0.1",
35-
"lodash": "^4.17.4",
36-
"match-require": "^2.0.0",
37-
"minimist": "^1.2.0",
38-
"path-exists": "^3.0.0",
39-
"progress": "^2.0.0",
40-
"qrcode-terminal": "^0.11.0",
41-
"rimraf": "^2.6.1",
42-
"xdl": "48.1.4"
31+
"minimist": "^1.2.0"
4332
},
4433
"devDependencies": {
4534
"@taskr/babel": "^1.0.6",
Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,77 @@
11
#!/usr/bin/env node
2-
// @flow
2+
'use strict';
33
import spawn from 'cross-spawn';
4+
import chalk from 'chalk';
45

56
const script = process.argv[2];
67
const args = process.argv.slice(3);
78

8-
const validCommands = ['eject', 'android', 'ios', 'start', 'test'];
9-
10-
if (validCommands.indexOf(script) !== -1) {
11-
// the command is valid
12-
const result = spawn.sync(
13-
'node',
14-
['--no-deprecation', require.resolve('../scripts/' + script)].concat(args),
15-
{ stdio: 'inherit' }
16-
);
17-
process.exit(result.status);
9+
if (script === 'start' || script === 'eject') {
10+
printDeprecationMessage();
11+
runExpoCli(script, ...args);
12+
} else if (script === 'android' || script === 'ios') {
13+
printDeprecationMessage();
14+
runExpoCli('start', `--${script}`, ...args);
1815
} else {
1916
console.log(
2017
`Invalid command '${script}'. Please check if you need to update react-native-scripts.`
2118
);
19+
process.exit(1);
20+
}
21+
22+
function printDeprecationMessage() {
23+
console.warn(chalk.bold('Note: react-native-scripts is deprecated.\n'));
24+
console.warn(chalk.underline('Upgrading your project to use Expo CLI:\n'));
25+
console.warn('Make these changes to package.json:');
26+
console.warn(
27+
chalk.bold("1) Replace 'react-native-scripts' with 'expo' in the 'scripts' config.")
28+
);
29+
console.warn(
30+
` Example:
31+
"scripts": {
32+
"start": "expo start",
33+
"eject": "expo eject",
34+
"android": "expo start --android",
35+
"ios": "expo start --ios",
36+
"test": "jest"
37+
}`
38+
);
39+
console.warn(chalk.bold('2) Remove react-native-scripts from devDependencies.\n'));
40+
console.warn(
41+
chalk.bold("That's all! Expo CLI will install automatically when you run `npm start`.\n")
42+
);
43+
}
44+
45+
function runExpoCli(...args) {
46+
spawn('expo-cli', args, { stdio: 'inherit' })
47+
.on('exit', function(code) {
48+
process.exit(code);
49+
})
50+
.on('error', function() {
51+
console.warn('This command requires Expo CLI.');
52+
var rl = require('readline').createInterface({
53+
input: process.stdin,
54+
output: process.stdout,
55+
});
56+
rl.question('Do you want to install it globally [Y/n]? ', function(answer) {
57+
rl.close();
58+
if (/^n/i.test(answer.trim())) {
59+
process.exit(1);
60+
} else {
61+
console.log("Installing the package 'expo-cli'...");
62+
spawn('npm', ['install', '--global', '--loglevel', 'error', 'expo-cli@latest'], {
63+
stdio: ['inherit', 'ignore', 'inherit'],
64+
}).on('close', function(code) {
65+
if (code !== 0) {
66+
console.error('Installing Expo CLI failed. You can install it manually with:');
67+
console.error(' npm install --global expo-cli');
68+
process.exit(code);
69+
} else {
70+
console.log('Expo CLI installed. You can run `expo --help` for instructions.');
71+
runExpoCli(...args);
72+
}
73+
});
74+
}
75+
});
76+
});
2277
}

react-native-scripts/src/scripts/android.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)