forked from jfrog/jfrog-azure-devops-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
43 lines (39 loc) · 1.25 KB
/
build.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
const exec = require('child_process').execSync;
const rimraf = require('rimraf');
const fs = require('fs');
const path = require('path');
cleanExecNpm('pack', 'artifactory-tasks-utils');
installTasks();
cleanExecNpm(('i'), 'tests');
/**
* Install tasks.
*/
function installTasks() {
fs.readdir('tasks', (err, files) => {
files.forEach(taskName => {
let taskDir = path.join('tasks', taskName);
// If a package.json is missing, npm will exec the install command on the parent folder. This will cause an endless install loop.
if (fs.existsSync(path.join(taskDir, "package.json"))) {
cleanExecNpm('i', taskDir);
}
});
});
}
/**
* Clean npm install/pack files.
* @param cwd - (String) - Current working directory.
*/
function clean(cwd) {
rimraf.sync(path.join(cwd, 'node_modules'));
rimraf.sync(path.join(cwd, 'package-lock.json'));
rimraf.sync(path.join(cwd, '*.tgz'));
}
/**
* Clean directory and execute npm command.
* @param command - (String) - The command to execute, i.e. install, pack, etc.
* @param cwd - (String) - Current working directory.
*/
function cleanExecNpm(command, cwd) {
clean(cwd);
exec('npm ' + command, {cwd: cwd, stdio: [0, 1, 2]});
}