-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnpm.ts
More file actions
37 lines (32 loc) · 967 Bytes
/
npm.ts
File metadata and controls
37 lines (32 loc) · 967 Bytes
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
const path = require('path');
const { pathExists } = require('fs-extra');
const spawn = require('cross-spawn-promise');
async function isNPMInstalled(args) {
return pathExists(path.join(args.workDir, 'node_modules'));
}
async function install(args) {
if (await isNPMInstalled(args)) return;
const { workDir, npmClient = 'tnpm' } = args;
try {
await spawn(npmClient, ['i'], { stdio: 'inherit', cwd: workDir });
} catch (e) {
// TODO
}
}
async function isNPMModuleInstalled(args, name) {
const modulePkgJsonPath = path.resolve(args.workDir || '', 'node_modules', name, 'package.json');
return pathExists(modulePkgJsonPath);
}
async function installModule(args, name) {
if (await isNPMModuleInstalled(args, name)) return;
const { workDir, npmClient = 'tnpm' } = args;
try {
await spawn(npmClient, ['i', name], { stdio: 'inherit', cwd: workDir });
} catch (e) {
// TODO
}
}
module.exports = {
installModule,
install,
};