create-aicms 0.0.0-stage → 0.5.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.
Files changed (3) hide show
  1. package/index.js +125 -0
  2. package/package.json +30 -4
  3. package/README.md +0 -3
package/index.js ADDED
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+ // npm create aicms@latest [dir] -- [--no-install]
3
+ // Writes package.json, installs aicms, and runs `aicms init` so the starter
4
+ // files always come from the aicms version you installed. No dependencies.
5
+
6
+ import { spawnSync } from "node:child_process";
7
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
8
+ import { basename, join, relative, resolve } from "node:path";
9
+ import { createInterface } from "node:readline/promises";
10
+ import { parseArgs } from "node:util";
11
+
12
+ const own = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
13
+ const tty = process.stdout.isTTY && !process.env.NO_COLOR;
14
+ const paint = (code) => (s) => (tty ? `\x1b[${code}m${s}\x1b[0m` : s);
15
+ const bold = paint(1);
16
+ const dim = paint(2);
17
+ const green = paint(32);
18
+ const red = paint(31);
19
+
20
+ const HELP = `create-aicms ${own.version}: start a site on AICMS, the CMS for AI agents
21
+
22
+ Usage: npm create aicms@latest [dir] [-- options]
23
+
24
+ Options
25
+ --no-install Only write package.json; install and run "aicms init" yourself
26
+ --pm <name> npm, pnpm, yarn or bun (default: the one running this)
27
+ -h, --help This help`;
28
+
29
+ function fail(message) {
30
+ console.error(`${red("✗")} ${message}`);
31
+ process.exit(1);
32
+ }
33
+
34
+ /** The package manager that ran us, from npm_config_user_agent ("pnpm/9.1.0 npm/? node/…"). */
35
+ function detectPm() {
36
+ const ua = process.env.npm_config_user_agent ?? "";
37
+ for (const pm of ["pnpm", "yarn", "bun"]) if (ua.startsWith(`${pm}/`)) return pm;
38
+ return "npm";
39
+ }
40
+
41
+ /** A valid npm package name from a folder name. */
42
+ function packageName(dir) {
43
+ const name = basename(dir).toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[._-]+|[-._]+$/g, "");
44
+ return name || "aicms-site";
45
+ }
46
+
47
+ function run(cmd, args, cwd) {
48
+ const r = spawnSync(cmd, args, { cwd, stdio: "inherit", shell: process.platform === "win32" });
49
+ return r.status === 0;
50
+ }
51
+
52
+ async function main() {
53
+ const { values, positionals } = parseArgs({
54
+ allowPositionals: true,
55
+ options: {
56
+ install: { type: "boolean", default: true },
57
+ "no-install": { type: "boolean" },
58
+ pm: { type: "string" },
59
+ help: { type: "boolean", short: "h" },
60
+ },
61
+ });
62
+ if (values.help) return console.log(HELP);
63
+ const install = values.install && !values["no-install"];
64
+ const pm = values.pm ?? detectPm();
65
+ if (!["npm", "pnpm", "yarn", "bun"].includes(pm)) fail(`Unknown package manager "${pm}"`);
66
+
67
+ let dir = positionals[0];
68
+ if (!dir && process.stdin.isTTY) {
69
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
70
+ dir = (await rl.question(`Project folder ${dim("(my-site)")}: `)).trim();
71
+ rl.close();
72
+ }
73
+ dir ||= "my-site";
74
+ const root = resolve(process.cwd(), dir);
75
+ if (existsSync(root) && readdirSync(root).some((f) => f !== ".git" && f !== ".DS_Store")) {
76
+ fail(`${root} isn't empty. Pick a new folder, or run "npx aicms init" inside an existing project.`);
77
+ }
78
+ mkdirSync(root, { recursive: true });
79
+
80
+ // AICMS_PACKAGE lets tests install a local tarball instead of the registry version.
81
+ const dependency = process.env.AICMS_PACKAGE ?? `^${own.version}`;
82
+ const pkg = {
83
+ name: packageName(root),
84
+ private: true,
85
+ type: "module",
86
+ scripts: {
87
+ dev: "aicms dev",
88
+ start: "aicms start",
89
+ types: "aicms types --out aicms-types.ts",
90
+ },
91
+ dependencies: { aicms: dependency },
92
+ engines: { node: ">=22.13" },
93
+ };
94
+ writeFileSync(join(root, "package.json"), JSON.stringify(pkg, null, 2) + "\n");
95
+ console.log(`${green("✓")} Created ${bold(join(relative(process.cwd(), root) || ".", "package.json"))}`);
96
+
97
+ const where = relative(process.cwd(), root) || ".";
98
+ const runScript = pm === "npm" ? "npm run" : pm;
99
+ if (!install) {
100
+ console.log(`
101
+ Next:
102
+ cd ${where}
103
+ ${pm} install
104
+ npx aicms init ${dim("# aicms.config.ts, models, .mcp.json")}
105
+ ${runScript} dev`);
106
+ return;
107
+ }
108
+
109
+ console.log(dim(`\n${pm} install…`));
110
+ if (!run(pm, ["install"], root)) fail(`${pm} install failed. Fix the error above, then run "${pm} install" and "npx aicms init" in ${where}.`);
111
+ const cli = join(root, "node_modules", "aicms", "dist", "cli.js");
112
+ if (!existsSync(cli)) fail(`aicms didn't install into ${where}/node_modules`);
113
+ if (!run(process.execPath, [cli, "init", "."], root)) fail(`"aicms init" failed in ${where}`);
114
+
115
+ console.log(`
116
+ ${green("✓")} ${bold(pkg.name)} is ready.
117
+
118
+ cd ${where}
119
+ ${runScript} dev ${dim("# Studio, REST, MCP and events on http://127.0.0.1:4321")}
120
+
121
+ Coding agents that read .mcp.json (Claude Code, Cursor) get the site's tools
122
+ as the "writer" agent when you open the folder. Others: see AGENTS.md.`);
123
+ }
124
+
125
+ main().catch((e) => fail(e instanceof Error ? e.message : String(e)));
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "create-aicms",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.5.0",
4
+ "description": "Start an AICMS site: npm create aicms@latest my-site",
5
+ "keywords": [
6
+ "cms",
7
+ "aicms",
8
+ "create",
9
+ "scaffold",
10
+ "ai",
11
+ "agents",
12
+ "mcp"
13
+ ],
14
+ "author": "malkovych",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/malkovych/aicms.git",
19
+ "directory": "packages/create-aicms"
20
+ },
21
+ "homepage": "https://malkovych.github.io/aicms/",
22
+ "type": "module",
23
+ "bin": {
24
+ "create-aicms": "./index.js"
25
+ },
26
+ "files": [
27
+ "index.js"
28
+ ],
29
+ "engines": {
30
+ "node": ">=22.13"
31
+ }
32
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.