Reorganize repo structure and standards references

This commit is contained in:
david committed 2026-06-29 05:03:42 +02:00
1 parent 3cb93a81be
commit be2054274d
5885 files changed
+2588 -195

No files matched your search

@@ -0,0 +1,61 @@
import { describe, expect, test } from "vitest";
import { renderPluginScaffold, writePluginScaffold } from "./scaffold.js";
describe("renderPluginScaffold", () => {
test("emits the five expected files for a valid name", () => {
const files = renderPluginScaffold({ name: "slack-notifier", targetDir: "/tmp" });
const paths = files.map((f) => f.path).sort();
expect(paths).toEqual([
"README.md",
"package.json",
"plugin.toml",
"src/index.ts",
"tsconfig.json",
]);
});
test("plugin.toml carries the supplied publisher in the id", () => {
const [manifest] = renderPluginScaffold({
name: "slack",
targetDir: "/tmp",
publisher: "de.acme",
});
expect(manifest?.contents).toContain(`id = "de.acme.slack"`);
});
test("rejects names with uppercase or whitespace", () => {
expect(() => renderPluginScaffold({ name: "BadName", targetDir: "/tmp" })).toThrow(/invalid plugin name/u);
expect(() => renderPluginScaffold({ name: "has space", targetDir: "/tmp" })).toThrow(/invalid plugin name/u);
});
test("rejects publisher prefixes that produce non-reverse-DNS ids", () => {
expect(() => renderPluginScaffold({ name: "x", targetDir: "/tmp", publisher: "TOP" })).toThrow(/reverse-DNS/u);
});
test("source file imports from @toolctrl/plugin-sdk", () => {
const files = renderPluginScaffold({ name: "x", targetDir: "/tmp" });
const src = files.find((f) => f.path === "src/index.ts");
expect(src?.contents).toContain('from "@toolctrl/plugin-sdk"');
});
});
describe("writePluginScaffold (dry-friendly IO)", () => {
test("calls writeFile once per emitted file under the target root", async () => {
const writes: { path: string; bytes: number }[] = [];
const mkdirs: string[] = [];
const written = await writePluginScaffold(
{ name: "demo", targetDir: "/tmp/plugins" },
{
async mkdir(p) {
mkdirs.push(p);
},
async writeFile(p, c) {
writes.push({ path: p, bytes: c.length });
},
}
);
expect(writes).toHaveLength(5);
expect(written.every((p) => p.includes("/tmp/plugins/demo"))).toBe(true);
expect(mkdirs[0]).toContain("/tmp/plugins/demo");
});
});