create-cloudflare 0.0.0-e4ef867c → 0.0.0-e600f029

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.
Files changed (2) hide show
  1. package/dist/cli.js +129 -27
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -53155,8 +53155,6 @@ var space = (n = 1) => {
53155
53155
  return hidden("\u200A".repeat(n));
53156
53156
  };
53157
53157
  var logRaw = (msg) => {
53158
- if (process.env.VITEST)
53159
- return;
53160
53158
  process.stdout.write(`${msg}
53161
53159
  `);
53162
53160
  };
@@ -54509,9 +54507,9 @@ var getConfirmRenderers = (config14) => {
54509
54507
  cancel: handleCancel
54510
54508
  };
54511
54509
  };
54510
+ var spinnerFrames = ["\u2524", "\u2518", "\u2534", "\u2514", "\u251C", "\u250C", "\u252C", "\u2510"];
54511
+ var ellipsisFrames = ["", ".", "..", "...", " ..", " .", ""];
54512
54512
  var spinner = () => {
54513
- const spinnerFrames = ["\u2524", "\u2518", "\u2534", "\u2514", "\u251C", "\u250C", "\u252C", "\u2510"];
54514
- const ellipsisFrames = ["", ".", "..", "...", " ..", " .", ""];
54515
54513
  const color = brandColor;
54516
54514
  const frameRate = 120;
54517
54515
  let loop = null;
@@ -59412,7 +59410,7 @@ var Yargs = YargsFactory(esm_default);
59412
59410
  var yargs_default = Yargs;
59413
59411
 
59414
59412
  // package.json
59415
- var version = "0.0.0-e4ef867c";
59413
+ var version = "0.0.0-e600f029";
59416
59414
 
59417
59415
  // src/common.ts
59418
59416
  var import_fs6 = require("fs");
@@ -59473,15 +59471,14 @@ var runCommand = async (command2, opts = {}) => {
59473
59471
  }
59474
59472
  return printAsyncStatus({
59475
59473
  useSpinner: opts.useSpinner ?? opts.silent,
59476
- startText: opts.startText || command2.join(" "),
59474
+ startText: opts.startText || command2.join(" ").trim(),
59477
59475
  doneText: opts.doneText,
59478
59476
  promise() {
59479
59477
  const [executable, ...args] = command2;
59480
- const squelch = opts.silent || process.env.VITEST;
59481
59478
  const cmd = (0, import_cross_spawn.spawn)(executable, [...args], {
59482
59479
  // TODO: ideally inherit stderr, but npm install uses this for warnings
59483
59480
  // stdio: [ioMode, ioMode, "inherit"],
59484
- stdio: squelch ? "pipe" : "inherit",
59481
+ stdio: opts.silent ? "pipe" : "inherit",
59485
59482
  env: {
59486
59483
  ...process.env,
59487
59484
  ...opts.env
@@ -59489,7 +59486,7 @@ var runCommand = async (command2, opts = {}) => {
59489
59486
  cwd: opts.cwd
59490
59487
  });
59491
59488
  let output = ``;
59492
- if (opts?.captureOutput ?? squelch) {
59489
+ if (opts.captureOutput ?? opts.silent) {
59493
59490
  cmd.stdout?.on("data", (data) => {
59494
59491
  output += data;
59495
59492
  });
@@ -59804,7 +59801,7 @@ var runDeploy = async (ctx) => {
59804
59801
  const result = await runCommand(deployCmd, {
59805
59802
  silent: true,
59806
59803
  cwd: ctx.project.path,
59807
- env: { CLOUDFLARE_ACCOUNT_ID: ctx.account.id },
59804
+ env: { CLOUDFLARE_ACCOUNT_ID: ctx.account.id, NODE_ENV: "production" },
59808
59805
  startText: `Deploying your application`,
59809
59806
  doneText: `${brandColor("deployed")} ${dim(`via \`${deployCmd}\``)}`
59810
59807
  });
@@ -59853,7 +59850,7 @@ var chooseAccount = async (ctx) => {
59853
59850
  };
59854
59851
  var printSummary = async (ctx) => {
59855
59852
  const nextSteps = [
59856
- [`Navigate to the new directory:`, `cd ${ctx.project.name}`],
59853
+ [`Navigate to the new directory`, `cd ${ctx.project.name}`],
59857
59854
  [
59858
59855
  `Run the development server`,
59859
59856
  `${npm} run ${ctx.framework?.config.devCommand ?? "start"}`
@@ -59980,6 +59977,24 @@ async function initializeGit(cwd) {
59980
59977
  await runCommand(`git init`, { useSpinner: false, silent: true, cwd });
59981
59978
  }
59982
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
+ }
59983
59998
 
59984
59999
  // src/pages.ts
59985
60000
  var import_path8 = require("path");
@@ -60009,6 +60024,9 @@ var readJSON = (path3) => {
60009
60024
  const contents = readFile(path3);
60010
60025
  return contents ? JSON.parse(contents) : contents;
60011
60026
  };
60027
+ var writeJSON = (path3, object, stringifySpace) => {
60028
+ writeFile2(path3, JSON.stringify(object, null, stringifySpace));
60029
+ };
60012
60030
  var probePaths = (paths, errorMsg = "Failed to find required file.") => {
60013
60031
  for (const path3 of paths) {
60014
60032
  if ((0, import_fs7.existsSync)(path3)) {
@@ -60021,6 +60039,35 @@ var probePaths = (paths, errorMsg = "Failed to find required file.") => {
60021
60039
  var usesTypescript = (projectRoot = ".") => {
60022
60040
  return (0, import_fs7.existsSync)(`${projectRoot}/tsconfig.json`);
60023
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
+ };
60024
60071
  var compatDateFlag = () => {
60025
60072
  const date = /* @__PURE__ */ new Date();
60026
60073
  return `--compatibility-date=${date.toISOString().slice(0, 10)}`;
@@ -60326,14 +60373,50 @@ var configure3 = async (ctx) => {
60326
60373
  );
60327
60374
  writeFile2(handlerPath, handlerFile);
60328
60375
  updateStatus("Created an example API route handler");
60376
+ const installEslintPlugin = await shouldInstallNextOnPagesEslintPlugin(ctx);
60377
+ if (installEslintPlugin) {
60378
+ await writeEslintrc(ctx);
60379
+ }
60329
60380
  process.chdir(projectName);
60330
- 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
+ ];
60331
60386
  await installPackages(packages, {
60332
60387
  dev: true,
60333
60388
  startText: "Adding the Cloudflare Pages adapter",
60334
60389
  doneText: `${brandColor(`installed`)} ${dim(packages.join(", "))}`
60335
60390
  });
60336
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
+ };
60337
60420
  var config6 = {
60338
60421
  generate: generate6,
60339
60422
  configure: configure3,
@@ -60352,7 +60435,7 @@ var config6 = {
60352
60435
  "--src-dir",
60353
60436
  "--app",
60354
60437
  "--import-alias",
60355
- '"@/*"'
60438
+ "@/*"
60356
60439
  ],
60357
60440
  compatibilityFlags: ["nodejs_compat"]
60358
60441
  };
@@ -60370,6 +60453,7 @@ var generate7 = async (ctx) => {
60370
60453
  };
60371
60454
  var configure4 = async (ctx) => {
60372
60455
  process.chdir(ctx.project.path);
60456
+ writeFile2("./.node-version", "17");
60373
60457
  await npmInstall();
60374
60458
  };
60375
60459
  var config7 = {
@@ -60377,8 +60461,9 @@ var config7 = {
60377
60461
  configure: configure4,
60378
60462
  displayName: "Nuxt",
60379
60463
  packageScripts: {
60464
+ build: (cmd) => `NITRO_PRESET=cloudflare-pages ${cmd}`,
60380
60465
  "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- npm run dev`,
60381
- "pages:deploy": `NODE_VERSION=17 npm run generate && wrangler pages deploy ./dist`
60466
+ "pages:deploy": "npm run build && wrangler pages deploy ./dist"
60382
60467
  }
60383
60468
  };
60384
60469
  var nuxt_default = config7;
@@ -60728,11 +60813,29 @@ var updatePackageScripts = async (ctx) => {
60728
60813
  const { packageScripts } = ctx.framework?.config ?? {};
60729
60814
  if (packageScripts) {
60730
60815
  const s = spinner();
60731
- 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
+ );
60732
60823
  const pkgJsonPath = (0, import_path8.resolve)("package.json");
60733
60824
  const pkgConfig = readJSON(pkgJsonPath);
60734
- Object.entries(packageScripts).forEach(([target, command2]) => {
60735
- 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
+ }
60736
60839
  });
60737
60840
  writeFile2(pkgJsonPath, JSON.stringify(pkgConfig, null, 2));
60738
60841
  s.stop(`${brandColor("added")} ${dim("commands to `package.json`")}`);
@@ -60748,7 +60851,8 @@ var createProject = async (ctx) => {
60748
60851
  const CLOUDFLARE_ACCOUNT_ID = ctx.account.id;
60749
60852
  const compatFlags = ctx.framework?.config.compatibilityFlags?.join(" ");
60750
60853
  const compatFlagsArg = compatFlags ? `--compatibility-flags ${compatFlags}` : "";
60751
- 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}`;
60752
60856
  try {
60753
60857
  await retry(
60754
60858
  CREATE_PROJECT_RETRIES,
@@ -60757,7 +60861,7 @@ var createProject = async (ctx) => {
60757
60861
  cwd: ctx.project.path,
60758
60862
  env: { CLOUDFLARE_ACCOUNT_ID },
60759
60863
  startText: "Creating Pages project",
60760
- doneText: `${brandColor("created")} ${dim(`via \`${cmd}\``)}`
60864
+ doneText: `${brandColor("created")} ${dim(`via \`${cmd.trim()}\``)}`
60761
60865
  })
60762
60866
  );
60763
60867
  } catch (error) {
@@ -60791,14 +60895,12 @@ var runWorkersGenerator = async (args) => {
60791
60895
  await printSummary(ctx);
60792
60896
  };
60793
60897
  async function getTemplate(ctx) {
60794
- if (ctx.args.ts === void 0) {
60795
- ctx.args.ts = await processArgument(ctx.args, "ts", {
60796
- type: "confirm",
60797
- question: "Do you want to use TypeScript?",
60798
- label: "typescript",
60799
- defaultValue: C3_DEFAULTS.ts
60800
- });
60801
- }
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
+ });
60802
60904
  const preexisting = ctx.args.type === "pre-existing";
60803
60905
  const template = preexisting ? "hello-world" : ctx.args.type;
60804
60906
  const path3 = (0, import_path9.resolve)(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cloudflare",
3
- "version": "0.0.0-e4ef867c",
3
+ "version": "0.0.0-e600f029",
4
4
  "description": "A CLI for creating and deploying new applications to Cloudflare.",
5
5
  "keywords": [
6
6
  "cloudflare",