@campfire-net/ready 0.2.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/index.js +80 -0
- package/package.json +21 -0
package/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { execFileSync, execSync } = require('child_process');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const os = require('os');
|
|
8
|
+
|
|
9
|
+
function getBinaryPath() {
|
|
10
|
+
const platform = os.platform();
|
|
11
|
+
const arch = os.arch();
|
|
12
|
+
|
|
13
|
+
// Check if rd is already on PATH
|
|
14
|
+
try {
|
|
15
|
+
const which = platform === 'win32' ? 'where' : 'which';
|
|
16
|
+
const systemBin = execSync(`${which} rd`, { encoding: 'utf8', stdio: 'pipe' }).trim();
|
|
17
|
+
if (systemBin) return systemBin;
|
|
18
|
+
} catch {}
|
|
19
|
+
|
|
20
|
+
// Check cache
|
|
21
|
+
const cacheDir = path.join(os.homedir(), '.cache', 'ready');
|
|
22
|
+
const binName = platform === 'win32' ? 'rd.exe' : 'rd';
|
|
23
|
+
const cachedBin = path.join(cacheDir, binName);
|
|
24
|
+
if (fs.existsSync(cachedBin)) return cachedBin;
|
|
25
|
+
|
|
26
|
+
// Download from GitHub Releases
|
|
27
|
+
const crypto = require('crypto');
|
|
28
|
+
const goArch = arch === 'x64' ? 'amd64' : arch;
|
|
29
|
+
const ext = platform === 'win32' ? 'zip' : 'tar.gz';
|
|
30
|
+
const archiveName = `rd_${platform === 'win32' ? 'windows' : platform}_${goArch}.${ext}`;
|
|
31
|
+
const baseUrl = 'https://github.com/campfire-net/ready/releases/latest/download';
|
|
32
|
+
const archiveUrl = `${baseUrl}/${archiveName}`;
|
|
33
|
+
const checksumsUrl = `${baseUrl}/checksums.txt`;
|
|
34
|
+
const archivePath = path.join(cacheDir, archiveName);
|
|
35
|
+
|
|
36
|
+
process.stderr.write(`rd: downloading ${archiveName}\n`);
|
|
37
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
execSync(`curl -sL "${archiveUrl}" -o "${archivePath}"`, { stdio: 'pipe' });
|
|
41
|
+
const checksums = execSync(`curl -sL "${checksumsUrl}"`, { encoding: 'utf8' });
|
|
42
|
+
|
|
43
|
+
// Verify SHA256
|
|
44
|
+
const archiveData = fs.readFileSync(archivePath);
|
|
45
|
+
const actualHash = crypto.createHash('sha256').update(archiveData).digest('hex');
|
|
46
|
+
const expectedLine = checksums.split('\n').find(l => l.includes(archiveName));
|
|
47
|
+
if (!expectedLine) {
|
|
48
|
+
throw new Error(`checksum not found for ${archiveName}`);
|
|
49
|
+
}
|
|
50
|
+
const expectedHash = expectedLine.trim().split(/\s+/)[0];
|
|
51
|
+
if (actualHash !== expectedHash) {
|
|
52
|
+
fs.unlinkSync(archivePath);
|
|
53
|
+
throw new Error(`checksum mismatch: expected ${expectedHash}, got ${actualHash}`);
|
|
54
|
+
}
|
|
55
|
+
process.stderr.write(`rd: checksum verified\n`);
|
|
56
|
+
|
|
57
|
+
// Extract
|
|
58
|
+
if (platform === 'win32') {
|
|
59
|
+
execSync(`cd "${cacheDir}" && tar -xf "${archivePath}" --strip-components=1 --include='*/rd.exe'`, { stdio: 'pipe' });
|
|
60
|
+
} else {
|
|
61
|
+
execSync(`tar xzf "${archivePath}" -C "${cacheDir}" --strip-components=1 --wildcards '*/rd'`, { stdio: 'pipe' });
|
|
62
|
+
}
|
|
63
|
+
fs.unlinkSync(archivePath);
|
|
64
|
+
fs.chmodSync(cachedBin, 0o755);
|
|
65
|
+
if (fs.existsSync(cachedBin)) return cachedBin;
|
|
66
|
+
} catch (e) {
|
|
67
|
+
throw new Error(`rd: failed to download/verify binary: ${e.message}\nInstall manually: curl -fsSL https://ready.getcampfire.dev/install.sh | sh`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
throw new Error('rd: could not find or download binary');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const bin = getBinaryPath();
|
|
75
|
+
execFileSync(bin, process.argv.slice(2), { stdio: 'inherit' });
|
|
76
|
+
} catch (err) {
|
|
77
|
+
if (err.status) process.exit(err.status);
|
|
78
|
+
process.stderr.write(err.message + '\n');
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@campfire-net/ready",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Work management as a campfire convention — rd CLI",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"bin": {
|
|
7
|
+
"rd": "index.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/campfire-net/ready"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://ready.getcampfire.dev",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"campfire",
|
|
16
|
+
"work-management",
|
|
17
|
+
"cli",
|
|
18
|
+
"agents",
|
|
19
|
+
"delegation"
|
|
20
|
+
]
|
|
21
|
+
}
|