mirror of
https://github.com/msojocs/wechat-web-devtools-linux.git
synced 2025-07-22 00:00:04 +08:00
update: 清理无用代码 #16
This commit is contained in:
parent
6dcf602079
commit
1fb6cb11c6
@ -6,6 +6,7 @@ const args = process.argv.slice(2);
|
|||||||
const funcName = args[args.indexOf('-gn') + 1]
|
const funcName = args[args.indexOf('-gn') + 1]
|
||||||
const debugWXS = args.includes('-ds')
|
const debugWXS = args.includes('-ds')
|
||||||
const wccPath = path.resolve(__dirname, './wcc.bin')
|
const wccPath = path.resolve(__dirname, './wcc.bin')
|
||||||
|
|
||||||
function genFunctionContent_LLW(wxmlName, config={}, source) {
|
function genFunctionContent_LLW(wxmlName, config={}, source) {
|
||||||
// 起始
|
// 起始
|
||||||
let content = `var cs = cs || [];\u000a${config.funcName}` + "=function(_,_v,_n,_p,_s,_wp,_wl,$gwn,$gwl,$gwh,wh,$gstack,$gwrt,gra,grb,TestTest,wfor,_ca,_da,_r,_rz,_o,_oz,_1,_1z,_2,_2z,_m,_mz,nv_getDate,nv_getRegExp,nv_console,nv_parseInt,nv_parseFloat,nv_isNaN,nv_isFinite,nv_decodeURI,nv_decodeURIComponent,nv_encodeURI,nv_encodeURIComponent,$gdc,nv_JSON,_af,_gv,_ai,_grp,_gd,_gapi,$ixc,_ic,_w,_ev,_tsd){return function(path,global){\u000aif(typeof global==='undefined'){if (typeof __GWX_GLOBAL__==='undefined')global={};else global=__GWX_GLOBAL__;}if(typeof __WXML_GLOBAL__ === 'undefined') {__WXML_GLOBAL__={};\u000a}__WXML_GLOBAL__.modules = __WXML_GLOBAL__.modules || {};\u000a"
|
let content = `var cs = cs || [];\u000a${config.funcName}` + "=function(_,_v,_n,_p,_s,_wp,_wl,$gwn,$gwl,$gwh,wh,$gstack,$gwrt,gra,grb,TestTest,wfor,_ca,_da,_r,_rz,_o,_oz,_1,_1z,_2,_2z,_m,_mz,nv_getDate,nv_getRegExp,nv_console,nv_parseInt,nv_parseFloat,nv_isNaN,nv_isFinite,nv_decodeURI,nv_decodeURIComponent,nv_encodeURI,nv_encodeURIComponent,$gdc,nv_JSON,_af,_gv,_ai,_grp,_gd,_gapi,$ixc,_ic,_w,_ev,_tsd){return function(path,global){\u000aif(typeof global==='undefined'){if (typeof __GWX_GLOBAL__==='undefined')global={};else global=__GWX_GLOBAL__;}if(typeof __WXML_GLOBAL__ === 'undefined') {__WXML_GLOBAL__={};\u000a}__WXML_GLOBAL__.modules = __WXML_GLOBAL__.modules || {};\u000a"
|
||||||
@ -17,12 +18,11 @@ function genFunctionContent_LLW(wxmlName, config={}, source) {
|
|||||||
content += "var cs = cs || [];" + cs[1].replace(new RegExp(`\\${funcName}`, 'g'), config.funcName)
|
content += "var cs = cs || [];" + cs[1].replace(new RegExp(`\\${funcName}`, 'g'), config.funcName)
|
||||||
|
|
||||||
// gz函数
|
// gz函数
|
||||||
// `function gz\\$gwx_${config.num+1}\\(\\){[\s\S]+_WXML_GLOBAL__\\.ops_cached\\.\\$gwx_${config.num+1}\\u000a}`
|
|
||||||
const exp = `function gz\\${funcName}_${config.num+1}\\(\\)\\{[\\s\\S]*_WXML_GLOBAL__\\.ops_cached\\.\\${funcName}_${config.num+1}\n}`
|
const exp = `function gz\\${funcName}_${config.num+1}\\(\\)\\{[\\s\\S]*_WXML_GLOBAL__\\.ops_cached\\.\\${funcName}_${config.num+1}\n}`
|
||||||
const gz = source.match(new RegExp(exp))[0]
|
const gz = source.match(new RegExp(exp))[0]
|
||||||
content += gz
|
content += gz
|
||||||
|
|
||||||
// debug要作为判断依据,所以放前面
|
// debug
|
||||||
let debug = source.match(new RegExp(`\\n__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*?\\nvar`))
|
let debug = source.match(new RegExp(`\\n__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*?\\nvar`))
|
||||||
debug = debug[0].substring(0, debug[0].length-3).replace(new RegExp(`\\${funcName}`, 'g'), config.funcName)
|
debug = debug[0].substring(0, debug[0].length-3).replace(new RegExp(`\\${funcName}`, 'g'), config.funcName)
|
||||||
content += debug
|
content += debug
|
||||||
@ -49,7 +49,6 @@ function genCommonContent_LLW(source){
|
|||||||
common += "var cs = cs || [];" + cs[1]
|
common += "var cs = cs || [];" + cs[1]
|
||||||
|
|
||||||
// nv_require
|
// nv_require
|
||||||
// bug llw1.sh
|
|
||||||
const nv_require = source.match(new RegExp(`(__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*)var x=\\[`))
|
const nv_require = source.match(new RegExp(`(__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*)var x=\\[`))
|
||||||
common += nv_require[1]
|
common += nv_require[1]
|
||||||
|
|
||||||
@ -70,7 +69,6 @@ function genFunctionContent_LLA(wxmlName, config={}, source) {
|
|||||||
if(!debugWXS){
|
if(!debugWXS){
|
||||||
const exp = `function gz\\${funcName}_${config.num+1}\\(\\)\\{[\\s\\S]*?\\)}`
|
const exp = `function gz\\${funcName}_${config.num+1}\\(\\)\\{[\\s\\S]*?\\)}`
|
||||||
const gz = source.match(new RegExp(exp))
|
const gz = source.match(new RegExp(exp))
|
||||||
// console.log(gz)
|
|
||||||
content += gz[0].replace(new RegExp(`\\${funcName}\\_\\d+`, 'g'), `${config.funcName}_1`) + `\u000a})(__WXML_GLOBAL__.ops_cached.${config.funcName}_1);return __WXML_GLOBAL__.ops_cached.${config.funcName}_1\u000a}`
|
content += gz[0].replace(new RegExp(`\\${funcName}\\_\\d+`, 'g'), `${config.funcName}_1`) + `\u000a})(__WXML_GLOBAL__.ops_cached.${config.funcName}_1);return __WXML_GLOBAL__.ops_cached.${config.funcName}_1\u000a}`
|
||||||
}else{
|
}else{
|
||||||
// gz函数2
|
// gz函数2
|
||||||
@ -109,7 +107,6 @@ function genCommonContent_LLA(source){
|
|||||||
|
|
||||||
// nv_require
|
// nv_require
|
||||||
const nv_require = source.match(new RegExp(`(__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*)var x=\\[`))
|
const nv_require = source.match(new RegExp(`(__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*)var x=\\[`))
|
||||||
// console.log(nv_require)
|
|
||||||
common += nv_require[1]
|
common += nv_require[1]
|
||||||
|
|
||||||
common += "var x=[];if(path&&e_[path]){\u000areturn function(env,dd,global){$gwxc=0;var root={\u0022tag\u0022:\u0022wx-page\u0022};root.children=[]\u000a;g=\u0022"
|
common += "var x=[];if(path&&e_[path]){\u000areturn function(env,dd,global){$gwxc=0;var root={\u0022tag\u0022:\u0022wx-page\u0022};root.children=[]\u000a;g=\u0022"
|
||||||
@ -132,7 +129,6 @@ if (args.includes("-llw")) {
|
|||||||
errData.push(e);
|
errData.push(e);
|
||||||
});
|
});
|
||||||
wcc.on("close", (n) => {
|
wcc.on("close", (n) => {
|
||||||
// console.log('close', new Date().getTime()/1000)
|
|
||||||
if (0 === n) {
|
if (0 === n) {
|
||||||
const str = Buffer.concat(spwanData).toString()
|
const str = Buffer.concat(spwanData).toString()
|
||||||
const resultObj = {
|
const resultObj = {
|
||||||
@ -158,10 +154,8 @@ if (args.includes("-llw")) {
|
|||||||
resultObj.generateFunctionName[key] = pageConfig[key].funcName
|
resultObj.generateFunctionName[key] = pageConfig[key].funcName
|
||||||
resultObj.generateFunctionContent[key] = genFunctionContent_LLW(key, pageConfig[key], str)
|
resultObj.generateFunctionContent[key] = genFunctionContent_LLW(key, pageConfig[key], str)
|
||||||
}
|
}
|
||||||
// console.log(pageConfig)
|
|
||||||
let result = JSON.stringify(resultObj)
|
let result = JSON.stringify(resultObj)
|
||||||
result = result.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) {
|
result = result.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) {
|
||||||
// console.log($0, $1)
|
|
||||||
let c
|
let c
|
||||||
switch ($0) {
|
switch ($0) {
|
||||||
case "\\n":
|
case "\\n":
|
||||||
@ -177,8 +171,7 @@ if (args.includes("-llw")) {
|
|||||||
}
|
}
|
||||||
return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0")
|
return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0")
|
||||||
})
|
})
|
||||||
// console.log(pageConfig)
|
process.stdout.write(result)
|
||||||
process.stdout.write(" " + result + " ")
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -197,7 +190,6 @@ if (args.includes("-llw")) {
|
|||||||
errData.push(e);
|
errData.push(e);
|
||||||
});
|
});
|
||||||
wcc.on("close", (n) => {
|
wcc.on("close", (n) => {
|
||||||
// console.log('close', new Date().getTime()/1000)
|
|
||||||
if (0 === n) {
|
if (0 === n) {
|
||||||
let str = Buffer.concat(spwanData).toString();
|
let str = Buffer.concat(spwanData).toString();
|
||||||
// 获取Linux wcc的输出数据,用于分析
|
// 获取Linux wcc的输出数据,用于分析
|
||||||
@ -211,7 +203,6 @@ if (args.includes("-llw")) {
|
|||||||
"__COMMON__": funcName,
|
"__COMMON__": funcName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// str = str.replace(/\n/g, '\\u000a')
|
|
||||||
const indexArr = eval(str.match(/var x=(\[.*\]);/)[1])
|
const indexArr = eval(str.match(/var x=(\[.*\]);/)[1])
|
||||||
const pageConfig = {}
|
const pageConfig = {}
|
||||||
indexArr.forEach((ele, i) => {
|
indexArr.forEach((ele, i) => {
|
||||||
@ -226,7 +217,6 @@ if (args.includes("-llw")) {
|
|||||||
}
|
}
|
||||||
let result = JSON.stringify(resultObj)
|
let result = JSON.stringify(resultObj)
|
||||||
result = result.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) {
|
result = result.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) {
|
||||||
// console.log($0, $1)
|
|
||||||
let c
|
let c
|
||||||
switch ($0) {
|
switch ($0) {
|
||||||
case "\\n":
|
case "\\n":
|
||||||
@ -242,8 +232,7 @@ if (args.includes("-llw")) {
|
|||||||
}
|
}
|
||||||
return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0")
|
return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0")
|
||||||
})
|
})
|
||||||
// console.log(pageConfig)
|
process.stdout.write(result)
|
||||||
process.stdout.write(" " + result + " ")
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const { spawn, spawnSync } = require("child_process");
|
const { spawn } = require("child_process");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const version = "20220222"
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
const wcscPath = path.resolve(__dirname, "./wcsc.bin")
|
const wcscPath = path.resolve(__dirname, "./wcsc.bin")
|
||||||
|
|
||||||
function encode1(s) {
|
function encode1(s) {
|
||||||
return encodeURI(s).replace(
|
return encodeURI(s).replace(
|
||||||
/%(u[0-9A-F]{4})|(%[0-9A-F]{2})/gm,
|
/%(u[0-9A-F]{4})|(%[0-9A-F]{2})/gm,
|
||||||
@ -24,7 +26,6 @@ if (args.includes("-ll")) {
|
|||||||
errData.push(e);
|
errData.push(e);
|
||||||
});
|
});
|
||||||
wcsc.on("close", (n) => {
|
wcsc.on("close", (n) => {
|
||||||
// console.log('close', new Date().getTime()/1000)
|
|
||||||
if (0 === n) {
|
if (0 === n) {
|
||||||
const str = Buffer.concat(spwanData).toString().replace(/\\\\/g, '\\\\u005c');
|
const str = Buffer.concat(spwanData).toString().replace(/\\\\/g, '\\\\u005c');
|
||||||
const resultSplit = encode1(str).split("=");
|
const resultSplit = encode1(str).split("=");
|
||||||
@ -41,16 +42,13 @@ if (args.includes("-ll")) {
|
|||||||
/((\\x[\da-f]{2}|\\u[\da-f]{4})){1,}/gi,
|
/((\\x[\da-f]{2}|\\u[\da-f]{4})){1,}/gi,
|
||||||
function ($0, $1, $2) {
|
function ($0, $1, $2) {
|
||||||
return eval('"' + $0 + '"');
|
return eval('"' + $0 + '"');
|
||||||
// return dict[$0] ? dict[$0] : eval('"' + $0 + '"')
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const resultObj = {
|
const resultObj = {
|
||||||
common: tempObj.comm, //.replace(/\\n/g, '\\u000a'),
|
common: tempObj.comm,
|
||||||
pageWxss: {},
|
pageWxss: {},
|
||||||
};
|
};
|
||||||
// console.log(resultObj.common)
|
|
||||||
// console.log('for key', new Date().getTime()/1000)
|
|
||||||
for (const key in tempObj) {
|
for (const key in tempObj) {
|
||||||
if (key.endsWith(".wxss")) {
|
if (key.endsWith(".wxss")) {
|
||||||
resultObj.pageWxss[key] = tempObj[key];
|
resultObj.pageWxss[key] = tempObj[key];
|
||||||
@ -61,82 +59,14 @@ if (args.includes("-ll")) {
|
|||||||
return this.slice(0, start) + newStr + this.slice(start + 1);
|
return this.slice(0, start) + newStr + this.slice(start + 1);
|
||||||
};
|
};
|
||||||
result = result.replace(/\\\\/g, "\\");
|
result = result.replace(/\\\\/g, "\\");
|
||||||
// console.log('main replace', new Date().getTime()/1000)
|
|
||||||
// for (let i = 0; i < result.length; i++) {
|
|
||||||
// if (result[i] === "\\") {
|
|
||||||
// // && result[i + 1] !== 'u'
|
|
||||||
// const c = result[i + 1] === "n" ? "\n" : result[i + 1];
|
|
||||||
// result = result.splice(
|
|
||||||
// i + 1,
|
|
||||||
// "u" + c.charCodeAt(0).toString(16).padStart(4, "0")
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
result = result.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) {
|
result = result.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) {
|
||||||
// console.log($0, $1)
|
|
||||||
const c = $0 === "\\n" ? "\n" : $0[1];
|
const c = $0 === "\\n" ? "\n" : $0[1];
|
||||||
return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0")
|
return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0")
|
||||||
})
|
})
|
||||||
// console.log('main replace end', new Date().getTime()/1000)
|
|
||||||
// result = result.replace(/u005c"/g, 'u005cx22')
|
|
||||||
// console.log('done', new Date().getTime()/1000)
|
|
||||||
process.stdout.write(result);
|
process.stdout.write(result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// const wcsc = spawnSync(path.resolve(__dirname, "../wcsc"), args, {
|
|
||||||
// cwd: process.cwd(),
|
|
||||||
// });
|
|
||||||
// if (wcsc.status !== 0) {
|
|
||||||
// console.error(wcsc.error);
|
|
||||||
// process.exit(wcsc.status);
|
|
||||||
// }
|
|
||||||
// const str = wcsc.stdout.toString();
|
|
||||||
// // console.log(str)
|
|
||||||
// const resultSplit = encode1(str).split("=");
|
|
||||||
// const tempObj = {};
|
|
||||||
// for (
|
|
||||||
// let i = 0, total = resultSplit.length;
|
|
||||||
// i < total && resultSplit[i + 1];
|
|
||||||
// i += 2
|
|
||||||
// ) {
|
|
||||||
// // a=b ---> a: b
|
|
||||||
// const key = resultSplit[i];
|
|
||||||
// if (key === "version") continue;
|
|
||||||
// tempObj[key] = resultSplit[i + 1].replace(
|
|
||||||
// /((\\x[\da-f]{2}|\\u[\da-f]{4})){1,}/gi,
|
|
||||||
// function ($0, $1, $2) {
|
|
||||||
// return eval('"' + $0 + '"');
|
|
||||||
// // return dict[$0] ? dict[$0] : eval('"' + $0 + '"')
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// const resultObj = {
|
|
||||||
// common: tempObj.comm, //.replace(/\\n/g, '\\u000a'),
|
|
||||||
// pageWxss: {},
|
|
||||||
// };
|
|
||||||
// // console.log(resultObj.common)
|
|
||||||
// for (const key in tempObj) {
|
|
||||||
// if (key.endsWith(".wxss")) {
|
|
||||||
// resultObj.pageWxss[key] = tempObj[key];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// let result = JSON.stringify(resultObj);
|
|
||||||
// String.prototype.splice = function (start, newStr) {
|
|
||||||
// return this.slice(0, start) + newStr + this.slice(start + 1);
|
|
||||||
// };
|
|
||||||
// result = result.replace(/\\\\/g, "\\");
|
|
||||||
// for (let i = 0; i < result.length; i++) {
|
|
||||||
// if (result[i] === "\\") {
|
|
||||||
// // && result[i + 1] !== 'u'
|
|
||||||
// const c = result[i + 1] === "n" ? "\n" : result[i + 1];
|
|
||||||
// result = result.splice(
|
|
||||||
// i + 1,
|
|
||||||
// "u" + c.charCodeAt(0).toString(16).padStart(4, "0")
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// process.stdout.write(result);
|
|
||||||
} else {
|
} else {
|
||||||
spawn(wcscPath, args, {
|
spawn(wcscPath, args, {
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
|
@ -15,12 +15,11 @@ function genFunctionContent_LL(wxmlName, config={}, source, funcName) {
|
|||||||
content += "var cs" + cs[1].replace(new RegExp(`\\${funcName}`, 'g'), config.funcName)
|
content += "var cs" + cs[1].replace(new RegExp(`\\${funcName}`, 'g'), config.funcName)
|
||||||
|
|
||||||
// gz函数
|
// gz函数
|
||||||
// `function gz\\$gwx_${config.num+1}\\(\\){[\s\S]+_WXML_GLOBAL__\\.ops_cached\\.\\$gwx_${config.num+1}\\u000a}`
|
|
||||||
const exp = `function gz\\${funcName}_${config.num+1}\\(\\)\\{[\\s\\S]*_WXML_GLOBAL__\\.ops_cached\\.\\${funcName}_${config.num+1}\n}`
|
const exp = `function gz\\${funcName}_${config.num+1}\\(\\)\\{[\\s\\S]*_WXML_GLOBAL__\\.ops_cached\\.\\${funcName}_${config.num+1}\n}`
|
||||||
const gz = source.match(new RegExp(exp))[0]
|
const gz = source.match(new RegExp(exp))[0]
|
||||||
content += gz
|
content += gz
|
||||||
|
|
||||||
// debug要作为判断依据,所以放前面
|
// debug
|
||||||
let debug = source.match(new RegExp(`\\n__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*?\\nvar`))
|
let debug = source.match(new RegExp(`\\n__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*?\\nvar`))
|
||||||
debug = debug[0].substring(0, debug[0].length-3).replace(new RegExp(`\\${funcName}`, 'g'), config.funcName)
|
debug = debug[0].substring(0, debug[0].length-3).replace(new RegExp(`\\${funcName}`, 'g'), config.funcName)
|
||||||
content += debug
|
content += debug
|
||||||
@ -47,7 +46,6 @@ function genCommonContent_LL(source, funcName){
|
|||||||
common += "var cs" + cs[1]
|
common += "var cs" + cs[1]
|
||||||
|
|
||||||
// nv_require
|
// nv_require
|
||||||
// bug llw1.sh
|
|
||||||
const nv_require = source.match(new RegExp(`(__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*)var x=\\[`))
|
const nv_require = source.match(new RegExp(`(__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*)var x=\\[`))
|
||||||
common += nv_require[1]
|
common += nv_require[1]
|
||||||
|
|
||||||
@ -222,24 +220,6 @@ function wxmlToJS(options={}) {
|
|||||||
}
|
}
|
||||||
// console.log(pageConfig)
|
// console.log(pageConfig)
|
||||||
result = resultObj
|
result = resultObj
|
||||||
// result = result.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) {
|
|
||||||
// // console.log($0, $1)
|
|
||||||
// let c
|
|
||||||
// switch ($0) {
|
|
||||||
// case "\\n":
|
|
||||||
// c = "\n"
|
|
||||||
// break;
|
|
||||||
// case "\\t":
|
|
||||||
// c = "\t"
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// default:
|
|
||||||
// c = $0[1]
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0")
|
|
||||||
// })
|
|
||||||
// console.log(pageConfig)
|
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user