@lazycatcloud/lzc-cli 1.3.4 → 1.3.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/changelog.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 1.3.6
2
+
3
+ 1. 处理创建的应用模板 `routes` 字段命名错误问题
4
+ 2. 支持 lzc-manifest 模板语法解析
5
+ 3. 调整开发者 ssh key 授权用户提示文案
6
+
7
+ # 1.3.5
8
+
9
+ 1. 支持自定义的公钥
10
+
1
11
  # 1.3.4
2
12
 
3
13
  1. 添加算力舱和浏览器插件打包
@@ -8,7 +8,8 @@ import {
8
8
  ensureDirectoryExists,
9
9
  dumpToYaml,
10
10
  isFileExist,
11
- isValidAppId
11
+ isValidAppId,
12
+ fakeLoadManifestYml
12
13
  } from "../utils.js"
13
14
  import path from "node:path"
14
15
  import { TemplateConfig } from "./lpk_create_generator.js"
@@ -40,7 +41,11 @@ export class LpkManifest {
40
41
  let answer = await this.askLpkInfo()
41
42
  this.manifest = yaml.load(await envTemplateFile(manifestFilePath, answer))
42
43
  } else {
43
- this.manifest = loadFromYaml(manifestFilePath)
44
+ try {
45
+ this.manifest = loadFromYaml(manifestFilePath)
46
+ } catch (err) {
47
+ this.manifest = fakeLoadManifestYml(manifestFilePath)
48
+ }
44
49
  }
45
50
  }
46
51
 
@@ -93,8 +93,8 @@ export class DebugBridge {
93
93
  ssh.status == 0
94
94
  ? resolve(ssh.stdout)
95
95
  : reject(
96
- `执行命令 ${cmd} ${args.join(" ")} 出错\n${ssh.stdout ?? ""}\n${ssh.stderr ?? ""}`
97
- )
96
+ `执行命令 ${cmd} ${args.join(" ")} 出错\n${ssh.stdout ?? ""}\n${ssh.stderr ?? ""}`
97
+ )
98
98
  })
99
99
  }
100
100
 
