This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodulesUpdate.ts
56 lines (48 loc) · 1.54 KB
/
modulesUpdate.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
55
56
import {spawn} from 'child_process';
(async () =>
{
const outdatedProcess = spawn(`npm.cmd`, [`outdated`]);
const forbiddenPackageNames: (string | undefined)[] = [undefined, `Package`];
outdatedProcess.stdout.on(`data`, async (data: Buffer) =>
{
const packageNames: string[] = data.toString().split(`\n`).map((packageLine) =>
{
return packageLine.match(`[^ ]+`)?.[0];
}).filter((packageName) =>
{
return !forbiddenPackageNames.includes(packageName);
}).map((packageName) =>
{
if (!packageName)
{
return ``;
}
return `${packageName}@latest`;
});
return new Promise((reject, resolve) =>
{
const installProcess = spawn(`npm.cmd`, [
`i`,
...packageNames
]);
installProcess.stderr.on(`data`, (err: Buffer) =>
{
console.log(`Error:`, err.toString());
return reject(err.toString());
});
installProcess.on(`close`, (data2: Buffer) =>
{
console.log(`Packages successfully installed`);
return resolve(data2.toString());
});
}).catch(console.error);
});
outdatedProcess.stderr.on(`data`, (data: Buffer) =>
{
console.log(data.toString());
});
outdatedProcess.on(`exit`, (exitCode: string) =>
{
console.log(`Process finished with exit code ${exitCode}`);
});
})();