create-hsi-app 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/create-hsi-app.mjs +68 -23
- package/package.json +1 -1
package/bin/create-hsi-app.mjs
CHANGED
|
@@ -12,15 +12,18 @@ import { stdin as input, stdout as output } from 'node:process';
|
|
|
12
12
|
import readline from 'node:readline/promises';
|
|
13
13
|
|
|
14
14
|
const templateRepo = 'https://github.com/Hsiii/frontend-template.git';
|
|
15
|
-
const templateTag = 'v0.5.
|
|
15
|
+
const templateTag = 'v0.5.2';
|
|
16
16
|
const defaultAppName = 'my-app';
|
|
17
17
|
const packageManagers = ['bun', 'npm', 'pnpm', 'yarn'];
|
|
18
18
|
const rawArgs = process.argv.slice(2);
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
19
|
+
const parsedArgs = parseCliArgs(rawArgs);
|
|
20
|
+
const selectedPackageManager = resolvePackageManager(parsedArgs);
|
|
21
|
+
const shouldInstallDependencies = !(
|
|
22
|
+
parsedArgs.noInstall || readNpmBooleanFlag('noinstall')
|
|
23
|
+
);
|
|
24
|
+
const shouldSkipRepoSetup = parsedArgs.noRepo || readNpmBooleanFlag('norepo');
|
|
22
25
|
const isInteractive = input.isTTY && output.isTTY;
|
|
23
|
-
const targetArg =
|
|
26
|
+
const targetArg = parsedArgs.targetArg ?? '.';
|
|
24
27
|
const targetPath = resolve(targetArg);
|
|
25
28
|
const appName = toPackageName(basename(targetPath));
|
|
26
29
|
|
|
@@ -111,6 +114,7 @@ function updatePackageJson() {
|
|
|
111
114
|
delete packageJson.publishConfig;
|
|
112
115
|
delete packageJson.packageManager;
|
|
113
116
|
delete packageJson.engines;
|
|
117
|
+
delete packageJson.scripts.prepare;
|
|
114
118
|
delete packageJson.scripts.release;
|
|
115
119
|
packageJson.scripts.check =
|
|
116
120
|
'tsc -p tsconfig.json --noEmit && eslint . && prettier . --check && vite build';
|
|
@@ -385,28 +389,69 @@ function toPackageName(value) {
|
|
|
385
389
|
return name || defaultAppName;
|
|
386
390
|
}
|
|
387
391
|
|
|
388
|
-
function
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
+
function parseCliArgs(args) {
|
|
393
|
+
const parsedArgs = {
|
|
394
|
+
noInstall: false,
|
|
395
|
+
noRepo: false,
|
|
396
|
+
packageManager: null,
|
|
397
|
+
targetArg: null,
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
for (const arg of args) {
|
|
401
|
+
switch (arg) {
|
|
402
|
+
case '--bun':
|
|
403
|
+
setPackageManagerOverride(parsedArgs, 'bun');
|
|
404
|
+
continue;
|
|
405
|
+
case '--npm':
|
|
406
|
+
setPackageManagerOverride(parsedArgs, 'npm');
|
|
407
|
+
continue;
|
|
408
|
+
case '--pnpm':
|
|
409
|
+
setPackageManagerOverride(parsedArgs, 'pnpm');
|
|
410
|
+
continue;
|
|
411
|
+
case '--yarn':
|
|
412
|
+
setPackageManagerOverride(parsedArgs, 'yarn');
|
|
413
|
+
continue;
|
|
414
|
+
case '--noInstall':
|
|
415
|
+
parsedArgs.noInstall = true;
|
|
416
|
+
continue;
|
|
417
|
+
case '--noRepo':
|
|
418
|
+
parsedArgs.noRepo = true;
|
|
419
|
+
continue;
|
|
420
|
+
default:
|
|
421
|
+
if (arg.startsWith('--')) {
|
|
422
|
+
fail(`Unsupported option: ${arg}`);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (parsedArgs.targetArg) {
|
|
426
|
+
fail(`Unexpected argument: ${arg}`);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
parsedArgs.targetArg = arg;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
392
432
|
|
|
393
|
-
|
|
433
|
+
return parsedArgs;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function setPackageManagerOverride(parsedArgs, packageManager) {
|
|
437
|
+
if (
|
|
438
|
+
parsedArgs.packageManager &&
|
|
439
|
+
parsedArgs.packageManager !== packageManager
|
|
440
|
+
) {
|
|
394
441
|
fail('Pass only one of --bun, --npm, --pnpm, or --yarn.');
|
|
395
442
|
}
|
|
396
443
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
fail(`Unsupported package manager flag: ${selectedFlags[0]}`);
|
|
409
|
-
}
|
|
444
|
+
parsedArgs.packageManager = packageManager;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function resolvePackageManager(parsedArgs) {
|
|
448
|
+
return parsedArgs.packageManager ?? 'bun';
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function readNpmBooleanFlag(name) {
|
|
452
|
+
const value = process.env[`npm_config_${name}`];
|
|
453
|
+
|
|
454
|
+
return value === 'true' || value === '';
|
|
410
455
|
}
|
|
411
456
|
|
|
412
457
|
function packageManagerDeclaration() {
|