@lazycatcloud/lzc-cli 1.1.7 → 1.1.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/README.md +69 -11
- package/lib/api.js +71 -36
- package/lib/app/index.js +79 -23
- package/lib/app/lpk_build.js +96 -52
- package/lib/app/lpk_create.js +63 -41
- package/lib/app/lpk_create_generator.js +202 -0
- package/lib/app/lpk_devshell.js +393 -328
- package/lib/app/lpk_devshell_docker.js +211 -0
- package/lib/app/lpk_installer.js +63 -26
- package/lib/app/lpk_log.js +68 -0
- package/lib/app/lpk_status.js +18 -0
- package/lib/app/lpk_uninstall.js +19 -0
- package/lib/appstore/index.js +37 -0
- package/lib/appstore/login.js +137 -0
- package/lib/appstore/publish.js +62 -0
- package/lib/autologin.js +0 -80
- package/lib/box/api/clientapi.js +1322 -0
- package/lib/box/api/empty.js +35 -0
- package/lib/box/check_qemu.js +1 -0
- package/lib/box/index.js +41 -94
- package/lib/box/qemu_vm_mgr.js +208 -239
- package/lib/box/schemes/vm_box_system_debian.json +1 -1
- package/lib/docker-compose.js +1 -2
- package/lib/env.js +23 -142
- package/lib/key.js +1 -0
- package/lib/sdk.js +10 -25
- package/lib/utils.js +156 -233
- package/package.json +19 -11
- package/scripts/cli.js +14 -135
- package/template/_lpk/README.md +31 -0
- package/template/_lpk/exec.sh +19 -0
- package/template/_lpk/golang.manifest.yml.in +16 -0
- package/template/_lpk/lazycat.png +0 -0
- package/template/_lpk/lite.manifest.yml.in +19 -0
- package/template/_lpk/local_devshell/Dockerfile +16 -0
- package/template/_lpk/local_devshell/build.sh +5 -0
- package/template/_lpk/local_devshell/entrypoint.sh +87 -0
- package/template/{_lazycat/debug/shell → _lpk/local_devshell}/sshd_config +8 -8
- package/template/_lpk/manifest.yml.in +0 -1
- package/template/{vue/lzc-build.yml → _lpk/vue.lzc-build.yml.in} +9 -1
- package/template/golang/README.md +0 -2
- package/template/golang/_gitignore +2 -0
- package/template/golang/build.sh +6 -0
- package/template/golang/lazycat.png +0 -0
- package/template/golang/lzc-build.yml +9 -1
- package/template/golang/rego.go +15 -16
- package/template/golang/rego_test.go +13 -0
- package/template/ionic_vue3/lazycat.png +0 -0
- package/template/ionic_vue3/lzc-build.yml +9 -1
- package/template/lite/error_pages/502.html.tpl +13 -0
- package/template/lite/lazycat.png +0 -0
- package/template/lite/lzc-build.yml +60 -0
- package/cmds/app.js +0 -133
- package/cmds/config.js +0 -55
- package/cmds/create.js +0 -55
- package/cmds/dev.js +0 -130
- package/cmds/init.js +0 -125
- package/cmds/log.js +0 -103
- package/cmds/publish.js +0 -116
- package/lib/archiver.js +0 -105
- package/lib/box/hportal.js +0 -120
- package/lib/builder.js +0 -313
- package/lib/dev.js +0 -314
- package/lib/generator.js +0 -146
- package/template/_lazycat/_gitignore +0 -1
- package/template/_lazycat/app-config +0 -1
- package/template/_lazycat/debug/devforward/50x.html +0 -30
- package/template/_lazycat/debug/devforward/Dockerfile +0 -16
- package/template/_lazycat/debug/devforward/docker-compose.override.yml.in +0 -11
- package/template/_lazycat/debug/devforward/entrypoint.sh +0 -10
- package/template/_lazycat/debug/devforward/nginx.conf.template +0 -56
- package/template/_lazycat/debug/devforward/sshd_config +0 -116
- package/template/_lazycat/debug/shell/50x.html +0 -32
- package/template/_lazycat/debug/shell/Dockerfile +0 -18
- package/template/_lazycat/debug/shell/build.sh +0 -15
- package/template/_lazycat/debug/shell/docker-compose.override.yml.in +0 -13
- package/template/_lazycat/debug/shell/entrypoint.sh +0 -12
- package/template/_lazycat/docker-compose.yml.in +0 -15
- package/template/_lazycat/icon.svg +0 -1
- package/template/_lazycat/screenshot.png +0 -0
- package/template/_lpk/sync/Dockerfile +0 -16
- package/template/_lpk/sync/build.sh +0 -5
- package/template/_lpk/sync/entrypoint.sh +0 -8
- package/template/_lpk/sync/sshd_config +0 -117
- package/template/_lpk/sync.manifest.yml.in +0 -3
- package/template/release/golang/Dockerfile +0 -18
- package/template/release/golang/build.sh +0 -13
- package/template/release/ionic_vue3/Dockerfile +0 -10
- package/template/release/ionic_vue3/build.sh +0 -7
- package/template/release/ionic_vue3/docker-compose.yml.in +0 -3
- package/template/release/vue/Dockerfile +0 -10
- package/template/release/vue/build.sh +0 -10
- package/template/release/vue/docker-compose.yml.in +0 -3
- package/template/vue/README.md +0 -29
- package/template/vue/_dockerignore +0 -1
- package/template/vue/babel.config.js +0 -3
- package/template/vue/package.json +0 -43
- package/template/vue/public/favicon.ico +0 -0
- package/template/vue/public/index.html +0 -33
- package/template/vue/src/App.vue +0 -39
- package/template/vue/src/main.js +0 -8
- package/template/vue/src/todo.vue +0 -640
- package/template/vue/src/top-bar.vue +0 -100
- package/template/vue/src/webdav.vue +0 -183
- package/template/vue/vue.config.js +0 -21
package/lib/env.js
CHANGED
|
@@ -5,18 +5,14 @@ import {
|
|
|
5
5
|
APP_CONFIG_FILE,
|
|
6
6
|
GLOBAL_CONFIG_DIR,
|
|
7
7
|
APP_FOLDER,
|
|
8
|
-
findAppIsInstalled,
|
|
9
|
-
checkSDKInstallStatus,
|
|
10
|
-
InstallSDK,
|
|
11
8
|
} from "./utils.js";
|
|
12
|
-
import { debuglog } from "util";
|
|
13
9
|
import inquirer from "inquirer";
|
|
14
10
|
import chalk from "chalk";
|
|
15
|
-
import
|
|
16
|
-
|
|
11
|
+
import logger from "loglevel";
|
|
12
|
+
import fetch from "node-fetch";
|
|
17
13
|
|
|
18
14
|
const GLOBAL_CONFIG_NAME = "box-config.json";
|
|
19
|
-
const
|
|
15
|
+
const allPermitEnv = [
|
|
20
16
|
{
|
|
21
17
|
name: "DEFAULT_BOXNAME",
|
|
22
18
|
type: "input",
|
|
@@ -27,91 +23,6 @@ const permitGlobalEnv = [
|
|
|
27
23
|
},
|
|
28
24
|
];
|
|
29
25
|
|
|
30
|
-
const _permitLocalEnv = [
|
|
31
|
-
{
|
|
32
|
-
name: "APP_ID",
|
|
33
|
-
type: "input",
|
|
34
|
-
message: "应用名称",
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: "APP_DESCRIPTION",
|
|
38
|
-
type: "input",
|
|
39
|
-
message: "应用描述",
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
name: "BUILD_CONTEXT",
|
|
43
|
-
message: "",
|
|
44
|
-
type: "input",
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: "DEV_CONTEXT",
|
|
48
|
-
message: "",
|
|
49
|
-
type: "input",
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: "APP_VERSION",
|
|
53
|
-
message: "应用版本号",
|
|
54
|
-
type: "input",
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name: "HTTP_SERVICE_PORT",
|
|
58
|
-
message: "服务暴露端口",
|
|
59
|
-
type: "input",
|
|
60
|
-
validate: (input) => {
|
|
61
|
-
if (!/^[^0]\d+$/.test(input)) {
|
|
62
|
-
return "端口必须为数字";
|
|
63
|
-
}
|
|
64
|
-
return true;
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
const permitLocalEnv = _permitLocalEnv.concat(permitGlobalEnv);
|
|
70
|
-
|
|
71
|
-
const allPermits = _permitLocalEnv.concat(permitGlobalEnv);
|
|
72
|
-
|
|
73
|
-
const controller = new AbortController();
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* 检查URL是否能被ping通
|
|
77
|
-
* @param url 要检查的URL
|
|
78
|
-
* @param suffix 可选,与URL拼接的后缀
|
|
79
|
-
**/
|
|
80
|
-
async function checkURL(url, suffix = "") {
|
|
81
|
-
const timeout = setTimeout(() => {
|
|
82
|
-
controller.abort();
|
|
83
|
-
}, 5000);
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
const resp = await request(url + suffix, { signal: controller.signal });
|
|
87
|
-
if (resp.status != 200) {
|
|
88
|
-
// 设备可以访问 (client 有正常连接), 但是sdk 这个服务无法访问
|
|
89
|
-
throw new Error(
|
|
90
|
-
chalk.red(
|
|
91
|
-
`无法连接 sdk 服务, 请确保 ${chalk.yellow(
|
|
92
|
-
new URL(url).origin
|
|
93
|
-
)} 可以访问或者在应用商店安装 sdk`
|
|
94
|
-
)
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
} catch (error) {
|
|
98
|
-
switch (error.name) {
|
|
99
|
-
case "FetchError":
|
|
100
|
-
console.log(chalk.red("盒子入口地址有误,请核对后再试"));
|
|
101
|
-
process.exit();
|
|
102
|
-
default:
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
} finally {
|
|
106
|
-
clearTimeout(timeout);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const allPermitEnv = permitGlobalEnv
|
|
111
|
-
.concat(permitLocalEnv)
|
|
112
|
-
.map((e) => e.name)
|
|
113
|
-
.filter((value, index, self) => self.indexOf(value) == index);
|
|
114
|
-
|
|
115
26
|
class Env {
|
|
116
27
|
constructor(cwd) {
|
|
117
28
|
// 只加载
|
|
@@ -135,7 +46,7 @@ class Env {
|
|
|
135
46
|
this.localEnv = JSON.parse(fs.readFileSync(this.localEnvPath));
|
|
136
47
|
this.existance.local = true;
|
|
137
48
|
} catch (e) {
|
|
138
|
-
debug("local env fail to fetch
|
|
49
|
+
logger.debug("local env fail to fetch ", e.message);
|
|
139
50
|
this.localEnv = {};
|
|
140
51
|
}
|
|
141
52
|
|
|
@@ -170,7 +81,7 @@ class Env {
|
|
|
170
81
|
|
|
171
82
|
stringify() {
|
|
172
83
|
let content = "";
|
|
173
|
-
Object.keys(this.
|
|
84
|
+
Object.keys(this.allEnv).forEach((key) => {
|
|
174
85
|
content += `${key}="${this.allEnv[key]}"\n`;
|
|
175
86
|
});
|
|
176
87
|
return content.trimEnd();
|
|
@@ -224,7 +135,7 @@ class Env {
|
|
|
224
135
|
this.globalEnv = JSON.parse(fs.readFileSync(this.globalEnvPath));
|
|
225
136
|
this.existance.global = true;
|
|
226
137
|
} catch (e) {
|
|
227
|
-
debug("global env fail to fetch
|
|
138
|
+
logger.debug("global env fail to fetch ", e.message);
|
|
228
139
|
this.globalEnv = {};
|
|
229
140
|
}
|
|
230
141
|
}
|
|
@@ -251,63 +162,33 @@ class SDKEnv {
|
|
|
251
162
|
}
|
|
252
163
|
|
|
253
164
|
async ensure() {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
165
|
+
try {
|
|
166
|
+
const resp = await fetch(`${this.sdkUrl}/api/v1/ping`);
|
|
167
|
+
if (resp.status != 200)
|
|
168
|
+
throw new Error(chalk.red("debug.bridge服务未正常运行"));
|
|
169
|
+
} catch (e) {
|
|
170
|
+
logger.error(e);
|
|
171
|
+
console.log(
|
|
172
|
+
chalk.yellow(
|
|
173
|
+
`检测到SDK尚未安装,请将盒子"${env.get(
|
|
174
|
+
"DEFAULT_BOXNAME"
|
|
175
|
+
)}"开启开发者模式`
|
|
176
|
+
)
|
|
177
|
+
);
|
|
178
|
+
process.exit(-1);
|
|
264
179
|
}
|
|
265
180
|
}
|
|
266
181
|
|
|
267
|
-
async setDefaultBoxName(boxname = ""
|
|
182
|
+
async setDefaultBoxName(boxname = "") {
|
|
268
183
|
if (!boxname) {
|
|
269
184
|
boxname = await this._promptAnswers();
|
|
270
185
|
}
|
|
271
186
|
let url = this.buildSdkUrl(boxname);
|
|
272
|
-
|
|
273
|
-
if (ensureSDK) {
|
|
274
|
-
await this.installSDK(url);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
187
|
env.set({ DEFAULT_BOXNAME: boxname }, true);
|
|
278
188
|
}
|
|
279
189
|
|
|
280
190
|
buildSdkUrl(boxname) {
|
|
281
|
-
return `
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
async checkConnection(host) {
|
|
285
|
-
return await checkURL(host, "/api/v1/ping");
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* 确保sdk已安装
|
|
290
|
-
* @param need_answer {boolean} 是否需要询问用户地址
|
|
291
|
-
*/
|
|
292
|
-
async installSDK(sdkURL) {
|
|
293
|
-
// 无法直接从环境变量拿到SDK_URL,就让用户输入
|
|
294
|
-
debug(sdkURL);
|
|
295
|
-
|
|
296
|
-
let boxURL = sdkURL.replace("sdk.", "");
|
|
297
|
-
|
|
298
|
-
try {
|
|
299
|
-
if (await findAppIsInstalled(boxURL, "sdk")) {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
console.log(chalk.yellow("检测到SDK尚未安装,开始安装SDK"));
|
|
304
|
-
await InstallSDK(boxURL);
|
|
305
|
-
console.log(chalk.green("SDK安装完成,开始部署SDK"));
|
|
306
|
-
|
|
307
|
-
await checkSDKInstallStatus(boxURL);
|
|
308
|
-
} catch (e) {
|
|
309
|
-
throw e;
|
|
310
|
-
}
|
|
191
|
+
return `http://sdk.${boxname}.heiyu.space`;
|
|
311
192
|
}
|
|
312
193
|
|
|
313
194
|
/**
|
|
@@ -316,7 +197,7 @@ class SDKEnv {
|
|
|
316
197
|
*/
|
|
317
198
|
async _promptAnswers() {
|
|
318
199
|
const answers = await inquirer.prompt(
|
|
319
|
-
|
|
200
|
+
allPermitEnv.filter((a) => a.name == "DEFAULT_BOXNAME")
|
|
320
201
|
);
|
|
321
202
|
return answers["DEFAULT_BOXNAME"];
|
|
322
203
|
}
|
package/lib/key.js
CHANGED
package/lib/sdk.js
CHANGED
|
@@ -7,6 +7,14 @@ import { Client } from "ssh2";
|
|
|
7
7
|
import Key from "./key.js";
|
|
8
8
|
import logger from "loglevel";
|
|
9
9
|
|
|
10
|
+
const sshDebug = function () {
|
|
11
|
+
if (process.env["SSH2_DEBUG"]) {
|
|
12
|
+
return logger.debug;
|
|
13
|
+
} else {
|
|
14
|
+
return function () {};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
10
18
|
export async function connectOptions(host) {
|
|
11
19
|
const pairs = await new Key().getKeyPair();
|
|
12
20
|
return {
|
|
@@ -27,6 +35,8 @@ export async function connectOptions(host) {
|
|
|
27
35
|
agent: process.env.SSH_AUTH_SOCK,
|
|
28
36
|
},
|
|
29
37
|
],
|
|
38
|
+
keepaliveInterval: 5000, // 5s
|
|
39
|
+
debug: sshDebug(),
|
|
30
40
|
};
|
|
31
41
|
}
|
|
32
42
|
|
|
@@ -123,28 +133,3 @@ export class SSHClient {
|
|
|
123
133
|
);
|
|
124
134
|
}
|
|
125
135
|
}
|
|
126
|
-
|
|
127
|
-
export async function dockerPullLzcAppsImage(host) {
|
|
128
|
-
logger.warn("* 更新lzcapp镜像, 未来可能会移除此操作");
|
|
129
|
-
const opts = await connectOptions(host);
|
|
130
|
-
const client = new SSHClient(opts);
|
|
131
|
-
await client.connect();
|
|
132
|
-
try {
|
|
133
|
-
const stream = await client.exec(
|
|
134
|
-
"docker pull registry.lazycat.cloud/lzc/lzcapp:0.1"
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
return new Promise((resolve, reject) => {
|
|
138
|
-
stream.stdout.pipe(process.stdout);
|
|
139
|
-
stream.stderr.pipe(process.stdout);
|
|
140
|
-
stream.on("close", () => {
|
|
141
|
-
client.close();
|
|
142
|
-
resolve();
|
|
143
|
-
});
|
|
144
|
-
stream.on("error", (e) => reject(e));
|
|
145
|
-
});
|
|
146
|
-
} catch (e) {
|
|
147
|
-
client.close();
|
|
148
|
-
throw e;
|
|
149
|
-
}
|
|
150
|
-
}
|