提交 11c5fb72 编写于 作者: 5 592767809

加载器抽取优化

上级 fa9be0c6
let n = require('./webpack_out');
let DCSAPPClientAPI = require('./DCSAPPClientAPI-0.0.0.7');
let password_enc = n('56f2');
let u = "kcn071805buj05k313ql" , c = "4sig52dR0Xxw2raF0v37dngO3DiiR1PaITXS4ddJiRb1xfjSjAUQ6P9VuyxfaiZ8gElGKMcSskm70yGY0ZrQEQ==";
let data = {
"txnCommCom":{"txnIttChnlId":"C0081234567890987654321","txnIttChnlCgyCode":"BC01C101"},
"txnBodyCom":{
"loginType":"AU01","loginNo":"13088888888",
"loginPassword":password_enc.a("a123456"),
"acctType":"10","vcodeId":"1641482664426","vcode":"y9sb",
"sessionId":"fe823fd1-cb32-453f-a037-b4800037767d","clientId":"000000000"
}
};
let t = DCSAPPClientAPI.parseUtf8StringToArray(JSON.stringify(data));
let n2 = DCSAPPClientAPI.workKey_nego_and_data_encrypt_cpa(false, u, c, t, false);
let paypload = n2.keySM2Cipher;
console.log(paypload);
\ No newline at end of file
console.log(n);
\ No newline at end of file
node webpack_mixer.js -l tieba_promise.1e7c6aac.js -m common.f6f2d4d3.js -m utils.f6706911.js -m vendors.a4eb29bc.js -o webpack_out.js
\ No newline at end of file
此差异已折叠。
let n = require('./webpack_out');
console.log(n);
此差异已折叠。
(window.webpackJsonp=window.webpackJsonp||[]).push([[1],{26:function(e,a,t){"use strict";var n=t(2),d=t(0);n(a,"__esModule",{value:!0}),a.getConfigData=function(e){return o.default.get("/mo/q/getConfigData",{params:{amis_key:i[e]}}).then((function(e){return e&&0==+e.data.no&&e.data.data?e.data.data:r})).catch((function(e){return console.log(e),r}))},a.getConfigDataByKey=function(e){return o.default.get("/mo/q/getConfigData",{params:{amis_key:e}}).then((function(e){return e&&0==+e.data.no&&e.data.data?e.data.data:r})).catch((function(e){return console.log(e),r}))};var o=d(t(264)),i={tieba_promise:"b1eacfb4f0134729f19724d65c341ad115",agreement:"e53b06d85e9d2f1fece56992fce6043e15",vip_eula:"5bffb373a6e4feae710bde57bda9abd915",broadcast:"0d5710b306fa4bd478221e5f3e3894b815",privacy:"42ff5b275a35a66f1af3a3271985770615","service-agreement":"1b2211c924b7d02d87729a7138f9527515","video-rule":"185b4bab11a2104c45156b6fb8f9caba15",thirdparty_sdk:"fd229e1e69cb12fcec706e804dd948dd15","thirdparty-sdk":"a982a41fd3ec6d34c5524f8f6f62b9b015","bazhu-identity":"ef13b78695e780cc5ddd82782a91811215",viprenew_eula_mobile:"e767e293d0c279b48a06ec9ae12da08615",brand_area_download_center:"3a5b89cbd076007f16fa234ae723c49c15",eula_mobile:"c2db870787dde46b548479033a1f2e9b15",eula:"326a2bc4bd0812e771d3763109511d8215",vip_eula_mobile:"915b1df9ca09f97d94f91542dd12064515",bawudengji:"15b48d9888191e18f9670958e28e37d015","speed-common":"334839a2b8ad5d2615683ee144fd220415","speed-xiaomi":"4aaba990061c8fe7601bcdba9680107115","speed-huawei":"97ba30906427e1fafae6a8baa87fef0915","speed-oppo":"72e8291cbbd2a3555cb819c60840be4215","speed-vivo":"855e510b97cb89c3b46b3c75a129183915","same-city":"62493ae7ff992f41bbee7d5156e5507e15"},r='\n <style>\n .content {\n width: 100%;\n position: absolute;\n top: 0%;\n bottom: 0;\n left: 0;\n right: 0;\n }\n .emotion {\n display: block;\n margin: 0 auto 42px;\n width: 144px;\n height: 144px;\n padding-top: 10%;\n text-align: center;\n }\n p {\n margin-bottom: 2px;\n text-align: center;\n color: #8F8E94;\n font-size: 14px;\n line-height: 14px;\n }\n </style>\n <div class="content">\n <img class="emotion" src="https://tieba-fe.gz.bcebos.com/hybrid_offline/assets/thread-not-found.44ef1fb5.png">\n <p>网络出错了</p>\n </div>\n'},270:function(e,a,t){"use strict";var n=t(2),d=t(0);t(80),t(10),t(39),n(a,"__esModule",{value:!0}),a.deepClone=r,a.resHook=function(e){var a=String(void 0!==e.no?e.no:e.errno),t=e.errmsg||e.msg||e.errormsg;e.data||(e.data=r(e));return{errno:a,errmsg:t,data:e.data}},a.getQueryString=function(e,a){var t="",n=new RegExp("(\\?|&)"+a+"=([^&#]*)(#|&|$)","ig").exec(e);n&&(t=n[2]);return t};var o=d(t(30)),i=d(t(72));function r(e){var a=(0,i.default)(e)?[]:{};if(e&&"object"===(0,o.default)(e))for(var t in e)e.hasOwnProperty(t)&&(e[t]&&"object"===(0,o.default)(e[t])?a[t]=r(e[t]):a[t]=e[t]);return a}},680:function(e,a,t){"use strict";t(2)(a,"__esModule",{value:!0}),a.default=void 0;var n,d=t(681),o=t(270),i={baseURL:"",tbs:(null===(n=window.TBCONFIG)||void 0===n?void 0:n.tbs)||"",resHook:o.resHook};d.Http.useConfig(i);var r=d.Http;a.default=r}}]);
\ No newline at end of file
此差异已折叠。
const parser = require("@babel/parser");
const t = require("@babel/types");
const generator = require("@babel/generator");
const traverse = require("@babel/traverse").default;
const fs = require("fs");
function wtofile(path, flags, code) {
var fd = fs.openSync(path,flags);
fs.writeSync(fd, code);
fs.closeSync(fd);
}
function run(loader_path, out_path, modular_path) {
let js_code = fs.readFileSync(loader_path, {
encoding: "utf-8"
});
// 转换为AST语法树
let loader_ast = parser.parse(js_code);
// 获取加载器代码
let loader_body;
if (loader_ast.program.body[0].expression.type === 'UnaryExpression'){
loader_body = loader_ast.program.body[0].expression.argument.callee.body.body;
}else{
loader_body = loader_ast.program.body[0].expression.callee.body.body;
}
let export_function = null;
traverse(loader_ast, {
FunctionDeclaration(path){
if(path.toString().includes("exports:") && export_function == null){
export_function = path.node.id.name
}
}
});
if(export_function == null){
throw "未找到导出函数错误"
}
for (let i = 0; i < loader_body.length; i++){
let item = loader_body[i];
if(item.type === 'ExpressionStatement'){
if(item.expression.type === 'SequenceExpression' && item.expression.expressions[0].type === 'AssignmentExpression' && item.expression.expressions[0].left.type === 'MemberExpression' && item.expression.expressions[0].left.object.type === 'Identifier' && item.expression.expressions[0].left.object.name === export_function){
let j = 1;
while (j < item.expression.expressions.length){
let item2 = item.expression.expressions[j];
if(item2.left &&item2.left.type === 'MemberExpression' && item2.left.object.type === 'Identifier' && item2.left.object.name === export_function){
j++
}else{
item.expression.expressions.splice(j, item.expression.expressions.length - j);
break
}
}
loader_body.splice(i + 1, loader_body.length - i - 1);
loader_body.push(t.expressionStatement(t.assignmentExpression("=", t.identifier("export_function"), t.identifier(export_function))));
}
}else if(item.type === 'ReturnStatement'){
loader_body[i] = t.expressionStatement(item.argument);
let j = 0;
while (j < loader_body[i].expression.expressions.length){
let item2 = loader_body[i].expression.expressions[j];
if(item2.left &&item2.left.type === 'MemberExpression' && item2.left.object.type === 'Identifier' && item2.left.object.name === export_function){
j++
}else{
loader_body[i].expression.expressions.splice(j, loader_body[i].expression.expressions.length - j);
break
}
}
loader_body.push(t.expressionStatement(t.assignmentExpression("=", t.identifier("export_function"), t.identifier(export_function))));
}
}
// 导入加载器中的函数体
let loader_arguments;
if (loader_ast.program.body[0].expression.type === 'UnaryExpression'){
loader_arguments = loader_ast.program.body[0].expression.argument.arguments[0];
}else{
loader_arguments = loader_ast.program.body[0].expression.arguments[0];
}
if (loader_arguments.type === 'ArrayExpression'){
let tempobjectexpression = t.objectExpression([]);
loader_arguments.elements.forEach(function (item, index) {
if (item && item.type === 'FunctionExpression'){
tempobjectexpression.properties.push(t.objectProperty(
t.numericLiteral(index),
item,
false,
false
));
}
});
loader_arguments = tempobjectexpression;
}
// 加载外部函数体
modular_path.forEach(function (item, index) {
var jscode = fs.readFileSync(item, {
encoding: "utf-8"
});
let modular_ast = parser.parse(jscode);
modular_ast.program.body[0].expression.arguments[0].elements.forEach(function (item2, index2) {
if (item2.type === 'ArrayExpression'){
item2.elements.forEach(function (item3, index3) {
if (item3 && item3.type === 'FunctionExpression'){
loader_arguments.properties.push(t.objectProperty(
t.numericLiteral(index3),
item3,
false,
false
));
}
});
}else {
item2.properties.forEach(function (item3, index3) {
loader_arguments.properties.push(item3)
})
}
});
});
if (loader_ast.program.body[0].expression.type === 'UnaryExpression'){
loader_ast.program.body[0].expression.argument.arguments[0] = loader_arguments;
}else{
loader_ast.program.body[0].expression.arguments[0] = loader_arguments;
}
// 申请全局导出函数
loader_ast.program.body.splice(0, 0, t.variableDeclaration("var",[t.variableDeclarator(t.identifier("export_function"))]));
// 导出函数
loader_ast.program.body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier("module"), t.identifier("exports"), false), t.identifier("export_function"))));
let code = generator.default(loader_ast, {
compact: false, // 压缩格式
comments: false, // 注释
jsescOption: {
minimal: false // 转义
}
}).code;
wtofile(out_path, 'w', code);
}
!function () {
let loader_path, out_path;
let modular_path = [];
for(let i = 0; i < process.argv.length; i++){
if (process.argv[i] === '-l'){
loader_path = process.argv[i + 1];
i += 1;
}else if(process.argv[i] === '-m'){
modular_path.push(process.argv[i + 1]);
i += 1;
}else if(process.argv[i] === '-o'){
out_path = process.argv[i + 1];
i += 1;
}
}
if (loader_path && out_path){
run(loader_path, out_path, modular_path)
}
}();
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册