@winner-fed/winner-deploy 3.4.2 → 4.0.6

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
@@ -1,6 +1,7 @@
1
1
  # winner-deploy
2
2
 
3
3
  ## 功能接口说明
4
+
4
5
  ```javscript
5
6
  /**
6
7
  * 生成 see 平台部署包
@@ -10,6 +11,7 @@
10
11
  * @param options.appType {string} 发布物类型, 默认为 应用名称 - name
11
12
  * @param options.version {string} 发布包版本
12
13
  * @param options.configName {string} 配置文件名称,不带有 .js, 默认为 config.local
14
+ * @param options.outputName {string} 输出的目录名称,默认为 dist
13
15
  * @param options.templateFunc {function} 自定义变量配置文件, 默认为
14
16
  * function () {
15
17
  if (type === 'bizframe') {
@@ -43,7 +45,7 @@
43
45
  * @param options.scriptsType 脚本类型 'python'(默认的) | 'bash'
44
46
  * @param cb {function} 回调函数,用于处理在组装 see 包后,可以自定义执行的动作
45
47
  */
46
- exports.generateSeePackageZip = function generateSeePackageZip({system, type, name, appType, version, configName, templateFunc, variablesFunc, copyFiles, description, seePackageType, dockerImage, scriptsType}, cb) {
48
+ export const generateSeePackageZip = function generateSeePackageZip({system, type, name, appType, version, configName, outputName, templateFunc, variablesFunc, copyFiles, description, seePackageType, dockerImage, scriptsType}, cb) {
47
49
  ...
48
50
  }
49
51
  ```
