@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.
@@ -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