From f3e30cecc5408fdc19b994b43143568b263c4ee4 Mon Sep 17 00:00:00 2001 From: Antigravity AI Date: Fri, 8 May 2026 11:07:09 +1200 Subject: [PATCH] feat(wwv-cli): implement publish command for wwvpkg creation --- packages/wwv-cli/package.json | 2 + packages/wwv-cli/src/commands/publish.ts | 57 ++++++++++++++++++++++++ packages/wwv-cli/src/index.ts | 14 ++++++ packages/wwv-cli/tests/publish.test.ts | 8 ++++ 4 files changed, 81 insertions(+) create mode 100644 packages/wwv-cli/src/commands/publish.ts create mode 100644 packages/wwv-cli/tests/publish.test.ts diff --git a/packages/wwv-cli/package.json b/packages/wwv-cli/package.json index 3cb12746..f53d539e 100644 --- a/packages/wwv-cli/package.json +++ b/packages/wwv-cli/package.json @@ -9,11 +9,13 @@ "test": "vitest run" }, "dependencies": { + "archiver": "^7.0.1", "commander": "^11.1.0", "vite": "^8.0.8", "ws": "^8.20.0" }, "devDependencies": { + "@types/archiver": "^7.0.0", "@types/node": "^20.0.0", "@types/ws": "^8.18.1", "typescript": "^5.0.0", diff --git a/packages/wwv-cli/src/commands/publish.ts b/packages/wwv-cli/src/commands/publish.ts new file mode 100644 index 00000000..d8198c9e --- /dev/null +++ b/packages/wwv-cli/src/commands/publish.ts @@ -0,0 +1,57 @@ +import fs from "fs"; +import path from "path"; +import { build } from "vite"; +import archiver from "archiver"; + +export async function buildPackage() { + const cwd = process.cwd(); + const manifestPath = path.join(cwd, "wwv-manifest.json"); + + if (!fs.existsSync(manifestPath)) { + throw new Error("No wwv-manifest.json found in current directory"); + } + + const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8")); + + console.log(`[WWV CLI] Building production bundle...`); + await build({ + root: cwd, + build: { + lib: { + entry: path.resolve(cwd, manifest.dev_entry || "src/index.ts"), + name: 'WWVPlugin', + formats: ['es'], + fileName: () => 'frontend.mjs' + }, + outDir: 'dist', + emptyOutDir: true + } + }); + + const pkgName = `${manifest.id}-${manifest.version}.wwvpkg`; + const outputPath = path.join(cwd, pkgName); + + console.log(`[WWV CLI] Creating archive ${pkgName}...`); + + await new Promise((resolve, reject) => { + const output = fs.createWriteStream(outputPath); + const archive = archiver("zip", { zlib: { level: 9 } }); + + output.on("close", () => resolve()); + archive.on("error", (err) => reject(err)); + + archive.pipe(output); + + archive.file(manifestPath, { name: "wwv-manifest.json" }); + archive.directory(path.join(cwd, "dist"), "dist"); + + if (fs.existsSync(path.join(cwd, "data"))) { + archive.directory(path.join(cwd, "data"), "data"); + } + + archive.finalize(); + }); + + console.log(`\nšŸŽ‰ Success! Package created at ${outputPath}`); + console.log(`You can now upload this file to the WorldWideView Marketplace.`); +} diff --git a/packages/wwv-cli/src/index.ts b/packages/wwv-cli/src/index.ts index eac06fdc..ca54c542 100644 --- a/packages/wwv-cli/src/index.ts +++ b/packages/wwv-cli/src/index.ts @@ -36,4 +36,18 @@ program } }); +import { buildPackage } from "./commands/publish"; + +program + .command("publish") + .description("Build and package the plugin into a .wwvpkg file") + .action(async () => { + try { + await buildPackage(); + } catch (err: any) { + console.error("Error:", err.message); + process.exit(1); + } + }); + program.parse(); diff --git a/packages/wwv-cli/tests/publish.test.ts b/packages/wwv-cli/tests/publish.test.ts new file mode 100644 index 00000000..eb3b614d --- /dev/null +++ b/packages/wwv-cli/tests/publish.test.ts @@ -0,0 +1,8 @@ +import { describe, it, expect } from "vitest"; +import { buildPackage } from "../src/commands/publish"; + +describe("publish command", () => { + it("should export buildPackage function", () => { + expect(typeof buildPackage).toBe("function"); + }); +});