@@ -124,54 +124,33 @@ async function create(name, options) {
124124 packageLockJson . name = name ;
125125 fs . writeFileSync ( path . join ( createPath , "package.json" ) , JSON . stringify ( packageJson , null , 2 ) ) ;
126126 fs . writeFileSync ( path . join ( createPath , "package-lock.json" ) , JSON . stringify ( packageLockJson , null , 2 ) ) ;
127- // download resources from cdn
128- spinner . update ( "Download resources" ) ;
129- outputDev ( "Download resources" ) ;
130- // download to createPath
131- const download = require ( 'download' ) ;
132- download ( { extract : true , strip : 1 } )
133- . get ( `https://cdn.fastjs.com.cn/fastjs-cli/template/${ projectTypeSuper } .zip` )
134- . dest ( createPath )
135- . run ( ( error ) => {
136- // check error
137- if ( error ) {
138- // check is 404
139- if ( error . statusCode !== 404 ) {
140- spinner . stop ( ) ;
141- outputDev ( error ) ;
142- outputDev ( "Program exit by error" ) ;
143- output ( "Download resources failed, retry after a while." , "red" ) ;
144- return
145- }
146- spinner . stop ( ) ;
147- outputDev ( "Download resources failed, 404" ) ;
148- output ( "Template not found, continue with vite template." , "yellow" ) ;
149- } else {
150- outputDev ( "Download resources success in " + createPath ) ;
151- // read createPath/cli-config.json
152- const cliConfig = require ( path . join ( createPath , "cli-config.json" ) ) ;
153- const deleteList = cliConfig . rm ;
154- // delete files
155- spinner . update ( "Deleting files" ) ;
156- outputDev ( "Deleting files" ) ;
157- deleteList . forEach ( ( item ) => {
158- fs . removeSync ( path . join ( createPath , item ) ) ;
159- } )
160- // delete cli-config.json
161- fs . removeSync ( path . join ( createPath , "cli-config.json" ) ) ;
162- spinner . stop ( ) ;
163- }
164- outputDev ( "Program create success in " + createPath ) ;
165- output ( `Project *blue*${ name } *blue* created in *blue*${ createPath } *blue*` ) ;
166- output ( "" )
167- output ( `Project create success in ${ Math . floor ( ( new Date ( ) . getTime ( ) - startTime ) / 1000 ) } s` ) ;
168- output ( "" )
169- output ( "To get started:" , "green" ) ;
170- output ( "- npm run dev" , "green" ) ;
171- } )
172- // continue by download callback
127+ // copy template
128+ spinner . update ( "Copy resources" ) ;
129+ outputDev ( "Copy resources" ) ;
130+ // copy ./template/projectTypeSuper to createPath
131+ fs . copySync ( path . join ( __dirname , ".." , "template" , projectTypeSuper ) , createPath ) ;
132+ outputDev ( "Copy resources success in " + createPath ) ;
133+ // read createPath/cli-config.json
134+ const cliConfig = require ( path . join ( createPath , "cli-config.json" ) ) ;
135+ const deleteList = cliConfig . rm ;
136+ // delete files
137+ spinner . update ( "Deleting files" ) ;
138+ outputDev ( "Deleting files" ) ;
139+ deleteList . forEach ( ( item ) => {
140+ fs . removeSync ( path . join ( createPath , item ) ) ;
141+ } )
142+ // delete cli-config.json
143+ fs . removeSync ( path . join ( createPath , "cli-config.json" ) ) ;
144+ spinner . stop ( ) ;
145+ outputDev ( "Program create success in " + createPath ) ;
146+ output ( `Project *blue*${ name } *blue* created in *blue*${ createPath } *blue*` ) ;
147+ output ( "" )
148+ output ( `Project create success in ${ Math . floor ( ( new Date ( ) . getTime ( ) - startTime ) / 1000 ) } s` ) ;
149+ output ( "" )
150+ output ( "To get started:" , "green" ) ;
151+ output ( "- npm run dev" , "green" ) ;
152+ output ( "" ) ;
173153 } )
174- // continue by installation callback
175154 } )
176155 // end by child_process
177156 // continue by child_process callback
0 commit comments