release: WRNexusJS 0.4.0
This commit is contained in:
+41
-15
@@ -1,8 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
/* global console */
|
||||
import { cp, mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { spawn } from "node:child_process";
|
||||
import process from "node:process";
|
||||
|
||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||
const bundleRoot = resolve(scriptDir, "..");
|
||||
@@ -15,18 +17,35 @@ const withShowcase = flags.has("--with-showcase");
|
||||
const withManaged = flags.has("--with-managed-service");
|
||||
const runChecks = flags.has("--check");
|
||||
|
||||
async function exists(path) { try { await stat(path); return true; } catch { return false; } }
|
||||
async function exists(path) {
|
||||
try {
|
||||
await stat(path);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
async function copyDirectory(source, destination) {
|
||||
if ((await exists(destination)) && force) await rm(destination, { recursive: true, force: true });
|
||||
await mkdir(dirname(destination), { recursive: true });
|
||||
await cp(source, destination, { recursive: true, force: true });
|
||||
}
|
||||
async function readJson(path) { return JSON.parse(await readFile(path, "utf8")); }
|
||||
async function writeJson(path, value) { await writeFile(path, `${JSON.stringify(value, null, 2)}\n`); }
|
||||
async function readJson(path) {
|
||||
return JSON.parse(await readFile(path, "utf8"));
|
||||
}
|
||||
async function writeJson(path, value) {
|
||||
await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
|
||||
}
|
||||
async function run(command, commandArgs) {
|
||||
await new Promise((resolvePromise, reject) => {
|
||||
const child = spawn(command, commandArgs, { cwd: target, stdio: "inherit", shell: process.platform === "win32" });
|
||||
child.on("exit", (code) => code === 0 ? resolvePromise() : reject(new Error(`${command} exited with ${code}`)));
|
||||
const child = spawn(command, commandArgs, {
|
||||
cwd: target,
|
||||
stdio: "inherit",
|
||||
shell: process.platform === "win32",
|
||||
});
|
||||
child.on("exit", (code) =>
|
||||
code === 0 ? resolvePromise() : reject(new Error(`${command} exited with ${code}`)),
|
||||
);
|
||||
child.on("error", reject);
|
||||
});
|
||||
}
|
||||
@@ -36,16 +55,22 @@ if (!(await exists(join(target, "packages"))) || !(await exists(join(target, "ts
|
||||
}
|
||||
|
||||
await copyDirectory(join(bundleRoot, "packages/captcha"), join(target, "packages/captcha"));
|
||||
await mkdir(join(target, "packages/ui/components"), { recursive: true });
|
||||
const uiComponent = join(target, "packages/ui/components/Captcha.wrn");
|
||||
if (!(await exists(uiComponent)) || force) {
|
||||
await cp(join(bundleRoot, "packages/captcha/components/Captcha.wrn"), uiComponent, { force: true });
|
||||
} else {
|
||||
console.warn(`Skipped existing ${uiComponent}; use --force to replace it.`);
|
||||
}
|
||||
|
||||
if (withShowcase) await copyDirectory(join(bundleRoot, "examples/captcha-showcase"), join(target, "examples/captcha-showcase"));
|
||||
if (withManaged) await copyDirectory(join(bundleRoot, "services/managed-captcha"), join(target, "services/managed-captcha"));
|
||||
// WRNexusJS 0.4 discovers package-owned components and browser runtimes through
|
||||
// package.json `wrnexus` metadata. Do not copy Captcha.wrn or captcha.js into the
|
||||
// UI/public directories: doing so creates stale duplicates that bypass package
|
||||
// upgrades and content-hashed production assets.
|
||||
|
||||
if (withShowcase)
|
||||
await copyDirectory(
|
||||
join(bundleRoot, "examples/captcha-showcase"),
|
||||
join(target, "examples/captcha-showcase"),
|
||||
);
|
||||
if (withManaged)
|
||||
await copyDirectory(
|
||||
join(bundleRoot, "services/managed-captcha"),
|
||||
join(target, "services/managed-captcha"),
|
||||
);
|
||||
|
||||
const tsconfigPath = join(target, "tsconfig.json");
|
||||
const tsconfig = await readJson(tsconfigPath);
|
||||
@@ -70,7 +95,8 @@ if (withManaged) {
|
||||
|
||||
console.log("Installed @wrnexus/captcha.");
|
||||
console.log("Canonical package: packages/captcha");
|
||||
console.log("Discoverable component: packages/ui/components/Captcha.wrn");
|
||||
console.log("Component/runtime discovery: automatic through package.json wrnexus.plugin");
|
||||
console.log("No public captcha.js or UI component copy is required.");
|
||||
|
||||
if (runChecks) {
|
||||
await run("bun", ["install"]);
|
||||
|
||||
Reference in New Issue
Block a user