@@ -14,24 +14,19 @@ import { setupGit } from './integrations/git.js'
14
14
15
15
import type { Environment , FileBundleHandler , Options } from './types.js'
16
16
17
- async function writeFiles (
18
- environment : Environment ,
19
- targetDir : string ,
20
- options : Options ,
21
- ) {
22
- const templateFileFromContent = createTemplateFile (
23
- environment ,
24
- options ,
25
- targetDir ,
26
- )
17
+ async function writeFiles ( environment : Environment , options : Options ) {
18
+ const templateFileFromContent = createTemplateFile ( environment , options )
27
19
28
20
async function writeFileBundle ( bundle : FileBundleHandler ) {
29
21
const files = await bundle . getFiles ( )
30
22
for ( const file of files ) {
31
23
const contents = await bundle . getFileContents ( file )
32
24
const binaryFile = getBinaryFile ( contents )
33
25
if ( binaryFile ) {
34
- await environment . writeFile ( resolve ( targetDir , file ) , binaryFile )
26
+ await environment . writeFile (
27
+ resolve ( options . targetDir , file ) ,
28
+ binaryFile ,
29
+ )
35
30
} else {
36
31
await templateFileFromContent ( file , contents )
37
32
}
@@ -55,32 +50,31 @@ async function writeFiles(
55
50
}
56
51
57
52
await environment . writeFile (
58
- resolve ( targetDir , './package.json' ) ,
53
+ resolve ( options . targetDir , './package.json' ) ,
59
54
JSON . stringify ( createPackageJSON ( options ) , null , 2 ) ,
60
55
)
61
56
62
- await writeConfigFile ( environment , targetDir , options )
57
+ await writeConfigFile ( environment , options . targetDir , options )
63
58
}
64
59
65
60
async function runCommandsAndInstallDependencies (
66
61
environment : Environment ,
67
- targetDir : string ,
68
62
options : Options ,
69
63
) {
70
64
const s = environment . spinner ( )
71
65
72
66
// Setup git
73
67
if ( options . git ) {
74
68
s . start ( `Initializing git repository...` )
75
- await setupGit ( environment , targetDir )
69
+ await setupGit ( environment , options . targetDir )
76
70
s . stop ( `Initialized git repository` )
77
71
}
78
72
79
73
// Install dependencies
80
74
s . start ( `Installing dependencies via ${ options . packageManager } ...` )
81
75
await packageManagerInstall (
82
76
environment ,
83
- resolve ( targetDir ) ,
77
+ options . targetDir ,
84
78
options . packageManager ,
85
79
)
86
80
s . stop ( `Installed dependencies` )
@@ -94,7 +88,7 @@ async function runCommandsAndInstallDependencies(
94
88
await environment . execute (
95
89
addOn . command ! . command ,
96
90
addOn . command ! . args || [ ] ,
97
- resolve ( targetDir ) ,
91
+ options . targetDir ,
98
92
)
99
93
s . stop ( `${ addOn . name } setup complete` )
100
94
}
@@ -110,15 +104,15 @@ async function runCommandsAndInstallDependencies(
110
104
await environment . execute (
111
105
options . starter . command . command ,
112
106
options . starter . command . args || [ ] ,
113
- resolve ( targetDir ) ,
107
+ options . targetDir ,
114
108
)
115
109
s . stop ( `Starter ${ options . starter . name } setup complete` )
116
110
}
117
111
118
- await installShadcnComponents ( environment , targetDir , options )
112
+ await installShadcnComponents ( environment , options . targetDir , options )
119
113
}
120
114
121
- function report ( environment : Environment , options : Options , targetDir : string ) {
115
+ function report ( environment : Environment , options : Options ) {
122
116
const warnings : Array < string > = [ ]
123
117
for ( const addOn of options . chosenAddOns ) {
124
118
if ( addOn . warning ) {
@@ -140,35 +134,24 @@ Errors were encountered during this process:
140
134
${ environment . getErrors ( ) . join ( '\n' ) } `
141
135
}
142
136
143
- environment . outro ( `Your ${ environment . appName } app is ready in '${ basename ( targetDir ) } '.
137
+ environment . outro (
138
+ `Your ${ environment . appName } app is ready in '${ basename ( options . targetDir ) } '.
144
139
145
140
Use the following commands to start your app:
146
141
% cd ${ options . projectName }
147
142
% ${ formatCommand (
148
- getPackageManagerScriptCommand ( options . packageManager , [ 'dev' ] ) ,
149
- ) }
143
+ getPackageManagerScriptCommand ( options . packageManager , [ 'dev' ] ) ,
144
+ ) }
150
145
151
- Please check the README.md for more information on testing, styling, adding routes, etc.${ errorStatement } ` )
146
+ Please check the README.md for more information on testing, styling, adding routes, etc.${ errorStatement } ` ,
147
+ )
152
148
}
153
149
154
- export async function createApp (
155
- environment : Environment ,
156
- options : Options ,
157
- {
158
- cwd,
159
- } : {
160
- cwd ?: string
161
- } = { } ,
162
- ) {
150
+ export async function createApp ( environment : Environment , options : Options ) {
163
151
environment . startRun ( )
164
-
165
- const targetDir : string = cwd || resolve ( process . cwd ( ) , options . projectName )
166
-
167
- await writeFiles ( environment , targetDir , options )
168
-
169
- await runCommandsAndInstallDependencies ( environment , targetDir , options )
170
-
152
+ await writeFiles ( environment , options )
153
+ await runCommandsAndInstallDependencies ( environment , options )
171
154
environment . finishRun ( )
172
155
173
- report ( environment , options , targetDir )
156
+ report ( environment , options )
174
157
}
0 commit comments