@@ -10,12 +10,13 @@ const s = prompts.spinner();
10
10
const brandColor = /** @type {const } */ ( [ 174 , 128 , 255 ] ) ;
11
11
12
12
( async function createPreact ( ) {
13
+ const args = process . argv . slice ( 2 ) ;
14
+
13
15
// Silences the 'Getting Started' info, mainly
14
16
// for use in other initializers that may wrap this
15
17
// one but provide their own scripts/instructions.
16
- //
17
- // Don't love the flag, need to find a better name.
18
- const skipHint = process . argv . slice ( 2 ) . includes ( '--skip-hints' ) ;
18
+ const skipHint = args . includes ( '--skip-hints' ) ;
19
+ const argDir = args . find ( ( arg ) => ! arg . startsWith ( '--' ) ) ;
19
20
const packageManager = getPkgManager ( ) ;
20
21
21
22
prompts . intro (
@@ -27,17 +28,19 @@ const brandColor = /** @type {const} */ ([174, 128, 255]);
27
28
const { dir, language, useRouter, usePrerender, useESLint } = await prompts . group (
28
29
{
29
30
dir : ( ) =>
30
- prompts . text ( {
31
- message : 'Project directory:' ,
32
- placeholder : 'my-preact-app' ,
33
- validate ( value ) {
34
- if ( value . length == 0 ) {
35
- return 'Directory name is required!' ;
36
- } else if ( existsSync ( value ) ) {
37
- return 'Refusing to overwrite existing directory or file! Please provide a non-clashing name.' ;
38
- }
39
- } ,
40
- } ) ,
31
+ argDir
32
+ ? Promise . resolve ( argDir )
33
+ : prompts . text ( {
34
+ message : 'Project directory:' ,
35
+ placeholder : 'my-preact-app' ,
36
+ validate ( value ) {
37
+ if ( value . length == 0 ) {
38
+ return 'Directory name is required!' ;
39
+ } else if ( existsSync ( value ) ) {
40
+ return 'Refusing to overwrite existing directory or file! Please provide a non-clashing name.' ;
41
+ }
42
+ } ,
43
+ } ) ,
41
44
language : ( ) =>
42
45
prompts . select ( {
43
46
message : 'Project language:' ,
@@ -226,7 +229,8 @@ async function installDeps(to, opts) {
226
229
if ( opts . useESLint ) devDependencies . push ( 'eslint' , 'eslint-config-preact' ) ;
227
230
228
231
await installPackages ( dependencies , { ...installOpts } ) ;
229
- devDependencies . length && await installPackages ( devDependencies , { ...installOpts , dev : true } ) ;
232
+ devDependencies . length &&
233
+ ( await installPackages ( devDependencies , { ...installOpts , dev : true } ) ) ;
230
234
}
231
235
232
236
/**
@@ -253,8 +257,8 @@ function installPackages(pkgs, opts) {
253
257
* @returns {'yarn' | 'pnpm' | 'npm' }
254
258
*/
255
259
function getPkgManager ( ) {
256
- const userAgent = process . env . npm_config_user_agent || ''
257
- if ( userAgent . startsWith ( 'yarn' ) ) return 'yarn'
258
- if ( userAgent . startsWith ( 'pnpm' ) ) return 'pnpm'
259
- return 'npm'
260
+ const userAgent = process . env . npm_config_user_agent || '' ;
261
+ if ( userAgent . startsWith ( 'yarn' ) ) return 'yarn' ;
262
+ if ( userAgent . startsWith ( 'pnpm' ) ) return 'pnpm' ;
263
+ return 'npm' ;
260
264
}
0 commit comments