-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.js
52 lines (39 loc) · 1.28 KB
/
install.js
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
#!/usr/bin/env node
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import url from 'node:url';
import appConfig from './.languagetoolrc.js';
import downloadLanguageTool from './lib/download-language-tool.js';
import { error, info, success } from './lib/log.js';
import unzipFile from './lib/unzip-file.js';
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
await install();
async function install() {
try {
const { url: zipUrl, md5 } = appConfig.downloadUrls.stable;
const urlParts = url.parse(zipUrl, true);
const { base, name } = path.parse(decodeURIComponent(urlParts.pathname));
const savePath = path.resolve(fs.realpathSync(os.tmpdir()), base);
const installPath = __dirname;
const finalPath = path.join(installPath, 'languagetool');
if (fs.existsSync(finalPath)) {
return;
}
console.log();
await downloadLanguageTool({ url: zipUrl, md5, savePath });
console.log();
await unzipFile(savePath, installPath);
console.log();
info(`Rename "${name}" to "languagetool" ...`);
fs.renameSync(path.resolve(installPath, name), finalPath);
success('Done!');
console.log();
info('Remove temp files ...');
fs.unlinkSync(savePath);
success('Done!');
} catch (error_) {
error(error_);
process.exit(1);
}
}