create-cloudflare 0.0.0-ec358f4f → 0.0.0-f753f3af
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 +94 -6
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -59410,7 +59410,7 @@ var Yargs = YargsFactory(esm_default);
|
|
|
59410
59410
|
var yargs_default = Yargs;
|
|
59411
59411
|
|
|
59412
59412
|
// package.json
|
|
59413
|
-
var version = "0.0.0-
|
|
59413
|
+
var version = "0.0.0-f753f3af";
|
|
59414
59414
|
|
|
59415
59415
|
// src/common.ts
|
|
59416
59416
|
var import_fs6 = require("fs");
|
|
@@ -60024,6 +60024,9 @@ var readJSON = (path3) => {
|
|
|
60024
60024
|
const contents = readFile(path3);
|
|
60025
60025
|
return contents ? JSON.parse(contents) : contents;
|
|
60026
60026
|
};
|
|
60027
|
+
var writeJSON = (path3, object, stringifySpace) => {
|
|
60028
|
+
writeFile2(path3, JSON.stringify(object, null, stringifySpace));
|
|
60029
|
+
};
|
|
60027
60030
|
var probePaths = (paths, errorMsg = "Failed to find required file.") => {
|
|
60028
60031
|
for (const path3 of paths) {
|
|
60029
60032
|
if ((0, import_fs7.existsSync)(path3)) {
|
|
@@ -60036,6 +60039,35 @@ var probePaths = (paths, errorMsg = "Failed to find required file.") => {
|
|
|
60036
60039
|
var usesTypescript = (projectRoot = ".") => {
|
|
60037
60040
|
return (0, import_fs7.existsSync)(`${projectRoot}/tsconfig.json`);
|
|
60038
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
|
+
};
|
|
60039
60071
|
var compatDateFlag = () => {
|
|
60040
60072
|
const date = /* @__PURE__ */ new Date();
|
|
60041
60073
|
return `--compatibility-date=${date.toISOString().slice(0, 10)}`;
|
|
@@ -60341,14 +60373,50 @@ var configure3 = async (ctx) => {
|
|
|
60341
60373
|
);
|
|
60342
60374
|
writeFile2(handlerPath, handlerFile);
|
|
60343
60375
|
updateStatus("Created an example API route handler");
|
|
60376
|
+
const installEslintPlugin = await shouldInstallNextOnPagesEslintPlugin(ctx);
|
|
60377
|
+
if (installEslintPlugin) {
|
|
60378
|
+
await writeEslintrc(ctx);
|
|
60379
|
+
}
|
|
60344
60380
|
process.chdir(projectName);
|
|
60345
|
-
const packages = [
|
|
60381
|
+
const packages = [
|
|
60382
|
+
"@cloudflare/next-on-pages@1",
|
|
60383
|
+
"vercel",
|
|
60384
|
+
...installEslintPlugin ? ["eslint-plugin-next-on-pages"] : []
|
|
60385
|
+
];
|
|
60346
60386
|
await installPackages(packages, {
|
|
60347
60387
|
dev: true,
|
|
60348
60388
|
startText: "Adding the Cloudflare Pages adapter",
|
|
60349
60389
|
doneText: `${brandColor(`installed`)} ${dim(packages.join(", "))}`
|
|
60350
60390
|
});
|
|
60351
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
|
+
};
|
|
60352
60420
|
var config6 = {
|
|
60353
60421
|
generate: generate6,
|
|
60354
60422
|
configure: configure3,
|
|
@@ -60385,6 +60453,7 @@ var generate7 = async (ctx) => {
|
|
|
60385
60453
|
};
|
|
60386
60454
|
var configure4 = async (ctx) => {
|
|
60387
60455
|
process.chdir(ctx.project.path);
|
|
60456
|
+
writeFile2("./.node-version", "17");
|
|
60388
60457
|
await npmInstall();
|
|
60389
60458
|
};
|
|
60390
60459
|
var config7 = {
|
|
@@ -60392,8 +60461,9 @@ var config7 = {
|
|
|
60392
60461
|
configure: configure4,
|
|
60393
60462
|
displayName: "Nuxt",
|
|
60394
60463
|
packageScripts: {
|
|
60464
|
+
build: (cmd) => `NITRO_PRESET=cloudflare-pages ${cmd}`,
|
|
60395
60465
|
"pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- npm run dev`,
|
|
60396
|
-
"pages:deploy":
|
|
60466
|
+
"pages:deploy": "npm run build && wrangler pages deploy ./dist"
|
|
60397
60467
|
}
|
|
60398
60468
|
};
|
|
60399
60469
|
var nuxt_default = config7;
|
|
@@ -60743,11 +60813,29 @@ var updatePackageScripts = async (ctx) => {
|
|
|
60743
60813
|
const { packageScripts } = ctx.framework?.config ?? {};
|
|
60744
60814
|
if (packageScripts) {
|
|
60745
60815
|
const s = spinner();
|
|
60746
|
-
|
|
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
|
+
);
|
|
60747
60823
|
const pkgJsonPath = (0, import_path8.resolve)("package.json");
|
|
60748
60824
|
const pkgConfig = readJSON(pkgJsonPath);
|
|
60749
|
-
Object.entries(packageScripts).forEach(([target,
|
|
60750
|
-
|
|
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
|
+
}
|
|
60751
60839
|
});
|
|
60752
60840
|
writeFile2(pkgJsonPath, JSON.stringify(pkgConfig, null, 2));
|
|
60753
60841
|
s.stop(`${brandColor("added")} ${dim("commands to `package.json`")}`);
|