create-cloudflare 0.0.0-cc9ced83 → 0.0.0-ccc19d57

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());
@@ -53153,8 +53155,6 @@ var space = (n = 1) => {
53153
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,174 +54347,165 @@ 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 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
- }
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);
54410
54360
  return value;
54411
54361
  };
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;
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);
54442
54376
  }
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;
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
+ });
54457
54388
  } else {
54458
- value = await prompt.prompt();
54459
- if (eD(value)) {
54460
- cancel("Operation cancelled.");
54461
- process.exit(0);
54462
- }
54389
+ prompt = new oD({
54390
+ ...promptConfig,
54391
+ defaultValue: String(promptConfig.defaultValue),
54392
+ render() {
54393
+ return dispatchRender(this);
54394
+ }
54395
+ });
54463
54396
  }
54464
- 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}`];
54408
+ };
54409
+ var handleCancel = () => {
54410
+ cancel("Operation cancelled.");
54411
+ process.exit(0);
54465
54412
  };
54466
- var confirmInput = async (opts) => {
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) => {
54467
54424
  const {
54468
- activeText,
54469
- inactiveText,
54425
+ defaultValue,
54470
54426
  question,
54471
- renderSubmitted,
54472
- defaultValue = true,
54473
- acceptDefault
54474
- } = opts;
54475
- 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 ?? "";
54476
54491
  const active = activeText || "Yes";
54477
54492
  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;
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
+ };
54518
54509
  };
54519
54510
  var spinner = () => {
54520
54511
  const spinnerFrames = ["\u2524", "\u2518", "\u2534", "\u2514", "\u251C", "\u250C", "\u252C", "\u2510"];
@@ -59419,7 +59410,7 @@ var Yargs = YargsFactory(esm_default);
59419
59410
  var yargs_default = Yargs;
59420
59411
 
59421
59412
  // package.json
59422
- var version = "0.0.0-cc9ced83";
59413
+ var version = "0.0.0-ccc19d57";
59423
59414
 
59424
59415
  // src/common.ts
59425
59416
  var import_fs6 = require("fs");
@@ -59480,15 +59471,14 @@ var runCommand = async (command2, opts = {}) => {
59480
59471
  }
59481
59472
  return printAsyncStatus({
59482
59473
  useSpinner: opts.useSpinner ?? opts.silent,
59483
- startText: opts.startText || command2.join(" "),
59474
+ startText: opts.startText || command2.join(" ").trim(),
59484
59475
  doneText: opts.doneText,
59485
59476
  promise() {
59486
59477
  const [executable, ...args] = command2;
59487
- const squelch = opts.silent || process.env.VITEST;
59488
59478
  const cmd = (0, import_cross_spawn.spawn)(executable, [...args], {
59489
59479
  // TODO: ideally inherit stderr, but npm install uses this for warnings
59490
59480
  // stdio: [ioMode, ioMode, "inherit"],
59491
- stdio: squelch ? "pipe" : "inherit",
59481
+ stdio: opts.silent ? "pipe" : "inherit",
59492
59482
  env: {
59493
59483
  ...process.env,
59494
59484
  ...opts.env
@@ -59496,7 +59486,7 @@ var runCommand = async (command2, opts = {}) => {
59496
59486
  cwd: opts.cwd
59497
59487
  });
59498
59488
  let output = ``;
59499
- if (opts?.captureOutput ?? squelch) {
59489
+ if (opts.captureOutput ?? opts.silent) {
59500
59490
  cmd.stdout?.on("data", (data) => {
59501
59491
  output += data;
59502
59492
  });
@@ -59521,6 +59511,9 @@ var runCommand = async (command2, opts = {}) => {
59521
59511
  }
59522
59512
  }
59523
59513
  });
59514
+ cmd.on("error", (code) => {
59515
+ reject(code);
59516
+ });
59524
59517
  });
59525
59518
  }
59526
59519
  });
@@ -59631,10 +59624,14 @@ var installWrangler = async () => {
59631
59624
  };
59632
59625
  var isLoggedIn = async () => {
59633
59626
  const { npx: npx6 } = detectPackageManager();
59634
- const output = await runCommand(`${npx6} wrangler whoami`, {
59635
- silent: true
59636
- });
59637
- 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
+ }
59638
59635
  };
59639
59636
  var wranglerLogin = async () => {
59640
59637
  const { npx: npx6 } = detectPackageManager();
@@ -59779,14 +59776,12 @@ var setupProjectDirectory = (args) => {
59779
59776
  };
59780
59777
  var offerToDeploy = async (ctx) => {
59781
59778
  startSection(`Deploy with Cloudflare`, `Step 3 of 3`);
59782
- 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",
59783
59782
  question: "Do you want to deploy your application?",
59784
- renderSubmitted: (value) => `${brandColor(value ? `yes` : `no`)} ${dim(
59785
- `deploying via \`${npm} run ${ctx.framework?.config.deployCommand ?? "deploy"}\``
59786
- )}`,
59787
- defaultValue: ctx.args.deploy ?? (ctx.args.wranglerDefaults ? false : true),
59788
- // if --wrangler-defaults, default to false, otherwise default to true
59789
- acceptDefault: ctx.args.wranglerDefaults
59783
+ label,
59784
+ defaultValue: C3_DEFAULTS.deploy
59790
59785
  });
59791
59786
  if (!ctx.args.deploy)
59792
59787
  return;
@@ -59840,14 +59835,12 @@ var chooseAccount = async (ctx) => {
59840
59835
  label: name,
59841
59836
  value: id
59842
59837
  }));
59843
- accountId = await selectInput({
59838
+ accountId = await inputPrompt({
59839
+ type: "select",
59844
59840
  question: "Which account do you want to use?",
59845
59841
  options: accountOptions,
59846
- renderSubmitted: (option) => {
59847
- return `${brandColor("account")} ${dim(option.label)}`;
59848
- },
59849
- defaultValue: accountOptions[0].value,
59850
- acceptDefault: ctx.args.wranglerDefaults
59842
+ label: "account",
59843
+ defaultValue: accountOptions[0].value
59851
59844
  });
59852
59845
  }
59853
59846
  const accountName = Object.keys(accounts).find(
@@ -59857,6 +59850,7 @@ var chooseAccount = async (ctx) => {
59857
59850
  };
59858
59851
  var printSummary = async (ctx) => {
59859
59852
  const nextSteps = [
59853
+ [`Navigate to the new directory`, `cd ${ctx.project.name}`],
59860
59854
  [
59861
59855
  `Run the development server`,
59862
59856
  `${npm} run ${ctx.framework?.config.devCommand ?? "start"}`
@@ -59919,11 +59913,11 @@ var offerGit = async (ctx) => {
59919
59913
  const insideGitRepo = await isInsideGitRepo(ctx.project.path);
59920
59914
  if (insideGitRepo)
59921
59915
  return;
59922
- ctx.args.git ??= await confirmInput({
59916
+ ctx.args.git = await processArgument(ctx.args, "git", {
59917
+ type: "confirm",
59923
59918
  question: "Do you want to use git for version control?",
59924
- renderSubmitted: (value) => `${brandColor("git")} ${dim(value ? `yes` : `no`)}`,
59925
- defaultValue: true,
59926
- acceptDefault: ctx.args.wranglerDefaults
59919
+ label: "git",
59920
+ defaultValue: C3_DEFAULTS.git
59927
59921
  });
59928
59922
  if (ctx.args.git) {
59929
59923
  await printAsyncStatus({
@@ -59983,6 +59977,24 @@ async function initializeGit(cwd) {
59983
59977
  await runCommand(`git init`, { useSpinner: false, silent: true, cwd });
59984
59978
  }
59985
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
+ }
59986
59998
 
59987
59999
  // src/pages.ts
59988
60000
  var import_path8 = require("path");
@@ -60012,6 +60024,9 @@ var readJSON = (path3) => {
60012
60024
  const contents = readFile(path3);
60013
60025
  return contents ? JSON.parse(contents) : contents;
60014
60026
  };
60027
+ var writeJSON = (path3, object, stringifySpace) => {
60028
+ writeFile2(path3, JSON.stringify(object, null, stringifySpace));
60029
+ };
60015
60030
  var probePaths = (paths, errorMsg = "Failed to find required file.") => {
60016
60031
  for (const path3 of paths) {
60017
60032
  if ((0, import_fs7.existsSync)(path3)) {
@@ -60024,6 +60039,35 @@ var probePaths = (paths, errorMsg = "Failed to find required file.") => {
60024
60039
  var usesTypescript = (projectRoot = ".") => {
60025
60040
  return (0, import_fs7.existsSync)(`${projectRoot}/tsconfig.json`);
60026
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
+ };
60027
60071
  var compatDateFlag = () => {
60028
60072
  const date = /* @__PURE__ */ new Date();
60029
60073
  return `--compatibility-date=${date.toISOString().slice(0, 10)}`;
@@ -60191,25 +60235,19 @@ var docusaurus_default = config3;
60191
60235
  var { npm: npm4, dlx: dlx4 } = detectPackageManager();
60192
60236
  var generate4 = async (ctx) => {
60193
60237
  const defaultTemplate = "https://github.com/gatsbyjs/gatsby-starter-blog";
60194
- const useTemplate = await confirmInput({
60238
+ const useTemplate = await inputPrompt({
60239
+ type: "confirm",
60195
60240
  question: "Would you like to use a template?",
60196
- renderSubmitted: (value) => {
60197
- const status2 = value ? "yes" : "no";
60198
- return `${brandColor(`template`)} ${status2}`;
60199
- },
60200
- defaultValue: true,
60201
- acceptDefault: false
60241
+ label: "template",
60242
+ defaultValue: true
60202
60243
  });
60203
60244
  let templateUrl = "";
60204
60245
  if (useTemplate) {
60205
- templateUrl = await textInput({
60246
+ templateUrl = await inputPrompt({
60247
+ type: "text",
60206
60248
  question: `Please specify the url of the template you'd like to use`,
