11const runWebpack = require ( '../lib/webpack/run-webpack' ) ;
22const { isPortFree, toBool, warn } = require ( '../util' ) ;
3- const { validateArgs } = require ( './validate-args' ) ;
43const getPort = require ( 'get-port' ) ;
54const { resolve } = require ( 'path' ) ;
65
7- const options = [
8- {
9- name : '--src' ,
10- description : 'Specify source directory' ,
11- default : 'src' ,
12- } ,
13- {
14- name : '--cwd' ,
15- description : 'A directory to use instead of $PWD' ,
16- default : '.' ,
17- } ,
18- {
19- name : '--esm' ,
20- description : 'Builds ES-2015 bundles for your code' ,
21- default : false ,
22- } ,
23- {
24- name : '--clear' ,
25- description : 'Clear the console' ,
26- default : true ,
27- } ,
28- {
29- name : '--sw' ,
30- description : 'Generate and attach a Service Worker' ,
31- default : undefined ,
32- } ,
33- {
34- name : '--babelConfig' ,
35- description : 'Path to custom Babel config' ,
36- default : '.babelrc' ,
37- } ,
38- {
39- name : '--rhl' ,
40- description : '(Deprecated) use --refresh instead' ,
41- default : false ,
42- } ,
43- {
44- name : '--json' ,
45- description : 'Generate build stats for bundle analysis' ,
46- } ,
47- {
48- name : '--https' ,
49- description : 'Run server with HTTPS protocol' ,
50- } ,
51- {
52- name : '--key' ,
53- description : 'Path to PEM key for custom SSL certificate' ,
54- } ,
55- {
56- name : '--cert' ,
57- description : 'Path to custom SSL certificate' ,
58- } ,
59- {
60- name : '--cacert' ,
61- description : 'Path to optional CA certificate override' ,
62- } ,
63- {
64- name : '--prerender' ,
65- description : 'Pre-render static content on first run' ,
66- } ,
67- {
68- name : '--prerenderUrls' ,
69- description : 'Path to pre-rendered routes config' ,
70- default : 'prerender-urls.json' ,
71- } ,
72- {
73- name : '--template' ,
74- description : 'Path to custom HTML template (default "src/template.html")' ,
75- } ,
76- {
77- name : '--refresh' ,
78- description : 'Enables experimental preact-refresh functionality' ,
79- default : false ,
80- } ,
81- {
82- name : '-c, --config' ,
83- description : 'Path to custom CLI config' ,
84- default : 'preact.config.js' ,
85- } ,
86- {
87- name : '-H, --host' ,
88- description : 'Set server hostname' ,
89- default : '0.0.0.0' ,
90- } ,
91- {
92- name : '-p, --port' ,
93- description : 'Set server port (default 8080)' ,
94- } ,
95- ] ;
96-
97- async function command ( src , argv ) {
98- validateArgs ( argv , options , 'watch' ) ;
6+ exports . watch = async function watchCommand ( src , argv ) {
997 if ( argv . rhl ) {
1008 delete argv . rhl ;
1019 argv . refresh = argv . rhl ;
@@ -126,9 +34,9 @@ async function command(src, argv) {
12634 }
12735
12836 return runWebpack ( argv , true ) ;
129- }
37+ } ;
13038
131- async function determinePort ( port ) {
39+ const determinePort = ( exports . determinePort = async function ( port ) {
13240 port = parseInt ( port , 10 ) ;
13341 if ( port ) {
13442 if ( ! ( await isPortFree ( port ) ) ) {
@@ -141,10 +49,4 @@ async function determinePort(port) {
14149 }
14250
14351 return port ;
144- }
145-
146- module . exports = {
147- command,
148- options,
149- determinePort,
150- } ;
52+ } ) ;
0 commit comments