@@ -6,6 +6,7 @@ import { replaceInFile } from 'replace-in-file'
6
6
import handler from 'serve-handler'
7
7
import http from 'http'
8
8
import events from 'events'
9
+ import yargs from 'yargs'
9
10
10
11
const createStaticServer = ( port , distFolder ) =>
11
12
http . createServer ( ( request , response ) =>
@@ -17,15 +18,26 @@ const createStaticServer = (port, distFolder) =>
17
18
} )
18
19
) . listen ( port )
19
20
21
+ const renderPages = async ( ) => {
22
+
23
+ const argv = yargs ( process . argv . slice ( 2 ) )
24
+ . usage ( 'Usage: $0 [options]' )
25
+ . describe ( 'port' , 'Port to use for the prerendering server' )
26
+ . alias ( 'p' , 'port' )
27
+ . describe ( 'dist' , 'Directory containing built static files from the bundler' )
28
+ . alias ( 'd' , 'dist' )
29
+ . describe ( 'entry' , 'Entry page to start crawling the site from' )
30
+ . alias ( 'e' , 'entry' )
31
+ . describe ( 'extra' , 'Comma separated list of paths to render if they aren\'t automatically crawled' )
32
+ . alias ( 'x' , 'extra' )
33
+ . argv ;
34
+
35
+ // Get command line arguments with defaults
36
+ const port = argv . port ? Number ( argv . port ) : 54321
37
+ const distFolder = argv . dist ? String ( argv . dist ) : 'dist'
38
+ const entryPoint = argv . entry ? String ( argv . entry ) : '/'
39
+ const extraPages = typeof argv . extra === 'string' ? argv . extra . split ( ',' ) : [ ]
20
40
21
- interface StaticOptions {
22
- port ?: number ;
23
- distFolder ?: string ;
24
- entryPoint ?: string ;
25
- extraPages ?: string [ ]
26
- }
27
-
28
- const renderPages = async ( { port = 54322 , distFolder = 'dist' , entryPoint = '/' , extraPages = [ ] } : StaticOptions ) => {
29
41
try {
30
42
31
43
// Spin up a static server to use for prerendering with pupeteer
@@ -157,4 +169,4 @@ const renderPages = async ({ port = 54322, distFolder = 'dist', entryPoint = '/'
157
169
process . exit ( 0 )
158
170
}
159
171
160
- renderPages ( { } )
172
+ export default renderPages
0 commit comments