package/dist/index.cjs ADDED
@@ -0,0 +1,7 @@
1
+ var me=Object.create;var w=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var ge=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty;var q=i=>w(i,"__esModule",{value:!0});var Se=(i,t)=>{q(i);for(var o in t)w(i,o,{get:t[o],enumerable:!0})},$e=(i,t,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ye(t))!de.call(i,r)&&r!=="default"&&w(i,r,{get:()=>t[r],enumerable:!(o=ue(t,r))||o.enumerable});return i},y=i=>$e(q(w(i!=null?me(ge(i)):{},"default",i&&i.__esModule&&"default"in i?{get:()=>i.default,enumerable:!0}:{value:i,enumerable:!0})),i);Se(exports,{generateSeePackageZip:()=>ke});var ae=y(require("chalk")),pe=y(require("path")),z=y(require("ora")),h=y(require("fs-extra"));var g=y(require("fs-extra")),Q=y(require("rimraf"));var X=y(require("path")),D=y(require("fs-extra")),W=y(require("archiver")),K=y(require("xml")),Z=process.cwd(),H=function(t){let o={"&amp;":"&","&quot;":'"',"&apos;":"'","&lt;":"<","&gt;":">"};return t&&t.replace?t.replace(/(&amp;)|(&quot;)|(&apos;)|(&lt;)|(&gt;)/g,function(r){return o[r]}):t},v=function(t,o){let r=o||"",a=X.default.resolve(Z,t,r,"sysconfig.js");return D.default.pathExistsSync(a)},E=function(t){let o=X.default.resolve(Z,t,"config.local.js");return D.default.pathExistsSync(o)},F=function(t,o,r){let a="package";D.default.ensureDirSync(a);let n=D.default.createWriteStream(`${a}/${t}.zip`);n.on("close",function(){setTimeout(function(){r&&r()})});let e=(0,W.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(n),e.directory(o,!1),e.finalize()},L=function(t,o,r){let{type:a,label:n,name:e,tooltip:l="",visible:s="true",required:c="false",fixed:p="false",fold:f="false",options:m=""}=t,d=t.default;if(r==="form"){let x=(0,K.default)({form:[{_attr:{name:e,tooltip:l,visible:s,required:c,fixed:p,fold:f,options:m}},o]});return exports.unEscapeForXML(x)}let O=(0,K.default)({field:[{_attr:{type:a,label:n,name:e,tooltip:l,visible:s,required:c,fixed:p,fold:f,options:m}},d||o]});return exports.unEscapeForXML(O)},Y=function(t){let r=t.children.map(a=>{let e=a.children.map(l=>L(l)).join("");return L(a,e,"form")}).join("");return L(t,r)},M=function i(t,o,r="",a=""){for(let n=0;n<t.length;n++){let e=t[n];if(e.fullName=`${r===""?"":r+"."}${e.name}`,e.fullPath=`${a===""?"":a+"-"}${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=y(require("fs-extra")),G=y(require("path")),b=y(require("lodash.template")),ee=y(require("xml")),te=y(require("@babel/core"));var he=["input","editor","select","switch","smallfile","table","mselect","switchForm","complexSelect","division"],P=i=>G.default.resolve(__dirname,`../templates/see/${i}`),N=i=>{let t=i.type;if(!he.includes(t))return"";let{label:o,name:r,tooltip:a="",visible:n="true",required:e="false",fixed:l="false",fold:s="false",options:c=""}=i,p=i.default;if(t==="table"){let m=i.keys||[];p=(i.columns||m).map(O=>N(O)).join(`
2
+ `)}else if(t==="switchForm"||t==="division")p=i.children.map(d=>N(d)).join(`
3
+ `);else{if(t==="complexSelect")return Y(i);t==="editor"?p=[JSON.stringify(p)]:p=[p]}let f=(0,ee.default)({field:[{_attr:{type:t,label:o,name:r,tooltip:a,visible:n,required:e,fixed:l,fold:s,options:c}},p].concat(p)});return H(`${f}`)},ne=function({system:t,type:o,name:r,appType:a,version:n,configFileName:e="config.local",variables:l=[],description:s}){let c=k.default.readFileSync(P("python/deploy.xml")).toString();return(0,b.default)(c,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:o,name:r,appType:a,version:n,configFileName:e,variables:(()=>l.map(p=>N(p)).join(`
4
+ `))(),description:s})},j=function(t,o){let r=k.default.readFileSync(P(`python/scripts/${t}.py`)).toString();return(0,b.default)(r,{interpolate:/{{([\s\S]+?)}}/g})(o)},T=function(t,o=[]){let{code:r}=te.default.transformFileSync(t,{babelrc:!1,plugins:[function(){return{visitor:{Literal(n){if(n.parentPath.isProperty()){let e=n.parentPath.get("key").node,l=e.name;e.type==="StringLiteral"&&(e.type="Identifier",e.name=e.value,l=e.value);let s=M(o,c=>l===c.name);if(s){if(s.fullPath.includes("complexSelect")&&(s.name=s.fullName),n.isObjectExpression()){n.node.value=`[NO_QUOTATION_MARKS]\${${s.name}}[NO_QUOTATION_MARKS]`;return}if(n.isNumericLiteral()){n.node.value=`$!{${s.name}}`;return}if(n.isBooleanLiteral()){if(n.node.type="StringLiteral",s.fullPath.includes("complexSelect")){n.node.value=`$!{${s.fullName}}`;return}n.node.value=`[NO_QUOTATION_MARKS]\${${s.name}}[NO_QUOTATION_MARKS]`}if(n.isObjectExpression()){n.node.value=`$!{${s.name}}`;return}}}},ArrayExpression(n){if(n.parentPath.isProperty()){let e=M(o,l=>n.parentPath.get("key").node.name===l.name);if(e){e.fullPath.includes("complexSelect")&&(e.name=e.fullName);let l="",s=e.keys||[],c=e.columns||s;if(e.options){l=`[NO_QUOTATION_MARKS][#foreach($row in $${e.name}) '$row' , #end][NO_QUOTATION_MARKS]`,n.node.type="StringLiteral",n.node.value=l;return}c&&c.length&&c.forEach(f=>{l+=`${f.name}: '$!{row.${f.name}}',`}),n.node.type="StringLiteral",n.node.value=`[NO_QUOTATION_MARKS][#foreach($row in $${e.name}) {${l}}, #end][NO_QUOTATION_MARKS]`}}},ObjectExpression(n){if(n.parentPath.isProperty()){let e=n.parentPath.get("key").node,l=e.name;if(e){let s=M(o,c=>l===c.name);if(s){if(n.node.type="StringLiteral",s.fullPath.includes("editor")){n.node.value=`[NO_QUOTATION_MARKS]\${${s.name}}[NO_QUOTATION_MARKS]`;return}n.node.value=`[NO_QUOTATION_MARKS]\${${s.name}}[NO_QUOTATION_MARKS]`;return}}}}}}}],retainLines:!0});return r.replace(/"\[NO_QUOTATION_MARKS](.*)\[NO_QUOTATION_MARKS]"/g,"$1")},re=function({system:t,type:o,name:r,appType:a,version:n,configFileName:e="config.local",variables:l=[],description:s,web_app_web_service_name:c,dockerImage:p}){let f=k.default.readFileSync(P("docker/deploy.xml")).toString();return(0,b.default)(f,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:o,name:r,appType:a,version:n,configFileName:e,variables:(()=>l.map(m=>N(m)).join(`
5
+ `))(),description:s,web_app_web_service_name:c,dockerImage:p})},oe=function(t){let o=k.default.readFileSync(P("docker/k8s-deploy-res.yaml")).toString();return(0,b.default)(o,{interpolate:/{{([\s\S]+?)}}/g})(t)},ie=function(t){let o=k.default.readFileSync(P("docker/Dockerfile")).toString();return(0,b.default)(o)(t)},le=function({system:t,type:o,name:r,appType:a,version:n,configFileName:e="config.local",variables:l=[],description:s}){let c=k.default.readFileSync(P("bash/deploy.xml")).toString();return(0,b.default)(c,{interpolate:/{{([\s\S]+?)}}/g})({system:t,type:o,name:r,appType:a,version:n,configFileName:e,variables:(()=>l.map(p=>N(p)).join(`
6
+ `))(),description:s})},R=function(t,o){let r=k.default.readFileSync(P(`bash/scripts/${t}.sh`)).toString();return(0,b.default)(r,{interpolate:/{{([\s\S]+?)}}/g})(o)};var u="tmp",se=function(t,o,r){let{system:a,type:n,name:e,appType:l,version:s,template:c,variables:p,configName:f,outputName:m,description:d,scriptsType:O}=o;g.default.ensureDirSync(u),g.default.ensureDirSync(`${u}/scripts`),g.default.ensureDirSync(`${u}/template`),E(m)?g.default.outputFileSync(`./${u}/template/config.local.js`,c?T(c,p):""):v(m)||v(m,e)?(f="sysconfig",g.default.outputFileSync(`./${u}/template/sysconfig.js`,c?T(c,p):"")):f&&g.default.outputFileSync(`./${u}/template/${f}.js`,c?T(c,p):""),O==="python"?(g.default.outputFileSync(`./${u}/scripts/${e}/utils.py`,j("utils")),g.default.outputFileSync(`./${u}/scripts/${e}/install.py`,j("install",{name:e,type:n})),g.default.outputFileSync(`./${u}/scripts/${e}/afterInstall.py`,j("afterInstall",{name:e})),g.default.outputFileSync(`./${u}/scripts/${e}/uninstall.py`,j("uninstall",{name:e,type:n})),g.default.outputFileSync(`./${u}/deploy.xml`,ne({system:a,type:n,name:e,appType:l,version:s,configFileName:f,variables:p,description:d}))):(g.default.outputFileSync(`./${u}/scripts/${e}/install.sh`,R("install",{name:e,type:n})),g.default.outputFileSync(`./${u}/scripts/${e}/afterInstall.sh`,R("afterInstall",{name:e})),g.default.outputFileSync(`./${u}/scripts/${e}/uninstall.sh`,R("uninstall",{name:e,type:n})),g.default.outputFileSync(`./${u}/deploy.xml`,le({system:a,type:n,name:e,appType:l,version:s,configFileName:f,variables:p,description:d}))),r?r(x=>{F(t,u,()=>{Q.default.sync(u),typeof x=="function"&&x()})}):F(t,u,()=>{Q.default.sync(u)})};var U=y(require("path")),S=y(require("fs-extra")),V=y(require("rimraf"));var $="tmp",ce=function(t,o,r){let{system:a,type:n,name:e,appType:l,version:s,template:c,variables:p,configName:f,outputName:m,description:d,dockerImage:O=s.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(U.default.resolve(process.cwd(),"docker/Dockerfile"))||S.default.outputFileSync(U.default.resolve(process.cwd(),"docker/Dockerfile"),ie({name:e,type:n})),S.default.ensureDirSync(`${$}/scripts`),S.default.ensureDirSync(`${$}/template`),E(m)?S.default.outputFileSync(`./${$}/template/${e}/config.local.js`,c?T(c,p):""):v(m)||v(m,e)?(f="sysconfig",S.default.outputFileSync(`./${$}/template/${e}/sysconfig.js`,c?T(c,p):"")):f&&S.default.outputFileSync(`./${$}/template/${e}/${f}.js`,c?T(c,p):""),S.default.outputFileSync(`./${$}/template/k8s-deploy-res.yaml`,oe({configFileName:f})),S.default.outputFileSync(`./${$}/deploy.xml`,re({system:a,type:n,name:e,appType:l,version:s,configFileName:f,variables:p,description:d,web_app_web_service_name:`${e}-web`,dockerImage:O})),r?r(x=>{F(t,$,()=>{V.default.sync($),typeof x=="function"&&x()})}):F(t,$,()=>{V.default.sync($)})};var xe=process.cwd();function Oe(i,t,o){let r="",a;if(i==="bizframe"){r=h.default.readdirSync(`./${o}`).find(n=>/manifest\.[0-9]+\.json/.test(n));try{a=h.default.readJsonSync(`./${o}/${r}`)}catch(n){process.exit(0)}}return i==="subsystem"&&(r=h.default.readdirSync(`./${o}/${t}`).find(n=>/manifest\.[0-9]+\.json/.test(n)),a=h.default.readJsonSync(`./${o}/${t}/${r}`)),{manifest:r,manifestJson:a}}var ke=function({system:t="winner-front",type:o="bizframe",name:r,appType:a,version:n,configName:e="config.local",outputName:l="dist",templateFunc:s,variablesFunc:c,copyFiles:p,description:f,seePackageName:m,seePackageType:d="web",dockerImage:O,scriptsType:x="python"},J){if(!r||!n)throw new Error("\u5E94\u7528\u540D\u79F0\u548C\u5E94\u7528\u7248\u672C\u4E0D\u80FD\u7F3A\u5931~");if(r=r.replace(/@/gi,"").replace(/\//gi,"-"),typeof m=="string"&&m&&(m=m.replace(/@/gi,"").replace(/\//gi,"-")),a=a||r,c=c||function(){try{let{variables:_}=require(pe.default.resolve(xe,"build","package","./variables.js"));return _||[]}catch(_){return console.error(_),[]}},s=s||function(){return o==="bizframe"?`./${l}/config.local.js`:`./${l}/${r}/sysconfig.js`},d==="docker"){ce(m||`${t}-${r}-${n}`,{system:t,type:o,name:r,appType:a,version:n,configName:e,outputName:l,template:s(),variables:c(),description:f,dockerImage:O},_=>{console.log(),(0,z.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(),_(J)});return}se(m||`${t}-${r}-${n}`,{system:t,type:o,name:r,appType:a,version:n,configName:e,outputName:l,template:s(),variables:c(),description:f,scriptsType:x},_=>{if(x==="python"){let{manifest:A,manifestJson:I}=Oe(o,r,l);for(let B in I)if(I.hasOwnProperty(B)){let{path:C,dir:fe}=I[B];h.default.ensureDirSync(`./tmp/source/${fe}`),h.default.copyFileSync(`./${l}/${C}`,`./tmp/source/${C}`)}h.default.outputJSONSync(`./tmp/scripts/${r}/conf/${A}`,I)}else h.default.ensureDirSync("./tmp/source"),h.default.copySync(`./${l}`,"./tmp/source");Array.isArray(p)&&p.length&&p.forEach(A=>{h.default.ensureFileSync(`./tmp/source/${r}/${A}`),h.default.copyFileSync(`./${l}/${r}/${A}`,`./tmp/source/${r}/${A}`)}),console.log(),(0,z.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${ae.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(),_(J)})};0&&(module.exports={generateSeePackageZip});
@@ -0,0 +1,130 @@
1
+ declare type variablesType = 'input' | 'select' | 'switch' | 'smallfile' | 'table' | 'mselect' | 'switchForm' | 'complexSelect' | 'division';
2
+ interface variables {
3
+ type: variablesType;
4
+ label: string;
5
+ name: string;
6
+ options: string;
7
+ required: boolean;
8
+ fold: boolean;
9
+ children: Array<variables>;
10
+ tooltip: string;
11
+ default: string;
12
+ }
13
+ interface deployOptions {
14
+ /**
15
+ * 系统类型, SEE 平台的分组是以系统类型字段纬度来的
16
+ * @default winner-front
17
+ */
18
+ system: string;
19
+ /**
20
+ * 应用类型, 外框架 - bizframe | 子系统 - subsystem
21
+ * @default bizframe
22
+ */
23
+ type: 'bizframe' | 'subsystem';
24
+ /**
25
+ * 发布物名称。当包含 scope 时,如字符 @、/ 。会做自动的转换。如@winner-fed/winner-deploy 转换为 winner-fed-winner-deploy
26
+ * @default package.json -> name
27
+ */
28
+ name: string;
29
+ /**
30
+ * 发布包版本
31
+ * @default package.json -> version
32
+ */
33
+ version: string;
34
+ /**
35
+ * 发布包的描述说明
36
+ * @default package.json -> description
37
+ */
38
+ description: string;
39
+ /**
40
+ * 发布物类型, 默认为 应用名称
41
+ * @default name
42
+ */
43
+ appType?: string;
44
+ /**
45
+ * 配置文件名称,不带有 .js。当强制为空时,可以理解成,是构建静态资源的 see 包,不包含 index.html,config.local.js 文件等,此时 scriptsType 只能使用 bash
46
+ * @default config.local
47
+ */
48
+ configName?: string;
49
+ /**
50
+ * 输出的目录名称
51
+ * @default dist
52
+ */
53
+ outputName?: string;
54
+ /**
55
+ * 自定义变量配置文件
56
+ */
57
+ templateFunc?: () => string | undefined;
58
+ /**
59
+ * deploy.xml模板变量, 可以动态配置
60
+ */
61
+ variablesFunc?: () => Array<variables> | undefined;
62
+ /**
63
+ * 不包含在 manifest.json 配置的文件,直接拷贝到 see 包里。文件路径是相对于项目根目录的路径+文件名,比如 dist/子包/version.js,那么 copyFiles: ['version.js']
64
+ */
65
+ copyFiles?: string[];
66
+ /**
67
+ * see发布物的包名,也就是 zip 包的命名
68
+ * @default `${system}-${name}-${version}`
69
+ */
70
+ seePackageName?: string;
71
+ /**
72
+ * see平台发布物包的类型,'web'(默认的) | 'docker'(支持容器化部署的SEE发布物)
73
+ * @default web
74
+ */
75
+ seePackageType?: 'web' | 'docker';
76
+ /**
77
+ * docker 容器化镜像名,seePackageType 为 docker 时生效
78
+ */
79
+ dockerImage?: string;
80
+ /**
81
+ * 脚本类型
82
+ * @default python
83
+ */
84
+ scriptsType?: 'python' | 'bash';
85
+ }
86
+ /**
87
+ * 生成 see 平台部署包
88
+ * @param system {string} 系统类型, SEE 平台的分组是以系统类型字段纬度来的, 默认为 winner-front
89
+ * @param type {string} 应用类型, 外框架 - bizframe | 子系统 - subsystem, 默认为 主系统 - bizframe
90
+ * @param name {string} 发布物名称。当包含 scope 时,如字符 @、/ 。会做自动的转换。如@winner-fed/winner-deploy 转换为 winner-fed-winner-deploy
91
+ * @param appType {string} 发布物类型, 默认为 应用名称 - name
92
+ * @param version {string} 发布包版本
93
+ * @param configName {string} 配置文件名称,不带有 .js, 默认为 config.local
94
+ * @param outputName {string} 输出的目录名称,默认为 dist
95
+ * @param templateFunc {function} 自定义变量配置文件, 默认为
96
+ * function () {
97
+ if (type === 'bizframe') {
98
+ return `./dist/config.local.js`;
99
+ }
100
+ }
101
+ * @param variablesFunc {function} deploy.xml模板变量, 可以动态配置, 默认为
102
+ * function () {
103
+ * const context = process.cwd()
104
+ if (type === 'bizframe') {
105
+ try {
106
+ const {variables} = require(path.resolve(
107
+ context,
108
+ 'build',
109
+ 'package',
110
+ `./variables.js`
111
+ ));
112
+
113
+ return variables || [];
114
+ } catch (error) {
115
+ console.error(error);
116
+ return [];
117
+ }
118
+ }
119
+ }
120
+ * @param copyFiles {Array<string>} 不包含在 manifest.json 配置的文件,直接拷贝到 see 包里。文件路径是相对于项目根目录的路径+文件名,比如 dist/子包/version.js,那么 copyFiles: ['version.js']
121
+ * @param description {string} 发布包说明
122
+ * @param seePackageName {string} see发布物的包名,也就是 zip 包的命名,默认为 `${system}-${name}-${version}`
123
+ * @param seePackageType see 平台发布物包的类型,'web'(默认的) | 'docker'(支持容器化部署的SEE发布物)
124
+ * @param dockerImage docker 容器化镜像名,seePackageType 为 docker 生效
125
+ * @param scriptsType 脚本类型 'python' | 'bash'
126
+ * @param cb {function} 回调函数,用于处理在组装 see 包后,可以自定义执行的动作
127
+ */
128
+ declare const generateSeePackageZip: ({ system, type, name, appType, version, configName, outputName, templateFunc, variablesFunc, copyFiles, description, seePackageName, seePackageType, dockerImage, scriptsType }: deployOptions, cb: () => void) => void;
129
+
130
+ export { deployOptions, generateSeePackageZip, variables, variablesType };
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ var L=(c=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(c,{get:(n,o)=>(typeof require!="undefined"?require:n)[o]}):c)(function(c){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+c+'" is not supported')});import ae from"chalk";import pe from"path";import ne from"ora";import $ from"fs-extra";import y from"fs-extra";import H from"rimraf";import Q from"path";import j from"fs-extra";import oe from"archiver";import U from"xml";var V=process.cwd(),z=function(n){let o={"&amp;":"&","&quot;":'"',"&apos;":"'","&lt;":"<","&gt;":">"};return n&&n.replace?n.replace(/(&amp;)|(&quot;)|(&apos;)|(&lt;)|(&gt;)/g,function(r){return o[r]}):n},P=function(n,o){let r=o||"",a=Q.resolve(V,n,r,"sysconfig.js");return j.pathExistsSync(a)},I=function(n){let o=Q.resolve(V,n,"config.local.js");return j.pathExistsSync(o)},v=function(n,o,r){let a="package";j.ensureDirSync(a);let t=j.createWriteStream(`${a}/${n}.zip`);t.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(t),e.directory(o,!1),e.finalize()},M=function(n,o,r){let{type:a,label:t,name:e,tooltip:i="",visible:l="true",required:s="false",fixed:p="false",fold:f="false",options:m=""}=n,g=n.default;if(r==="form"){let h=U({form:[{_attr:{name:e,tooltip:i,visible:l,required:s,fixed:p,fold:f,options:m}},o]});return exports.unEscapeForXML(h)}let x=U({field:[{_attr:{type:a,label:t,name:e,tooltip:i,visible:l,required:s,fixed:p,fold:f,options:m}},g||o]});return exports.unEscapeForXML(x)},J=function(n){let r=n.children.map(a=>{let e=a.children.map(i=>M(i)).join("");return M(a,e,"form")}).join("");return M(n,r)},w=function c(n,o,r="",a=""){for(let t=0;t<n.length;t++){let e=n[t];if(e.fullName=`${r===""?"":r+"."}${e.name}`,e.fullPath=`${a===""?"":a+"-"}${e.type}`,o(e))return e;if(e.children&&e.children.length>0){let i=c(e.children,o,e.fullName,e.fullPath);if(i)return i}}return null};import b from"fs-extra";import ie from"path";import T from"lodash.template";import le from"xml";import se from"@babel/core";var ce=["input","editor","select","switch","smallfile","table","mselect","switchForm","complexSelect","division"],_=c=>ie.resolve(__dirname,`../templates/see/${c}`),A=c=>{let n=c.type;if(!ce.includes(n))return"";let{label:o,name:r,tooltip:a="",visible:t="true",required:e="false",fixed:i="false",fold:l="false",options:s=""}=c,p=c.default;if(n==="table"){let m=c.keys||[];p=(c.columns||m).map(x=>A(x)).join(`
2
+ `)}else if(n==="switchForm"||n==="division")p=c.children.map(g=>A(g)).join(`
3
+ `);else{if(n==="complexSelect")return J(c);n==="editor"?p=[JSON.stringify(p)]:p=[p]}let f=le({field:[{_attr:{type:n,label:o,name:r,tooltip:a,visible:t,required:e,fixed:i,fold:l,options:s}},p].concat(p)});return z(`${f}`)},B=function({system:n,type:o,name:r,appType:a,version:t,configFileName:e="config.local",variables:i=[],description:l}){let s=b.readFileSync(_("python/deploy.xml")).toString();return T(s,{interpolate:/{{([\s\S]+?)}}/g})({system:n,type:o,name:r,appType:a,version:t,configFileName:e,variables:(()=>i.map(p=>A(p)).join(`
4
+ `))(),description:l})},D=function(n,o){let r=b.readFileSync(_(`python/scripts/${n}.py`)).toString();return T(r,{interpolate:/{{([\s\S]+?)}}/g})(o)},O=function(n,o=[]){let{code:r}=se.transformFileSync(n,{babelrc:!1,plugins:[function(){return{visitor:{Literal(t){if(t.parentPath.isProperty()){let e=t.parentPath.get("key").node,i=e.name;e.type==="StringLiteral"&&(e.type="Identifier",e.name=e.value,i=e.value);let l=w(o,s=>i===s.name);if(l){if(l.fullPath.includes("complexSelect")&&(l.name=l.fullName),t.isObjectExpression()){t.node.value=`[NO_QUOTATION_MARKS]\${${l.name}}[NO_QUOTATION_MARKS]`;return}if(t.isNumericLiteral()){t.node.value=`$!{${l.name}}`;return}if(t.isBooleanLiteral()){if(t.node.type="StringLiteral",l.fullPath.includes("complexSelect")){t.node.value=`$!{${l.fullName}}`;return}t.node.value=`[NO_QUOTATION_MARKS]\${${l.name}}[NO_QUOTATION_MARKS]`}if(t.isObjectExpression()){t.node.value=`$!{${l.name}}`;return}}}},ArrayExpression(t){if(t.parentPath.isProperty()){let e=w(o,i=>t.parentPath.get("key").node.name===i.name);if(e){e.fullPath.includes("complexSelect")&&(e.name=e.fullName);let i="",l=e.keys||[],s=e.columns||l;if(e.options){i=`[NO_QUOTATION_MARKS][#foreach($row in $${e.name}) '$row' , #end][NO_QUOTATION_MARKS]`,t.node.type="StringLiteral",t.node.value=i;return}s&&s.length&&s.forEach(f=>{i+=`${f.name}: '$!{row.${f.name}}',`}),t.node.type="StringLiteral",t.node.value=`[NO_QUOTATION_MARKS][#foreach($row in $${e.name}) {${i}}, #end][NO_QUOTATION_MARKS]`}}},ObjectExpression(t){if(t.parentPath.isProperty()){let e=t.parentPath.get("key").node,i=e.name;if(e){let l=w(o,s=>i===s.name);if(l){if(t.node.type="StringLiteral",l.fullPath.includes("editor")){t.node.value=`[NO_QUOTATION_MARKS]\${${l.name}}[NO_QUOTATION_MARKS]`;return}t.node.value=`[NO_QUOTATION_MARKS]\${${l.name}}[NO_QUOTATION_MARKS]`;return}}}}}}}],retainLines:!0});return r.replace(/"\[NO_QUOTATION_MARKS](.*)\[NO_QUOTATION_MARKS]"/g,"$1")},C=function({system:n,type:o,name:r,appType:a,version:t,configFileName:e="config.local",variables:i=[],description:l,web_app_web_service_name:s,dockerImage:p}){let f=b.readFileSync(_("docker/deploy.xml")).toString();return T(f,{interpolate:/{{([\s\S]+?)}}/g})({system:n,type:o,name:r,appType:a,version:t,configFileName:e,variables:(()=>i.map(m=>A(m)).join(`
5
+ `))(),description:l,web_app_web_service_name:s,dockerImage:p})},q=function(n){let o=b.readFileSync(_("docker/k8s-deploy-res.yaml")).toString();return T(o,{interpolate:/{{([\s\S]+?)}}/g})(n)},W=function(n){let o=b.readFileSync(_("docker/Dockerfile")).toString();return T(o)(n)},Z=function({system:n,type:o,name:r,appType:a,version:t,configFileName:e="config.local",variables:i=[],description:l}){let s=b.readFileSync(_("bash/deploy.xml")).toString();return T(s,{interpolate:/{{([\s\S]+?)}}/g})({system:n,type:o,name:r,appType:a,version:t,configFileName:e,variables:(()=>i.map(p=>A(p)).join(`
6
+ `))(),description:l})},E=function(n,o){let r=b.readFileSync(_(`bash/scripts/${n}.sh`)).toString();return T(r,{interpolate:/{{([\s\S]+?)}}/g})(o)};var u="tmp",Y=function(n,o,r){let{system:a,type:t,name:e,appType:i,version:l,template:s,variables:p,configName:f,outputName:m,description:g,scriptsType:x}=o;y.ensureDirSync(u),y.ensureDirSync(`${u}/scripts`),y.ensureDirSync(`${u}/template`),I(m)?y.outputFileSync(`./${u}/template/config.local.js`,s?O(s,p):""):P(m)||P(m,e)?(f="sysconfig",y.outputFileSync(`./${u}/template/sysconfig.js`,s?O(s,p):"")):f&&y.outputFileSync(`./${u}/template/${f}.js`,s?O(s,p):""),x==="python"?(y.outputFileSync(`./${u}/scripts/${e}/utils.py`,D("utils")),y.outputFileSync(`./${u}/scripts/${e}/install.py`,D("install",{name:e,type:t})),y.outputFileSync(`./${u}/scripts/${e}/afterInstall.py`,D("afterInstall",{name:e})),y.outputFileSync(`./${u}/scripts/${e}/uninstall.py`,D("uninstall",{name:e,type:t})),y.outputFileSync(`./${u}/deploy.xml`,B({system:a,type:t,name:e,appType:i,version:l,configFileName:f,variables:p,description:g}))):(y.outputFileSync(`./${u}/scripts/${e}/install.sh`,E("install",{name:e,type:t})),y.outputFileSync(`./${u}/scripts/${e}/afterInstall.sh`,E("afterInstall",{name:e})),y.outputFileSync(`./${u}/scripts/${e}/uninstall.sh`,E("uninstall",{name:e,type:t})),y.outputFileSync(`./${u}/deploy.xml`,Z({system:a,type:t,name:e,appType:i,version:l,configFileName:f,variables:p,description:g}))),r?r(h=>{v(n,u,()=>{H.sync(u),typeof h=="function"&&h()})}):v(n,u,()=>{H.sync(u)})};import G from"path";import S from"fs-extra";import ee from"rimraf";var d="tmp",te=function(n,o,r){let{system:a,type:t,name:e,appType:i,version:l,template:s,variables:p,configName:f,outputName:m,description:g,dockerImage:x=l.indexOf("-")>0?`isee1.0-docker-dev-local/${e}`:`isee1.0-docker-release-local/${e}`}=o;S.ensureDirSync(d),S.ensureDirSync("docker"),S.pathExistsSync(G.resolve(process.cwd(),"docker/Dockerfile"))||S.outputFileSync(G.resolve(process.cwd(),"docker/Dockerfile"),W({name:e,type:t})),S.ensureDirSync(`${d}/scripts`),S.ensureDirSync(`${d}/template`),I(m)?S.outputFileSync(`./${d}/template/${e}/config.local.js`,s?O(s,p):""):P(m)||P(m,e)?(f="sysconfig",S.outputFileSync(`./${d}/template/${e}/sysconfig.js`,s?O(s,p):"")):f&&S.outputFileSync(`./${d}/template/${e}/${f}.js`,s?O(s,p):""),S.outputFileSync(`./${d}/template/k8s-deploy-res.yaml`,q({configFileName:f})),S.outputFileSync(`./${d}/deploy.xml`,C({system:a,type:t,name:e,appType:i,version:l,configFileName:f,variables:p,description:g,web_app_web_service_name:`${e}-web`,dockerImage:x})),r?r(h=>{v(n,d,()=>{ee.sync(d),typeof h=="function"&&h()})}):v(n,d,()=>{ee.sync(d)})};var fe=process.cwd();function me(c,n,o){let r="",a;if(c==="bizframe"){r=$.readdirSync(`./${o}`).find(t=>/manifest\.[0-9]+\.json/.test(t));try{a=$.readJsonSync(`./${o}/${r}`)}catch(t){process.exit(0)}}return c==="subsystem"&&(r=$.readdirSync(`./${o}/${n}`).find(t=>/manifest\.[0-9]+\.json/.test(t)),a=$.readJsonSync(`./${o}/${n}/${r}`)),{manifest:r,manifestJson:a}}var Ve=function({system:n="winner-front",type:o="bizframe",name:r,appType:a,version:t,configName:e="config.local",outputName:i="dist",templateFunc:l,variablesFunc:s,copyFiles:p,description:f,seePackageName:m,seePackageType:g="web",dockerImage:x,scriptsType:h="python"},R){if(!r||!t)throw new Error("\u5E94\u7528\u540D\u79F0\u548C\u5E94\u7528\u7248\u672C\u4E0D\u80FD\u7F3A\u5931~");if(r=r.replace(/@/gi,"").replace(/\//gi,"-"),typeof m=="string"&&m&&(m=m.replace(/@/gi,"").replace(/\//gi,"-")),a=a||r,s=s||function(){try{let{variables:k}=L(pe.resolve(fe,"build","package","./variables.js"));return k||[]}catch(k){return console.error(k),[]}},l=l||function(){return o==="bizframe"?`./${i}/config.local.js`:`./${i}/${r}/sysconfig.js`},g==="docker"){te(m||`${n}-${r}-${t}`,{system:n,type:o,name:r,appType:a,version:t,configName:e,outputName:i,template:l(),variables:s(),description:f,dockerImage:x},k=>{console.log(),ne("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(R)});return}Y(m||`${n}-${r}-${t}`,{system:n,type:o,name:r,appType:a,version:t,configName:e,outputName:i,template:l(),variables:s(),description:f,scriptsType:h},k=>{if(h==="python"){let{manifest:F,manifestJson:N}=me(o,r,i);for(let X in N)if(N.hasOwnProperty(X)){let{path:K,dir:re}=N[X];$.ensureDirSync(`./tmp/source/${re}`),$.copyFileSync(`./${i}/${K}`,`./tmp/source/${K}`)}$.outputJSONSync(`./tmp/scripts/${r}/conf/${F}`,N)}else $.ensureDirSync("./tmp/source"),$.copySync(`./${i}`,"./tmp/source");Array.isArray(p)&&p.length&&p.forEach(F=>{$.ensureFileSync(`./tmp/source/${r}/${F}`),$.copyFileSync(`./${i}/${r}/${F}`,`./tmp/source/${r}/${F}`)}),console.log(),ne(`\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${ae.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(R)})};export{Ve as generateSeePackageZip};
package/package.json CHANGED
@@ -1,73 +1,60 @@
1
1
  {
2
2
  "name": "@winner-fed/winner-deploy",
3
- "version": "3.4.2",
3
+ "version": "4.0.6",
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",
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"
19
+ }
20
+ },
21
+ "typesVersions": {
22
+ "*": {
23
+ "*": [
24
+ "./dist/*",
25
+ "./dist/index.d.ts"
26
+ ]
27
+ }
28
+ },
29
+ "type": "module",
30
+ "author": "winner-fed",
31
+ "license": "MIT",
32
+ "sideEffects": false,
11
33
  "files": [
12
- "src",
34
+ "dist",
13
35
  "templates"
14
36
  ],
15
- "author": "winner-fed <cloudbroker@163.com>",
16
- "engines": {
17
- "node": ">=6.0.0"
18
- },
19
37
  "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"
36
- }
37
- },
38
- "prettier": {
39
- "semi": false,
40
- "singleQuote": true
41
- },
42
- "commitlint": {
43
- "extends": [
44
- "@commitlint/config-conventional"
45
- ]
38
+ "prepublishOnly": "npm run build",
39
+ "dev": "tsup --watch",
40
+ "build": "tsup",
41
+ "typecheck": "tsc --noEmit"
46
42
  },
47
43
  "dependencies": {
48
44
  "@babel/core": "^7.12.3",
49
45
  "archiver": "^3.1.1",
50
46
  "chalk": "^4.0.0",
51
- "fs-extra": "^8.1.0",
47
+ "fs-extra": "^10.1.0",
52
48
  "lodash.template": "^4.5.0",
53
49
  "ora": "^4.0.4",
54
50
  "rimraf": "^3.0.2",
55
51
  "xml": "^1.0.1"
56
52
  },
57
53
  "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"
54
+ "@types/fs-extra": "^9.0.13",
55
+ "@types/lodash.template": "^4.5.1",
56
+ "@types/node": "^16.10.1",
57
+ "tsup": "^4.14.0"
71
58
  },
