@winner-fed/winner-deploy
Version:
Generate a publication deployed by the See platform
8 lines (7 loc) • 12.6 kB
JavaScript
/** build time: Thu Jul 24 2025 16:55:53 GMT+0800 (中国标准时间), build version 4.3.5 **/
var ae=Object.defineProperty;var Z=Object.getOwnPropertySymbols;var pe=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var q=(i,t,n)=>t in i?ae(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n,E=(i,t)=>{for(var n in t||(t={}))pe.call(t,n)&&q(i,n,t[n]);if(Z)for(var n of Z(t))fe.call(t,n)&&q(i,n,t[n]);return i};var B=(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 Se from"chalk";import $e from"path";import A from"fs-extra";import O from"fs-extra";import{rimraf as re}from"rimraf";import C from"path";import X from"fs-extra";import me from"archiver";import W from"xml";var z=process.cwd(),K=function(t){let n={""":'"',"'":"'","<":"<",">":">"},o=/(")|(')|(<)|(>)/g;return t&&t.replace?t.replace(o,function(c){return n[c]}):t},D=function(t,n){let o=n||"",c=C.resolve(z,t,o,"sysconfig.js");return X.pathExistsSync(c)},L=function(t){let n=C.resolve(z,t,"config.local.js");return X.pathExistsSync(n)},v=function(t,n,o,c){let r=C.join(z,n);n!=="/"&&X.ensureDirSync(r);let e=X.createWriteStream(`${n==="/"?".":r}/${t}.zip`);e.on("close",function(){setTimeout(function(){c&&c()})});let l=me("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(o,!1),l.finalize()},V=function(t,n,o){let{type:c,label:r,name:e,tooltip:l="",visible:s="true",required:a="false",fixed:g="false",fold:p="false",options:f="",validate:m="",upgrade:u="false"}=t,_=t.default;if(o==="form"){let x=W({form:[{_attr:{name:e,tooltip:l,visible:s,required:a,fixed:g,fold:p,options:f,validate:m,upgrade:u}},n]});return K(x)}let $=c==="complexSelect"?{default:t.default}:{},y=W({field:[{_attr:E({type:c,label:r,name:e,tooltip:l,visible:s,required:a,fixed:g,fold:p,options:f,validate:m,upgrade:u},$)},n||_]});return K(y)},G=function(t){let o=t.children.map(c=>{let e=c.children.map(l=>V(l)).join("");return V(c,e,"form")}).join("");return V(t,o)},Q=function i(t,n,o="",c=""){for(let r=0;r<t.length;r++){let e=t[r];if(e.type==="complexSelect"?(e.fullName=`${e.name}`,e.fullPath=`${e.type}`):(e.fullName=`${o===""?"":o+"."}${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 H(i="python"){return i==="python"?"py":"sh"}import N from"fs-extra";import ue from"path";import w from"lodash.template";import ye from"xml";import de from"@babel/core";var ge=["input","editor","select","switch","smallfile","table","mselect","switchForm","complexSelect","division","password","hidden"],I=i=>ue.resolve(__dirname,`../templates/see/${i}`),U=i=>{let t=i.type;if(!ge.includes(t))return"";let{label:n,name:o,tooltip:c="",visible:r="true",required:e="false",fixed:l="false",fold:s="false",options:a="",validate:g="",upgrade:p="false",expose:f="",algorithm:m="",merge:u="",isomeris:_="",old_name:$=""}=i,y=i.default;if(t==="table"){let d=i.keys||[];y=(i.columns||d).map(R=>U(R)).join(`
`)}else if(t==="switchForm"||t==="division"){let d=i.children;y=d?d.map(h=>U(h)).join(`
`):""}else{if(t==="complexSelect")return G(i);t==="editor"?y=typeof y=="object"?[JSON.stringify(y)]:[y]:y=[y]}let x=t==="switchForm"?{default:i.default}:{},P=E({type:t,label:n,name:o,tooltip:c,visible:r,required:e,fixed:l,fold:s,options:a,validate:g,upgrade:p,expose:f,algorithm:m,merge:u,isomeris:_,old_name:$},x),j=Object.fromEntries(Object.entries(P).filter(([d,h])=>h!==""&&h!==null&&h!==void 0)),b=ye({field:[{_attr:j},...Array.isArray(y)?y:[y]]});return K(b)},Y=function({system:t,type:n,name:o,appType:c,appName:r,group:e,version:l,configFileName:s="config.local",variables:a=[],description:g,scriptsType:p="python"}){let f=N.readFileSync(I(`${p}/deploy.xml`)).toString();return w(f,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:n,name:o,appName:r,appType:c,group:e,version:l,configFileName:s,variables:a.map(m=>U(m)).join(`
`),description:g})},M=function(t,n){let o=N.readFileSync(I(`${n.scriptsType}/scripts/${t}.${n.scriptsType==="python"?"py":"sh"}`)).toString();return w(o,{interpolate:/{{([\s\S]+?)}}/g})(n)},F=function(t,n=[]){let{code:o}=de.transformFileSync(t,{babelrc:!1,plugins:[function(){return{visitor:{Literal(r){if(r.parentPath.isProperty()){let e=r.parentPath.get("key").node,l=e.name;e.type==="StringLiteral"&&(e.type="Identifier",e.name=e.value,l=e.value);let s=Q(n,a=>l===a.name);if(s){if(s.fullPath.includes("complexSelect")&&(s.name=s.fullName),r.isStringLiteral()){r.node.value=`$!{${s.name}}`;return}if(r.isNumericLiteral()){r.node.value=`$!{${s.name}}`;return}if(r.isBooleanLiteral()){if(r.node.type="StringLiteral",s.fullPath.includes("complexSelect")){r.node.value=`$!{${s.fullName}}`;return}r.node.value=`[NO_QUOTATION_MARKS]\${${s.name}}[NO_QUOTATION_MARKS]`}}}},ArrayExpression(r){if(r.parentPath.isProperty()){let e=Q(n,l=>r.parentPath.get("key").node.name===l.name);if(e){if(e.fullPath.includes("editor")){r.node.type="StringLiteral",r.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]`,r.node.type="StringLiteral",r.node.value=l;return}a&&a.length&&a.forEach(p=>{l+=`${p.name}: '$!{row.${p.name}}',`}),r.node.type="StringLiteral",r.node.value=`[NO_QUOTATION_MARKS][#foreach($row in $${e.name}) {${l}}, #end][NO_QUOTATION_MARKS]`}}},ObjectExpression(r){if(r.parentPath.isProperty()){let e=r.parentPath.get("key").node,l=e.name;if(e){let s=Q(n,a=>l===a.name);if(s){if(r.node.type="StringLiteral",s.fullPath.includes("editor")){r.node.value=`[NO_QUOTATION_MARKS]\${${s.name}}[NO_QUOTATION_MARKS]`;return}r.node.value=`[NO_QUOTATION_MARKS]\${${s.name}}[NO_QUOTATION_MARKS]`;return}}}}}}}],retainLines:!0});return o.replace(/"\[NO_QUOTATION_MARKS](.*)\[NO_QUOTATION_MARKS]"/g,"$1")},ee=function({system:t,type:n,name:o,appName:c,appType:r,version:e,group:l,configFileName:s="config.local",variables:a=[],description:g,web_app_web_service_name:p,dockerImage:f}){let m=N.readFileSync(I("docker/deploy.xml")).toString();return w(m,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:n,name:o,appName:c,appType:r,version:e,group:l,configFileName:s,variables:a.map(u=>U(u)).join(`
`),description:g,web_app_web_service_name:p,dockerImage:f})},te=function(t){let n=N.readFileSync(I("docker/k8s-deploy-res.yaml")).toString();return w(n,{interpolate:/{{([\s\S]+?)}}/g})(t)},ne=function(t){let n=N.readFileSync(I("docker/Dockerfile")).toString();return w(n)(t)};var S="tmp",oe=function(t,n,o){let{system:c,type:r,name:e,appType:l,appName:s,group:a,version:g,template:p,variables:f=[],configName:m,outputName:u="dist",description:_,scriptsType:$,seePackagePath:y,tplPath:x}=n;O.ensureDirSync(S),O.ensureDirSync(`${S}/scripts`),O.ensureDirSync(`${S}/template`);let P=H($);$==="python"&&O.outputFileSync(`./${S}/scripts/${e}/utils.${P}`,M("utils",{scriptsType:$})),O.outputFileSync(`./${S}/scripts/${e}/install.${P}`,M("install",{name:e,type:r,scriptsType:$})),O.outputFileSync(`./${S}/scripts/${e}/afterInstall.${P}`,M("afterInstall",{name:e,scriptsType:$})),O.outputFileSync(`./${S}/scripts/${e}/uninstall.${P}`,M("uninstall",{name:e,type:r,scriptsType:$}));let j=!1,b=!1;if(x&&Object.keys(x).length>0)for(let[d,h]of Object.entries(x))d==="deploy.xml"?(O.copyFileSync(h,`./${S}/deploy.xml`),j=!0):O.copyFileSync(h,`./${S}/template/${d}`),(d==="sysconfig.js"||d==="config.local.js")&&(b=!0);j||O.outputFileSync(`./${S}/deploy.xml`,Y({system:c,type:r,name:e,appType:l,appName:s,group:a,version:g,configFileName:m,variables:f,description:_,scriptsType:$})),b||(L(u)?O.outputFileSync(`./${S}/template/config.local.js`,p?F(p,f):""):D(u)||D(u,e)?(m="sysconfig",O.outputFileSync(`./${S}/template/sysconfig.js`,p?F(p,f):"")):m&&O.outputFileSync(`./${S}/template/${m}.js`,p?F(p,f):"")),o?o(d=>{v(t,y,S,()=>{re.sync(S),typeof d=="function"&&d()})}):v(t,y,S,()=>{re.sync(S)})};import ie from"path";import k from"fs-extra";import{rimraf as le}from"rimraf";var T="tmp",se=function(t,n,o){let{system:c,type:r,name:e,appType:l,appName:s,version:a,group:g,template:p,variables:f,configName:m,outputName:u,description:_,seePackagePath:$,dockerImage:y=a.indexOf("-")>0?`isee1.0-docker-dev-local/${e}`:`isee1.0-docker-release-local/${e}`}=n;k.ensureDirSync(T),k.ensureDirSync("docker"),k.pathExistsSync(ie.resolve(process.cwd(),"docker/Dockerfile"))||k.outputFileSync(ie.resolve(process.cwd(),"docker/Dockerfile"),ne({name:e,type:r})),k.ensureDirSync(`${T}/scripts`),k.ensureDirSync(`${T}/template`),L(u)?k.outputFileSync(`./${T}/template/${e}/config.local.js`,p?F(p,f):""):D(u)||D(u,e)?(m="sysconfig",k.outputFileSync(`./${T}/template/${e}/sysconfig.js`,p?F(p,f):"")):m&&k.outputFileSync(`./${T}/template/${e}/${m}.js`,p?F(p,f):""),k.outputFileSync(`./${T}/template/k8s-deploy-res.yaml`,te({configFileName:m})),k.outputFileSync(`./${T}/deploy.xml`,ee({system:c,type:r,name:e,appName:s,appType:l,version:a,group:g,configFileName:m,variables:f,description:_,web_app_web_service_name:`${e}-web`,dockerImage:y})),o?o(x=>{v(t,$,T,()=>{le.sync(T),typeof x=="function"&&x()})}):v(t,$,T,()=>{le.sync(T)})};var he=process.cwd();function xe(i,t,n){let o="",c;if(i==="bizframe"){o=A.readdirSync(`./${n}`).find(r=>/manifest\.[0-9]+\.json/.test(r));try{c=A.readJsonSync(`./${n}/${o}`)}catch(r){console.error(`${n} \u76EE\u5F55\u4E0B\u7684 manifest.xxx.json \u89E3\u6790\u5931\u8D25\uFF01\u8BF7\u786E\u8BA4\u6B64\u6587\u4EF6\u662F\u5426\u5B58\u5728\u3002\u6216\u53EF\u4EE5\u5C06 scriptsType \u8BBE\u7F6E\u4E3A bash \u8BD5\u8BD5\u770B\u3002`),process.exit(0)}}return i==="subsystem"&&(o=A.readdirSync(`./${n}/${t}`).find(r=>/manifest\.[0-9]+\.json/.test(r)),c=A.readJsonSync(`./${n}/${t}/${o}`)),{manifest:o,manifestJson:c}}var He=function({system:t="winner-front",type:n="bizframe",name:o,appType:c,appName:r,group:e="bizframe",version:l,configName:s="config.local",outputName:a="dist",templateFunc:g,variablesFunc:p,copyFiles:f,description:m,seePackageName:u,seePackagePath:_="package",seePackageType:$="web",dockerImage:y,scriptsType:x="python",tplPath:P={}},j){if(!o||!l)throw new Error("\u5E94\u7528\u540D\u79F0\u548C\u5E94\u7528\u7248\u672C\u4E0D\u80FD\u7F3A\u5931~");if(o=o.replace(/@/gi,"").replace(/\//gi,"-"),typeof u=="string"&&u&&(u=u.replace(/@/gi,"").replace(/\//gi,"-")),c=c||o,r=r||o,p=p||function(){try{let{variables:b}=B($e.resolve(he,"build","package","./variables.js"));return b||[]}catch(b){return console.error(b),[]}},g=g||function(){return n==="bizframe"?`./${a}/config.local.js`:`./${a}/${o}/sysconfig.js`},$==="docker"){se(u||`${t}-${o}-${l}`,{system:t,type:n,name:o,appType:c,appName:r,group:e,version:l,configName:s,outputName:a,template:g(),variables:p(),seePackagePath:_,description:m,dockerImage:y},b=>{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"),b(j)});return}oe(u||`${t}-${o}-${l}`,{system:t,type:n,name:o,group:e,appType:c,appName:r,version:l,configName:s,outputName:a,template:g(),variables:p(),seePackagePath:_,description:m,scriptsType:x,tplPath:P},b=>{if(x==="python"){let{manifest:d,manifestJson:h}=xe(n,o,a);for(let R in h)if(h.hasOwnProperty(R)){let{path:J,dir:ce}=h[R];A.ensureDirSync(`./tmp/source/${ce}`),A.copyFileSync(`./${a}/${J}`,`./tmp/source/${J}`)}A.outputJSONSync(`./tmp/scripts/${o}/conf/${d}`,h)}else A.ensureDirSync("./tmp/source"),A.copySync(`./${a}`,"./tmp/source");Array.isArray(f)&&f.length&&f.forEach(d=>{A.ensureFileSync(`./tmp/source/${o}/${d}`),A.copyFileSync(`./${a}/${o}/${d}`,`./tmp/source/${o}/${d}`)}),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${Se.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
`),b(j)})};export{He as generateSeePackageZip};