@@ -24,23 +24,38 @@ const yaml = require('js-yaml');
2424const repoPath = path . resolve ( `${ __dirname } /..` ) ;
2525
2626// Command-line options.
27- const { source : sourceFile } = yargs
28- . option ( 'source ' , {
29- default : ` ${ repoPath } /src/{v1,logger}` ,
27+ const { api : apiVersion } = yargs
28+ . option ( 'api ' , {
29+ default : 'v1' ,
3030 describe : 'Typescript source file(s)' ,
3131 type : 'string' ,
3232 } )
3333 . version ( false )
3434 . help ( ) . argv ;
3535
36+ let sourceFile ;
37+ switch ( apiVersion ) {
38+ case 'v1' :
39+ sourceFile = `${ repoPath } /src/{v1,logger}` ;
40+ break ;
41+ case 'v2' :
42+ sourceFile = `${ repoPath } /src/{v2,logger}` ;
43+ break ;
44+ default :
45+ throw new Error (
46+ `Unrecognized version ${ apiVersion } , must be one of v1 or v2`
47+ ) ;
48+ }
49+
3650const docPath = path . resolve ( `${ __dirname } /html` ) ;
37- const contentPath = path . resolve ( `${ __dirname } /content-sources` ) ;
51+ const contentPath = path . resolve ( `${ __dirname } /content-sources/ ${ apiVersion } ` ) ;
3852const tempHomePath = path . resolve ( `${ contentPath } /HOME_TEMP.md` ) ;
3953const devsitePath = `/docs/reference/functions/` ;
4054
4155const { JSDOM } = require ( 'jsdom' ) ;
4256
4357const typeMap = require ( './type-aliases.json' ) ;
58+ const { existsSync } = require ( 'fs' ) ;
4459
4560/**
4661 * Strips path prefix and returns only filename.
@@ -72,8 +87,10 @@ function runTypedoc() {
7287 * @param {string } subdir Subdir to move files out of.
7388 */
7489async function moveFilesToRoot ( subdir ) {
75- await exec ( `mv ${ docPath } /${ subdir } /* ${ docPath } ` ) ;
76- await exec ( `rmdir ${ docPath } /${ subdir } ` ) ;
90+ if ( existsSync ( `${ docPath } /${ subdir } ` ) ) {
91+ await exec ( `mv ${ docPath } /${ subdir } /* ${ docPath } ` ) ;
92+ await exec ( `rmdir ${ docPath } /${ subdir } ` ) ;
93+ }
7794}
7895
7996/**
0 commit comments