@frigear-nu/cli 0.0.0-stage → 0.0.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 +27 -2
- package/dist/chunks/add.mjs +92 -0
- package/dist/chunks/app-create.mjs +78 -0
- package/dist/chunks/init.mjs +90 -0
- package/dist/chunks/module-create.mjs +72 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +5 -0
- package/dist/index.d.mts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.mjs +14 -0
- package/dist/shared/cli.BTkbFZ3J.mjs +58 -0
- package/dist/shared/cli.CCJgOooL.mjs +7 -0
- package/dist/shared/cli.C_62nhcg.mjs +20 -0
- package/dist/shared/cli.CfDN9-ET.mjs +24 -0
- package/package.json +60 -3
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @frigear-nu/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Create Frigear projects from the starters, add apps and modules to a pnpm workspace, and install Frigear modules in a
|
|
4
|
+
Nuxt app.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pnpx @frigear-nu/cli --help
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
| Command | What it does |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| `init [dir] --starter <workspace\|mobile\|mobile-standalone>` | New project from a starter, then `pnpm install` and `pnpm prepare:env`. |
|
|
13
|
+
| `app:create <name> --template <web\|web-standalone\|mobile>` | Adds a starter's app to `apps/<name>`. |
|
|
14
|
+
| `module:create <name> [--scope @acme]` | Scaffolds a Nuxt module in `packages/<name>`. |
|
|
15
|
+
| `add <module...> [--app <app>]` | `pnpm add` in the app and adds the modules to its `nuxt.config`. |
|
|
16
|
+
|
|
17
|
+
Starters are downloaded from `Frigear-nu/frigear-nu` with [giget](https://github.com/unjs/giget) (`--ref` picks a branch
|
|
18
|
+
or tag). While that repository is not public, set `GIGET_AUTH` to a GitHub token that can read it.
|
|
19
|
+
|
|
20
|
+
`pnpm create frigear-app` ([create-frigear-app](../create-frigear-app)) is `init` under its own name.
|
|
21
|
+
|
|
22
|
+
Full reference: [docs.frigear.dev/contribute/tooling/cli](https://docs.frigear.dev/contribute/tooling/cli).
|
|
23
|
+
|
|
24
|
+
## In this repository
|
|
25
|
+
|
|
26
|
+
`pnpm cli <command>` from the root runs `bin/cli.mjs`, which loads `src/cli.ts` through
|
|
27
|
+
[jiti](https://github.com/unjs/jiti), so there is no build step. The published package is built with unbuild into
|
|
28
|
+
`dist/` (`publishConfig.bin`).
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { resolve, join, relative } from 'node:path';
|
|
6
|
+
import { parseModule, generateCode } from 'magicast';
|
|
7
|
+
import { getDefaultExportOptions, addNuxtModule } from 'magicast/helpers';
|
|
8
|
+
import { b as readPackage, d as defineCommandArgs, f as findWorkspaceRoot, l as listDirs } from '../shared/cli.BTkbFZ3J.mjs';
|
|
9
|
+
import { a as addDeps } from '../shared/cli.CCJgOooL.mjs';
|
|
10
|
+
import 'scule';
|
|
11
|
+
import 'pkg-types';
|
|
12
|
+
import 'nypm';
|
|
13
|
+
|
|
14
|
+
const NUXT_CONFIGS = ["nuxt.config.ts", "nuxt.config.mts", "nuxt.config.js", "nuxt.config.mjs"];
|
|
15
|
+
const resolveModuleName = (name) => name.includes("/") ? name : `@frigear-nu/${name}`;
|
|
16
|
+
const findNuxtConfig = (dir) => NUXT_CONFIGS.map((file) => join(dir, file)).find(existsSync);
|
|
17
|
+
const resolveTargetApp = async (cwd, app) => {
|
|
18
|
+
if (app) {
|
|
19
|
+
const root2 = await findWorkspaceRoot(cwd) ?? cwd;
|
|
20
|
+
const candidates = [resolve(cwd, app), join(root2, "apps", app)];
|
|
21
|
+
const dir = candidates.find(findNuxtConfig);
|
|
22
|
+
if (!dir) throw new Error(`No nuxt.config found in ${candidates.join(" or ")}`);
|
|
23
|
+
return dir;
|
|
24
|
+
}
|
|
25
|
+
if (findNuxtConfig(cwd)) return cwd;
|
|
26
|
+
const root = await findWorkspaceRoot(cwd);
|
|
27
|
+
const apps = root ? (await listDirs(join(root, "apps"))).filter(findNuxtConfig) : [];
|
|
28
|
+
if (apps.length === 1) return apps[0];
|
|
29
|
+
if (apps.length === 0) throw new Error(`No Nuxt app found in ${cwd}. Pass --app <dir>.`);
|
|
30
|
+
throw new Error(`Several Nuxt apps found (${apps.map((dir) => relative(root, dir)).join(", ")}). Pass --app <name>.`);
|
|
31
|
+
};
|
|
32
|
+
const addModulesToConfig = async (configPath, modules) => {
|
|
33
|
+
const mod = parseModule(await readFile(configPath, "utf-8"));
|
|
34
|
+
const config = getDefaultExportOptions(mod);
|
|
35
|
+
const added = modules.filter((name) => !config.modules?.includes(name));
|
|
36
|
+
for (const name of added) addNuxtModule(mod, name);
|
|
37
|
+
if (added.length) await writeFile(configPath, `${generateCode(mod).code.trimEnd()}
|
|
38
|
+
`, "utf-8");
|
|
39
|
+
return added;
|
|
40
|
+
};
|
|
41
|
+
const add = defineCommand({
|
|
42
|
+
meta: {
|
|
43
|
+
name: "add",
|
|
44
|
+
description: "Install Frigear modules in a Nuxt app and add them to its nuxt.config"
|
|
45
|
+
},
|
|
46
|
+
args: defineCommandArgs({
|
|
47
|
+
modules: {
|
|
48
|
+
type: "positional",
|
|
49
|
+
description: "Modules to add e.g. forms or @frigear-nu/forms",
|
|
50
|
+
required: true
|
|
51
|
+
},
|
|
52
|
+
app: {
|
|
53
|
+
type: "string",
|
|
54
|
+
description: "App to add the modules to: a path, or a folder under apps/"
|
|
55
|
+
},
|
|
56
|
+
install: {
|
|
57
|
+
type: "boolean",
|
|
58
|
+
description: "Install the packages (--no-install to only edit nuxt.config)",
|
|
59
|
+
default: true
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
async run({ args }) {
|
|
63
|
+
const logger = consola.withTag("add");
|
|
64
|
+
const modules = [...new Set(args._.map(String).map(resolveModuleName))];
|
|
65
|
+
const appDir = await resolveTargetApp(resolve(args.cwd), args.app).catch((error) => {
|
|
66
|
+
logger.error(error instanceof Error ? error.message : error);
|
|
67
|
+
return process.exit(1);
|
|
68
|
+
});
|
|
69
|
+
const configPath = findNuxtConfig(appDir);
|
|
70
|
+
if (args.install) {
|
|
71
|
+
logger.start(`Installing ${modules.join(", ")} in ${appDir}`);
|
|
72
|
+
await addDeps(modules, appDir);
|
|
73
|
+
}
|
|
74
|
+
const added = await addModulesToConfig(configPath, modules).catch((error) => {
|
|
75
|
+
logger.warn(`Could not edit ${configPath}: ${error instanceof Error ? error.message : error}`);
|
|
76
|
+
logger.info(`Add these to \`modules\` yourself:
|
|
77
|
+
${modules.map((name) => ` '${name}',`).join("\n")}`);
|
|
78
|
+
return void 0;
|
|
79
|
+
});
|
|
80
|
+
if (added) {
|
|
81
|
+
if (added.length) logger.success(`Added ${added.join(", ")} to ${configPath}`);
|
|
82
|
+
else logger.info(`Already in ${configPath}`);
|
|
83
|
+
}
|
|
84
|
+
for (const name of modules) {
|
|
85
|
+
const homepage = (await readPackage(join(appDir, "node_modules", name)).catch(() => void 0))?.homepage;
|
|
86
|
+
if (homepage) logger.info(`${name}: options, policies and migrations at ${homepage}`);
|
|
87
|
+
}
|
|
88
|
+
logger.info("Modules that add tables need a migration: run `pnpm db:generate` and commit it.");
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export { addModulesToConfig, add as default, resolveModuleName, resolveTargetApp };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { f as findWorkspaceRoot, t as toPackageName, h as hasPackage, r as renamePackage, d as defineCommandArgs, a as templateArgs, l as listDirs, p as packageScope, b as readPackage } from '../shared/cli.BTkbFZ3J.mjs';
|
|
5
|
+
import { i as installDeps } from '../shared/cli.CCJgOooL.mjs';
|
|
6
|
+
import { d as downloadTemplateToDir, r as repoSource } from '../shared/cli.C_62nhcg.mjs';
|
|
7
|
+
import 'scule';
|
|
8
|
+
import 'node:fs';
|
|
9
|
+
import 'node:fs/promises';
|
|
10
|
+
import 'pkg-types';
|
|
11
|
+
import 'nypm';
|
|
12
|
+
import 'giget';
|
|
13
|
+
|
|
14
|
+
const APP_TEMPLATES = {
|
|
15
|
+
"web": ".starters/workspace/apps/web",
|
|
16
|
+
"web-standalone": ".starters/mobile-standalone/apps/web",
|
|
17
|
+
"mobile": ".starters/mobile/apps/mobile"
|
|
18
|
+
};
|
|
19
|
+
const isAppTemplate = (value) => value in APP_TEMPLATES;
|
|
20
|
+
const resolveAppScope = async (root) => {
|
|
21
|
+
for (const dir of await listDirs(join(root, "apps"))) {
|
|
22
|
+
const scope = packageScope((await readPackage(dir))?.name);
|
|
23
|
+
if (scope) return scope;
|
|
24
|
+
}
|
|
25
|
+
return packageScope((await readPackage(root))?.name);
|
|
26
|
+
};
|
|
27
|
+
const appCreate = defineCommand({
|
|
28
|
+
meta: {
|
|
29
|
+
name: "app:create",
|
|
30
|
+
description: "Add an app from a Frigear starter to apps/<name> of a pnpm workspace"
|
|
31
|
+
},
|
|
32
|
+
args: defineCommandArgs({
|
|
33
|
+
name: {
|
|
34
|
+
type: "positional",
|
|
35
|
+
description: "Name of the new app e.g. web",
|
|
36
|
+
required: true
|
|
37
|
+
},
|
|
38
|
+
template: {
|
|
39
|
+
type: "string",
|
|
40
|
+
description: `App template: ${Object.keys(APP_TEMPLATES).join(", ")}`,
|
|
41
|
+
default: "web"
|
|
42
|
+
},
|
|
43
|
+
...templateArgs
|
|
44
|
+
}),
|
|
45
|
+
async run({ args }) {
|
|
46
|
+
const logger = consola.withTag("app:create");
|
|
47
|
+
const { template } = args;
|
|
48
|
+
if (!isAppTemplate(template)) {
|
|
49
|
+
logger.error(`Unknown template "${template}". Use one of: ${Object.keys(APP_TEMPLATES).join(", ")}`);
|
|
50
|
+
return process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
const root = await findWorkspaceRoot(args.cwd);
|
|
53
|
+
if (!root) {
|
|
54
|
+
logger.error(`No pnpm-workspace.yaml found above ${args.cwd}. Run \`init\` to create a project first.`);
|
|
55
|
+
return process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
const name = toPackageName(args.name);
|
|
58
|
+
const appPath = join(root, "apps", name);
|
|
59
|
+
if (hasPackage(appPath)) {
|
|
60
|
+
logger.error(`App ${name} already exists at ${appPath}`);
|
|
61
|
+
return process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
const scope = await resolveAppScope(root);
|
|
64
|
+
await downloadTemplateToDir({ template: repoSource(APP_TEMPLATES[template], args.ref), path: appPath }).catch((error) => {
|
|
65
|
+
logger.error(`Failed to create app ${name} at ${appPath}`);
|
|
66
|
+
logger.error(error instanceof Error ? error.message : error);
|
|
67
|
+
return process.exit(1);
|
|
68
|
+
});
|
|
69
|
+
await renamePackage(appPath, scope ? `${scope}/${name}` : name);
|
|
70
|
+
logger.success(`Created app ${name} at ${appPath}`);
|
|
71
|
+
if (args.install) {
|
|
72
|
+
logger.start("Installing dependencies");
|
|
73
|
+
await installDeps(root);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export { APP_TEMPLATES, appCreate as default, resolveAppScope };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { resolve, basename, relative } from 'node:path';
|
|
4
|
+
import { i as isEmptyDir, r as renamePackage, t as toPackageName, d as defineCommandArgs, a as templateArgs } from '../shared/cli.BTkbFZ3J.mjs';
|
|
5
|
+
import { i as installDeps, r as runPackageScript } from '../shared/cli.CCJgOooL.mjs';
|
|
6
|
+
import { d as downloadTemplateToDir, r as repoSource } from '../shared/cli.C_62nhcg.mjs';
|
|
7
|
+
import 'scule';
|
|
8
|
+
import 'node:fs';
|
|
9
|
+
import 'node:fs/promises';
|
|
10
|
+
import 'pkg-types';
|
|
11
|
+
import 'nypm';
|
|
12
|
+
import 'giget';
|
|
13
|
+
|
|
14
|
+
const STARTERS = {
|
|
15
|
+
"workspace": "apps/web: users, auth, account and admin",
|
|
16
|
+
"mobile": "apps/mobile: a Capacitor app against any OAuth issuer",
|
|
17
|
+
"mobile-standalone": "workspace + apps/mobile, with apps/web as the OAuth server"
|
|
18
|
+
};
|
|
19
|
+
const isStarter = (value) => typeof value === "string" && value in STARTERS;
|
|
20
|
+
const init = defineCommand({
|
|
21
|
+
meta: {
|
|
22
|
+
name: "init",
|
|
23
|
+
description: "Create a new project from a Frigear starter"
|
|
24
|
+
},
|
|
25
|
+
args: defineCommandArgs({
|
|
26
|
+
dir: {
|
|
27
|
+
type: "positional",
|
|
28
|
+
description: "Directory to create the project in",
|
|
29
|
+
required: false,
|
|
30
|
+
default: "frigear-app"
|
|
31
|
+
},
|
|
32
|
+
starter: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description: `Starter to use: ${Object.keys(STARTERS).join(", ")}`
|
|
35
|
+
},
|
|
36
|
+
force: {
|
|
37
|
+
type: "boolean",
|
|
38
|
+
description: "Write into a directory that is not empty",
|
|
39
|
+
default: false
|
|
40
|
+
},
|
|
41
|
+
...templateArgs
|
|
42
|
+
}),
|
|
43
|
+
async run({ args }) {
|
|
44
|
+
const logger = consola.withTag("init");
|
|
45
|
+
const dir = resolve(args.cwd, args.dir);
|
|
46
|
+
let starter = args.starter;
|
|
47
|
+
if (starter === void 0) {
|
|
48
|
+
starter = process.stdin.isTTY ? await consola.prompt("Which starter?", {
|
|
49
|
+
type: "select",
|
|
50
|
+
options: Object.entries(STARTERS).map(([value, hint]) => ({ value, label: value, hint })),
|
|
51
|
+
initial: "workspace",
|
|
52
|
+
cancel: "reject"
|
|
53
|
+
}) : "workspace";
|
|
54
|
+
}
|
|
55
|
+
if (!isStarter(starter)) {
|
|
56
|
+
logger.error(`Unknown starter "${starter}". Use one of: ${Object.keys(STARTERS).join(", ")}`);
|
|
57
|
+
return process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
if (!args.force && !await isEmptyDir(dir)) {
|
|
60
|
+
logger.error(`${dir} is not empty. Pick another directory or pass --force.`);
|
|
61
|
+
return process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
await downloadTemplateToDir({
|
|
64
|
+
template: repoSource(`.starters/${starter}`, args.ref),
|
|
65
|
+
path: dir,
|
|
66
|
+
force: args.force
|
|
67
|
+
}).catch((error) => {
|
|
68
|
+
logger.error(`Failed to download the ${starter} starter`);
|
|
69
|
+
logger.error(error instanceof Error ? error.message : error);
|
|
70
|
+
return process.exit(1);
|
|
71
|
+
});
|
|
72
|
+
await renamePackage(dir, toPackageName(basename(dir)));
|
|
73
|
+
logger.success(`Created the ${starter} starter in ${dir}`);
|
|
74
|
+
if (args.install) {
|
|
75
|
+
logger.start("Installing dependencies");
|
|
76
|
+
await installDeps(dir);
|
|
77
|
+
await runPackageScript("prepare:env", dir);
|
|
78
|
+
}
|
|
79
|
+
const cd = relative(args.cwd, dir) || ".";
|
|
80
|
+
logger.box([
|
|
81
|
+
"Next steps:",
|
|
82
|
+
cd === "." ? void 0 : ` cd ${cd}`,
|
|
83
|
+
args.install ? void 0 : " pnpm install && pnpm prepare:env",
|
|
84
|
+
...starter === "mobile" ? [" set NUXT_PUBLIC_AUTHENTICATION_CLIENT_ISSUER (and _API_BASE) in apps/mobile/.env"] : [" put your email in NUXT_ACL_ADMINS in apps/web/.env"],
|
|
85
|
+
" pnpm dev"
|
|
86
|
+
].filter(Boolean).join("\n"));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export { STARTERS, init as default };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { t as toPackageName, f as findWorkspaceRoot, h as hasPackage, r as renamePackage, d as defineCommandArgs, p as packageScope, b as readPackage } from '../shared/cli.BTkbFZ3J.mjs';
|
|
4
|
+
import { d as downloadTemplateToDir } from '../shared/cli.C_62nhcg.mjs';
|
|
5
|
+
import consola from 'consola';
|
|
6
|
+
import 'scule';
|
|
7
|
+
import 'node:fs';
|
|
8
|
+
import 'node:fs/promises';
|
|
9
|
+
import 'pkg-types';
|
|
10
|
+
import 'giget';
|
|
11
|
+
|
|
12
|
+
const resolveModuleScope = async (root, scope) => {
|
|
13
|
+
if (scope !== void 0) return scope ? `@${scope.replace(/^@/, "")}` : void 0;
|
|
14
|
+
return packageScope((await readPackage(root))?.name);
|
|
15
|
+
};
|
|
16
|
+
const moduleCreate = defineCommand({
|
|
17
|
+
meta: {
|
|
18
|
+
name: "module:create",
|
|
19
|
+
description: "Create a new Nuxt Module"
|
|
20
|
+
},
|
|
21
|
+
args: defineCommandArgs({
|
|
22
|
+
name: {
|
|
23
|
+
type: "positional",
|
|
24
|
+
description: "Name of the new Nuxt Module e.g my-module",
|
|
25
|
+
required: true
|
|
26
|
+
},
|
|
27
|
+
template: {
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "Template to use for the new Nuxt Module e.g gh:github.com/my/package",
|
|
30
|
+
default: "gh:nuxt/starter#module"
|
|
31
|
+
},
|
|
32
|
+
scope: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description: `npm scope of the package e.g. @acme (defaults to the root package's scope, "" for none)`
|
|
35
|
+
},
|
|
36
|
+
dir: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "Folder of the workspace to create the module in",
|
|
39
|
+
default: "packages"
|
|
40
|
+
}
|
|
41
|
+
}),
|
|
42
|
+
async run({ args }) {
|
|
43
|
+
const logger = consola.withTag("module:create");
|
|
44
|
+
const { template } = args;
|
|
45
|
+
const name = toPackageName(args.name);
|
|
46
|
+
const root = await findWorkspaceRoot(args.cwd) ?? resolve(args.cwd);
|
|
47
|
+
const modulePath = resolve(root, args.dir, name);
|
|
48
|
+
if (hasPackage(modulePath)) {
|
|
49
|
+
logger.error(`Module ${name} already exists at ${modulePath}`);
|
|
50
|
+
return process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
const { dir } = await downloadTemplateToDir({
|
|
53
|
+
template,
|
|
54
|
+
path: modulePath,
|
|
55
|
+
cwd: root
|
|
56
|
+
}).catch((error) => {
|
|
57
|
+
logger.error(`Failed to create module ${name} at ${modulePath}`);
|
|
58
|
+
logger.error(error instanceof Error ? error.message : error);
|
|
59
|
+
return process.exit(1);
|
|
60
|
+
});
|
|
61
|
+
if (!hasPackage(dir)) {
|
|
62
|
+
logger.error(`The template has no package.json at ${dir}`);
|
|
63
|
+
return process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
const scope = await resolveModuleScope(root, args.scope);
|
|
66
|
+
const packageName = scope ? `${scope}/${name}` : name;
|
|
67
|
+
await renamePackage(dir, packageName);
|
|
68
|
+
logger.log(`Created module ${packageName} at ${dir}`);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export { moduleCreate as default, resolveModuleScope };
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/cli.mjs
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as citty from 'citty';
|
|
2
|
+
|
|
3
|
+
declare const mainCmd: citty.CommandDef<citty.ArgsDef>;
|
|
4
|
+
declare function main(): Promise<void>;
|
|
5
|
+
|
|
6
|
+
declare const STARTERS: {
|
|
7
|
+
readonly workspace: "apps/web: users, auth, account and admin";
|
|
8
|
+
readonly mobile: "apps/mobile: a Capacitor app against any OAuth issuer";
|
|
9
|
+
readonly 'mobile-standalone': "workspace + apps/mobile, with apps/web as the OAuth server";
|
|
10
|
+
};
|
|
11
|
+
type Starter = keyof typeof STARTERS;
|
|
12
|
+
declare const _default: citty.CommandDef<{
|
|
13
|
+
cwd: {
|
|
14
|
+
type: "string";
|
|
15
|
+
description: string;
|
|
16
|
+
default: string;
|
|
17
|
+
};
|
|
18
|
+
} & {
|
|
19
|
+
ref: {
|
|
20
|
+
type: "string";
|
|
21
|
+
description: string;
|
|
22
|
+
default: string;
|
|
23
|
+
};
|
|
24
|
+
install: {
|
|
25
|
+
type: "boolean";
|
|
26
|
+
description: string;
|
|
27
|
+
default: true;
|
|
28
|
+
};
|
|
29
|
+
dir: {
|
|
30
|
+
type: "positional";
|
|
31
|
+
description: string;
|
|
32
|
+
required: false;
|
|
33
|
+
default: string;
|
|
34
|
+
};
|
|
35
|
+
starter: {
|
|
36
|
+
type: "string";
|
|
37
|
+
description: string;
|
|
38
|
+
};
|
|
39
|
+
force: {
|
|
40
|
+
type: "boolean";
|
|
41
|
+
description: string;
|
|
42
|
+
default: false;
|
|
43
|
+
};
|
|
44
|
+
}>;
|
|
45
|
+
|
|
46
|
+
export { STARTERS, main as default, _default as initCmd, mainCmd };
|
|
47
|
+
export type { Starter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as citty from 'citty';
|
|
2
|
+
|
|
3
|
+
declare const mainCmd: citty.CommandDef<citty.ArgsDef>;
|
|
4
|
+
declare function main(): Promise<void>;
|
|
5
|
+
|
|
6
|
+
declare const STARTERS: {
|
|
7
|
+
readonly workspace: "apps/web: users, auth, account and admin";
|
|
8
|
+
readonly mobile: "apps/mobile: a Capacitor app against any OAuth issuer";
|
|
9
|
+
readonly 'mobile-standalone': "workspace + apps/mobile, with apps/web as the OAuth server";
|
|
10
|
+
};
|
|
11
|
+
type Starter = keyof typeof STARTERS;
|
|
12
|
+
declare const _default: citty.CommandDef<{
|
|
13
|
+
cwd: {
|
|
14
|
+
type: "string";
|
|
15
|
+
description: string;
|
|
16
|
+
default: string;
|
|
17
|
+
};
|
|
18
|
+
} & {
|
|
19
|
+
ref: {
|
|
20
|
+
type: "string";
|
|
21
|
+
description: string;
|
|
22
|
+
default: string;
|
|
23
|
+
};
|
|
24
|
+
install: {
|
|
25
|
+
type: "boolean";
|
|
26
|
+
description: string;
|
|
27
|
+
default: true;
|
|
28
|
+
};
|
|
29
|
+
dir: {
|
|
30
|
+
type: "positional";
|
|
31
|
+
description: string;
|
|
32
|
+
required: false;
|
|
33
|
+
default: string;
|
|
34
|
+
};
|
|
35
|
+
starter: {
|
|
36
|
+
type: "string";
|
|
37
|
+
description: string;
|
|
38
|
+
};
|
|
39
|
+
force: {
|
|
40
|
+
type: "boolean";
|
|
41
|
+
description: string;
|
|
42
|
+
default: false;
|
|
43
|
+
};
|
|
44
|
+
}>;
|
|
45
|
+
|
|
46
|
+
export { STARTERS, main as default, _default as initCmd, mainCmd };
|
|
47
|
+
export type { Starter };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { m as default, a as mainCmd } from './shared/cli.CfDN9-ET.mjs';
|
|
2
|
+
export { STARTERS, default as initCmd } from './chunks/init.mjs';
|
|
3
|
+
import 'citty';
|
|
4
|
+
import 'consola';
|
|
5
|
+
import 'node:path';
|
|
6
|
+
import './shared/cli.BTkbFZ3J.mjs';
|
|
7
|
+
import 'scule';
|
|
8
|
+
import 'node:fs';
|
|
9
|
+
import 'node:fs/promises';
|
|
10
|
+
import 'pkg-types';
|
|
11
|
+
import './shared/cli.CCJgOooL.mjs';
|
|
12
|
+
import 'nypm';
|
|
13
|
+
import './shared/cli.C_62nhcg.mjs';
|
|
14
|
+
import 'giget';
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { templateArgs as a, readPackage 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 };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { addDependency, installDependencies, 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 };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { downloadTemplate } from 'giget';
|
|
2
|
+
|
|
3
|
+
const FRIGEAR_REPO = "gh:Frigear-nu/frigear-nu";
|
|
4
|
+
const repoSource = (path, ref = "main") => `${FRIGEAR_REPO}/${path}#${ref}`;
|
|
5
|
+
const downloadTemplateToDir = async ({ template, path, cwd, force }) => {
|
|
6
|
+
return downloadTemplate(template, {
|
|
7
|
+
cwd,
|
|
8
|
+
dir: path,
|
|
9
|
+
force
|
|
10
|
+
}).catch((error) => {
|
|
11
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
12
|
+
if (template.startsWith(FRIGEAR_REPO) && /\b(?:401|403|404)\b/.test(message) && !process.env.GIGET_AUTH) {
|
|
13
|
+
throw new Error(`${message}
|
|
14
|
+
While Frigear-nu/frigear-nu is not public, set GIGET_AUTH to a GitHub token that can read it, e.g. GIGET_AUTH=$(gh auth token).`, { cause: error });
|
|
15
|
+
}
|
|
16
|
+
throw error;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { downloadTemplateToDir as d, repoSource as r };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineCommand, runMain } from 'citty';
|
|
2
|
+
|
|
3
|
+
const version = "0.0.0";
|
|
4
|
+
const pkg = {
|
|
5
|
+
version: version};
|
|
6
|
+
|
|
7
|
+
const mainCmd = defineCommand({
|
|
8
|
+
meta: {
|
|
9
|
+
name: "frigear-nu",
|
|
10
|
+
version: pkg.version,
|
|
11
|
+
description: "Scaffold Frigear projects, apps and modules"
|
|
12
|
+
},
|
|
13
|
+
subCommands: {
|
|
14
|
+
"init": () => import('../chunks/init.mjs').then((module) => module.default),
|
|
15
|
+
"app:create": () => import('../chunks/app-create.mjs').then((module) => module.default),
|
|
16
|
+
"module:create": () => import('../chunks/module-create.mjs').then((module) => module.default),
|
|
17
|
+
"add": () => import('../chunks/add.mjs').then((module) => module.default)
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
async function main() {
|
|
21
|
+
await runMain(mainCmd);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { mainCmd as a, main as m };
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/cli",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"description": "Frigear CLI: scaffold projects, apps and modules, and add Frigear modules to an app.",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Frigear",
|
|
9
|
+
"email": "kontakt@frigear.nu",
|
|
10
|
+
"url": "https://frigear.nu"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://docs.frigear.dev/contribute/tooling/cli",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/frigear-nu/frigear-nu.git",
|
|
16
|
+
"directory": "packages/cli"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=20.17.0"
|
|
21
|
+
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"frigear-nu": "./dist/cli.mjs"
|
|
24
|
+
},
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"default": "./dist/index.mjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"citty": "^0.2.2",
|
|
39
|
+
"consola": "^3.4.2",
|
|
40
|
+
"giget": "^3.3.1",
|
|
41
|
+
"magicast": "^0.5.5",
|
|
42
|
+
"nypm": "^0.6.10",
|
|
43
|
+
"pkg-types": "^2.4.0",
|
|
44
|
+
"scule": "^1.3.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@frigear-nu/eslint-config": "^0.2.2",
|
|
48
|
+
"@types/node": "^26.6.5",
|
|
49
|
+
"eslint": "^10.12.0",
|
|
50
|
+
"jiti": "^2.7.0",
|
|
51
|
+
"typescript": "^6.0.3",
|
|
52
|
+
"unbuild": "^3.6.1",
|
|
53
|
+
"vitest": "^5.0.2"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"dev": "node bin/cli.mjs",
|
|
57
|
+
"build": "unbuild",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"typecheck": "tsc --noEmit",
|
|
60
|
+
"lint": "eslint .",
|
|
61
|
+
"lint:fix": "eslint . --fix"
|
|
62
|
+
}
|
|
6
63
|
}
|