forked from Rich-Harris/degit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
42 lines (35 loc) · 951 Bytes
/
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
const child_process = require('child_process');
const chalk = require('chalk');
const path = require('path');
const fs = require('fs');
exports.error = function error(message, err) {
console.error(chalk.redBright(`[!] ${message}`)); // eslint-disable-line no-console
if (err) {
console.log(chalk.grey(err.stack)); // eslint-disable-line no-console
}
process.exit(1);
};
exports.log = function log(message) {
console.log(chalk.cyanBright(`[>] ${message}`)); // eslint-disable-line no-console
};
exports.exec = function exec(command) {
return new Promise((fulfil, reject) => {
child_process.exec(command, (err, stdout, stderr) => {
if (err) {
reject(err);
return;
}
fulfil({ stdout, stderr });
});
});
};
exports.mkdirp = function mkdirp(dir) {
const parent = path.dirname(dir);
if (parent === dir) return;
mkdirp(parent);
try {
fs.mkdirSync(dir);
} catch (err) {
if (err.code !== 'EEXIST') throw err;
}
};