Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
63 lines (50 loc) · 1.31 KB
/
Copy pathutils.js
File metadata and controls
63 lines (50 loc) · 1.31 KB
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
58
59
60
61
62
63
/*
*
* Diff to HTML CLI (utils.js)
* Author: rtfpessoa
*
*/
(function() {
var childProcess = require('child_process');
var fs = require('fs');
function Utils() {
}
Utils.prototype.print = function(line) {
return console.log(line);
};
Utils.prototype.error = function(msg) {
return console.error(msg);
};
Utils.prototype.existsSync = function(filePath) {
var result = false;
try {
result = fs.existsSync(filePath);
} catch (ignore) {
result = false;
}
return result || false;
};
Utils.prototype.readFileSync = function(filePath) {
return fs.readFileSync(filePath, 'utf8');
};
Utils.prototype.readFile = function(filePath, callback) {
return fs.readFile(filePath, {'encoding': 'utf8'}, callback);
};
Utils.prototype.readStdin = function(callback) {
var content = '';
process.stdin.resume();
process.stdin.on('data', function(buf) {
content += buf.toString('utf8');
});
process.stdin.on('end', function() {
return callback(null, content);
});
};
Utils.prototype.writeFile = function(filePath, content) {
return fs.writeFileSync(filePath, content);
};
Utils.prototype.runCmd = function(cmd) {
return childProcess.execSync(cmd).toString('utf8');
};
module.exports.Utils = new Utils();
})();