@lazycatcloud/lzc-cli 1.3.7 → 1.3.9
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 +8 -0
- package/lib/appstore/index.js +50 -39
- package/lib/utils.js +14 -7
- package/package.json +1 -1
- package/scripts/cli.js +1 -0
- package/template/_lpk/manifest.yml.in +1 -1
package/changelog.md
CHANGED
package/lib/appstore/index.js
CHANGED
|
@@ -68,13 +68,13 @@ export function appstoreCommand(program) {
|
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
|
-
command: "copy-image <
|
|
72
|
-
desc: "
|
|
73
|
-
handler: async ({ imageName }) => {
|
|
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}`
|
|
71
|
+
command: "copy-image <img> <arch>",
|
|
72
|
+
desc: `复制镜像至懒猫微服官方源\n - <img> NAME[:TAG]\n - <arch>: 'amd64', 'arm64' [字符串] [默认值: "amd64"]`,
|
|
73
|
+
handler: async ({ img: imageName, arch: platform }) => {
|
|
74
|
+
const uploadUrl = `${appStoreServerUrl}/api/v3/developer/app/docker/image/push/v3/copy?image=${imageName}&platform=${platform}`
|
|
75
|
+
const progressUrl = `${appStoreServerUrl}/api/v3/developer/app/docker/image/push/v3/progress?image=${imageName}&platform=${platform}`
|
|
76
76
|
logger.info(
|
|
77
|
-
`Waiting ... ( copy ${imageName} to lazycat offical registry)`
|
|
77
|
+
`Waiting ... ( copy ${imageName} (${platform}) to lazycat offical registry)`
|
|
78
78
|
)
|
|
79
79
|
try {
|
|
80
80
|
const resp = await request(uploadUrl)
|
|
@@ -85,61 +85,69 @@ export function appstoreCommand(program) {
|
|
|
85
85
|
return
|
|
86
86
|
}
|
|
87
87
|
sleep(1000)
|
|
88
|
-
let prevLineCount = 0
|
|
88
|
+
let prevLineCount = 0 // 新增:记录上次输出行数
|
|
89
89
|
let layers = []
|
|
90
90
|
|
|
91
91
|
let refreshProgress = (lys) => {
|
|
92
92
|
// 关键修改:动态回退多行
|
|
93
|
-
process.stdout.write(
|
|
93
|
+
process.stdout.write("\x1B[?25l") // 隐藏光标
|
|
94
94
|
if (prevLineCount > 0) {
|
|
95
|
-
process.stdout.write(`\x1B[${prevLineCount}A`)
|
|
95
|
+
process.stdout.write(`\x1B[${prevLineCount}A`) // 移动光标到之前输出的起始行
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
// 构建多行进度字符串
|
|
99
|
-
let output = []
|
|
100
|
-
(lys || []).forEach(v => {
|
|
101
|
-
const progressBar =
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
let output = []
|
|
100
|
+
;(lys || []).forEach((v) => {
|
|
101
|
+
const progressBar =
|
|
102
|
+
"#".repeat(v.progress) + " ".repeat(100 - v.progress)
|
|
103
|
+
output.push(
|
|
104
|
+
`${v.hash.substring(0, 8)}: [${progressBar}] ${v.progress}%`
|
|
105
|
+
)
|
|
106
|
+
})
|
|
104
107
|
|
|
105
108
|
// 清除旧行并写入新内容
|
|
106
|
-
output.forEach(line => {
|
|
107
|
-
process.stdout.write(
|
|
108
|
-
process.stdout.write(line +
|
|
109
|
-
})
|
|
110
|
-
prevLineCount = output.length
|
|
111
|
-
process.stdout.write(
|
|
109
|
+
output.forEach((line) => {
|
|
110
|
+
process.stdout.write("\x1B[2K") // 清除当前行
|
|
111
|
+
process.stdout.write(line + "\n")
|
|
112
|
+
})
|
|
113
|
+
prevLineCount = output.length // 记录本次输出行数
|
|
114
|
+
process.stdout.write("\x1B[?25h") // 恢复光标显示
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
for (
|
|
115
|
-
const pgsResp = await request(progressUrl)
|
|
117
|
+
for (;;) {
|
|
118
|
+
const pgsResp = await request(progressUrl)
|
|
116
119
|
if (pgsResp.ok) {
|
|
117
|
-
const pgs = JSON.parse(await pgsResp.text())
|
|
120
|
+
const pgs = JSON.parse(await pgsResp.text())
|
|
118
121
|
if (pgs.finished) {
|
|
119
|
-
(layers ? layers : [])?.forEach(v => {
|
|
122
|
+
;(layers ? layers : [])?.forEach((v) => {
|
|
120
123
|
v.progress = 100
|
|
121
|
-
})
|
|
124
|
+
})
|
|
122
125
|
refreshProgress(layers)
|
|
123
|
-
process.stdout.write("\n")
|
|
126
|
+
process.stdout.write("\n")
|
|
124
127
|
if (pgs.errmsg) {
|
|
125
|
-
logger.error(
|
|
126
|
-
|
|
128
|
+
logger.error(
|
|
129
|
+
"failed to copyimage ",
|
|
130
|
+
imageName,
|
|
131
|
+
" err:",
|
|
132
|
+
pgs.errmsg
|
|
133
|
+
)
|
|
134
|
+
break
|
|
127
135
|
}
|
|
128
|
-
logger.info("uploaded: ", pgs.lzc_image)
|
|
129
|
-
break
|
|
136
|
+
logger.info("uploaded: ", pgs.lzc_image)
|
|
137
|
+
break
|
|
130
138
|
}
|
|
131
139
|
layers = pgs?.layers
|
|
132
140
|
refreshProgress(layers)
|
|
133
|
-
await sleep(1000)
|
|
141
|
+
await sleep(1000)
|
|
134
142
|
} else {
|
|
135
|
-
logger.error("error: ", await resp.text())
|
|
136
|
-
break
|
|
143
|
+
logger.error("error: ", await resp.text())
|
|
144
|
+
break
|
|
137
145
|
}
|
|
138
146
|
}
|
|
139
147
|
} catch (err) {
|
|
140
148
|
console.error(err)
|
|
141
149
|
}
|
|
142
|
-
}
|
|
150
|
+
}
|
|
143
151
|
},
|
|
144
152
|
{
|
|
145
153
|
command: "my-images",
|
|
@@ -151,17 +159,20 @@ export function appstoreCommand(program) {
|
|
|
151
159
|
if (resp.ok) {
|
|
152
160
|
const ilist = JSON.parse(await resp.text())
|
|
153
161
|
ilist.sort((a, b) => {
|
|
154
|
-
return
|
|
162
|
+
return (
|
|
163
|
+
new Date(b.UpdatedAt).getTime() -
|
|
164
|
+
new Date(a.UpdatedAt).getTime()
|
|
165
|
+
)
|
|
155
166
|
})
|
|
156
167
|
const tableItems = []
|
|
157
|
-
ilist?.forEach(v => {
|
|
168
|
+
ilist?.forEach((v) => {
|
|
158
169
|
if (v.errmsg) {
|
|
159
170
|
return
|
|
160
171
|
}
|
|
161
172
|
tableItems.push({
|
|
162
173
|
"Source Image": v.source_image,
|
|
163
174
|
"Lazycat Image": v.lzc_image,
|
|
164
|
-
"Updated At": new Date(v.UpdatedAt).toLocaleString()
|
|
175
|
+
"Updated At": new Date(v.UpdatedAt).toLocaleString()
|
|
165
176
|
})
|
|
166
177
|
})
|
|
167
178
|
console.table(tableItems)
|
|
@@ -171,8 +182,8 @@ export function appstoreCommand(program) {
|
|
|
171
182
|
} catch (err) {
|
|
172
183
|
console.error(err)
|
|
173
184
|
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
176
187
|
]
|
|
177
188
|
|
|
178
189
|
program.command({
|
package/lib/utils.js
CHANGED
|
@@ -178,16 +178,23 @@ export function fakeLoadManifestYml(file) {
|
|
|
178
178
|
subdomain: undefined,
|
|
179
179
|
},
|
|
180
180
|
}
|
|
181
|
+
|
|
181
182
|
res.split("\n").forEach(v => {
|
|
182
|
-
let line = v.trim()
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
let line = v.trim()
|
|
184
|
+
const arr = line.split(":")
|
|
185
|
+
if (arr.length != 2) {
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
let [key, value] = arr
|
|
189
|
+
value = value.trim()
|
|
190
|
+
if (!obj.package && key == "package") {
|
|
191
|
+
obj.package = value
|
|
185
192
|
}
|
|
186
|
-
if (!obj.application.subdomain &&
|
|
187
|
-
obj.application.subdomain =
|
|
193
|
+
if (!obj.application.subdomain && key == "subdomain") {
|
|
194
|
+
obj.application.subdomain = value
|
|
188
195
|
}
|
|
189
|
-
if (!obj.version &&
|
|
190
|
-
obj.version =
|
|
196
|
+
if (!obj.version && key == "version") {
|
|
197
|
+
obj.version = value
|
|
191
198
|
}
|
|
192
199
|
})
|
|
193
200
|
return obj
|
package/package.json
CHANGED
package/scripts/cli.js
CHANGED