@frigear-nu/cli 0.2.4 → 0.2.5
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 +7 -2
- package/dist/chunks/add.mjs +66 -69
- package/dist/chunks/add2.mjs +93 -0
- package/dist/chunks/app-create.mjs +28 -52
- package/dist/chunks/init.mjs +4 -3
- package/dist/chunks/init2.mjs +53 -0
- package/dist/chunks/list.mjs +48 -0
- package/dist/chunks/module-create.mjs +2 -2
- package/dist/chunks/module-folder.mjs +5 -4
- package/dist/chunks/module-move.mjs +5 -5
- package/dist/chunks/package-rename.mjs +1 -2
- package/dist/chunks/platform.mjs +15 -0
- package/dist/chunks/upgrade.mjs +2 -3
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +226 -2
- package/dist/index.d.ts +226 -2
- package/dist/index.mjs +13 -9
- package/dist/shared/cli.B8wGY3pU.mjs +127 -0
- package/dist/shared/{cli.C_0i5HKZ.mjs → cli.B9jOPxYC.mjs} +1 -1
- package/dist/shared/cli.BVDx1SIR.mjs +84 -0
- package/dist/shared/cli.C-q4Gf2K.mjs +18 -0
- package/dist/shared/cli.CJ66durw.mjs +22 -0
- package/dist/shared/{cli.DUmSgMcB.mjs → cli.CU1tZqxU.mjs} +90 -2
- package/dist/shared/{cli.CybmnaqF.mjs → cli.DAggATZw.mjs} +1 -1
- package/dist/shared/cli.DEhqG8Aw.mjs +119 -0
- package/dist/shared/{cli.B_BErT55.mjs → cli.DX_up8fP.mjs} +3 -2
- package/package.json +5 -4
- package/dist/shared/cli.Cfkcp0w9.mjs +0 -58
- package/dist/shared/cli.CkMCvUCp.mjs +0 -7
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import consola from 'consola';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { relative, join, resolve } from 'node:path';
|
|
4
|
+
import { r as runPackageScript, e as execBin } from './cli.C-q4Gf2K.mjs';
|
|
5
|
+
import { t as toPosix } from './cli.BLUxtpPi.mjs';
|
|
6
|
+
import { l as listDirs, b as readPackage, f as findWorkspaceRoot, P as PlatformError, r as resolveAppsDir, h as hasPackage, g as isInside } from './cli.CU1tZqxU.mjs';
|
|
7
|
+
import { p as platformRegistry, f as findTarget } from './cli.B8wGY3pU.mjs';
|
|
8
|
+
|
|
9
|
+
const detectAppPlatform = (registry, pkg) => {
|
|
10
|
+
const own = pkg.frigear?.platform;
|
|
11
|
+
if (typeof own === "string" && registry.platforms[own]) return registry.platforms[own];
|
|
12
|
+
const ordered = Object.values(registry.platforms).sort((a, b) => Number(a.name === "web") - Number(b.name === "web"));
|
|
13
|
+
return ordered.find((platform) => platform.detect?.(pkg));
|
|
14
|
+
};
|
|
15
|
+
const listWorkspaceApps = async (appsDir, registry) => {
|
|
16
|
+
const apps = [];
|
|
17
|
+
for (const dir of await listDirs(appsDir)) {
|
|
18
|
+
const pkg = await readPackage(dir);
|
|
19
|
+
if (pkg) apps.push({ name: relative(appsDir, dir), dir, pkg, platform: detectAppPlatform(registry, pkg) });
|
|
20
|
+
}
|
|
21
|
+
return apps;
|
|
22
|
+
};
|
|
23
|
+
const resolvePlatformApp = async (options) => {
|
|
24
|
+
const apps = await listWorkspaceApps(options.appsDir, options.registry);
|
|
25
|
+
if (options.app) {
|
|
26
|
+
const dirs = [join(options.appsDir, options.app), resolve(options.cwd, options.app)];
|
|
27
|
+
const app = apps.find((candidate) => dirs.includes(candidate.dir));
|
|
28
|
+
if (app) return app;
|
|
29
|
+
const dir = dirs.find(hasPackage);
|
|
30
|
+
if (dir) {
|
|
31
|
+
const pkg = await readPackage(dir);
|
|
32
|
+
return { name: relative(options.appsDir, dir), dir, pkg, platform: detectAppPlatform(options.registry, pkg) };
|
|
33
|
+
}
|
|
34
|
+
throw new PlatformError("APP_NOT_FOUND", `No app ${options.app} in ${options.appsDir}.`, { candidates: apps.map((app2) => app2.name) });
|
|
35
|
+
}
|
|
36
|
+
const current = apps.find((app) => isInside(resolve(options.cwd), app.dir));
|
|
37
|
+
if (current) return current;
|
|
38
|
+
const matching = apps.filter((app) => app.platform && findTarget(app.platform, options.target));
|
|
39
|
+
if (matching.length === 1) return matching[0];
|
|
40
|
+
if (matching.length === 0)
|
|
41
|
+
throw new PlatformError("APP_NOT_FOUND", `No app in ${toPosix(relative(options.root, options.appsDir)) || "."} has the target "${options.target}". Add one with \`platform add\`, or pass --app <name>.`, {
|
|
42
|
+
candidates: apps.map((app) => app.name)
|
|
43
|
+
});
|
|
44
|
+
throw new PlatformError("APP_AMBIGUOUS", `Several apps have the target "${options.target}" (${matching.map((app) => app.name).join(", ")}). Pass --app <name>.`, {
|
|
45
|
+
candidates: matching.map((app) => app.name)
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
const targetCommand = (target, pkg, extra = []) => {
|
|
49
|
+
const args = [...target.args ?? [], ...extra];
|
|
50
|
+
if (target.script && pkg.scripts?.[target.script]) return { kind: "script", name: target.script, args };
|
|
51
|
+
if (target.bin?.length) return { kind: "exec", name: target.bin[0], args: [...target.bin.slice(1), ...args] };
|
|
52
|
+
return void 0;
|
|
53
|
+
};
|
|
54
|
+
const initPlatform = async (options) => {
|
|
55
|
+
const logger = options.logger ?? consola.withTag("platform");
|
|
56
|
+
const root = await findWorkspaceRoot(options.cwd);
|
|
57
|
+
if (!root)
|
|
58
|
+
throw new PlatformError("NO_WORKSPACE", `No pnpm-workspace.yaml found above ${options.cwd}.`);
|
|
59
|
+
const registry = platformRegistry(await readPackage(root));
|
|
60
|
+
const { dir: appsDir } = await resolveAppsDir({ cwd: options.cwd, root, appsDir: options.appsDir });
|
|
61
|
+
const app = await resolvePlatformApp({ cwd: options.cwd, root, appsDir, registry, target: options.target, app: options.app });
|
|
62
|
+
const found = app.platform ? findTarget(app.platform, options.target) : void 0;
|
|
63
|
+
if (!app.platform || !found) {
|
|
64
|
+
const targets = Object.keys(app.platform?.targets ?? {});
|
|
65
|
+
throw new PlatformError("UNKNOWN_TARGET", `App ${app.name}${app.platform ? ` (${app.platform.name})` : ""} has no target "${options.target}"${targets.length ? `; it has ${targets.join(", ")}` : ""}.`, {
|
|
66
|
+
candidates: targets
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const command = targetCommand(found.target, app.pkg, options.args);
|
|
70
|
+
if (!command)
|
|
71
|
+
throw new PlatformError("UNKNOWN_TARGET", `App ${app.name} has no "${found.target.script}" script, and the target names no binary to run instead.`);
|
|
72
|
+
const result = { root, app, platform: app.platform.name, target: found.id, command };
|
|
73
|
+
if (options.dryRun) return result;
|
|
74
|
+
logger.start(`Setting up ${found.id} in ${toPosix(relative(root, app.dir))}`);
|
|
75
|
+
if (command.kind === "script") await runPackageScript(command.name, app.dir, command.args);
|
|
76
|
+
else {
|
|
77
|
+
if (!existsSync(join(app.dir, "node_modules")))
|
|
78
|
+
logger.warn(`${app.name} has no node_modules yet: run the install first if ${command.name} is not found.`);
|
|
79
|
+
await execBin(command.name, command.args, app.dir);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { detectAppPlatform as d, initPlatform as i, listWorkspaceApps as l, resolvePlatformApp as r, targetCommand as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { installDependencies, addDependency, runScript, detectPackageManager } from 'nypm';
|
|
2
|
+
import { x } from 'tinyexec';
|
|
3
|
+
|
|
4
|
+
const packageManagerOf = async (cwd) => (await detectPackageManager(cwd, { includeParentDirs: true }).catch(() => void 0))?.name ?? "pnpm";
|
|
5
|
+
const installDeps = async (cwd) => installDependencies({ cwd, packageManager: await packageManagerOf(cwd) });
|
|
6
|
+
const addDeps = async (names, cwd) => addDependency(names, { cwd, packageManager: await packageManagerOf(cwd) });
|
|
7
|
+
const runPackageScript = async (name, cwd, args) => runScript(name, { cwd, packageManager: await packageManagerOf(cwd), args });
|
|
8
|
+
const execBin = async (bin, args, cwd) => {
|
|
9
|
+
const pm = await packageManagerOf(cwd);
|
|
10
|
+
const command = pm === "npm" ? "npx" : pm;
|
|
11
|
+
const result = await x(command, pm === "npm" ? ["--no-install", bin, ...args] : ["exec", bin, ...args], {
|
|
12
|
+
nodeOptions: { cwd, stdio: "inherit" },
|
|
13
|
+
throwOnError: true
|
|
14
|
+
});
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { addDeps as a, execBin as e, installDeps as i, runPackageScript as r };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { P as PlatformError } from './cli.CU1tZqxU.mjs';
|
|
2
|
+
|
|
3
|
+
const exitWith = (logger, error) => {
|
|
4
|
+
if (error instanceof PlatformError) {
|
|
5
|
+
logger.error(error.message);
|
|
6
|
+
return process.exit(1);
|
|
7
|
+
}
|
|
8
|
+
throw error;
|
|
9
|
+
};
|
|
10
|
+
const passThroughArgs = (rawArgs) => {
|
|
11
|
+
const index = rawArgs.indexOf("--");
|
|
12
|
+
return index === -1 ? [] : rawArgs.slice(index + 1);
|
|
13
|
+
};
|
|
14
|
+
const appsDirArg = {
|
|
15
|
+
"apps-dir": {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "Folder the apps live in: auto (the apps folder you are in, else apps/) or a path",
|
|
18
|
+
default: "auto"
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { appsDirArg as a, exitWith as e, passThroughArgs as p };
|
|
@@ -1,6 +1,47 @@
|
|
|
1
|
+
import { kebabCase } from 'scule';
|
|
1
2
|
import { existsSync } from 'node:fs';
|
|
2
3
|
import { readFile, readdir } from 'node:fs/promises';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
+
import { join, dirname, resolve, relative, isAbsolute } from 'node:path';
|
|
5
|
+
import { readPackageJSON, findNearestFile, writePackageJSON } from 'pkg-types';
|
|
6
|
+
|
|
7
|
+
const getDefaultCommandArgs = () => {
|
|
8
|
+
return {
|
|
9
|
+
cwd: {
|
|
10
|
+
type: "string",
|
|
11
|
+
description: "The current working directory",
|
|
12
|
+
default: process.env.INIT_CWD || process.cwd()
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const defineCommandArgs = (args) => {
|
|
17
|
+
return {
|
|
18
|
+
...getDefaultCommandArgs(),
|
|
19
|
+
...args
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const templateArgs = {
|
|
23
|
+
ref: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Branch or tag of the frigear-nu repository to copy from",
|
|
26
|
+
default: "main"
|
|
27
|
+
},
|
|
28
|
+
install: {
|
|
29
|
+
type: "boolean",
|
|
30
|
+
description: "Install dependencies afterwards (--no-install to skip)",
|
|
31
|
+
default: true
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
class PlatformError extends Error {
|
|
36
|
+
code;
|
|
37
|
+
candidates;
|
|
38
|
+
constructor(code, message, options) {
|
|
39
|
+
super(message, { cause: options?.cause });
|
|
40
|
+
this.name = "PlatformError";
|
|
41
|
+
this.code = code;
|
|
42
|
+
this.candidates = options?.candidates;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
4
45
|
|
|
5
46
|
const VERSION = /(\d+)\.(\d+)\.(\d+)(?:-([\w.-]+))?/;
|
|
6
47
|
const parseVersion = (value) => {
|
|
@@ -172,4 +213,51 @@ const movePatchedDependencies = (file, text, targets) => {
|
|
|
172
213
|
return { text: out, moves };
|
|
173
214
|
};
|
|
174
215
|
|
|
175
|
-
|
|
216
|
+
const findWorkspaceRoot = async (cwd) => {
|
|
217
|
+
const file = await findNearestFile("pnpm-workspace.yaml", { startingFrom: cwd }).catch(() => void 0);
|
|
218
|
+
return file ? dirname(file) : void 0;
|
|
219
|
+
};
|
|
220
|
+
const readPackage = async (dir) => {
|
|
221
|
+
const path = join(dir, "package.json");
|
|
222
|
+
return existsSync(path) ? readPackageJSON(path) : void 0;
|
|
223
|
+
};
|
|
224
|
+
const hasPackage = (dir) => existsSync(join(dir, "package.json"));
|
|
225
|
+
const renamePackage = async (dir, name) => {
|
|
226
|
+
const path = join(dir, "package.json");
|
|
227
|
+
const pkg = await readPackageJSON(path);
|
|
228
|
+
await writePackageJSON(path, { ...pkg, name });
|
|
229
|
+
};
|
|
230
|
+
const packageScope = (name) => name?.startsWith("@") ? name.split("/")[0] : void 0;
|
|
231
|
+
const listDirs = async (dir) => {
|
|
232
|
+
if (!existsSync(dir)) return [];
|
|
233
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
234
|
+
return entries.filter((entry) => entry.isDirectory()).map((entry) => join(dir, entry.name));
|
|
235
|
+
};
|
|
236
|
+
const isEmptyDir = async (dir) => !existsSync(dir) || (await readdir(dir)).length === 0;
|
|
237
|
+
const toPackageName = (name) => kebabCase(name.replace(/[^\w-]+/g, "-")).replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
238
|
+
const isInside = (path, dir) => {
|
|
239
|
+
const rel = relative(dir, path);
|
|
240
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
|
|
241
|
+
};
|
|
242
|
+
const appGlobDirs = async (root) => {
|
|
243
|
+
const yamlPath = join(root, "pnpm-workspace.yaml");
|
|
244
|
+
const globs = existsSync(yamlPath) ? workspaceGlobs(await readFile(yamlPath, "utf-8")) : [];
|
|
245
|
+
return [...new Set(globs.map((glob) => glob.replace(/^\.\//, "").replace(/\/+$/, "")).filter((glob) => /^[^*]+\/\*{1,2}$/.test(glob)).map((glob) => glob.replace(/\/\*{1,2}$/, "")).filter((dir) => dir !== "packages"))];
|
|
246
|
+
};
|
|
247
|
+
const resolveAppsDir = async ({ cwd, root, appsDir }) => {
|
|
248
|
+
const globDirs = await appGlobDirs(root);
|
|
249
|
+
const covered = (dir2) => globDirs.some((globDir) => resolve(root, globDir) === dir2);
|
|
250
|
+
if (appsDir && appsDir !== "auto") {
|
|
251
|
+
const dir2 = resolve(cwd, appsDir);
|
|
252
|
+
if (!isInside(dir2, root) || dir2 === root)
|
|
253
|
+
throw new PlatformError("OUTSIDE_ROOT", `${dir2} is not a folder inside the workspace at ${root}`);
|
|
254
|
+
return { dir: dir2, covered: covered(dir2) };
|
|
255
|
+
}
|
|
256
|
+
const current = globDirs.map((globDir) => resolve(root, globDir)).find((dir2) => isInside(resolve(cwd), dir2));
|
|
257
|
+
if (current) return { dir: current, covered: true };
|
|
258
|
+
const fallback = globDirs.includes("apps") ? "apps" : globDirs[0] ?? "apps";
|
|
259
|
+
const dir = resolve(root, fallback);
|
|
260
|
+
return { dir, covered: covered(dir) };
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
export { PlatformError as P, renamePackage as a, readPackage as b, templateArgs as c, defineCommandArgs as d, workspacePackageDirs as e, findWorkspaceRoot as f, isInside as g, hasPackage as h, isEmptyDir as i, isBetween as j, duplicateVersions as k, listDirs as l, manifestFiles as m, findPins as n, currentVersions as o, packageScope as p, compareVersions as q, resolveAppsDir as r, sharedDuplicates as s, toPackageName as t, rewritePins as u, movePatchedDependencies as v, workspaceGlobs as w };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, statSync } from 'node:fs';
|
|
2
2
|
import { extname, join, basename } from 'node:path';
|
|
3
|
-
import { resolveTargetApp } from '../chunks/
|
|
3
|
+
import { resolveTargetApp } from '../chunks/add2.mjs';
|
|
4
4
|
import { r as resolveArg } from './cli.BLUxtpPi.mjs';
|
|
5
5
|
|
|
6
6
|
const MODULE_EXTS = [".ts", ".mts", ".js", ".mjs"];
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import consola from 'consola';
|
|
2
|
+
import { relative, join } from 'node:path';
|
|
3
|
+
import { readPackageJSON, writePackageJSON } from 'pkg-types';
|
|
4
|
+
import { i as installDeps, r as runPackageScript } from './cli.C-q4Gf2K.mjs';
|
|
5
|
+
import { t as toPosix } from './cli.BLUxtpPi.mjs';
|
|
6
|
+
import { d as downloadTemplateToDir } from './cli.B9jOPxYC.mjs';
|
|
7
|
+
import { f as findWorkspaceRoot, P as PlatformError, b as readPackage, r as resolveAppsDir, t as toPackageName, h as hasPackage, l as listDirs, p as packageScope } from './cli.CU1tZqxU.mjs';
|
|
8
|
+
import { p as platformRegistry, i as isTemplateSource } from './cli.B8wGY3pU.mjs';
|
|
9
|
+
|
|
10
|
+
const resolveAppScope = async (root, appsDir = join(root, "apps")) => {
|
|
11
|
+
for (const dir of await listDirs(appsDir)) {
|
|
12
|
+
const scope = packageScope((await readPackage(dir))?.name);
|
|
13
|
+
if (scope) return scope;
|
|
14
|
+
}
|
|
15
|
+
return packageScope((await readPackage(root))?.name);
|
|
16
|
+
};
|
|
17
|
+
const resolvePlatform = (registry, platform, template) => {
|
|
18
|
+
if (typeof platform !== "string") return platform;
|
|
19
|
+
const name = platform.trim().toLowerCase();
|
|
20
|
+
const known = registry.platforms[name];
|
|
21
|
+
if (known) return known;
|
|
22
|
+
if (template) return { name };
|
|
23
|
+
throw new PlatformError("UNKNOWN_PLATFORM", `Unknown platform "${platform}". Use one of ${Object.keys(registry.platforms).join(", ")}, or pass --template <name or giget source> for a platform of your own.`, {
|
|
24
|
+
candidates: Object.keys(registry.platforms)
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const resolveTemplateSource = (registry, template) => {
|
|
28
|
+
if (registry.templates[template]) return registry.templates[template];
|
|
29
|
+
if (isTemplateSource(template)) return template;
|
|
30
|
+
throw new PlatformError("UNKNOWN_TEMPLATE", `Unknown template "${template}". Use one of ${Object.keys(registry.templates).join(", ")}, or a giget source like gh:org/repo/path.`, {
|
|
31
|
+
candidates: Object.keys(registry.templates)
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const fillPlaceholders = (text, values) => text.replaceAll("<name>", values.name).replaceAll("<dir>", values.dir).replaceAll("<package>", values.package ?? values.name);
|
|
35
|
+
const platformScripts = (platform, appName, appDir) => Object.fromEntries(Object.entries(platform.scripts ?? {}).map(([key, command]) => [
|
|
36
|
+
fillPlaceholders(key, { name: appName, dir: appDir }),
|
|
37
|
+
fillPlaceholders(command, { name: appName, dir: appDir })
|
|
38
|
+
]));
|
|
39
|
+
const mergeRootScripts = async (root, scripts) => {
|
|
40
|
+
const path = join(root, "package.json");
|
|
41
|
+
const pkg = await readPackageJSON(path);
|
|
42
|
+
const existing = pkg.scripts ?? {};
|
|
43
|
+
const added = Object.keys(scripts).filter((key) => !(key in existing));
|
|
44
|
+
const skipped = Object.keys(scripts).filter((key) => key in existing && existing[key] !== scripts[key]);
|
|
45
|
+
if (added.length)
|
|
46
|
+
await writePackageJSON(path, { ...pkg, scripts: { ...existing, ...Object.fromEntries(added.map((key) => [key, scripts[key]])) } });
|
|
47
|
+
return { added, skipped };
|
|
48
|
+
};
|
|
49
|
+
const usesOAuthServer = async (root, appsDir) => {
|
|
50
|
+
for (const dir of [...await listDirs(appsDir), ...await listDirs(join(root, "apps"))]) {
|
|
51
|
+
const pkg = await readPackage(dir);
|
|
52
|
+
if (pkg?.dependencies?.["@frigear-nu/oauth-server"]) return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
};
|
|
56
|
+
const addPlatform = async (options) => {
|
|
57
|
+
const logger = options.logger ?? consola.withTag("platform");
|
|
58
|
+
const root = await findWorkspaceRoot(options.cwd);
|
|
59
|
+
if (!root)
|
|
60
|
+
throw new PlatformError("NO_WORKSPACE", `No pnpm-workspace.yaml found above ${options.cwd}. Run \`init\` to create a project first.`);
|
|
61
|
+
const rootPkg = await readPackage(root);
|
|
62
|
+
const registry = platformRegistry(rootPkg, options.ref);
|
|
63
|
+
const platform = resolvePlatform(registry, options.platform, options.template);
|
|
64
|
+
const template = options.template ?? platform.template;
|
|
65
|
+
if (!template)
|
|
66
|
+
throw new PlatformError("UNKNOWN_TEMPLATE", `Platform "${platform.name}" has no template. Pass --template <name or giget source>.`);
|
|
67
|
+
const source = resolveTemplateSource(registry, template);
|
|
68
|
+
const appsDir = await resolveAppsDir({ cwd: options.cwd, root, appsDir: options.appsDir });
|
|
69
|
+
if (!appsDir.covered)
|
|
70
|
+
logger.warn(`${toPosix(relative(root, appsDir.dir))} is not covered by the packages: globs of pnpm-workspace.yaml: add it, or pnpm will not install the app.`);
|
|
71
|
+
const appName = toPackageName(options.name ?? platform.defaultAppName ?? platform.name);
|
|
72
|
+
const appDir = join(appsDir.dir, appName);
|
|
73
|
+
if (hasPackage(appDir))
|
|
74
|
+
throw new PlatformError("APP_EXISTS", `App ${appName} already exists at ${appDir}. Pick another name.`);
|
|
75
|
+
const scope = await resolveAppScope(root, appsDir.dir);
|
|
76
|
+
await downloadTemplateToDir({ template: source, path: appDir }).catch((error) => {
|
|
77
|
+
throw new PlatformError("DOWNLOAD_FAILED", `Failed to copy ${source} to ${appDir}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
78
|
+
});
|
|
79
|
+
const packageName = scope ? `${scope}/${appName}` : appName;
|
|
80
|
+
if (hasPackage(appDir)) {
|
|
81
|
+
const path = join(appDir, "package.json");
|
|
82
|
+
const pkg = await readPackageJSON(path);
|
|
83
|
+
const frigear = pkg.frigear && typeof pkg.frigear === "object" ? pkg.frigear : {};
|
|
84
|
+
await writePackageJSON(path, { ...pkg, name: packageName, frigear: { ...frigear, platform: platform.name } });
|
|
85
|
+
}
|
|
86
|
+
logger.success(`Created ${platform.name} app ${appName} at ${appDir}`);
|
|
87
|
+
const dir = `./${toPosix(relative(root, appDir))}`;
|
|
88
|
+
const scripts = options.scripts === false ? { added: [], skipped: [] } : await mergeRootScripts(root, platformScripts(platform, appName, dir));
|
|
89
|
+
if (scripts.added.length) logger.info(`Added root scripts: ${scripts.added.join(", ")}`);
|
|
90
|
+
if (scripts.skipped.length) logger.info(`Kept the root's own scripts: ${scripts.skipped.join(", ")}`);
|
|
91
|
+
const install = options.install !== false;
|
|
92
|
+
if (install) {
|
|
93
|
+
logger.start("Installing dependencies");
|
|
94
|
+
await installDeps(root);
|
|
95
|
+
}
|
|
96
|
+
if ((options.prepareEnv ?? install) && rootPkg?.scripts?.["prepare:env"])
|
|
97
|
+
await runPackageScript("prepare:env", root);
|
|
98
|
+
const context = {
|
|
99
|
+
appName,
|
|
100
|
+
appDir: toPosix(relative(root, appDir)),
|
|
101
|
+
packageName,
|
|
102
|
+
root,
|
|
103
|
+
hasOAuthServer: await usesOAuthServer(root, appsDir.dir)
|
|
104
|
+
};
|
|
105
|
+
const steps = typeof platform.nextSteps === "function" ? platform.nextSteps(context) : (platform.nextSteps ?? []).map((step) => fillPlaceholders(step, { name: appName, dir: context.appDir, package: packageName }));
|
|
106
|
+
return {
|
|
107
|
+
root,
|
|
108
|
+
platform: platform.name,
|
|
109
|
+
source,
|
|
110
|
+
appName,
|
|
111
|
+
appDir,
|
|
112
|
+
packageName,
|
|
113
|
+
appsDir,
|
|
114
|
+
scripts,
|
|
115
|
+
nextSteps: steps
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export { addPlatform as a, resolvePlatform as b, resolveTemplateSource as c, fillPlaceholders as f, mergeRootScripts as m, platformScripts as p, resolveAppScope as r };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCommand, runMain } from 'citty';
|
|
2
2
|
|
|
3
|
-
const version = "0.2.
|
|
3
|
+
const version = "0.2.5";
|
|
4
4
|
const pkg = {
|
|
5
5
|
version: version};
|
|
6
6
|
|
|
@@ -12,12 +12,13 @@ const mainCmd = defineCommand({
|
|
|
12
12
|
},
|
|
13
13
|
subCommands: {
|
|
14
14
|
"init": () => import('../chunks/init.mjs').then((module) => module.default),
|
|
15
|
+
"platform": () => import('../chunks/platform.mjs').then((module) => module.default),
|
|
15
16
|
"app:create": () => import('../chunks/app-create.mjs').then((module) => module.default),
|
|
16
17
|
"module:create": () => import('../chunks/module-create.mjs').then((module) => module.default),
|
|
17
18
|
"module:folder": () => import('../chunks/module-folder.mjs').then((module) => module.default),
|
|
18
19
|
"module:move": () => import('../chunks/module-move.mjs').then((module) => module.default),
|
|
19
20
|
"package:rename": () => import('../chunks/package-rename.mjs').then((module) => module.default),
|
|
20
|
-
"add": () => import('../chunks/
|
|
21
|
+
"add": () => import('../chunks/add2.mjs').then((module) => module.default),
|
|
21
22
|
"upgrade": () => import('../chunks/upgrade.mjs').then(function (n) { return n.a; }).then((module) => module.default)
|
|
22
23
|
}
|
|
23
24
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Frigear CLI: scaffold projects, apps and modules, and add Frigear modules to an app.",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"email": "kontakt@frigear.nu",
|
|
10
10
|
"url": "https://frigear.nu"
|
|
11
11
|
},
|
|
12
|
-
"homepage": "https://docs.frigear.dev/
|
|
12
|
+
"homepage": "https://docs.frigear.dev/cli/overview",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git+https://github.com/Frigear-nu/frigear-nu.git",
|
|
@@ -41,10 +41,11 @@
|
|
|
41
41
|
"magicast": "^0.5.5",
|
|
42
42
|
"nypm": "^0.6.12",
|
|
43
43
|
"pkg-types": "^2.4.0",
|
|
44
|
-
"scule": "^1.3.0"
|
|
44
|
+
"scule": "^1.3.0",
|
|
45
|
+
"tinyexec": "^1.3.1"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@frigear-nu/eslint-config": "^0.2.
|
|
48
|
+
"@frigear-nu/eslint-config": "^0.2.6",
|
|
48
49
|
"@types/node": "^26.6.6",
|
|
49
50
|
"eslint": "^10.15.0",
|
|
50
51
|
"jiti": "^2.7.0",
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { kebabCase } from 'scule';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { readdir } from 'node:fs/promises';
|
|
4
|
-
import { join, dirname } from 'node:path';
|
|
5
|
-
import { readPackageJSON, findNearestFile, writePackageJSON } from 'pkg-types';
|
|
6
|
-
|
|
7
|
-
const getDefaultCommandArgs = () => {
|
|
8
|
-
return {
|
|
9
|
-
cwd: {
|
|
10
|
-
type: "string",
|
|
11
|
-
description: "The current working directory",
|
|
12
|
-
default: process.env.INIT_CWD || process.cwd()
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
const defineCommandArgs = (args) => {
|
|
17
|
-
return {
|
|
18
|
-
...getDefaultCommandArgs(),
|
|
19
|
-
...args
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
const templateArgs = {
|
|
23
|
-
ref: {
|
|
24
|
-
type: "string",
|
|
25
|
-
description: "Branch or tag of the frigear-nu repository to copy from",
|
|
26
|
-
default: "main"
|
|
27
|
-
},
|
|
28
|
-
install: {
|
|
29
|
-
type: "boolean",
|
|
30
|
-
description: "Install dependencies afterwards (--no-install to skip)",
|
|
31
|
-
default: true
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const findWorkspaceRoot = async (cwd) => {
|
|
36
|
-
const file = await findNearestFile("pnpm-workspace.yaml", { startingFrom: cwd }).catch(() => void 0);
|
|
37
|
-
return file ? dirname(file) : void 0;
|
|
38
|
-
};
|
|
39
|
-
const readPackage = async (dir) => {
|
|
40
|
-
const path = join(dir, "package.json");
|
|
41
|
-
return existsSync(path) ? readPackageJSON(path) : void 0;
|
|
42
|
-
};
|
|
43
|
-
const hasPackage = (dir) => existsSync(join(dir, "package.json"));
|
|
44
|
-
const renamePackage = async (dir, name) => {
|
|
45
|
-
const path = join(dir, "package.json");
|
|
46
|
-
const pkg = await readPackageJSON(path);
|
|
47
|
-
await writePackageJSON(path, { ...pkg, name });
|
|
48
|
-
};
|
|
49
|
-
const packageScope = (name) => name?.startsWith("@") ? name.split("/")[0] : void 0;
|
|
50
|
-
const listDirs = async (dir) => {
|
|
51
|
-
if (!existsSync(dir)) return [];
|
|
52
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
53
|
-
return entries.filter((entry) => entry.isDirectory()).map((entry) => join(dir, entry.name));
|
|
54
|
-
};
|
|
55
|
-
const isEmptyDir = async (dir) => !existsSync(dir) || (await readdir(dir)).length === 0;
|
|
56
|
-
const toPackageName = (name) => kebabCase(name.replace(/[^\w-]+/g, "-")).replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
57
|
-
|
|
58
|
-
export { readPackage as a, templateArgs as b, defineCommandArgs as d, findWorkspaceRoot as f, hasPackage as h, isEmptyDir as i, listDirs as l, packageScope as p, renamePackage as r, toPackageName as t };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { installDependencies, addDependency, runScript } from 'nypm';
|
|
2
|
-
|
|
3
|
-
const installDeps = (cwd) => installDependencies({ cwd, packageManager: "pnpm" });
|
|
4
|
-
const addDeps = (names, cwd) => addDependency(names, { cwd, packageManager: "pnpm" });
|
|
5
|
-
const runPackageScript = (name, cwd) => runScript(name, { cwd, packageManager: "pnpm" });
|
|
6
|
-
|
|
7
|
-
export { addDeps as a, installDeps as i, runPackageScript as r };
|