This repository was archived by the owner on Jan 11, 2023. It is now read-only.
File tree 3 files changed +18
-4
lines changed
3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ const prog = sade('sapper').version(pkg.version);
13
13
prog . command ( 'dev' )
14
14
. describe ( 'Start a development server' )
15
15
. option ( '-p, --port' , 'Specify a port' )
16
- . action ( async ( opts : { port : number } ) => {
16
+ . option ( '-o, --open' , 'Open a browser window' )
17
+ . action ( async ( opts : { port : number , open : boolean } ) => {
17
18
const { dev } = await import ( './cli/dev' ) ;
18
19
dev ( opts ) ;
19
20
} ) ;
@@ -40,7 +41,8 @@ prog.command('build [dest]')
40
41
prog . command ( 'start [dir]' )
41
42
. describe ( 'Start your app' )
42
43
. option ( '-p, --port' , 'Specify a port' )
43
- . action ( async ( dir = 'build' , opts : { port : number } ) => {
44
+ . option ( '-o, --open' , 'Open a browser window' )
45
+ . action ( async ( dir = 'build' , opts : { port : number , open : boolean } ) => {
44
46
const { start } = await import ( './cli/start' ) ;
45
47
start ( dir , opts ) ;
46
48
} ) ;
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ function create_hot_update_server(port: number, interval = 10000) {
70
70
return { send } ;
71
71
}
72
72
73
- export async function dev ( opts : { port : number } ) {
73
+ export async function dev ( opts : { port : number , open : boolean } ) {
74
74
process . env . NODE_ENV = 'development' ;
75
75
76
76
let port = opts . port || + process . env . PORT ;
@@ -241,6 +241,8 @@ export async function dev(opts: { port: number }) {
241
241
}
242
242
} ) ;
243
243
244
+ let first = true ;
245
+
244
246
watch ( compilers . client , {
245
247
name : 'client' ,
246
248
@@ -263,6 +265,12 @@ export async function dev(opts: { port: number }) {
263
265
hot_update_server . send ( {
264
266
status : 'completed'
265
267
} ) ;
268
+
269
+ if ( first ) {
270
+ first = false ;
271
+ console . log ( `${ clorox . bold . cyan ( `> Listening on localhost:${ port } ` ) } ` ) ;
272
+ if ( opts . open ) child_process . exec ( `open http://localhost:${ port } ` ) ;
273
+ }
266
274
} ) ;
267
275
268
276
create_serviceworker_manifest ( {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import * as child_process from 'child_process';
4
4
import * as clorox from 'clorox' ;
5
5
import * as ports from 'port-authority' ;
6
6
7
- export async function start ( dir : string , opts : { port : number } ) {
7
+ export async function start ( dir : string , opts : { port : number , open : boolean } ) {
8
8
let port = opts . port || + process . env . PORT ;
9
9
10
10
const resolved = path . resolve ( dir ) ;
@@ -32,4 +32,8 @@ export async function start(dir: string, opts: { port: number }) {
32
32
SAPPER_DEST : dir
33
33
} , process . env )
34
34
} ) ;
35
+
36
+ await ports . wait ( port ) ;
37
+ console . log ( `${ clorox . bold . cyan ( `> Listening on localhost:${ port } ` ) } ` ) ;
38
+ if ( opts . open ) child_process . exec ( `open http://localhost:${ port } ` ) ;
35
39
}
You can’t perform that action at this time.
0 commit comments