create-kedge 0.0.0-stage → 0.9.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/bin/create-kedge.mjs +8 -0
- package/package.json +23 -3
- package/src/create.mjs +123 -0
- package/template.json +1 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The Kedge Authors
|
|
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.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { main } from "../src/create.mjs";
|
|
5
|
+
|
|
6
|
+
process.exitCode = main(process.argv.slice(2), {
|
|
7
|
+
template: join(dirname(fileURLToPath(import.meta.url)), "..", "template.json"),
|
|
8
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-kedge",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/chandeldivyam/Kedge.git",
|
|
8
|
+
"directory": "packages/create-kedge"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"description": "npx create-kedge my-store: a new Kedge store from the starter.",
|
|
12
|
+
"bin": {
|
|
13
|
+
"create-kedge": "./bin/create-kedge.mjs"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"bin",
|
|
17
|
+
"src",
|
|
18
|
+
"template.json"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "24.19.2"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "vitest run"
|
|
25
|
+
}
|
|
6
26
|
}
|
package/src/create.mjs
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// create-kedge: a new store from the starter (docs/proposals/p0.8-cli-agent-kit.md §2).
|
|
2
|
+
// The template is `apps/starter`, which the pack script writes into
|
|
3
|
+
// `template.json` (path → text) rather than as files: npm renames or drops
|
|
4
|
+
// some dot files in a tarball, and a store needs its `.gitignore` and `.claude/`.
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { randomBytes } from "node:crypto";
|
|
7
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
9
|
+
|
|
10
|
+
/** A store's name: it becomes Worker, database and queue names, so Cloudflare's rules apply. */
|
|
11
|
+
export const NAME = /^[a-z][a-z0-9-]{0,38}[a-z0-9]$/;
|
|
12
|
+
/** The starter's placeholder for the store's Cloudflare names. */
|
|
13
|
+
export const PLACEHOLDER = "my-store";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A random suffix for the store's Cloudflare names (§6.1): a Worker upload
|
|
17
|
+
* is create-or-update, so a name nothing else will choose is what keeps a
|
|
18
|
+
* first deploy from overwriting another application in the same account.
|
|
19
|
+
*/
|
|
20
|
+
export const suffix = () => randomBytes(3).toString("hex");
|
|
21
|
+
|
|
22
|
+
/** Each `@kedge/*` tarball in a pack directory, by package name. */
|
|
23
|
+
export function packsIn(dir, version) {
|
|
24
|
+
const out = {};
|
|
25
|
+
for (const f of readdirSync(dir)) {
|
|
26
|
+
const m = /^kedge-(.+)-(\d+\.\d+\.\d+)\.tgz$/.exec(f);
|
|
27
|
+
if (m && m[2] === version) out[`@kedge/${m[1]}`] = resolve(dir, f);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The new store's files: the template with the store's name in package.json,
|
|
34
|
+
* its suffixed name in wrangler.jsonc, and each `workspace:*` pinned to the
|
|
35
|
+
* template's version. With packs, `pnpm-workspace.yaml` overrides every
|
|
36
|
+
* `@kedge/*`, transitive ones included, to its tarball.
|
|
37
|
+
*/
|
|
38
|
+
export function render(template, { name, suffix: sfx, packs }) {
|
|
39
|
+
if (!NAME.test(name)) throw new Error(`"${name}" isn't a store name: lowercase letters, digits and dashes, 2 to 40`);
|
|
40
|
+
const files = { ...template.files };
|
|
41
|
+
const pkg = JSON.parse(files["package.json"]);
|
|
42
|
+
pkg.name = name;
|
|
43
|
+
pkg.version = "0.0.0";
|
|
44
|
+
pkg.private = true;
|
|
45
|
+
for (const field of ["dependencies", "devDependencies"])
|
|
46
|
+
for (const [dep, v] of Object.entries(pkg[field] ?? {}))
|
|
47
|
+
if (v === "workspace:*") pkg[field][dep] = template.version;
|
|
48
|
+
files["package.json"] = `${JSON.stringify(pkg, null, 2)}\n`;
|
|
49
|
+
const wrangler = files["wrangler.jsonc"];
|
|
50
|
+
if (!wrangler?.includes(`"${PLACEHOLDER}`)) throw new Error(`the template's wrangler.jsonc lacks "${PLACEHOLDER}"`);
|
|
51
|
+
files["wrangler.jsonc"] = wrangler.replaceAll(PLACEHOLDER, `${name}-${sfx}`);
|
|
52
|
+
// pnpm runs no dependency's install script unless allowed: workerd and
|
|
53
|
+
// esbuild fetch their binaries in theirs, and Wrangler needs both.
|
|
54
|
+
let workspace = "allowBuilds:\n esbuild: true\n workerd: true\n";
|
|
55
|
+
if (packs) {
|
|
56
|
+
const lines = Object.entries(packs)
|
|
57
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
58
|
+
.map(([dep, file]) => ` "${dep}": "file:${file}"`);
|
|
59
|
+
workspace += `# Kedge's packages from local tarballs (create-kedge --from-packs).\noverrides:\n${lines.join("\n")}\n`;
|
|
60
|
+
}
|
|
61
|
+
files["pnpm-workspace.yaml"] = workspace;
|
|
62
|
+
return files;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function write(dir, files) {
|
|
66
|
+
for (const [path, text] of Object.entries(files)) {
|
|
67
|
+
if (isAbsolute(path) || path.split("/").includes("..")) throw new Error(`template path ${path} escapes the store`);
|
|
68
|
+
const target = join(dir, path);
|
|
69
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
70
|
+
writeFileSync(target, text);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const USAGE = `usage: create-kedge <directory> [--name <name>] [--from-packs <dir>] [--no-install] [--no-git]`;
|
|
75
|
+
|
|
76
|
+
export function main(argv, { template, run = spawnSync, log = console.log, error = console.error } = {}) {
|
|
77
|
+
const flags = new Set(argv.filter((a) => a.startsWith("--no-")));
|
|
78
|
+
const value = (f) => {
|
|
79
|
+
const i = argv.indexOf(f);
|
|
80
|
+
return i >= 0 ? argv[i + 1] : undefined;
|
|
81
|
+
};
|
|
82
|
+
const positional = argv.filter((a, i) => !a.startsWith("--") && !["--name", "--from-packs"].includes(argv[i - 1]));
|
|
83
|
+
const target = positional[0];
|
|
84
|
+
if (!target) {
|
|
85
|
+
error(USAGE);
|
|
86
|
+
return 2;
|
|
87
|
+
}
|
|
88
|
+
const dir = resolve(target);
|
|
89
|
+
if (existsSync(dir) && readdirSync(dir).length > 0) {
|
|
90
|
+
error(`${dir} isn't empty`);
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
const name = value("--name") ?? basename(dir).toLowerCase();
|
|
94
|
+
const fromPacks = value("--from-packs");
|
|
95
|
+
const t = JSON.parse(readFileSync(template, "utf8"));
|
|
96
|
+
let files;
|
|
97
|
+
try {
|
|
98
|
+
files = render(t, { name, suffix: suffix(), packs: fromPacks ? packsIn(fromPacks, t.version) : undefined });
|
|
99
|
+
} catch (e) {
|
|
100
|
+
error(e.message);
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
mkdirSync(dir, { recursive: true });
|
|
104
|
+
write(dir, files);
|
|
105
|
+
log(`created ${name} in ${dir} (Kedge ${t.version})`);
|
|
106
|
+
if (!flags.has("--no-git")) run("git", ["init", "-q"], { cwd: dir, stdio: "inherit" });
|
|
107
|
+
if (!flags.has("--no-install")) {
|
|
108
|
+
const r = run("pnpm", ["install"], { cwd: dir, stdio: "inherit" });
|
|
109
|
+
if (r.status !== 0) {
|
|
110
|
+
error("pnpm install failed; fix it and run `pnpm install` in the store");
|
|
111
|
+
return r.status ?? 1;
|
|
112
|
+
}
|
|
113
|
+
// The agent kit's skills ship in @kedge/docs and are copied by generate, gitignored, so the
|
|
114
|
+
// store's AGENTS.md can point an agent at them from its first session (p0.8 §9.3).
|
|
115
|
+
const g = run("pnpm", ["exec", "kedge", "generate"], { cwd: dir, stdio: "inherit" });
|
|
116
|
+
if (g.status !== 0) {
|
|
117
|
+
error("kedge generate failed; run `pnpm kedge generate` in the store");
|
|
118
|
+
return g.status ?? 1;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
log(`next: cd ${target} && pnpm kedge check`);
|
|
122
|
+
return 0;
|
|
123
|
+
}
|