2017-02-18 21:06:39 +00:00
|
|
|
/*global exit */
|
2017-03-29 15:37:30 +00:00
|
|
|
let path = require('path');
|
|
|
|
let globule = require('globule');
|
|
|
|
let merge = require('merge');
|
2017-07-02 17:33:11 +00:00
|
|
|
let http = require('follow-redirects').http;
|
2017-03-29 15:37:30 +00:00
|
|
|
let shelljs = require('shelljs');
|
2017-02-18 19:10:01 +00:00
|
|
|
|
|
|
|
function joinPath() {
|
|
|
|
return path.join.apply(path.join, arguments);
|
|
|
|
}
|
|
|
|
|
2017-02-18 19:45:57 +00:00
|
|
|
function filesMatchingPattern(files) {
|
2017-02-19 05:00:01 +00:00
|
|
|
return globule.find(files, {nonull: true});
|
2017-02-18 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function fileMatchesPattern(patterns, intendedPath) {
|
2017-02-19 05:00:01 +00:00
|
|
|
return globule.isMatch(patterns, intendedPath);
|
2017-02-18 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2017-02-18 19:45:57 +00:00
|
|
|
function recursiveMerge(target, source) {
|
|
|
|
return merge.recursive(target, source);
|
|
|
|
}
|
|
|
|
|
2017-02-18 20:27:08 +00:00
|
|
|
function checkIsAvailable(url, callback) {
|
2017-03-30 11:12:39 +00:00
|
|
|
http.get(url, function (res) {
|
2017-02-19 04:17:43 +00:00
|
|
|
callback(true);
|
2017-03-30 11:12:39 +00:00
|
|
|
}).on('error', function (res) {
|
2017-02-19 04:17:43 +00:00
|
|
|
callback(false);
|
2017-02-18 20:27:08 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-02 18:40:10 +00:00
|
|
|
function httpGet(url, callback) {
|
|
|
|
return http.get(url, callback);
|
|
|
|
}
|
|
|
|
|
2017-02-18 21:06:39 +00:00
|
|
|
function runCmd(cmd, options) {
|
2017-03-29 15:37:30 +00:00
|
|
|
let result = shelljs.exec(cmd, options || {silent: true});
|
2017-02-18 21:06:39 +00:00
|
|
|
if (result.code !== 0) {
|
|
|
|
console.log("error doing.. " + cmd);
|
|
|
|
console.log(result.output);
|
|
|
|
if (result.stderr !== undefined) {
|
|
|
|
console.log(result.stderr);
|
|
|
|
}
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function cd(folder) {
|
|
|
|
shelljs.cd(folder);
|
|
|
|
}
|
|
|
|
|
2017-02-25 22:34:45 +00:00
|
|
|
function sed(file, pattern, replace) {
|
|
|
|
shelljs.sed('-i', pattern, replace, file);
|
|
|
|
}
|
|
|
|
|
2017-02-18 21:06:39 +00:00
|
|
|
function exit(code) {
|
|
|
|
process.exit(code);
|
|
|
|
}
|
|
|
|
|
2017-03-29 15:37:30 +00:00
|
|
|
//TODO: Maybe desired to just `module.exports = this` ?
|
2017-02-18 19:10:01 +00:00
|
|
|
module.exports = {
|
2017-02-18 19:45:57 +00:00
|
|
|
joinPath: joinPath,
|
|
|
|
filesMatchingPattern: filesMatchingPattern,
|
|
|
|
fileMatchesPattern: fileMatchesPattern,
|
2017-02-18 20:27:08 +00:00
|
|
|
recursiveMerge: recursiveMerge,
|
2017-02-18 21:06:39 +00:00
|
|
|
checkIsAvailable: checkIsAvailable,
|
2017-04-02 18:40:10 +00:00
|
|
|
httpGet: httpGet,
|
2017-02-18 21:06:39 +00:00
|
|
|
runCmd: runCmd,
|
|
|
|
cd: cd,
|
2017-02-25 22:34:45 +00:00
|
|
|
sed: sed,
|
2017-02-18 21:06:39 +00:00
|
|
|
exit: exit
|
2017-02-18 19:10:01 +00:00
|
|
|
};
|
|
|
|
|