@lazycatcloud/lzc-cli 1.3.2 → 1.3.4
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 +9 -0
- package/lib/app/lpk_build.js +34 -2
- package/lib/appstore/index.js +91 -16
- package/package.json +1 -1
package/changelog.md
CHANGED
package/lib/app/lpk_build.js
CHANGED
|
@@ -4,6 +4,7 @@ import logger from "loglevel"
|
|
|
4
4
|
import {
|
|
5
5
|
loadFromYaml,
|
|
6
6
|
isDirExist,
|
|
7
|
+
isDirSync,
|
|
7
8
|
isFileExist,
|
|
8
9
|
dumpToYaml,
|
|
9
10
|
envTemplateFile,
|
|
@@ -255,6 +256,8 @@ export class LpkBuild {
|
|
|
255
256
|
|
|
256
257
|
const tempDir = fs.mkdtempSync(".lzc-cli-build")
|
|
257
258
|
let contentdir = this.options["contentdir"]
|
|
259
|
+
let browserExtension = this.options["browser-extension"]
|
|
260
|
+
let aiPodService = this.options["ai-pod-service"]
|
|
258
261
|
try {
|
|
259
262
|
if (contentdir) {
|
|
260
263
|
contentdir = path.resolve(this.pwd, contentdir)
|
|
@@ -283,6 +286,32 @@ export class LpkBuild {
|
|
|
283
286
|
fs.rmSync(contentdir, { recursive: true })
|
|
284
287
|
}
|
|
285
288
|
|
|
289
|
+
if (browserExtension) {
|
|
290
|
+
browserExtension = path.resolve(this.pwd, browserExtension)
|
|
291
|
+
|
|
292
|
+
if (isDirSync(browserExtension)) {
|
|
293
|
+
// 开始打包 browserExtensionDir,这里打包成 zip 包
|
|
294
|
+
await archiveFolderTo(
|
|
295
|
+
browserExtension,
|
|
296
|
+
path.join(tempDir, "extension.zip")
|
|
297
|
+
)
|
|
298
|
+
} else if (isFileExist(browserExtension)) {
|
|
299
|
+
fs.copyFileSync(browserExtension, path.join(tempDir, "extension.zip"))
|
|
300
|
+
} else {
|
|
301
|
+
throw `${browserExtension} 不存在`
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (aiPodService) {
|
|
306
|
+
aiPodService = path.resolve(this.pwd, aiPodService)
|
|
307
|
+
if (!isDirExist(aiPodService)) {
|
|
308
|
+
throw `${aiPodService} 不存在`
|
|
309
|
+
}
|
|
310
|
+
fs.cpSync(aiPodService, path.join(tempDir, "ai-pod-service"), {
|
|
311
|
+
recursive: true
|
|
312
|
+
})
|
|
313
|
+
}
|
|
314
|
+
|
|
286
315
|
// 开始生成 manifest.yml
|
|
287
316
|
let manifest = await this.getManifest()
|
|
288
317
|
if (process.env.LZC_VERSION) {
|
|
@@ -306,8 +335,11 @@ export class LpkBuild {
|
|
|
306
335
|
}
|
|
307
336
|
|
|
308
337
|
// compose.override.yml
|
|
309
|
-
if (this.options[
|
|
310
|
-
dumpToYaml(
|
|
338
|
+
if (this.options["compose_override"]) {
|
|
339
|
+
dumpToYaml(
|
|
340
|
+
this.options["compose_override"],
|
|
341
|
+
path.join(tempDir, "compose.override.yml")
|
|
342
|
+
)
|
|
311
343
|
}
|
|
312
344
|
|
|
313
345
|
// 打包 lpk
|
package/lib/appstore/index.js
CHANGED
|
@@ -71,33 +71,108 @@ export function appstoreCommand(program) {
|
|
|
71
71
|
command: "copy-image <imageName>",
|
|
72
72
|
desc: "复制镜像至懒猫微服官方源",
|
|
73
73
|
handler: async ({ imageName }) => {
|
|
74
|
-
const
|
|
74
|
+
const uploadUrl = `${appStoreServerUrl}/api/v3/developer/app/docker/image/push/v3/copy?image=${imageName}`
|
|
75
|
+
const progressUrl = `${appStoreServerUrl}/api/v3/developer/app/docker/image/push/v3/progress?image=${imageName}`
|
|
75
76
|
logger.info(
|
|
76
77
|
`Waiting ... ( copy ${imageName} to lazycat offical registry)`
|
|
77
78
|
)
|
|
78
79
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
const resp = await request(uploadUrl)
|
|
81
|
+
if (resp.ok) {
|
|
82
|
+
logger.info("uploading")
|
|
83
|
+
} else {
|
|
84
|
+
logger.error("error: ", resp, await resp.text())
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
sleep(1000)
|
|
88
|
+
let prevLineCount = 0; // 新增:记录上次输出行数
|
|
89
|
+
let layers = []
|
|
90
|
+
|
|
91
|
+
let refreshProgress = (lys) => {
|
|
92
|
+
// 关键修改:动态回退多行
|
|
93
|
+
process.stdout.write('\x1B[?25l'); // 隐藏光标
|
|
94
|
+
if (prevLineCount > 0) {
|
|
95
|
+
process.stdout.write(`\x1B[${prevLineCount}A`); // 移动光标到之前输出的起始行
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 构建多行进度字符串
|
|
99
|
+
let output = [];
|
|
100
|
+
(lys || []).forEach(v => {
|
|
101
|
+
const progressBar = '#'.repeat(v.progress) + ' '.repeat(100 - v.progress);
|
|
102
|
+
output.push(`${v.hash.substring(0, 8)}: [${progressBar}] ${v.progress}%`);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// 清除旧行并写入新内容
|
|
106
|
+
output.forEach(line => {
|
|
107
|
+
process.stdout.write('\x1B[2K'); // 清除当前行
|
|
108
|
+
process.stdout.write(line + '\n');
|
|
109
|
+
});
|
|
110
|
+
prevLineCount = output.length; // 记录本次输出行数
|
|
111
|
+
process.stdout.write('\x1B[?25h'); // 恢复光标显示
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (; ;) {
|
|
115
|
+
const pgsResp = await request(progressUrl);
|
|
116
|
+
if (pgsResp.ok) {
|
|
117
|
+
const pgs = JSON.parse(await pgsResp.text());
|
|
118
|
+
if (pgs.finished) {
|
|
119
|
+
(layers ? layers : [])?.forEach(v => {
|
|
120
|
+
v.progress = 100
|
|
121
|
+
});
|
|
122
|
+
refreshProgress(layers)
|
|
123
|
+
process.stdout.write("\n");
|
|
124
|
+
if (pgs.errmsg) {
|
|
125
|
+
logger.error("failed to copyimage ", imageName, " err:", pgs.errmsg);
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
logger.info("uploaded: ", pgs.lzc_image);
|
|
129
|
+
break;
|
|
88
130
|
}
|
|
89
|
-
|
|
131
|
+
layers = pgs?.layers
|
|
132
|
+
refreshProgress(layers)
|
|
133
|
+
await sleep(1000);
|
|
90
134
|
} else {
|
|
91
|
-
logger.error("error: ", await resp.text())
|
|
135
|
+
logger.error("error: ", await resp.text());
|
|
136
|
+
break;
|
|
92
137
|
}
|
|
93
|
-
|
|
94
|
-
break
|
|
95
138
|
}
|
|
96
139
|
} catch (err) {
|
|
97
140
|
console.error(err)
|
|
98
141
|
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
command: "my-images",
|
|
146
|
+
desc: "查看已上传镜像列表",
|
|
147
|
+
handler: async () => {
|
|
148
|
+
const url = `${appStoreServerUrl}/api/v3/developer/app/docker/image/push/v3/myimages`
|
|
149
|
+
try {
|
|
150
|
+
const resp = await request(url)
|
|
151
|
+
if (resp.ok) {
|
|
152
|
+
const ilist = JSON.parse(await resp.text())
|
|
153
|
+
ilist.sort((a, b) => {
|
|
154
|
+
return new Date(b.UpdatedAt).getTime() - new Date(a.UpdatedAt).getTime()
|
|
155
|
+
})
|
|
156
|
+
const tableItems = []
|
|
157
|
+
ilist?.forEach(v => {
|
|
158
|
+
if (v.errmsg) {
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
tableItems.push({
|
|
162
|
+
"Source Image": v.source_image,
|
|
163
|
+
"Lazycat Image": v.lzc_image,
|
|
164
|
+
"Updated At": new Date(v.UpdatedAt).toLocaleString(),
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
console.table(tableItems)
|
|
168
|
+
} else {
|
|
169
|
+
logger.error("error: ", await resp.text())
|
|
170
|
+
}
|
|
171
|
+
} catch (err) {
|
|
172
|
+
console.error(err)
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
},
|
|
101
176
|
]
|
|
102
177
|
|
|
103
178
|
program.command({
|