@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.
Files changed (105) hide show
  1. package/README.md +69 -11
  2. package/lib/api.js +71 -36
  3. package/lib/app/index.js +79 -23
  4. package/lib/app/lpk_build.js +96 -52
  5. package/lib/app/lpk_create.js +63 -41
  6. package/lib/app/lpk_create_generator.js +202 -0
  7. package/lib/app/lpk_devshell.js +393 -328
  8. package/lib/app/lpk_devshell_docker.js +211 -0
  9. package/lib/app/lpk_installer.js +63 -26
  10. package/lib/app/lpk_log.js +68 -0
  11. package/lib/app/lpk_status.js +18 -0
  12. package/lib/app/lpk_uninstall.js +19 -0
  13. package/lib/appstore/index.js +37 -0
  14. package/lib/appstore/login.js +137 -0
  15. package/lib/appstore/publish.js +62 -0
  16. package/lib/autologin.js +0 -80
  17. package/lib/box/api/clientapi.js +1322 -0
  18. package/lib/box/api/empty.js +35 -0
  19. package/lib/box/check_qemu.js +1 -0
  20. package/lib/box/index.js +41 -94
  21. package/lib/box/qemu_vm_mgr.js +208 -239
  22. package/lib/box/schemes/vm_box_system_debian.json +1 -1
  23. package/lib/docker-compose.js +1 -2
  24. package/lib/env.js +23 -142
  25. package/lib/key.js +1 -0
  26. package/lib/sdk.js +10 -25
  27. package/lib/utils.js +156 -233
  28. package/package.json +19 -11
  29. package/scripts/cli.js +14 -135
  30. package/template/_lpk/README.md +31 -0
  31. package/template/_lpk/exec.sh +19 -0
  32. package/template/_lpk/golang.manifest.yml.in +16 -0
  33. package/template/_lpk/lazycat.png +0 -0
  34. package/template/_lpk/lite.manifest.yml.in +19 -0
  35. package/template/_lpk/local_devshell/Dockerfile +16 -0
  36. package/template/_lpk/local_devshell/build.sh +5 -0
  37. package/template/_lpk/local_devshell/entrypoint.sh +87 -0
  38. package/template/{_lazycat/debug/shell → _lpk/local_devshell}/sshd_config +8 -8
  39. package/template/_lpk/manifest.yml.in +0 -1
  40. package/template/{vue/lzc-build.yml → _lpk/vue.lzc-build.yml.in} +9 -1
  41. package/template/golang/README.md +0 -2
  42. package/template/golang/_gitignore +2 -0
  43. package/template/golang/build.sh +6 -0
  44. package/template/golang/lazycat.png +0 -0
  45. package/template/golang/lzc-build.yml +9 -1
  46. package/template/golang/rego.go +15 -16
  47. package/template/golang/rego_test.go +13 -0
  48. package/template/ionic_vue3/lazycat.png +0 -0
  49. package/template/ionic_vue3/lzc-build.yml +9 -1
  50. package/template/lite/error_pages/502.html.tpl +13 -0
  51. package/template/lite/lazycat.png +0 -0
  52. package/template/lite/lzc-build.yml +60 -0
  53. package/cmds/app.js +0 -133
  54. package/cmds/config.js +0 -55
  55. package/cmds/create.js +0 -55
  56. package/cmds/dev.js +0 -130
  57. package/cmds/init.js +0 -125
  58. package/cmds/log.js +0 -103
  59. package/cmds/publish.js +0 -116
  60. package/lib/archiver.js +0 -105
  61. package/lib/box/hportal.js +0 -120
  62. package/lib/builder.js +0 -313
  63. package/lib/dev.js +0 -314
  64. package/lib/generator.js +0 -146
  65. package/template/_lazycat/_gitignore +0 -1
  66. package/template/_lazycat/app-config +0 -1
  67. package/template/_lazycat/debug/devforward/50x.html +0 -30
  68. package/template/_lazycat/debug/devforward/Dockerfile +0 -16
  69. package/template/_lazycat/debug/devforward/docker-compose.override.yml.in +0 -11
  70. package/template/_lazycat/debug/devforward/entrypoint.sh +0 -10
  71. package/template/_lazycat/debug/devforward/nginx.conf.template +0 -56
  72. package/template/_lazycat/debug/devforward/sshd_config +0 -116
  73. package/template/_lazycat/debug/shell/50x.html +0 -32
  74. package/template/_lazycat/debug/shell/Dockerfile +0 -18
  75. package/template/_lazycat/debug/shell/build.sh +0 -15
  76. package/template/_lazycat/debug/shell/docker-compose.override.yml.in +0 -13
  77. package/template/_lazycat/debug/shell/entrypoint.sh +0 -12
  78. package/template/_lazycat/docker-compose.yml.in +0 -15
  79. package/template/_lazycat/icon.svg +0 -1
  80. package/template/_lazycat/screenshot.png +0 -0
  81. package/template/_lpk/sync/Dockerfile +0 -16
  82. package/template/_lpk/sync/build.sh +0 -5
  83. package/template/_lpk/sync/entrypoint.sh +0 -8
  84. package/template/_lpk/sync/sshd_config +0 -117
  85. package/template/_lpk/sync.manifest.yml.in +0 -3
  86. package/template/release/golang/Dockerfile +0 -18
  87. package/template/release/golang/build.sh +0 -13
  88. package/template/release/ionic_vue3/Dockerfile +0 -10
  89. package/template/release/ionic_vue3/build.sh +0 -7
  90. package/template/release/ionic_vue3/docker-compose.yml.in +0 -3
  91. package/template/release/vue/Dockerfile +0 -10
  92. package/template/release/vue/build.sh +0 -10
  93. package/template/release/vue/docker-compose.yml.in +0 -3
  94. package/template/vue/README.md +0 -29
  95. package/template/vue/_dockerignore +0 -1
  96. package/template/vue/babel.config.js +0 -3
  97. package/template/vue/package.json +0 -43
  98. package/template/vue/public/favicon.ico +0 -0
  99. package/template/vue/public/index.html +0 -33
  100. package/template/vue/src/App.vue +0 -39
  101. package/template/vue/src/main.js +0 -8
  102. package/template/vue/src/todo.vue +0 -640
  103. package/template/vue/src/top-bar.vue +0 -100
  104. package/template/vue/src/webdav.vue +0 -183
  105. 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 { request } from "./autologin.js";
