@lazycatcloud/lzc-cli 1.3.12 → 1.3.14
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/changelog.md +21 -0
- package/lib/app/apkshell.js +37 -40
- package/lib/app/index.js +187 -186
- package/lib/app/lpk_build.js +345 -358
- package/lib/app/lpk_create.js +136 -155
- package/lib/app/lpk_create_generator.js +77 -66
- package/lib/app/lpk_devshell.js +444 -533
- package/lib/app/lpk_devshell_docker.js +48 -47
- package/lib/app/lpk_installer.js +120 -123
- package/lib/appstore/index.js +245 -214
- package/lib/appstore/login.js +146 -143
- package/lib/appstore/prePublish.js +101 -100
- package/lib/appstore/publish.js +256 -256
- package/lib/box/index.js +82 -77
- package/lib/config/index.js +59 -54
- package/lib/debug_bridge.js +282 -330
- package/lib/docker/index.js +84 -86
- package/lib/i18n/README.md +25 -0
- package/lib/i18n/index.js +37 -0
- package/lib/i18n/locales/en/translation.json +252 -0
- package/lib/i18n/locales/zh/translation.json +252 -0
- package/lib/shellapi.js +122 -146
- package/lib/utils.js +539 -552
- package/package.json +6 -8
- package/scripts/cli.js +81 -77
- package/scripts/lzc-docker-compose.js +34 -33
- package/scripts/lzc-docker.js +34 -33
package/lib/app/lpk_build.js
CHANGED
|
@@ -1,376 +1,363 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import fs from
|
|
3
|
-
import logger from
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import logger from 'loglevel';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from
|
|
18
|
-
import spawn from
|
|
19
|
-
import { LpkManifest } from
|
|
20
|
-
import archiver from
|
|
21
|
-
import yaml from
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
5
|
+
loadFromYaml,
|
|
6
|
+
isDirExist,
|
|
7
|
+
isDirSync,
|
|
8
|
+
isFileExist,
|
|
9
|
+
dumpToYaml,
|
|
10
|
+
envTemplateFile,
|
|
11
|
+
isValidPackageName,
|
|
12
|
+
tarContentDir,
|
|
13
|
+
isPngWithFile,
|
|
14
|
+
isMacOs,
|
|
15
|
+
isWindows,
|
|
16
|
+
isLinux,
|
|
17
|
+
} from '../utils.js';
|
|
18
|
+
import spawn from 'cross-spawn';
|
|
19
|
+
import { LpkManifest } from './lpk_create.js';
|
|
20
|
+
import archiver from 'archiver';
|
|
21
|
+
import yaml from 'js-yaml';
|
|
22
|
+
import { t } from '../i18n/index.js';
|
|
23
|
+
|
|
24
|
+
async function archiveFolderTo(appDir, out, format = 'zip') {
|
|
25
|
+
return new Promise(async (resolve, reject) => {
|
|
26
|
+
if (!fs.existsSync(appDir)) {
|
|
27
|
+
reject(new Error(t('lzc_cli.lib.app.lpk_build.archive_folder_to_exist_fail', `{{appDir}} 文件夹不存在`, { appDir, interpolation: { escapeValue: false } })));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
logger.debug('start archive app ...');
|
|
32
|
+
const output = fs.createWriteStream(out);
|
|
33
|
+
const archive = archiver(format);
|
|
34
|
+
|
|
35
|
+
archive.on('error', (e) => {
|
|
36
|
+
reject(e);
|
|
37
|
+
logger.error(e);
|
|
38
|
+
});
|
|
39
|
+
archive.on('end', () => {
|
|
40
|
+
resolve(output);
|
|
41
|
+
});
|
|
42
|
+
archive.pipe(output);
|
|
43
|
+
|
|
44
|
+
archive.directory(appDir, false);
|
|
45
|
+
archive.finalize();
|
|
46
|
+
});
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
async function fetchIconTo(options, cwd, destDir) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
50
|
+
if (!options['icon']) {
|
|
51
|
+
logger.warn(t('lzc_cli.lib.app.lpk_build.fetch_icon_to_icon_empty_fail', '图标icon 没有指定'));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let iconPath = options['icon'];
|
|
56
|
+
if (path.extname(iconPath) !== '.png') {
|
|
57
|
+
logger.warn(t('lzc_cli.lib.app.lpk_build.fetch_icon_to_icon_extname_fail', '图标icon 不是一个 .png 文件'));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!path.isAbsolute(iconPath)) {
|
|
62
|
+
iconPath = path.resolve(cwd, iconPath);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!isFileExist(iconPath)) {
|
|
66
|
+
logger.warn(t('lzc_cli.lib.app.lpk_build.fetch_icon_to_icon_file_not_exist_fail', `图标icon {{ iconPath }} 不存在`, { iconPath, interpolation: { escapeValue: false } }));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!isPngWithFile(iconPath)) {
|
|
71
|
+
logger.warn(t('lzc_cli.lib.app.lpk_build.fetch_icon_to_icon_not_is_png_fail', `图标icon {{ iconPath }} 验证失败(不是一个png格式)`, { iconPath, interpolation: { escapeValue: false } }));
|
|
72
|
+
return;
|
|
73
|
+
} else {
|
|
74
|
+
logger.debug(t('lzc_cli.lib.app.lpk_build.fetch_icon_to_icon_is_png', `图标icon {{ iconPath }} 验证成功(png格式)`, { iconPath, interpolation: { escapeValue: false } }));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fs.copyFileSync(iconPath, path.join(destDir, 'icon.png'));
|
|
78
|
+
return;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
async function fetchLzcDeployParamTo(options, cwd, destDir) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
82
|
+
let deployParamsPath = options['deploy_params'];
|
|
83
|
+
if (!deployParamsPath) {
|
|
84
|
+
logger.debug('deploy_params not specified');
|
|
85
|
+
let cwdDeployParamsPath = path.join(cwd, 'lzc-deploy-params.yml');
|
|
86
|
+
if (isFileExist(cwdDeployParamsPath)) {
|
|
87
|
+
deployParamsPath = cwdDeployParamsPath;
|
|
88
|
+
logger.debug(t('lzc_cli.lib.app.lpk_build.fetch_lzc_deploy_param_to_exist', '检测当前目录下具有 lzc-deploy-params.yml'));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!deployParamsPath) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!path.isAbsolute(deployParamsPath)) {
|
|
96
|
+
deployParamsPath = path.resolve(cwd, deployParamsPath);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!isFileExist(deployParamsPath)) {
|
|
100
|
+
logger.warn(t('lzc_cli.lib.app.lpk_build.fetch_lzc_deploy_param_to_not_exist', `deploy_params {{ deployParamsPath }} 不存在`, { deployParamsPath, interpolation: { escapeValue: false } }));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fs.copyFileSync(deployParamsPath, path.join(destDir, 'deploy_params.yml'));
|
|
105
|
+
return;
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
// 提供一些方便的环境变量,可以在 lzc-build.yml 中直接使用
|
|
108
109
|
// - LocalIP 本地局域网ip
|
|
109
110
|
function localIp() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
111
|
+
const regex = /inet6 (fc03:1136:[0-9a-fA-F:]+)[?:\/ ]/;
|
|
112
|
+
|
|
113
|
+
let output = '';
|
|
114
|
+
if (isMacOs) {
|
|
115
|
+
const result = spawn.sync('sh', ['-c', 'ifconfig'], {
|
|
116
|
+
encoding: 'utf-8',
|
|
117
|
+
});
|
|
118
|
+
if (result.status != 0 || result.error) {
|
|
119
|
+
logger.debug('macos get current ip is error', result.error);
|
|
120
|
+
return '';
|
|
121
|
+
}
|
|
122
|
+
output = result.stdout;
|
|
123
|
+
} else if (isWindows) {
|
|
124
|
+
logger.debug(t('lzc_cli.lib.app.lpk_build.local_ip_is_windows_fail', `当前 Windows 不支持使用 LocalIP 反代`));
|
|
125
|
+
return '';
|
|
126
|
+
} else {
|
|
127
|
+
const result = spawn.sync('ip', ['addr', 'show', 'heiyu-0'], {
|
|
128
|
+
encoding: 'utf-8',
|
|
129
|
+
});
|
|
130
|
+
if (result.status !== 0 || result.error) {
|
|
131
|
+
logger.debug('run ip addr show heiyu-0 failed', result.error);
|
|
132
|
+
return '';
|
|
133
|
+
}
|
|
134
|
+
output = result.stdout;
|
|
135
|
+
}
|
|
136
|
+
const match = output.match(regex);
|
|
137
|
+
if (match) {
|
|
138
|
+
return `[${match[1]}]`;
|
|
139
|
+
} else {
|
|
140
|
+
logger.debug('get LocalIP environment error', output.stderr);
|
|
141
|
+
return '';
|
|
142
|
+
}
|
|
142
143
|
}
|
|
143
144
|
function convenientEnv() {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
return Object.assign(
|
|
146
|
+
{},
|
|
147
|
+
{
|
|
148
|
+
LocalIP: localIp(),
|
|
149
|
+
},
|
|
150
|
+
process.env,
|
|
151
|
+
);
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
export class LpkBuild {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
packName = path.resolve(
|
|
363
|
-
pkgout,
|
|
364
|
-
`${manifest.package}-v${manifest.version}.lpk`
|
|
365
|
-
)
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
const lpkPath = await archiveFolderTo(tempDir, packName)
|
|
369
|
-
logger.info(`输出lpk包 ${lpkPath.path}`)
|
|
370
|
-
|
|
371
|
-
return lpkPath.path
|
|
372
|
-
} finally {
|
|
373
|
-
fs.rmSync(tempDir, { recursive: true })
|
|
374
|
-
}
|
|
375
|
-
}
|
|
155
|
+
constructor(cwd, buildConfigFile) {
|
|
156
|
+
this.pwd = cwd ?? process.cwd();
|
|
157
|
+
|
|
158
|
+
this.optionsFilePath = path.join(this.pwd, buildConfigFile);
|
|
159
|
+
this.options = loadFromYaml(this.optionsFilePath);
|
|
160
|
+
|
|
161
|
+
this.manifestFilePath = this.options['manifest'] ? path.join(this.pwd, this.options['manifest']) : path.join(this.pwd, 'lzc-manifest.yml');
|
|
162
|
+
this.manifest = null;
|
|
163
|
+
|
|
164
|
+
this.beforeBuildPackageFn = [];
|
|
165
|
+
this.beforeDumpYamlFn = [];
|
|
166
|
+
this.beforeTarContentFn = [];
|
|
167
|
+
this.beforeDumpLpkFn = [fetchIconTo, fetchLzcDeployParamTo];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// init 时替换 lzc-build.yml 中的模板字段
|
|
171
|
+
async init() {
|
|
172
|
+
const manifest = await this.getManifest();
|
|
173
|
+
const primitive = convenientEnv();
|
|
174
|
+
this.options = yaml.load(await envTemplateFile(this.optionsFilePath, Object.assign({}, primitive, manifest)));
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// onBeforeDumpYaml
|
|
179
|
+
// fn: function(manifest, options) => manifest
|
|
180
|
+
onBeforeDumpYaml(fn) {
|
|
181
|
+
this.beforeDumpYamlFn.push(fn);
|
|
182
|
+
}
|
|
183
|
+
// onBeforeTarContent
|
|
184
|
+
// fn: function(contentdir, options) => void
|
|
185
|
+
onBeforeTarContent(fn) {
|
|
186
|
+
this.beforeTarContentFn.push(fn);
|
|
187
|
+
}
|
|
188
|
+
// onBeforeBuildPackage
|
|
189
|
+
// fn: function(options) => options
|
|
190
|
+
onBeforeBuildPackage(fn) {
|
|
191
|
+
this.beforeBuildPackageFn.push(fn);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// onBeforeDumpLpk
|
|
195
|
+
// fn: function(options, cwd, dir) => void
|
|
196
|
+
onBeforeDumpLpk(fn) {
|
|
197
|
+
this.beforeDumpLpkFn.push(fn);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async getManifest() {
|
|
201
|
+
if (this.manifest) {
|
|
202
|
+
return this.manifest;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
let lpkM = new LpkManifest();
|
|
206
|
+
await lpkM.init(this.manifestFilePath);
|
|
207
|
+
this.manifest = lpkM.manifest;
|
|
208
|
+
// manifest使用 text/template模板时,标记为异常manifest
|
|
209
|
+
// 创建lpk时,直接将源文件拷入 lpk
|
|
210
|
+
this.excpManifest = lpkM.excpManifest;
|
|
211
|
+
|
|
212
|
+
if (!isValidPackageName(this.manifest['package'])) {
|
|
213
|
+
throw t('lzc_cli.lib.app.lpk_build.get_manifest_package_name_fail', `{{ package }} 含有非法字符,请使用正确的包名格式(java的包名格式),如:cloud.lazycat.apps.video`, {
|
|
214
|
+
package: this.manifest['package'],
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!this.manifest['application']['subdomain']) {
|
|
219
|
+
throw t('lzc_cli.lib.app.lpk_build.get_manifest_subdomain_empty', `application 模块下的 subdomain 字段不能为空`);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return this.manifest;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async exec() {
|
|
226
|
+
if (this.beforeBuildPackageFn.length > 0) {
|
|
227
|
+
this.options = await this.beforeBuildPackageFn.reduce(async (prev, curr) => {
|
|
228
|
+
return await curr(await prev);
|
|
229
|
+
}, this.options);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (this.options['buildscript']) {
|
|
233
|
+
const cmd = isWindows ? 'cmd' : 'sh';
|
|
234
|
+
const cmdArgs = isWindows ? '/c' : '-c';
|
|
235
|
+
let p = spawn.sync(cmd, [cmdArgs, this.options['buildscript']], {
|
|
236
|
+
cwd: this.pwd,
|
|
237
|
+
stdio: 'inherit',
|
|
238
|
+
});
|
|
239
|
+
if (p.status != 0) {
|
|
240
|
+
throw t('lzc_cli.lib.app.lpk_build.exec_build_fail', `构建失败`);
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
logger.warn(t('lzc_cli.lib.app.lpk_build.exec_skip_buildscript', '跳过执行 buildscript'));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 输出路径
|
|
247
|
+
let packName = this.options['lpkPath'];
|
|
248
|
+
const pkgout = path.resolve(this.pwd, this.options['pkgout']);
|
|
249
|
+
if (!packName && !isDirExist(pkgout)) {
|
|
250
|
+
throw t('lzc_cli.lib.app.lpk_build.exec_pkgout_not_exist', `{{ pkgout }} 不存在`, { pkgout, interpolation: { escapeValue: false } });
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const tempDir = fs.mkdtempSync('.lzc-cli-build');
|
|
254
|
+
let contentdir = this.options['contentdir'];
|
|
255
|
+
let browserExtension = this.options['browser-extension'];
|
|
256
|
+
let aiPodService = this.options['ai-pod-service'];
|
|
257
|
+
try {
|
|
258
|
+
if (contentdir) {
|
|
259
|
+
contentdir = path.resolve(this.pwd, contentdir);
|
|
260
|
+
if (!isDirExist(contentdir)) {
|
|
261
|
+
throw `${contentdir} 不存在`;
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
logger.warn(t('lzc_cli.lib.app.lpk_build.exec_skip_copy_contentdir', '跳过拷贝 contentdir 内容'));
|
|
265
|
+
// 当没有指定的 contentdir 的时候,也生成一个空的文件夹
|
|
266
|
+
// 原因是:可能其他地方会复制内容进来,像 devshell 中的会在打包的时候,将ssh key拷贝进来
|
|
267
|
+
contentdir = fs.mkdtempSync(path.join(tempDir, 'fake-contentdir'));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// 开始打包 contentdir
|
|
271
|
+
if (this.beforeTarContentFn.length > 0) {
|
|
272
|
+
await this.beforeTarContentFn.reduce(async (prev, curr) => {
|
|
273
|
+
let _prev = await prev;
|
|
274
|
+
await curr(_prev, this.options);
|
|
275
|
+
return _prev;
|
|
276
|
+
}, contentdir);
|
|
277
|
+
}
|
|
278
|
+
await tarContentDir(['./'], path.join(tempDir, 'content.tar'), contentdir);
|
|
279
|
+
|
|
280
|
+
// 如果是临时的 contentdir, 目录在打包完成后删除
|
|
281
|
+
if (!this.options['contentdir']) {
|
|
282
|
+
fs.rmSync(contentdir, { recursive: true });
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (browserExtension) {
|
|
286
|
+
browserExtension = path.resolve(this.pwd, browserExtension);
|
|
287
|
+
|
|
288
|
+
if (isDirSync(browserExtension)) {
|
|
289
|
+
// 开始打包 browserExtensionDir,这里打包成 zip 包
|
|
290
|
+
await archiveFolderTo(browserExtension, path.join(tempDir, 'extension.zip'));
|
|
291
|
+
} else if (isFileExist(browserExtension)) {
|
|
292
|
+
fs.copyFileSync(browserExtension, path.join(tempDir, 'extension.zip'));
|
|
293
|
+
} else {
|
|
294
|
+
throw t('lzc_cli.lib.app.lpk_build.exec_browser_extension_not_exist', `{{ browserExtension }} 不存在`, { browserExtension, interpolation: { escapeValue: false } });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (aiPodService) {
|
|
299
|
+
aiPodService = path.resolve(this.pwd, aiPodService);
|
|
300
|
+
if (!isDirExist(aiPodService)) {
|
|
301
|
+
throw t('lzc_cli.lib.app.lpk_build.exec_ai_pos_service_not_exist', `{{ aiPodService }} 不存在`, {
|
|
302
|
+
aiPodService,
|
|
303
|
+
interpolation: { escapeValue: false }
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
fs.cpSync(aiPodService, path.join(tempDir, 'ai-pod-service'), {
|
|
307
|
+
recursive: true,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// 开始生成 manifest.yml
|
|
312
|
+
let manifest = await this.getManifest();
|
|
313
|
+
if (process.env.LZC_VERSION) {
|
|
314
|
+
manifest.version = process.env.LZC_VERSION;
|
|
315
|
+
}
|
|
316
|
+
if (this.beforeDumpYamlFn.length > 0) {
|
|
317
|
+
manifest = await this.beforeDumpYamlFn.reduce(async (prev, curr) => {
|
|
318
|
+
return await curr(await prev, this.options);
|
|
319
|
+
}, manifest);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (process.env.LZC_MANIFEST_TEMPLATE) {
|
|
323
|
+
logger.debug('copy origin manifest\n', this.manifestFilePath);
|
|
324
|
+
fs.copyFileSync(this.manifestFilePath, path.join(tempDir, 'manifest.yml'));
|
|
325
|
+
} else {
|
|
326
|
+
logger.debug('manifest\n', manifest);
|
|
327
|
+
// 异常的manifest,就将源文件给转到lpk内
|
|
328
|
+
if (this.excpManifest) {
|
|
329
|
+
fs.writeFileSync(path.join(tempDir, 'manifest.yml'), fs.readFileSync(this.manifestFilePath, 'utf8'));
|
|
330
|
+
} else {
|
|
331
|
+
dumpToYaml(manifest, path.join(tempDir, 'manifest.yml'));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// compose.override.yml
|
|
336
|
+
if (this.options['compose_override']) {
|
|
337
|
+
dumpToYaml(this.options['compose_override'], path.join(tempDir, 'compose.override.yml'));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// 打包 lpk
|
|
341
|
+
if (this.beforeDumpLpkFn.length > 0) {
|
|
342
|
+
await this.beforeDumpLpkFn.reduce(async (prev, curr) => {
|
|
343
|
+
await curr(this.options, this.pwd, tempDir);
|
|
344
|
+
return prev;
|
|
345
|
+
}, {});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (!packName) {
|
|
349
|
+
packName = path.resolve(pkgout, `${manifest.package}-v${manifest.version}.lpk`);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const lpkPath = await archiveFolderTo(tempDir, packName);
|
|
353
|
+
logger.info(`${t('lzc_cli.lib.app.lpk_build.exec_output_lpk_path', '输出lpk包 {{ path }}', {
|
|
354
|
+
path: lpkPath.path,
|
|
355
|
+
interpolation: { escapeValue: false } // https://www.i18next.com/translation-function/interpolation#unescape
|
|
356
|
+
})}`);
|
|
357
|
+
|
|
358
|
+
return lpkPath.path;
|
|
359
|
+
} finally {
|
|
360
|
+
fs.rmSync(tempDir, { recursive: true });
|
|
361
|
+
}
|
|
362
|
+
}
|
|
376
363
|
}
|