-
Notifications
You must be signed in to change notification settings - Fork 423
/
package-utils.js
95 lines (82 loc) · 2.53 KB
/
package-utils.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// this code is partitially copied from vsts-task repo
var fs = require('fs');
var path = require('path');
var shell = require('shelljs');
var ncp = require('child_process');
//------------------------------------------------------------------------------
// shell functions
//------------------------------------------------------------------------------
var rp = function (relPath) {
return path.join(shell.pwd() + '', relPath);
}
exports.rp = rp;
var shellAssert = function () {
var errMsg = shell.error();
if (errMsg) {
throw new Error(errMsg);
}
}
var cd = function (dir) {
shell.cd(dir);
shellAssert();
}
exports.cd = cd;
var test = function (options, p) {
var result = shell.test(options, p);
shellAssert();
return result;
}
exports.test = test;
var fail = function (message) {
console.error('ERROR: ' + message);
process.exit(1);
}
exports.fail = fail;
var run = function (cl, inheritStreams, noHeader) {
if (!noHeader) {
console.log();
console.log('> ' + cl);
}
var options = {
stdio: inheritStreams ? 'inherit' : 'pipe'
};
var rc = 0;
var output;
try {
output = ncp.execSync(cl, options);
}
catch (err) {
if (!inheritStreams) {
console.error(err.output ? err.output.toString() : err.message);
}
process.exit(1);
}
return (output || '').toString().trim();
}
exports.run = run;
var buildNodeTask = function (taskPath, outDir) {
var originalDir = shell.pwd();
cd(taskPath);
var packageJsonPath = rp('package.json');
console.log("");
if (test('-f', packageJsonPath)) {
var packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
if (packageJson.devDependencies && Object.keys(packageJson.devDependencies).length != 0) {
fail('The package.json should not contain dev dependencies. Move the dev dependencies into a package.json file under the Tests sub-folder. Offending package.json: ' + packageJsonPath);
}
run('npm install');
}
cd(originalDir);
}
exports.buildNodeTask = buildNodeTask;
var buildUIContribution = function (source, destination) {
var originalDir = shell.pwd();
shell.cd(destination);
var packageJsonPath = rp('package.json');
if (test('-f', packageJsonPath)) {
run('npm install');
}
run('npm run buildWeb');
cd(originalDir);
}
exports.buildUIContribution = buildUIContribution;