Skip to content

Commit

Permalink
pass arguments to underlying CLIs
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Aug 23, 2023
1 parent 83e526b commit 0678e57
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .changeset/clever-cooks-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"create-cloudflare": patch
---

adjusted arguments passing so that arguments following an extra `--` are
passed to the underlying cli (if any)

For example:
```
$ npm create cloudflare -- --framework=X -- -a -b
```
now will run the framework X's cli with the `-a` and `-b` arguments
(such arguments will be completely ignored by C3)
9 changes: 7 additions & 2 deletions packages/create-cloudflare/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ const printBanner = () => {
startSection(`Create an application with Cloudflare`, "Step 1 of 3");
};

export const parseArgs = async (argv: string[]): Promise<Partial<C3Args>> => {
const args = await yargs(hideBin(argv))
const parseArgs = async (argv: string[]): Promise<Partial<C3Args>> => {
const doubleDashesIdx = argv.indexOf('--');
const c3Args = doubleDashesIdx < 0 ? argv : argv.slice(0, doubleDashesIdx < 0 ? undefined : doubleDashesIdx);
const additionalArgs = doubleDashesIdx < 0 ? [] : argv.slice(doubleDashesIdx + 1);

const args = await yargs(hideBin(c3Args))
.scriptName("create-cloudflare")
.usage("$0 [args]")
.positional("name", { type: "string" })
Expand Down Expand Up @@ -115,6 +119,7 @@ export const parseArgs = async (argv: string[]): Promise<Partial<C3Args>> => {
...(args.wranglerDefaults && WRANGLER_DEFAULTS),
...(args.acceptDefaults && C3_DEFAULTS),
projectName: args._[0] as string | undefined,
additionalArgs,
...args,
};
};
Expand Down
4 changes: 4 additions & 0 deletions packages/create-cloudflare/src/helpers/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ export const runFrameworkGenerator = async (
ctx: PagesGeneratorContext,
cmd: string
) => {
if(ctx.framework?.args?.length) {
cmd = `${cmd} ${ctx.framework.args.join(" ")}`;
}

endSection(
`Continue with ${ctx.framework?.config.displayName}`,
`via \`${cmd.trim()}\``
Expand Down
1 change: 1 addition & 0 deletions packages/create-cloudflare/src/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const runPagesGenerator = async (args: C3Args) => {
...defaultFrameworkConfig,
...frameworkConfig,
},
args: args.additionalArgs ?? [],
},
args,
type: frameworkConfig.type,
Expand Down
2 changes: 2 additions & 0 deletions packages/create-cloudflare/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type C3Args = {
existingScript?: string;
wranglerDefaults?: boolean;
acceptDefaults?: boolean;
additionalArgs?: string[];
};

export type C3Arg = C3Args[keyof C3Args];
Expand All @@ -29,6 +30,7 @@ export type PagesGeneratorContext = {
framework?: {
name: string;
config: FrameworkConfig;
args: string[];
commitMessage?: string;
};
project: {
Expand Down

0 comments on commit 0678e57

Please sign in to comment.