@lazycatcloud/lzc-cli 1.2.52 → 1.2.53

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,8 @@
1
+ # 1.2.53
2
+
3
+ 1. 修复 devshell 模型下,环境变量中有空格导致export错误
4
+ 2. 优化生成 apk shell 错误提示
5
+
1
6
  # 1.2.52
2
7
 
3
8
  1. appstore api 变更
@@ -101,11 +101,16 @@ export class LpkInstaller {
101
101
 
102
102
  logger.debug("是否生成APK:", installConfig.apk)
103
103
  if (installConfig.apk) {
104
- await triggerApk(
104
+ triggerApk(
105
105
  manifest["package"],
106
106
  manifest["name"],
107
107
  path.resolve(path.join(tempDir, "icon.png"))
108
- )
108
+ ).catch((err) => {
109
+ logger.debug("生成 APK 失败: ", err)
110
+ logger.debug(
111
+ "生成 APK 失败,使用 lzc-cli project devshell --apk n 忽略该错误"
112
+ )
113
+ })
109
114
  }
110
115
  logger.debug("lpk manifest", manifest)
111
116
  } finally {
@@ -1,7 +1,7 @@
1
1
  import fetch from "node-fetch"
2
2
  import path from "path"
3
3
  import logger from "loglevel"
4
- import env from "../env.js"
4
+ import env from "../config/env.js"
5
5
  import inquirer from "inquirer"
6
6
 
7
7
  const accountServerUrl = "https://account.lazycat.cloud"
@@ -5,7 +5,7 @@ import fs from "node:fs"
5
5
  import inquirer from "inquirer"
6
6
  import path from "node:path"
7
7
  import { isFileExist, isPngWithFile, unzipSync } from "../utils.js"
8
- import env from "../env.js"
8
+ import env from "../config/env.js"
9
9
  import { Publish } from "./publish.js"
10
10
 
11
11
  async function askChangeLog() {
@@ -0,0 +1,60 @@
1
+ import path from "path"
2
+ import fs from "fs"
3
+ import { ensureDir } from "../utils.js"
4
+ import logger from "loglevel"
5
+ import os from "node:os"
6
+
7
+ export const GLOBAL_CONFIG_DIR = path.join(
8
+ os.homedir(),
9
+ "/.config/lazycat/box-config.json"
10
+ )
11
+
12
+ class Env {
13
+ constructor() {
14
+ this.allEnv = {}
15
+ this.globalEnvPath = GLOBAL_CONFIG_DIR
16
+ ensureDir(this.globalEnvPath)
17
+
18
+ this._loadGlobalEnv()
19
+ }
20
+
21
+ has(key) {
22
+ return Object.keys(this.allEnv).indexOf(key) > -1
23
+ }
24
+
25
+ get(key) {
26
+ return this.allEnv[key]
27
+ }
28
+
29
+ all() {
30
+ return this.allEnv
31
+ }
32
+
33
+ del(key) {
34
+ delete this.allEnv[key]
35
+ this.save()
36
+ }
37
+
38
+ save() {
39
+ fs.writeFileSync(
40
+ this.globalEnvPath,
41
+ JSON.stringify(this.allEnv, null, " ")
42
+ )
43
+ }
44
+
45
+ set(pairs) {
46
+ Object.assign(this.allEnv, pairs)
47
+ this.save()
48
+ }
49
+
50
+ _loadGlobalEnv() {
51
+ try {
52
+ this.allEnv = JSON.parse(fs.readFileSync(this.globalEnvPath))
53
+ } catch (e) {
54
+ logger.debug("global env fail to fetch ", e.message)
55
+ this.allEnv = {}
56
+ }
57
+ }
58
+ }
59
+
60
+ export default new Env()
@@ -0,0 +1,57 @@
1
+ import env from "./env.js"
2
+ import logger from "loglevel"
3
+
4
+ export function configCommand(program) {
5
+ const subCommands = [
6
+ {
7
+ command: "set [key] [value]",
8
+ desc: "设置配置",
9
+ handler: async ({ key, value }) => {
10
+ if (!key && !value) {
11
+ throw `key 和 value 不能为空`
12
+ }
13
+ const pair = Object.fromEntries([[key, value]])
14
+ env.set(pair)
15
+ logger.info(`${key} 配置成功!`)
16
+ }
17
+ },
18
+ {
19
+ command: "del [key]",
20
+ desc: "删除配置",
21
+ handler: async ({ key, value }) => {
22
+ if (key) {
23
+ env.del(key)
24
+ logger.info(`删除 ${key} 成功!`)
25
+ return
26
+ }
27
+ }
28
+ },
29
+ {
30
+ command: "get [key]",
31
+ desc: "获取配置",
32
+ handler: async ({ key }) => {
33
+ if (key) {
34
+ const v = env.get(key)
35
+ logger.info(`${key} ${v}`)
36
+ } else {
37
+ const all = env.all()
38
+ Object.keys(all).forEach((k) => {
39
+ logger.info(`${k} ${all[k]}`)
40
+ })
41
+ }
42
+ return
43
+ }
44
+ }
45
+ ]
46
+ program.command({
47
+ command: "config",
48
+ desc: "配置管理",
49
+ builder: (args) => {
50
+ args.command(subCommands)
51
+ args
52
+ .example("$0 config get", "列出所有配置")
53
+ .example("$0 config get foo", "获取key为foo的配置")
54
+ .example("$0 config set noCheckVersion false", "禁用lzc-cli的版本检测")
55
+ }
56
+ })
57
+ }
package/lib/env.js CHANGED
@@ -26,14 +26,27 @@ class Env {
26
26
  return this.allEnv[key]
27
27
  }
28
28
 
29
- set(pairs) {
30
- Object.assign(this.allEnv, pairs)
29
+ all() {
30
+ return this.allEnv
31
+ }
32
+
33
+ del(key) {
34
+ delete this.allEnv[key]
35
+ this.save()
36
+ }
37
+
38
+ save() {
31
39
  fs.writeFileSync(
32
40
  this.globalEnvPath,
33
41
  JSON.stringify(this.allEnv, null, " ")
34
42
  )
35
43
  }
36
44
 
45
+ set(pairs) {
46
+ Object.assign(this.allEnv, pairs)
47
+ this.save()
48
+ }
49
+
37
50
  _loadGlobalEnv() {
38
51
  try {
39
52
  this.allEnv = JSON.parse(fs.readFileSync(this.globalEnvPath))
package/lib/shellapi.js CHANGED
@@ -77,7 +77,7 @@ NOTE:在指定环境变量的模式下,有些接口依旧不能访问,为
77
77
  this.metadata = md
78
78
  this.info = await this.initBoxInfo()
79
79
  }
80
- this.checkDevTools()
80
+ await this.checkDevTools()
81
81
  }
82
82
 
83
83
  get boxname() {
@@ -142,18 +142,29 @@ NOTE:在指定环境变量的模式下,有些接口依旧不能访问,为
142
142
 
143
143
  async checkDevTools() {
144
144
  const url = `https://dev.${this.info.boxname}.heiyu.space/bannerfile`
145
- fetch(url, { redirect: "error" })
146
- .then(async (res) => {
147
- const content = await res.text()
148
- if (res.status != 200 || content != bannerfileContent) {
145
+ return new Promise((resolve, reject) => {
146
+ fetch(url, { redirect: "error" })
147
+ .then(async (res) => {
148
+ const content = await res.text()
149
+ if (res.status == 200 && content == bannerfileContent) {
150
+ resolve()
151
+ return
152
+ }
149
153
  logger.warn(
150
- `检测到你还没有安装懒猫微服开发者工具,请先到商店中搜索安装`
154
+ `检测到你还没有安装 '懒猫开发者工具',请先到商店中搜索安装
155
+ 点击直接跳转 https://appstore.${this.info.boxname}.heiyu.space/#/shop/detail/cloud.lazycat.developer.tools
156
+ 点击打开应用 https://dev.${this.info.boxname}.heiyu.space 查看应用状态
157
+ `
151
158
  )
152
- }
153
- })
154
- .catch(() => {
155
- logger.debug(`你的懒猫微服开发者工具版本较低,请从商店中更新`)
156
- })
159
+ reject()
160
+ })
161
+ .catch(() => {
162
+ logger.error(
163
+ `检测懒猫开发者工具失败,请检测您当前的网络或者懒猫微服客户端是否正常启动。`
164
+ )
165
+ reject()
166
+ })
167
+ })
157
168
  }
158
169
 
159
170
  checkEnvProxy() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lazycatcloud/lzc-cli",
3
- "version": "1.2.52",
3
+ "version": "1.2.53",
4
4
  "description": "lazycat cloud developer kit",
5
5
  "scripts": {
6
6
  "prepublishOnly": "node check-changelog.js"
@@ -12,7 +12,7 @@
12
12
  "changelog.md"
13
13
  ],
14
14
  "bin": {
15
- "lzc-cli": "./scripts/cli.js"
15
+ "lzc-cli": "scripts/cli.js"
16
16
  },
17
17
  "type": "module",
18
18
  "keywords": [
package/scripts/cli.js CHANGED
@@ -11,7 +11,7 @@ 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
- import env from "../lib/env.js"
14
+ import { configCommand } from "../lib/config/index.js"
15
15
 
16
16
  // logger level middleware
17
17
  const logLevelOriginalFactory = logger.methodFactory
@@ -73,22 +73,7 @@ const program = yargs(hideBin(process.argv))
73
73
  })
74
74
  .completion("completion", false)
75
75
 
76
- program.command({
77
- command: "config [key] [value]",
78
- desc: false,
79
- builder: (args) => {
80
- args.implies("key", "value")
81
- },
82
- handler: async ({ key, value }) => {
83
- if (!key && !value) {
84
- console.log(env.stringify())
85
- return
86
- }
87
- const pair = Object.fromEntries([[key, value]])
88
- env.set(pair, true)
89
- }
90
- })
91
-
76
+ configCommand(program)
92
77
  boxCommand(program)
93
78
  lpkAppCommand(program)
94
79
  lpkProjectCommand(program)
@@ -109,6 +94,7 @@ appstoreCommand(program)
109
94
  case "app":
110
95
  case "project":
111
96
  case "appstore":
97
+ case "config":
112
98
  program.showHelp()
113
99
  return
114
100
  }
@@ -4,7 +4,7 @@
4
4
  # 从1号进程读取环境变量
5
5
  cat > /tmp/lzcapp_env.sh << EOF
6
6
  #!/bin/sh
7
- $(/usr/lib/debug.bridge/busybox tr '\0' '\n' < /proc/1/environ | /usr/lib/debug.bridge/busybox xargs -I{} echo export {})
7
+ $(/usr/lib/debug.bridge/busybox tr '\0' '\n' < /proc/1/environ | /usr/lib/debug.bridge/busybox xargs -I{} echo 'export "{}"')
8
8
  EOF
9
9
  . /tmp/lzcapp_env.sh
10
10