-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathql_install_whistle.x-scripts.ts
54 lines (44 loc) · 1.65 KB
/
ql_install_whistle.x-scripts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* @Author: renxia
* @Date: 2024-04-03 19:33:28
* @LastEditors: renxia
* @LastEditTime: 2024-09-10 11:58:38
* @Description:
*
* new Env('whistle.x-scripts 插件安装与更新')
* cron: 0 18 * * *
*/
import fs from 'node:fs';
import { dirname, resolve } from 'node:path';
import { execPromisfy, rmrf, mkdirp } from '@lzwme/fe-utils';
const githubProxyUrl = process.env.GH_PROXY_URL ?? '';
const baseDir = process.env.QL_WHISTLE_BASEDIR || '/ql/data/scripts/whistle/';
const repoList = ['x-scripts-rules', 'whistle.x-scripts'];
async function updateRepo(repoName: string) {
if (repoName === 'whistle.x-scripts' && process.env.WS_GLOBAL_INSTALL !== '0') {
await execPromisfy(`npm i -g @lzwme/whistle.x-scripts`);
return;
}
const dir = resolve(baseDir, repoName);
if (fs.existsSync(resolve(dir, '.git/config'))) {
await execPromisfy(`git fetch --all && git reset --hard remotes/origin/main`, true, { cwd: dir });
} else {
rmrf(dir);
await execPromisfy(`git clone ${githubProxyUrl}https://github.com/lzwme/${repoName}.git`, true, { cwd: dirname(dir) });
}
if (repoName === 'whistle.x-scripts') {
await execPromisfy('pnpm install && pnpm build && npm link .', true, { cwd: dir });
}
}
async function start() {
mkdirp(baseDir);
process.chdir(baseDir);
console.log(process.cwd());
const r = await execPromisfy('w2 stop', true, { cwd: baseDir });
if (r.stderr) await execPromisfy('npm i -g whistle', true, { cwd: baseDir });
for (const repoName of repoList) await updateRepo(repoName);
await execPromisfy('w2 start', true, { cwd: baseDir });
}
start()
.catch((e) => console.error(e))
.finally(() => process.exit());