@harvey-au/hover 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @harvey-au/hover
2
+
3
+ CLI for the Hover cache-warming platform.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install -g @harvey-au/hover
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```sh
14
+ hover jobs generate --pr <number>
15
+ ```
16
+
17
+ See [GitHub releases](https://github.com/Harvey-AU/hover/releases) for changelogs.
package/bin/.gitkeep ADDED
File without changes
package/install.js ADDED
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { execFileSync } = require("child_process");
5
+ const fs = require("fs");
6
+ const https = require("https");
7
+ const path = require("path");
8
+
9
+ const REPO = "Harvey-AU/hover";
10
+ const BIN_DIR = path.join(__dirname, "bin");
11
+ const BIN_NAME = process.platform === "win32" ? "hover.exe" : "hover";
12
+ const BIN_PATH = path.join(BIN_DIR, BIN_NAME);
13
+
14
+ const PLATFORM_MAP = { darwin: "darwin", linux: "linux", win32: "windows" };
15
+ const ARCH_MAP = { x64: "amd64", arm64: "arm64" };
16
+
17
+ function getVersion() {
18
+ const pkg = require("./package.json");
19
+ return pkg.version;
20
+ }
21
+
22
+ function isWindows() {
23
+ return process.platform === "win32";
24
+ }
25
+
26
+ function getAssetName() {
27
+ const os = PLATFORM_MAP[process.platform];
28
+ const arch = ARCH_MAP[process.arch];
29
+ if (!os || !arch) {
30
+ throw new Error(
31
+ `Unsupported platform: ${process.platform}-${process.arch}`
32
+ );
33
+ }
34
+ const ext = isWindows() ? "zip" : "tar.gz";
35
+ return `hover_${getVersion()}_${os}_${arch}.${ext}`;
36
+ }
37
+
38
+ function fetch(url) {
39
+ return new Promise((resolve, reject) => {
40
+ https
41
+ .get(url, (res) => {
42
+ if (
43
+ res.statusCode >= 300 &&
44
+ res.statusCode < 400 &&
45
+ res.headers.location
46
+ ) {
47
+ return fetch(res.headers.location).then(resolve, reject);
48
+ }
49
+ if (res.statusCode !== 200) {
50
+ return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
51
+ }
52
+ const chunks = [];
53
+ res.on("data", (c) => chunks.push(c));
54
+ res.on("end", () => resolve(Buffer.concat(chunks)));
55
+ res.on("error", reject);
56
+ })
57
+ .on("error", reject);
58
+ });
59
+ }
60
+
61
+ async function main() {
62
+ const version = getVersion();
63
+ const asset = getAssetName();
64
+ const url = `https://github.com/${REPO}/releases/download/v${version}/${asset}`;
65
+
66
+ console.log(
67
+ `Downloading hover v${version} for ${process.platform}-${process.arch}...`
68
+ );
69
+
70
+ const buffer = await fetch(url);
71
+
72
+ // Write archive to temp file and extract.
73
+ fs.mkdirSync(BIN_DIR, { recursive: true });
74
+
75
+ if (isWindows()) {
76
+ const tmpFile = path.join(BIN_DIR, "_download.zip");
77
+ fs.writeFileSync(tmpFile, buffer);
78
+ execFileSync(
79
+ "powershell",
80
+ [
81
+ "-NoProfile",
82
+ "-Command",
83
+ `Expand-Archive -Force -Path '${tmpFile}' -DestinationPath '${BIN_DIR}'`,
84
+ ],
85
+ { stdio: "ignore" }
86
+ );
87
+ fs.unlinkSync(tmpFile);
88
+ } else {
89
+ const tmpFile = path.join(BIN_DIR, "_download.tar.gz");
90
+ fs.writeFileSync(tmpFile, buffer);
91
+ execFileSync("tar", ["xzf", tmpFile, "-C", BIN_DIR], { stdio: "ignore" });
92
+ fs.unlinkSync(tmpFile);
93
+ fs.chmodSync(BIN_PATH, 0o755);
94
+ }
95
+ console.log("hover installed successfully.");
96
+ }
97
+
98
+ main().catch((err) => {
99
+ console.error(`Failed to install hover: ${err.message}`);
100
+ process.exit(1);
101
+ });
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@harvey-au/hover",
3
+ "version": "0.1.0",
4
+ "description": "CLI for the Hover cache-warming platform",
5
+ "bin": {
6
+ "hover": "bin/hover"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js"
10
+ },
11
+ "files": [
12
+ "bin/",
13
+ "install.js",
14
+ "README.md"
15
+ ],
16
+ "os": [
17
+ "darwin",
18
+ "linux",
19
+ "win32"
20
+ ],
21
+ "cpu": [
22
+ "x64",
23
+ "arm64"
24
+ ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/Harvey-AU/hover"
28
+ },
29
+ "license": "UNLICENSED"
30
+ }