You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/build/utils.js

29 lines
771 B
JavaScript

const fs = require('fs');
const path = require('path');
exports.root = (name) => path.resolve(__dirname, '..', name);
exports.exist = (name) => {
try {
fs.statSync(exports.root(name));
} catch (e) {
return false;
}
return true;
};
exports.rmdir = function rmdir(p, recursive = true) {
if (!fs.existsSync(p)) return;
if (recursive) {
fs.readdirSync(p).forEach((file) => {
const curPath = `${p}/${file}`;
if (fs.statSync(curPath).isDirectory()) rmdir(curPath);
else fs.unlinkSync(curPath);
});
}
fs.rmdirSync(p);
};
exports.ignoreFailure = function ignoreFailure(func, ...params) {
try {
func(...params);
} catch (e) { } // eslint-disable-line no-empty
};