-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage-linux-cli.js
More file actions
66 lines (57 loc) · 2.06 KB
/
Copy pathpackage-linux-cli.js
File metadata and controls
66 lines (57 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
"use strict";
const fs = require("node:fs");
const path = require("node:path");
const { execFileSync } = require("node:child_process");
const ROOT = path.resolve(__dirname, "..");
const DIST = path.join(ROOT, "dist");
const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, "package.json"), "utf8"));
const { versioned: versionedName, latest: latestName } = linuxCliArtifactNames(pkg.version);
function linuxCliArtifactNames(version) {
if (!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(String(version || ""))) {
throw new Error("A semantic package version is required");
}
return {
versioned: `ReRouted-${version}-linux-node.tgz`,
latest: "ReRouted-linux-node.tgz",
};
}
if (require.main !== module) {
module.exports = { linuxCliArtifactNames };
return;
}
fs.mkdirSync(DIST, { recursive: true });
for (const name of [versionedName, latestName]) {
fs.rmSync(path.join(DIST, name), { force: true });
}
const output = execFileSync(
process.platform === "win32" ? "npm.cmd" : "npm",
["pack", "--json", "--pack-destination", DIST],
{ cwd: ROOT, encoding: "utf8" }
);
const result = JSON.parse(output)[0];
if (!result?.filename) throw new Error("npm pack did not return an artifact filename");
const packedPath = path.join(DIST, result.filename);
const versionedPath = path.join(DIST, versionedName);
const latestPath = path.join(DIST, latestName);
fs.renameSync(packedPath, versionedPath);
fs.copyFileSync(versionedPath, latestPath);
const listing = execFileSync("tar", ["-tzf", versionedPath], { encoding: "utf8" });
for (const required of [
"package/package.json",
"package/LICENSE",
"package/src/cli/index.js",
"package/src/lib/headless-runtime.js",
"package/src/lib/gateway.js",
"package/src/renderer/index.html",
"package/src/renderer/web-api.js",
]) {
if (!listing.split("\n").includes(required)) {
throw new Error(`Linux CLI package is missing ${required}`);
}
}
if (/(?:^|\/)AGENTS\.md$/m.test(listing)) {
throw new Error("Linux CLI package must not contain AGENTS.md");
}
console.log(versionedPath);
console.log(latestPath);