@@ -26,67 +26,60 @@ export default defineCommand({
2626
2727 const cwd = resolve ( ctx . args . cwd || ctx . args . rootDir )
2828
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
4932 resolveModulePath ( 'typescript' , { try : true } ) ,
5033 resolveModulePath ( 'vue-tsc/bin/vue-tsc.js' , { try : true } ) ,
34+ writeTypes ( cwd , ctx . args . dotenv , ctx . args . logLevel as 'silent' | 'info' | 'verbose' ) ,
5135 ] )
36+
37+ const typeCheckArgs = supportsProjects ? [ '-b' , '--noEmit' ] : [ '--noEmit' ]
5238 if ( resolvedTypeScript && resolvedVueTsc ) {
53- await x ( resolvedVueTsc , typeCheckArgs , {
39+ return await x ( resolvedVueTsc , typeCheckArgs , {
5440 throwOnError : true ,
5541 nodeOptions : {
5642 stdio : 'inherit' ,
5743 cwd,
5844 } ,
5945 } )
6046 }
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- )
7147
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+ } )
9061 }
62+
63+ await x ( 'npx' , [ '-p' , 'vue-tsc' , '-p' , 'typescript' , 'vue-tsc' , ...typeCheckArgs ] , {
64+ throwOnError : true ,
65+ nodeOptions : { stdio : 'inherit' , cwd } ,
66+ } )
9167 } ,
9268} )
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