-
-
Notifications
You must be signed in to change notification settings - Fork 375
/
Copy pathindex.js
executable file
·144 lines (133 loc) · 4.73 KB
/
index.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env node
const envinfo = require('envinfo');
const sade = require('sade');
const notifier = require('update-notifier');
const { error } = require('./util');
const pkg = require('../package.json');
const { isNodeVersionGreater } = require('./util');
const min = pkg.engines.node;
if (!isNodeVersionGreater(min)) {
error(
`You are using Node ${process.version} but preact-cli requires Node ${min}. Please upgrade Node to continue!\n`
);
}
// Safe to load async-based funcs
const commands = require('./commands');
// installHooks();
notifier({ pkg }).notify();
process.on('unhandledRejection', err => {
error(err.stack || err.message);
});
const prog = sade('preact').version(pkg.version);
prog
.command('build [src]')
.describe(
'Create a production build. You can disable "default: true" flags by prefixing them with --no-<option>'
)
.option('--src', 'Specify source directory', 'src')
.option('--dest', 'Specify output directory', 'build')
.option('--cwd', 'A directory to use instead of $PWD', '.')
.option('--esm', 'Builds ES-2015 bundles for your code', true)
.option('--sw', 'Generate and attach a Service Worker', true)
.option('--babelConfig', 'Path to custom Babel config', '.babelrc')
.option('--json', 'Generate build stats for bundle analysis', false)
.option(
'--template',
'Path to custom HTML template (default "src/template.html")'
)
.option(
'--preload',
'Adds preload links to the HTML for required resources',
false
)
.option(
'--analyze',
'Launch interactive Analyzer to inspect production bundle(s)',
false
)
.option('--prerender', 'Renders route(s) into static HTML', true)
.option(
'--prerenderUrls',
'Path to prerendered routes config',
'prerender-urls.json'
)
.option('--brotli', 'Builds brotli compressed bundles of JS resources', false)
.option('--inline-css', 'Adds critical CSS to the prerendered HTML', true)
.option('-c, --config', 'Path to custom CLI config', 'preact.config.js')
.option('-v, --verbose', 'Verbose output', false)
.action(commands.build);
prog
.command('create [template] [dest]')
.describe('Create a new application')
.option('--name', 'The application name')
.option('--cwd', 'A directory to use instead of $PWD', '.')
.option('--force', 'Force destination output; will override!', false)
.option('--install', 'Install dependencies', true)
.option(
'--yarn',
'Use `yarn` instead of `npm` to install dependencies',
false
)
.option('--git', 'Initialize Git repository', false)
.option('--license', 'License type', 'MIT')
.option('-v, --verbose', 'Verbose output', false)
.action(commands.create);
prog
.command('watch [src]')
.describe('Start a live-reload server for development')
.option('--src', 'Specify source directory', 'src')
.option('--cwd', 'A directory to use instead of $PWD', '.')
.option('--esm', 'Builds ES-2015 bundles for your code', false)
.option('--clear', 'Clears the console when the devServer updates', true)
.option('--sw', 'Generate and attach a Service Worker')
.option('--babelConfig', 'Path to custom Babel config', '.babelrc')
.option('--rhl', 'Deprecated, use --refresh instead', false)
.option('--refresh', 'Enables experimental prefresh functionality', false)
.option('--json', 'Generate build stats for bundle analysis', false)
.option(
'--template',
'Path to custom HTML template (default "src/template.html")'
)
.option('--https', 'Run server with HTTPS protocol')
.option('--key', 'Path to PEM key for custom SSL certificate')
.option('--cert', 'Path to custom SSL certificate')
.option('--cacert', 'Path to optional CA certificate override')
.option('--prerender', 'Render route(s) into static HTML (first run only)')
.option(
'--prerenderUrls',
'Path to prerendered routes config',
'prerender-urls.json'
)
.option('-c, --config', 'Path to custom CLI config', 'preact.config.js')
.option('-H, --host', 'Set server hostname', '0.0.0.0')
.option('-p, --port', 'Set server port (default 8080)')
.action(commands.watch);
prog.command('list').describe('List official templates').action(commands.list);
prog
.command('info')
.describe('Print out debugging information about the local environment')
.action(() => {
envinfo
.run({
System: ['OS', 'CPU'],
Binaries: ['Node', 'Yarn', 'npm'],
Browsers: ['Chrome', 'Edge', 'Firefox', 'Safari'],
npmPackages: [
'preact',
'preact-compat',
'preact-cli',
'preact-router',
'preact-render-to-string',
],
npmGlobalPackages: ['preact-cli'],
})
.then(info => process.stdout.write(`\nEnvironment Info:${info}\n`));
});
prog.parse(process.argv, {
unknown: arg => {
const cmd = process.argv[2];
error(
`Invalid argument '${arg}' passed to ${cmd}. Please refer to 'preact ${cmd} --help' for the full list of options.\n`
);
},
});