gm-oc 2.0.286 → 2.0.289
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/package.json +1 -1
- package/scripts/bootstrap.js +39 -23
package/package.json
CHANGED
package/scripts/bootstrap.js
CHANGED
|
@@ -3,60 +3,66 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const https = require('https');
|
|
6
|
+
const { execFileSync } = require('child_process');
|
|
6
7
|
|
|
7
8
|
const pluginRoot = process.env.CLAUDE_PLUGIN_ROOT;
|
|
8
9
|
if (!pluginRoot) process.exit(0);
|
|
9
10
|
|
|
10
11
|
const IS_WIN = process.platform === 'win32';
|
|
11
|
-
const
|
|
12
|
+
const binDir = path.join(pluginRoot, 'bin');
|
|
13
|
+
const binPath = path.join(binDir, IS_WIN ? 'plugkit.exe' : 'plugkit');
|
|
12
14
|
const pendingPath = binPath + '.pending';
|
|
15
|
+
const versionFile = path.join(binDir, '.plugkit-version');
|
|
16
|
+
const pendingVersionFile = pendingPath + '.version';
|
|
13
17
|
|
|
14
18
|
function getAssetName() {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const cpu = arch === 'arm64' ? 'arm64' : 'x64';
|
|
19
|
-
const ext = platform === 'win32' ? '.exe' : '';
|
|
19
|
+
const os = process.platform === 'win32' ? 'win32' : process.platform === 'darwin' ? 'darwin' : 'linux';
|
|
20
|
+
const cpu = process.arch === 'arm64' ? 'arm64' : 'x64';
|
|
21
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
20
22
|
return `plugkit-${os}-${cpu}${ext}`;
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
function killDaemon() {
|
|
26
|
+
try {
|
|
27
|
+
execFileSync(binPath, ['runner', 'stop'], { timeout: 5000, stdio: 'ignore' });
|
|
28
|
+
} catch {}
|
|
29
|
+
if (IS_WIN) {
|
|
30
|
+
try { execFileSync('taskkill', ['/F', '/IM', 'plugkit.exe'], { timeout: 3000, stdio: 'ignore' }); } catch {}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
function applyPending() {
|
|
24
35
|
if (!fs.existsSync(pendingPath)) return;
|
|
36
|
+
killDaemon();
|
|
25
37
|
try {
|
|
26
38
|
if (fs.existsSync(binPath)) fs.unlinkSync(binPath);
|
|
27
39
|
fs.renameSync(pendingPath, binPath);
|
|
40
|
+
if (fs.existsSync(pendingVersionFile)) {
|
|
41
|
+
try { fs.renameSync(pendingVersionFile, versionFile); } catch {}
|
|
42
|
+
}
|
|
28
43
|
} catch {}
|
|
29
44
|
}
|
|
30
45
|
|
|
31
46
|
applyPending();
|
|
32
47
|
|
|
33
|
-
function
|
|
48
|
+
function getRequiredVersion() {
|
|
34
49
|
try {
|
|
35
50
|
return JSON.parse(fs.readFileSync(path.join(pluginRoot, 'gm.json'), 'utf8')).plugkitVersion || null;
|
|
36
51
|
} catch { return null; }
|
|
37
52
|
}
|
|
38
53
|
|
|
39
54
|
function getCurrentVersion() {
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const { execFileSync } = require('child_process');
|
|
43
|
-
const out = execFileSync(binPath, ['--version'], { timeout: 5000 }).toString().trim();
|
|
44
|
-
const m = out.match(/(\d+\.\d+\.\d+)/);
|
|
45
|
-
return m ? m[1] : null;
|
|
46
|
-
} catch { return null; }
|
|
55
|
+
try { return fs.readFileSync(versionFile, 'utf8').trim() || null; } catch { return null; }
|
|
47
56
|
}
|
|
48
57
|
|
|
49
|
-
const required =
|
|
58
|
+
const required = getRequiredVersion();
|
|
50
59
|
const current = getCurrentVersion();
|
|
51
60
|
if (current && current === required) process.exit(0);
|
|
52
61
|
|
|
53
62
|
function download(version, dest, cb) {
|
|
54
63
|
const asset = getAssetName();
|
|
55
|
-
const urlPath = version
|
|
56
|
-
|
|
57
|
-
: `/AnEntrypoint/rs-plugkit/releases/latest/download/${asset}`;
|
|
58
|
-
const destDir = path.dirname(dest);
|
|
59
|
-
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
|
|
64
|
+
const urlPath = `/AnEntrypoint/rs-plugkit/releases/download/v${version}/${asset}`;
|
|
65
|
+
if (!fs.existsSync(path.dirname(dest))) fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
60
66
|
const follow = (url) => {
|
|
61
67
|
const mod = url.startsWith('https') ? https : require('http');
|
|
62
68
|
const opts = { ...require('url').parse(url), headers: { 'User-Agent': 'gm-bootstrap' } };
|
|
@@ -65,19 +71,28 @@ function download(version, dest, cb) {
|
|
|
65
71
|
if (res.statusCode !== 200) return cb(new Error(`HTTP ${res.statusCode}`));
|
|
66
72
|
const chunks = [];
|
|
67
73
|
res.on('data', c => chunks.push(c));
|
|
68
|
-
res.on('end', () => {
|
|
74
|
+
res.on('end', () => {
|
|
75
|
+
try {
|
|
76
|
+
fs.writeFileSync(dest, Buffer.concat(chunks));
|
|
77
|
+
try { fs.chmodSync(dest, 0o755); } catch {}
|
|
78
|
+
cb(null);
|
|
79
|
+
} catch (e) { cb(e); }
|
|
80
|
+
});
|
|
69
81
|
}).on('error', cb);
|
|
70
82
|
};
|
|
71
83
|
follow(`https://github.com${urlPath}`);
|
|
72
84
|
}
|
|
73
85
|
|
|
86
|
+
killDaemon();
|
|
87
|
+
|
|
74
88
|
download(required, binPath, (err) => {
|
|
75
|
-
if (err && err.
|
|
89
|
+
if (err && err.code === 'EBUSY') {
|
|
76
90
|
download(required, pendingPath, (err2) => {
|
|
77
91
|
if (err2) {
|
|
78
|
-
process.stderr.write(`bootstrap: ${err2.message}\n`);
|
|
92
|
+
process.stderr.write(`bootstrap: pending failed: ${err2.message}\n`);
|
|
79
93
|
process.exit(fs.existsSync(binPath) ? 0 : 1);
|
|
80
94
|
}
|
|
95
|
+
try { fs.writeFileSync(pendingVersionFile, required); } catch {}
|
|
81
96
|
process.exit(0);
|
|
82
97
|
});
|
|
83
98
|
return;
|
|
@@ -86,5 +101,6 @@ download(required, binPath, (err) => {
|
|
|
86
101
|
process.stderr.write(`bootstrap: ${err.message}\n`);
|
|
87
102
|
process.exit(fs.existsSync(binPath) ? 0 : 1);
|
|
88
103
|
}
|
|
104
|
+
try { fs.writeFileSync(versionFile, required); } catch {}
|
|
89
105
|
process.exit(0);
|
|
90
106
|
});
|