create-cloudflare 0.0.0-a74477f6 → 0.0.0-a7c1dd5b

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.
@@ -37,7 +37,8 @@ async function bundleMain() {
37
37
  ],
38
38
  });
39
39
 
40
- let main = result.outputFiles[0].text;
40
+ // Store the original promise (before Angular/Zone.js replaces it) on the global scope.
41
+ let main = "globalThis.OGPromise = Promise;\n" + result.outputFiles[0].text;
41
42
 
42
43
  // Patch any dynamic imports (converting `require()` calls to `import()` calls).
43
44
  main = main.replace(
@@ -45,7 +46,9 @@ async function bundleMain() {
45
46
  'promises.push(import("./" + __webpack_require__.u(chunkId)).then((mod) => installChunk(mod.default))'
46
47
  );
47
48
  // Export the fetch handler (grabbing it from the global).
48
- main += "\nexport default { fetch : globalThis.__workerFetchHandler };";
49
+ // Also Cloudflare expects `fetch()` to return an original Promise (not a ZoneAwarePromise).
50
+ main +=
51
+ "\nexport default { fetch: (request, env) => globalThis.OGPromise.resolve(globalThis.__workerFetchHandler(request, env)) };";
49
52
 
50
53
  await fs.writeFile(path.resolve(workerPath, "index.js"), main);
51
54
  }
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());
@@ -54347,174 +54349,165 @@ var logUpdateStderr = createLogUpdate(import_node_process6.default.stderr);
54347
54349
  var grayBar = gray(shapes.bar);
54348
54350
  var blCorner = gray(shapes.corners.bl);
54349
54351
  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 format3 = opts.format || ((val) => val);
54354
- const prompt = new oD({
54355
- defaultValue,
54356
- validate,
54357
- render() {
54358
- let body = "";
54359
- switch (this.state) {
54360
- case "initial":
54361
- body += `${blCorner} ${bold(question)} ${dim(helpText)}
54362
- `;
54363
- body += `${space(2)}${gray(format3(defaultValue))}
54364
- `;
54365
- break;
54366
- case "active":
54367
- body += `${blCorner} ${bold(question)} ${dim(helpText)}
54368
- `;
54369
- body += `${space(2)}${format3(this.value || dim(defaultValue))}
54370
- `;
54371
- break;
54372
- case "submit":
54373
- body += `${leftT} ${question}
54374
- `;
54375
- body += `${grayBar} ${renderSubmitted(
54376
- format3(this.value)
54377
- )}
54378
- ${grayBar}`;
54379
- break;
54380
- case "error":
54381
- body += `${leftT} ${status.error} ${dim(this.error)}
54382
- `;
54383
- body += `${grayBar}
54384
- `;
54385
- body += `${blCorner} ${question} ${dim(helpText)}
54386
- `;
54387
- body += `${space(2)}${format3(this.value)}
54388
- `;
54389
- break;
54390
- default:
54391
- break;
54392
- }
54393
- return body;
54394
- }
54395
- });
54396
- let value;
54397
- if (acceptDefault) {
54398
- logRaw(`${leftT} ${question}`);
54399
- logRaw(`${grayBar} ${renderSubmitted(defaultValue)}
54400
- ${grayBar}`);
54401
- value = defaultValue;
54402
- validate?.(value);
54403
- } else {
54404
- value = await prompt.prompt();
54405
- if (eD(value)) {
54406
- cancel("Operation cancelled.");
54407
- process.exit(0);
54408
- }
54409
- }
54352
+ var processArgument = async (args, name, promptConfig) => {
54353
+ let value = args[name];
54354
+ const renderSubmitted = getRenderers(promptConfig).submit;
54355
+ if (value !== void 0) {
54356
+ promptConfig.validate?.(value);
54357
+ const lines = renderSubmitted({ value });
54358
+ logRaw(lines.join("\n"));
54359
+ return value;
54360
+ }
54361
+ value = await inputPrompt(promptConfig);
54410
54362
  return value;
54411
54363
  };
