@winner-fed/winner-deploy
Version:
Generate a publication deployed by the See platform
8 lines (7 loc) • 12.9 kB
JavaScript
/** build time: Wed Apr 15 2026 10:38:51 GMT+0800 (中国标准时间), build version 4.3.7 **/
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(`
`)}else if(t==="switchForm"||t==="division"){let u=i.children;g=u?u.map(h=>V(h)).join(`
`):""}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(`
`),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(`
`),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
`),u(F)})};export{tt as generateSeePackageZip};