Skip to content

Commit

Permalink
provide -m to enchance fixes for #14
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty472123 committed Mar 26, 2018
1 parent 02d1857 commit a94c69b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Wechat App(微信小程序, .wxapkg)解包及相关文件(.wxss, .json, .wxs, .w

- `node wuConfig.js <files...>` 将 app-config.json 中的内容拆分到各个文件对应的 .json 和 app.json , 并通过搜索 app-config.json 所在文件夹下的所有文件尝试将 iconData 还原为 iconPath 。
- `node wuJs.js <files...>` 将 app-service.js (或小游戏中的 game.js ) 拆分成一系列原先独立的 javascript 文件,并使用 Uglify-ES 美化,从而尽可能还原编译前的情况。
- `node wuWxml.js <files...>` 将编译/混合到 page-frame.html ( 或 app-wxss.js ) 中的 wxml 和 wxs 文件还原为独立的、未编译的文件。
- `node wuWxml.js [-m] <files...>` 将编译/混合到 page-frame.html ( 或 app-wxss.js ) 中的 wxml 和 wxs 文件还原为独立的、未编译的文件。如果加上`-m`指令,就会阻止`block`块自动省略,可能帮助解决一些相关过程的 bug
- `node wuWxss.js <dirs...>` 通过获取文件夹下的 page-frame.html ( 或 app-wxss.js ) 和其他 html 文件的内容,还原出编译前 wxss 文件的内容。
- `node wuWxapkg.js [-d] <files...>` 将 wxapkg 文件解包,并将包中上述命令中所提的被编译/混合的文件自动地恢复原状。如果加上`-d`指令,就会保留编译/混合后所生成的新文件,否则会自动删去这些文件。
- `node wuWxapkg.js [-d] <files...>` 将 wxapkg 文件解包,并将包中上述命令中所提的被编译/混合的文件自动地恢复原状。如果加上`-d`指令,就会保留编译/混合后所生成的新文件,否则会自动删去这些文件。同时,前面命令中的指令也可直接加在这一命令上。

### wxapkg 包的获取

Expand Down
4 changes: 2 additions & 2 deletions wuWxapkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function packDone(dir,cb,order){
wuCfg.doConfig(path.resolve(dir,"app-config.json"),doBack);
wuJs.splitJs(path.resolve(dir,"app-service.js"),doBack);
if(fs.existsSync(path.resolve(dir,"page-frame.html")))
wuMl.doFrame(path.resolve(dir,"page-frame.html"),doBack);
wuMl.doFrame(path.resolve(dir,"page-frame.html"),doBack,order);
else if(fs.existsSync(path.resolve(dir,"app-wxss.js"))) {
wuMl.doFrame(path.resolve(dir,"app-wxss.js"),doBack);
wuMl.doFrame(path.resolve(dir,"app-wxss.js"),doBack,order);
needDelete[path.resolve(dir,"page-frame.js")]=8;
} else throw Error("page-frame-like file is not found in the package by auto.");
wuSs.doWxss(dir,doBack);//Force it run at last, becuase lots of error occured in this part
Expand Down
24 changes: 14 additions & 10 deletions wuWxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,15 @@ function wxmlify(str,isText){
if(isText)return str;//may have some bugs in some specific case(undocumented by tx)
else return str.replace(/"/g, '\\"');
}
function elemToString(elem,dep){
function elemToString(elem,dep,moreInfo=false){
const longerList=[];//put tag name which can't be <x /> style.
const indent=' '.repeat(4);
function isTextTag(elem){
return elem.tag=="__textNode__"&&elem.content;
}
function elemRecursion(elem,dep){
return elemToString(elem,dep,moreInfo);
}
function trimMerge(rets){
let needTrimLeft=false,ans="";
for(let ret of rets){
Expand All @@ -206,7 +209,7 @@ function elemToString(elem,dep){
str.textNode=1;
return wxmlify(str,true);//indent.repeat(dep)+wxmlify(elem.content.trim(),true)+"\n";
}
if(elem.tag=="block"){
if(elem.tag=="block"&&!moreInfo){
if(elem.son.length==1&&!isTextTag(elem.son[0])){
let ok=true,s=elem.son[0];
for(let x in elem.v)if(x in s.v){
Expand All @@ -215,11 +218,11 @@ function elemToString(elem,dep){
}
if(ok&&!(("wx:for" in s.v||"wx:if" in s.v)&&("wx:if" in elem.v||"wx:else" in elem.v||"wx:elif" in elem.v))){//if for and if in one tag, the default result is an if in for. And we should block if nested in elif/else been combined.
Object.assign(s.v,elem.v);
return elemToString(s,dep);
return elemRecursion(s,dep);
}
}else if(Object.keys(elem.v).length==0){
let ret=[];
for(let s of elem.son)ret.push(elemToString(s,dep));
for(let s of elem.son)ret.push(elemRecursion(s,dep));
return trimMerge(ret);
}
}
Expand All @@ -231,25 +234,25 @@ function elemToString(elem,dep){
}
ret+=">\n";
let rets=[ret];
for(let s of elem.son)rets.push(elemToString(s,dep+1));
for(let s of elem.son)rets.push(elemRecursion(s,dep+1));
rets.push(indent.repeat(dep)+"</"+elem.tag+">\n");
return trimMerge(rets);
}
function doWxml(dir,name,code,z,xPool,rDs,wxsList){
function doWxml(dir,name,code,z,xPool,rDs,wxsList,moreInfo){
let rname=code.slice(code.lastIndexOf("return")+6).replace(/[\;\}]/g,"").trim();
code=code.slice(code.indexOf("\n"),code.lastIndexOf("return")).trim();
let r={son:[]};
analyze(esprima.parseScript(code).body,z,{[rname]:r},xPool,{[rname]:r});
let ans=[];
for(let elem of r.son)ans.push(elemToString(elem,0));
for(let elem of r.son)ans.push(elemToString(elem,0,moreInfo));
let result=[ans.join("")];
for(let v in rDs){
let code=rDs[v].toString();
let rname=code.slice(code.lastIndexOf("return")+6).replace(/[\;\}]/g,"").trim();
code=code.slice(code.indexOf("\ntry{")+5,code.lastIndexOf("\n}catch(")).trim();
let r={tag:"template",v:{name:v},son:[]};
analyze(esprima.parseScript(code).body,z,{[rname]:r},xPool,{[rname]:r});
result.unshift(elemToString(r,0));
result.unshift(elemToString(r,0,moreInfo));
}
name=path.resolve(dir,name);
if(wxsList[name])result.push(wxsList[name]);
Expand All @@ -269,7 +272,8 @@ function doWxs(code){
const before='nv_module={nv_exports:{}};';
return jsBeautify(code.slice(code.indexOf(before)+before.length,code.lastIndexOf('return nv_module.nv_exports;}')).replace(/nv\_/g,''));
}
function doFrame(name,cb){
function doFrame(name,cb,order){
let moreInfo=order.includes("m");
wxsList={};
getZ(name,z=>{
wu.get(name,code=>{
Expand Down Expand Up @@ -301,7 +305,7 @@ function doFrame(name,cb){
wxsList[name]=res.join("\n");
}
}
for(let name in rE)tryWxml(dir,name,rE[name].f.toString(),z,x,rD[name],wxsList);
for(let name in rE)tryWxml(dir,name,rE[name].f.toString(),z,x,rD[name],wxsList,moreInfo);
cb({[name]:4});
});
});
Expand Down

0 comments on commit a94c69b

Please sign in to comment.