54412
- var selectInput = async (opts) => {
54413
- const { question, options, renderSubmitted, defaultValue, acceptDefault } = opts;
54414
- const helpText = opts.helpText || ``;
54415
- const prompt = new ED({
54416
- options,
54417
- initialValue: defaultValue ?? options[0].value,
54418
- render() {
54419
- const renderOption = (opt, i) => {
54420
- const { label } = opt;
54421
- const active = i === this.cursor;
54422
- const text = active ? blue.underline(label) : dim(label);
54423
- const indicator = active ? blue(shapes.radioActive) : dim(shapes.radioInactive);
54424
- return `${space(2)}${indicator} ${text}`;
54425
- };
54426
- let body = ``;
54427
- switch (this.state) {
54428
- case "submit":
54429
- body += `${leftT} ${question}
54430
- `;
54431
- body += `${grayBar} ${renderSubmitted(options[this.cursor])}`;
54432
- body += `
54433
- ${grayBar}`;
54434
- break;
54435
- default:
54436
- body += `${blCorner} ${bold(question)} ${dim(helpText)}
54437
- `;
54438
- body += `${options.map(renderOption).join(`
54439
- `)}
54440
- `;
54441
- break;
54364
+ var inputPrompt = async (promptConfig) => {
54365
+ const renderers = getRenderers(promptConfig);
54366
+ let prompt;
54367
+ const dispatchRender = (props) => {
54368
+ const renderedLines = renderers[props.state](props);
54369
+ return renderedLines.join("\n");
54370
+ };
54371
+ if (promptConfig.type === "select") {
54372
+ prompt = new ED({
54373
+ ...promptConfig,
54374
+ options: promptConfig.options,
54375
+ initialValue: String(promptConfig.defaultValue),
54376
+ render() {
54377
+ return dispatchRender(this);
54442
54378
  }
54443
- return body;
54444
- }
54445
- });
54446
- let value;
54447
- if (acceptDefault) {
54448
- logRaw(`${leftT} ${question}`);
54449
- logRaw(
54450
- `${grayBar} ${renderSubmitted({
54451
- label: defaultValue,
54452
- value: defaultValue
54453
- })}`
54454
- );
54455
- logRaw(`${grayBar}`);
54456
- value = defaultValue;
54379
+ });
54380
+ } else if (promptConfig.type === "confirm") {
54381
+ prompt = new sD({
54382
+ ...promptConfig,
54383
+ initialValue: Boolean(promptConfig.defaultValue),
54384
+ active: promptConfig.activeText || "",
54385
+ inactive: promptConfig.inactiveText || "",
54386
+ render() {
54387
+ return dispatchRender(this);
54388
+ }
54389
+ });
54457
54390
  } else {
54458
- value = await prompt.prompt();
54459
- if (eD(value)) {
54460
- cancel("Operation cancelled.");
54461
- process.exit(0);
54462
- }
54391
+ prompt = new oD({
54392
+ ...promptConfig,
54393
+ defaultValue: String(promptConfig.defaultValue),
54394
+ render() {
54395
+ return dispatchRender(this);
54396
+ }
54397
+ });
54398
+ }
54399
+ const input = await prompt.prompt();
54400
+ if (eD(input)) {
54401
+ cancel("Operation cancelled.");
54402
+ process.exit(0);
54403
+ }
54404
+ return input;
54405
+ };
54406
+ var renderSubmit = (config14, value) => {
54407
+ const { question, label } = config14;
54408
+ const content = config14.type === "confirm" ? `${grayBar} ${brandColor(value)} ${dim(label)}` : `${grayBar} ${brandColor(label)} ${dim(value)}`;
54409
+ return [`${leftT} ${question}`, content, `${grayBar}`];
54410
+ };
54411
+ var handleCancel = () => {
54412
+ cancel("Operation cancelled.");
54413
+ process.exit(0);
54414
+ };
54415
+ var getRenderers = (config14) => {
54416
+ switch (config14.type) {
54417
+ case "select":
54418
+ return getSelectRenderers(config14);
54419
+ case "confirm":
54420
+ return getConfirmRenderers(config14);
54421
+ case "text":
54422
+ return getTextRenderers(config14);
54463
54423
  }
54464
- return value;
54465
54424
  };
54466
- var confirmInput = async (opts) => {
54425
+ var getTextRenderers = (config14) => {
54467
54426
  const {
54468
- activeText,
54469
- inactiveText,
54427
+ defaultValue,
54470
54428
  question,
54471
- renderSubmitted,
54472
- defaultValue = true,
54473
- acceptDefault
54474
- } = opts;
54475
- const helpText = opts.helpText || `(y/n)`;
54429
+ helpText: _helpText,
54430
+ format: _format
54431
+ } = config14;
54432
+ const helpText = _helpText ?? "";
54433
+ const format3 = _format ?? ((val) => String(val));
54434
+ return {
54435
+ initial: () => [
54436
+ `${blCorner} ${bold(question)} ${dim(helpText)}`,
54437
+ `${space(2)}${gray(format3(defaultValue))}`,
54438
+ ``
54439
+ // extra line for readability
54440
+ ],
54441
+ active: ({ value }) => [
54442
+ `${blCorner} ${bold(question)} ${dim(helpText)}`,
54443
+ `${space(2)}${format3(value || dim(defaultValue))}`,
54444
+ ``
54445
+ // extra line for readability
54446
+ ],
54447
+ error: ({ value, error }) => [
54448
+ `${leftT} ${status.error} ${dim(error)}`,
54449
+ `${grayBar}`,
54450
+ `${blCorner} ${question} ${dim(helpText)}`,
54451
+ `${space(2)}${format3(value)}`,
54452
+ ``
54453
+ // extra line for readability
54454
+ ],
54455
+ submit: ({ value }) => renderSubmit(config14, format3(value)),
54456
+ cancel: handleCancel
54457
+ };
54458
+ };
54459
+ var getSelectRenderers = (config14) => {
54460
+ const { options, question, helpText: _helpText } = config14;
54461
+ const helpText = _helpText ?? "";
54462
+ const defaultRenderer = ({ cursor }) => {
54463
+ const renderOption = (opt, i) => {
54464
+ const { label: optionLabel } = opt;
54465
+ const active = i === cursor;
54466
+ const text = active ? blue.underline(optionLabel) : dim(optionLabel);
54467
+ const indicator = active ? blue(shapes.radioActive) : dim(shapes.radioInactive);
54468
+ return `${space(2)}${indicator} ${text}`;
54469
+ };
54470
+ return [
54471
+ `${blCorner} ${bold(question)} ${dim(helpText)}`,
54472
+ `${options.map(renderOption).join(`
54473
+ `)}`,
54474
+ ``
54475
+ // extra line for readability
54476
+ ];
54477
+ };
54478
+ return {
54479
+ initial: defaultRenderer,
54480
+ active: defaultRenderer,
54481
+ confirm: defaultRenderer,
54482
+ error: defaultRenderer,
54483
+ submit: ({ value }) => renderSubmit(
54484
+ config14,
54485
+ options.find((o2) => o2.value === value)?.label
54486
+ ),
54487
+ cancel: handleCancel
54488
+ };
54489
+ };
54490
+ var getConfirmRenderers = (config14) => {
54491
+ const { activeText, inactiveText, question, helpText: _helpText } = config14;
54492
+ const helpText = _helpText ?? "";
54476
54493
  const active = activeText || "Yes";
54477
54494
  const inactive = inactiveText || "No";
54478
- const prompt = new sD({
54479
- active,
54480
- inactive,
54481
- initialValue: defaultValue,
54482
- render() {
54483
- const yesColor = this.value ? blue : dim;
54484
- const noColor = this.value ? dim : blue;
54485
- let body = ``;
54486
- switch (this.state) {
54487
- case "submit":
54488
- body += `${leftT} ${question}
54489
- `;
54490
- body += `${grayBar} ${renderSubmitted(this.value)}`;
54491
- body += `
54492
- ${grayBar}`;
54493
- break;
54494
- default:
54495
- body += `${blCorner} ${bold(question)} ${dim(helpText)}
54496
- `;
54497
- body += `${space(2)}${yesColor(active)} / ${noColor(inactive)}
54498
- `;
54499
- break;
54500
- }
54501
- return body;
54502
- }
54503
- });
54504
- let value;
54505
- if (acceptDefault) {
54506
- logRaw(`${leftT} ${question}`);
54507
- logRaw(`${grayBar} ${renderSubmitted(defaultValue)}`);
54508
- logRaw(`${grayBar}`);
54509
- value = defaultValue;
54510
- } else {
54511
- value = Boolean(await prompt.prompt());
54512
- if (eD(value)) {
54513
- cancel("Operation cancelled.");
54514
- process.exit(0);
54515
- }
54516
- }
54517
- return value;
54495
+ const defaultRenderer = ({ value }) => {
54496
+ const yesColor = value ? blue : dim;
54497
+ const noColor = value ? dim : blue;
54498
+ return [
54499
+ `${blCorner} ${bold(question)} ${dim(helpText)}`,
54500
+ `${space(2)}${yesColor(active)} / ${noColor(inactive)}`
54501
+ ];
54502
+ };
54503
+ return {
54504
+ initial: defaultRenderer,
54505
+ active: defaultRenderer,
54506
+ confirm: defaultRenderer,
54507
+ error: defaultRenderer,
54508
+ submit: ({ value }) => renderSubmit(config14, value ? "yes" : "no"),
54509
+ cancel: handleCancel
54510
+ };
54518
54511
  };
54519
54512
  var spinner = () => {
54520
54513
  const spinnerFrames = ["\u2524", "\u2518", "\u2534", "\u2514", "\u251C", "\u250C", "\u252C", "\u2510"];
@@ -59419,7 +59412,7 @@ var Yargs = YargsFactory(esm_default);
59419
59412
  var yargs_default = Yargs;
59420
59413
 
59421
59414
  // package.json
59422
- var version = "0.0.0-a74477f6";
59415
+ var version = "0.0.0-a7c1dd5b";
59423
59416
 
59424
59417
  // src/common.ts
59425
59418
  var import_fs6 = require("fs");
@@ -59474,26 +59467,26 @@ var detectPackageManager = () => {
59474
59467
  };
59475
59468
 
59476
59469
  // src/helpers/command.ts
59477
- var runCommand = async (command2, opts) => {
59470
+ var runCommand = async (command2, opts = {}) => {
59478
59471
  if (typeof command2 === "string") {
59479
59472
  command2 = command2.trim().replace(/\s+/g, ` `).split(" ");
59480
59473
  }
59481
59474
  return printAsyncStatus({
59482
- useSpinner: opts?.useSpinner ?? opts?.silent,
59483
- startText: opts?.startText || command2.join(" "),
59484
- doneText: opts?.doneText,
59475
+ useSpinner: opts.useSpinner ?? opts.silent,
59476
+ startText: opts.startText || command2.join(" "),
59477
+ doneText: opts.doneText,
59485
59478
  promise() {
59486
59479
  const [executable, ...args] = command2;
59487
- const squelch = opts?.silent || process.env.VITEST;
59480
+ const squelch = opts.silent || process.env.VITEST;
59488
59481
  const cmd = (0, import_cross_spawn.spawn)(executable, [...args], {
59489
59482
  // TODO: ideally inherit stderr, but npm install uses this for warnings
59490
59483
  // stdio: [ioMode, ioMode, "inherit"],
59491
59484
  stdio: squelch ? "pipe" : "inherit",
59492
59485
  env: {
59493
59486
  ...process.env,
59494
- ...opts?.env
59487
+ ...opts.env
59495
59488
  },
59496
- cwd: opts?.cwd
59489
+ cwd: opts.cwd
59497
59490
  });
59498
59491
  let output = ``;
59499
59492
  if (opts?.captureOutput ?? squelch) {
@@ -59506,10 +59499,19 @@ var runCommand = async (command2, opts) => {
59506
59499
  }
59507
59500
  return new Promise((resolve9, reject) => {
59508
59501
  cmd.on("close", (code) => {
59509
- if (code === 0) {
59510
- resolve9(stripAnsi(output));
59511
- } else {
59512
- reject(new Error(output, { cause: code }));
59502
+ try {
59503
+ if (code !== 0) {
59504
+ throw new Error(output, { cause: code });
59505
+ }
59506
+ const transformOutput = opts.transformOutput ?? ((result) => result);
59507
+ const processedOutput = transformOutput(stripAnsi(output));
59508
+ resolve9(processedOutput);
59509
+ } catch (e) {
59510
+ if (opts.fallbackOutput) {
59511
+ resolve9(opts.fallbackOutput(e));
59512
+ } else {
59513
+ reject(new Error(output, { cause: e }));
59514
+ }
59513
59515
  }
59514
59516
  });
59515
59517
  });
@@ -59522,9 +59524,11 @@ async function runCommands({ commands, ...opts }) {
59522
59524
  startText: opts.startText,
59523
59525
  doneText: opts.doneText,
59524
59526
  async promise() {
59527
+ const results = [];
59525
59528
  for (const command2 of commands) {
59526
- await runCommand(command2, { ...opts, useSpinner: false });
59529
+ results.push(await runCommand(command2, { ...opts, useSpinner: false }));
59527
59530
  }
59531
+ return results.join("\n");
59528
59532
  }
59529
59533
  });
59530
59534
  }
@@ -59541,8 +59545,9 @@ var printAsyncStatus = async ({
59541
59545
  promise = promise();
59542
59546
  }
59543
59547
  try {
59544
- await promise;
59545
- 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);
59546
59551
  } catch (err) {
59547
59552
  s?.stop(err.message);
59548
59553
  } finally {
@@ -59655,6 +59660,24 @@ var listAccounts = async () => {
59655
59660
  });
59656
59661
  return accounts;
59657
59662
  };
59663
+ async function getWorkerdCompatibilityDate() {
59664
+ const { npm: npm12 } = detectPackageManager();
59665
+ return runCommand(`${npm12} info workerd dist-tags.latest`, {
59666
+ silent: true,
59667
+ captureOutput: true,
59668
+ startText: "Retrieving current workerd compatibility date",
59669
+ transformOutput: (result) => {
59670
+ const match = result.match(/\d+\.(\d{4})(\d{2})(\d{2})\.\d+/);
59671
+ if (!match) {
59672
+ throw new Error("Could not find workerd date");
59673
+ }
59674
+ const [, year, month, date] = match;
59675
+ return `${year}-${month}-${date}`;
59676
+ },
59677
+ fallbackOutput: () => "2023-05-18",
59678
+ doneText: (output) => `${brandColor("compatibility date")} ${dim(output)}`
59679
+ });
59680
+ }
59658
59681
 
59659
59682
  // src/helpers/poll.ts
59660
59683
  var import_promises = require("node:dns/promises");
@@ -59749,14 +59772,12 @@ var setupProjectDirectory = (args) => {
59749
59772
  };
59750
59773
  var offerToDeploy = async (ctx) => {
59751
59774
  startSection(`Deploy with Cloudflare`, `Step 3 of 3`);
59752
- ctx.args.deploy = await confirmInput({
59775
+ const label = `deploy via \`${npm} run ${ctx.framework?.config.deployCommand ?? "deploy"}\``;
59776
+ ctx.args.deploy = await processArgument(ctx.args, "deploy", {
59777
+ type: "confirm",
59753
59778
  question: "Do you want to deploy your application?",
59754
- renderSubmitted: (value) => `${brandColor(value ? `yes` : `no`)} ${dim(
59755
- `deploying via \`${npm} run ${ctx.framework?.config.deployCommand ?? "deploy"}\``
59756
- )}`,
59757
- defaultValue: ctx.args.deploy ?? (ctx.args.wranglerDefaults ? false : true),
59758
- // if --wrangler-defaults, default to false, otherwise default to true
59759
- acceptDefault: ctx.args.wranglerDefaults
59779
+ label,
59780
+ defaultValue: C3_DEFAULTS.deploy
59760
59781
  });
59761
59782
  if (!ctx.args.deploy)
59762
59783
  return;
@@ -59810,14 +59831,12 @@ var chooseAccount = async (ctx) => {
59810
59831
  label: name,
59811
59832
  value: id
59812
59833
  }));
59813
- accountId = await selectInput({
59834
+ accountId = await inputPrompt({
59835
+ type: "select",
59814
59836
  question: "Which account do you want to use?",
59815
59837
  options: accountOptions,
59816
- renderSubmitted: (option) => {
59817
- return `${brandColor("account")} ${dim(option.label)}`;
59818
- },
59819
- defaultValue: accountOptions[0].value,
59820
- acceptDefault: ctx.args.wranglerDefaults
59838
+ label: "account",
59839
+ defaultValue: accountOptions[0].value
59821
59840
  });
59822
59841
  }
59823
59842
  const accountName = Object.keys(accounts).find(
@@ -59827,6 +59846,7 @@ var chooseAccount = async (ctx) => {
59827
59846
  };
59828
59847
  var printSummary = async (ctx) => {
59829
59848
  const nextSteps = [
59849
+ [`Navigate to the new directory:`, `cd ${ctx.project.name}`],
59830
59850
  [
59831
59851
  `Run the development server`,
59832
59852
  `${npm} run ${ctx.framework?.config.devCommand ?? "start"}`
@@ -59889,11 +59909,11 @@ var offerGit = async (ctx) => {
59889
59909
  const insideGitRepo = await isInsideGitRepo(ctx.project.path);
59890
59910
  if (insideGitRepo)
59891
59911
  return;
59892
- ctx.args.git ??= await confirmInput({
59912
+ ctx.args.git = await processArgument(ctx.args, "git", {
59913
+ type: "confirm",
59893
59914
  question: "Do you want to use git for version control?",
59894
- renderSubmitted: (value) => `${brandColor("git")} ${dim(value ? `yes` : `no`)}`,
59895
- defaultValue: true,
59896
- acceptDefault: ctx.args.wranglerDefaults
59915
+ label: "git",
59916
+ defaultValue: C3_DEFAULTS.git
59897
59917
  });
59898
59918
  if (ctx.args.git) {
59899
59919
  await printAsyncStatus({
@@ -60161,25 +60181,19 @@ var docusaurus_default = config3;
60161
60181
  var { npm: npm4, dlx: dlx4 } = detectPackageManager();
60162
60182
  var generate4 = async (ctx) => {
60163
60183
  const defaultTemplate = "https://github.com/gatsbyjs/gatsby-starter-blog";
60164
- const useTemplate = await confirmInput({
60184
+ const useTemplate = await inputPrompt({
60185
+ type: "confirm",
60165
60186
  question: "Would you like to use a template?",
60166
- renderSubmitted: (value) => {
60167
- const status2 = value ? "yes" : "no";
60168
- return `${brandColor(`template`)} ${status2}`;
60169
- },
60170
- defaultValue: true,
60171
- acceptDefault: false
60187
+ label: "template",
60188
+ defaultValue: true
60172
60189
  });
60173
60190
  let templateUrl = "";
60174
60191
  if (useTemplate) {
60175
- templateUrl = await textInput({
60192
+ templateUrl = await inputPrompt({
60193
+ type: "text",
60176
60194
  question: `Please specify the url of the template you'd like to use`,
60177
- renderSubmitted: (value) => {
60178
- const result = `Using template \`${value}\``;
60179
- return `${brandColor("template")} ${dim(result)}`;
60180
- },
60181
- defaultValue: defaultTemplate,
60182
- acceptDefault: false
60195
+ label: "template",
60196
+ defaultValue: defaultTemplate
60183
60197
  });
60184
60198
  }
60185
60199
  const version2 = getFrameworkVersion(ctx);
@@ -60583,7 +60597,7 @@ var versionMap_default = {
60583
60597
  astro: "3.1.5",
60584
60598
  docusaurus: "2.4.1",
60585
60599
  gatsby: "5.10.0",
60586
- hono: "0.2.0",
60600
+ hono: "0.2.6",
60587
60601
  next: "13.4.2",
60588
60602
  nuxt: "3.4.2",
60589
60603
  qwik: "1.1.x",
@@ -60688,14 +60702,12 @@ var getFrameworkSelection = async (args) => {
60688
60702
  value: key
60689
60703
  })
60690
60704
  );
60691
- const framework = await selectInput({
60705
+ const framework = await processArgument(args, "framework", {
60706
+ type: "select",
60707
+ label: "framework",
60692
60708
  question: "Which development framework do you want to use?",
60693
60709
  options: frameworkOptions,
60694
- renderSubmitted: (option) => {
60695
- return `${brandColor("framework")} ${dim(option.label)}`;
60696
- },
60697
- defaultValue: args.framework ?? "svelte",
60698
- acceptDefault: Boolean(args.framework)
60710
+ defaultValue: C3_DEFAULTS.framework
60699
60711
  });
60700
60712
  framework || crash("A framework must be selected to continue.");
60701
60713
  if (!supportedFramework(framework)) {
@@ -60773,11 +60785,11 @@ var runWorkersGenerator = async (args) => {
60773
60785
  };
60774
60786
  async function getTemplate(ctx) {
60775
60787
  if (ctx.args.ts === void 0) {
60776
- ctx.args.ts = await confirmInput({
60788
+ ctx.args.ts = await processArgument(ctx.args, "ts", {
60789
+ type: "confirm",
60777
60790
  question: "Do you want to use TypeScript?",
60778
- renderSubmitted: (value) => `${brandColor("typescript")} ${dim(`${value ? "yes" : "no"}`)}`,
60779
- defaultValue: true,
60780
- acceptDefault: ctx.args.wranglerDefaults
60791
+ label: "typescript",
60792
+ defaultValue: C3_DEFAULTS.ts
60781
60793
  });
60782
60794
  }
60783
60795
  const preexisting = ctx.args.type === "pre-existing";
@@ -60803,12 +60815,16 @@ async function copyExistingWorkerFiles(ctx) {
60803
60815
  if (preexisting) {
60804
60816
  await chooseAccount(ctx);
60805
60817
  if (ctx.args.existingScript === void 0) {
60806
- ctx.args.existingScript = await textInput({
60807
- question: "Please specify the name of the existing worker in this account?",
60808
- renderSubmitted: (value) => `${brandColor("worker")} ${dim(`"${value}"`)}`,
60809
- defaultValue: ctx.project.name,
60810
- acceptDefault: ctx.args.wranglerDefaults
60811
- });
60818
+ ctx.args.existingScript = await processArgument(
60819
+ ctx.args,
60820
+ "existingScript",
60821
+ {
60822
+ type: "text",
60823
+ question: "Please specify the name of the existing worker in this account?",
60824
+ label: "worker",
60825
+ defaultValue: ctx.project.name
60826
+ }
60827
+ );
60812
60828
  }
60813
60829
  const tempdir = await (0, import_promises3.mkdtemp)(
60814
60830
  (0, import_path9.join)((0, import_os.tmpdir)(), "c3-wrangler-init--from-dash-")
@@ -60849,10 +60865,12 @@ async function updateFiles(ctx) {
60849
60865
  packagejson: JSON.parse(await (0, import_promises3.readFile)(paths.packagejson, "utf-8")),
60850
60866
  wranglertoml: await (0, import_promises3.readFile)(paths.wranglertoml, "utf-8")
60851
60867
  };
60852
- contents.packagejson.name = ctx.project.name;
60853
- contents.wranglertoml = contents.wranglertoml.replace(/^name = .+$/m, `name = "${ctx.project.name}"`).replace(
60854
- /^compatibility_date = .+$/m,
60855
- `compatibility_date = "${(/* @__PURE__ */ new Date()).toISOString().substring(0, 10)}"`
60868
+ if (contents.packagejson.name === "<TBD>") {
60869
+ contents.packagejson.name = ctx.project.name;
60870
+ }
60871
+ contents.wranglertoml = contents.wranglertoml.replace(/^name\s*=\s*"<TBD>"/m, `name = "${ctx.project.name}"`).replace(
60872
+ /^compatibility_date\s*=\s*"<TBD>"/m,
60873
+ `compatibility_date = "${await getWorkerdCompatibilityDate()}"`
60856
60874
  );
60857
60875
  await (0, import_promises3.writeFile)(
60858
60876
  paths.packagejson,
@@ -60862,19 +60880,55 @@ async function updateFiles(ctx) {
60862
60880
  }
60863
60881
 
60864
60882
  // src/cli.ts
60883
+ var C3_DEFAULTS = {
60884
+ projectName: new import_haikunator.default().haikunate({ tokenHex: true }),
60885
+ type: "hello-world",
60886
+ framework: "angular",
60887
+ deploy: true,
60888
+ git: true,
60889
+ open: true,
60890
+ ts: true
60891
+ };
60892
+ var WRANGLER_DEFAULTS = {
60893
+ ...C3_DEFAULTS,
60894
+ deploy: false
60895
+ };
60865
60896
  var main = async (argv) => {
60866
- printBanner();
60867
60897
  const args = await parseArgs(argv);
60898
+ printBanner();
60899
+ const projectName = await processArgument(args, "projectName", {
60900
+ type: "text",
60901
+ question: `In which directory do you want to create your application?`,
60902
+ helpText: "also used as application name",
60903
+ defaultValue: C3_DEFAULTS.projectName,
60904
+ label: "dir",
60905
+ validate: (value) => validateProjectDirectory(String(value) || C3_DEFAULTS.projectName),
60906
+ format: (val) => `./${val}`
60907
+ });
60908
+ if (!args.type) {
60909
+ if (args.framework) {
60910
+ args.type = "webFramework";
60911
+ } else if (args.existingScript) {
60912
+ args.type = "pre-existing";
60913
+ }
60914
+ }
60915
+ const templateOptions = Object.entries(templateMap).filter(([_3, { hidden: hidden2 }]) => !hidden2).map(([value, { label }]) => ({ value, label }));
60916
+ const type = await processArgument(args, "type", {
60917
+ type: "select",
60918
+ question: "What type of application do you want to create?",
60919
+ label: "type",
60920
+ options: templateOptions,
60921
+ defaultValue: C3_DEFAULTS.type
60922
+ });
60923
+ if (!type || !Object.keys(templateMap).includes(type)) {
60924
+ return crash("An application type must be specified to continue.");
60925
+ }
60868
60926
  const validatedArgs = {
60869
60927
  ...args,
60870
- projectName: await validateName(args.projectName, {
60871
- acceptDefault: args.wranglerDefaults
60872
- }),
60873
- type: await validateType(args.type, {
60874
- acceptDefault: args.wranglerDefaults
60875
- })
60928
+ type,
60929
+ projectName
60876
60930
  };
60877
- const { handler } = templateMap[validatedArgs.type];
60931
+ const { handler } = templateMap[type];
60878
60932
  await handler(validatedArgs);
60879
60933
  };
60880
60934
  var printBanner = () => {
@@ -60891,42 +60945,17 @@ var parseArgs = async (argv) => {
60891
60945
  }).option("existing-script", {
60892
60946
  type: "string",
60893
60947
  hidden: templateMap["pre-existing"].hidden
60894
- }).option("wrangler-defaults", { type: "boolean", hidden: true }).help().argv;
60948
+ }).option("accept-defaults", {
60949
+ alias: "y",
60950
+ type: "boolean"
60951
+ }).option("wrangler-defaults", { type: "boolean", hidden: true }).version(version).help().argv;
60895
60952
  return {
60953
+ ...args.wranglerDefaults && WRANGLER_DEFAULTS,
60954
+ ...args.acceptDefaults && C3_DEFAULTS,
60896
60955
  projectName: args._[0],
60897
60956
  ...args
60898
60957
  };
60899
60958
  };
60900
- var validateName = async (name, { acceptDefault = false } = {}) => {
60901
- const defaultValue = name ?? new import_haikunator.default().haikunate({ tokenHex: true });
60902
- return textInput({
60903
- question: `Where do you want to create your application?`,
60904
- helpText: "also used as application name",
60905
- renderSubmitted: (value) => {
60906
- return `${brandColor("dir")} ${dim(value)}`;
60907
- },
60908
- defaultValue,
60909
- acceptDefault,
60910
- validate: (value) => validateProjectDirectory(value || defaultValue),
60911
- format: (val) => `./${val}`
60912
- });
60913
- };
60914
- var validateType = async (type, { acceptDefault = false } = {}) => {
60915
- const templateOptions = Object.entries(templateMap).filter(([_3, { hidden: hidden2 }]) => !hidden2).map(([value, { label }]) => ({ value, label }));
60916
- type = await selectInput({
60917
- question: "What type of application do you want to create?",
60918
- options: templateOptions,
60919
- renderSubmitted: (option) => {
60920
- return `${brandColor("type")} ${dim(option.label)}`;
60921
- },
60922
- defaultValue: type ?? "hello-world",
60923
- acceptDefault
60924
- });
60925
- if (!type || !Object.keys(templateMap).includes(type)) {
60926
- crash("An application type must be specified to continue.");
60927
- }
60928
- return type;
60929
- };
60930
60959
  var templateMap = {
60931
60960
  webFramework: {
60932
60961
  label: "Website or web app",
@@ -60964,7 +60993,9 @@ var templateMap = {
60964
60993
  main(process.argv).catch((e) => crash(e));
60965
60994
  // Annotate the CommonJS export names for ESM import in node:
60966
60995
  0 && (module.exports = {
60967
- main
60996
+ C3_DEFAULTS,
60997
+ main,
60998
+ parseArgs
60968
60999
  });
60969
61000
  /*! Bundled license information:
60970
61001
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cloudflare",
3
- "version": "0.0.0-a74477f6",
3
+ "version": "0.0.0-a7c1dd5b",
4
4
  "description": "A CLI for creating and deploying new applications to Cloudflare.",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -1,3 +1,3 @@
1
- name = "cloudflare-workers-chatgpt-plugin-example"
1
+ name = "<TBD>"
2
2
  main = "src/index.ts"
3
- compatibility_date = "2023-04-07"
3
+ compatibility_date = "<TBD>"
@@ -1,6 +1,6 @@
1
1
  name = "<TBD>"
2
2
  main = "src/worker.js"
3
- compatibility_date = "2023-04-21"
3
+ compatibility_date = "<TBD>"
4
4
 
5
5
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
6
6
  # Note: Use secrets to store sensitive data.
@@ -1,6 +1,6 @@
1
1
  name = "<TBD>"
2
2
  main = "src/worker.ts"
3
- compatibility_date = "2023-04-21"
3
+ compatibility_date = "<TBD>"
4
4
 
5
5
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
6
6
  # Note: Use secrets to store sensitive data.
@@ -1,6 +1,6 @@
1
1
  name = "<TBD>"
2
2
  main = "src/worker.js"
3
- compatibility_date = "2023-04-21"
3
+ compatibility_date = "<TBD>"
4
4
 
5
5
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
6
6
  # Note: Use secrets to store sensitive data.
@@ -1,6 +1,6 @@
1
1
  name = "<TBD>"
2
2
  main = "src/worker.ts"
3
- compatibility_date = "2023-04-21"
3
+ compatibility_date = "<TBD>"
4
4
 
5
5
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
6
6
  # Note: Use secrets to store sensitive data.
@@ -1,6 +1,6 @@
1
1
  name = "<TBD>"
2
2
  main = "src/worker.js"
3
- compatibility_date = "2023-05-15"
3
+ compatibility_date = "<TBD>"
4
4
 
5
5
  # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
6
6
  # Docs: https://developers.cloudflare.com/queues/get-started
@@ -1,6 +1,6 @@
1
1
  name = "<TBD>"
2
2
  main = "src/worker.ts"
3
- compatibility_date = "2023-05-15"
3
+ compatibility_date = "<TBD>"
4
4
 
5
5
  # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
6
6
  # Docs: https://developers.cloudflare.com/queues/get-started
@@ -1,6 +1,6 @@
1
1
  name = "<TBD>"
2
2
  main = "src/worker.ts"
3
- compatibility_date = "2023-05-15"
3
+ compatibility_date = "<TBD>"
4
4
 
5
5
  # Cron Triggers
6
6
  # Docs: https://developers.cloudflare.com/workers/platform/triggers/cron-triggers/