@lazycatcloud/lzc-cli 1.2.44 → 1.2.46

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,11 @@
1
+ # 1.2.46
2
+
3
+ 1. 修复拉取构建的镜像dns错误
4
+
5
+ # 1.2.45
6
+
7
+ 1. 修复 helloworld 404 错误
8
+
1
9
  # 1.2.44
2
10
 
3
11
  1. 修复查询状态等接口没有使用ipv6地址
@@ -8,7 +8,8 @@ import {
8
8
  sleep,
9
9
  findSshPublicKey,
10
10
  isWindows,
11
- contextDirname
11
+ contextDirname,
12
+ compareVersions
12
13
  } from "../utils.js"
13
14
  import logger from "loglevel"
14
15
  import commandExists from "command-exists"
@@ -142,6 +143,20 @@ export class DebugBridge {
142
143
  ])
143
144
  }
144
145
 
146
+ async version() {
147
+ const output = await this.common(sshBinary(), [
148
+ ...sshCmdArgs(`box@${this.domain}`),
149
+ `version`
150
+ ])
151
+ logger.debug(`backend version:\n${output}`)
152
+ try {
153
+ const data = JSON.parse(output)
154
+ return data.version
155
+ } catch {
156
+ return "0.0.0"
157
+ }
158
+ }
159
+
145
160
  async uninstall(appId) {
146
161
  return this.common(sshBinary(), [
147
162
  ...sshCmdArgs(`box@${this.domain}`),
@@ -193,6 +208,8 @@ export class DebugBridge {
193
208
  }
194
209
 
195
210
  async buildImage(label, contextTar) {
211
+ const backendVersion = await this.version()
212
+
196
213
  const tag = `debug.bridge/${label}`
197
214
  const resolvedIp = await resolveDomain(this.domain)
198
215
  const stream = fs.createReadStream(contextTar)
@@ -209,8 +226,12 @@ export class DebugBridge {
209
226
  return new Promise((resolve, reject) => {
210
227
  buildStream.on("close", (code) => {
211
228
  code == 0
212
- ? resolve(`dev.${this.boxname}.heiyu.space/${tag}`)
213
- : reject("在盒子中构建 image 失败")
229
+ ? resolve(
230
+ compareVersions("0.1.12", backendVersion) >= 0
231
+ ? `localhost:5000/${tag}`
232
+ : `dev.${this.boxname}.heiyu.space/${tag}`
233
+ )
234
+ : reject(`在盒子中构建 image 失败`)
214
235
  })
215
236
  }).finally(() => {
216
237
  fs.rmSync(contextTar)
@@ -21,10 +21,10 @@ import {
21
21
  resolveDomain,
22
22
  isWindows,
23
23
  isMacOs,
24
- isLinux
24
+ isLinux,
25
+ checkRsync
25
26
  } from "../utils.js"
26
27
  import os from "node:os"
27
- import commandExists from "command-exists"
28
28
  import chokidar from "chokidar"
29
29
  import _ from "lodash"
30
30
  import { DebugBridge } from "./lpk_debug_bridge.js"
@@ -444,14 +444,7 @@ class DevShell {
444
444
  }
445
445
 
446
446
  async syncProject(appId) {
447
- if (isLinux || isMacOs) {
448
- // 检查rsync工具是否存在:提示用户
449
- const rsyncExisted = commandExists.sync("rsync")
450
- if (!rsyncExisted) {
451
- logger.error("请检查 rsync 是否安装,路径是否正确!")
452
- process.exit(1)
453
- }
454
- }
447
+ checkRsync()
455
448
 
456
449
  const resolvedIp = await resolveDomain(
457
450
  `dev.${shellApi.boxname}.heiyu.space`
package/lib/utils.js CHANGED
@@ -18,6 +18,14 @@ import * as tar from "tar"
18
18
  import dns from "node:dns/promises"
19
19
  import axios from "axios"
20
20
  import AdmZip from "adm-zip"
21
+ import commandExists from "command-exists"
22
+
23
+ // lzc-cli 包的 pkgInfo 信息
24
+ export const pkgInfo = JSON.parse(
25
+ fs.readFileSync(
26
+ path.join(contextDirname(import.meta.url), "..", "package.json")
27
+ )
28
+ )
21
29
 
22
30
  // 创建 Axios 实例
23
31
  export const api = axios.create()
@@ -42,6 +50,27 @@ export const envsubstr = async (templateContents, args) => {
42
50
  return parse(templateContents, args)
43
51
  }
44
52
 
53
+ // 比较当前的版本和want的大小,如果
54
+ // - 当前版本大于指定的版本 => 1
55
+ // - 当前版本等于指定的版本 => 0
56
+ // - 当前版本小于指定的版本 => -1
57
+ export function compareVersions(want, current = pkgInfo.version) {
58
+ const wantArrs = want.split(".")
59
+ const currArrs = current.split(".")
60
+
61
+ // Compare each part
62
+ for (let i = 0; i < Math.max(wantArrs.length, currArrs.length); i++) {
63
+ // Convert to integers, default to 0 if part doesn't exist
64
+ const w = parseInt(wantArrs[i] || 0)
65
+ const c = parseInt(currArrs[i] || 0)
66
+
67
+ if (c > w) return 1
68
+ if (c < w) return -1
69
+ }
70
+
71
+ return 0 // Versions are equal
72
+ }
73
+
45
74
  /**
46
75
  * 确保文件夹存在
47
76
  * @param filePath {string} 如果为文件路径 确保其文件夹存在; 如果为文件夹, 则确保该文件夹存在
@@ -588,3 +617,36 @@ export function findSshPublicKey() {
588
617
  throw error
589
618
  }
590
619
  }
620
+
621
+ export function checkRsync() {
622
+ if (isLinux || isMacOs) {
623
+ // 检查rsync工具是否存在:提示用户
624
+ const rsyncExisted = commandExists.sync("rsync")
625
+ if (!rsyncExisted) {
626
+ logger.error("请检查 rsync 是否安装,路径是否正确!")
627
+ process.exit(1)
628
+ }
629
+
630
+ const check = spawn.sync("rsync", ["--version"], {
631
+ shell: true,
632
+ encoding: "utf-8",
633
+ stdio: ["pipe", "pipe", "pipe"]
634
+ })
635
+ logger.debug(`执行命令 rsync --version`)
636
+ if (check.status == 0) {
637
+ const versionMatch = check.stdout.match(
638
+ /rsync\s+version\s+(\d+\.\d+\.\d+)/i
639
+ )
640
+ if (!versionMatch || compareVersions("3.2.0", versionMatch[1]) < 0) {
641
+ logger.error(
642
+ `当前rsync版本为:${versionMatch[1]}, 要求rsync版本为: 3.2.0+`
643
+ )
644
+ process.exit(1)
645
+ }
646
+ logger.debug(`当前rsync版本为:${versionMatch[1]}`)
647
+ } else {
648
+ logger.error("请检查 rsync 安装是否正确,指定 rsync --version 错误")
649
+ process.exit(1)
650
+ }
651
+ }
652
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lazycatcloud/lzc-cli",
3
- "version": "1.2.44",
3
+ "version": "1.2.46",
4
4
  "description": "lazycat cloud developer kit",
5
5
  "files": [
6
6
  "template",
package/scripts/cli.js CHANGED
@@ -7,13 +7,10 @@ import yargs from "yargs"
7
7
  import { hideBin } from "yargs/helpers"
8
8
  import chalk from "chalk"
9
9
 
10
- import { contextDirname } from "../lib/utils.js"
10
+ import { contextDirname, pkgInfo } from "../lib/utils.js"
11
11
  import { boxCommand } from "../lib/box/index.js"
12
12
  import { appstoreCommand } from "../lib/appstore/index.js"
13
13
  import { lpkAppCommand, lpkProjectCommand } from "../lib/app/index.js"
14
- const pkgInfo = JSON.parse(
15
- fs.readFileSync(path.join(contextDirname(import.meta.url), "../package.json"))
16
- )
17
14
  import env from "../lib/env.js"
18
15
 
19
16
  // logger level middleware
@@ -33,6 +33,10 @@ if ${LZCBUSYBOX} netstat -tln | grep ':22222' >/dev/null; then
33
33
  else
34
34
  echo "启动 rsync daemon."
35
35
  rsync --daemon --no-detach --config=/lzcapp/pkg/content/devshell/rsyncd.conf &
36
+ while ! nc -z localhost 873; do
37
+ sleep 1
38
+ done
39
+ echo "rsync daemon 已成功监听 873 端口"
36
40
 
37
41
  mkdir -p /etc/dropbear
38
42
  exec dropbearmulti dropbear -R -F -E -B -p 22222
@@ -4,4 +4,7 @@ import vue from '@vitejs/plugin-vue'
4
4
  // https://vitejs.dev/config/
5
5
  export default defineConfig({
6
6
  plugins: [vue()],
7
+ build: {
8
+ outDir: "./dist/dist"
9
+ }
7
10
  })