@justestif/go-jobs 0.0.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/bin.js +17 -0
- package/install.js +87 -0
- package/package.json +21 -0
package/bin.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
const { spawnSync } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
|
|
7
|
+
const exe = process.platform === "win32" ? "jobs.exe" : "jobs";
|
|
8
|
+
const binPath = path.join(__dirname, "bin", exe);
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(binPath)) {
|
|
11
|
+
console.error(`jobs: binary not found at ${binPath}`);
|
|
12
|
+
console.error("Try reinstalling: npm install -g @justestif/go-jobs");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const result = spawnSync(binPath, process.argv.slice(2), { stdio: "inherit" });
|
|
17
|
+
process.exit(result.status ?? 1);
|
package/install.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const https = require("https");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { execFileSync } = require("child_process");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
|
|
8
|
+
const BINARY = "jobs";
|
|
9
|
+
const REPO = "justEstif/go-jobs";
|
|
10
|
+
const VERSION = require("./package.json").version;
|
|
11
|
+
|
|
12
|
+
const PLATFORM_MAP = {
|
|
13
|
+
"linux-x64": { os: "linux", arch: "amd64", ext: ".tar.gz" },
|
|
14
|
+
"linux-arm64": { os: "linux", arch: "arm64", ext: ".tar.gz" },
|
|
15
|
+
"darwin-x64": { os: "darwin", arch: "amd64", ext: ".tar.gz" },
|
|
16
|
+
"darwin-arm64": { os: "darwin", arch: "arm64", ext: ".tar.gz" },
|
|
17
|
+
"win32-x64": { os: "windows", arch: "amd64", ext: ".zip" },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const key = `${process.platform}-${process.arch}`;
|
|
21
|
+
const plat = PLATFORM_MAP[key];
|
|
22
|
+
if (!plat) {
|
|
23
|
+
console.error(`@justestif/go-jobs: unsupported platform "${key}"`);
|
|
24
|
+
console.error(`Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const exe = process.platform === "win32" ? `${BINARY}.exe` : BINARY;
|
|
29
|
+
const archiveName = `jobs_v${VERSION}_${plat.os}_${plat.arch}${plat.ext}`;
|
|
30
|
+
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`;
|
|
31
|
+
const binDir = path.join(__dirname, "bin");
|
|
32
|
+
const tmpFile = path.join(os.tmpdir(), archiveName);
|
|
33
|
+
const outPath = path.join(binDir, exe);
|
|
34
|
+
|
|
35
|
+
if (fs.existsSync(outPath)) {
|
|
36
|
+
process.exit(0); // already installed
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
40
|
+
|
|
41
|
+
console.log(`Downloading jobs from ${url}...`);
|
|
42
|
+
|
|
43
|
+
function tryUnlink(p) {
|
|
44
|
+
try { fs.unlinkSync(p); } catch {}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function download(url, dest, cb) {
|
|
48
|
+
const file = fs.createWriteStream(dest);
|
|
49
|
+
https.get(url, (res) => {
|
|
50
|
+
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
51
|
+
file.close();
|
|
52
|
+
tryUnlink(dest);
|
|
53
|
+
return download(res.headers.location, dest, cb);
|
|
54
|
+
}
|
|
55
|
+
if (res.statusCode !== 200) {
|
|
56
|
+
file.close();
|
|
57
|
+
tryUnlink(dest);
|
|
58
|
+
return cb(new Error(`HTTP ${res.statusCode} for ${url}`));
|
|
59
|
+
}
|
|
60
|
+
res.pipe(file);
|
|
61
|
+
file.on("finish", () => file.close(cb));
|
|
62
|
+
}).on("error", (err) => {
|
|
63
|
+
tryUnlink(dest);
|
|
64
|
+
cb(err);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
download(url, tmpFile, (err) => {
|
|
69
|
+
if (err) {
|
|
70
|
+
console.error(`Failed to download jobs: ${err.message}`);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
if (plat.ext === ".zip") {
|
|
76
|
+
execFileSync("unzip", ["-j", tmpFile, exe, "-d", binDir]);
|
|
77
|
+
} else {
|
|
78
|
+
execFileSync("tar", ["-xzf", tmpFile, "--strip-components=0", "-C", binDir]);
|
|
79
|
+
}
|
|
80
|
+
fs.chmodSync(outPath, 0o755);
|
|
81
|
+
fs.unlinkSync(tmpFile);
|
|
82
|
+
console.log(`Installed jobs to ${outPath}`);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.error(`Failed to extract jobs: ${e.message}`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@justestif/go-jobs",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "CLI for jobs.estifanos.cc — search job postings and track applications",
|
|
5
|
+
"bin": {
|
|
6
|
+
"jobs": "bin.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node install.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin.js",
|
|
13
|
+
"install.js",
|
|
14
|
+
"bin/"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/justEstif/go-jobs.git"
|
|
20
|
+
}
|
|
21
|
+
}
|