@@ -11,42 +11,18 @@ import {
1111import { createPackageJSON } from './package-json.js'
1212import { createTemplateFile } from './template-file.js'
1313import { installShadcnComponents } from './integrations/shadcn.js'
14-
14+ import { setupGit } from './integrations/git.js'
1515import type {
1616 Environment ,
1717 FileBundleHandler ,
1818 Options ,
1919} from '@tanstack/cta-core'
2020
21- export async function createApp (
21+ async function writeFiles (
22+ environment : Environment ,
23+ targetDir : string ,
2224 options : Options ,
23- {
24- silent = false ,
25- environment,
26- cwd,
27- appName = 'TanStack' ,
28- } : {
29- silent ?: boolean
30- environment : Environment
31- cwd ?: string
32- name ?: string
33- appName ?: string
34- } ,
3525) {
36- environment . startRun ( )
37-
38- let targetDir : string = cwd || ''
39- if ( ! targetDir . length ) {
40- targetDir = resolve ( process . cwd ( ) , options . projectName )
41-
42- if ( environment . exists ( targetDir ) ) {
43- if ( ! silent ) {
44- environment . error ( `Directory "${ options . projectName } " already exists` )
45- }
46- return
47- }
48- }
49-
5026 const templateFileFromContent = createTemplateFile (
5127 environment ,
5228 options ,
@@ -66,8 +42,6 @@ export async function createApp(
6642 }
6743 }
6844
69- // Write the project files
70-
7145 await writeFileBundle ( options . framework )
7246
7347 for ( const type of [ 'add-on' , 'example' , 'toolchain' ] ) {
@@ -90,10 +64,31 @@ export async function createApp(
9064 )
9165
9266 await writeConfigFile ( environment , targetDir , options )
67+ }
9368
69+ async function runCommandsAndInstallDependencies (
70+ environment : Environment ,
71+ targetDir : string ,
72+ options : Options ,
73+ silent : boolean ,
74+ ) {
9475 const s = silent ? null : environment . spinner ( )
9576
96- // Install all the dependencies
77+ // Setup git
78+ if ( options . git ) {
79+ s ?. start ( `Initializing git repository...` )
80+ await setupGit ( environment , targetDir )
81+ s ?. stop ( `Initialized git repository` )
82+ }
83+
84+ // Install dependencies
85+ s ?. start ( `Installing dependencies via ${ options . packageManager } ...` )
86+ await packageManagerInstall (
87+ environment ,
88+ resolve ( targetDir ) ,
89+ options . packageManager ,
90+ )
91+ s ?. stop ( `Installed dependencies` )
9792
9893 for ( const phase of [ 'setup' , 'add-on' , 'example' ] ) {
9994 for ( const addOn of options . chosenAddOns . filter (
@@ -125,29 +120,7 @@ export async function createApp(
125120 s ?. stop ( `Starter ${ options . starter . name } setup complete` )
126121 }
127122
128- // Setup git
129- if ( options . git ) {
130- s ?. start ( `Initializing git repository...` )
131- await environment . execute ( 'git' , [ 'init' ] , resolve ( targetDir ) )
132- s ?. stop ( `Initialized git repository` )
133- }
134-
135- // Install dependencies
136- s ?. start ( `Installing dependencies via ${ options . packageManager } ...` )
137- await packageManagerInstall (
138- environment ,
139- resolve ( targetDir ) ,
140- options . packageManager ,
141- )
142- s ?. stop ( `Installed dependencies` )
143-
144123 await installShadcnComponents ( environment , targetDir , options , silent )
145-
146- environment . finishRun ( )
147-
148- if ( ! silent ) {
149- report ( environment , options , appName , targetDir )
150- }
151124}
152125
153126function report (
@@ -192,3 +165,48 @@ Use the following commands to start your app:
192165
193166 Please check the README.md for more information on testing, styling, adding routes, etc.${ errorStatement } ` )
194167}
168+
169+ export async function createApp (
170+ options : Options ,
171+ {
172+ silent = false ,
173+ environment,
174+ cwd,
175+ appName = 'TanStack' ,
176+ } : {
177+ silent ?: boolean
178+ environment : Environment
179+ cwd ?: string
180+ name ?: string
181+ appName ?: string
182+ } ,
183+ ) {
184+ environment . startRun ( )
185+
186+ let targetDir : string = cwd || ''
187+ if ( ! targetDir . length ) {
188+ targetDir = resolve ( process . cwd ( ) , options . projectName )
189+
190+ if ( environment . exists ( targetDir ) ) {
191+ if ( ! silent ) {
192+ environment . error ( `Directory "${ options . projectName } " already exists` )
193+ }
194+ return
195+ }
196+ }
197+
198+ await writeFiles ( environment , targetDir , options )
199+
200+ await runCommandsAndInstallDependencies (
201+ environment ,
202+ targetDir ,
203+ options ,
204+ silent ,
205+ )
206+
207+ environment . finishRun ( )
208+
209+ if ( ! silent ) {
210+ report ( environment , options , appName , targetDir )
211+ }
212+ }
0 commit comments