aboutsummaryrefslogtreecommitdiff
path: root/packages/create-astro/src
diff options
context:
space:
mode:
authorGravatar Bjorn Lu <bjornlu.dev@gmail.com> 2024-08-16 00:27:08 +0800
committerGravatar GitHub <noreply@github.com> 2024-08-16 00:27:08 +0800
commit391324df969db71d1c7ca25c2ed14c9eb6eea5ee (patch)
tree01d2df4b490051bc3e6ac65d077e7a6ef8cf1d3f /packages/create-astro/src
parent91d36fa36bc8c5ca3e27c72b85399d1eb150c872 (diff)
downloadastro-391324df969db71d1c7ca25c2ed14c9eb6eea5ee.tar.gz
astro-391324df969db71d1c7ca25c2ed14c9eb6eea5ee.tar.zst
astro-391324df969db71d1c7ca25c2ed14c9eb6eea5ee.zip
Revert parseArgs change (#11733)
Diffstat (limited to 'packages/create-astro/src')
-rw-r--r--packages/create-astro/src/actions/context.ts91
1 files changed, 39 insertions, 52 deletions
diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts
index bf1b522bd..83a13eda7 100644
--- a/packages/create-astro/src/actions/context.ts
+++ b/packages/create-astro/src/actions/context.ts
@@ -1,7 +1,7 @@
import os from 'node:os';
-import { parseArgs } from 'node:util';
import { type Task, prompt } from '@astrojs/cli-kit';
import { random } from '@astrojs/cli-kit/utils';
+import arg from 'arg';
import getSeasonalData from '../data/seasonal.js';
import { getName, getVersion } from '../messages.js';
@@ -33,44 +33,47 @@ export interface Context {
}
export async function getContext(argv: string[]): Promise<Context> {
- const args = parseArgs({
- args: argv,
- allowPositionals: true,
- strict: false,
- options: {
- template: { type: 'string' },
- ref: { type: 'string' },
- yes: { type: 'boolean', short: 'y' },
- no: { type: 'boolean', short: 'n' },
- install: { type: 'boolean' },
- 'no-install': { type: 'boolean' },
- git: { type: 'boolean' },
- 'no-git': { type: 'boolean' },
- typescript: { type: 'string' },
- 'skip-houston': { type: 'boolean' },
- 'dry-run': { type: 'boolean' },
- help: { type: 'boolean', short: 'h' },
- fancy: { type: 'boolean' },
+ const flags = arg(
+ {
+ '--template': String,
+ '--ref': String,
+ '--yes': Boolean,
+ '--no': Boolean,
+ '--install': Boolean,
+ '--no-install': Boolean,
+ '--git': Boolean,
+ '--no-git': Boolean,
+ '--typescript': String,
+ '--skip-houston': Boolean,
+ '--dry-run': Boolean,
+ '--help': Boolean,
+ '--fancy': Boolean,
+
+ '-y': '--yes',
+ '-n': '--no',
+ '-h': '--help',
},
- });
+ { argv, permissive: true },
+ );
const packageManager = detectPackageManager() ?? 'npm';
- const projectName = args.positionals[0];
+ let cwd = flags['_'][0];
let {
- help,
- template,
- no,
- yes,
- install,
- 'no-install': noInstall,
- git,
- 'no-git': noGit,
- typescript,
- fancy,
- 'skip-houston': skipHouston,
- 'dry-run': dryRun,
- ref,
- } = args.values;
+ '--help': help = false,
+ '--template': template,
+ '--no': no,
+ '--yes': yes,
+ '--install': install,
+ '--no-install': noInstall,
+ '--git': git,
+ '--no-git': noGit,
+ '--typescript': typescript,
+ '--fancy': fancy,
+ '--skip-houston': skipHouston,
+ '--dry-run': dryRun,
+ '--ref': ref,
+ } = flags;
+ let projectName = cwd;
if (no) {
yes = false;
@@ -79,26 +82,10 @@ export async function getContext(argv: string[]): Promise<Context> {
if (typescript == undefined) typescript = 'strict';
}
- skipHouston = typeof skipHouston == 'boolean' ? skipHouston : undefined;
skipHouston =
((os.platform() === 'win32' && !fancy) || skipHouston) ??
[yes, no, install, git, typescript].some((v) => v !== undefined);
- // We use `strict: false` in `parseArgs` to allow unknown options, but Node also
- // simply doesn't guarantee the types anymore, so we need to validate ourselves :(
- help = !!help;
- template = typeof template == 'string' ? template : undefined;
- no = !!no;
- yes = !!yes;
- install = !!install;
- noInstall = !!noInstall;
- git = !!git;
- noGit = !!noGit;
- typescript = typeof typescript == 'string' ? typescript : undefined;
- fancy = !!fancy;
- dryRun = !!dryRun;
- ref = typeof ref == 'string' ? ref : undefined;
-
const { messages, hats, ties } = getSeasonalData({ fancy });
const context: Context = {
@@ -120,7 +107,7 @@ export async function getContext(argv: string[]): Promise<Context> {
install: install ?? (noInstall ? false : undefined),
git: git ?? (noGit ? false : undefined),
typescript,
- cwd: projectName,
+ cwd,
exit(code) {
process.exit(code);
},