这个方法直接创建一个资源路径
writePathFile("./src/main/webapp/static/dist/js/common/base.min.js","helle world")
function writePathFile(path, codes) {var pathA = path.split("/");
pathA.pop();
createDirsSync(pathA.join("/"), function () {fs.writeFile(path, codes, function (value) {// console.log(value)
codes = "";
});
})
}
// 判断有没有当前文件夹,有就查询下一层文件夹,没有就创建
function createDirsSync(dir, callback) {var dirs = dir.split('/');
if (dirs[0] == '.' || dirs[0] == "..") {dirs[1] = dirs[0] + "/" + dirs[1];
dirs.shift();}
if (dirs[dirs.length - 1] == "") {dirs.pop();
}
var len = dirs.length;
var i = 0;
var url = dirs[i];
makeDirs(url);
function makeDirs(url) {if (fs.existsSync(url)) {
i = i + 1;
if (len > i) {url = url + "/" + dirs[i];
makeDirs(url);
}else{callback();
}
} else {mkdir(url)
}
}
function mkdir(url) {fs.mkdirSync(url);
i = i + 1;
if (len > i) {url = url + "/" + dirs[i];
mkdir(url);
} else {callback();
}
}
}