@@ -26,67 +26,60 @@ export default defineCommand({
26
26
27
27
const cwd = resolve ( ctx . args . cwd || ctx . args . rootDir )
28
28
29
- const { loadNuxt, buildNuxt, writeTypes } = await loadKit ( cwd )
30
- const nuxt = await loadNuxt ( {
31
- cwd,
32
- dotenv : { cwd, fileName : ctx . args . dotenv } ,
33
- overrides : {
34
- _prepare : true ,
35
- logLevel : ctx . args . logLevel as 'silent' | 'info' | 'verbose' ,
36
- } ,
37
- } )
38
-
39
- // Generate types and build Nuxt instance
40
- await writeTypes ( nuxt )
41
- await buildNuxt ( nuxt )
42
- await nuxt . close ( )
43
-
44
- const supportsProjects = await readTSConfig ( cwd ) . then ( r => ! ! ( r . references ?. length ) )
45
- const typeCheckArgs = supportsProjects ? [ '-b' , '--noEmit' ] : [ '--noEmit' ]
46
-
47
- // Prefer local install if possible
48
- const [ resolvedTypeScript , resolvedVueTsc ] = await Promise . all ( [
29
+ const [ supportsProjects , resolvedTypeScript , resolvedVueTsc ] = await Promise . all ( [
30
+ readTSConfig ( cwd ) . then ( r => ! ! ( r . references ?. length ) ) ,
31
+ // Prefer local install if possible
49
32
resolveModulePath ( 'typescript' , { try : true } ) ,
50
33
resolveModulePath ( 'vue-tsc/bin/vue-tsc.js' , { try : true } ) ,
34
+ writeTypes ( cwd , ctx . args . dotenv , ctx . args . logLevel as 'silent' | 'info' | 'verbose' ) ,
51
35
] )
36
+
37
+ const typeCheckArgs = supportsProjects ? [ '-b' , '--noEmit' ] : [ '--noEmit' ]
52
38
if ( resolvedTypeScript && resolvedVueTsc ) {
53
- await x ( resolvedVueTsc , typeCheckArgs , {
39
+ return await x ( resolvedVueTsc , typeCheckArgs , {
54
40
throwOnError : true ,
55
41
nodeOptions : {
56
42
stdio : 'inherit' ,
57
43
cwd,
58
44
} ,
59
45
} )
60
46
}
61
- else {
62
- if ( isBun ) {
63
- await x (
64
- 'bun' ,
65
- 'install typescript vue-tsc --global --silent' . split ( ' ' ) ,
66
- {
67
- throwOnError : true ,
68
- nodeOptions : { stdio : 'inherit' , cwd } ,
69
- } ,
70
- )
71
47
72
- await x ( 'bunx' , [ 'vue-tsc' , ...typeCheckArgs ] , {
73
- throwOnError : true ,
74
- nodeOptions : {
75
- stdio : 'inherit' ,
76
- cwd,
77
- } ,
78
- } )
79
- }
80
- else {
81
- await x (
82
- 'npx' ,
83
- [ '-p' , 'vue-tsc' , '-p' , 'typescript' , 'vue-tsc' , ...typeCheckArgs ] ,
84
- {
85
- throwOnError : true ,
86
- nodeOptions : { stdio : 'inherit' , cwd } ,
87
- } ,
88
- )
89
- }
48
+ if ( isBun ) {
49
+ await x ( 'bun' , [ 'install' , 'typescript' , 'vue-tsc' , '--global' , '--silent' ] , {
50
+ throwOnError : true ,
51
+ nodeOptions : { stdio : 'inherit' , cwd } ,
52
+ } )
53
+
54
+ return await x ( 'bunx' , [ 'vue-tsc' , ...typeCheckArgs ] , {
55
+ throwOnError : true ,
56
+ nodeOptions : {
57
+ stdio : 'inherit' ,
58
+ cwd,
59
+ } ,
60
+ } )
90
61
}
62
+
63
+ await x ( 'npx' , [ '-p' , 'vue-tsc' , '-p' , 'typescript' , 'vue-tsc' , ...typeCheckArgs ] , {
64
+ throwOnError : true ,
65
+ nodeOptions : { stdio : 'inherit' , cwd } ,
66
+ } )
91
67
} ,
92
68
} )
69
+
70
+ async function writeTypes ( cwd : string , dotenv ?: string , logLevel ?: 'silent' | 'info' | 'verbose' ) {
71
+ const { loadNuxt, buildNuxt, writeTypes } = await loadKit ( cwd )
72
+ const nuxt = await loadNuxt ( {
73
+ cwd,
74
+ dotenv : { cwd, fileName : dotenv } ,
75
+ overrides : {
76
+ _prepare : true ,
77
+ logLevel,
78
+ } ,
79
+ } )
80
+
81
+ // Generate types and build Nuxt instance
82
+ await writeTypes ( nuxt )
83
+ await buildNuxt ( nuxt )
84
+ await nuxt . close ( )
85
+ }
0 commit comments