-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
storybook-start.js
96 lines (84 loc) · 3.03 KB
/
storybook-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
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env node
/* eslint-disable no-console */
import path from 'path';
import program from 'commander';
import shelljs from 'shelljs';
import Server from '../server';
program
.option('-h, --host <host>', 'host to listen on')
.option('-p, --port <port>', 'port to listen on')
.option('--haul <configFile>', 'use haul with config file')
.option('--platform <ios|android|all>', 'build platform-specific build')
.option('-s, --secured', 'whether server is running on https')
.option('-c, --config-dir [dir-name]', 'storybook config directory')
.option('-e, --environment [environment]', 'DEVELOPMENT/PRODUCTION environment for webpack')
.option('-r, --reset-cache', 'reset react native packager')
.option('--skip-packager', 'run only storybook server')
.option('-i, --manual-id', 'allow multiple users to work with same storybook')
.option('--smoke-test', 'Exit after successful start')
.option('--packager-port <packagerPort>', 'Custom packager port')
.option('--root [root]', 'Add additional root(s) to be used by the packager in this project')
.option('--projectRoots [projectRoots]', 'Override the root(s) to be used by the packager')
.parse(process.argv);
const projectDir = path.resolve();
const configDir = path.resolve(program.configDir || './storybook');
const listenAddr = [program.port];
if (program.host) {
listenAddr.push(program.host);
}
const server = new Server({
projectDir,
configDir,
environment: program.environment,
manualId: program.manualId,
secured: program.secured,
});
server.listen(...listenAddr, err => {
if (err) {
throw err;
}
const address = `http://${program.host || 'localhost'}:${program.port}/`;
console.info(`\nReact Native Storybook started on => ${address}\n`);
if (program.smokeTest) {
process.exit(0);
}
});
if (!program.skipPackager) {
let symlinks = [];
let roots = [projectDir];
if (program.root) {
roots = roots.concat(program.root.split(',').map(root => path.resolve(root)));
}
try {
const findSymlinksPaths = require('react-native/local-cli/util/findSymlinksPaths'); // eslint-disable-line global-require
symlinks = findSymlinksPaths(path.join(projectDir, 'node_modules'), [projectDir]);
} catch (e) {
console.warn(`Unable to load findSymlinksPaths: ${e.message}`);
}
let projectRoots = (configDir === projectDir ? [configDir] : [configDir, projectDir]).concat(
symlinks
);
if (program.projectRoots) {
projectRoots = projectRoots.concat(
program.projectRoots.split(',').map(root => path.resolve(root))
);
}
let cliCommand = 'react-native start';
if (program.haul) {
const platform = program.platform || 'all';
cliCommand = `haul start --config ${program.haul} --platform ${platform}`;
}
// RN packager
shelljs.exec(
[
cliCommand,
`--projectRoots ${projectRoots.join(',')}`,
`--root ${roots.join(',')}`,
program.resetCache && '--reset-cache',
program.packagerPort && `--port=${program.packagerPort}`,
]
.filter(x => x)
.join(' '),
{ async: true }
);
}