@winner-fed/winner-deploy 3.4.2 → 4.0.0

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 CHANGED
@@ -43,7 +43,7 @@
43
43
  * @param options.scriptsType 脚本类型 'python'(默认的) | 'bash'
44
44
  * @param cb {function} 回调函数,用于处理在组装 see 包后,可以自定义执行的动作
45
45
  */
46
- exports.generateSeePackageZip = function generateSeePackageZip({system, type, name, appType, version, configName, templateFunc, variablesFunc, copyFiles, description, seePackageType, dockerImage, scriptsType}, cb) {
46
+ export const generateSeePackageZip = function generateSeePackageZip({system, type, name, appType, version, configName, templateFunc, variablesFunc, copyFiles, description, seePackageType, dockerImage, scriptsType}, cb) {
47
47
  ...
48
48
  }
49
49
  ```
package/dist/index.cjs ADDED
@@ -0,0 +1,7 @@
1
+ var pe=Object.create;var I=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var de=i=>I(i,"__esModule",{value:!0});var ge=(i,t,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of me(t))!ye.call(i,n)&&n!=="default"&&I(i,n,{get:()=>t[n],enumerable:!(o=fe(t,n))||o.enumerable});return i},m=i=>ge(de(I(i!=null?pe(ue(i)):{},"default",i&&i.__esModule&&"default"in i?{get:()=>i.default,enumerable:!0}:{value:i,enumerable:!0})),i);var se=m(require("chalk")),ce=m(require("path")),Q=m(require("ora")),h=m(require("fs-extra"));var y=m(require("fs-extra")),V=m(require("rimraf"));var L=m(require("path")),Se=m(require("chalk")),$e=m(require("ora")),O=m(require("fs-extra")),J=m(require("archiver")),M=m(require("xml")),W=process.cwd();var Z=function(t){let o={"&amp;":"&","&quot;":'"',"&apos;":"'","&lt;":"<","&gt;":">"};return t&&t.replace?t.replace(/(&amp;)|(&quot;)|(&apos;)|(&lt;)|(&gt;)/g,function(n){return o[n]}):t},v=function(t){let o=t||"",n=L.default.resolve(W,"dist",o,"sysconfig.js");return O.default.pathExistsSync(n)},E=function(){let t=L.default.resolve(W,"dist","config.local.js");return O.default.pathExistsSync(t)},_=function(t,o,n){let c="package";O.default.ensureDirSync(c);let r=O.default.createWriteStream(`${c}/${t}.zip`);r.on("close",function(){setTimeout(function(){n&&n()})});let e=(0,J.default)("zip",{zlib:{level:9}});e.on("error",function(l){console.error(),console.error(l.stack||l),l.details&&console.error(l.details)}),e.pipe(r),e.directory(o,!1),e.finalize()},R=function(t,o,n){let{type:c,label:r,name:e,tooltip:l="",visible:a="true",required:s="false",fixed:p="false",fold:f="false",options:d=""}=t,x=t.default;if(n==="form"){let w=(0,M.default)({form:[{_attr:{name:e,tooltip:l,visible:a,required:s,fixed:p,fold:f,options:d}},o]});return exports.unEscapeForXML(w)}let g=(0,M.default)({field:[{_attr:{type:c,label:r,name:e,tooltip:l,visible:a,required:s,fixed:p,fold:f,options:d}},x||o]});return exports.unEscapeForXML(g)},q=function(t){let n=t.children.map(c=>{let e=c.children.map(l=>R(l)).join("");return R(c,e,"form")}).join("");return R(t,n)},K=function i(t,o,n="",c=""){for(let r=0;r<t.length;r++){let e=t[r];if(e.fullName=`${n===""?"":n+"."}${e.name}`,e.fullPath=`${c===""?"":c+"-"}${e.type}`,o(e))return e;if(e.children&&e.children.length>0){let l=i(e.children,o,e.fullName,e.fullPath);if(l)return l}}return null};var k=m(require("fs-extra")),H=m(require("path")),P=m(require("lodash.template")),Y=m(require("xml")),G=m(require("@babel/core"));var he=["input","select","switch","smallfile","table","mselect","switchForm","complexSelect","division"],F=i=>H.default.resolve(__dirname,`../templates/see/${i}`),N=i=>{let t=i.type;if(!he.includes(t))return"";let{label:o,name:n,tooltip:c="",visible:r="true",required:e="false",fixed:l="false",fold:a="false",options:s=""}=i,p=i.default;if(t==="table"){let d=i.keys||[];p=(i.columns||d).map(g=>N(g)).join(`
2
+ `)}else if(t==="switchForm"||t==="division")p=i.children.map(x=>N(x)).join(`
3
+ `);else{if(t==="complexSelect")return q(i);p=[p]}let f=(0,Y.default)({field:[{_attr:{type:t,label:o,name:n,tooltip:c,visible:r,required:e,fixed:l,fold:a,options:s}},p].concat(p)});return Z(`${f}`)},ee=function({system:t,type:o,name:n,appType:c,version:r,configFileName:e="config.local",variables:l=[],description:a}){let s=k.default.readFileSync(F("python/deploy.xml")).toString();return(0,P.default)(s,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:o,name:n,appType:c,version:r,configFileName:e,variables:(()=>l.map(p=>N(p)).join(`
4
+ `))(),description:a})},T=function(t,o){let n=k.default.readFileSync(F(`python/scripts/${t}.py`)).toString();return(0,P.default)(n,{interpolate:/{{([\s\S]+?)}}/g})(o)},D=function(t,o=[]){let{code:n}=G.default.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 a=K(o,s=>l===s.name);if(a){if(a.fullPath.includes("complexSelect")&&(a.name=a.fullName),r.isStringLiteral()){r.node.value=`$!{${a.name}}`;return}if(r.isNumericLiteral()){r.node.value=`$!{${a.name}}`;return}if(r.isBooleanLiteral()){if(r.node.type="StringLiteral",a.fullPath.includes("complexSelect")){r.node.value=`$!{${a.fullName}}`;return}r.node.value=`[NO_QUOTATION_MARKS]\${${a.name}}[NO_QUOTATION_MARKS]`}}}},ArrayExpression(r){if(r.parentPath.isProperty()){let e=K(o,l=>r.parentPath.get("key").node.name===l.name);if(e){e.fullPath.includes("complexSelect")&&(e.name=e.fullName);let l="",a=e.keys||[],s=e.columns||a;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}s&&s.length&&s.forEach(f=>{l+=`${f.name}: '$!{row.${f.name}}',`}),r.node.type="StringLiteral",r.node.value=`[NO_QUOTATION_MARKS][#foreach($row in $${e.name}) {${l}}, #end][NO_QUOTATION_MARKS]`}}}}}}],retainLines:!0});return n.replace(/"\[NO_QUOTATION_MARKS](.*)\[NO_QUOTATION_MARKS]"/g,"$1")},te=function({system:t,type:o,name:n,appType:c,version:r,configFileName:e="config.local",variables:l=[],description:a,web_app_web_service_name:s,dockerImage:p}){let f=k.default.readFileSync(F("docker/deploy.xml")).toString();return(0,P.default)(f,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:o,name:n,appType:c,version:r,configFileName:e,variables:(()=>l.map(d=>N(d)).join(`
5
+ `))(),description:a,web_app_web_service_name:s,dockerImage:p})},ne=function(t){let o=k.default.readFileSync(F("docker/k8s-deploy-res.yaml")).toString();return(0,P.default)(o,{interpolate:/{{([\s\S]+?)}}/g})(t)},oe=function(t){let o=k.default.readFileSync(F("docker/Dockerfile")).toString();return(0,P.default)(o)(t)},re=function({system:t,type:o,name:n,appType:c,version:r,configFileName:e="config.local",variables:l=[],description:a}){let s=k.default.readFileSync(F("bash/deploy.xml")).toString();return(0,P.default)(s,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:o,name:n,appType:c,version:r,configFileName:e,variables:(()=>l.map(p=>N(p)).join(`
6
+ `))(),description:a})},X=function(t,o){let n=k.default.readFileSync(F(`bash/scripts/${t}.sh`)).toString();return(0,P.default)(n,{interpolate:/{{([\s\S]+?)}}/g})(o)};var u="tmp",ie=function(t,o,n){let{system:c,type:r,name:e,appType:l,version:a,template:s,variables:p,configName:f,description:d,scriptsType:x}=o;y.default.ensureDirSync(u),y.default.ensureDirSync(`${u}/scripts`),y.default.ensureDirSync(`${u}/template`),E()?y.default.outputFileSync(`./${u}/template/config.local.js`,s?D(s,p):""):v()||v(e)?(f="sysconfig",y.default.outputFileSync(`./${u}/template/sysconfig.js`,s?D(s,p):"")):y.default.outputFileSync(`./${u}/template/${f}.js`,s?D(s,p):""),x==="python"?(y.default.outputFileSync(`./${u}/scripts/${e}/utils.py`,T("utils")),y.default.outputFileSync(`./${u}/scripts/${e}/install.py`,T("install",{name:e,type:r})),y.default.outputFileSync(`./${u}/scripts/${e}/afterInstall.py`,T("afterInstall",{name:e})),y.default.outputFileSync(`./${u}/scripts/${e}/uninstall.py`,T("uninstall",{name:e,type:r})),y.default.outputFileSync(`./${u}/deploy.xml`,ee({system:c,type:r,name:e,appType:l,version:a,configFileName:f,variables:p,description:d}))):(y.default.outputFileSync(`./${u}/scripts/${e}/install.sh`,X("install",{name:e,type:r})),y.default.outputFileSync(`./${u}/scripts/${e}/afterInstall.sh`,X("afterInstall",{name:e})),y.default.outputFileSync(`./${u}/scripts/${e}/uninstall.sh`,X("uninstall",{name:e,type:r})),y.default.outputFileSync(`./${u}/deploy.xml`,re({system:c,type:r,name:e,appType:l,version:a,configFileName:f,variables:p,description:d}))),n?n(g=>{_(t,u,()=>{V.default.sync(u),typeof g=="function"&&g()})}):_(t,u,()=>{V.default.sync(u)})};var z=m(require("path")),S=m(require("fs-extra")),B=m(require("rimraf"));var $="tmp",le=function(t,o,n){let{system:c,type:r,name:e,appType:l,version:a,template:s,variables:p,configName:f,description:d,dockerImage:x=a.indexOf("-")>0?`isee1.0-docker-dev-local/${e}`:`isee1.0-docker-release-local/${e}`}=o;S.default.ensureDirSync($),S.default.ensureDirSync("docker"),S.default.pathExistsSync(z.default.resolve(process.cwd(),"docker/Dockerfile"))||S.default.outputFileSync(z.default.resolve(process.cwd(),"docker/Dockerfile"),oe({name:e,type:r})),S.default.ensureDirSync(`${$}/scripts`),S.default.ensureDirSync(`${$}/template`),E()?S.default.outputFileSync(`./${$}/template/${e}/config.local.js`,s?D(s,p):""):v()||v(e)?(f="sysconfig",S.default.outputFileSync(`./${$}/template/${e}/sysconfig.js`,s?D(s,p):"")):S.default.outputFileSync(`./${$}/template/${e}/${f}.js`,s?D(s,p):""),S.default.outputFileSync(`./${$}/template/k8s-deploy-res.yaml`,ne({configFileName:f})),S.default.outputFileSync(`./${$}/deploy.xml`,te({system:c,type:r,name:e,appType:l,version:a,configFileName:f,variables:p,description:d,web_app_web_service_name:`${e}-web`,dockerImage:x})),n?n(g=>{_(t,$,()=>{B.default.sync($),typeof g=="function"&&g()})}):_(t,$,()=>{B.default.sync($)})};var xe=process.cwd();function ke(i,t){let o="",n;return i==="bizframe"&&(o=h.default.readdirSync("./dist").find(c=>/manifest\.[0-9]+\.json/.test(c)),n=h.default.readJsonSync(`./dist/${o}`)),i==="subsystem"&&(o=h.default.readdirSync(`./dist/${t}`).find(c=>/manifest\.[0-9]+\.json/.test(c)),n=h.default.readJsonSync(`./dist/${t}/${o}`)),{manifest:o,manifestJson:n}}exports.generateSeePackageZip=function({system:t,type:o,name:n,appType:c,version:r,configName:e,templateFunc:l,variablesFunc:a,copyFiles:s,description:p,seePackageName:f,seePackageType:d="web",dockerImage:x,scriptsType:g="python"},w){if(!n||!r)throw new Error("\u5E94\u7528\u540D\u79F0\u548C\u5E94\u7528\u7248\u672C\u4E0D\u80FD\u7F3A\u5931~");if(t=t||"winner-front",o=o||"bizframe",c=c||n,a=a||function(){if(o==="bizframe")try{let{variables:b}=require(ce.default.resolve(xe,"build","package","./variables.js"));return b||[]}catch(b){return console.error(b),[]}},l=l||function(){if(o==="bizframe")return"./dist/config.local.js"},d==="docker"){le(f||`${t}-${n}-${r}`,{system:t,type:o,name:n,appType:c,version:r,configName:e,template:l(),variables:a(),description:p,dockerImage:x},b=>{console.log(),(0,Q.default)("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").succeed(),b(w)});return}ie(f||`${t}-${n}-${r}`,{system:t,type:o,name:n,appType:c,version:r,configName:e,template:l(),variables:a(),description:p,scriptsType:g},b=>{if(g==="python"){let{manifest:j,manifestJson:A}=ke(o,n);for(let U in A)if(A.hasOwnProperty(U)){let{path:C,dir:ae}=A[U];h.default.ensureDirSync(`./tmp/source/${ae}`),h.default.copyFileSync(`./dist/${C}`,`./tmp/source/${C}`)}h.default.outputJSONSync(`./tmp/scripts/${n}/conf/${j}`,A)}else h.default.ensureDirSync("./tmp/source"),h.default.copySync("./dist","./tmp/source");Array.isArray(s)&&s.length&&s.forEach(j=>{h.default.ensureFileSync(`./tmp/source/${n}/${j}`),h.default.copyFileSync(`./dist/${n}/${j}`,`./tmp/source/${n}/${j}`)}),console.log(),(0,Q.default)(`\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.default.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
+ `).succeed(),b(w)})};
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ var R=(l=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(l,{get:(t,n)=>(typeof require!="undefined"?require:t)[n]}):l)(function(l){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+l+'" is not supported')});import ce from"chalk";import ae from"path";import te from"ora";import h from"fs-extra";import u from"fs-extra";import q from"rimraf";import K from"path";import de from"chalk";import Se from"ora";import w from"fs-extra";import oe from"archiver";import V from"xml";var z=process.cwd();var B=function(t){let n={"&amp;":"&","&quot;":'"',"&apos;":"'","&lt;":"<","&gt;":">"};return t&&t.replace?t.replace(/(&amp;)|(&quot;)|(&apos;)|(&lt;)|(&gt;)/g,function(r){return n[r]}):t},F=function(t){let n=t||"",r=K.resolve(z,"dist",n,"sysconfig.js");return w.pathExistsSync(r)},A=function(){let t=K.resolve(z,"dist","config.local.js");return w.pathExistsSync(t)},v=function(t,n,r){let c="package";w.ensureDirSync(c);let o=w.createWriteStream(`${c}/${t}.zip`);o.on("close",function(){setTimeout(function(){r&&r()})});let e=oe("zip",{zlib:{level:9}});e.on("error",function(i){console.error(),console.error(i.stack||i),i.details&&console.error(i.details)}),e.pipe(o),e.directory(n,!1),e.finalize()},X=function(t,n,r){let{type:c,label:o,name:e,tooltip:i="",visible:a="true",required:s="false",fixed:p="false",fold:f="false",options:y=""}=t,S=t.default;if(r==="form"){let N=V({form:[{_attr:{name:e,tooltip:i,visible:a,required:s,fixed:p,fold:f,options:y}},n]});return exports.unEscapeForXML(N)}let d=V({field:[{_attr:{type:c,label:o,name:e,tooltip:i,visible:a,required:s,fixed:p,fold:f,options:y}},S||n]});return exports.unEscapeForXML(d)},Q=function(t){let r=t.children.map(c=>{let e=c.children.map(i=>X(i)).join("");return X(c,e,"form")}).join("");return X(t,r)},I=function l(t,n,r="",c=""){for(let o=0;o<t.length;o++){let e=t[o];if(e.fullName=`${r===""?"":r+"."}${e.name}`,e.fullPath=`${c===""?"":c+"-"}${e.type}`,n(e))return e;if(e.children&&e.children.length>0){let i=l(e.children,n,e.fullName,e.fullPath);if(i)return i}}return null};import P from"fs-extra";import re from"path";import D from"lodash.template";import ie from"xml";import le from"@babel/core";var se=["input","select","switch","smallfile","table","mselect","switchForm","complexSelect","division"],b=l=>re.resolve(__dirname,`../templates/see/${l}`),j=l=>{let t=l.type;if(!se.includes(t))return"";let{label:n,name:r,tooltip:c="",visible:o="true",required:e="false",fixed:i="false",fold:a="false",options:s=""}=l,p=l.default;if(t==="table"){let y=l.keys||[];p=(l.columns||y).map(d=>j(d)).join(`
2
+ `)}else if(t==="switchForm"||t==="division")p=l.children.map(S=>j(S)).join(`
3
+ `);else{if(t==="complexSelect")return Q(l);p=[p]}let f=ie({field:[{_attr:{type:t,label:n,name:r,tooltip:c,visible:o,required:e,fixed:i,fold:a,options:s}},p].concat(p)});return B(`${f}`)},U=function({system:t,type:n,name:r,appType:c,version:o,configFileName:e="config.local",variables:i=[],description:a}){let s=P.readFileSync(b("python/deploy.xml")).toString();return D(s,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:n,name:r,appType:c,version:o,configFileName:e,variables:(()=>i.map(p=>j(p)).join(`
4
+ `))(),description:a})},O=function(t,n){let r=P.readFileSync(b(`python/scripts/${t}.py`)).toString();return D(r,{interpolate:/{{([\s\S]+?)}}/g})(n)},x=function(t,n=[]){let{code:r}=le.transformFileSync(t,{babelrc:!1,plugins:[function(){return{visitor:{Literal(o){if(o.parentPath.isProperty()){let e=o.parentPath.get("key").node,i=e.name;e.type==="StringLiteral"&&(e.type="Identifier",e.name=e.value,i=e.value);let a=I(n,s=>i===s.name);if(a){if(a.fullPath.includes("complexSelect")&&(a.name=a.fullName),o.isStringLiteral()){o.node.value=`$!{${a.name}}`;return}if(o.isNumericLiteral()){o.node.value=`$!{${a.name}}`;return}if(o.isBooleanLiteral()){if(o.node.type="StringLiteral",a.fullPath.includes("complexSelect")){o.node.value=`$!{${a.fullName}}`;return}o.node.value=`[NO_QUOTATION_MARKS]\${${a.name}}[NO_QUOTATION_MARKS]`}}}},ArrayExpression(o){if(o.parentPath.isProperty()){let e=I(n,i=>o.parentPath.get("key").node.name===i.name);if(e){e.fullPath.includes("complexSelect")&&(e.name=e.fullName);let i="",a=e.keys||[],s=e.columns||a;if(e.options){i=`[NO_QUOTATION_MARKS][#foreach($row in $${e.name}) '$row' , #end][NO_QUOTATION_MARKS]`,o.node.type="StringLiteral",o.node.value=i;return}s&&s.length&&s.forEach(f=>{i+=`${f.name}: '$!{row.${f.name}}',`}),o.node.type="StringLiteral",o.node.value=`[NO_QUOTATION_MARKS][#foreach($row in $${e.name}) {${i}}, #end][NO_QUOTATION_MARKS]`}}}}}}],retainLines:!0});return r.replace(/"\[NO_QUOTATION_MARKS](.*)\[NO_QUOTATION_MARKS]"/g,"$1")},C=function({system:t,type:n,name:r,appType:c,version:o,configFileName:e="config.local",variables:i=[],description:a,web_app_web_service_name:s,dockerImage:p}){let f=P.readFileSync(b("docker/deploy.xml")).toString();return D(f,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:n,name:r,appType:c,version:o,configFileName:e,variables:(()=>i.map(y=>j(y)).join(`
5
+ `))(),description:a,web_app_web_service_name:s,dockerImage:p})},J=function(t){let n=P.readFileSync(b("docker/k8s-deploy-res.yaml")).toString();return D(n,{interpolate:/{{([\s\S]+?)}}/g})(t)},W=function(t){let n=P.readFileSync(b("docker/Dockerfile")).toString();return D(n)(t)},Z=function({system:t,type:n,name:r,appType:c,version:o,configFileName:e="config.local",variables:i=[],description:a}){let s=P.readFileSync(b("bash/deploy.xml")).toString();return D(s,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:n,name:r,appType:c,version:o,configFileName:e,variables:(()=>i.map(p=>j(p)).join(`
6
+ `))(),description:a})},E=function(t,n){let r=P.readFileSync(b(`bash/scripts/${t}.sh`)).toString();return D(r,{interpolate:/{{([\s\S]+?)}}/g})(n)};var m="tmp",H=function(t,n,r){let{system:c,type:o,name:e,appType:i,version:a,template:s,variables:p,configName:f,description:y,scriptsType:S}=n;u.ensureDirSync(m),u.ensureDirSync(`${m}/scripts`),u.ensureDirSync(`${m}/template`),A()?u.outputFileSync(`./${m}/template/config.local.js`,s?x(s,p):""):F()||F(e)?(f="sysconfig",u.outputFileSync(`./${m}/template/sysconfig.js`,s?x(s,p):"")):u.outputFileSync(`./${m}/template/${f}.js`,s?x(s,p):""),S==="python"?(u.outputFileSync(`./${m}/scripts/${e}/utils.py`,O("utils")),u.outputFileSync(`./${m}/scripts/${e}/install.py`,O("install",{name:e,type:o})),u.outputFileSync(`./${m}/scripts/${e}/afterInstall.py`,O("afterInstall",{name:e})),u.outputFileSync(`./${m}/scripts/${e}/uninstall.py`,O("uninstall",{name:e,type:o})),u.outputFileSync(`./${m}/deploy.xml`,U({system:c,type:o,name:e,appType:i,version:a,configFileName:f,variables:p,description:y}))):(u.outputFileSync(`./${m}/scripts/${e}/install.sh`,E("install",{name:e,type:o})),u.outputFileSync(`./${m}/scripts/${e}/afterInstall.sh`,E("afterInstall",{name:e})),u.outputFileSync(`./${m}/scripts/${e}/uninstall.sh`,E("uninstall",{name:e,type:o})),u.outputFileSync(`./${m}/deploy.xml`,Z({system:c,type:o,name:e,appType:i,version:a,configFileName:f,variables:p,description:y}))),r?r(d=>{v(t,m,()=>{q.sync(m),typeof d=="function"&&d()})}):v(t,m,()=>{q.sync(m)})};import Y from"path";import $ from"fs-extra";import G from"rimraf";var g="tmp",ee=function(t,n,r){let{system:c,type:o,name:e,appType:i,version:a,template:s,variables:p,configName:f,description:y,dockerImage:S=a.indexOf("-")>0?`isee1.0-docker-dev-local/${e}`:`isee1.0-docker-release-local/${e}`}=n;$.ensureDirSync(g),$.ensureDirSync("docker"),$.pathExistsSync(Y.resolve(process.cwd(),"docker/Dockerfile"))||$.outputFileSync(Y.resolve(process.cwd(),"docker/Dockerfile"),W({name:e,type:o})),$.ensureDirSync(`${g}/scripts`),$.ensureDirSync(`${g}/template`),A()?$.outputFileSync(`./${g}/template/${e}/config.local.js`,s?x(s,p):""):F()||F(e)?(f="sysconfig",$.outputFileSync(`./${g}/template/${e}/sysconfig.js`,s?x(s,p):"")):$.outputFileSync(`./${g}/template/${e}/${f}.js`,s?x(s,p):""),$.outputFileSync(`./${g}/template/k8s-deploy-res.yaml`,J({configFileName:f})),$.outputFileSync(`./${g}/deploy.xml`,C({system:c,type:o,name:e,appType:i,version:a,configFileName:f,variables:p,description:y,web_app_web_service_name:`${e}-web`,dockerImage:S})),r?r(d=>{v(t,g,()=>{G.sync(g),typeof d=="function"&&d()})}):v(t,g,()=>{G.sync(g)})};var pe=process.cwd();function fe(l,t){let n="",r;return l==="bizframe"&&(n=h.readdirSync("./dist").find(c=>/manifest\.[0-9]+\.json/.test(c)),r=h.readJsonSync(`./dist/${n}`)),l==="subsystem"&&(n=h.readdirSync(`./dist/${t}`).find(c=>/manifest\.[0-9]+\.json/.test(c)),r=h.readJsonSync(`./dist/${t}/${n}`)),{manifest:n,manifestJson:r}}exports.generateSeePackageZip=function({system:t,type:n,name:r,appType:c,version:o,configName:e,templateFunc:i,variablesFunc:a,copyFiles:s,description:p,seePackageName:f,seePackageType:y="web",dockerImage:S,scriptsType:d="python"},N){if(!r||!o)throw new Error("\u5E94\u7528\u540D\u79F0\u548C\u5E94\u7528\u7248\u672C\u4E0D\u80FD\u7F3A\u5931~");if(t=t||"winner-front",n=n||"bizframe",c=c||r,a=a||function(){if(n==="bizframe")try{let{variables:k}=R(ae.resolve(pe,"build","package","./variables.js"));return k||[]}catch(k){return console.error(k),[]}},i=i||function(){if(n==="bizframe")return"./dist/config.local.js"},y==="docker"){ee(f||`${t}-${r}-${o}`,{system:t,type:n,name:r,appType:c,version:o,configName:e,template:i(),variables:a(),description:p,dockerImage:S},k=>{console.log(),te("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").succeed(),k(N)});return}H(f||`${t}-${r}-${o}`,{system:t,type:n,name:r,appType:c,version:o,configName:e,template:i(),variables:a(),description:p,scriptsType:d},k=>{if(d==="python"){let{manifest:_,manifestJson:T}=fe(n,r);for(let L in T)if(T.hasOwnProperty(L)){let{path:M,dir:ne}=T[L];h.ensureDirSync(`./tmp/source/${ne}`),h.copyFileSync(`./dist/${M}`,`./tmp/source/${M}`)}h.outputJSONSync(`./tmp/scripts/${r}/conf/${_}`,T)}else h.ensureDirSync("./tmp/source"),h.copySync("./dist","./tmp/source");Array.isArray(s)&&s.length&&s.forEach(_=>{h.ensureFileSync(`./tmp/source/${r}/${_}`),h.copyFileSync(`./dist/${r}/${_}`,`./tmp/source/${r}/${_}`)}),console.log(),te(`\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${ce.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
+ `).succeed(),k(N)})};
package/package.json CHANGED
@@ -1,49 +1,39 @@
1
1
  {
2
2
  "name": "@winner-fed/winner-deploy",
3
- "version": "3.4.2",
3
+ "version": "4.0.0",
4
4
  "description": "Generate a publication deployed by the See platform",
5
5
  "keywords": [
6
6
  "winner",
7
7
  "see",
8
8
  "deploy"
9
9
  ],
10
- "main": "src/winner-deploy.js",
11
- "files": [
12
- "src",
13
- "templates"
14
- ],
15
- "author": "winner-fed <cloudbroker@163.com>",
16
- "engines": {
17
- "node": ">=6.0.0"
18
- },
19
- "scripts": {
20
- "lint": "eslint --ext .js src/ test/",
21
- "lint:fix": "eslint --ext .js src/ --fix",
22
- "prebuild": "rimraf dist",
23
- "commit": "git-cz",
24
- "precommit": "lint-staged",
25
- "np-release": "np --branch=main --no-tests"
26
- },
27
- "lint-staged": {
28
- "{src,test}/**/*.js": [
29
- "prettier --write",
30
- "git add"
31
- ]
32
- },
33
- "config": {
34
- "commitizen": {
35
- "path": "node_modules/cz-conventional-changelog"
10
+ "packageManager": "pnpm@7.0.0",
11
+ "main": "dist/index.js",
12
+ "module": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "require": "./dist/index.cjs",
17
+ "import": "./dist/index.js",
18
+ "types": "./dist/index.d.ts"
36
19
  }
37
20
  },
38
- "prettier": {
39
- "semi": false,
40
- "singleQuote": true
41
- },
42
- "commitlint": {
43
- "extends": [
44
- "@commitlint/config-conventional"
45
- ]
21
+ "typesVersions": {
22
+ "*": {
23
+ "*": [
24
+ "./dist/*",
25
+ "./dist/index.d.ts"
26
+ ]
27
+ }
46
28
  },
29
+ "type": "module",
30
+ "author": "winner-fed",
31
+ "license": "MIT",
32
+ "sideEffects": false,
33
+ "files": [
34
+ "dist",
35
+ "templates"
36
+ ],
47
37
  "dependencies": {
48
38
  "@babel/core": "^7.12.3",
49
39
  "archiver": "^3.1.1",
@@ -55,22 +45,26 @@
55
45
  "xml": "^1.0.1"
56
46
  },
57
47
  "devDependencies": {
58
- "@commitlint/cli": "^11.0.0",
59
- "@commitlint/config-conventional": "^11.0.0",
60
- "babel-eslint": "^10.1.0",
61
- "colors": "^1.4.0",
62
- "commitizen": "^4.2.2",
63
- "cross-env": "^7.0.2",
64
- "cz-conventional-changelog": "^3.3.0",
65
- "eslint": "^7.12.1",
66
- "husky": "^4.3.0",
67
- "lint-staged": "^10.5.1",
68
- "lodash.camelcase": "^4.3.0",
69
- "np": "^7.0.0",
70
- "prettier": "^2.1.2"
48
+ "@antfu/ni": "^0.7.0",
49
+ "@types/fs-extra": "^9.0.13",
50
+ "@types/lodash.template": "^4.5.1",
51
+ "@types/node": "^16.10.1",
52
+ "bumpp": "^7.1.1",
53
+ "esno": "^0.9.1",
54
+ "pnpm": "^7.0.0",
55
+ "tsup": "^4.14.0",
56
+ "typescript": "^4.6.4"
71
57
  },
72
58
  "publishConfig": {
73
59
  "access": "public",
74
60
  "registry": "https://registry.npmjs.org/"
75
- }
76
- }
61
+ },
62
+ "scripts": {
63
+ "dev": "nr build --watch",
64
+ "start": "esno src/index.ts",
65
+ "build": "tsup",
66
+ "release": "bumpp --commit --push --tag && pnpm publish",
67
+ "typecheck": "tsc --noEmit"
68
+ },
69
+ "readme": "# winner-deploy\n\n## 功能接口说明\n```javscript\n/**\n * 生成 see 平台部署包\n * @param options.system {string} 系统类型, SEE 平台的分组是以系统类型字段纬度来的, 默认为 winner-front\n * @param options.type {string} 应用类型, 外框架 - bizframe | 子系统 - subsystem, 默认为 子系统 - subsystem\n * @param options.name {string} 发布物名称\n * @param options.appType {string} 发布物类型, 默认为 应用名称 - name\n * @param options.version {string} 发布包版本\n * @param options.configName {string} 配置文件名称,不带有 .js, 默认为 config.local\n * @param options.templateFunc {function} 自定义变量配置文件, 默认为\n * function () {\n if (type === 'bizframe') {\n return `./dist/config.local.js`;\n }\n }\n * @param options.variablesFunc {function} deploy.xml模板变量, 可以动态配置, 默认为\n * function () {\n * const context = process.cwd()\n if (type === 'bizframe') {\n try {\n const {variables} = require(path.resolve(\n context,\n 'build',\n 'package',\n `./variables.js`\n ));\n\n return variables || [];\n } catch (error) {\n console.error(error);\n return [];\n }\n }\n }\n * @param options.copyFiles {Array<string>} 不包含在 manifest.json 配置的文件,直接拷贝到 see 包里。文件路径是相对于项目根目录的路径+文件名,比如 dist/子包/version.js,那么 copyFiles: ['version.js']\n * @param options.description {string} 发布包说明\n * @param options.seePackageName {string} see发布物的包名,也就是 zip 包的命名,默认为 `${system}-${name}-${version}`\n * @param options.seePackageType see 平台发布物包的类型,'web'(默认的) | 'docker'(支持容器化部署的SEE发布物)\n * @param options.dockerImage docker 容器化镜像名,seePackageType 为 docker 生效\n * @param options.scriptsType 脚本类型 'python'(默认的) | 'bash'\n * @param cb {function} 回调函数,用于处理在组装 see 包后,可以自定义执行的动作\n */\nexport const generateSeePackageZip = function generateSeePackageZip({system, type, name, appType, version, configName, templateFunc, variablesFunc, copyFiles, description, seePackageType, dockerImage, scriptsType}, cb) {\n...\n}\n```\n"
70
+ }
@@ -7,7 +7,7 @@
7
7
  <appType describe="发布物类型">{{ appType }}</appType>
8
8
  <appDescribe describe="发布包说明">{{ description }}</appDescribe>
9
9
  <version describe="发布包版本">{{ version }}</version>
10
- <group>bizframe</group>
10
+ <group describe="应用分组">bizframe</group>
11
11
  <packInEffect describe="影响的主包(只有补丁需要配置,填写主包的版本号)" />
12
12
  </basic>
13
13
  <globalConfig describe="系统全局配置" />
@@ -7,7 +7,7 @@
7
7
  <appName describe="应用名称">{{ name }}</appName>
8
8
  <appDescribe describe="应用说明">{{ description }}</appDescribe>
9
9
  <version describe="应用版本">{{ version }}</version>
10
- <group>bizframe</group>
10
+ <group describe="应用分组">bizframe</group>
11
11
  <packInEffect describe="影响的主包(只有补丁需要配置,填写主包的版本号)" />
12
12
  </basic>
13
13
  <globalConfig describe="系统全局配置" />
@@ -7,7 +7,7 @@
7
7
  <appType describe="发布物类型">{{ appType }}</appType>
8
8
  <appDescribe describe="发布包说明">{{ description }}</appDescribe>
9
9
  <version describe="发布包版本">{{ version }}</version>
10
- <group>bizframe</group>
10
+ <group describe="应用分组">bizframe</group>
11
11
  <packInEffect describe="影响的主包(只有补丁需要配置,填写主包的版本号)" />
12
12
  </basic>
13
13
  <globalConfig describe="系统全局配置" />
@@ -1,93 +0,0 @@
1
- const path = require('path')
2
- const fs = require('fs-extra')
3
- const rm = require('rimraf')
4
-
5
- const { isWinnerProject, isProProject, genZipPackage } = require('./utils')
6
- const { genDockerDeployXml, genTemplate, genDockerfile, genK8sDeployRes } = require('./see')
7
-
8
- const tmp = 'tmp'
9
-
10
- /**
11
- * 生成 docker 包
12
- * 自动生成 SEE 平台的发布物和构建镜像所需的文本文件 Dockerfile
13
- * @description 系统类型、应用类型和版本决定了发布物的唯一性
14
- * @param seePackageName
15
- * @param options
16
- * @property {options.system} 系统类型, SEE 平台的分组是以系统类型字段纬度来的
17
- * @property {options.type} 应用类型, 外框架 - bizframe | 子系统 - subsystem
18
- * @property {options.name} 发布物名称
19
- * @property {options.appType} 发布物类型
20
- * @property {options.version} 发布包版本
21
- * @property {options.configName} 配置文件名称 winner - config.local pro - sysconfig
22
- * @param handler
23
- */
24
- exports.genDockerPackage = function genDockerPackage (seePackageName, options, handler) {
25
- let {
26
- system,
27
- type,
28
- name,
29
- appType,
30
- version,
31
- template,
32
- variables,
33
- configName: configFileName,
34
- description,
35
- dockerImage = version.indexOf('-') > 0 ? `isee1.0-docker-dev-local/${name}` : `isee1.0-docker-release-local/${name}`
36
- } = options
37
- fs.ensureDirSync(tmp)
38
-
39
- // 项目根目录下 Dockerfile 文件
40
- fs.ensureDirSync('docker')
41
-
42
- // 如果项目根目录下已经存在 Dockerfile,则不进行重新生成
43
- if (!fs.pathExistsSync(path.resolve(process.cwd(), `docker/Dockerfile`))) {
44
- fs.outputFileSync(path.resolve(process.cwd(), `docker/Dockerfile`), genDockerfile({ name, type }));
45
- }
46
-
47
- // 缺少 scripts 目录会导致 SEE 平台上传发布物报错
48
- fs.ensureDirSync(`${tmp}/scripts`);
49
-
50
- // 缺少 template 目录会导致 SEE 平台上传发布物报错
51
- fs.ensureDirSync(`${tmp}/template`)
52
-
53
- if (isWinnerProject()) {
54
- fs.outputFileSync(`./${tmp}/template/${name}/config.local.js`, template ? genTemplate(template, variables) : '')
55
- } else if (isProProject() || isProProject(name)) { // 子包目录 dist/'name'/sysconfig.js
56
- // 这里做了默认重写
57
- // 兼容操作员中心产品
58
- configFileName = 'sysconfig';
59
- fs.outputFileSync(`./${tmp}/template/${name}/sysconfig.js`, template ? genTemplate(template, variables) : '')
60
- } else {
61
- // 自定义配置文件的名字
62
- fs.outputFileSync(`./${tmp}/template/${name}/${configFileName}.js`, template ? genTemplate(template, variables) : '')
63
- }
64
-
65
- // 生成 k8s-deploy-res.yaml
66
- fs.outputFileSync(`./${tmp}/template/k8s-deploy-res.yaml`, genK8sDeployRes({ configFileName }))
67
-
68
- fs.outputFileSync(`./${tmp}/deploy.xml`, genDockerDeployXml({
69
- system,
70
- type,
71
- name,
72
- appType,
73
- version,
74
- configFileName,
75
- variables,
76
- description,
77
- web_app_web_service_name: `${name}-web`,
78
- dockerImage
79
- }))
80
-
81
- if (handler) {
82
- handler((cb) => {
83
- genZipPackage(seePackageName, tmp, () => {
84
- rm.sync(tmp)
85
- typeof cb === 'function' && cb()
86
- })
87
- })
88
- } else {
89
- genZipPackage(seePackageName, tmp, () => {
90
- rm.sync(tmp)
91
- })
92
- }
93
- }
@@ -1,102 +0,0 @@
1
- const fs = require('fs-extra')
2
- const rm = require('rimraf')
3
-
4
- const { isWinnerProject, isProProject, genZipPackage } = require('./utils')
5
- const { genDeployXml, genScripts, genTemplate, genDeployXmlBySh, genScriptsBySh } = require('./see')
6
-
7
- const tmp = 'tmp'
8
-
9
- /**
10
- * @description 系统类型、应用类型和版本决定了发布物的唯一性
11
- * @param seePackageName
12
- * @param options
13
- * @property {options.system} 系统类型, SEE 平台的分组是以系统类型字段纬度来的
14
- * @property {options.type} 应用类型, 外框架 - bizframe | 子系统 - subsystem
15
- * @property {options.name} 发布物名称
16
- * @property {options.appType} 发布物类型
17
- * @property {options.version} 发布包版本
18
- * @property {options.configName} 配置文件名称 winner - config.local pro - sysconfig
19
- * @property {options.scriptsType} 脚本类型
20
- * @param handler
21
- */
22
- exports.genSeePackage = function genSeePackage (seePackageName, options, handler) {
23
- let {
24
- system,
25
- type,
26
- name,
27
- appType,
28
- version,
29
- template,
30
- variables,
31
- configName: configFileName,
32
- description,
33
- scriptsType
34
- } = options
35
- fs.ensureDirSync(tmp)
36
- fs.ensureDirSync(`${tmp}/scripts`)
37
- // 缺少 template 目录会导致 SEE 平台上传发布物报错
38
- fs.ensureDirSync(`${tmp}/template`)
39
- if (isWinnerProject()) {
40
- fs.outputFileSync(`./${tmp}/template/config.local.js`, template ? genTemplate(template, variables) : '')
41
- } else if (isProProject() || isProProject(name)) { // 子包目录 dist/'name'/sysconfig.js
42
- // 这里做了默认重写
43
- // 兼容操作员中心产品
44
- configFileName = 'sysconfig';
45
- fs.outputFileSync(`./${tmp}/template/sysconfig.js`, template ? genTemplate(template, variables) : '')
46
- } else {
47
- // 自定义配置文件的名字
48
- fs.outputFileSync(`./${tmp}/template/${configFileName}.js`, template ? genTemplate(template, variables) : '')
49
- }
50
-
51
- if (scriptsType === 'python') {
52
- fs.outputFileSync(`./${tmp}/scripts/${name}/utils.py`, genScripts('utils'))
53
- fs.outputFileSync(`./${tmp}/scripts/${name}/install.py`, genScripts('install', { name, type }))
54
- fs.outputFileSync(`./${tmp}/scripts/${name}/afterInstall.py`, genScripts('afterInstall', { name }))
55
- fs.outputFileSync(`./${tmp}/scripts/${name}/uninstall.py`, genScripts('uninstall', {
56
- name,
57
- type
58
- }))
59
-
60
- fs.outputFileSync(`./${tmp}/deploy.xml`, genDeployXml({
61
- system,
62
- type,
63
- name,
64
- appType,
65
- version,
66
- configFileName,
67
- variables,
68
- description
69
- }))
70
- } else {
71
- fs.outputFileSync(`./${tmp}/scripts/${name}/install.sh`, genScriptsBySh('install', { name, type }))
72
- fs.outputFileSync(`./${tmp}/scripts/${name}/afterInstall.sh`, genScriptsBySh('afterInstall', { name }))
73
- fs.outputFileSync(`./${tmp}/scripts/${name}/uninstall.sh`, genScriptsBySh('uninstall', {
74
- name,
75
- type
76
- }))
77
-
78
- fs.outputFileSync(`./${tmp}/deploy.xml`, genDeployXmlBySh({
79
- system,
80
- type,
81
- name,
82
- appType,
83
- version,
84
- configFileName,
85
- variables,
86
- description
87
- }))
88
- }
89
-
90
- if (handler) {
91
- handler((cb) => {
92
- genZipPackage(seePackageName, tmp, () => {
93
- rm.sync(tmp)
94
- typeof cb === 'function' && cb()
95
- })
96
- })
97
- } else {
98
- genZipPackage(seePackageName, tmp, () => {
99
- rm.sync(tmp)
100
- })
101
- }
102
- }
package/src/see.js DELETED
@@ -1,334 +0,0 @@
1
- const fs = require('fs-extra')
2
- const path = require('path')
3
- const tpl = require('lodash.template')
4
- const xml = require('xml')
5
- const babel = require('@babel/core')
6
- const { unEscapeForXML, formatComplexSelectXml, findTemplateVariableItem } = require('./utils')
7
-
8
- // 支持的类型
9
- // input - 普通文本输入框。
10
- // select - 单选下拉框。
11
- // switch - 开关组件。
12
- // smallfile - 文件上传控件,仅支持小于 2M 的文件,文件内容以 base64 转码后的字符串存储。
13
- // switchForm - 开关表单,通过控件 switch 控制下面表单的显示
14
- // complexSelect - 复杂单选框,通过控件 select 控制下面显示哪个表单
15
- // table - 表格控件,table 类型的模板配置目前只支持 Array<Object> 类型配置项,比如 APPS。
16
- // division - 分栏折叠控件。 division分栏组件将界面上众多的组件分栏并给出每一栏目的标头该控件仅用于界面展示控制由于其不具有name属性故其子元素取值方式保持原有不变,举例division包含子控件b其取值变量为b),分区组件,用于界面控制,作为分栏使用,对参数使用没意义
17
- const typeSupported = ['input', 'select', 'switch', 'smallfile', 'table', 'mselect', 'switchForm', 'complexSelect', 'division']
18
- const resolveFile = (file) => path.resolve(__dirname, `../templates/see/${file}`)
19
-
20
- // 生成 filed 属性解析
21
- const generateField = (attr) => {
22
- const type = attr.type
23
- if (!typeSupported.includes(type)) return ''
24
- const {
25
- label,
26
- name,
27
- tooltip = '',
28
- // 配置界面开启是否默认显示该参数,用于隐藏不常修改的配置参数。可选值:true、false
29
- visible = 'true',
30
- required = 'false',
31
- // 冻结表行,表格配置默认值,配置不允许用户增加或者修改行
32
- fixed = 'false',
33
- // 控件是否默认折叠,操控控件默认展示时是否占用最小空间,选填字段;可选值:true、false。
34
- fold = 'false',
35
- // 选择项,select、mselect、linkageform控件必填。示例:“true:是;false:否“
36
- options = ''
37
- } = attr
38
- let defaultValue = attr.default
39
-
40
- if (type === 'table') {
41
- const keys = attr.keys || []
42
- const columns = attr.columns || keys
43
-
44
- defaultValue = columns.map(attr => generateField(attr)).join('\n ')
45
- } else if (type === 'switchForm' || type === 'division') {
46
- const children = attr.children
47
- defaultValue = children.map(attr => generateField(attr)).join('\n ')
48
- } else if (type === 'complexSelect') {
49
- return formatComplexSelectXml(attr)
50
- } else {
51
- defaultValue = [defaultValue]
52
- }
53
-
54
- const xmlVariable = xml({
55
- field: [{
56
- _attr: {
57
- type,
58
- label,
59
- name,
60
- tooltip,
61
- visible,
62
- required,
63
- fixed,
64
- fold,
65
- options
66
- }
67
- }, defaultValue].concat(defaultValue)
68
- })
69
-
70
- return unEscapeForXML(`${xmlVariable}`)
71
- }
72
-
73
- exports.genDeployXml = function genDeployXml ({
74
- system,
75
- type,
76
- name,
77
- appType,
78
- version,
79
- configFileName = 'config.local',
80
- variables = [],
81
- description
82
- }) {
83
- const template = fs.readFileSync(resolveFile(`python/deploy.xml`)).toString()
84
-
85
- return tpl(template, {
86
- interpolate: /{{([\s\S]+?)}}/g
87
- })({
88
- system,
89
- type,
90
- name,
91
- appType,
92
- version,
93
- configFileName,
94
- variables: (() => {
95
- return variables.map((attr) => {
96
- return generateField(attr)
97
- }).join('\n ')
98
- })(),
99
- description
100
- })
101
- }
102
-
103
- exports.genScripts = function genScripts (name, options) {
104
- const template = fs.readFileSync(resolveFile(`python/scripts/${name}.py`)).toString()
105
- return tpl(template, {
106
- interpolate: /{{([\s\S]+?)}}/g
107
- })(options)
108
- }
109
-
110
- exports.genTemplate = function genTemplate (file, variables = []) {
111
- // phase 1. parse
112
- // const template = fs.readFileSync(file).toString();
113
- // const ast = parse(template);
114
-
115
- // phase 2. traverse
116
- // traverse(ast, {
117
- // enter(path) {
118
- // if (path.isLiteral() && path.parentPath.isProperty()) {
119
- // const _match = variables.find((variable) => path.parentPath.get("key").node.name === variable.name);
120
- // if (_match) {
121
- // console.log(_match.name);
122
- // if (path.isStringLiteral()) {
123
- // path.node.value = `$\{${_match.name}\}`;
124
- // return;
125
- // }
126
- // if (path.isBooleanLiteral()) {
127
- // path.node.type = "StringLiteral";
128
- // path.node.value = `[NO_QUOTATION_MARKS]$\{${_match.name}\}[NO_QUOTATION_MARKS]`;
129
- // return;
130
- // }
131
- // }
132
- // }
133
- // },
134
- // });
135
-
136
- // phase 3. traverse
137
- // let { code } = generate(ast, template);
138
-
139
- const { code } = babel.transformFileSync(file, {
140
- babelrc: false,
141
- plugins: [
142
- function seeTemplatePlugin () {
143
- return {
144
- visitor: {
145
- Literal (path) {
146
- if (path.parentPath.isProperty()) {
147
- const currentNode = path.parentPath.get('key').node
148
- let currentNodeName = currentNode.name
149
- // 当 key 为字符串的时候,会转换失败
150
- // 解决方法,重置为标识符字面量节点
151
- // 如
152
- // window.LOCAL_CONFIG_whaleTest = {
153
- // "API_HOME": 'https://api.github.com/',
154
- // 'API_USER': "https://www.baidu.com",
155
- // API_UPLOAD: 'https://api.github.com/upload',
156
- // IS_OPEN_VCONSOLE: false
157
- // }
158
- // 转换之后的效果是有问题的,API_HOME 没有转换
159
- // window.LOCAL_CONFIG_whaleTest = {
160
- // "API_HOME": 'https://api.github.com/',
161
- // 'API_USER': "https://www.baidu.com",
162
- // API_UPLOAD: 'https://api.github.com/upload',
163
- // IS_OPEN_VCONSOLE: ${IS_OPEN_VCONSOLE}
164
- // }
165
- if (currentNode.type === 'StringLiteral') {
166
- currentNode.type = 'Identifier'
167
- currentNode.name = currentNode.value
168
- currentNodeName = currentNode.value
169
- }
170
-
171
- const _match = findTemplateVariableItem(variables, (variable) => currentNodeName === variable.name)
172
- if (_match) {
173
- if (_match.fullPath.includes('complexSelect')) {
174
- _match.name = _match.fullName
175
- }
176
-
177
- // 是否为字符串字面量节点
178
- if (path.isStringLiteral()) {
179
- path.node.value = `$!\{${_match.name}\}`
180
- return
181
- }
182
- // 是否为数字字面量节点
183
- if (path.isNumericLiteral()) {
184
- path.node.value = `$!\{${_match.name}\}`
185
- return
186
- }
187
- // 是否为数布尔字面量节点
188
- if (path.isBooleanLiteral()) {
189
- path.node.type = 'StringLiteral'
190
-
191
- if (_match.fullPath.includes('complexSelect')) {
192
- path.node.value = `$!\{${_match.fullName}\}`
193
- return
194
- }
195
-
196
- path.node.value = `[NO_QUOTATION_MARKS]$\{${_match.name}\}[NO_QUOTATION_MARKS]`
197
- }
198
- }
199
- }
200
- },
201
-
202
- ArrayExpression (path) {
203
- if (path.parentPath.isProperty()) {
204
- const _match = findTemplateVariableItem(variables, variable => path.parentPath.get('key').node.name === variable.name)
205
-
206
- if (_match) {
207
- if (_match.fullPath.includes('complexSelect')) {
208
- _match.name = _match.fullName
209
- }
210
-
211
- let value = ''
212
-
213
- // 目前只支持 [{}, {}] 这种形式的 table
214
- // keys 表示 Object 元素的 key,value 目前只支持 String 类型
215
- const keys = _match.keys || []
216
- // 原来这个字段是 keys,不太好理解,换成 columns,需要处理兼容问题
217
- const columns = _match.columns || keys
218
- const options = _match.options
219
-
220
- if (options) {
221
- value = `[NO_QUOTATION_MARKS][#foreach($row in $${_match.name}) '$row' , #end][NO_QUOTATION_MARKS]`
222
- path.node.type = 'StringLiteral'
223
- path.node.value = value
224
- return
225
- }
226
-
227
- if (columns && columns.length) {
228
- columns.forEach(item => {
229
- value += `${item.name}: '$\!{row.${item.name}}',` // 双引号会被转义
230
- })
231
- }
232
-
233
- path.node.type = 'StringLiteral'
234
- path.node.value = `[NO_QUOTATION_MARKS][#foreach($row in $${_match.name}) {${value}}, #end][NO_QUOTATION_MARKS]`
235
- }
236
- }
237
- }
238
- }
239
- }
240
- }
241
- ],
242
- retainLines: true
243
- })
244
-
245
- // BooleanLiteral 需要在模版中去掉引号
246
- return code.replace(/"\[NO_QUOTATION_MARKS](.*)\[NO_QUOTATION_MARKS]"/g, '$1')
247
- }
248
-
249
- // ---------------------------------------------------docker
250
- exports.genDockerDeployXml = function genDockerDeployXml ({
251
- system,
252
- type,
253
- name,
254
- appType,
255
- version,
256
- configFileName = 'config.local',
257
- variables = [],
258
- description,
259
- web_app_web_service_name,
260
- dockerImage
261
- }) {
262
- const template = fs.readFileSync(resolveFile(`docker/deploy.xml`)).toString()
263
-
264
- return tpl(template, {
265
- interpolate: /{{([\s\S]+?)}}/g
266
- })({
267
- system,
268
- type,
269
- name,
270
- appType,
271
- version,
272
- configFileName,
273
- variables: (() => {
274
- return variables.map((attr) => {
275
- return generateField(attr)
276
- }).join('\n ')
277
- })(),
278
- description,
279
- web_app_web_service_name,
280
- dockerImage
281
- })
282
- }
283
-
284
- exports.genK8sDeployRes = function genK8sDeployResYaml (options) {
285
- const template = fs.readFileSync(resolveFile(`docker/k8s-deploy-res.yaml`)).toString()
286
-
287
- return tpl(template, {
288
- interpolate: /{{([\s\S]+?)}}/g
289
- })(options)
290
- }
291
-
292
- exports.genDockerfile = function genDockerfile (options) {
293
- const template = fs.readFileSync(resolveFile(`docker/Dockerfile`)).toString()
294
-
295
- return tpl(template)(options)
296
- }
297
-
298
- // --------------------------------------------------- bash
299
- exports.genDeployXmlBySh = function genDeployXmlBySh ({
300
- system,
301
- type,
302
- name,
303
- appType,
304
- version,
305
- configFileName = 'config.local',
306
- variables = [],
307
- description
308
- }) {
309
- const template = fs.readFileSync(resolveFile(`bash/deploy.xml`)).toString()
310
-
311
- return tpl(template, {
312
- interpolate: /{{([\s\S]+?)}}/g
313
- })({
314
- system,
315
- type,
316
- name,
317
- appType,
318
- version,
319
- configFileName,
320
- variables: (() => {
321
- return variables.map((attr) => {
322
- return generateField(attr)
323
- }).join('\n ')
324
- })(),
325
- description
326
- })
327
- }
328
-
329
- exports.genScriptsBySh = function genScriptsBySh (name, options) {
330
- const template = fs.readFileSync(resolveFile(`bash/scripts/${name}.sh`)).toString()
331
- return tpl(template, {
332
- interpolate: /{{([\s\S]+?)}}/g
333
- })(options)
334
- }
package/src/utils.js DELETED
@@ -1,182 +0,0 @@
1
- const path = require('path')
2
- const chalk = require('chalk')
3
- const ora = require('ora')
4
- const fs = require('fs-extra')
5
- const archiver = require('archiver')
6
- const xml = require('xml')
7
-
8
- const context = process.cwd()
9
-
10
- exports.spinner = function spinner (text) {
11
- return ora({
12
- text: `${chalk.white('[deploy] ')}${text}`
13
- })
14
- }
15
-
16
- // 还原特殊字符 /([&"<>'])/g
17
- exports.unEscapeForXML = function unEscapeForXML (string) {
18
- const XML_CHARACTER_MAP = {
19
- '&amp;': '&',
20
- '&quot;': '"',
21
- '&apos;': '\'',
22
- '&lt;': '<',
23
- '&gt;': '>'
24
- }
25
- return string && string.replace
26
- ? string.replace(/(&amp;)|(&quot;)|(&apos;)|(&lt;)|(&gt;)/g, function(str) {
27
- return XML_CHARACTER_MAP[str]
28
- })
29
- : string
30
- }
31
-
32
- /**
33
- *
34
- * @param subPath 子包路径
35
- * @returns {*}
36
- */
37
- // 1,项目包名为 dist
38
- exports.isProProject = function isProProject (subPath) {
39
- const newSubPath = subPath || ''
40
- const sysconfigJS = path.resolve(context, 'dist', newSubPath, 'sysconfig.js')
41
- return fs.pathExistsSync(sysconfigJS)
42
- }
43
-
44
- // winner项目特点
45
- // 1,项目包名为 dist
46
- // 2,配置文件名为 config.local
47
- exports.isWinnerProject = function isWinnerProject () {
48
- // 默认为 dist 目录
49
- const configLocalJS = path.resolve(context, 'dist', 'config.local.js')
50
- return fs.pathExistsSync(configLocalJS)
51
- }
52
-
53
- /**
54
- * 生成 zip
55
- * @param zipPackageName
56
- * @param tmp
57
- * @param cb
58
- */
59
- exports.genZipPackage = function genZipPackage (zipPackageName, tmp, cb) {
60
- // 包存放路径
61
- const packagePath = 'package'
62
- fs.ensureDirSync(packagePath)
63
-
64
- const output = fs.createWriteStream(`${packagePath}/${zipPackageName}.zip`)
65
-
66
- output.on('close', function() {
67
- setTimeout(function() {
68
- cb && cb()
69
- })
70
- })
71
-
72
- const archive = archiver('zip', { zlib: { level: 9 } }) // Sets the compression level.
73
-
74
- archive.on('error', function(error) {
75
- console.error()
76
- console.error(error.stack || error)
77
- error.details && console.error(error.details)
78
- })
79
-
80
- archive.pipe(output)
81
- archive.directory(tmp, false)
82
- archive.finalize()
83
- }
84
-
85
- /**
86
- * 生成通用的 field 字段
87
- * @param attr 属性
88
- * @param children 子集
89
- * @param t 字段类型
90
- * @return {*}
91
- */
92
- exports.formatCommonField = function formatCommonField (attr, children = [], t) {
93
- const {
94
- type,
95
- label,
96
- name,
97
- tooltip = '',
98
- visible = 'true',
99
- required = 'false',
100
- fixed = 'false',
101
- fold = 'false',
102
- options = ''
103
- } = attr
104
- const defaultValue = attr.default
105
-
106
- if (t === 'form') {
107
- const xmlVariable = xml({
108
- form: [{
109
- _attr: {
110
- name,
111
- tooltip,
112
- visible,
113
- required,
114
- fixed,
115
- fold,
116
- options
117
- }
118
- }, children]
119
- })
120
- return exports.unEscapeForXML(xmlVariable)
121
- }
122
-
123
- const xmlVariable = xml({
124
- field: [{
125
- _attr: {
126
- type,
127
- label,
128
- name,
129
- tooltip,
130
- visible,
131
- required,
132
- fixed,
133
- fold,
134
- options
135
- }
136
- }, defaultValue ? defaultValue : children]
137
- })
138
-
139
- return exports.unEscapeForXML(xmlVariable)
140
- }
141
-
142
- /**
143
- * 复杂选择器解析
144
- * @param attr
145
- * @return {*}
146
- */
147
- exports.formatComplexSelectXml = function formatComplexSelectXml (attr) {
148
- const children = attr.children
149
- const formsXmlVariable = children.map((form) => {
150
- const children = form.children
151
- const formItemsValue = children.map(formItem => exports.formatCommonField(formItem)).join('')
152
- return exports.formatCommonField(form, formItemsValue, 'form')
153
- }).join('')
154
-
155
- return exports.formatCommonField(attr, formsXmlVariable)
156
- }
157
-
158
- /**
159
- * 解析模板变量
160
- *
161
- * @param {Array} variables 模板变量数组
162
- * @param {Function} cb 回调函数
163
- * @param prefix
164
- * @param path
165
- * @returns 查询对象,若没有找到则返回 null
166
- */
167
- exports.findTemplateVariableItem = function findTemplateVariableItem (variables, cb, prefix = '', path = '') {
168
- for (let i = 0; i < variables.length; i++) {
169
- let item = variables[i]
170
- item.fullName = `${prefix === '' ? '' : prefix + '.'}${item.name}`
171
- item.fullPath = `${path === '' ? '' : path + '-'}${item.type}`
172
-
173
- if (cb(item)) {
174
- return item
175
- } else if (item.children && item.children.length > 0) {
176
- let result = exports.findTemplateVariableItem(item.children, cb, item.fullName, item.fullPath)
177
- if (result) return result
178
- }
179
- }
180
-
181
- return null
182
- }
@@ -1,212 +0,0 @@
1
- const chalk = require('chalk')
2
- const path = require('path')
3
- const ora = require('ora')
4
- const fs = require('fs-extra')
5
-
6
- const context = process.cwd()
7
-
8
- const { genSeePackage } = require('./genWebPackage')
9
- const { genDockerPackage } = require('./genDockerPackage')
10
-
11
- function genManifest (type, name) {
12
- let manifest = ''
13
- let manifestJson = ''
14
-
15
- if (type === 'bizframe') {
16
- manifest = fs
17
- .readdirSync(`./dist`)
18
- .find(file => /manifest\.[0-9]+\.json/.test(file))
19
-
20
- manifestJson = fs.readJsonSync(`./dist/${manifest}`)
21
- }
22
-
23
- if (type === 'subsystem') {
24
- manifest = fs
25
- .readdirSync(`./dist/${name}`)
26
- .find(file => /manifest\.[0-9]+\.json/.test(file))
27
-
28
- manifestJson = fs.readJsonSync(`./dist/${name}/${manifest}`)
29
- }
30
-
31
- return { manifest, manifestJson }
32
- }
33
-
34
- /**
35
- * 生成 see 平台部署包
36
- * @param system {string} 系统类型, SEE 平台的分组是以系统类型字段纬度来的, 默认为 winner-front
37
- * @param type {string} 应用类型, 外框架 - bizframe | 子系统 - subsystem, 默认为 子系统 - subsystem
38
- * @param name {string} 发布物名称
39
- * @param appType {string} 发布物类型, 默认为 应用名称 - name
40
- * @param version {string} 发布包版本
41
- * @param configName {string} 配置文件名称,不带有 .js, 默认为 config.local
42
- * @param templateFunc {function} 自定义变量配置文件, 默认为
43
- * function () {
44
- if (type === 'bizframe') {
45
- return `./dist/config.local.js`;
46
- }
47
- }
48
- * @param variablesFunc {function} deploy.xml模板变量, 可以动态配置, 默认为
49
- * function () {
50
- * const context = process.cwd()
51
- if (type === 'bizframe') {
52
- try {
53
- const {variables} = require(path.resolve(
54
- context,
55
- 'build',
56
- 'package',
57
- `./variables.js`
58
- ));
59
-
60
- return variables || [];
61
- } catch (error) {
62
- console.error(error);
63
- return [];
64
- }
65
- }
66
- }
67
- * @param copyFiles {Array<string>} 不包含在 manifest.json 配置的文件,直接拷贝到 see 包里。文件路径是相对于项目根目录的路径+文件名,比如 dist/子包/version.js,那么 copyFiles: ['version.js']
68
- * @param description {string} 发布包说明
69
- * @param seePackageName {string} see发布物的包名,也就是 zip 包的命名,默认为 `${system}-${name}-${version}`
70
- * @param seePackageType see 平台发布物包的类型,'web'(默认的) | 'docker'(支持容器化部署的SEE发布物)
71
- * @param dockerImage docker 容器化镜像名,seePackageType 为 docker 生效
72
- * @param scriptsType 脚本类型 'python' | 'bash'
73
- * @param cb {function} 回调函数,用于处理在组装 see 包后,可以自定义执行的动作
74
- */
75
- exports.generateSeePackageZip = function generateSeePackageZip ({
76
- system,
77
- type,
78
- name,
79
- appType,
80
- version,
81
- configName,
82
- templateFunc,
83
- variablesFunc,
84
- copyFiles,
85
- description,
86
- seePackageName,
87
- seePackageType = 'web',
88
- dockerImage,
89
- scriptsType = 'python'
90
- }, cb) {
91
- if (!name || !version) {
92
- throw new Error('应用名称和应用版本不能缺失~')
93
- }
94
- system = system || 'winner-front'
95
- type = type || 'bizframe'
96
- appType = appType || name
97
- variablesFunc = variablesFunc || function() {
98
- if (type === 'bizframe') {
99
- try {
100
- const { variables } = require(path.resolve(
101
- context,
102
- 'build',
103
- 'package',
104
- `./variables.js`
105
- ))
106
-
107
- return variables || []
108
- } catch (error) {
109
- console.error(error)
110
- return []
111
- }
112
- }
113
- }
114
-
115
- templateFunc = templateFunc || function() {
116
- if (type === 'bizframe') {
117
- return `./dist/config.local.js`
118
- }
119
- }
120
-
121
- if (seePackageType === 'docker') {
122
- genDockerPackage(
123
- seePackageName || `${system}-${name}-${version}`,
124
- {
125
- system,
126
- type,
127
- name,
128
- appType,
129
- version,
130
- configName,
131
- template: (templateFunc)(),
132
- variables: (variablesFunc)(),
133
- description,
134
- dockerImage
135
- },
136
- done => {
137
-
138
- console.log()
139
- ora(
140
- `docker 容器化部署的 SEE 发布物制作完成,您可以在 SEE 平台上传并部署应用。`
141
- ).succeed()
142
-
143
- done(cb)
144
- }
145
- )
146
- return;
147
- }
148
-
149
- genSeePackage(
150
- seePackageName || `${system}-${name}-${version}`,
151
- {
152
- system,
153
- type,
154
- name,
155
- appType,
156
- version,
157
- configName,
158
- template: (templateFunc)(),
159
- variables: (variablesFunc)(),
160
- description,
161
- scriptsType
162
- },
163
- done => {
164
- if (scriptsType === 'python') {
165
- const { manifest, manifestJson } = genManifest(type, name)
166
- // 发布物中的源码部分统一放到 source 目录下
167
- for (const file in manifestJson) {
168
- if (manifestJson.hasOwnProperty(file)) {
169
- const { path, dir } = manifestJson[file]
170
-
171
- fs.ensureDirSync(`./tmp/source/${dir}`)
172
- fs.copyFileSync(`./dist/${path}`, `./tmp/source/${path}`)
173
- }
174
- }
175
-
176
- fs.outputJSONSync(
177
- `./tmp/scripts/${name}/conf/${manifest}`,
178
- manifestJson
179
- )
180
- } else {
181
- // bash
182
- fs.ensureDirSync(`./tmp/source`)
183
- fs.copySync(`./dist`, `./tmp/source`)
184
- }
185
-
186
- // 自定义拷贝的文件,直接拷贝到 see 包里
187
- if (Array.isArray(copyFiles) && copyFiles.length) {
188
- copyFiles.forEach((file) => {
189
- // 1. 首先先确保文件目录存在,否则创建
190
- fs.ensureFileSync(`./tmp/source/${name}/${file}`)
191
- // 2. 然后进行拷贝
192
- fs.copyFileSync(`./dist/${name}/${file}`, `./tmp/source/${name}/${file}`)
193
- });
194
- }
195
-
196
- console.log()
197
- ora(
198
- `发布物制作完成,您可以在 SEE 平台上传并部署应用。注意:${chalk.yellow(
199
- '子系统发布物的安装目录需要指定到具体的应用目录'
200
- )}。比如/home/hsiar/hsiar-green/html/。\n`
201
- ).succeed()
202
-
203
- done(cb)
204
- }
205
- )
206
- }
207
-
208
- /**
209
- * 兼容 hui-deploy
210
- * @type {function(*=, *, *=): void}
211
- */
212
- exports.genSeePackage = genSeePackage