-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathutils.js
48 lines (40 loc) · 1.45 KB
/
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
var fs = require("fs");
var path = require("path");
var sanitize = require("sanitize-filename");
module.exports = (function () {
var loadConfigFile = function (absolute_path) {
try {
return require(absolute_path);
} catch (ex) {
return {};
}
};
var getBaseOrCustomPath = function (partial_path) {
return fs.existsSync(path.join(process.cwd(), partial_path))
? path.join(process.cwd(), partial_path)
: path.join(__dirname, partial_path);
};
var getBaseAndCustomPaths = function (partial_path) {
return [path.join(process.cwd(), partial_path), path.join(__dirname, partial_path)];
};
var loadConfiguration = function (partial_path) {
return Object.assign(
{},
loadConfigFile(path.join(__dirname, partial_path)),
loadConfigFile(path.join(process.cwd(), partial_path))
);
};
var constructArchiveName = function (settings) {
var nameParts = [sanitize(settings.name), settings.version, settings.options.environment];
if (settings.options.architecture) {
nameParts.push(settings.options.architecture);
}
return nameParts.join("-");
};
return {
getBaseOrCustomPath: getBaseOrCustomPath,
getBaseAndCustomPaths: getBaseAndCustomPaths,
loadConfiguration: loadConfiguration,
constructArchiveName: constructArchiveName,
};
})();