72
59
  "publishConfig": {
73
60
  "access": "public",
@@ -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="系统全局配置" />
@@ -36,7 +36,9 @@
36
36
  <% } %>
37
37
  {{ variables }}
38
38
  </variables>
39
+ <% if (configFileName) { %>
39
40
  <config path="./${webAppName}/{{ configFileName }}.js" encoding="UTF-8"/>
41
+ <% } %>
40
42
  <config path="./scripts/{{ name }}/install.sh" encoding="UTF-8"/>
41
43
  <config path="./scripts/{{ name }}/afterInstall.sh" encoding="UTF-8"/>
42
44
  <config path="./scripts/{{ name }}/uninstall.sh" encoding="UTF-8"/>
@@ -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="系统全局配置" />
@@ -39,7 +39,9 @@
39
39
  {{ variables }}
40
40
 
41
41
  </variables>
42
+ <% if (configFileName) { %>
42
43
  <config path="./{{ name }}/{{ configFileName }}.js" encoding="UTF-8"/>
44
+ <% } %>
43
45
  <config reference="" encoding="utf-8" path="./k8s-deploy-res.yaml" />
44
46
  <node describe="节点私有配置信息" />
45
47
  </system>
@@ -7,9 +7,9 @@ metadata:
7
7
  name: ${svc_id}-service
