offwatch 0.5.1 → 0.5.3
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/offwatch.js +1 -1
- package/lib/downloader.js +112 -0
- package/package.json +4 -2
- package/postinstall.js +1 -1
package/bin/offwatch.js
CHANGED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import got from "got";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import fsa from "fs-extra";
|
|
4
|
+
import * as os from "node:os";
|
|
5
|
+
import tar from "tar";
|
|
6
|
+
import stream from "node:stream";
|
|
7
|
+
import { promisify } from "node:util";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import { dirname } from "path";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
|
|
12
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const debugMode = process.env.DEBUG != null;
|
|
14
|
+
const pipeline = promisify(stream.pipeline);
|
|
15
|
+
|
|
16
|
+
const pkg = JSON.parse(fs.readFileSync(__dirname + "/../package.json", "utf8"));
|
|
17
|
+
const CLI_FILENAME = "offwatch";
|
|
18
|
+
|
|
19
|
+
const logDebug = (message) => {
|
|
20
|
+
if (debugMode) {
|
|
21
|
+
console.debug(`[DEBUG] ${message}`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getPlatform = () => {
|
|
26
|
+
const platform = os.platform();
|
|
27
|
+
if (platform === "win32") return "win32-x64";
|
|
28
|
+
if (platform === "darwin") return "darwin-x64";
|
|
29
|
+
return "linux-x64";
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const downloadRelease = async (versionDir) => {
|
|
33
|
+
logDebug(`downloadRelease(${versionDir})`);
|
|
34
|
+
const version = pkg.version;
|
|
35
|
+
const currentVersion = extractVersionParts(version);
|
|
36
|
+
|
|
37
|
+
const releases = (await got
|
|
38
|
+
.get(`https://api.github.com/repos/triss-smith/offwatch/releases`)
|
|
39
|
+
.json());
|
|
40
|
+
|
|
41
|
+
const matchingRelease = releases
|
|
42
|
+
.filter((release) => {
|
|
43
|
+
const releaseVersion = extractVersionParts(release.tag_name);
|
|
44
|
+
return (releaseVersion.major === currentVersion.major &&
|
|
45
|
+
releaseVersion.minor === currentVersion.minor);
|
|
46
|
+
})
|
|
47
|
+
.sort((a, b) => {
|
|
48
|
+
return Number(extractVersionParts(a.tag_name).patch) >
|
|
49
|
+
Number(extractVersionParts(b.tag_name).patch)
|
|
50
|
+
? -1
|
|
51
|
+
: 1;
|
|
52
|
+
})[0] || releases[0];
|
|
53
|
+
|
|
54
|
+
if (!matchingRelease) {
|
|
55
|
+
throw new Error(`No matching release for ${currentVersion.major}.${currentVersion.minor}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const platform = getPlatform();
|
|
59
|
+
const asset = matchingRelease.assets.find((asset) => {
|
|
60
|
+
return asset.name.includes(platform);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (!asset) {
|
|
64
|
+
throw new Error(`${platform} is not currently supported`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
fsa.mkdirpSync(versionDir);
|
|
69
|
+
} catch (e) { }
|
|
70
|
+
|
|
71
|
+
const filePath = path.join(versionDir, CLI_FILENAME);
|
|
72
|
+
logDebug(`download(${asset.browser_download_url})`);
|
|
73
|
+
|
|
74
|
+
// For .js files, just download directly
|
|
75
|
+
if (asset.name.endsWith(".js")) {
|
|
76
|
+
await pipeline(got.stream(asset.browser_download_url), fs.createWriteStream(filePath));
|
|
77
|
+
fs.chmodSync(filePath, 0o755);
|
|
78
|
+
} else {
|
|
79
|
+
// For compressed files
|
|
80
|
+
const tarPath = path.join(versionDir, path.basename(asset.browser_download_url));
|
|
81
|
+
await pipeline(got.stream(asset.browser_download_url), fs.createWriteStream(tarPath));
|
|
82
|
+
await decompress(tarPath, filePath);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const decompress = async (tarPath, outPath) => {
|
|
87
|
+
logDebug(`decompress(${tarPath})`);
|
|
88
|
+
await pipeline(fs.createReadStream(tarPath), tar.x({
|
|
89
|
+
C: path.dirname(outPath),
|
|
90
|
+
strip: 1,
|
|
91
|
+
}));
|
|
92
|
+
fs.chmodSync(outPath, 0o755);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const loadCLIBinPath = async (cwd) => {
|
|
96
|
+
const versionDir = path.join(cwd, pkg.version);
|
|
97
|
+
const binPath = path.join(versionDir, CLI_FILENAME);
|
|
98
|
+
logDebug(`loadCLIBinPath: ${binPath}`);
|
|
99
|
+
|
|
100
|
+
if (!fs.existsSync(binPath)) {
|
|
101
|
+
await downloadRelease(versionDir);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
logDebug(`returning ${binPath}`);
|
|
105
|
+
|
|
106
|
+
return binPath;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const extractVersionParts = (version) => {
|
|
110
|
+
const [major, minor, patch] = version.replace(/^v/, "").split(".");
|
|
111
|
+
return { major, minor, patch };
|
|
112
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "offwatch",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Offwatch — orchestrate AI agent teams to automate dev work",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
"postinstall": "node postinstall.js"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"
|
|
38
|
+
"fs-extra": "^10.1.0",
|
|
39
|
+
"got": "^14.0.0",
|
|
40
|
+
"tar": "^6.2.0"
|
|
39
41
|
}
|
|
40
42
|
}
|
package/postinstall.js
CHANGED