33 * - test different package managers
44 * - think about npm < 6
55 * - get notified if any framework files change
6+ * - exit properly anytime
67 */
78
89import { spawn } from 'child_process'
@@ -137,12 +138,6 @@ async function main() {
137138 return
138139 }
139140
140- const isTs = [ 'nuxt' ] . indexOf ( framework ) !== - 1 || ts
141- const isBuilder = builder === 'builder'
142- const isTailwind = [ 'tailwind' , 'tailwind-material' ] . indexOf ( theme ) !== - 1
143- const isBootstrap = [ 'bootstrap' ] . indexOf ( theme ) !== - 1
144- const isAstro = framework === 'astro'
145-
146141 /**
147142 * Enter project folder
148143 */
@@ -155,6 +150,17 @@ async function main() {
155150 console . log ( 'Running npm install...' )
156151 await runCommand ( 'npm' , [ 'install' ] )
157152
153+ /**
154+ * Variables
155+ */
156+ const isAstro = framework === 'astro'
157+ const isTs = await isTypescript ( process . cwd ( ) , framework , ts )
158+ const isBuilder = builder === 'builder'
159+ const isTailwind = [ 'tailwind' , 'tailwind-material' ] . indexOf ( theme ) !== - 1
160+ const isBootstrap = [ 'bootstrap' ] . indexOf ( theme ) !== - 1
161+ const sourcePath = path . join ( __dirname , 'files' , builder , framework , theme , isTs ? 'ts' : 'js' )
162+ const targetPath = process . cwd ( )
163+
158164 /**
159165 * Install Tailwind
160166 */
@@ -175,11 +181,15 @@ async function main() {
175181 }
176182
177183 /**
178- * Install Vue in Astro
184+ * Astro updates
179185 */
180186 if ( isAstro ) {
187+ // Install Vue in Astro
181188 console . log ( 'Installing Vue...' )
182189 await runCommand ( 'npm' , [ 'install' , 'vue' , '@astrojs/vue' ] )
190+
191+ // Extend tsconfig.json
192+ await updateAstroTsConfig ( process . cwd ( ) )
183193 }
184194
185195 /**
@@ -196,8 +206,6 @@ async function main() {
196206 * Copy Vueform files to project directory
197207 */
198208 console . log ( `Copying additional files to ${ projectName } ...` )
199- const sourcePath = path . join ( __dirname , 'files' , builder , framework , theme , isTs ? 'ts' : 'js' )
200- const targetPath = process . cwd ( )
201209 await copyFilesToProject ( sourcePath , targetPath )
202210
203211 console . log ( '' )
@@ -256,6 +264,46 @@ async function directoryExists(path) {
256264 }
257265}
258266
267+ async function isTypescript ( dir , framework , ts ) {
268+ switch ( framework ) {
269+ case 'nuxt' :
270+ return true
271+ break
272+
273+ case 'astro' :
274+ const tsConfigPath = path . join ( dir , 'tsconfig.json' )
275+
276+ try {
277+ const tsConfig = await fsExtra . readJson ( tsConfigPath )
278+
279+ return tsConfig . extends !== 'astro/tsconfigs/base'
280+ } catch ( err ) {
281+ console . error ( 'Error reading tsconfig.json:' , err )
282+ }
283+ break
284+
285+ default :
286+ return ts
287+ }
288+ }
289+
290+ async function updateAstroTsConfig ( dir ) {
291+ const tsConfigPath = path . join ( dir , 'tsconfig.json' )
292+
293+ try {
294+ const tsConfig = await fsExtra . readJson ( tsConfigPath )
295+
296+ tsConfig . compilerOptions = {
297+ 'jsx' : 'preserve'
298+ }
299+
300+ await fsExtra . writeJson ( tsConfigPath , tsConfig , { spaces : 2 } )
301+ console . log ( 'tsconfig.json has been updated' )
302+ } catch ( err ) {
303+ console . error ( 'Error updating tsconfig.json:' , err )
304+ }
305+ }
306+
259307async function copyFilesToProject ( sourceDir , targetDir ) {
260308 try {
261309 await fsExtra . copy ( sourceDir , targetDir , { overwrite : true } )
0 commit comments