Open SunXinFei opened 5 years ago
git没有特别好的方法下载指定文件夹,而svn可以,但是windows会涉及到svn的安装,所以下载并解压是兼容不同系统的比较好的方式
注意:将trunk替换之前的路径即可
svn export https://github.com/SunXinFei/vue-webpack-demo/**trunk**/src/pages
这里解压是使用的tar的命令或npm包,原因是unzip或者adm-zip之类的虽然也支持解压,但是不支持忽略n层文件夹,也就是说想解压结果不包含最外层文件夹或者aaa/src下的所有文件的话,tar是非常合适的。 tar 压缩命令
tar -cvf MyCard.tar ./vue-webpack-demo/src/pages/Home/components/MyCard/
//开始loading
//使用文件流下载模版项目
const templateZipSrc =
"https://iivbox.github.io/iivbox/preview/open-source/static/zip/vue-webpack-demo.tar"; //获取图片的url
const zipFileName = "vue-webpack-demo.tar";
//采用request模块,向服务器发起一次请求,获取资源
request.head(templateZipSrc, function(err, res, body) {
if (err) {
this.$Notice.error({
title: "error",
desc: err
});
console.log(err);
}
});
//创建writeSteam
const writeSteam = fs.createWriteStream(
`${realPath}/${zipFileName}`,
{ autoClose: true }
);
//下载资源并写文件流
request(templateZipSrc)
.pipe(writeSteam)
.on("finish", () => {
//创建读取文件流
fs.createReadStream(`${realPath}/${zipFileName}`)
.pipe(
tar.x({
strip: 2, //去掉两层目录
C: `${realPath}`
})
)
.on("finish", () => {
//删除压缩包,windows没有rm指令
//shell.exec(
//`rm ${realPath}/${zipFileName}`,
// (code, stdout, stderr) => {
// console.log(code, stdout, stderr);
// }
// );
//使用node删除压缩包,兼容系统
fs.unlink(`${realPath}/${zipFileName}`,(error)=>{
if(error){
console.log(error);
return false;
}
console.log('删除文件成功');
})
//路由跳转,业务操作,结束loading
});
});
1.依赖管理页面的version取自node_modules对应的文件夹下的package.json的文件的version 2.页面列表中添加页面会修改menuConfig.js、routerConfig.js、以及创建页面文件夹和组件
Node创建/删除文件夹
原生的创建文件夹方法不支持自动创建,需要封装方法递归创建