|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import fs from "node:fs"; |
| 4 | +import path from "node:path"; |
| 5 | +import process from "node:process"; |
| 6 | +import { execFileSync } from "node:child_process"; |
| 7 | + |
| 8 | +const repoRoot = path.resolve(process.argv[2] ?? "."); |
| 9 | +const packageJsonPath = path.join(repoRoot, "package.json"); |
| 10 | +const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); |
| 11 | +const binPath = packageJson.bin?.imgbin; |
| 12 | + |
| 13 | +if (!binPath) { |
| 14 | + throw new Error("package.json must define bin.imgbin before publishing."); |
| 15 | +} |
| 16 | + |
| 17 | +const resolvedBinPath = path.join(repoRoot, binPath); |
| 18 | +if (!fs.existsSync(resolvedBinPath)) { |
| 19 | + throw new Error(`Missing built CLI entrypoint: ${binPath}`); |
| 20 | +} |
| 21 | + |
| 22 | +const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm"; |
| 23 | +const output = execFileSync(npmCommand, ["pack", "--dry-run", "--json"], { |
| 24 | + cwd: repoRoot, |
| 25 | + encoding: "utf8", |
| 26 | +}); |
| 27 | +const [packSummary] = JSON.parse(output); |
| 28 | +const packedFiles = new Set((packSummary?.files ?? []).map((file) => file.path)); |
| 29 | +const requiredFiles = [binPath, "README.md", "prompts/default-analysis-prompt.txt"]; |
| 30 | +const missingFiles = requiredFiles.filter((file) => !packedFiles.has(file)); |
| 31 | + |
| 32 | +if (missingFiles.length > 0) { |
| 33 | + throw new Error( |
| 34 | + `npm pack is missing required publish files: ${missingFiles.join(", ")}`, |
| 35 | + ); |
| 36 | +} |
| 37 | + |
| 38 | +process.stdout.write( |
| 39 | + `Verified ${packSummary.name} with ${packSummary.files.length} packed files.\n`, |
| 40 | +); |
0 commit comments