create-cloudflare 0.0.0-d199ffbc → 0.0.0-d208ede3

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/dist/cli.js CHANGED
@@ -52612,7 +52612,9 @@ var require_typescript2 = __commonJS({
52612
52612
  // src/cli.ts
52613
52613
  var cli_exports = {};
52614
52614
  __export(cli_exports, {
52615
- main: () => main
52615
+ C3_DEFAULTS: () => C3_DEFAULTS,
52616
+ main: () => main,
52617
+ parseArgs: () => parseArgs
52616
52618
  });
52617
52619
  module.exports = __toCommonJS(cli_exports);
52618
52620
  var import_haikunator = __toESM(require_dist_node());
@@ -53150,11 +53152,9 @@ var status = {
53150
53152
  success: bgRed(` SUCCESS `)
53151
53153
  };
53152
53154
  var space = (n = 1) => {
53153
- return [...Array(n)].map(() => hidden("-")).join("");
53155
+ return hidden("\u200A".repeat(n));
53154
53156
  };
53155
53157
  var logRaw = (msg) => {
53156
- if (process.env.VITEST)
53157
- return;
53158
53158
  process.stdout.write(`${msg}
53159
53159
  `);
53160
53160
  };
@@ -54347,175 +54347,169 @@ var logUpdateStderr = createLogUpdate(import_node_process6.default.stderr);
54347
54347
  var grayBar = gray(shapes.bar);
54348
54348
  var blCorner = gray(shapes.corners.bl);
54349
54349
  var leftT = gray(shapes.leftT);
54350
- var textInput = async (opts) => {
54351
- const { renderSubmitted, question, defaultValue, validate, acceptDefault } = opts;
54352
- const helpText = opts.helpText || ``;
54353
- const prompt = new oD({
54354
- defaultValue,
54355
- validate,
54356
- render() {
54357
- let body = "";
54358
- switch (this.state) {
54359
- case "initial":
54360
- body += `${blCorner} ${bold(question)} ${dim(helpText)}
54361
- `;
54362
- body += `${space(2)}${gray(defaultValue)}
54363
- `;
54364
- break;
54365
- case "active":
54366
- body += `${blCorner} ${bold(question)} ${dim(helpText)}
54367
- `;
54368
- body += `${space(2)}${this.value}
54369
- `;
54370
- break;
54371
- case "submit":
54372
- body += `${leftT} ${question}
54373
- `;
54374
- body += `${grayBar} ${renderSubmitted(this.value)}
54375
- ${grayBar}`;
54376
- break;
54377
- case "error":
54378
- body += `${leftT} ${status.error} ${dim(this.error)}
54379
- `;
54380
- body += `${grayBar}
54381
- `;
54382
- body += `${blCorner} ${question} ${dim(helpText)}
54383
- `;
54384
- body += `${space(2)}${this.value}
54385
- `;
54386
- break;
54387
- default:
54388
- break;
54389
- }
54390
- return body;
54391
- }
54392
- });
54393
- let value;
54394
- if (acceptDefault) {
54395
- logRaw(`${leftT} ${question}`);
54396
- logRaw(`${grayBar} ${renderSubmitted(defaultValue)}
54397
- ${grayBar}`);
54398
- value = defaultValue;
54399
- validate?.(value);
54400
- } else {
54401
- value = await prompt.prompt();
54402
- if (eD(value)) {
54403
- cancel("Operation cancelled.");
54404
- process.exit(0);
54405
- }
54406
- }
54350
+ var processArgument = async (args, name, promptConfig) => {
54351
+ let value = args[name];
54352
+ const renderSubmitted = getRenderers(promptConfig).submit;
54353
+ if (value !== void 0) {
54354
+ promptConfig.validate?.(value);
54355
+ const lines = renderSubmitted({ value });
54356
+ logRaw(lines.join("\n"));
54357
+ return value;
54358
+ }
54359
+ value = await inputPrompt(promptConfig);
54407
54360
  return value;
54408
54361
  };
54409
- var selectInput = async (opts) => {
54410
- const { question, options, renderSubmitted, defaultValue, acceptDefault } = opts;
54411
- const helpText = opts.helpText || ``;
54412
- const prompt = new ED({
54413
- options,
54414
- initialValue: defaultValue ?? options[0].value,
54415
- render() {
54416
- const renderOption = (opt, i) => {
54417
- const { label } = opt;
54418
- const active = i === this.cursor;
54419
- const text = active ? blue.underline(label) : dim(label);
54420
- const indicator = active ? blue(shapes.radioActive) : dim(shapes.radioInactive);
54421
- return `${space(2)}${indicator} ${text}`;
54422
- };
54423
- let body = ``;
54424
- switch (this.state) {
54425
- case "submit":
54426
- body += `${leftT} ${question}
54427
- `;
54428
- body += `${grayBar} ${renderSubmitted(options[this.cursor])}`;
54429
- body += `
54430
- ${grayBar}`;
54431
- break;
54432
- default:
54433
- body += `${blCorner} ${bold(question)} ${dim(helpText)}
54434
- `;
54435
- body += `${options.map(renderOption).join(`
54436
- `)}
54437
- `;
54438
- break;
54362
+ var inputPrompt = async (promptConfig) => {
54363
+ const renderers = getRenderers(promptConfig);
54364
+ let prompt;
54365
+ const dispatchRender = (props) => {
54366
+ const renderedLines = renderers[props.state](props);
54367
+ return renderedLines.join("\n");
54368
+ };
54369
+ if (promptConfig.type === "select") {
54370
+ prompt = new ED({
54371
+ ...promptConfig,
54372
+ options: promptConfig.options,
54373
+ initialValue: String(promptConfig.defaultValue),
54374
+ render() {
54375
+ return dispatchRender(this);
54439
54376
  }
54440
- return body;
54441
- }
54442
- });
54443
- let value;
54444
- if (acceptDefault) {
54445
- logRaw(`${leftT} ${question}`);
54446
- logRaw(
54447
- `${grayBar} ${renderSubmitted({
54448
- label: defaultValue,
54449
- value: defaultValue
54450
- })}`
54451
- );
54452
- logRaw(`${grayBar}`);
54453
- value = defaultValue;
54377
+ });
54378
+ } else if (promptConfig.type === "confirm") {
54379
+ prompt = new sD({
54380
+ ...promptConfig,
54381
+ initialValue: Boolean(promptConfig.defaultValue),
54382
+ active: promptConfig.activeText || "",
54383
+ inactive: promptConfig.inactiveText || "",
54384
+ render() {
54385
+ return dispatchRender(this);
54386
+ }
54387
+ });
54454
54388
  } else {
54455
- value = await prompt.prompt();
54456
- if (eD(value)) {
54457
- cancel("Operation cancelled.");
54458
- process.exit(0);
54459
- }
54389
+ prompt = new oD({
54390
+ ...promptConfig,
54391
+ defaultValue: String(promptConfig.defaultValue),
54392
+ render() {
54393
+ return dispatchRender(this);
54394
+ }
54395
+ });
54460
54396
  }
54461
- return value;
54397
+ const input = await prompt.prompt();
54398
+ if (eD(input)) {
54399
+ cancel("Operation cancelled.");
54400
+ process.exit(0);
54401
+ }
54402
+ return input;
54403
+ };
54404
+ var renderSubmit = (config14, value) => {
54405
+ const { question, label } = config14;
54406
+ const content = config14.type === "confirm" ? `${grayBar} ${brandColor(value)} ${dim(label)}` : `${grayBar} ${brandColor(label)} ${dim(value)}`;
54407
+ return [`${leftT} ${question}`, content, `${grayBar}`];
54462
54408
  };
54463
- var confirmInput = async (opts) => {
54409
+ var handleCancel = () => {
54410
+ cancel("Operation cancelled.");
54411
+ process.exit(0);
54412
+ };
54413
+ var getRenderers = (config14) => {
54414
+ switch (config14.type) {
54415
+ case "select":
54416
+ return getSelectRenderers(config14);
54417
+ case "confirm":
54418
+ return getConfirmRenderers(config14);
54419
+ case "text":
54420
+ return getTextRenderers(config14);
54421
+ }
54422
+ };
54423
+ var getTextRenderers = (config14) => {
54464
54424
  const {
54465
- activeText,
54466
- inactiveText,
54425
+ defaultValue,
54467
54426
  question,
54468
- renderSubmitted,
54469
- defaultValue = true,
54470
- acceptDefault
54471
- } = opts;
54472
- const helpText = opts.helpText || `(y/n)`;
54427
+ helpText: _helpText,
54428
+ format: _format
54429
+ } = config14;
54430
+ const helpText = _helpText ?? "";
54431
+ const format3 = _format ?? ((val) => String(val));
54432
+ return {
54433
+ initial: () => [
54434
+ `${blCorner} ${bold(question)} ${dim(helpText)}`,
54435
+ `${space(2)}${gray(format3(defaultValue))}`,
54436
+ ``
54437
+ // extra line for readability
54438
+ ],
54439
+ active: ({ value }) => [
54440
+ `${blCorner} ${bold(question)} ${dim(helpText)}`,
54441
+ `${space(2)}${format3(value || dim(defaultValue))}`,
54442
+ ``
54443
+ // extra line for readability
54444
+ ],
54445
+ error: ({ value, error }) => [
54446
+ `${leftT} ${status.error} ${dim(error)}`,
54447
+ `${grayBar}`,
54448
+ `${blCorner} ${question} ${dim(helpText)}`,
54449
+ `${space(2)}${format3(value)}`,
54450
+ ``
54451
+ // extra line for readability
54452
+ ],
54453
+ submit: ({ value }) => renderSubmit(config14, format3(value)),
54454
+ cancel: handleCancel
54455
+ };
54456
+ };
54457
+ var getSelectRenderers = (config14) => {
54458
+ const { options, question, helpText: _helpText } = config14;
54459
+ const helpText = _helpText ?? "";
54460
+ const defaultRenderer = ({ cursor }) => {
54461
+ const renderOption = (opt, i) => {
54462
+ const { label: optionLabel } = opt;
54463
+ const active = i === cursor;
54464
+ const text = active ? blue.underline(optionLabel) : dim(optionLabel);
54465
+ const indicator = active ? blue(shapes.radioActive) : dim(shapes.radioInactive);
54466
+ return `${space(2)}${indicator} ${text}`;
54467
+ };
54468
+ return [
54469
+ `${blCorner} ${bold(question)} ${dim(helpText)}`,
54470
+ `${options.map(renderOption).join(`
54471
+ `)}`,
54472
+ ``
54473
+ // extra line for readability
54474
+ ];
54475
+ };
54476
+ return {
54477
+ initial: defaultRenderer,
54478
+ active: defaultRenderer,
54479
+ confirm: defaultRenderer,
54480
+ error: defaultRenderer,
54481
+ submit: ({ value }) => renderSubmit(
54482
+ config14,
54483
+ options.find((o2) => o2.value === value)?.label
54484
+ ),
54485
+ cancel: handleCancel
54486
+ };
54487
+ };
54488
+ var getConfirmRenderers = (config14) => {
54489
+ const { activeText, inactiveText, question, helpText: _helpText } = config14;
54490
+ const helpText = _helpText ?? "";
54473
54491
  const active = activeText || "Yes";
54474
54492
  const inactive = inactiveText || "No";
54475
- const prompt = new sD({
54476
- active,
54477
- inactive,
54478
- initialValue: defaultValue,
54479
- render() {
54480
- const yesColor = this.value ? blue : dim;
54481
- const noColor = this.value ? dim : blue;
54482
- let body = ``;
54483
- switch (this.state) {
54484
- case "submit":
54485
- body += `${leftT} ${question}
54486
- `;
54487
- body += `${grayBar} ${renderSubmitted(this.value)}`;
54488
- body += `
54489
- ${grayBar}`;
54490
- break;
54491
- default:
54492
- body += `${blCorner} ${bold(question)} ${dim(helpText)}
54493
- `;
54494
- body += `${space(2)}${yesColor(active)} / ${noColor(inactive)}
54495
- `;
54496
- break;
54497
- }
54498
- return body;
54499
- }
54500
- });
54501
- let value;
54502
- if (acceptDefault) {
54503
- logRaw(`${leftT} ${question}`);
54504
- logRaw(`${grayBar} ${renderSubmitted(defaultValue)}`);
54505
- logRaw(`${grayBar}`);
54506
- value = defaultValue;
54507
- } else {
54508
- value = Boolean(await prompt.prompt());
54509
- if (eD(value)) {
54510
- cancel("Operation cancelled.");
54511
- process.exit(0);
54512
- }
54513
- }
54514
- return value;
54493
+ const defaultRenderer = ({ value }) => {
54494
+ const yesColor = value ? blue : dim;
54495
+ const noColor = value ? dim : blue;
54496
+ return [
54497
+ `${blCorner} ${bold(question)} ${dim(helpText)}`,
54498
+ `${space(2)}${yesColor(active)} / ${noColor(inactive)}`
54499
+ ];
54500
+ };
54501
+ return {
54502
+ initial: defaultRenderer,
54503
+ active: defaultRenderer,
54504
+ confirm: defaultRenderer,
54505
+ error: defaultRenderer,
54506
+ submit: ({ value }) => renderSubmit(config14, value ? "yes" : "no"),
54507
+ cancel: handleCancel
54508
+ };
54515
54509
  };
54510
+ var spinnerFrames = ["\u2524", "\u2518", "\u2534", "\u2514", "\u251C", "\u250C", "\u252C", "\u2510"];
54511
+ var ellipsisFrames = ["", ".", "..", "...", " ..", " .", ""];
54516
54512
  var spinner = () => {
54517
- const spinnerFrames = ["\u2524", "\u2518", "\u2534", "\u2514", "\u251C", "\u250C", "\u252C", "\u2510"];
54518
- const ellipsisFrames = ["", ".", "..", "...", " ..", " .", ""];
54519
54513
  const color = brandColor;
54520
54514
  const frameRate = 120;
54521
54515
  let loop = null;
@@ -59416,7 +59410,7 @@ var Yargs = YargsFactory(esm_default);
59416
59410
  var yargs_default = Yargs;
59417
59411
 
59418
59412
  // package.json
59419
- var version = "0.0.0-d199ffbc";
59413
+ var version = "0.0.0-d208ede3";
59420
59414
 
59421
59415
  // src/common.ts
59422
59416
  var import_fs6 = require("fs");
@@ -59471,29 +59465,28 @@ var detectPackageManager = () => {
59471
59465
  };
59472
59466
 
59473
59467
  // src/helpers/command.ts
59474
- var runCommand = async (command2, opts) => {
59468
+ var runCommand = async (command2, opts = {}) => {
59475
59469
  if (typeof command2 === "string") {
59476
59470
  command2 = command2.trim().replace(/\s+/g, ` `).split(" ");
59477
59471
  }
59478
59472
  return printAsyncStatus({
59479
- useSpinner: opts?.useSpinner ?? opts?.silent,
59480
- startText: opts?.startText || command2.join(" "),
59481
- doneText: opts?.doneText,
59473
+ useSpinner: opts.useSpinner ?? opts.silent,
59474
+ startText: opts.startText || command2.join(" ").trim(),
59475
+ doneText: opts.doneText,
59482
59476
  promise() {
59483
59477
  const [executable, ...args] = command2;
59484
- const squelch = opts?.silent || process.env.VITEST;
59485
59478
  const cmd = (0, import_cross_spawn.spawn)(executable, [...args], {
59486
59479
  // TODO: ideally inherit stderr, but npm install uses this for warnings
59487
59480
  // stdio: [ioMode, ioMode, "inherit"],
59488
- stdio: squelch ? "pipe" : "inherit",
59481
+ stdio: opts.silent ? "pipe" : "inherit",
59489
59482
  env: {
59490
59483
  ...process.env,
59491
- ...opts?.env
59484
+ ...opts.env
59492
59485
  },
59493
- cwd: opts?.cwd
59486
+ cwd: opts.cwd
59494
59487
  });
59495
59488
  let output = ``;
59496
- if (opts?.captureOutput ?? squelch) {
59489
+ if (opts.captureOutput ?? opts.silent) {
59497
59490
  cmd.stdout?.on("data", (data) => {
59498
59491
  output += data;
59499
59492
  });
@@ -59503,12 +59496,24 @@ var runCommand = async (command2, opts) => {
59503
59496
  }
59504
59497
  return new Promise((resolve9, reject) => {
59505
59498
  cmd.on("close", (code) => {
59506
- if (code === 0) {
59507
- resolve9(stripAnsi(output));
59508
- } else {
59509
- reject(new Error(output, { cause: code }));
59499
+ try {
59500
+ if (code !== 0) {
59501
+ throw new Error(output, { cause: code });
59502
+ }
59503
+ const transformOutput = opts.transformOutput ?? ((result) => result);
59504
+ const processedOutput = transformOutput(stripAnsi(output));
59505
+ resolve9(processedOutput);
59506
+ } catch (e) {
59507
+ if (opts.fallbackOutput) {
59508
+ resolve9(opts.fallbackOutput(e));
59509
+ } else {
59510
+ reject(new Error(output, { cause: e }));
59511
+ }
59510
59512
  }
59511
59513
  });
59514
+ cmd.on("error", (code) => {
59515
+ reject(code);
59516
+ });
59512
59517
  });
59513
59518
  }
59514
59519
  });
@@ -59519,9 +59524,11 @@ async function runCommands({ commands, ...opts }) {
59519
59524
  startText: opts.startText,
59520
59525
  doneText: opts.doneText,
59521
59526
  async promise() {
59527
+ const results = [];
59522
59528
  for (const command2 of commands) {
59523
- await runCommand(command2, { ...opts, useSpinner: false });
59529
+ results.push(await runCommand(command2, { ...opts, useSpinner: false }));
59524
59530
  }
59531
+ return results.join("\n");
59525
59532
  }
59526
59533
  });
59527
59534
  }
@@ -59538,8 +59545,9 @@ var printAsyncStatus = async ({
59538
59545
  promise = promise();
59539
59546
  }
59540
59547
  try {
59541
- await promise;
59542
- s?.stop(opts.doneText);
59548
+ const output = await promise;
59549
+ const doneText = typeof opts.doneText === "function" ? opts.doneText(output) : opts.doneText;
59550
+ s?.stop(doneText);
59543
59551
  } catch (err) {
59544
59552
  s?.stop(err.message);
59545
59553
  } finally {
@@ -59616,10 +59624,14 @@ var installWrangler = async () => {
59616
59624
  };
59617
59625
  var isLoggedIn = async () => {
59618
59626
  const { npx: npx6 } = detectPackageManager();
59619
- const output = await runCommand(`${npx6} wrangler whoami`, {
59620
- silent: true
59621
- });
59622
- return !/not authenticated/.test(output);
59627
+ try {
59628
+ const output = await runCommand(`${npx6} wrangler whoami`, {
59629
+ silent: true
59630
+ });
59631
+ return /You are logged in/.test(output);
59632
+ } catch (error) {
59633
+ return false;
59634
+ }
59623
59635
  };
59624
59636
  var wranglerLogin = async () => {
59625
59637
  const { npx: npx6 } = detectPackageManager();
@@ -59652,6 +59664,24 @@ var listAccounts = async () => {
59652
59664
  });
59653
59665
  return accounts;
59654
59666
  };
59667
+ async function getWorkerdCompatibilityDate() {
59668
+ const { npm: npm12 } = detectPackageManager();
59669
+ return runCommand(`${npm12} info workerd dist-tags.latest`, {
59670
+ silent: true,
59671
+ captureOutput: true,
59672
+ startText: "Retrieving current workerd compatibility date",
59673
+ transformOutput: (result) => {
59674
+ const match = result.match(/\d+\.(\d{4})(\d{2})(\d{2})\.\d+/);
59675
+ if (!match) {
59676
+ throw new Error("Could not find workerd date");
59677
+ }
59678
+ const [, year, month, date] = match;
59679
+ return `${year}-${month}-${date}`;
59680
+ },
59681
+ fallbackOutput: () => "2023-05-18",
59682
+ doneText: (output) => `${brandColor("compatibility date")} ${dim(output)}`
59683
+ });
59684
+ }
59655
59685
 
59656
59686
  // src/helpers/poll.ts
59657
59687
  var import_promises = require("node:dns/promises");
@@ -59729,14 +59759,15 @@ var validateProjectDirectory = (relativePath) => {
59729
59759
  const existsAlready = (0, import_fs6.existsSync)(path3);
59730
59760
  const isEmpty = existsAlready && (0, import_fs6.readdirSync)(path3).length === 0;
59731
59761
  if (existsAlready && !isEmpty) {
59732
- crash(
59733
- `Directory \`${relativePath}\` already exists and is not empty. Please choose a new name.`
59734
- );
59762
+ return `Directory \`${relativePath}\` already exists and is not empty. Please choose a new name.`;
59735
59763
  }
59736
59764
  };
59737
59765
  var setupProjectDirectory = (args) => {
59738
59766
  const path3 = (0, import_path6.resolve)(args.projectName);
59739
- validateProjectDirectory(path3);
59767
+ const err = validateProjectDirectory(path3);
59768
+ if (err) {
59769
+ crash(err);
59770
+ }
59740
59771
  const directory = (0, import_path6.dirname)(path3);
59741
59772
  const name = (0, import_path6.basename)(path3);
59742
59773
  (0, import_fs6.mkdirSync)(directory, { recursive: true });
@@ -59745,14 +59776,12 @@ var setupProjectDirectory = (args) => {
59745
59776
  };
59746
59777
  var offerToDeploy = async (ctx) => {
59747
59778
  startSection(`Deploy with Cloudflare`, `Step 3 of 3`);
59748
- ctx.args.deploy = await confirmInput({
59779
+ const label = `deploy via \`${npm} run ${ctx.framework?.config.deployCommand ?? "deploy"}\``;
59780
+ ctx.args.deploy = await processArgument(ctx.args, "deploy", {
59781
+ type: "confirm",
59749
59782
  question: "Do you want to deploy your application?",
59750
- renderSubmitted: (value) => `${brandColor(value ? `yes` : `no`)} ${dim(
59751
- `deploying via \`${npm} run ${ctx.framework?.config.deployCommand ?? "deploy"}\``
59752
- )}`,
59753
- defaultValue: ctx.args.deploy ?? (ctx.args.wranglerDefaults ? false : true),
59754
- // if --wrangler-defaults, default to false, otherwise default to true
59755
- acceptDefault: ctx.args.wranglerDefaults
59783
+ label,
59784
+ defaultValue: C3_DEFAULTS.deploy
59756
59785
  });
59757
59786
  if (!ctx.args.deploy)
59758
59787
  return;
@@ -59772,7 +59801,7 @@ var runDeploy = async (ctx) => {
59772
59801
  const result = await runCommand(deployCmd, {
59773
59802
  silent: true,
59774
59803
  cwd: ctx.project.path,
59775
- env: { CLOUDFLARE_ACCOUNT_ID: ctx.account.id },
59804
+ env: { CLOUDFLARE_ACCOUNT_ID: ctx.account.id, NODE_ENV: "production" },
59776
59805
  startText: `Deploying your application`,
59777
59806
  doneText: `${brandColor("deployed")} ${dim(`via \`${deployCmd}\``)}`
59778
59807
  });
@@ -59806,14 +59835,12 @@ var chooseAccount = async (ctx) => {
59806
59835
  label: name,
59807
59836
  value: id
59808
59837
  }));
59809
- accountId = await selectInput({
59838
+ accountId = await inputPrompt({
59839
+ type: "select",
59810
59840
  question: "Which account do you want to use?",
59811
59841
  options: accountOptions,
59812
- renderSubmitted: (option) => {
59813
- return `${brandColor("account")} ${dim(option.label)}`;
59814
- },
59815
- defaultValue: accountOptions[0].value,
59816
- acceptDefault: ctx.args.wranglerDefaults
59842
+ label: "account",
59843
+ defaultValue: accountOptions[0].value
59817
59844
  });
59818
59845
  }
59819
59846
  const accountName = Object.keys(accounts).find(
@@ -59823,6 +59850,7 @@ var chooseAccount = async (ctx) => {
59823
59850
  };
59824
59851
  var printSummary = async (ctx) => {
59825
59852
  const nextSteps = [
59853
+ [`Navigate to the new directory`, `cd ${ctx.project.name}`],
59826
59854
  [
59827
59855
  `Run the development server`,
59828
59856
  `${npm} run ${ctx.framework?.config.devCommand ?? "start"}`
@@ -59885,11 +59913,11 @@ var offerGit = async (ctx) => {
59885
59913
  const insideGitRepo = await isInsideGitRepo(ctx.project.path);
59886
59914
  if (insideGitRepo)
59887
59915
  return;
59888
- ctx.args.git ??= await confirmInput({
59916
+ ctx.args.git = await processArgument(ctx.args, "git", {
59917
+ type: "confirm",
59889
59918
  question: "Do you want to use git for version control?",
59890
- renderSubmitted: (value) => `${brandColor("git")} ${dim(value ? `yes` : `no`)}`,
59891
- defaultValue: true,
59892
- acceptDefault: ctx.args.wranglerDefaults
59919
+ label: "git",
59920
+ defaultValue: C3_DEFAULTS.git
59893
59921
  });
59894
59922
  if (ctx.args.git) {
59895
59923
  await printAsyncStatus({
@@ -59949,6 +59977,24 @@ async function initializeGit(cwd) {
59949
59977
  await runCommand(`git init`, { useSpinner: false, silent: true, cwd });
59950
59978
  }
59951
59979
  }
59980
+ async function getProductionBranch(cwd) {
59981
+ try {
59982
+ const productionBranch = await runCommand(
59983
+ // "git branch --show-current", // git@^2.22
59984
+ "git rev-parse --abbrev-ref HEAD",
59985
+ // git@^1.6.3
59986
+ {
59987
+ silent: true,
59988
+ cwd,
59989
+ useSpinner: false,
59990
+ captureOutput: true
59991
+ }
59992
+ );
59993
+ return productionBranch.trim();
59994
+ } catch (err) {
59995
+ }
59996
+ return "main";
59997
+ }
59952
59998
 
59953
59999
  // src/pages.ts
59954
60000
  var import_path8 = require("path");
@@ -59978,6 +60024,9 @@ var readJSON = (path3) => {
59978
60024
  const contents = readFile(path3);
59979
60025
  return contents ? JSON.parse(contents) : contents;
59980
60026
  };
60027
+ var writeJSON = (path3, object, stringifySpace) => {
60028
+ writeFile2(path3, JSON.stringify(object, null, stringifySpace));
60029
+ };
59981
60030
  var probePaths = (paths, errorMsg = "Failed to find required file.") => {
59982
60031
  for (const path3 of paths) {
59983
60032
  if ((0, import_fs7.existsSync)(path3)) {
@@ -59990,6 +60039,35 @@ var probePaths = (paths, errorMsg = "Failed to find required file.") => {
59990
60039
  var usesTypescript = (projectRoot = ".") => {
59991
60040
  return (0, import_fs7.existsSync)(`${projectRoot}/tsconfig.json`);
59992
60041
  };
60042
+ var eslintRcExts = ["js", "cjs", "yaml", "yml", "json"];
60043
+ var usesEslint = (ctx) => {
60044
+ for (const ext of eslintRcExts) {
60045
+ const eslintRcFilename = `.eslintrc.${ext}`;
60046
+ if ((0, import_fs7.existsSync)(`${ctx.project.path}/${eslintRcFilename}`)) {
60047
+ return {
60048
+ used: true,
60049
+ configType: eslintRcFilename
60050
+ };
60051
+ }
60052
+ }
60053
+ if ((0, import_fs7.existsSync)(`${ctx.project.path}/eslint.config.js`)) {
60054
+ return {
60055
+ used: true,
60056
+ configType: "eslint.config.js"
60057
+ };
60058
+ }
60059
+ try {
60060
+ const pkgJson = readJSON(`${ctx.project.path}/package.json`);
60061
+ if (pkgJson.eslintConfig) {
60062
+ return {
60063
+ used: true,
60064
+ configType: "package.json"
60065
+ };
60066
+ }
60067
+ } catch {
60068
+ }
60069
+ return { used: false };
60070
+ };
59993
60071
  var compatDateFlag = () => {
59994
60072
  const date = /* @__PURE__ */ new Date();
59995
60073
  return `--compatibility-date=${date.toISOString().slice(0, 10)}`;
@@ -60021,10 +60099,10 @@ var config = {
60021
60099
  displayName: "Angular",
60022
60100
  packageScripts: {
60023
60101
  process: "node ./tools/copy-worker-files.mjs && node ./tools/copy-client-files.mjs && node ./tools/bundle.mjs",
60024
- prestart: `${npm2} run build:ssr && npm run process`,
60102
+ prestart: `${npm2} run build:ssr && ${npm2} run process`,
60025
60103
  start: "wrangler pages dev dist/cloudflare --compatibility-date=2021-09-20 --experimental-local",
60026
- predeploy: `${npm2} run build:ssr && npm run process`,
60027
- deploy: "wrangler pages publish dist/cloudflare"
60104
+ predeploy: `${npm2} run build:ssr && ${npm2} run process`,
60105
+ deploy: "wrangler pages deploy dist/cloudflare"
60028
60106
  },
60029
60107
  deployCommand: "deploy",
60030
60108
  devCommand: "start"
@@ -60119,7 +60197,7 @@ var config2 = {
60119
60197
  displayName: "Astro",
60120
60198
  packageScripts: {
60121
60199
  "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- astro dev`,
60122
- "pages:deploy": `astro build && wrangler pages publish ./dist`
60200
+ "pages:deploy": `astro build && wrangler pages deploy ./dist`
60123
60201
  },
60124
60202
  testFlags: [
60125
60203
  "--skip-houston",
@@ -60148,7 +60226,7 @@ var config3 = {
60148
60226
  displayName: "Docusaurus",
60149
60227
  packageScripts: {
60150
60228
  "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- ${npm3} run start`,
60151
- "pages:deploy": `NODE_VERSION=16 ${npm3} run build && wrangler pages publish ./build`
60229
+ "pages:deploy": `NODE_VERSION=16 ${npm3} run build && wrangler pages deploy ./build`
60152
60230
  }
60153
60231
  };
60154
60232
  var docusaurus_default = config3;
@@ -60157,25 +60235,19 @@ var docusaurus_default = config3;
60157
60235
  var { npm: npm4, dlx: dlx4 } = detectPackageManager();
60158
60236
  var generate4 = async (ctx) => {
60159
60237
  const defaultTemplate = "https://github.com/gatsbyjs/gatsby-starter-blog";
60160
- const useTemplate = await confirmInput({
60238
+ const useTemplate = await inputPrompt({
60239
+ type: "confirm",
60161
60240
  question: "Would you like to use a template?",
60162
- renderSubmitted: (value) => {
60163
- const status2 = value ? "yes" : "no";
60164
- return `${brandColor(`template`)} ${status2}`;
60165
- },
60166
- defaultValue: true,
60167
- acceptDefault: false
60241
+ label: "template",
60242
+ defaultValue: true
60168
60243
  });
60169
60244
  let templateUrl = "";
60170
60245
  if (useTemplate) {
60171
- templateUrl = await textInput({
60246
+ templateUrl = await inputPrompt({
60247
+ type: "text",
60172
60248
  question: `Please specify the url of the template you'd like to use`,
60173
- renderSubmitted: (value) => {
60174
- const result = `Using template \`${value}\``;
60175
- return `${brandColor("template")} ${dim(result)}`;
60176
- },
60177
- defaultValue: defaultTemplate,
60178
- acceptDefault: false
60249
+ label: "template",
60250
+ defaultValue: defaultTemplate
60179
60251
  });
60180
60252
  }
60181
60253
  const version2 = getFrameworkVersion(ctx);
@@ -60189,7 +60261,7 @@ var config4 = {
60189
60261
  displayName: "Gatsby",
60190
60262
  packageScripts: {
60191
60263
  "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 8000 -- ${npm4} run develop`,
60192
- "pages:deploy": `${npm4} run build && wrangler pages publish ./public`
60264
+ "pages:deploy": `${npm4} run build && wrangler pages deploy ./public`
60193
60265
  }
60194
60266
  };
60195
60267
  var gatsby_default = config4;
@@ -60301,21 +60373,57 @@ var configure3 = async (ctx) => {
60301
60373
  );
60302
60374
  writeFile2(handlerPath, handlerFile);
60303
60375
  updateStatus("Created an example API route handler");
60376
+ const installEslintPlugin = await shouldInstallNextOnPagesEslintPlugin(ctx);
60377
+ if (installEslintPlugin) {
60378
+ await writeEslintrc(ctx);
60379
+ }
60304
60380
  process.chdir(projectName);
60305
- const packages = ["@cloudflare/next-on-pages@1", "vercel"];
60381
+ const packages = [
60382
+ "@cloudflare/next-on-pages@1",
60383
+ "vercel",
60384
+ ...installEslintPlugin ? ["eslint-plugin-next-on-pages"] : []
60385
+ ];
60306
60386
  await installPackages(packages, {
60307
60387
  dev: true,
60308
60388
  startText: "Adding the Cloudflare Pages adapter",
60309
60389
  doneText: `${brandColor(`installed`)} ${dim(packages.join(", "))}`
60310
60390
  });
60311
60391
  };
60392
+ var shouldInstallNextOnPagesEslintPlugin = async (ctx) => {
60393
+ const eslintUsage = usesEslint(ctx);
60394
+ if (!eslintUsage.used)
60395
+ return false;
60396
+ if (eslintUsage.configType !== ".eslintrc.json") {
60397
+ warn(
60398
+ `Expected .eslintrc.json from Next.js scaffolding but found ${eslintUsage.configType} instead`
60399
+ );
60400
+ return false;
60401
+ }
60402
+ return await processArgument(ctx.args, "eslint-plugin", {
60403
+ type: "confirm",
60404
+ question: "Do you want to use the next-on-pages eslint-plugin?",
60405
+ label: "eslint-plugin",
60406
+ defaultValue: true
60407
+ });
60408
+ };
60409
+ var writeEslintrc = async (ctx) => {
60410
+ const eslintConfig = readJSON(`${ctx.project.name}/.eslintrc.json`);
60411
+ eslintConfig.plugins ??= [];
60412
+ eslintConfig.plugins.push("eslint-plugin-next-on-pages");
60413
+ if (typeof eslintConfig.extends === "string") {
60414
+ eslintConfig.extends = [eslintConfig.extends];
60415
+ }
60416
+ eslintConfig.extends ??= [];
60417
+ eslintConfig.extends.push("plugin:eslint-plugin-next-on-pages/recommended");
60418
+ writeJSON(`${ctx.project.name}/.eslintrc.json`, eslintConfig, 2);
60419
+ };
60312
60420
  var config6 = {
60313
60421
  generate: generate6,
60314
60422
  configure: configure3,
60315
60423
  displayName: "Next",
60316
60424
  packageScripts: {
60317
60425
  "pages:build": `${npx3} @cloudflare/next-on-pages@1`,
60318
- "pages:deploy": `${npm5} run pages:build && wrangler pages publish .vercel/output/static`,
60426
+ "pages:deploy": `${npm5} run pages:build && wrangler pages deploy .vercel/output/static`,
60319
60427
  "pages:watch": `${npx3} @cloudflare/next-on-pages@1 --watch`,
60320
60428
  "pages:dev": `${npx3} wrangler pages dev .vercel/output/static --compatibility-flag=nodejs_compat`
60321
60429
  },
@@ -60327,7 +60435,7 @@ var config6 = {
60327
60435
  "--src-dir",
60328
60436
  "--app",
60329
60437
  "--import-alias",
60330
- '"@/*"'
60438
+ "@/*"
60331
60439
  ],
60332
60440
  compatibilityFlags: ["nodejs_compat"]
60333
60441
  };
@@ -60345,6 +60453,7 @@ var generate7 = async (ctx) => {
60345
60453
  };
60346
60454
  var configure4 = async (ctx) => {
60347
60455
  process.chdir(ctx.project.path);
60456
+ writeFile2("./.node-version", "17");
60348
60457
  await npmInstall();
60349
60458
  };
60350
60459
  var config7 = {
@@ -60352,8 +60461,9 @@ var config7 = {
60352
60461
  configure: configure4,
60353
60462
  displayName: "Nuxt",
60354
60463
  packageScripts: {
60464
+ build: (cmd) => `NITRO_PRESET=cloudflare-pages ${cmd}`,
60355
60465
  "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- npm run dev`,
60356
- "pages:deploy": `NODE_VERSION=17 npm run generate && wrangler pages publish ./dist`
60466
+ "pages:deploy": "npm run build && wrangler pages deploy ./dist"
60357
60467
  }
60358
60468
  };
60359
60469
  var nuxt_default = config7;
@@ -60400,7 +60510,7 @@ var config9 = {
60400
60510
  displayName: "React",
60401
60511
  packageScripts: {
60402
60512
  "pages:dev": `wrangler pages dev ${compatDateFlag()} --port 3000 -- ${npm7} start`,
60403
- "pages:deploy": `${npm7} run build && wrangler pages publish ./build`
60513
+ "pages:deploy": `${npm7} run build && wrangler pages deploy ./build`
60404
60514
  }
60405
60515
  };
60406
60516
  var react_default = config9;
@@ -60419,7 +60529,7 @@ var config10 = {
60419
60529
  generate: generate10,
60420
60530
  displayName: "Remix",
60421
60531
  packageScripts: {
60422
- "pages:deploy": `${npm8} run build && wrangler pages publish ./public`
60532
+ "pages:deploy": `${npm8} run build && wrangler pages deploy ./public`
60423
60533
  },
60424
60534
  devCommand: "dev",
60425
60535
  testFlags: ["--typescript", "--no-install"]
@@ -60468,7 +60578,7 @@ var config11 = {
60468
60578
  displayName: "Solid",
60469
60579
  packageScripts: {
60470
60580
  "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- ${npm9} run dev`,
60471
- "pages:deploy": `${npm9} run build build && wrangler pages publish ./dist/public`
60581
+ "pages:deploy": `${npm9} run build && wrangler pages deploy ./dist/public`
60472
60582
  }
60473
60583
  };
60474
60584
  var solid_default = config11;
@@ -60568,7 +60678,7 @@ var config12 = {
60568
60678
  displayName: "Svelte",
60569
60679
  packageScripts: {
60570
60680
  "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 5173 -- ${npm10} run dev`,
60571
- "pages:deploy": `NODE_VERSION=16 ${npm10} run build && wrangler pages publish .svelte-kit/cloudflare`
60681
+ "pages:deploy": `NODE_VERSION=16 ${npm10} run build && wrangler pages deploy .svelte-kit/cloudflare`
60572
60682
  }
60573
60683
  };
60574
60684
  var svelte_default = config12;
@@ -60579,7 +60689,7 @@ var versionMap_default = {
60579
60689
  astro: "3.1.5",
60580
60690
  docusaurus: "2.4.1",
60581
60691
  gatsby: "5.10.0",
60582
- hono: "0.2.0",
60692
+ hono: "0.2.6",
60583
60693
  next: "13.4.2",
60584
60694
  nuxt: "3.4.2",
60585
60695
  qwik: "1.1.x",
@@ -60604,7 +60714,7 @@ var config13 = {
60604
60714
  displayName: "Vue",
60605
60715
  packageScripts: {
60606
60716
  "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 5173 -- ${npm11} run dev`,
60607
- "pages:deploy": `${npm11} run build && wrangler pages publish ./dist`
60717
+ "pages:deploy": `${npm11} run build && wrangler pages deploy ./dist`
60608
60718
  },
60609
60719
  testFlags: ["--ts"]
60610
60720
  };
@@ -60684,14 +60794,12 @@ var getFrameworkSelection = async (args) => {
60684
60794
  value: key
60685
60795
  })
60686
60796
  );
60687
- const framework = await selectInput({
60797
+ const framework = await processArgument(args, "framework", {
60798
+ type: "select",
60799
+ label: "framework",
60688
60800
  question: "Which development framework do you want to use?",
60689
60801
  options: frameworkOptions,
60690
- renderSubmitted: (option) => {
60691
- return `${brandColor("framework")} ${dim(option.label)}`;
60692
- },
60693
- defaultValue: args.framework ?? "svelte",
60694
- acceptDefault: Boolean(args.framework)
60802
+ defaultValue: C3_DEFAULTS.framework
60695
60803
  });
60696
60804
  framework || crash("A framework must be selected to continue.");
60697
60805
  if (!supportedFramework(framework)) {
@@ -60705,11 +60813,29 @@ var updatePackageScripts = async (ctx) => {
60705
60813
  const { packageScripts } = ctx.framework?.config ?? {};
60706
60814
  if (packageScripts) {
60707
60815
  const s = spinner();
60708
- s.start(`Adding command scripts`, `for development and deployment`);
60816
+ const updatingScripts = Object.entries(packageScripts).filter(
60817
+ ([_3, cmdOrUpdater]) => typeof cmdOrUpdater === "function"
60818
+ ).length > 0;
60819
+ s.start(
60820
+ `${updatingScripts ? "Updating" : "Adding"} command scripts`,
60821
+ "for development and deployment"
60822
+ );
60709
60823
  const pkgJsonPath = (0, import_path8.resolve)("package.json");
60710
60824
  const pkgConfig = readJSON(pkgJsonPath);
60711
- Object.entries(packageScripts).forEach(([target, command2]) => {
60712
- pkgConfig.scripts[target] = command2;
60825
+ Object.entries(packageScripts).forEach(([target, cmdOrUpdater]) => {
60826
+ if (typeof cmdOrUpdater === "string") {
60827
+ const command2 = cmdOrUpdater;
60828
+ pkgConfig.scripts[target] = command2;
60829
+ } else {
60830
+ const existingCommand = pkgConfig.scripts[target];
60831
+ if (!existingCommand) {
60832
+ throw new Error(
60833
+ `Could not find ${target} script to update during ${ctx.framework} setup`
60834
+ );
60835
+ }
60836
+ const updater = cmdOrUpdater;
60837
+ pkgConfig.scripts[target] = updater(existingCommand);
60838
+ }
60713
60839
  });
60714
60840
  writeFile2(pkgJsonPath, JSON.stringify(pkgConfig, null, 2));
60715
60841
  s.stop(`${brandColor("added")} ${dim("commands to `package.json`")}`);
@@ -60725,7 +60851,8 @@ var createProject = async (ctx) => {
60725
60851
  const CLOUDFLARE_ACCOUNT_ID = ctx.account.id;
60726
60852
  const compatFlags = ctx.framework?.config.compatibilityFlags?.join(" ");
60727
60853
  const compatFlagsArg = compatFlags ? `--compatibility-flags ${compatFlags}` : "";
60728
- const cmd = `${npx5} wrangler pages project create ${ctx.project.name} --production-branch main ${compatFlagsArg}`;
60854
+ const productionBranch = await getProductionBranch(ctx.project.path);
60855
+ const cmd = `${npx5} wrangler pages project create ${ctx.project.name} --production-branch ${productionBranch} ${compatFlagsArg}`;
60729
60856
  try {
60730
60857
  await retry(
60731
60858
  CREATE_PROJECT_RETRIES,
@@ -60734,7 +60861,7 @@ var createProject = async (ctx) => {
60734
60861
  cwd: ctx.project.path,
60735
60862
  env: { CLOUDFLARE_ACCOUNT_ID },
60736
60863
  startText: "Creating Pages project",
60737
- doneText: `${brandColor("created")} ${dim(`via \`${cmd}\``)}`
60864
+ doneText: `${brandColor("created")} ${dim(`via \`${cmd.trim()}\``)}`
60738
60865
  })
60739
60866
  );
60740
60867
  } catch (error) {
@@ -60768,14 +60895,12 @@ var runWorkersGenerator = async (args) => {
60768
60895
  await printSummary(ctx);
60769
60896
  };
60770
60897
  async function getTemplate(ctx) {
60771
- if (ctx.args.ts === void 0) {
60772
- ctx.args.ts = await confirmInput({
60773
- question: "Do you want to use TypeScript?",
60774
- renderSubmitted: (value) => `${brandColor("typescript")} ${dim(`${value ? "yes" : "no"}`)}`,
60775
- defaultValue: true,
60776
- acceptDefault: ctx.args.wranglerDefaults
60777
- });
60778
- }
60898
+ ctx.args.ts = await processArgument(ctx.args, "ts", {
60899
+ type: "confirm",
60900
+ question: "Do you want to use TypeScript?",
60901
+ label: "typescript",
60902
+ defaultValue: C3_DEFAULTS.ts
60903
+ });
60779
60904
  const preexisting = ctx.args.type === "pre-existing";
60780
60905
  const template = preexisting ? "hello-world" : ctx.args.type;
60781
60906
  const path3 = (0, import_path9.resolve)(
@@ -60799,12 +60924,16 @@ async function copyExistingWorkerFiles(ctx) {
60799
60924
  if (preexisting) {
60800
60925
  await chooseAccount(ctx);
60801
60926
  if (ctx.args.existingScript === void 0) {
60802
- ctx.args.existingScript = await textInput({
60803
- question: "Please specify the name of the existing worker in this account?",
60804
- renderSubmitted: (value) => `${brandColor("worker")} ${dim(`"${value}"`)}`,
60805
- defaultValue: ctx.project.name,
60806
- acceptDefault: ctx.args.wranglerDefaults
60807
- });
60927
+ ctx.args.existingScript = await processArgument(
60928
+ ctx.args,
60929
+ "existingScript",
60930
+ {
60931
+ type: "text",
60932
+ question: "Please specify the name of the existing worker in this account?",
60933
+ label: "worker",
60934
+ defaultValue: ctx.project.name
60935
+ }
60936
+ );
60808
60937
  }
60809
60938
  const tempdir = await (0, import_promises3.mkdtemp)(
60810
60939
  (0, import_path9.join)((0, import_os.tmpdir)(), "c3-wrangler-init--from-dash-")
@@ -60845,10 +60974,12 @@ async function updateFiles(ctx) {
60845
60974
  packagejson: JSON.parse(await (0, import_promises3.readFile)(paths.packagejson, "utf-8")),
60846
60975
  wranglertoml: await (0, import_promises3.readFile)(paths.wranglertoml, "utf-8")
60847
60976
  };
60848
- contents.packagejson.name = ctx.project.name;
60849
- contents.wranglertoml = contents.wranglertoml.replace(/^name = .+$/m, `name = "${ctx.project.name}"`).replace(
60850
- /^compatibility_date = .+$/m,
60851
- `compatibility_date = "${(/* @__PURE__ */ new Date()).toISOString().substring(0, 10)}"`
60977
+ if (contents.packagejson.name === "<TBD>") {
60978
+ contents.packagejson.name = ctx.project.name;
60979
+ }
60980
+ contents.wranglertoml = contents.wranglertoml.replace(/^name\s*=\s*"<TBD>"/m, `name = "${ctx.project.name}"`).replace(
60981
+ /^compatibility_date\s*=\s*"<TBD>"/m,
60982
+ `compatibility_date = "${await getWorkerdCompatibilityDate()}"`
60852
60983
  );
60853
60984
  await (0, import_promises3.writeFile)(
60854
60985
  paths.packagejson,
@@ -60858,19 +60989,55 @@ async function updateFiles(ctx) {
60858
60989
  }
60859
60990
 
60860
60991
  // src/cli.ts
60992
+ var C3_DEFAULTS = {
60993
+ projectName: new import_haikunator.default().haikunate({ tokenHex: true }),
60994
+ type: "hello-world",
60995
+ framework: "angular",
60996
+ deploy: true,
60997
+ git: true,
60998
+ open: true,
60999
+ ts: true
61000
+ };
61001
+ var WRANGLER_DEFAULTS = {
61002
+ ...C3_DEFAULTS,
61003
+ deploy: false
61004
+ };
60861
61005
  var main = async (argv) => {
60862
- printBanner();
60863
61006
  const args = await parseArgs(argv);
61007
+ printBanner();
61008
+ const projectName = await processArgument(args, "projectName", {
61009
+ type: "text",
61010
+ question: `In which directory do you want to create your application?`,
61011
+ helpText: "also used as application name",
61012
+ defaultValue: C3_DEFAULTS.projectName,
61013
+ label: "dir",
61014
+ validate: (value) => validateProjectDirectory(String(value) || C3_DEFAULTS.projectName),
61015
+ format: (val) => `./${val}`
61016
+ });
61017
+ if (!args.type) {
61018
+ if (args.framework) {
61019
+ args.type = "webFramework";
61020
+ } else if (args.existingScript) {
61021
+ args.type = "pre-existing";
61022
+ }
61023
+ }
61024
+ const templateOptions = Object.entries(templateMap).filter(([_3, { hidden: hidden2 }]) => !hidden2).map(([value, { label }]) => ({ value, label }));
61025
+ const type = await processArgument(args, "type", {
61026
+ type: "select",
61027
+ question: "What type of application do you want to create?",
61028
+ label: "type",
61029
+ options: templateOptions,
61030
+ defaultValue: C3_DEFAULTS.type
61031
+ });
61032
+ if (!type || !Object.keys(templateMap).includes(type)) {
61033
+ return crash("An application type must be specified to continue.");
61034
+ }
60864
61035
  const validatedArgs = {
60865
61036
  ...args,
60866
- projectName: await validateName(args.projectName, {
60867
- acceptDefault: args.wranglerDefaults
60868
- }),
60869
- type: await validateType(args.type, {
60870
- acceptDefault: args.wranglerDefaults
60871
- })
61037
+ type,
61038
+ projectName
60872
61039
  };
60873
- const { handler } = templateMap[validatedArgs.type];
61040
+ const { handler } = templateMap[type];
60874
61041
  await handler(validatedArgs);
60875
61042
  };
60876
61043
  var printBanner = () => {
@@ -60887,41 +61054,17 @@ var parseArgs = async (argv) => {
60887
61054
  }).option("existing-script", {
60888
61055
  type: "string",
60889
61056
  hidden: templateMap["pre-existing"].hidden
60890
- }).option("wrangler-defaults", { type: "boolean", hidden: true }).help().argv;
61057
+ }).option("accept-defaults", {
61058
+ alias: "y",
61059
+ type: "boolean"
61060
+ }).option("wrangler-defaults", { type: "boolean", hidden: true }).version(version).help().argv;
60891
61061
  return {
61062
+ ...args.wranglerDefaults && WRANGLER_DEFAULTS,
61063
+ ...args.acceptDefaults && C3_DEFAULTS,
60892
61064
  projectName: args._[0],
60893
61065
  ...args
60894
61066
  };
60895
61067
  };
60896
- var validateName = async (name, { acceptDefault = false } = {}) => {
60897
- const defaultValue = name ?? new import_haikunator.default().haikunate({ tokenHex: true });
60898
- return textInput({
60899
- question: `Where do you want to create your application?`,
60900
- helpText: "also used as application name",
60901
- renderSubmitted: (value) => {
60902
- return `${brandColor("dir")} ${dim(value)}`;
60903
- },
60904
- defaultValue,
60905
- acceptDefault,
60906
- validate: (value = defaultValue) => validateProjectDirectory(value)
60907
- });
60908
- };
60909
- var validateType = async (type, { acceptDefault = false } = {}) => {
60910
- const templateOptions = Object.entries(templateMap).filter(([_3, { hidden: hidden2 }]) => !hidden2).map(([value, { label }]) => ({ value, label }));
60911
- type = await selectInput({
60912
- question: "What type of application do you want to create?",
60913
- options: templateOptions,
60914
- renderSubmitted: (option) => {
60915
- return `${brandColor("type")} ${dim(option.label)}`;
60916
- },
60917
- defaultValue: type ?? "hello-world",
60918
- acceptDefault
60919
- });
60920
- if (!type || !Object.keys(templateMap).includes(type)) {
60921
- crash("An application type must be specified to continue.");
60922
- }
60923
- return type;
60924
- };
60925
61068
  var templateMap = {
60926
61069
  webFramework: {
60927
61070
  label: "Website or web app",
@@ -60959,7 +61102,9 @@ var templateMap = {
60959
61102
  main(process.argv).catch((e) => crash(e));
60960
61103
  // Annotate the CommonJS export names for ESM import in node:
60961
61104
  0 && (module.exports = {
60962
- main
61105
+ C3_DEFAULTS,
61106
+ main,
61107
+ parseArgs
60963
61108
  });
60964
61109
  /*! Bundled license information:
60965
61110