33import { promises as fs } from "fs" ;
44import path from "path" ;
55
6+ import opn from "open" ;
67import yargs from "yargs" ;
78import { hideBin } from "yargs/helpers" ;
89
@@ -34,6 +35,12 @@ const argv = yargs(hideBin(process.argv))
3435 type : "boolean" ,
3536 default : false ,
3637 } )
38+ . option ( "open" , {
39+ describe : "Open generated tempate in default user agent" ,
40+ type : "boolean" ,
41+ default : false ,
42+ } )
43+ . strict ( )
3744 . help ( )
3845 . parseSync ( ) ;
3946
@@ -44,9 +51,10 @@ interface CliArgs {
4451 title: string ;
4552 template: TemplateType ;
4653 sourcemap: boolean ;
54+ open: boolean ;
4755}
4856
49- const runForPluginJson = async ( { title, template, filename } : CliArgs , files : string [ ] ) => {
57+ const runForPluginJson = async ( { title, template, filename, open } : CliArgs , files : string [ ] ) => {
5058 if ( files . length === 0 ) {
5159 throw new Error ( "Empty file list" ) ;
5260 }
@@ -57,7 +65,7 @@ const runForPluginJson = async ({ title, template, filename }: CliArgs, files: s
5765 const data = JSON . parse ( textContent ) as VisualizerData ;
5866
5967 return { file, data } ;
60- } )
68+ } ) ,
6169 ) ;
6270
6371 const tree : ModuleTree = {
@@ -70,7 +78,7 @@ const runForPluginJson = async ({ title, template, filename }: CliArgs, files: s
7078 for ( const { file, data } of fileContents ) {
7179 if ( data . version !== version ) {
7280 warn (
73- `Version in ${ file } is not supported (${ data . version } ). Current version ${ version } . Skipping...`
81+ `Version in ${ file } is not supported (${ data . version } ). Current version ${ version } . Skipping...` ,
7482 ) ;
7583 continue ;
7684 }
@@ -106,6 +114,10 @@ const runForPluginJson = async ({ title, template, filename }: CliArgs, files: s
106114 // ignore
107115 }
108116 await fs . writeFile ( filename , fileContent ) ;
117+
118+ if ( open ) {
119+ await opn ( filename ) ;
120+ }
109121} ;
110122
111123runForPluginJson ( argv , listOfFiles as string [ ] ) . catch ( ( err : Error ) => {
0 commit comments