Skip to content

Commit f564a85

Browse files
committed
tasks: add common task util module
1 parent bac6685 commit f564a85

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tasks/util/common.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var fs = require('fs');
2+
var exec = require('child_process').exec;
3+
4+
exports.execCmd = function(cmd, cb) {
5+
exec(cmd, function(err) {
6+
if(err) throw err;
7+
if(cb) cb();
8+
})
9+
.stdout.pipe(process.stdout);
10+
};
11+
12+
exports.writeFile = function(filePath, content, cb) {
13+
fs.writeFile(filePath, content, function(err) {
14+
if(err) throw err;
15+
if(cb) cb();
16+
});
17+
};
18+
19+
exports.doesDirExist = function(dirPath) {
20+
try {
21+
if(fs.statSync(dirPath).isDirectory()) return true;
22+
}
23+
catch(e) {
24+
return false;
25+
}
26+
27+
return false;
28+
};
29+
30+
exports.doesFileExist = function(filePath) {
31+
try {
32+
if(fs.statSync(filePath).isFile()) return true;
33+
}
34+
catch(e) {
35+
return false;
36+
}
37+
38+
return false;
39+
};
40+
41+
exports.touch = function(filePath) {
42+
fs.closeSync(fs.openSync(filePath, 'w'));
43+
};
44+
45+
exports.throwOnError = function(err) {
46+
if(err) throw err;
47+
};

0 commit comments

Comments
 (0)