-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts-install-all.mjs
45 lines (37 loc) · 1.12 KB
/
ts-install-all.mjs
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
import { spawn } from 'child_process';
let output = '';
const treesitter = spawn(process.platform === 'win32' ? `C:/tools/neovim/nvim-win64/bin/nvim` : './squashfs-root/usr/bin/nvim', ['--headless', '-c', 'TSInstall all']);
const stop = (msg) => {
treesitter.stderr.pause();
treesitter.kill();
console.log(msg);
process.exit(0);
}
setTimeout(() => {
stop('ERROR: time out');
}, 1000 * 60 * 12);
treesitter.stderr.on('data', (data) => {
data = data
.toString()
console.log(data);
output +=data;
if (output.length > 1000) {
output.slice(-1000)
}
if (output.includes('Out of memory')) {
stop('ERROR: out of memory');
}
if (output.includes('up-to-date')) {
stop('DONE: all parser are up-to-date');
}
const installed = output.split('installed');
if (installed.length > 1) {
const installedParser = installed.at(-2).split('[nvim-treesitter]').at(-1);
const resultRegex = /^\s\[([\d]+)\/([\d]+)/g.exec(installedParser);
if (resultRegex === null) return;
const [original, current, total] = resultRegex;
if (current === total) {
stop('DONE: all parse installed');
}
}
});