Skip to content

Commit

Permalink
解决init程序文件复制不全问题
Browse files Browse the repository at this point in the history
发现是innerCopy函数中的path处理问题导致合成目的地址失败
  • Loading branch information
gmono committed Feb 20, 2020
1 parent 9227ebb commit e7329f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 9 additions & 3 deletions app/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function innerCopy(src:string,dest:string){
let wd=fse.createWriteStream(d);
return new Promise<void>((r)=>{
wd.addListener("finish",()=>{
console.log(`复制文件 ${s}${d}`)
// console.log(`复制文件 ${s} 到 ${d}`)
r();
})
rd.pipe(wd);
Expand All @@ -41,14 +41,20 @@ async function innerCopy(src:string,dest:string){
await fse.ensureDir(dest);
//开始复制目录 遍历src目录树
let mon=walk.walk(src);
mon.on("directory",(base,name,next)=>{
// console.log(path.resolve(base,name.name));
next();
})
mon.on("file",async (dirpath,filename,next)=>{
//把文件复制到对应位置 把dirpath和filename合成完整src路径 从中生成dest路径 复制文件
//不带src路径前缀的目录路径
let endDirpath=dirpath.slice(src.length);
//不带src路径前缀的目录路径 从1开始截取是为了去掉path前面的/ 以免被认为是从root开始
let endDirpath=dirpath.slice(src.length).slice(1);
let allpath=path.resolve(dirpath,filename.name); //源地址
// console.log(allpath);
//在allpath中去除src的部分
let destdir=path.resolve(dest,endDirpath); //目的目录地址
let destpath=path.resolve(destdir,filename.name);//目的文件地址
console.log(dest,endDirpath,destdir);
await fse.ensureDir(destdir);
//复制文件
await copyFile(allpath,destpath);
Expand Down
12 changes: 9 additions & 3 deletions dist_server/init.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist_server/init.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e7329f3

Please sign in to comment.