Commit 127ea07c authored by ninglx's avatar ninglx

本地引入 取消unistrong node-file-util依赖

parent a0df6db4
......@@ -11,7 +11,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"@unistrong/node-file-util": "^0.1.0",
"chalk": "^4.1.0",
"express": "^4.17.1",
"http-proxy-middleware": "^1.0.4",
......
const shell = require("shelljs");
const chalk = require("chalk");
const systemMap = require("../system");
const util = require("@unistrong/node-file-util");
const util = require("./node-file-util");
let system = process.argv.splice(2);
!system.length && (system = Object.keys(systemMap));
......
......@@ -5,7 +5,5 @@
"scripts": {
"build": "node ./tool/build.js"
},
"dependencies": {
"@unistrong/node-file-util": "^0.1.0"
}
"dependencies": {}
}
const util = require("@unistrong/node-file-util");
const util = require("./node-file-util");
util.delete("./dist");
util.copy("./src", "./dist");
const fs = require("fs");
const path = require("path");
module.exports = {
isExists(url) {
return fs.existsSync(url);
},
getDir(url) {
return fs.readdirSync(url);
},
isDirectory(url) {
return fs.statSync(url).isDirectory();
},
forEachFolder(url, callback) {
if (this.isExists(url)) {
callback("folderBefore", url);
const files = this.getDir(url);
files.forEach((file) => {
const curUrl = path.join(url, file);
if (this.isDirectory(curUrl)) {
this.forEachFolder(curUrl, callback);
} else {
callback("file", curUrl, file);
}
});
callback("folderAfter", url);
}
},
deleteFile(url) {
fs.unlinkSync(url);
},
deleteFolder(url) {
fs.rmdirSync(url);
},
deleteCatalog(url) {
this.forEachFolder(url, (type, urlname, filename) => {
if (type === "file") {
this.deleteFile(urlname);
}
if (type === "folderAfter") {
this.deleteFolder(urlname);
}
});
},
delete(url) {
if (this.isExists(url)) {
if (this.isDirectory(url)) {
this.deleteCatalog(url);
} else {
this.deleteFile(url);
}
}
},
copyFile(src, tar) {
if (this.isExists(src)) {
fs.copyFileSync(src, tar);
}
},
copyCatalog(src, tar) {
if (this.isExists(src)) {
if (!this.isExists(tar)) {
this.createFolder(tar);
}
const files = this.getDir(src);
files.forEach((file) => {
const srcUrl = path.join(src, file);
const tarUrl = path.join(tar, file);
if (this.isDirectory(srcUrl)) {
this.copyCatalog(srcUrl, tarUrl);
} else {
this.copyFile(srcUrl, tarUrl);
}
});
}
},
copy(src, tar) {
if (this.isExists(src)) {
if (this.isDirectory(src)) {
this.copyCatalog(src, tar);
} else {
this.copyFile(src, tar);
}
}
},
createFolder(url) {
fs.mkdirSync(url);
},
createFile(url, data) {
fs.writeFileSync(url, data);
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment