-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-chilkat.js.ignore
75 lines (62 loc) · 1.83 KB
/
install-chilkat.js.ignore
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const { spawn } = require('child_process');
const { platform, arch } = require('os');
const fs = require('fs');
const os = require('os');
const npmCmd = platform().startsWith('win') ? 'npm.cmd' : 'npm';
const run = (cmd) =>
new Promise((solve) => {
console.log(npmCmd, cmd);
const ls = spawn(npmCmd, cmd, {
env: process.env,
cwd: './',
stdio: 'inherit',
});
ls.on('close', solve);
});
const getChilkatTool = () => {
const v = process.version.split('.')[0].replace('v', '');
console.log(process.arch);
const node = v ? `node${v}` : 'node16';
const platform = os.platform();
const arch = os.arch();
let name = '';
if (platform == 'win32') {
if (arch == 'ia32') name = 'win-ia32';
else name = 'win64';
} else if (platform == 'linux') {
if (arch == 'arm') name = 'arm';
else if (arch == 'x86') name = 'linux32';
else name = 'linux64';
} else if (platform == 'darwin') {
if (arch == 'arm64') name = 'mac-m1';
else name = 'macosx';
}
const m = `@chilkat/ck-${node}-${name}`;
console.log("Installing",m);
return m;
};
const uninstallTool = () => {
//Uninstall all existing tool from package.json
const p = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
Object.keys(p.dependencies)
.filter((k) => k.startsWith('@chilkat'))
.forEach((k) => {
delete p.dependencies[k];
});
Object.keys(p.devDependencies)
.filter((k) => k.startsWith('@chilkat'))
.forEach((k) => {
delete p.dependencies[k];
});
fs.writeFileSync('./package.json', JSON.stringify(p, null, 2), {
encoding: 'utf8',
});
};
(async () => {
//Uninstall Tool
uninstallTool();
//Install new package with current os
await run(['install', getChilkatTool(), '--save']);
// Delete package-lock.json
fs.unlink('./package-lock.json', console.error);
})();