@@ -11,42 +11,18 @@ import {
11
11
import { createPackageJSON } from './package-json.js'
12
12
import { createTemplateFile } from './template-file.js'
13
13
import { installShadcnComponents } from './integrations/shadcn.js'
14
-
14
+ import { setupGit } from './integrations/git.js'
15
15
import type {
16
16
Environment ,
17
17
FileBundleHandler ,
18
18
Options ,
19
19
} from '@tanstack/cta-core'
20
20
21
- export async function createApp (
21
+ async function writeFiles (
22
+ environment : Environment ,
23
+ targetDir : string ,
22
24
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
- } ,
35
25
) {
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
-
50
26
const templateFileFromContent = createTemplateFile (
51
27
environment ,
52
28
options ,
@@ -66,8 +42,6 @@ export async function createApp(
66
42
}
67
43
}
68
44
69
- // Write the project files
70
-
71
45
await writeFileBundle ( options . framework )
72
46
73
47
for ( const type of [ 'add-on' , 'example' , 'toolchain' ] ) {
@@ -90,10 +64,31 @@ export async function createApp(
90
64
)
91
65
92
66
await writeConfigFile ( environment , targetDir , options )
67
+ }
93
68
69
+ async function runCommandsAndInstallDependencies (
70
+ environment : Environment ,
71
+ targetDir : string ,
72
+ options : Options ,
73
+ silent : boolean ,
74
+ ) {
94
75
const s = silent ? null : environment . spinner ( )
95
76
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` )
97
92
98
93
for ( const phase of [ 'setup' , 'add-on' , 'example' ] ) {
99
94
for ( const addOn of options . chosenAddOns . filter (
@@ -125,29 +120,7 @@ export async function createApp(
125
120
s ?. stop ( `Starter ${ options . starter . name } setup complete` )
126
121
}
127
122
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
-
144
123
await installShadcnComponents ( environment , targetDir , options , silent )
145
-
146
- environment . finishRun ( )
147
-
148
- if ( ! silent ) {
149
- report ( environment , options , appName , targetDir )
150
- }
151
124
}
152
125
153
126
function report (
@@ -192,3 +165,48 @@ Use the following commands to start your app:
192
165
193
166
Please check the README.md for more information on testing, styling, adding routes, etc.${ errorStatement } ` )
194
167
}
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