@lazycatcloud/lzc-cli 1.2.29 → 1.2.30
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/lib/app/apkshell.js +3 -6
- package/lib/app/lpk_debug_bridge.js +15 -4
- package/lib/app/lpk_devshell.js +0 -1
- package/lib/shellapi.js +18 -0
- package/lib/utils.js +15 -0
- package/package.json +2 -1
package/lib/app/apkshell.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs"
|
|
2
|
-
import fetch from "node-fetch"
|
|
3
2
|
import logger from "loglevel"
|
|
3
|
+
import { api } from "../utils.js"
|
|
4
4
|
|
|
5
5
|
export async function triggerApk(id, name, iconPath) {
|
|
6
6
|
if (!id) {
|
|
@@ -15,12 +15,9 @@ export async function triggerApk(id, name, iconPath) {
|
|
|
15
15
|
if (iconPath) {
|
|
16
16
|
form.append("app_icon", new Blob([fs.readFileSync(iconPath)]))
|
|
17
17
|
}
|
|
18
|
-
const resp = await
|
|
18
|
+
const resp = await api.post(
|
|
19
19
|
"https://appstore.lazycat.cloud/api/trigger_latest_for_app",
|
|
20
|
-
|
|
21
|
-
method: "POST",
|
|
22
|
-
body: form
|
|
23
|
-
}
|
|
20
|
+
form
|
|
24
21
|
)
|
|
25
22
|
if (resp.status == 304) {
|
|
26
23
|
} else if (resp.status == 201) {
|
|
@@ -2,7 +2,8 @@ import { spawn, spawnSync } from "child_process"
|
|
|
2
2
|
import fs from "node:fs"
|
|
3
3
|
import shellApi from "../shellapi.js"
|
|
4
4
|
import inquirer from "inquirer"
|
|
5
|
-
import { isDebugMode, resolveDomain } from "../utils.js"
|
|
5
|
+
import { isDebugMode, resolveDomain, sleep } from "../utils.js"
|
|
6
|
+
import logger from "loglevel"
|
|
6
7
|
|
|
7
8
|
export class DebugBridge {
|
|
8
9
|
constructor() {
|
|
@@ -85,6 +86,16 @@ export class DebugBridge {
|
|
|
85
86
|
|
|
86
87
|
async devshell(appId, isUserApp, onconnect = null) {
|
|
87
88
|
const resolvedIp = await resolveDomain(this.domain)
|
|
89
|
+
let waiting = true
|
|
90
|
+
while (waiting) {
|
|
91
|
+
if (await this.isDevshell(appId)) {
|
|
92
|
+
waiting = false
|
|
93
|
+
break
|
|
94
|
+
}
|
|
95
|
+
logger.debug("wait app container to running...")
|
|
96
|
+
await sleep(100)
|
|
97
|
+
}
|
|
98
|
+
|
|
88
99
|
const stream = spawn(
|
|
89
100
|
`ssh -p 22222 box@${resolvedIp}`,
|
|
90
101
|
[
|
|
@@ -104,9 +115,9 @@ export class DebugBridge {
|
|
|
104
115
|
stream.on("close", (code) => {
|
|
105
116
|
code == 0 ? resolve() : reject()
|
|
106
117
|
})
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
// spawn 事件只是进程启动成功的事件,并不是ssh成功连接上的事件。所以这里使
|
|
119
|
+
// 用前面的一个 isDevshell 判断是否已经启动这个容器,再使用 spawn
|
|
120
|
+
stream.on("spawn", onconnect)
|
|
110
121
|
})
|
|
111
122
|
}
|
|
112
123
|
|
package/lib/app/lpk_devshell.js
CHANGED
package/lib/shellapi.js
CHANGED
|
@@ -32,6 +32,11 @@ class ShellApi {
|
|
|
32
32
|
const { addr, cred } = this.readShellApiInfo()
|
|
33
33
|
this.client = new pbShell.ShellCore(addr, grpc.credentials.createInsecure())
|
|
34
34
|
|
|
35
|
+
// 检查当前 shell 环境上下文是否配置 HTTP_PROXY
|
|
36
|
+
if (this.checkEnvProxy()) {
|
|
37
|
+
logger.warn(`WARN:: 当前终端环境已配置 HTTP_PROXY 代理,可能会导致访问懒猫微服失败,如果未影响功能可以忽略该警告`)
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
const md = new grpc.Metadata()
|
|
36
41
|
md.add("lzc-shellapi-cred", cred)
|
|
37
42
|
this.metadata = md
|
|
@@ -115,6 +120,19 @@ class ShellApi {
|
|
|
115
120
|
})
|
|
116
121
|
}
|
|
117
122
|
|
|
123
|
+
checkEnvProxy() {
|
|
124
|
+
if(process.env.HTTPS_PROXY ||
|
|
125
|
+
process.env.HTTP_PROXY ||
|
|
126
|
+
process.env.ALL_PROXY ||
|
|
127
|
+
process.env.https_proxy ||
|
|
128
|
+
process.env.http_proxy ||
|
|
129
|
+
process.env.all_proxy
|
|
130
|
+
){
|
|
131
|
+
return true
|
|
132
|
+
}
|
|
133
|
+
return false
|
|
134
|
+
}
|
|
135
|
+
|
|
118
136
|
async setDefaultBox(boxname) {
|
|
119
137
|
const boxes = await this.boxList()
|
|
120
138
|
const box = boxes.find((b) => b.box_name === boxname)
|
package/lib/utils.js
CHANGED
|
@@ -16,6 +16,21 @@ import { spawnSync } from "node:child_process"
|
|
|
16
16
|
import logger from "loglevel"
|
|
17
17
|
import * as tar from "tar"
|
|
18
18
|
import dns from "node:dns/promises"
|
|
19
|
+
import axios from "axios"
|
|
20
|
+
|
|
21
|
+
// 创建 Axios 实例
|
|
22
|
+
export const api = axios.create()
|
|
23
|
+
|
|
24
|
+
// 添加响应拦截器
|
|
25
|
+
api.interceptors.response.use(
|
|
26
|
+
(response) => response, // 直接返回响应
|
|
27
|
+
(error) => {
|
|
28
|
+
if (error.response && error.response.status === 304) {
|
|
29
|
+
return Promise.resolve(error.response) // 返回响应以便后续处理
|
|
30
|
+
}
|
|
31
|
+
return Promise.reject(error) // 其他错误继续抛出
|
|
32
|
+
}
|
|
33
|
+
)
|
|
19
34
|
|
|
20
35
|
export const envsubstr = async (templateContents, args) => {
|
|
21
36
|
const parse = await importDefault("envsub/js/envsub-parser.js")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lazycatcloud/lzc-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.30",
|
|
4
4
|
"description": "lazycat cloud developer kit",
|
|
5
5
|
"files": [
|
|
6
6
|
"template",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"@grpc/grpc-js": "^1.11.1",
|
|
22
22
|
"@grpc/proto-loader": "^0.7.13",
|
|
23
23
|
"archiver": "^7.0.1",
|
|
24
|
+
"axios": "^1.7.7",
|
|
24
25
|
"chalk": "^5.3.0",
|
|
25
26
|
"chokidar": "^3.6.0",
|
|
26
27
|
"command-exists": "^1.2.9",
|