-
Notifications
You must be signed in to change notification settings - Fork 427
Expand file tree
/
Copy pathpackage-utils.js
More file actions
72 lines (61 loc) · 1.7 KB
/
package-utils.js
File metadata and controls
72 lines (61 loc) · 1.7 KB
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
// this code is partitially copied from vsts-task repo
const fs = require('fs');
const path = require('path');
const shell = require('shelljs');
const 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;
exports.isDebug = function () {
let { SYSTEM_DEBUG } = process.env;
SYSTEM_DEBUG = SYSTEM_DEBUG || 'false';
return SYSTEM_DEBUG.toLowerCase() === 'true' || process.argv.includes('--verbose');
}