create-easy-cms 0.20.1 → 0.22.0
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/README.md +5 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-DQXRGO3T.js → chunk-DGBBIS3J.js} +180 -22
- package/dist/index.d.ts +37 -5
- package/dist/index.js +23 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
Adds [Easy CMS](https://github.com/maritonx/easy-cms) to a Nuxt or Next.js project.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
|
|
6
|
+
npm create easy-cms@latest [dir] # or: pnpm create easy-cms, yarn create easy-cms, bun create easy-cms
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
+
Options: `--db sqlite|postgres`, `--pm npm|pnpm|yarn|bun`, `--standalone`, `--yes`, `--skip-install`.
|
|
10
|
+
It installs with your project's package manager (its `packageManager` field or lockfile), or the one
|
|
11
|
+
you ran it with.
|
|
12
|
+
|
|
9
13
|
Creates `easy-cms.config.ts`, adds `EASY_CMS_SECRET` to `.env`, updates `.gitignore`, wires the
|
|
10
14
|
Nuxt module or the Next.js route handlers and config, and installs the packages. Safe to run again.
|
package/dist/bin.js
CHANGED
|
@@ -8,6 +8,104 @@ import { createInterface } from "readline/promises";
|
|
|
8
8
|
import { fileURLToPath } from "url";
|
|
9
9
|
import { parseArgs } from "util";
|
|
10
10
|
|
|
11
|
+
// src/commands.ts
|
|
12
|
+
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
13
|
+
var isPackageManager = (value) => typeof value === "string" && PACKAGE_MANAGERS.includes(value);
|
|
14
|
+
function installArgs(pm, packages, dev) {
|
|
15
|
+
const add = pm === "npm" ? "install" : "add";
|
|
16
|
+
const devFlag = pm === "npm" ? "--save-dev" : pm === "bun" ? "--dev" : "-D";
|
|
17
|
+
return [add, ...dev ? [devFlag] : [], ...packages];
|
|
18
|
+
}
|
|
19
|
+
function runScript(pm, script, args = "") {
|
|
20
|
+
const rest = args ? ` ${args}` : "";
|
|
21
|
+
if (pm === "npm") return `npm run ${script}${args ? ` --${rest}` : ""}`;
|
|
22
|
+
if (pm === "bun") return `bun run ${script}${rest}`;
|
|
23
|
+
return `${pm} ${script}${rest}`;
|
|
24
|
+
}
|
|
25
|
+
function execBin(pm, command) {
|
|
26
|
+
if (pm === "npm") return `npx ${command}`;
|
|
27
|
+
if (pm === "pnpm") return `pnpm exec ${command}`;
|
|
28
|
+
if (pm === "yarn") return `yarn ${command}`;
|
|
29
|
+
return `bunx ${command}`;
|
|
30
|
+
}
|
|
31
|
+
function dlx(pm, command) {
|
|
32
|
+
if (pm === "npm") return `npx ${command}`;
|
|
33
|
+
if (pm === "pnpm") return `pnpm dlx ${command}`;
|
|
34
|
+
if (pm === "yarn") return `yarn dlx ${command}`;
|
|
35
|
+
return `bunx ${command}`;
|
|
36
|
+
}
|
|
37
|
+
function createCommand(pm, initializer, args = "") {
|
|
38
|
+
const rest = args ? ` ${args}` : "";
|
|
39
|
+
if (pm === "npm") return `npm create ${initializer}${rest}`;
|
|
40
|
+
return `${pm} create ${initializer.replace(/@latest$/, "")}${rest}`;
|
|
41
|
+
}
|
|
42
|
+
var LOCAL_BINS = /* @__PURE__ */ new Set(["easy-cms", "nuxi", "nuxt", "next", "drizzle-kit", "vitest", "tsx"]);
|
|
43
|
+
function translateLine(line, pm) {
|
|
44
|
+
if (pm === "npm") return line;
|
|
45
|
+
const match = /^(\s*(?:[A-Z_][A-Z0-9_]*=\S*\s+)*)(.*)$/.exec(line);
|
|
46
|
+
const prefix = match[1];
|
|
47
|
+
const body = match[2];
|
|
48
|
+
const at = body.search(/\s+#/);
|
|
49
|
+
const command = (at >= 0 ? body.slice(0, at) : body).trim();
|
|
50
|
+
const comment = at >= 0 ? body.slice(at) : "";
|
|
51
|
+
const parts = command.split(/\s+&&\s+/).map((part) => [part, translateCommand(part, pm)]);
|
|
52
|
+
if (parts.every(([, t]) => t === void 0)) return line;
|
|
53
|
+
if (parts.some(([, t]) => t === null)) return null;
|
|
54
|
+
return `${prefix}${parts.map(([part, t]) => t ?? part).join(" && ")}${comment}`;
|
|
55
|
+
}
|
|
56
|
+
function translateCommand(command, pm) {
|
|
57
|
+
const words = command.split(/\s+/);
|
|
58
|
+
const [tool, sub, ...rest] = words;
|
|
59
|
+
if (tool === "npx") {
|
|
60
|
+
const [bin = "", ...args2] = words.slice(1).filter((w) => w !== "-y" && w !== "--yes");
|
|
61
|
+
const name = bin.replace(/@[^/@]*$/, "");
|
|
62
|
+
const tail = args2.join(" ");
|
|
63
|
+
if (name.startsWith("create-")) return createCommand(pm, name.slice("create-".length), tail);
|
|
64
|
+
const full = [name, ...args2].join(" ");
|
|
65
|
+
return LOCAL_BINS.has(name) ? execBin(pm, full) : dlx(pm, [bin, ...args2].join(" "));
|
|
66
|
+
}
|
|
67
|
+
if (tool !== "npm" || sub === void 0) return void 0;
|
|
68
|
+
const args = rest.join(" ");
|
|
69
|
+
switch (sub) {
|
|
70
|
+
case "create":
|
|
71
|
+
case "init": {
|
|
72
|
+
const [initializer = "", ...more] = rest;
|
|
73
|
+
return createCommand(pm, initializer, more.join(" "));
|
|
74
|
+
}
|
|
75
|
+
case "install":
|
|
76
|
+
case "i":
|
|
77
|
+
case "add": {
|
|
78
|
+
if (rest.length === 0) return `${pm} install`;
|
|
79
|
+
const dev = rest.some((w) => w === "-D" || w === "--save-dev");
|
|
80
|
+
const packages = rest.filter((w) => w !== "-D" && w !== "--save-dev");
|
|
81
|
+
if (packages.some((p) => p.startsWith("-"))) return null;
|
|
82
|
+
return [pm, ...installArgs(pm, packages, dev)].join(" ");
|
|
83
|
+
}
|
|
84
|
+
case "ci":
|
|
85
|
+
if (rest.length > 0) return null;
|
|
86
|
+
return pm === "yarn" ? "yarn install --immutable" : `${pm} install --frozen-lockfile`;
|
|
87
|
+
case "uninstall":
|
|
88
|
+
case "remove":
|
|
89
|
+
return `${pm} remove ${args}`;
|
|
90
|
+
case "run": {
|
|
91
|
+
const [script = "", ...more] = rest;
|
|
92
|
+
const passed = more[0] === "--" ? more.slice(1) : more;
|
|
93
|
+
return runScript(pm, script, passed.join(" "));
|
|
94
|
+
}
|
|
95
|
+
case "start":
|
|
96
|
+
case "test":
|
|
97
|
+
return runScript(pm, sub, args);
|
|
98
|
+
case "exec":
|
|
99
|
+
return execBin(pm, (rest[0] === "--" ? rest.slice(1) : rest).join(" "));
|
|
100
|
+
default:
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function translateCommands(code, pm) {
|
|
105
|
+
const lines = code.split("\n").map((line) => translateLine(line, pm));
|
|
106
|
+
return lines.includes(null) ? null : lines.join("\n");
|
|
107
|
+
}
|
|
108
|
+
|
|
11
109
|
// src/templates.ts
|
|
12
110
|
function configTemplate(db, options = {}) {
|
|
13
111
|
const database = db === "sqlite" ? `import { sqlite } from '@easy-cms/db-sqlite'` : `import { postgres } from '@easy-cms/db-postgres'`;
|
|
@@ -67,6 +165,7 @@ export const { GET, HEAD } = createAdminRouteHandlers(config)
|
|
|
67
165
|
}
|
|
68
166
|
|
|
69
167
|
// src/index.ts
|
|
168
|
+
var NOT_FOUND = 127;
|
|
70
169
|
var defaultIO = {
|
|
71
170
|
out: (line) => console.log(line),
|
|
72
171
|
err: (line) => console.error(line),
|
|
@@ -86,7 +185,19 @@ var defaultIO = {
|
|
|
86
185
|
shell: process.platform === "win32"
|
|
87
186
|
});
|
|
88
187
|
child.on("close", (code) => done(code ?? 1));
|
|
89
|
-
child.on(
|
|
188
|
+
child.on(
|
|
189
|
+
"error",
|
|
190
|
+
(error) => done(error.code === "ENOENT" ? NOT_FOUND : 1)
|
|
191
|
+
);
|
|
192
|
+
}),
|
|
193
|
+
capture: (command, args, cwd) => new Promise((done) => {
|
|
194
|
+
const child = spawn(command, args, { cwd, shell: process.platform === "win32" });
|
|
195
|
+
let output = "";
|
|
196
|
+
child.stdout?.on("data", (chunk) => {
|
|
197
|
+
output += String(chunk);
|
|
198
|
+
});
|
|
199
|
+
child.on("close", (code) => done(code === 0 ? output.trim() : null));
|
|
200
|
+
child.on("error", () => done(null));
|
|
90
201
|
})
|
|
91
202
|
};
|
|
92
203
|
var HELP = `Usage: create-easy-cms [dir] [options]
|
|
@@ -99,6 +210,7 @@ Options:
|
|
|
99
210
|
--standalone Set up a standalone server even in an existing project
|
|
100
211
|
--db <sqlite|postgres> Database (default: ask, or sqlite with --yes)
|
|
101
212
|
--yes, -y Accept the defaults without asking
|
|
213
|
+
--pm <npm|pnpm|yarn|bun> Package manager (default: the project's, or the one running this)
|
|
102
214
|
--skip-install Write files only; install the packages yourself
|
|
103
215
|
-h, --help Show help
|
|
104
216
|
`;
|
|
@@ -108,15 +220,40 @@ function detectFramework(pkg) {
|
|
|
108
220
|
if (deps.next) return "next";
|
|
109
221
|
return void 0;
|
|
110
222
|
}
|
|
111
|
-
function detectPackageManager(dir) {
|
|
223
|
+
function detectPackageManager(dir, explicit) {
|
|
224
|
+
if (explicit) return explicit;
|
|
225
|
+
const declared = packageManagerField(dir);
|
|
226
|
+
if (declared) return declared;
|
|
112
227
|
if (existsSync(join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
113
228
|
if (existsSync(join(dir, "yarn.lock"))) return "yarn";
|
|
114
229
|
if (existsSync(join(dir, "bun.lock")) || existsSync(join(dir, "bun.lockb"))) return "bun";
|
|
115
230
|
if (existsSync(join(dir, "package-lock.json"))) return "npm";
|
|
116
231
|
const agent = process.env.npm_config_user_agent ?? "";
|
|
117
|
-
for (const pm of ["pnpm", "yarn", "bun"]) if (agent.startsWith(pm)) return pm;
|
|
232
|
+
for (const pm of ["pnpm", "yarn", "bun"]) if (agent.startsWith(`${pm}/`)) return pm;
|
|
118
233
|
return "npm";
|
|
119
234
|
}
|
|
235
|
+
function readPackage(dir) {
|
|
236
|
+
try {
|
|
237
|
+
return JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
238
|
+
} catch {
|
|
239
|
+
return void 0;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function packageManagerField(dir) {
|
|
243
|
+
const field = readPackage(dir)?.packageManager;
|
|
244
|
+
const name = typeof field === "string" ? field.split("@")[0] : void 0;
|
|
245
|
+
return isPackageManager(name) ? name : void 0;
|
|
246
|
+
}
|
|
247
|
+
async function isYarnBerry(dir, io) {
|
|
248
|
+
const field = readPackage(dir)?.packageManager;
|
|
249
|
+
if (typeof field === "string" && field.startsWith("yarn@"))
|
|
250
|
+
return Number.parseInt(field.slice(5), 10) >= 2;
|
|
251
|
+
if (existsSync(join(dir, ".yarnrc.yml"))) return true;
|
|
252
|
+
const lock = join(dir, "yarn.lock");
|
|
253
|
+
if (existsSync(lock)) return readFileSync(lock, "utf8").includes("__metadata:");
|
|
254
|
+
const version = io.capture ? await io.capture("yarn", ["--version"], dir) : null;
|
|
255
|
+
return version !== null && Number.parseInt(version, 10) >= 2;
|
|
256
|
+
}
|
|
120
257
|
function ownVersion() {
|
|
121
258
|
try {
|
|
122
259
|
const pkg = JSON.parse(
|
|
@@ -134,11 +271,6 @@ function packagesFor(target, db) {
|
|
|
134
271
|
else deps.push(`@easy-cms/db-postgres@${v}`, "@electric-sql/pglite");
|
|
135
272
|
return { deps, devDeps: target === "standalone" ? [] : [`easy-cms@${v}`] };
|
|
136
273
|
}
|
|
137
|
-
function installArgs(pm, packages, dev) {
|
|
138
|
-
const add = pm === "npm" ? "install" : "add";
|
|
139
|
-
const devFlag = pm === "npm" ? "--save-dev" : pm === "bun" ? "--dev" : "-D";
|
|
140
|
-
return [add, ...dev ? [devFlag] : [], ...packages];
|
|
141
|
-
}
|
|
142
274
|
async function run(argv, io = defaultIO) {
|
|
143
275
|
let values;
|
|
144
276
|
let positionals;
|
|
@@ -150,6 +282,7 @@ async function run(argv, io = defaultIO) {
|
|
|
150
282
|
options: {
|
|
151
283
|
db: { type: "string" },
|
|
152
284
|
yes: { type: "boolean", short: "y" },
|
|
285
|
+
pm: { type: "string" },
|
|
153
286
|
standalone: { type: "boolean" },
|
|
154
287
|
"skip-install": { type: "boolean" },
|
|
155
288
|
help: { type: "boolean", short: "h" }
|
|
@@ -164,7 +297,12 @@ async function run(argv, io = defaultIO) {
|
|
|
164
297
|
io.out(HELP);
|
|
165
298
|
return 0;
|
|
166
299
|
}
|
|
300
|
+
if (values.pm !== void 0 && !isPackageManager(values.pm)) {
|
|
301
|
+
io.err(`--pm must be one of ${PACKAGE_MANAGERS.join(", ")} (got "${values.pm}")`);
|
|
302
|
+
return 1;
|
|
303
|
+
}
|
|
167
304
|
const dir = resolve(positionals[0] ?? process.cwd());
|
|
305
|
+
const pm = detectPackageManager(dir, values.pm);
|
|
168
306
|
const pkgFile = join(dir, "package.json");
|
|
169
307
|
const hasPackage = existsSync(pkgFile);
|
|
170
308
|
const framework = hasPackage ? detectFramework(JSON.parse(await readFile(pkgFile, "utf8"))) : void 0;
|
|
@@ -177,7 +315,7 @@ async function run(argv, io = defaultIO) {
|
|
|
177
315
|
if (!yes) {
|
|
178
316
|
io.err('This does not look like a Nuxt or Next.js project (no "nuxt" or "next" dependency).');
|
|
179
317
|
io.err(
|
|
180
|
-
|
|
318
|
+
`Create one first (\`${dlx(pm, "nuxi init my-app")}\`, \`${createCommand(pm, "next-app", "my-app")}\`), or run with --standalone.`
|
|
181
319
|
);
|
|
182
320
|
return 1;
|
|
183
321
|
}
|
|
@@ -239,9 +377,12 @@ ${wanted.join("\n")}
|
|
|
239
377
|
if (target === "nuxt") await setupNuxt(dir, changes, notes);
|
|
240
378
|
else if (target === "next") await setupNext(dir, changes, notes);
|
|
241
379
|
else await setupStandalone(dir, changes);
|
|
380
|
+
if (pm === "yarn" && !existsSync(join(dir, ".yarnrc.yml")) && await isYarnBerry(dir, io)) {
|
|
381
|
+
await writeFile(join(dir, ".yarnrc.yml"), "nodeLinker: node-modules\n");
|
|
382
|
+
changes.push("created .yarnrc.yml (nodeLinker: node-modules; Plug'n'Play is not supported)");
|
|
383
|
+
}
|
|
242
384
|
for (const change of changes) io.out(` \u2713 ${change}`);
|
|
243
385
|
for (const note of notes) io.out(` \u2022 ${note}`);
|
|
244
|
-
const pm = detectPackageManager(dir);
|
|
245
386
|
const { deps, devDeps } = packagesFor(target, db);
|
|
246
387
|
if (values["skip-install"]) {
|
|
247
388
|
io.out("\nInstall the packages:");
|
|
@@ -252,38 +393,45 @@ ${wanted.join("\n")}
|
|
|
252
393
|
Installing with ${pm}\u2026`);
|
|
253
394
|
const code = await io.exec(pm, installArgs(pm, deps, false), dir) || (devDeps.length ? await io.exec(pm, installArgs(pm, devDeps, true), dir) : 0);
|
|
254
395
|
if (code !== 0) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
${pm} ${installArgs(pm, deps, false).join(" ")}`
|
|
259
|
-
);
|
|
396
|
+
const missing = code === NOT_FOUND ? `
|
|
397
|
+
${pm} is not installed. ${INSTALL_HINT[pm]}, or choose another with --pm.` : "\nInstalling failed.";
|
|
398
|
+
io.err(`${missing} Run it yourself:`);
|
|
399
|
+
io.err(` ${pm} ${installArgs(pm, deps, false).join(" ")}`);
|
|
400
|
+
if (devDeps.length) io.err(` ${pm} ${installArgs(pm, devDeps, true).join(" ")}`);
|
|
260
401
|
return 1;
|
|
261
402
|
}
|
|
262
403
|
}
|
|
263
|
-
const devCommand = pm
|
|
404
|
+
const devCommand = runScript(pm, "dev");
|
|
405
|
+
const cms = (command) => execBin(pm, `easy-cms ${command}`);
|
|
264
406
|
if (target === "standalone") {
|
|
265
407
|
const cd = relative(process.cwd(), dir);
|
|
266
408
|
io.out(`
|
|
267
409
|
Done. Next:
|
|
268
410
|
1. ${cd ? `cd ${cd} && ` : ""}${devCommand} (http://localhost:4000/admin)
|
|
269
|
-
2. Create the first admin there (or run:
|
|
411
|
+
2. Create the first admin there (or run: ${cms("create-admin")})
|
|
270
412
|
3. Point your frontend at http://localhost:4000/api/cms and list its origin in \`cors\`
|
|
271
413
|
in easy-cms.config.ts.
|
|
272
|
-
4. Before deploying:
|
|
273
|
-
run
|
|
414
|
+
4. Before deploying: ${cms("migrate:create init")}, commit easy-cms/migrations,
|
|
415
|
+
run ${cms("migrate")}, then NODE_ENV=production ${runScript(pm, "start")}.`);
|
|
274
416
|
return 0;
|
|
275
417
|
}
|
|
276
418
|
io.out(`
|
|
277
419
|
Done. Next:
|
|
278
420
|
1. ${devCommand}
|
|
279
|
-
2. Open /admin and create the first admin (or run:
|
|
280
|
-
3. Before deploying:
|
|
281
|
-
and run
|
|
421
|
+
2. Open /admin and create the first admin (or run: ${cms("create-admin")})
|
|
422
|
+
3. Before deploying: ${cms("migrate:create init")}, commit easy-cms/migrations,
|
|
423
|
+
and run ${cms("migrate")} where you deploy.
|
|
282
424
|
4. Set EASY_CMS_SECRET in the production environment.${target === "nuxt" ? `
|
|
283
425
|
Nuxt's production server does not read .env: set it on the host, or start with
|
|
284
426
|
node --env-file=.env .output/server/index.mjs` : ""}`);
|
|
285
427
|
return 0;
|
|
286
428
|
}
|
|
429
|
+
var INSTALL_HINT = {
|
|
430
|
+
npm: "Install Node.js from https://nodejs.org",
|
|
431
|
+
pnpm: "Install it with `npm install -g pnpm` (or `corepack enable`)",
|
|
432
|
+
yarn: "Install it with `npm install -g yarn` (or `corepack enable`)",
|
|
433
|
+
bun: "Install it from https://bun.sh"
|
|
434
|
+
};
|
|
287
435
|
var STANDALONE_SCRIPTS = {
|
|
288
436
|
dev: "easy-cms serve --watch",
|
|
289
437
|
start: "easy-cms serve",
|
|
@@ -380,8 +528,18 @@ ${source.replace(
|
|
|
380
528
|
}
|
|
381
529
|
|
|
382
530
|
export {
|
|
531
|
+
PACKAGE_MANAGERS,
|
|
532
|
+
isPackageManager,
|
|
533
|
+
installArgs,
|
|
534
|
+
runScript,
|
|
535
|
+
execBin,
|
|
536
|
+
dlx,
|
|
537
|
+
createCommand,
|
|
538
|
+
translateLine,
|
|
539
|
+
translateCommands,
|
|
383
540
|
detectFramework,
|
|
384
541
|
detectPackageManager,
|
|
542
|
+
isYarnBerry,
|
|
385
543
|
packagesFor,
|
|
386
544
|
run
|
|
387
545
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commands in each package manager's own words. No Node APIs: the docs site uses this too, to
|
|
3
|
+
* show every `npm`/`npx` command for pnpm, Yarn and Bun.
|
|
4
|
+
*/
|
|
5
|
+
declare const PACKAGE_MANAGERS: readonly ["npm", "pnpm", "yarn", "bun"];
|
|
6
|
+
type PackageManager = (typeof PACKAGE_MANAGERS)[number];
|
|
7
|
+
declare const isPackageManager: (value: unknown) => value is PackageManager;
|
|
8
|
+
/** Adds packages, as dependencies or devDependencies. */
|
|
9
|
+
declare function installArgs(pm: PackageManager, packages: readonly string[], dev: boolean): string[];
|
|
10
|
+
/** Runs a package.json script: `npm run dev`, `pnpm dev`, `yarn dev`, `bun run dev`. */
|
|
11
|
+
declare function runScript(pm: PackageManager, script: string, args?: string): string;
|
|
12
|
+
/** Runs a binary installed in the project: `npx easy-cms migrate`, `pnpm exec easy-cms migrate`… */
|
|
13
|
+
declare function execBin(pm: PackageManager, command: string): string;
|
|
14
|
+
/** Runs a package without installing it, e.g. `npx nuxi init`. */
|
|
15
|
+
declare function dlx(pm: PackageManager, command: string): string;
|
|
16
|
+
/** `npm create easy-cms@latest my-cms` → `pnpm create easy-cms my-cms`… */
|
|
17
|
+
declare function createCommand(pm: PackageManager, initializer: string, args?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* One line of an `npm`/`npx` command in another package manager's words. Lines that aren't
|
|
20
|
+
* npm commands (comments, `cd`, environment variables before a command…) are kept; `null`
|
|
21
|
+
* when the line has an npm command this does not know.
|
|
22
|
+
*/
|
|
23
|
+
declare function translateLine(line: string, pm: PackageManager): string | null;
|
|
24
|
+
/** A whole shell snippet in another package manager's words; `null` if any line can't be. */
|
|
25
|
+
declare function translateCommands(code: string, pm: PackageManager): string | null;
|
|
26
|
+
|
|
1
27
|
type DatabaseChoice = 'sqlite' | 'postgres';
|
|
2
28
|
|
|
3
29
|
type Framework = 'nuxt' | 'next';
|
|
4
30
|
/** Where Easy CMS runs: inside a Nuxt or Next.js app, or as its own server. */
|
|
5
31
|
type Target = Framework | 'standalone';
|
|
6
|
-
type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';
|
|
7
32
|
interface IO {
|
|
8
33
|
readonly out: (line: string) => void;
|
|
9
34
|
readonly err: (line: string) => void;
|
|
10
35
|
readonly interactive: boolean;
|
|
11
36
|
readonly prompt?: (question: string) => Promise<string>;
|
|
12
|
-
/** Runs a command (the package manager). Returns the exit code. */
|
|
37
|
+
/** Runs a command (the package manager). Returns the exit code; 127 when it isn't installed. */
|
|
13
38
|
readonly exec?: (command: string, args: string[], cwd: string) => Promise<number>;
|
|
39
|
+
/** Runs a command and returns what it printed, or `null` if it failed. */
|
|
40
|
+
readonly capture?: (command: string, args: string[], cwd: string) => Promise<string | null>;
|
|
14
41
|
}
|
|
15
42
|
/** Detects the framework from package.json dependencies. */
|
|
16
43
|
declare function detectFramework(pkg: Record<string, unknown>): Framework | undefined;
|
|
17
|
-
/**
|
|
18
|
-
|
|
44
|
+
/**
|
|
45
|
+
* The package manager to use: `--pm`, then package.json's `packageManager` (Corepack), then the
|
|
46
|
+
* lockfile, then the one running this (`npm create`, `pnpm create`…), else npm.
|
|
47
|
+
*/
|
|
48
|
+
declare function detectPackageManager(dir: string, explicit?: PackageManager): PackageManager;
|
|
49
|
+
/** Yarn 2 or later ("Berry"), whose default Plug'n'Play install Easy CMS does not support yet. */
|
|
50
|
+
declare function isYarnBerry(dir: string, io: IO): Promise<boolean>;
|
|
19
51
|
declare function packagesFor(target: Target, db: DatabaseChoice): {
|
|
20
52
|
deps: string[];
|
|
21
53
|
devDeps: string[];
|
|
@@ -23,4 +55,4 @@ declare function packagesFor(target: Target, db: DatabaseChoice): {
|
|
|
23
55
|
/** Runs create-easy-cms and returns the exit code. */
|
|
24
56
|
declare function run(argv: readonly string[], io?: IO): Promise<number>;
|
|
25
57
|
|
|
26
|
-
export { type Framework, type IO, type PackageManager, type Target, detectFramework, detectPackageManager, packagesFor, run };
|
|
58
|
+
export { type Framework, type IO, PACKAGE_MANAGERS, type PackageManager, type Target, createCommand, detectFramework, detectPackageManager, dlx, execBin, installArgs, isPackageManager, isYarnBerry, packagesFor, run, runScript, translateCommands, translateLine };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
|
+
PACKAGE_MANAGERS,
|
|
3
|
+
createCommand,
|
|
2
4
|
detectFramework,
|
|
3
5
|
detectPackageManager,
|
|
6
|
+
dlx,
|
|
7
|
+
execBin,
|
|
8
|
+
installArgs,
|
|
9
|
+
isPackageManager,
|
|
10
|
+
isYarnBerry,
|
|
4
11
|
packagesFor,
|
|
5
|
-
run
|
|
6
|
-
|
|
12
|
+
run,
|
|
13
|
+
runScript,
|
|
14
|
+
translateCommands,
|
|
15
|
+
translateLine
|
|
16
|
+
} from "./chunk-DGBBIS3J.js";
|
|
7
17
|
export {
|
|
18
|
+
PACKAGE_MANAGERS,
|
|
19
|
+
createCommand,
|
|
8
20
|
detectFramework,
|
|
9
21
|
detectPackageManager,
|
|
22
|
+
dlx,
|
|
23
|
+
execBin,
|
|
24
|
+
installArgs,
|
|
25
|
+
isPackageManager,
|
|
26
|
+
isYarnBerry,
|
|
10
27
|
packagesFor,
|
|
11
|
-
run
|
|
28
|
+
run,
|
|
29
|
+
runScript,
|
|
30
|
+
translateCommands,
|
|
31
|
+
translateLine
|
|
12
32
|
};
|