create-cloudflare 0.0.0-cb26366c → 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.
- package/dist/cli.js +70 -2
- 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-ccc19d57";
|
|
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,
|