@@ -146,11 +146,11 @@ export class DebugBridge {
146
146
  const pk = Buffer.from(sshInfo.content.trimLeft()).toString("base64")
147
147
 
148
148
  logger.warn(
149
- `检测到您当前没有授权,请点击下面的连接在浏览器中完成授权,才能使用当前的机器的 ssh public key 访问开发者工具.
150
- -> https://${this.domain}/auth?key=${pk}
149
+ `您当前机器的公钥未添加到微服(${this.boxname})的信任列表中,请使用微服管理员账号在浏览器中访问以下地址,将您选择的公钥自动添加到信任列表中。(所有操作均只在您微服中进行,包括本开发机在内的任何数据不会泄漏到您的微服之外)
151
150
 
152
- 如果您的 '懒猫开发者工具' 不是 0.2.0 及以上版本,请先到应用商店进行升级.
151
+ -> https://${this.domain}/auth?key=${pk}
153
152
  `
153
+
154
154
  )
155
155
  throw "请在授权完成后重试!"
156
156
  }
@@ -267,10 +267,10 @@ export class DebugBridge {
267
267
  buildStream.on("close", (code) => {
268
268
  code == 0
269
269
  ? resolve(
270
- compareVersions("0.1.12", backendVersion) >= 0
271
- ? `127.0.0.1:5000/${tag}`
272
- : `dev.${this.boxname}.heiyu.space/${tag}`
273
- )
270
+ compareVersions("0.1.12", backendVersion) >= 0
271
+ ? `127.0.0.1:5000/${tag}`
272
+ : `dev.${this.boxname}.heiyu.space/${tag}`
273
+ )
274
274
  : reject(`在盒子中构建 image 失败`)
275
275
  })
276
276
  }).finally(() => {
package/lib/utils.js CHANGED
@@ -170,6 +170,29 @@ export function loadFromYaml(file) {
170
170
  return yaml.load(fs.readFileSync(file, "utf8"))
171
171
  }
172
172
 
173
+ // lzc-manifest.yml 要支持模板,目前无法直接用yaml库解释,手动读出必要字段
174
+ export function fakeLoadManifestYml(file) {
175
+ const res = fs.readFileSync(file, "utf8")
176
+ let obj = {
177
+ application: {
178
+ subdomain: undefined,
179
+ },
180
+ }
181
+ res.split("\n").forEach(v => {
182
+ let line = v.trim().replace(" ", "")
183
+ if (line.includes("package") && line.split(":").length == 2) {
184
+ obj.package = line.split(":")[1]
185
+ }
186
+ if (line.includes("subdomain") && line.split(":").length == 2) {
187
+ obj.application.subdomain = line.split(":")[1]
188
+ }
189
+ if (line.includes("version") && line.split(":").length == 2) {
190
+ obj.version = line.split(":")[1]
191
+ }
192
+ })
193
+ return obj
194
+ }
195
+
173
196
  export function dumpToYaml(template, target) {
174
197
  fs.writeFileSync(
175
198
  target,
@@ -323,18 +346,18 @@ export async function md5File(filepath) {
323
346
  }
324
347
 
325
348
  export class Downloader {
326
- constructor() {}
349
+ constructor() { }
327
350
 
328
351
  showDownloadingProgress(received, total) {
329
352
  let percentage = ((received * 100) / total).toFixed(2)
330
353
  process.stdout.write("\r")
331
354
  process.stdout.write(
332
355
  percentage +
333
- "% | " +
334
- received +
335
- " bytes downloaded out of " +
336
- total +
337
- " bytes."
356
+ "% | " +
357
+ received +
358
+ " bytes downloaded out of " +
359
+ total +
360
+ " bytes."
338
361
  )
339
362
  }
340
363
 
@@ -464,7 +487,7 @@ export function isTraceMode() {
464
487
  // 会直接报错,连版本检测都到不了(包导入的太前面了)
465
488
  async function __resolveDomain(domain, ipv6 = false) {
466
489
  return new Promise((resolve, reject) => {
467
- const callback = function (err, addresses) {
490
+ const callback = function(err, addresses) {
468
491
  if (addresses && addresses.length > 0) {
469
492
  resolve(addresses[0])
470
493
  } else {
@@ -579,22 +602,12 @@ export function findSshPublicKey() {
579
602
  throw error
580
603
  }
581
604
 
582
- // 定义公钥优先级列表
583
- const priorityKeys = [
584
- "id_ed25519.pub",
585
- "id_rsa.pub",
586
- "id_ecdsa.pub",
587
- "id_dsa.pub"
588
- ]
589
-
590
605
  let avaiableKeys = []
591
606
  try {
592
607
  // 获取 .ssh 目录下所有文件
593
608
  const files = fs.readdirSync(sshDir)
594
-
595
- // 首先检查优先级列表中的公钥
596
- for (const keyName of priorityKeys) {
597
- if (files.includes(keyName)) {
609
+ files.forEach((keyName) => {
610
+ if (keyName.endsWith(".pub")) {
598
611
  const keyPath = path.join(sshDir, keyName)
599
612
  // 验证文件是否可读
600
613
  try {
@@ -605,10 +618,9 @@ export function findSshPublicKey() {
605
618
  })
606
619
  } catch (error) {
607
620
  console.warn(`Found ${keyName} but cannot read it:`, error.message)
608
- continue
609
621
  }
610
622
  }
611
- }
623
+ })
612
624
 
613
625
  if (avaiableKeys.length == 0) {
614
626
  throw new Error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lazycatcloud/lzc-cli",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "lazycat cloud developer kit",
5
5
  "scripts": {
6
6
  "prepublishOnly": "node check-changelog.js"
@@ -1,5 +1,3 @@
1
- lzc-sdk-version: 0.1
2
-
3
1
  name: ${name} # app名称
4
2
  package: ${package} # app的唯一标识符
5
3
  version: 0.0.1 # app的版本
@@ -22,11 +22,11 @@ icon: ./lazycat.png
22
22
  # deploy_params: ./lzc-deploy-params.yml
23
23
 
24
24
  # devshell 自定义应用的开发容器环境
25
- # - routers 指定应用容器的访问路由
25
+ # - routes 指定应用容器的访问路由
26
26
 
27
27
  # devshell 没有指定 image 的情况,将会默认使用 registry.lazycat.cloud/lzc-cli/devshell:v0.0.5
28
28
  # devshell:
29
- # routers:
29
+ # routes:
30
30
  # - /=http://127.0.0.1:8080
31
31
 
32
32
  # devshell 指定 image 的情况
@@ -18,11 +18,11 @@ pkgout: ./
18
18
  # icon 仅仅允许 png 后缀的文件
19
19
  icon: ./lzc-icon.png
20
20
  # devshell 自定义应用的开发容器环境
21
- # - routers 指定应用容器的访问路由
21
+ # - routes 指定应用容器的访问路由
22
22
 
23
23
  # devshell 没有指定 image 的情况,将会默认使用 registry.lazycat.cloud/lzc-cli/devshell:v0.0.5
24
24
  # devshell:
25
- # routers:
25
+ # routes:
26
26
  # - /=http://127.0.0.1:8080
27
27
 
28
28
  # devshell 指定 image 的情况
@@ -1,4 +1,3 @@
1
- lzc-sdk-version: 0.1
2
1
  name: helloworld
3
2
  package: cloud.lazycat.app.helloworld
4
3
  version: 0.0.1
@@ -19,11 +19,11 @@ pkgout: ./
19
19
  icon: ./lzc-icon.png
20
20
 
21
21
  # devshell 自定义应用的开发容器环境
22
- # - routers 指定应用容器的访问路由
22
+ # - routes 指定应用容器的访问路由
23
23
 
24
24
  # devshell 没有指定 image 的情况,将会默认使用 registry.lazycat.cloud/lzc-cli/devshell:v0.0.5
25
25
  # devshell:
26
- # routers:
26
+ # routes:
27
27
  # - /=http://127.0.0.1:8080
28
28
 
29
29
  # devshell 指定 image 的情况