forked from finos/perspective
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_utils.js
57 lines (50 loc) · 1.49 KB
/
script_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
/******************************************************************************
*
* Copyright (c) 2017, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/
require("dotenv").config({path: "./.perspectiverc"});
const execSync = require("child_process").execSync;
const _path = require("path");
const fs = require("fs");
const rimraf = require("rimraf");
function rimraf_err(e) {
if (e) {
console.error(e.message);
process.exit(1);
}
}
exports.execute = cmd => {
try {
execSync(cmd, {stdio: "inherit"});
} catch (e) {
console.error(e);
process.exit(1);
}
};
exports.path = function path(...strings) {
return _path.join(...strings.join("").split("/"));
};
exports.clean = function clean(...dirs) {
for (let dir of dirs) {
dir = exports.path(dir);
if (fs.existsSync(dir)) {
rimraf(dir, rimraf_err);
}
}
};
exports.bash = function bash(strings, ...args) {
let terms = [];
for (let i = 0; i < strings.length; ++i) {
terms = [...terms, ...strings[i].split(" ")];
if (terms.length > 0 && (args[i] === undefined || args[i] === NaN)) {
terms = terms.slice(0, terms.length - 1);
} else if (i < args.length) {
terms[terms.length - 1] = terms[terms.length - 1] + args[i];
}
}
return terms.join(" ");
};