1
- import fs from ' fs-extra'
2
- import path from ' node:path'
3
- import options from ' ../../../core/utils/vue/options'
4
- import { ejsRender } from ' ../../../utils/ejsRender'
5
- import chalk from "chalk"
6
- import { templateFilesMap } from ' ../../../core/utils/vue/templateFile'
7
- import { getFilterFile } from ' ../../../filter/filterFiles'
8
- import { fileURLToPath } from ' node:url' ;
9
- import { dirname } from ' node:path' ;
10
- import ora from ' ora'
1
+ import fs from " fs-extra" ;
2
+ import path from " node:path" ;
3
+ import options from " ../../../core/utils/vue/options" ;
4
+ import { ejsRender } from " ../../../utils/ejsRender" ;
5
+ import pc from "picocolors" ;
6
+ import { templateFilesMap } from " ../../../core/utils/vue/templateFile" ;
7
+ import { getFilterFile } from " ../../../filter/filterFiles" ;
8
+ import { fileURLToPath } from " node:url" ;
9
+ import { dirname } from " node:path" ;
10
+ import ora from " ora" ;
11
11
12
12
async function copyTemplate ( ) {
13
- const __filename = fileURLToPath ( import . meta. url ) ;
13
+ const __filename = fileURLToPath ( import . meta. url ) ;
14
14
15
- const __dirname = dirname ( __filename ) ;
15
+ const __dirname = dirname ( __filename ) ;
16
16
17
- const spinner = ora ( ' Copying template...' ) . start ( ) ;
17
+ const spinner = ora ( " Copying template..." ) . start ( ) ;
18
18
19
- const language = options . useTypeScript ? ' vue-ts' : ' vue-js' ;
19
+ const language = options . useTypeScript ? " vue-ts" : " vue-js" ;
20
20
21
- options . src = path . resolve ( __dirname , `../template/${ language } ` ) ;
21
+ options . src = path . resolve ( __dirname , `../template/${ language } ` ) ;
22
22
23
- const dest = options . name && path . resolve ( process . cwd ( ) , options . name )
24
-
25
- options . dest = dest
23
+ const dest = options . name && path . resolve ( process . cwd ( ) , options . name ) ;
26
24
27
- const templatePath = path . resolve (
28
- __dirname ,
29
- `../../../../template/${ language } `
30
- ) ;
31
- options . templatePath = templatePath
25
+ options . dest = dest ;
32
26
33
- const filterFileFn = getFilterFile ( )
27
+ const templatePath = path . resolve (
28
+ __dirname ,
29
+ `../../../../template/${ language } ` ,
30
+ ) ;
31
+ options . templatePath = templatePath ;
34
32
35
- async function copy ( ) {
36
- const targetDirectory = path . resolve ( __dirname , '../' ) ;
37
- if ( ! dest ) {
38
- return ;
39
- } ;
40
- await fs . copy ( ` ${ targetDirectory } /template/ ${ language } ` , dest )
33
+ const filterFileFn = getFilterFile ( ) ;
34
+
35
+ async function copy ( ) {
36
+ const targetDirectory = path . resolve ( __dirname , "../" ) ;
37
+ if ( ! dest ) {
38
+ return ;
41
39
}
42
- await copy ( ) ;
43
-
44
- filterFileFn && await filterFileFn ( ) ;
45
-
46
- options . dest && await fs . move (
47
- path . resolve ( options . dest , '.gitignore.ejs' ) ,
48
- path . resolve ( options . dest , '.gitignore' ) ,
49
- { overwrite : true }
50
- ) ;
51
-
52
- await Promise . all (
53
- templateFilesMap
54
- . get ( 'vue' ) ( )
55
- . map ( ( file : string ) => options . name && ejsRender ( file , options . name ) )
56
- )
57
- spinner . text = chalk . green ( 'Template successfully copied!' ) ;
58
-
59
- spinner . succeed ( )
40
+ await fs . copy ( `${ targetDirectory } /template/${ language } ` , dest ) ;
41
+ }
42
+ await copy ( ) ;
43
+
44
+ filterFileFn && ( await filterFileFn ( ) ) ;
45
+
46
+ options . dest &&
47
+ ( await fs . move (
48
+ path . resolve ( options . dest , ".gitignore.ejs" ) ,
49
+ path . resolve ( options . dest , ".gitignore" ) ,
50
+ { overwrite : true } ,
51
+ ) ) ;
52
+
53
+ await Promise . all (
54
+ templateFilesMap
55
+ . get ( "vue" ) ( )
56
+ . map ( ( file : string ) => options . name && ejsRender ( file , options . name ) ) ,
57
+ ) ;
58
+ spinner . text = pc . green ( "Template successfully copied!" ) ;
59
+
60
+ spinner . succeed ( ) ;
60
61
}
61
- export default copyTemplate
62
+ export default copyTemplate ;
0 commit comments