@titanium1971/local-business-engine-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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Titanium1971
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,11 @@
1
+ # local-business-engine-cli
2
+
3
+ CLI to generate Astro client instances that consume the Local Business Engine Core package.
4
+
5
+ ## Manual test
6
+
7
+ ```bash
8
+ npm run dev -- create-client agde
9
+ cd client-agde
10
+ npm run dev
11
+ ```
package/dist/index.js ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ import { mkdir, writeFile } from "node:fs/promises";
3
+ import { existsSync } from "node:fs";
4
+ import path from "node:path";
5
+ import process from "node:process";
6
+ import { Command } from "commander";
7
+ import { run } from "./run.js";
8
+ const CORE_PACKAGE = "@titanium1971/local-business-engine@^1.0.2";
9
+ function isValidSlug(slug) {
10
+ return slug === slug.toLowerCase() && /^[a-z0-9-]+$/.test(slug);
11
+ }
12
+ const program = new Command();
13
+ program
14
+ .name("lbe")
15
+ .description("Local Business Engine CLI")
16
+ .version("0.1.0");
17
+ program
18
+ .command("create-client")
19
+ .argument("<slug>", "client slug (e.g. agde, sete, divino)")
20
+ .description("Create a new Astro client instance from the template")
21
+ .action(async (inputSlug) => {
22
+ const slug = inputSlug.trim();
23
+ if (!isValidSlug(slug)) {
24
+ console.error("Invalid slug. Use lowercase letters, numbers, and hyphens only (regex: [a-z0-9-]).");
25
+ process.exit(1);
26
+ }
27
+ const targetDir = `client-${slug}`;
28
+ const targetPath = path.resolve(process.cwd(), targetDir);
29
+ if (existsSync(targetPath)) {
30
+ console.error(`Target directory already exists: ${targetDir}`);
31
+ process.exit(1);
32
+ }
33
+ try {
34
+ await run("npm", [
35
+ "create",
36
+ "astro@latest",
37
+ "--",
38
+ "--template",
39
+ "minimal",
40
+ "--yes",
41
+ "--no-git",
42
+ "--skip-houston",
43
+ targetDir
44
+ ]);
45
+ const npmrcContent = [
46
+ "@titanium1971:registry=https://npm.pkg.github.com",
47
+ "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}",
48
+ "always-auth=true",
49
+ ""
50
+ ].join("\n");
51
+ await writeFile(path.join(targetPath, ".npmrc"), npmrcContent, "utf8");
52
+ if (!process.env.GITHUB_TOKEN) {
53
+ console.log("Warning: GITHUB_TOKEN is not set in this shell. Installation may fail for private package access.");
54
+ }
55
+ await run("npm", ["install", CORE_PACKAGE], { cwd: targetPath });
56
+ const indexAstroContent = [
57
+ "---",
58
+ "import BaseLayout from \"@titanium1971/local-business-engine/layouts/BaseLayout.astro\";",
59
+ "---",
60
+ "",
61
+ `<BaseLayout title=\"Client ${slug}\">`,
62
+ " <main>",
63
+ " <h1>Instance OK</h1>",
64
+ " </main>",
65
+ "</BaseLayout>",
66
+ ""
67
+ ].join("\n");
68
+ await mkdir(path.join(targetPath, "src", "pages"), { recursive: true });
69
+ await writeFile(path.join(targetPath, "src", "pages", "index.astro"), indexAstroContent, "utf8");
70
+ console.log("\nInstance created successfully.");
71
+ console.log(`Directory: ${targetDir}`);
72
+ console.log("\nNext steps:");
73
+ console.log(`cd ${targetDir}`);
74
+ console.log("npm run dev");
75
+ console.log("\nReminder: export GITHUB_TOKEN=<PAT with read:packages> before npm install if private package access is required.");
76
+ }
77
+ catch (error) {
78
+ const message = error instanceof Error ? error.message : String(error);
79
+ console.error(`\ncreate-client failed: ${message}`);
80
+ process.exit(1);
81
+ }
82
+ });
83
+ program.parse(process.argv);
package/dist/run.js ADDED
@@ -0,0 +1,21 @@
1
+ import { spawn } from "node:child_process";
2
+ export function run(command, args, options = {}) {
3
+ const bin = process.platform === "win32" && command === "npm" ? "npm.cmd" : command;
4
+ return new Promise((resolve, reject) => {
5
+ const child = spawn(bin, args, {
6
+ cwd: options.cwd,
7
+ stdio: "inherit",
8
+ shell: false
9
+ });
10
+ child.on("error", (error) => {
11
+ reject(error);
12
+ });
13
+ child.on("exit", (code) => {
14
+ if (code === 0) {
15
+ resolve();
16
+ return;
17
+ }
18
+ reject(new Error(`Command failed (${command} ${args.join(" ")}) with exit code ${code ?? "null"}`));
19
+ });
20
+ });
21
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@titanium1971/local-business-engine-cli",
3
+ "version": "0.1.0",
4
+ "description": "CLI to generate Local Business Engine Astro instances",
5
+ "type": "module",
6
+ "bin": {
7
+ "lbe": "dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "dev": "tsx src/index.ts",
11
+ "build": "tsc -p tsconfig.json",
12
+ "prepack": "npm run build",
13
+ "start": "node dist/index.js"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "package.json",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "dependencies": {
22
+ "commander": "^12.0.0",
23
+ "degit": "^2.8.4",
24
+ "typescript": "^5.9.3",
25
+ "@types/node": "^22.0.0"
26
+ },
27
+ "devDependencies": {
28
+ "tsx": "^4.0.0"
29
+ }
30
+ }