-
-
Notifications
You must be signed in to change notification settings - Fork 373
/
Copy pathindex.js
executable file
·140 lines (129 loc) · 4.57 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
#!/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');
const ver = process.version;
const min = pkg.engines.node;
if (
ver
.substring(1)
.localeCompare(min.match(/\d+/g).join('.'), 'en', { numeric: true }) === -1
) {
return error(
`You are using Node ${ver} but preact-cli requires Node ${min}. Please upgrade Node to continue!`,
1
);
}
// Safe to load async-based funcs
const commands = require('./commands');
// installHooks();
notifier({ pkg }).notify();
process.on('unhandledRejection', (err) => {
error(err.stack || err.message);
});
let prog = sade('preact').version(pkg.version);
prog
.command('build [src]')
.describe('Create a production build')
.option('--src', 'Specify source directory', 'src')
.option('--dest', 'Specify output directory', 'build')
.option('--cwd', 'A directory to use instead of $PWD', '.')
.option('--sw', 'Generate and attach a Service Worker', true)
.option('--json', 'Generate build stats for bundle analysis')
.option('--template', 'Path to custom HTML template')
.option('--preload', 'Adds preload tags to the document its assets', false)
.option(
'--refresh',
'Enables experimental preact-refresh functionality',
false
)
.option(
'--analyze',
'Launch interactive Analyzer to inspect production bundle(s)'
)
.option(
'--prerenderUrls',
'Path to pre-rendered routes config',
'prerender-urls.json'
)
.option('-c, --config', 'Path to custom CLI config', 'preact.config.js')
.option('--babelConfig', 'Specify the babel config file', '.babelrc')
.option('--esm', 'Builds ES-2015 bundles for your code.', true)
.option('--brotli', 'Builds brotli compressed bundles of javascript.', false)
.option('--inline-css', 'Adds critical css to the prerendered markup.', true)
.option('-v, --verbose', 'Verbose output')
.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`', false)
.option('--git', 'Initialize git repository', false)
.option('--license', 'License type', 'MIT')
.option('-v, --verbose', 'Verbose output', false)
.action(commands.create);
prog.command('list').describe('List official templates').action(commands.list);
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('--devServer', 'Determine if dev server should be enabled', true)
.option(
'--dest',
'Specify output directory if dev server is disabled',
'build'
)
.option(
'--ignore',
'Path relative to src to be ignored during watch if dev server is disabled',
''
)
.option('--esm', 'Builds ES-2015 bundles for your code.', false)
.option('--clear', 'Clear the console', true)
.option('--sw', 'Generate and attach a Service Worker', undefined)
.option('--babelConfig', 'Specify the babel config file', '.babelrc')
.option('--rhl', '(Deprecated) use --refresh instead', false)
.option('--json', 'Generate build stats for bundle analysis')
.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', 'Pre-render static content on first run')
.option('--template', 'Path to custom HTML template')
.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', 8080)
.option(
'--prerenderUrls',
'Path to pre-rendered routes config',
'prerender-urls.json'
)
.action(commands.watch);
prog
.command('info')
.describe('Print out debugging information about the local environment')
.action(() => {
process.stdout.write('\nEnvironment Info:');
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(`${info}\n`));
});
prog.parse(process.argv);