8
8
  spec:
9
9
  ports:
10
- - name: "http"
11
- port: 80
12
- targetPort: 80
10
+ - name: 'http'
11
+ port: 80
12
+ targetPort: 80
13
13
  selector:
14
14
  name: ${svc_id}
15
15
  ---
@@ -29,10 +29,10 @@ spec:
29
29
  name: ${svc_id}
30
30
  spec:
31
31
  imagePullPolicy: ${image_pull_policy}
32
- #if(${image_pull_secrets_enable} == "true")
32
+ #if(${image_pull_secrets_enable} == "true")
33
33
  imagePullSecrets:
34
- - name: ${image_pull_secrets}
35
- #end
34
+ - name: ${image_pull_secrets}
35
+ #end
36
36
  restartPolicy: ${restart_policy}
37
37
  hostname: ${web_app_web_service_name}
38
38
  containers:
@@ -43,7 +43,7 @@ spec:
43
43
  value: Asia/Shanghai
44
44
  ports:
45
45
  - containerPort: 80
46
- #if(${resources_enable} == "true")
46
+ #if(${resources_enable} == "true")
47
47
  resources:
48
48
  requests:
49
49
  cpu: ${cpu_req}
@@ -51,8 +51,8 @@ spec:
51
51
  limits:
52
52
  cpu: ${cpu_limit}
53
53
  memory: ${memory_limit}
54
- #end
55
- #if(${liveness_probe_enable} == "true")
54
+ #end
55
+ #if(${liveness_probe_enable} == "true")
56
56
  livenessProbe:
57
57
  httpGet:
58
58
  scheme: HTTP
@@ -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="系统全局配置" />
@@ -37,7 +37,9 @@
37
37
  {{ variables }}
38
38
 
39
39
  </variables>
40
+ <% if (configFileName) { %>
40
41
  <config path="./${webAppName}/{{ configFileName }}.js" encoding="UTF-8"/>
42
+ <% } %>
41
43
  <config path="./scripts/{{ name }}/install.py" encoding="UTF-8"/>
42
44
  <config path="./scripts/{{ name }}/afterInstall.py" encoding="UTF-8"/>
43
45
  <config path="./scripts/{{ name }}/uninstall.py" encoding="UTF-8"/>
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 winner-fed
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -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
- }