@winner-fed/winner-deploy 4.3.6 → 4.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -161
- package/dist/index.cjs +7 -7
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +7 -7
- package/package.json +1 -1
- package/templates/see/bash/scripts/afterInstall.sh +48 -0
- package/templates/see/bash/scripts/js/confuse.js +43 -0
- package/templates/see/bash/scripts/js/confuse.sh +58 -0
- package/templates/see/bash/scripts/js/obfuscator.js +2 -0
- package/templates/see/bash/scripts/js/readme.md +16 -0
- package/templates/see/python/scripts/afterInstall.py +34 -3
- package/templates/see/python/scripts/js/confuse.js +43 -0
- package/templates/see/python/scripts/js/confuse.sh +58 -0
- package/templates/see/python/scripts/js/obfuscator.js +2 -0
- package/templates/see/python/scripts/js/readme.md +16 -0
package/dist/index.d.ts
CHANGED
|
@@ -135,6 +135,11 @@ interface DeployOptions {
|
|
|
135
135
|
* @default python
|
|
136
136
|
*/
|
|
137
137
|
scriptsType?: 'python' | 'bash';
|
|
138
|
+
/**
|
|
139
|
+
* 是否在安装后对 template 中的配置 .js 做混淆;为 false 时不拷贝 scripts/js,afterInstall 不执行 node 混淆
|
|
140
|
+
* @default false
|
|
141
|
+
*/
|
|
142
|
+
enableObfuscation?: boolean;
|
|
138
143
|
/**
|
|
139
144
|
* 模板文件路径,支持传入多个模板文件路径,key 为模板文件名称,会放到see包的 template 目录下,value 为模板文件的绝对路径,可以使用 ejs 语法
|
|
140
145
|
* @default null
|
|
@@ -185,9 +190,10 @@ interface DeployOptions {
|
|
|
185
190
|
* @param seePackageType see 平台发布物包的类型,'web'(默认的) | 'docker'(支持容器化部署的SEE发布物)
|
|
186
191
|
* @param dockerImage docker 容器化镜像名,seePackageType 为 docker 生效
|
|
187
192
|
* @param scriptsType 脚本类型 'python' | 'bash'
|
|
193
|
+
* @param enableObfuscation 是否在安装后对配置 .js 做混淆,默认 false
|
|
188
194
|
* @param tplPath 模板文件路径,支持传入多个模板文件路径,key 为模板文件名称,会放到see包的 template 目录下,value 为模板文件的绝对路径,可以使用 ejs 语法
|
|
189
195
|
* @param cb {function} 回调函数,用于处理在组装 see 包后,可以自定义执行的动作
|
|
190
196
|
*/
|
|
191
|
-
declare const generateSeePackageZip: ({ system, type, name, appType, appName, group, version, configName, outputName, templateFunc, variablesFunc, copyFiles, description, seePackageName, seePackagePath, seePackageType, dockerImage, scriptsType, tplPath }: DeployOptions, cb: () => void) => void;
|
|
197
|
+
declare const generateSeePackageZip: ({ system, type, name, appType, appName, group, version, configName, outputName, templateFunc, variablesFunc, copyFiles, description, seePackageName, seePackagePath, seePackageType, dockerImage, scriptsType, enableObfuscation, tplPath }: DeployOptions, cb: () => void) => void;
|
|
192
198
|
|
|
193
199
|
export { generateSeePackageZip };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/** build time:
|
|
2
|
-
var
|
|
3
|
-
`)}else if(t==="switchForm"||t==="division"){let
|
|
4
|
-
`):""}else{if(t==="complexSelect")return
|
|
5
|
-
`),description
|
|
6
|
-
`),description
|
|
7
|
-
`),
|
|
1
|
+
/** build time: Thu Jul 30 2026 10:40:12 GMT+0800 (中国标准时间), build version 4.3.8 **/
|
|
2
|
+
var fe=Object.defineProperty;var q=Object.getOwnPropertySymbols;var pe=Object.prototype.hasOwnProperty,me=Object.prototype.propertyIsEnumerable;var B=(i,t,n)=>t in i?fe(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n,K=(i,t)=>{for(var n in t||(t={}))pe.call(t,n)&&B(i,n,t[n]);if(q)for(var n of q(t))me.call(t,n)&&B(i,n,t[n]);return i};var W=(i=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(i,{get:(t,n)=>(typeof require!="undefined"?require:t)[n]}):i)(function(i){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});import he from"chalk";import xe from"path";import k from"fs-extra";import $e from"path";import b from"fs-extra";import{rimraf as re}from"rimraf";import z from"path";import L from"fs-extra";import ue from"archiver";import G from"xml";var J=process.cwd(),Q=function(t){let n={""":'"',"'":"'","<":"<",">":">"},r=/(")|(')|(<)|(>)/g;return t&&t.replace?t.replace(r,function(c){return n[c]}):t},j=function(t,n){let r=n||"",c=z.resolve(J,t,r,"sysconfig.js");return L.pathExistsSync(c)},E=function(t){let n=z.resolve(J,t,"config.local.js");return L.pathExistsSync(n)},N=function(t,n,r,c){let o=z.join(J,n);n!=="/"&&L.ensureDirSync(o);let e=L.createWriteStream(`${n==="/"?".":o}/${t}.zip`);e.on("close",function(){setTimeout(function(){c&&c()})});let l=ue("zip",{zlib:{level:9}});l.on("error",function(s){console.error(),console.error(s.stack||s),s.details&&console.error(s.details)}),l.pipe(e),l.directory(r,!1),l.finalize()},C=function(t,n,r){let{type:c,label:o,name:e,tooltip:l="",visible:s="true",required:a="false",fixed:$="false",fold:f="false",options:m="",validate:d="",upgrade:p="false"}=t,A=t.default;if(r==="form"){let O=G({form:[{_attr:{name:e,tooltip:l,visible:s,required:a,fixed:$,fold:f,options:m,validate:d,upgrade:p}},n]});return Q(O)}let y=c==="complexSelect"?{default:t.default}:{},g=G({field:[{_attr:K({type:c,label:o,name:e,tooltip:l,visible:s,required:a,fixed:$,fold:f,options:m,validate:d,upgrade:p},y)},n||A]});return Q(g)},H=function(t){let r=t.children.map(c=>{let e=c.children.map(l=>C(l)).join("");return C(c,e,"form")}).join("");return C(t,r)},U=function i(t,n,r="",c=""){for(let o=0;o<t.length;o++){let e=t[o];if(e.type==="complexSelect"?(e.fullName=`${e.name}`,e.fullPath=`${e.type}`):(e.fullName=`${r===""?"":r+"."}${e.name}`,e.fullPath=`${c===""?"":c+"-"}${e.type}`),n(e))return e;if(e.children&&e.children.length>0){let l=i(e.children,n,e.fullName,e.fullPath);if(l)return l}}return null};function Y(i="python"){return i==="python"?"py":"sh"}import M from"fs-extra";import ye from"path";import R from"lodash.template";import ge from"xml";import de from"@babel/core";var Se=["input","editor","select","switch","smallfile","table","mselect","switchForm","complexSelect","division","password","hidden"],X=i=>ye.resolve(__dirname,`../templates/see/${i}`),V=i=>{let t=i.type;if(!Se.includes(t))return"";let{label:n,name:r,tooltip:c="",visible:o="true",required:e="false",fixed:l="false",fold:s="false",options:a="",validate:$="",upgrade:f="false",expose:m="",algorithm:d="",merge:p="",isomeris:A="",old_name:y=""}=i,g=i.default;if(t==="table"){let u=i.keys||[];g=(i.columns||u).map(x=>V(x)).join(`
|
|
3
|
+
`)}else if(t==="switchForm"||t==="division"){let u=i.children;g=u?u.map(h=>V(h)).join(`
|
|
4
|
+
`):""}else{if(t==="complexSelect")return H(i);t==="editor"?g=typeof g=="object"?[JSON.stringify(g)]:[g]:g=[g]}let O=t==="switchForm"?{default:i.default}:{},P=K({type:t,label:n,name:r,tooltip:c,visible:o,required:e,fixed:l,fold:s,options:a,validate:$,upgrade:f,expose:m,algorithm:d,merge:p,isomeris:A,old_name:y},O),v=Object.fromEntries(Object.entries(P).filter(([u,h])=>h!==""&&h!==null&&h!==void 0)),F=ge({field:[{_attr:v},...Array.isArray(g)?g:[g]]});return Q(F)},ee=function({system:t,type:n,name:r,appType:c,appName:o,group:e,version:l,configFileName:s="config.local",variables:a=[],description:$,scriptsType:f="python"}){let m=M.readFileSync(X(`${f}/deploy.xml`)).toString();return R(m,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:n,name:r,appName:o,appType:c,group:e,version:l,configFileName:s,variables:a.map(d=>V(d)).join(`
|
|
5
|
+
`),description:$})},I=function(t,n){let r=`${n.scriptsType}/scripts/${t}.${n.scriptsType==="python"?"py":"sh"}`;t==="beforeInstall"&&(r=`${n.scriptsType}/scripts/${t}.sh`);let c=M.readFileSync(X(r)).toString();return R(c,{interpolate:/{{([\s\S]+?)}}/g})(n)},D=function(t,n=[]){let{code:r}=de.transformFileSync(t,{babelrc:!1,plugins:[function(){return{visitor:{Literal(o){if(o.parentPath.isProperty()){let e=o.parentPath.get("key").node,l=e.name;e.type==="StringLiteral"&&(e.type="Identifier",e.name=e.value,l=e.value);let s=U(n,a=>l===a.name);if(s){if(s.fullPath.includes("complexSelect")&&(s.name=s.fullName),o.isStringLiteral()){o.node.value=`$!{${s.name}}`;return}if(o.isNumericLiteral()){o.node.value=`$!{${s.name}}`;return}if(o.isBooleanLiteral()){if(o.node.type="StringLiteral",s.fullPath.includes("complexSelect")){o.node.value=`$!{${s.fullName}}`;return}o.node.value=`[NO_QUOTATION_MARKS]\${${s.name}}[NO_QUOTATION_MARKS]`}}}},ArrayExpression(o){if(o.parentPath.isProperty()){let e=U(n,l=>o.parentPath.get("key").node.name===l.name);if(e){if(e.fullPath.includes("editor")){o.node.type="StringLiteral",o.node.value=`[NO_QUOTATION_MARKS]\${${e.name}}[NO_QUOTATION_MARKS]`;return}e.fullPath.includes("complexSelect")&&(e.name=e.fullName);let l="",s=e.keys||[],a=e.columns||s;if(e.options){l=`[NO_QUOTATION_MARKS][#foreach($row in $${e.name}) '$row' , #end][NO_QUOTATION_MARKS]`,o.node.type="StringLiteral",o.node.value=l;return}a&&a.length&&a.forEach(f=>{l+=`${f.name}: '$!{row.${f.name}}',`}),o.node.type="StringLiteral",o.node.value=`[NO_QUOTATION_MARKS][#foreach($row in $${e.name}) {${l}}, #end][NO_QUOTATION_MARKS]`}}},ObjectExpression(o){if(o.parentPath.isProperty()){let e=o.parentPath.get("key").node,l=e.name;if(e){let s=U(n,a=>l===a.name);if(s){if(o.node.type="StringLiteral",s.fullPath.includes("editor")){o.node.value=`[NO_QUOTATION_MARKS]\${${s.name}}[NO_QUOTATION_MARKS]`;return}o.node.value=`[NO_QUOTATION_MARKS]\${${s.name}}[NO_QUOTATION_MARKS]`;return}}}}}}}],retainLines:!0});return r.replace(/"\[NO_QUOTATION_MARKS](.*)\[NO_QUOTATION_MARKS]"/g,"$1")},te=function({system:t,type:n,name:r,appName:c,appType:o,version:e,group:l,configFileName:s="config.local",variables:a=[],description:$,web_app_web_service_name:f,dockerImage:m}){let d=M.readFileSync(X("docker/deploy.xml")).toString();return R(d,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:n,name:r,appName:c,appType:o,version:e,group:l,configFileName:s,variables:a.map(p=>V(p)).join(`
|
|
6
|
+
`),description:$,web_app_web_service_name:f,dockerImage:m})},ne=function(t){let n=M.readFileSync(X("docker/k8s-deploy-res.yaml")).toString();return R(n,{interpolate:/{{([\s\S]+?)}}/g})(t)},oe=function(t){let n=M.readFileSync(X("docker/Dockerfile")).toString();return R(n)(t)};var S="tmp",ie=function(t,n,r){let{system:c,type:o,name:e,appType:l,appName:s,group:a,version:$,template:f,variables:m=[],configName:d,outputName:p="dist",description:A,scriptsType:y,enableObfuscation:g=!1,seePackagePath:O,tplPath:P}=n;b.ensureDirSync(S),b.ensureDirSync(`${S}/scripts`),b.ensureDirSync(`${S}/template`);let v=!1,F=!1;if(P&&Object.keys(P).length>0)for(let[x,w]of Object.entries(P))x==="deploy.xml"?(b.copyFileSync(w,`./${S}/deploy.xml`),v=!0):b.copyFileSync(w,`./${S}/template/${x}`),(x==="sysconfig.js"||x==="config.local.js")&&(F=!0);let u=d;if(F&&P?P["sysconfig.js"]?u="sysconfig":P["config.local.js"]&&(u="config.local"):F||(E(p)?u="config.local":(j(p)||j(p,e))&&(u="sysconfig")),g&&(y==="bash"||y==="python")){let x=$e.resolve(__dirname,`../templates/see/${y}/scripts/js`);b.pathExistsSync(x)&&b.copySync(x,`./${S}/scripts/${e}/js`)}let h=Y(y);y==="python"&&(b.outputFileSync(`./${S}/scripts/${e}/utils.${h}`,I("utils",{scriptsType:y})),b.outputFileSync(`./${S}/scripts/${e}/beforeInstall.sh`,I("beforeInstall",{scriptsType:y}))),b.outputFileSync(`./${S}/scripts/${e}/install.${h}`,I("install",{name:e,type:o,scriptsType:y})),b.outputFileSync(`./${S}/scripts/${e}/afterInstall.${h}`,I("afterInstall",{name:e,scriptsType:y,configFileName:u,enableObfuscation:g})),b.outputFileSync(`./${S}/scripts/${e}/uninstall.${h}`,I("uninstall",{name:e,type:o,scriptsType:y})),v||b.outputFileSync(`./${S}/deploy.xml`,ee({system:c,type:o,name:e,appType:l,appName:s,group:a,version:$,configFileName:u,variables:m,description:A,scriptsType:y})),F||(E(p)?b.outputFileSync(`./${S}/template/config.local.js`,f?D(f,m):""):j(p)||j(p,e)?b.outputFileSync(`./${S}/template/sysconfig.js`,f?D(f,m):""):u&&b.outputFileSync(`./${S}/template/${u}.js`,f?D(f,m):"")),r?r(x=>{N(t,O,S,()=>{re.sync(S),typeof x=="function"&&x()})}):N(t,O,S,()=>{re.sync(S)})};import le from"path";import _ from"fs-extra";import{rimraf as se}from"rimraf";var T="tmp",ce=function(t,n,r){let{system:c,type:o,name:e,appType:l,appName:s,version:a,group:$,template:f,variables:m,configName:d,outputName:p,description:A,seePackagePath:y,dockerImage:g=a.indexOf("-")>0?`isee1.0-docker-dev-local/${e}`:`isee1.0-docker-release-local/${e}`}=n;_.ensureDirSync(T),_.ensureDirSync("docker"),_.pathExistsSync(le.resolve(process.cwd(),"docker/Dockerfile"))||_.outputFileSync(le.resolve(process.cwd(),"docker/Dockerfile"),oe({name:e,type:o})),_.ensureDirSync(`${T}/scripts`),_.ensureDirSync(`${T}/template`),E(p)?_.outputFileSync(`./${T}/template/${e}/config.local.js`,f?D(f,m):""):j(p)||j(p,e)?(d="sysconfig",_.outputFileSync(`./${T}/template/${e}/sysconfig.js`,f?D(f,m):"")):d&&_.outputFileSync(`./${T}/template/${e}/${d}.js`,f?D(f,m):""),_.outputFileSync(`./${T}/template/k8s-deploy-res.yaml`,ne({configFileName:d})),_.outputFileSync(`./${T}/deploy.xml`,te({system:c,type:o,name:e,appName:s,appType:l,version:a,group:$,configFileName:d,variables:m,description:A,web_app_web_service_name:`${e}-web`,dockerImage:g})),r?r(O=>{N(t,y,T,()=>{se.sync(T),typeof O=="function"&&O()})}):N(t,y,T,()=>{se.sync(T)})};var be=process.cwd();function Oe(i,t,n){let r="",c,o=i==="bizframe"?`./${n}`:`./${n}/${t}`;return k.existsSync(o)&&(r=k.readdirSync(o).find(e=>/manifest\.[0-9]+\.json/.test(e)),r&&(c=k.readJsonSync(`${o}/${r}`))),{manifest:r,manifestJson:c}}var tt=function({system:t="winner-front",type:n="bizframe",name:r,appType:c,appName:o,group:e="bizframe",version:l,configName:s="config.local",outputName:a="dist",templateFunc:$,variablesFunc:f,copyFiles:m,description:d,seePackageName:p,seePackagePath:A="package",seePackageType:y="web",dockerImage:g,scriptsType:O="python",enableObfuscation:P=!1,tplPath:v={}},F){if(!r||!l)throw new Error("\u5E94\u7528\u540D\u79F0\u548C\u5E94\u7528\u7248\u672C\u4E0D\u80FD\u7F3A\u5931~");if(r=r.replace(/@/gi,"").replace(/\//gi,"-"),typeof p=="string"&&p&&(p=p.replace(/@/gi,"").replace(/\//gi,"-")),c=c||r,o=o||r,f=f||function(){try{let{variables:u}=W(xe.resolve(be,"build","package","./variables.js"));return u||[]}catch(u){return console.error(u),[]}},$=$||function(){return n==="bizframe"?`./${a}/config.local.js`:`./${a}/${r}/sysconfig.js`},y==="docker"){ce(p||`${t}-${r}-${l}`,{system:t,type:n,name:r,appType:c,appName:o,group:e,version:l,configName:s,outputName:a,template:$(),variables:f(),seePackagePath:A,description:d,dockerImage:g},u=>{console.log(),console.log("docker \u5BB9\u5668\u5316\u90E8\u7F72\u7684 SEE \u53D1\u5E03\u7269\u5236\u4F5C\u5B8C\u6210\uFF0C\u60A8\u53EF\u4EE5\u5728 SEE \u5E73\u53F0\u4E0A\u4F20\u5E76\u90E8\u7F72\u5E94\u7528\u3002"),u(F)});return}ie(p||`${t}-${r}-${l}`,{system:t,type:n,name:r,group:e,appType:c,appName:o,version:l,configName:s,outputName:a,template:$(),variables:f(),seePackagePath:A,description:d,scriptsType:O,enableObfuscation:P,tplPath:v},u=>{if(O==="python"){let{manifest:h,manifestJson:x}=Oe(n,r,a);if(h){for(let w in x)if(x.hasOwnProperty(w)){let{path:Z,dir:ae}=x[w];k.ensureDirSync(`./tmp/source/${ae}`),k.copyFileSync(`./${a}/${Z}`,`./tmp/source/${Z}`)}k.outputJSONSync(`./tmp/scripts/${r}/conf/${h}`,x)}else k.ensureDirSync("./tmp/source"),k.copySync(`./${a}`,"./tmp/source")}else k.ensureDirSync("./tmp/source"),k.copySync(`./${a}`,"./tmp/source");Array.isArray(m)&&m.length&&m.forEach(h=>{k.ensureFileSync(`./tmp/source/${r}/${h}`),k.copyFileSync(`./${a}/${r}/${h}`,`./tmp/source/${r}/${h}`)}),console.log(),console.log(`\u53D1\u5E03\u7269\u5236\u4F5C\u5B8C\u6210\uFF0C\u60A8\u53EF\u4EE5\u5728 SEE \u5E73\u53F0\u4E0A\u4F20\u5E76\u90E8\u7F72\u5E94\u7528\u3002\u6CE8\u610F\uFF1A${he.yellow("\u5B50\u7CFB\u7EDF\u53D1\u5E03\u7269\u7684\u5B89\u88C5\u76EE\u5F55\u9700\u8981\u6307\u5B9A\u5230\u5177\u4F53\u7684\u5E94\u7528\u76EE\u5F55")}\u3002\u6BD4\u5982/home/hsiar/hsiar-green/html/\u3002
|
|
7
|
+
`),u(F)})};export{tt as generateSeePackageZip};
|
package/package.json
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
+
# 定义图标
|
|
3
|
+
CHECK_ICON="✅"
|
|
4
|
+
ERROR_ICON="❌"
|
|
5
|
+
INFO_ICON="ℹ️"
|
|
6
|
+
WARNING_ICON="⚠️"
|
|
7
|
+
|
|
2
8
|
wk=`pwd`
|
|
3
9
|
chmod -R 755 $wk/${webAppName}
|
|
10
|
+
|
|
11
|
+
echo -e "${INFO_ICON} 开始执行安装后检查,应用: '${webAppName}'..."
|
|
12
|
+
|
|
13
|
+
# 1. 检查应用的主目录是否存在。
|
|
14
|
+
# -d 表示检查目标是否为一个目录。
|
|
15
|
+
if [ ! -d "${webAppName}" ]; then
|
|
16
|
+
echo -e "${ERROR_ICON} 错误: 安装检查失败。应用目录 '${webAppName}' 不存在。" >&2
|
|
17
|
+
exit 1
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
# 2. 检查目录是否为空。
|
|
21
|
+
# ls -A 会列出除 . 和 .. 之外的所有条目。
|
|
22
|
+
# -z 会检查命令输出的字符串是否为空。
|
|
23
|
+
if [ -z "$(ls -A "${webAppName}")" ]; then
|
|
24
|
+
echo -e "${ERROR_ICON} 错误: 安装检查失败。应用目录 '${webAppName}' 存在但为空。" >&2
|
|
25
|
+
exit 1
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
echo -e "${CHECK_ICON} 成功: 应用目录 '${webAppName}' 已找到且不为空。"
|
|
29
|
+
echo -e "${CHECK_ICON} 安装验证通过。"
|
|
30
|
+
|
|
31
|
+
<% if (enableObfuscation) { %>
|
|
32
|
+
# 混淆配置文件:优先 node(javascript-obfuscator),无 node 时回退 bash 轻量混淆
|
|
33
|
+
echo -e "${CHECK_ICON} 开始混淆配置文件..."
|
|
34
|
+
pkg_root=`pwd`
|
|
35
|
+
cd "$(dirname "$0")"
|
|
36
|
+
if command -v node >/dev/null 2>&1; then
|
|
37
|
+
echo -e "${INFO_ICON} 检测到 node,使用 confuse.js 强混淆"
|
|
38
|
+
node ./js/confuse.js "${webAppName}" "{{configFileName}}" "$pkg_root"
|
|
39
|
+
else
|
|
40
|
+
echo -e "${WARNING_ICON} 未检测到 node,使用 confuse.sh 轻量混淆(强度较弱)"
|
|
41
|
+
bash ./js/confuse.sh "${webAppName}" "{{configFileName}}" "$pkg_root"
|
|
42
|
+
fi
|
|
43
|
+
if [ $? -ne 0 ]; then
|
|
44
|
+
echo -e "${ERROR_ICON} 错误: 混淆配置文件失败。" >&2
|
|
45
|
+
exit 1
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
echo -e "${CHECK_ICON} 成功: 混淆配置文件完成。"
|
|
49
|
+
<% } %>
|
|
50
|
+
|
|
51
|
+
exit 0
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const JavaScriptObfuscator = require('./obfuscator')
|
|
4
|
+
try {
|
|
5
|
+
const webAppName = process.argv[2] || process.env.WEB_APP_NAME
|
|
6
|
+
const configBase = process.argv[3] || process.env.CONFIG_FILE_NAME || 'sysconfig'
|
|
7
|
+
const pkgRoot = process.argv[4] ? path.resolve(process.argv[4]) : path.resolve(__dirname, '..', '..')
|
|
8
|
+
if (!webAppName) {
|
|
9
|
+
console.error('缺少前端应用目录名:请传入第 1 个参数或设置环境变量 WEB_APP_NAME')
|
|
10
|
+
process.exit(1)
|
|
11
|
+
}
|
|
12
|
+
const filepath = path.join(pkgRoot, webAppName, `${configBase}.js`)
|
|
13
|
+
console.log(`__filename:${__filename}`)
|
|
14
|
+
console.log(`文件路径:${filepath}`)
|
|
15
|
+
if (!fs.existsSync(filepath)) {
|
|
16
|
+
console.error(`文件不存在: ${filepath}`)
|
|
17
|
+
process.exit(1)
|
|
18
|
+
}
|
|
19
|
+
const sourceCode = fs.readFileSync(filepath, 'utf8')
|
|
20
|
+
const obfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
21
|
+
sourceCode,
|
|
22
|
+
{
|
|
23
|
+
compact: true,
|
|
24
|
+
controlFlowFlattening: true,
|
|
25
|
+
controlFlowFlatteningThreshold: 0.75,
|
|
26
|
+
deadCodeInjection: true,
|
|
27
|
+
deadCodeInjectionThreshold: 0.5,
|
|
28
|
+
numbersToExpressions: true,
|
|
29
|
+
simplify: true,
|
|
30
|
+
selfDefending: true,
|
|
31
|
+
shuffleStringArray: true,
|
|
32
|
+
splitStrings: true,
|
|
33
|
+
stringArrayThreshold: 0.75,
|
|
34
|
+
unicodeEscapeSequence: true
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
fs.writeFileSync(filepath, obfuscationResult.getObfuscatedCode())
|
|
38
|
+
console.log('代码混淆完成,并已更新成功')
|
|
39
|
+
console.log(`更新路径:${filepath}`)
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.error(e)
|
|
42
|
+
process.exit(1)
|
|
43
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# 无 node 时的轻量混淆:整文件 base64 + atob/eval 包裹。
|
|
3
|
+
# 强度远低于 confuse.js(javascript-obfuscator),仅作兼容兜底。
|
|
4
|
+
# 参数:webAppName configBase [pkgRoot]
|
|
5
|
+
|
|
6
|
+
ERROR_ICON="❌"
|
|
7
|
+
INFO_ICON="ℹ️"
|
|
8
|
+
CHECK_ICON="✅"
|
|
9
|
+
|
|
10
|
+
webAppName="${1:-${WEB_APP_NAME}}"
|
|
11
|
+
configBase="${2:-${CONFIG_FILE_NAME:-sysconfig}}"
|
|
12
|
+
pkgRoot="${3:-}"
|
|
13
|
+
|
|
14
|
+
if [ -z "$pkgRoot" ]; then
|
|
15
|
+
pkgRoot="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
if [ -z "$webAppName" ]; then
|
|
19
|
+
echo -e "${ERROR_ICON} 缺少前端应用目录名:请传入第 1 个参数或设置 WEB_APP_NAME" >&2
|
|
20
|
+
exit 1
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
filepath="${pkgRoot}/${webAppName}/${configBase}.js"
|
|
24
|
+
echo -e "${INFO_ICON} 文件路径:${filepath}"
|
|
25
|
+
|
|
26
|
+
if [ ! -f "$filepath" ]; then
|
|
27
|
+
echo -e "${ERROR_ICON} 文件不存在: ${filepath}" >&2
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
# 已混淆过则跳过,避免重复包裹
|
|
32
|
+
if grep -q '__WINNER_BASH_OBFUSCATED__' "$filepath" 2>/dev/null; then
|
|
33
|
+
echo -e "${CHECK_ICON} 配置文件已混淆,跳过"
|
|
34
|
+
exit 0
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
b64=$(base64 < "$filepath" | tr -d '\n\r')
|
|
38
|
+
if [ -z "$b64" ]; then
|
|
39
|
+
echo -e "${ERROR_ICON} base64 编码失败" >&2
|
|
40
|
+
exit 1
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
tmpfile="${filepath}.obf.$$"
|
|
44
|
+
cat > "$tmpfile" <<EOF
|
|
45
|
+
/* __WINNER_BASH_OBFUSCATED__ */
|
|
46
|
+
(function(_0x){eval(atob(_0x))})('${b64}');
|
|
47
|
+
EOF
|
|
48
|
+
|
|
49
|
+
if [ $? -ne 0 ]; then
|
|
50
|
+
rm -f "$tmpfile"
|
|
51
|
+
echo -e "${ERROR_ICON} 写入临时文件失败" >&2
|
|
52
|
+
exit 1
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
mv "$tmpfile" "$filepath"
|
|
56
|
+
echo -e "${CHECK_ICON} bash 轻量混淆完成"
|
|
57
|
+
echo -e "${INFO_ICON} 更新路径:${filepath}"
|
|
58
|
+
exit 0
|