|
@@ -3,24 +3,46 @@
|
|
|
*/
|
|
|
const fs = require('fs');
|
|
|
|
|
|
-module.exports.exist = function (path, show = false) {
|
|
|
+module.exports.exist = function (path, verbose = false) {
|
|
|
try {
|
|
|
return fs.existsSync(path);
|
|
|
} catch (err) {
|
|
|
- if (show) {
|
|
|
+ if (verbose) {
|
|
|
console.log(err);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-module.exports.makedir = function (path, isFilePath = false) {
|
|
|
+module.exports.makedir = function (path, isFilePath = false, verbose = false) {
|
|
|
if (isFilePath) {
|
|
|
let split = path.split('/');
|
|
|
delete split[split.length - 1];
|
|
|
path = split.join('/');
|
|
|
}
|
|
|
if (!module.exports.exist(path)) {
|
|
|
- fs.mkdirSync(path, {recursive: true});
|
|
|
+ try {
|
|
|
+ fs.mkdirSync(path, {recursive: true});
|
|
|
+ return true;
|
|
|
+ } catch (err) {
|
|
|
+ if (verbose) {
|
|
|
+ console.error(err);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+module.exports.put = function (path, content, verbose = false) {
|
|
|
+ try {
|
|
|
+ fs.writeFileSync(path, content);
|
|
|
+ return true;
|
|
|
+ } catch (err) {
|
|
|
+ if (verbose) {
|
|
|
+ console.error(err);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+module.exports.fs = fs;
|