Package Anidev Skill and standalone API panel integration
This commit is contained in:
1 parent
8e4e8e6ef0
commit
61b05abe44
43 files changed
+1859
-57
No files matched your search
@@ -0,0 +1,154 @@
|
||||
import {
|
||||
cp,
|
||||
mkdir,
|
||||
readFile,
|
||||
writeFile,
|
||||
readdir,
|
||||
lstat,
|
||||
rm,
|
||||
} from "node:fs/promises";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
import { createHash } from "node:crypto";
|
||||
|
||||
const root = path.resolve(fileURLToPath(new URL("../", import.meta.url)));
|
||||
const dist = path.join(root, "dist");
|
||||
// Only clear named generated children of this repository's dist. Never follow links.
|
||||
await mkdir(dist, { recursive: true });
|
||||
if ((await lstat(dist)).isSymbolicLink())
|
||||
throw Error("dist must not be a symlink");
|
||||
async function reset(name) {
|
||||
const target = path.resolve(dist, name);
|
||||
if (path.dirname(target) !== dist) throw Error("Invalid build target");
|
||||
const stat = await lstat(target).catch((e) => {
|
||||
if (e.code !== "ENOENT") throw e;
|
||||
});
|
||||
if (stat?.isSymbolicLink()) throw Error("Build target must not be a symlink");
|
||||
await rm(target, { recursive: true, force: true });
|
||||
await mkdir(target, { recursive: true });
|
||||
return target;
|
||||
}
|
||||
const pkg = await reset("package"),
|
||||
skills = await reset("skills"),
|
||||
starter = await reset("starter");
|
||||
const { version } = JSON.parse(
|
||||
await readFile(path.join(root, "package.json"), "utf8"),
|
||||
);
|
||||
async function copy(from, to) {
|
||||
await mkdir(path.dirname(to), { recursive: true });
|
||||
await cp(path.join(root, from), to, { recursive: true });
|
||||
}
|
||||
for (const file of [
|
||||
"runtime/index.js",
|
||||
"components/system.css",
|
||||
"components/workspaces.css",
|
||||
"components/toast.js",
|
||||
"components/search-select.js",
|
||||
"components/copy-field.js",
|
||||
"components/dock.js",
|
||||
"components/navigation.js",
|
||||
"components/ssh-console.js",
|
||||
"components/log-reader.js",
|
||||
"patterns/demo-pty.js",
|
||||
"concepts/registry.js",
|
||||
"tokens/dock",
|
||||
"tokens/schema.json",
|
||||
"vendor/xterm",
|
||||
"icons/icons.js",
|
||||
"icons/manifest.json",
|
||||
"icons/sprite.svg",
|
||||
"icons/svg",
|
||||
])
|
||||
await copy(file, path.join(pkg, file));
|
||||
for (const file of [
|
||||
"DESIGN.md",
|
||||
"ANTI-SLOP.md",
|
||||
"components/CONTRACT.md",
|
||||
"patterns/UX.md",
|
||||
"patterns/WORKSPACES.md",
|
||||
"patterns/IDENTITY.md",
|
||||
"prompts/SSO.md",
|
||||
])
|
||||
await copy(file, path.join(pkg, "docs", file));
|
||||
await copy("docs/INTEGRATION.md", path.join(pkg, "docs/INTEGRATION.md"));
|
||||
const integration = await readFile(
|
||||
path.join(root, "docs/INTEGRATION.md"),
|
||||
"utf8",
|
||||
);
|
||||
await writeFile(
|
||||
path.join(pkg, "README.md"),
|
||||
integration
|
||||
.replaceAll("(PUBLIC-API.md)", "(docs/PUBLIC-API.md)")
|
||||
.replaceAll("(../NOTICE.md)", "(NOTICE.md)"),
|
||||
);
|
||||
const publicApi = await readFile(path.join(root, "docs/PUBLIC-API.md"), "utf8");
|
||||
await writeFile(
|
||||
path.join(pkg, "docs/PUBLIC-API.md"),
|
||||
publicApi
|
||||
.replaceAll("(../components/", "(components/")
|
||||
.replaceAll("(../patterns/", "(patterns/"),
|
||||
);
|
||||
await copy("docs/PANEL-API.md", path.join(pkg, "docs/PANEL-API.md"));
|
||||
await copy("NOTICE.md", path.join(pkg, "NOTICE.md"));
|
||||
await writeFile(
|
||||
path.join(pkg, "package.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
name: "@anidev/design-system",
|
||||
version,
|
||||
private: true,
|
||||
type: "module",
|
||||
license: "UNLICENSED",
|
||||
description: "Anidev Dock HTML/CSS/ESM integration preview",
|
||||
exports: {
|
||||
".": "./runtime/index.js",
|
||||
"./styles.css": "./components/system.css",
|
||||
"./tokens/light.css": "./tokens/dock/light.css",
|
||||
"./tokens/dark.css": "./tokens/dock/dark.css",
|
||||
"./tokens/light.json": "./tokens/dock/light.json",
|
||||
"./tokens/dark.json": "./tokens/dock/dark.json",
|
||||
"./ssh": "./components/ssh-console.js",
|
||||
"./logs": "./components/log-reader.js",
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
);
|
||||
async function hashes(dir, prefix = "") {
|
||||
const result = {};
|
||||
for (const entry of (await readdir(dir, { withFileTypes: true })).sort(
|
||||
(a, b) => a.name.localeCompare(b.name),
|
||||
)) {
|
||||
const relative = prefix + entry.name;
|
||||
if (entry.isDirectory())
|
||||
Object.assign(
|
||||
result,
|
||||
await hashes(path.join(dir, entry.name), relative + "/"),
|
||||
);
|
||||
else
|
||||
result[relative] = createHash("sha256")
|
||||
.update(await readFile(path.join(dir, entry.name)))
|
||||
.digest("hex");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
await writeFile(
|
||||
path.join(pkg, "manifest.json"),
|
||||
JSON.stringify(
|
||||
{ version, channel: "integration-preview", files: await hashes(pkg) },
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
);
|
||||
const skill = path.join(skills, "anidev-design-system");
|
||||
await copy("skills/anidev-design-system", skill);
|
||||
await mkdir(path.join(skill, "assets"), { recursive: true });
|
||||
await cp(pkg, path.join(skill, "assets/anidev"), { recursive: true });
|
||||
await copy("examples/starter", starter);
|
||||
await cp(pkg, path.join(starter, "anidev"), { recursive: true });
|
||||
await mkdir(path.join(skill, "assets/starter"), { recursive: true });
|
||||
await copy("examples/starter", path.join(skill, "assets/starter"));
|
||||
console.log(
|
||||
`Built Anidev ${version}: dist/package, dist/starter, dist/skills/anidev-design-system`,
|
||||
);
|
||||
@@ -0,0 +1,33 @@
|
||||
import { cp, mkdir, lstat, readFile } from "node:fs/promises";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length !== 2 || args[0] !== "--project")
|
||||
throw Error("Usage: node scripts/install-skill.mjs --project <project-root>");
|
||||
const project = await import("node:fs/promises").then((fs) =>
|
||||
fs.realpath(path.resolve(args[1])),
|
||||
);
|
||||
const source = fileURLToPath(
|
||||
new URL("../dist/skills/anidev-design-system/", import.meta.url),
|
||||
);
|
||||
await readFile(path.join(source, "SKILL.md"));
|
||||
let parent = project;
|
||||
for (const name of [".agents", "skills"]) {
|
||||
parent = path.join(parent, name);
|
||||
const stat = await lstat(parent).catch((e) => {
|
||||
if (e.code !== "ENOENT") throw e;
|
||||
});
|
||||
if (stat?.isSymbolicLink() || (stat && !stat.isDirectory()))
|
||||
throw Error("Skill install path must be a real directory");
|
||||
await mkdir(parent, { recursive: true });
|
||||
}
|
||||
const target = path.join(parent, "anidev-design-system");
|
||||
const exists = await lstat(target).catch((e) => {
|
||||
if (e.code !== "ENOENT") throw e;
|
||||
});
|
||||
if (exists)
|
||||
throw Error(
|
||||
`Skill already exists; compare versions before replacing: ${target}`,
|
||||
);
|
||||
await cp(source, target, { recursive: true, force: false, errorOnExist: true });
|
||||
console.log(`Installed project skill: ${target}`);
|
||||
@@ -0,0 +1,26 @@
|
||||
"""Archive already-built, self-contained deliverables; no publishing or installation."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile, ZIP_DEFLATED
|
||||
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
version = json.loads((root / "package.json").read_text(encoding="utf-8"))["version"]
|
||||
dist = root / "dist"
|
||||
for source, name, prefix in [
|
||||
(dist / "skills/anidev-design-system", f"anidev-skill-{version}.zip", "anidev-design-system"),
|
||||
(dist / "starter", f"anidev-panel-{version}.zip", "anidev-panel"),
|
||||
]:
|
||||
if not (source / ("SKILL.md" if "skill" in name else "index.html")).is_file():
|
||||
raise SystemExit("Run npm run build:package first")
|
||||
files = sorted(source.rglob("*"))
|
||||
target = dist / name
|
||||
with ZipFile(target, "w", ZIP_DEFLATED) as archive:
|
||||
for file in files:
|
||||
if file.is_symlink():
|
||||
raise SystemExit(f"Symlink in release input: {file}")
|
||||
if file.is_file():
|
||||
archive.write(file, (Path(prefix) / file.relative_to(source)).as_posix())
|
||||
with ZipFile(target) as archive:
|
||||
if archive.testzip() is not None:
|
||||
raise SystemExit(f"Invalid archive: {target}")
|
||||
print(f"{target.name}: {len(archive.namelist())} files, CRC valid")
|
||||
+4
-2
@@ -12,7 +12,7 @@ const types = {
|
||||
".md": "text/plain; charset=utf-8",
|
||||
};
|
||||
const port = Number(process.env.PORT || 4173);
|
||||
http
|
||||
const server = http
|
||||
.createServer(async (req, res) => {
|
||||
try {
|
||||
const pathname = decodeURIComponent(
|
||||
@@ -35,5 +35,7 @@ http
|
||||
}
|
||||
})
|
||||
.listen(port, "127.0.0.1", () =>
|
||||
console.log(`Anidev Design System: http://127.0.0.1:${port}`),
|
||||
console.log(
|
||||
`Anidev Design System: http://127.0.0.1:${server.address().port}`,
|
||||
),
|
||||
);
|
||||
@@ -0,0 +1,70 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
const cwd = fileURLToPath(new URL("../", import.meta.url));
|
||||
function run(file, env = process.env) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(process.execPath, [file], {
|
||||
cwd,
|
||||
env,
|
||||
stdio: "inherit",
|
||||
windowsHide: true,
|
||||
});
|
||||
child.once("error", reject);
|
||||
child.once("exit", (code) =>
|
||||
code === 0 ? resolve() : reject(Error(`${file} exited ${code}`)),
|
||||
);
|
||||
});
|
||||
}
|
||||
await run("scripts/check.mjs");
|
||||
await run("scripts/build-package.mjs");
|
||||
const server = spawn(process.execPath, ["scripts/serve.mjs"], {
|
||||
cwd,
|
||||
env: { ...process.env, PORT: "0" },
|
||||
stdio: ["ignore", "pipe", "inherit"],
|
||||
windowsHide: true,
|
||||
});
|
||||
try {
|
||||
const base = await new Promise((resolve, reject) => {
|
||||
const timeout = setTimeout(
|
||||
() => reject(Error("QA server did not start")),
|
||||
10000,
|
||||
);
|
||||
server.once("error", (e) => {
|
||||
clearTimeout(timeout);
|
||||
reject(e);
|
||||
});
|
||||
server.once("exit", (code) => {
|
||||
clearTimeout(timeout);
|
||||
reject(Error(`QA server exited ${code}`));
|
||||
});
|
||||
server.stdout.on("data", (data) => {
|
||||
const match = String(data).match(/http:\/\/127\.0\.0\.1:\d+/);
|
||||
if (match) {
|
||||
clearTimeout(timeout);
|
||||
resolve(match[0]);
|
||||
}
|
||||
});
|
||||
});
|
||||
const env = { ...process.env, BASE_URL: base };
|
||||
for (const name of [
|
||||
"browser",
|
||||
"dock",
|
||||
"approved-dock",
|
||||
"site",
|
||||
"identity",
|
||||
"totp-layout",
|
||||
"icons",
|
||||
"workspaces",
|
||||
"navigation-feedback",
|
||||
"search-select",
|
||||
"package",
|
||||
]) {
|
||||
console.log(`\nChecking ${name}`);
|
||||
await run(`tests/${name}.mjs`, env);
|
||||
}
|
||||
console.log(
|
||||
"Release checks passed. Browser coverage follows PLAYWRIGHT_EXECUTABLE_PATH; this does not certify other engines.",
|
||||
);
|
||||
} finally {
|
||||
server.kill();
|
||||
}
|
||||
Reference in new issue
Block a user