60207
- renderSubmitted: (value) => {
60208
- const result = `Using template \`${value}\``;
60209
- return `${brandColor("template")} ${dim(result)}`;
60210
- },
60211
- defaultValue: defaultTemplate,
60212
- acceptDefault: false
60249
+ label: "template",
60250
+ defaultValue: defaultTemplate
60213
60251
  });
60214
60252
  }
60215
60253
  const version2 = getFrameworkVersion(ctx);
@@ -60335,14 +60373,50 @@ var configure3 = async (ctx) => {
60335
60373
  );
60336
60374
  writeFile2(handlerPath, handlerFile);
60337
60375
  updateStatus("Created an example API route handler");
60376
+ const installEslintPlugin = await shouldInstallNextOnPagesEslintPlugin(ctx);
60377
+ if (installEslintPlugin) {
60378
+ await writeEslintrc(ctx);
60379
+ }
60338
60380
  process.chdir(projectName);
60339
- 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
+ ];
60340
60386
  await installPackages(packages, {
60341
60387
  dev: true,
60342
60388
  startText: "Adding the Cloudflare Pages adapter",
60343
60389
  doneText: `${brandColor(`installed`)} ${dim(packages.join(", "))}`
60344
60390
  });
60345
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
+ };
60346
60420
  var config6 = {
60347
60421
  generate: generate6,
60348
60422
  configure: configure3,
@@ -60379,6 +60453,7 @@ var generate7 = async (ctx) => {
60379
60453
  };
60380
60454
  var configure4 = async (ctx) => {
60381
60455
  process.chdir(ctx.project.path);
60456
+ writeFile2("./.node-version", "17");
60382
60457
  await npmInstall();
60383
60458
  };
60384
60459
  var config7 = {
@@ -60386,8 +60461,9 @@ var config7 = {
60386
60461
  configure: configure4,
60387
60462
  displayName: "Nuxt",
60388
60463
  packageScripts: {
60464
+ build: (cmd) => `NITRO_PRESET=cloudflare-pages ${cmd}`,
60389
60465
  "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- npm run dev`,
60390
- "pages:deploy": `NODE_VERSION=17 npm run generate && wrangler pages deploy ./dist`
60466
+ "pages:deploy": "npm run build && wrangler pages deploy ./dist"
60391
60467
  }
60392
60468
  };
60393
60469
  var nuxt_default = config7;
@@ -60502,7 +60578,7 @@ var config11 = {
60502
60578
  displayName: "Solid",
60503
60579
  packageScripts: {
60504
60580
  "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- ${npm9} run dev`,
60505
- "pages:deploy": `${npm9} run build build && wrangler pages deploy ./dist/public`
60581
+ "pages:deploy": `${npm9} run build && wrangler pages deploy ./dist/public`
60506
60582
  }
60507
60583
  };
60508
60584
  var solid_default = config11;
@@ -60613,7 +60689,7 @@ var versionMap_default = {
60613
60689
  astro: "3.1.5",
60614
60690
  docusaurus: "2.4.1",
60615
60691
  gatsby: "5.10.0",
60616
- hono: "0.2.0",
60692
+ hono: "0.2.6",
60617
60693
  next: "13.4.2",
60618
60694
  nuxt: "3.4.2",
60619
60695
  qwik: "1.1.x",
@@ -60718,14 +60794,12 @@ var getFrameworkSelection = async (args) => {
60718
60794
  value: key
60719
60795
  })
60720
60796
  );
60721
- const framework = await selectInput({
60797
+ const framework = await processArgument(args, "framework", {
60798
+ type: "select",
60799
+ label: "framework",
60722
60800
  question: "Which development framework do you want to use?",
60723
60801
  options: frameworkOptions,
60724
- renderSubmitted: (option) => {
60725
- return `${brandColor("framework")} ${dim(option.label)}`;
60726
- },
60727
- defaultValue: args.framework ?? "svelte",
60728
- acceptDefault: Boolean(args.framework)
60802
+ defaultValue: C3_DEFAULTS.framework
60729
60803
  });
60730
60804
  framework || crash("A framework must be selected to continue.");
60731
60805
  if (!supportedFramework(framework)) {
@@ -60739,11 +60813,29 @@ var updatePackageScripts = async (ctx) => {
60739
60813
  const { packageScripts } = ctx.framework?.config ?? {};
60740
60814
  if (packageScripts) {
60741
60815
  const s = spinner();
60742
- 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
+ );
60743
60823
  const pkgJsonPath = (0, import_path8.resolve)("package.json");
60744
60824
  const pkgConfig = readJSON(pkgJsonPath);
60745
- Object.entries(packageScripts).forEach(([target, command2]) => {
60746
- 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
+ }
60747
60839
  });
60748
60840
  writeFile2(pkgJsonPath, JSON.stringify(pkgConfig, null, 2));
60749
60841
  s.stop(`${brandColor("added")} ${dim("commands to `package.json`")}`);
@@ -60759,7 +60851,8 @@ var createProject = async (ctx) => {
60759
60851
  const CLOUDFLARE_ACCOUNT_ID = ctx.account.id;
60760
60852
  const compatFlags = ctx.framework?.config.compatibilityFlags?.join(" ");
60761
60853
  const compatFlagsArg = compatFlags ? `--compatibility-flags ${compatFlags}` : "";
60762
- 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}`;
60763
60856
  try {
60764
60857
  await retry(
60765
60858
  CREATE_PROJECT_RETRIES,
@@ -60768,7 +60861,7 @@ var createProject = async (ctx) => {
60768
60861
  cwd: ctx.project.path,
60769
60862
  env: { CLOUDFLARE_ACCOUNT_ID },
60770
60863
  startText: "Creating Pages project",
60771
- doneText: `${brandColor("created")} ${dim(`via \`${cmd}\``)}`
60864
+ doneText: `${brandColor("created")} ${dim(`via \`${cmd.trim()}\``)}`
60772
60865
  })
60773
60866
  );
60774
60867
  } catch (error) {
@@ -60802,14 +60895,12 @@ var runWorkersGenerator = async (args) => {
60802
60895
  await printSummary(ctx);
60803
60896
  };
60804
60897
  async function getTemplate(ctx) {
60805
- if (ctx.args.ts === void 0) {
60806
- ctx.args.ts = await confirmInput({
60807
- question: "Do you want to use TypeScript?",
60808
- renderSubmitted: (value) => `${brandColor("typescript")} ${dim(`${value ? "yes" : "no"}`)}`,
60809
- defaultValue: true,
60810
- acceptDefault: ctx.args.wranglerDefaults
60811
- });
60812
- }
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
+ });
60813
60904
  const preexisting = ctx.args.type === "pre-existing";
60814
60905
  const template = preexisting ? "hello-world" : ctx.args.type;
60815
60906
  const path3 = (0, import_path9.resolve)(
@@ -60833,12 +60924,16 @@ async function copyExistingWorkerFiles(ctx) {
60833
60924
  if (preexisting) {
60834
60925
  await chooseAccount(ctx);
60835
60926
  if (ctx.args.existingScript === void 0) {
60836
- ctx.args.existingScript = await textInput({
60837
- question: "Please specify the name of the existing worker in this account?",
60838
- renderSubmitted: (value) => `${brandColor("worker")} ${dim(`"${value}"`)}`,
60839
- defaultValue: ctx.project.name,
60840
- acceptDefault: ctx.args.wranglerDefaults
60841
- });
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
+ );
60842
60937
  }
60843
60938
  const tempdir = await (0, import_promises3.mkdtemp)(
60844
60939
  (0, import_path9.join)((0, import_os.tmpdir)(), "c3-wrangler-init--from-dash-")
@@ -60894,19 +60989,55 @@ async function updateFiles(ctx) {
60894
60989
  }
60895
60990
 
60896
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
+ };
60897
61005
  var main = async (argv) => {
60898
61006
  const args = await parseArgs(argv);
60899
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
+ }
60900
61035
  const validatedArgs = {
60901
61036
  ...args,
60902
- projectName: await validateName(args.projectName, {
60903
- acceptDefault: args.wranglerDefaults
60904
- }),
60905
- type: await validateType(args.type, {
60906
- acceptDefault: args.wranglerDefaults
60907
- })
61037
+ type,
61038
+ projectName
60908
61039
  };
60909
- const { handler } = templateMap[validatedArgs.type];
61040
+ const { handler } = templateMap[type];
60910
61041
  await handler(validatedArgs);
60911
61042
  };
60912
61043
  var printBanner = () => {
@@ -60923,42 +61054,17 @@ var parseArgs = async (argv) => {
60923
61054
  }).option("existing-script", {
60924
61055
  type: "string",
60925
61056
  hidden: templateMap["pre-existing"].hidden
61057
+ }).option("accept-defaults", {
61058
+ alias: "y",
61059
+ type: "boolean"
60926
61060
  }).option("wrangler-defaults", { type: "boolean", hidden: true }).version(version).help().argv;
60927
61061
  return {
61062
+ ...args.wranglerDefaults && WRANGLER_DEFAULTS,
61063
+ ...args.acceptDefaults && C3_DEFAULTS,
60928
61064
  projectName: args._[0],
60929
61065
  ...args
60930
61066
  };
60931
61067
  };
60932
- var validateName = async (name, { acceptDefault = false } = {}) => {
60933
- const defaultValue = name ?? new import_haikunator.default().haikunate({ tokenHex: true });
60934
- return textInput({
60935
- question: `In which directory do you want to create your application?`,
60936
- helpText: "also used as application name",
60937
- renderSubmitted: (value) => {
60938
- return `${brandColor("dir")} ${dim(value)}`;
60939
- },
60940
- defaultValue,
60941
- acceptDefault,
60942
- validate: (value) => validateProjectDirectory(value || defaultValue),
60943
- format: (val) => `./${val}`
60944
- });
60945
- };
60946
- var validateType = async (type, { acceptDefault = false } = {}) => {
60947
- const templateOptions = Object.entries(templateMap).filter(([_3, { hidden: hidden2 }]) => !hidden2).map(([value, { label }]) => ({ value, label }));
60948
- type = await selectInput({
60949
- question: "What type of application do you want to create?",
60950
- options: templateOptions,
60951
- renderSubmitted: (option) => {
60952
- return `${brandColor("type")} ${dim(option.label)}`;
60953
- },
60954
- defaultValue: type ?? "hello-world",
60955
- acceptDefault
60956
- });
60957
- if (!type || !Object.keys(templateMap).includes(type)) {
60958
- crash("An application type must be specified to continue.");
60959
- }
60960
- return type;
60961
- };
60962
61068
  var templateMap = {
60963
61069
  webFramework: {
60964
61070
  label: "Website or web app",
@@ -60996,7 +61102,9 @@ var templateMap = {
60996
61102
  main(process.argv).catch((e) => crash(e));
60997
61103
  // Annotate the CommonJS export names for ESM import in node:
60998
61104
  0 && (module.exports = {
60999
- main
61105
+ C3_DEFAULTS,
61106
+ main,
61107
+ parseArgs
61000
61108
  });
61001
61109
  /*! Bundled license information:
61002
61110
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cloudflare",
3
- "version": "0.0.0-cc9ced83",
3
+ "version": "0.0.0-ccc19d57",
4
4
  "description": "A CLI for creating and deploying new applications to Cloudflare.",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -7,7 +7,6 @@
7
7
  "start": "wrangler dev"
8
8
  },
9
9
  "devDependencies": {
10
- "@cloudflare/workers-types": "^4.20230419.0",
11
10
  "itty-router": "^3.0.12",
12
11
  "wrangler": "^3.0.0"
13
12
  }
@@ -7,8 +7,6 @@
7
7
  "start": "wrangler dev"
8
8
  },
9
9
  "devDependencies": {
10
- "@cloudflare/workers-types": "^4.20230419.0",
11
- "typescript": "^5.0.4",
12
10
  "wrangler": "^3.0.0"
13
11
  }
14
12
  }
@@ -7,8 +7,6 @@
7
7
  "start": "wrangler dev"
8
8
  },
9
9
  "devDependencies": {
10
- "@cloudflare/workers-types": "^4.20230419.0",
11
- "typescript": "^5.0.4",
12
10
  "wrangler": "^3.0.0"
13
11
  }
14
12
  }
@@ -7,8 +7,6 @@
7
7
  "start": "wrangler dev"
8
8
  },
9
9
  "devDependencies": {
10
- "@cloudflare/workers-types": "^4.20230419.0",
11
- "typescript": "^5.0.4",
12
10
  "wrangler": "^3.0.0"
13
11
  }
14
12
  }