2017-02-18 21:06:39 +00:00
|
|
|
/*global exit */
|
2017-02-18 19:10:01 +00:00
|
|
|
var path = require('path');
|
2017-02-18 19:37:07 +00:00
|
|
|
var grunt = require('grunt');
|
2017-02-18 19:45:57 +00:00
|
|
|
var merge = require('merge');
|
2017-02-18 20:27:08 +00:00
|
|
|
var request = require('request');
|
2017-02-18 21:06:39 +00:00
|
|
|
var 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-18 19:37:07 +00:00
|
|
|
return grunt.file.expand({nonull: true}, files);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fileMatchesPattern(patterns, intendedPath) {
|
|
|
|
return grunt.file.isMatch(patterns, intendedPath);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
request(url, function(error, response, body) {
|
|
|
|
callback(!error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-02-18 21:06:39 +00:00
|
|
|
function runCmd(cmd, options) {
|
|
|
|
var result = shelljs.exec(cmd, options || {silent: true});
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
function exit(code) {
|
|
|
|
process.exit(code);
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
runCmd: runCmd,
|
|
|
|
cd: cd,
|
|
|
|
exit: exit
|
2017-02-18 19:10:01 +00:00
|
|
|
};
|
|
|
|
|