16
- const debug = debuglog("lib/env");
11
+ import logger from "loglevel";
12
+ import fetch from "node-fetch";
17
13
 
18
14
  const GLOBAL_CONFIG_NAME = "box-config.json";
19
- const permitGlobalEnv = [
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 %s", e.message);
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.all).forEach((key) => {
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 %s", e.message);
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
- if (this.sdkUrl) {
255
- try {
256
- // 另一种是SDK尚未安装,不过会被catch捕获掉,并安装sdk
257
- await this.checkConnection(this.sdkUrl);
258
- } catch (e) {
259
- // sdk未安装
260
- await this.installSDK(this.sdkUrl);
261
- }
262
- } else {
263
- await this.setDefaultBoxName();
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 = "", ensureSDK = true) {
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 `https://sdk.${boxname}.heiyu.space`;
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
- permitGlobalEnv.filter((a) => a.name == "DEFAULT_BOXNAME")
200
+ allPermitEnv.filter((a) => a.name == "DEFAULT_BOXNAME")
320
201
  );
321
202
  return answers["DEFAULT_BOXNAME"];
322
203
  }
package/lib/key.js CHANGED
@@ -83,6 +83,7 @@ export default class Key {
83
83
  key: fs.readFileSync(pair["private"]),
84
84
  },
85
85
  ],
86
+ keepaliveInterval: 5000,
86
87
  });
87
88
  });
88
89
  }
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
- }