@headless-lms/cli 0.1.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/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mdwt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @headless-lms/cli
|
|
2
|
+
|
|
3
|
+
The `headless-lms` bin: a thin CLI over the operational functions
|
|
4
|
+
`@headless-lms/server` exports. Reads `.env` from the cwd if present.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
headless-lms migrate # apply the Drizzle migrations bundled in @headless-lms/adapter-db
|
|
8
|
+
headless-lms --help
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Installations get it as a dependency (the `create-headless-lms` scaffold wires
|
|
12
|
+
`pnpm migrate` to it). In this repo, `apps/api` runs the same entry via tsx:
|
|
13
|
+
`pnpm --filter @headless-lms/api db:migrate`.
|
|
14
|
+
|
|
15
|
+
## Structure
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
src/
|
|
19
|
+
index.ts bin entry: .env, dispatch, exit code — no logic
|
|
20
|
+
main.ts dispatcher: usage/help/version, error → exit 1 (testable, no process.exit)
|
|
21
|
+
command.ts the Command interface
|
|
22
|
+
commands/ one module per command + the explicit registry (index.ts)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Adding a command:** create `src/commands/<name>.ts` exporting a `Command`
|
|
26
|
+
(`{ name, description, run(args) }`), register it in `src/commands/index.ts`.
|
|
27
|
+
Throw from `run` to fail — the dispatcher prints the message and exits 1.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runMigrations } from "@headless-lms/server";
|
|
3
|
+
//#region package.json
|
|
4
|
+
var version = "0.1.0";
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/commands/index.ts
|
|
7
|
+
const commands = [{
|
|
8
|
+
name: "migrate",
|
|
9
|
+
description: "Apply the bundled Drizzle migrations to DATABASE_URL",
|
|
10
|
+
async run() {
|
|
11
|
+
await runMigrations(process.env.DATABASE_URL ?? "");
|
|
12
|
+
console.log("Migrations applied.");
|
|
13
|
+
}
|
|
14
|
+
}];
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/main.ts
|
|
17
|
+
function usage() {
|
|
18
|
+
const width = Math.max(...commands.map((c) => c.name.length));
|
|
19
|
+
return [
|
|
20
|
+
"Usage: headless-lms <command>",
|
|
21
|
+
"",
|
|
22
|
+
"Commands:",
|
|
23
|
+
...commands.map((c) => ` ${c.name.padEnd(width)} ${c.description}`),
|
|
24
|
+
"",
|
|
25
|
+
"Options:",
|
|
26
|
+
" -h, --help Show this help",
|
|
27
|
+
" -v, --version Print the CLI version"
|
|
28
|
+
].join("\n");
|
|
29
|
+
}
|
|
30
|
+
async function main(argv) {
|
|
31
|
+
const [name, ...args] = argv;
|
|
32
|
+
if (!name) {
|
|
33
|
+
console.error(usage());
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
if (name === "help" || name === "--help" || name === "-h") {
|
|
37
|
+
console.log(usage());
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
if (name === "--version" || name === "-v") {
|
|
41
|
+
console.log(version);
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
const command = commands.find((c) => c.name === name);
|
|
45
|
+
if (!command) {
|
|
46
|
+
console.error(`Unknown command: ${name}\n\n${usage()}`);
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
await command.run(args);
|
|
51
|
+
return 0;
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/index.ts
|
|
59
|
+
try {
|
|
60
|
+
process.loadEnvFile();
|
|
61
|
+
} catch {}
|
|
62
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
63
|
+
//#endregion
|
|
64
|
+
export {};
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["pkg.version"],"sources":["../package.json","../src/commands/migrate.ts","../src/commands/index.ts","../src/main.ts","../src/index.ts"],"sourcesContent":["","import { runMigrations } from \"@headless-lms/server\";\nimport type { Command } from \"../command.js\";\n\nexport const migrate: Command = {\n name: \"migrate\",\n description: \"Apply the bundled Drizzle migrations to DATABASE_URL\",\n async run() {\n await runMigrations(process.env.DATABASE_URL ?? \"\");\n console.log(\"Migrations applied.\");\n },\n};\n","import type { Command } from \"../command.js\";\nimport { migrate } from \"./migrate.js\";\n\nexport const commands: readonly Command[] = [migrate];\n","// Dispatcher, separated from the bin entry so it is testable: takes argv,\n// returns the exit code, never calls process.exit itself.\nimport pkg from \"../package.json\" with { type: \"json\" };\nimport { commands } from \"./commands/index.js\";\n\nfunction usage(): string {\n const width = Math.max(...commands.map((c) => c.name.length));\n return [\n \"Usage: headless-lms <command>\",\n \"\",\n \"Commands:\",\n ...commands.map((c) => ` ${c.name.padEnd(width)} ${c.description}`),\n \"\",\n \"Options:\",\n \" -h, --help Show this help\",\n \" -v, --version Print the CLI version\",\n ].join(\"\\n\");\n}\n\nexport async function main(argv: readonly string[]): Promise<number> {\n const [name, ...args] = argv;\n\n if (!name) {\n console.error(usage());\n return 1;\n }\n if (name === \"help\" || name === \"--help\" || name === \"-h\") {\n console.log(usage());\n return 0;\n }\n if (name === \"--version\" || name === \"-v\") {\n console.log(pkg.version);\n return 0;\n }\n\n const command = commands.find((c) => c.name === name);\n if (!command) {\n console.error(`Unknown command: ${name}\\n\\n${usage()}`);\n return 1;\n }\n\n try {\n await command.run(args);\n return 0;\n } catch (err) {\n console.error(err instanceof Error ? err.message : String(err));\n return 1;\n }\n}\n","#!/usr/bin/env node\n// The bin entry: env, dispatch, exit code. All logic lives in main.ts.\n// Loads ./.env from the cwd if present (Node 22 native), so installations\n// don't need --env-file gymnastics.\nimport { main } from \"./main.js\";\n\ntry {\n process.loadEnvFile();\n} catch {\n // no .env in cwd — fine, env may come from the environment itself\n}\n\nprocess.exitCode = await main(process.argv.slice(2));\n"],"mappings":";;;;;;AEGA,MAAa,WAA+B,CAAC;CDC3C,MAAM;CACN,aAAa;CACb,MAAM,MAAM;EACV,MAAM,cAAc,QAAQ,IAAI,g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.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@headless-lms/server": "0.1.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/node": "^22.10.2",
|
|
16
|
+
"tsdown": "^0.22.9",
|
|
17
|
+
"typescript": "^5.7.2",
|
|
18
|
+
"vitest": "^2.1.8"
|
|
19
|
+
},
|
|
20
|
+
"description": "CLI for running and managing a headless LMS instance",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/mdwt/headless-lms.git",
|
|
25
|
+
"directory": "packages/cli"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/mdwt/headless-lms#readme",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/mdwt/headless-lms/issues"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsdown",
|
|
36
|
+
"lint": "eslint src",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
39
|
+
}
|
|
40
|
+
}
|