This repository has been archived by the owner on Oct 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
start.js
85 lines (66 loc) · 2.04 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* @flow
*/
import { ProjectUtils, Project, UrlUtils } from 'xdl';
import chalk from 'chalk';
import path from 'path';
import log from '../log';
import sendTo from '../sendTo';
import { installExitHooks } from '../exit';
import urlOpts from '../urlOpts';
async function action(projectDir, options) {
const projectState = await Project.currentStatus(projectDir);
if (projectState === 'running') {
log.error('exp is already running for this project. Exiting...');
process.exit(1);
} else if (projectState === 'ill') {
log.warn(
'exp may have exited improperly. Proceeding, but you should check for orphaned processes.'
);
}
installExitHooks(projectDir);
await urlOpts.optsAsync(projectDir, options);
log(chalk.gray('Using project at', projectDir));
let root = path.resolve(projectDir);
let startOpts = {};
if (options.clear) {
startOpts.reset = true;
}
await Project.startAsync(root, startOpts);
log('Expo is ready.');
let url = await UrlUtils.constructManifestUrlAsync(projectDir);
let { exp } = await ProjectUtils.readConfigJsonAsync(projectDir);
if (!exp.isDetached) {
log('You can scan this QR code:\n');
urlOpts.printQRCode(url);
}
log('Your URL is\n\n' + chalk.underline(url) + '\n');
log.raw(url);
const recipient = await sendTo.getRecipient(options.sendTo);
if (recipient) {
await sendTo.sendUrlAsync(url, recipient);
}
await urlOpts.handleMobileOptsAsync(projectDir, options);
log(
chalk.green(
'Logs for your project will appear below. Press Ctrl+C to exit.'
)
);
}
export default (program: any) => {
program
.command('start [project-dir]')
.alias('r')
.description(
'Starts or restarts a local server for your app and gives you a URL to it'
)
.option(
'-s, --send-to [dest]',
'A phone number or e-mail address to send a link to'
)
.option('-c, --clear', 'Clear the React Native packager cache')
.urlOpts()
.allowNonInteractive()
.allowOffline()
.asyncActionProjectDir(action, true);
};