@lazycatcloud/lzc-cli 1.2.27 → 1.2.29

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 (37) hide show
  1. package/lib/app/apkshell.js +35 -0
  2. package/lib/app/index.js +89 -78
  3. package/lib/app/lpk_build.js +113 -117
  4. package/lib/app/lpk_create.js +78 -148
  5. package/lib/app/lpk_create_generator.js +103 -74
  6. package/lib/app/lpk_debug_bridge.js +61 -73
  7. package/lib/app/lpk_devshell.js +230 -229
  8. package/lib/app/lpk_devshell_docker.js +28 -28
  9. package/lib/app/lpk_installer.js +64 -49
  10. package/lib/appstore/index.js +29 -29
  11. package/lib/appstore/login.js +63 -68
  12. package/lib/appstore/prePublish.js +68 -68
  13. package/lib/appstore/publish.js +55 -55
  14. package/lib/box/index.js +25 -25
  15. package/lib/env.js +18 -18
  16. package/lib/shellapi.js +55 -58
  17. package/lib/utils.js +217 -164
  18. package/package.json +7 -1
  19. package/scripts/cli.js +56 -56
  20. package/template/_lpk/manifest.yml.in +8 -8
  21. package/template/vue/README.md +29 -0
  22. package/template/vue/index.html +13 -0
  23. package/template/vue/lzc-build.yml +59 -0
  24. package/template/vue/lzc-icon.png +0 -0
  25. package/template/vue/package.json +20 -0
  26. package/template/vue/public/vite.svg +1 -0
  27. package/template/vue/src/App.vue +30 -0
  28. package/template/vue/src/assets/vue.svg +1 -0
  29. package/template/vue/src/components/HelloWorld.vue +41 -0
  30. package/template/vue/src/main.ts +5 -0
  31. package/template/vue/src/style.css +79 -0
  32. package/template/vue/src/vite-env.d.ts +1 -0
  33. package/template/vue/tsconfig.app.json +24 -0
  34. package/template/vue/tsconfig.json +7 -0
  35. package/template/vue/tsconfig.node.json +22 -0
  36. package/template/vue/vite.config.ts +7 -0
  37. package/template/ionic_vue3/package-lock.json +0 -8100
@@ -1,106 +1,90 @@
1
- import { spawn, spawnSync } from "child_process";
2
- import fs from "node:fs";
3
- import shellApi from "../shellapi.js";
4
- import inquirer from "inquirer";
5
- import { isDebugMode, resolveDomain } from "../utils.js";
6
-
1
+ import { spawn, spawnSync } from "child_process"
2
+ import fs from "node:fs"
3
+ import shellApi from "../shellapi.js"
4
+ import inquirer from "inquirer"
5
+ import { isDebugMode, resolveDomain } from "../utils.js"
7
6
 
8
7
  export class DebugBridge {
9
8
  constructor() {
10
- this.uid = shellApi.uid;
11
- this.boxname = shellApi.boxname;
12
- this.domain = `dev.${this.boxname}.heiyu.space`;
13
- this.sshCmd = `ssh ${isDebugMode() ? "-vv" : ""} -p 22222 box@${this.domain}`;
9
+ this.uid = shellApi.uid
10
+ this.boxname = shellApi.boxname
11
+ this.domain = `dev.${this.boxname}.heiyu.space`
12
+ this.sshCmd = `ssh ${isDebugMode() ? "-vv" : ""} -p 22222 box@${this.domain}`
14
13
  }
15
14
 
16
15
  async common(cmd, args) {
17
- const resolvedIp = await resolveDomain(this.domain);
18
- const sshCmd = cmd.replace(this.domain, resolvedIp);
16
+ const resolvedIp = await resolveDomain(this.domain)
17
+ const sshCmd = cmd.replace(this.domain, resolvedIp)
19
18
  const ssh = spawnSync(sshCmd, args, {
20
19
  shell: true,
21
20
  encoding: "utf-8",
22
- stdio: ["pipe", "pipe", "inherit"],
23
- });
21
+ stdio: ["pipe", "pipe", "pipe"]
22
+ })
24
23
  return new Promise((resolve, reject) => {
25
24
  ssh.status == 0
26
25
  ? resolve(ssh.stdout)
27
- : reject(`执行命令 ${sshCmd} ${args.join(" ")} 出错\n${ssh.stderr ?? ""}`);
28
- });
26
+ : reject(
27
+ `执行命令 ${sshCmd} ${args.join(" ")} 出错\n${ssh.stderr ?? ""}`
28
+ )
29
+ })
29
30
  }
30
31
 
31
32
  async install(lpkPath, pkgId) {
32
33
  if (!(await this.canPublicKey())) {
33
- await this.sshCopyId();
34
+ // 如果不能 ssh public key 登录则直接调用 ssh-copy-id 复制,否则后面可能会出现 rsync 询问密码的问题
35
+ await this.sshCopyId()
34
36
  }
35
37
 
36
- const stream = fs.createReadStream(lpkPath);
37
- const resolvedIp = await resolveDomain(this.domain);
38
+ const stream = fs.createReadStream(lpkPath)
39
+ const resolvedIp = await resolveDomain(this.domain)
38
40
  const ssh = spawn(
39
41
  `ssh -p 22222 box@${resolvedIp}`,
40
42
  [`install --uid ${this.uid} --pkgId ${pkgId}`],
41
43
  {
42
44
  shell: true,
43
- stdio: ["pipe", "inherit", "inherit"],
45
+ stdio: ["pipe", "inherit", "inherit"]
44
46
  }
45
- );
46
- stream.pipe(ssh.stdin);
47
+ )
48
+ stream.pipe(ssh.stdin)
47
49
  return new Promise((resolve, reject) => {
48
50
  ssh.on("close", (code) => {
49
- code == 0 ? resolve() : reject("install 失败");
50
- });
51
- });
51
+ code == 0 ? resolve() : reject("install 失败")
52
+ })
53
+ })
52
54
  }
53
55
 
54
56
  async canPublicKey() {
55
- try {
56
- await this.common(this.sshCmd, [`-o PasswordAuthentication=no`]);
57
- return true;
58
- } catch {
59
- return false;
60
- }
57
+ // FIXME: 目前没有找到在允许空密码的情况下,检测是否只能通过 publickey 登录的方法。
58
+ return false
61
59
  }
62
60
 
63
61
  async sshCopyId() {
64
- const questions = [
65
- {
66
- name: "upload",
67
- type: "input",
68
- default: "y",
69
- message:
70
- "检测到你目前使用的密码帐号登录,是否使用 ssh-copy-id 上传密钥 (y/n): ",
71
- },
72
- ];
73
- const answers = await inquirer.prompt(questions);
74
- if (answers.upload.toLowerCase() == "y") {
75
- const resolvedIp = await resolveDomain(this.domain);
76
- return this.common(`ssh-copy-id`, [
77
- `-f -p 22222 box@${resolvedIp}`,
78
- ]);
79
- }
62
+ const resolvedIp = await resolveDomain(this.domain)
63
+ return this.common(`ssh-copy-id`, [`-f -p 22222 box@${resolvedIp}`])
80
64
  }
81
65
 
82
66
  async status(appId) {
83
- return this.common(this.sshCmd, [`status --uid ${this.uid}`, appId]);
67
+ return this.common(this.sshCmd, [`status --uid ${this.uid}`, appId])
84
68
  }
85
69
 
86
70
  async isDevshell(appId) {
87
71
  const stdout = await this.common(this.sshCmd, [
88
72
  `isDevshell --uid ${this.uid}`,
89
- appId,
90
- ]);
91
- return stdout == "true";
73
+ appId
74
+ ])
75
+ return stdout == "true"
92
76
  }
93
77
 
94
78
  async resume(appId) {
95
- return this.common(this.sshCmd, [`resume --uid ${this.uid}`, appId]);
79
+ return this.common(this.sshCmd, [`resume --uid ${this.uid}`, appId])
96
80
  }
97
81
 
98
82
  async uninstall(appId) {
99
- return this.common(this.sshCmd, [`uninstall --uid ${this.uid}`, appId]);
83
+ return this.common(this.sshCmd, [`uninstall --uid ${this.uid}`, appId])
100
84
  }
101
85
 
102
86
  async devshell(appId, isUserApp, onconnect = null) {
103
- const resolvedIp = await resolveDomain(this.domain);
87
+ const resolvedIp = await resolveDomain(this.domain)
104
88
  const stream = spawn(
105
89
  `ssh -p 22222 box@${resolvedIp}`,
106
90
  [
@@ -109,40 +93,44 @@ export class DebugBridge {
109
93
  `--uid ${this.uid}`,
110
94
  isUserApp ? "--userapp" : "",
111
95
  appId,
112
- "/lzcapp/pkg/content/devshell/exec.sh",
96
+ "/lzcapp/pkg/content/devshell/exec.sh"
113
97
  ],
114
98
  {
115
99
  shell: true,
116
- stdio: "inherit",
100
+ stdio: "inherit"
117
101
  }
118
- );
102
+ )
119
103
  return new Promise((resolve, reject) => {
120
104
  stream.on("close", (code) => {
121
- code == 0 ? resolve() : reject();
122
- });
105
+ code == 0 ? resolve() : reject()
106
+ })
123
107
  if (onconnect) {
124
- stream.on("spawn", onconnect);
108
+ stream.on("spawn", onconnect)
125
109
  }
126
- });
110
+ })
127
111
  }
128
112
 
129
113
  async buildImage(label, contextTar) {
130
- const tag = `debug.bridge/${label}`;
131
- const resolvedIp = await resolveDomain(this.domain);
132
- const stream = fs.createReadStream(contextTar);
133
- const ssh = spawn(`ssh -p 22222 box@${resolvedIp}`, [`build --tag ${tag}`], {
134
- shell: true,
135
- stdio: ["pipe", "inherit", "inherit"],
136
- });
137
- stream.pipe(ssh.stdin);
114
+ const tag = `debug.bridge/${label}`
115
+ const resolvedIp = await resolveDomain(this.domain)
116
+ const stream = fs.createReadStream(contextTar)
117
+ const ssh = spawn(
118
+ `ssh -p 22222 box@${resolvedIp}`,
119
+ [`build --tag ${tag}`],
120
+ {
121
+ shell: true,
122
+ stdio: ["pipe", "inherit", "inherit"]
123
+ }
124
+ )
125
+ stream.pipe(ssh.stdin)
138
126
  return new Promise((resolve, reject) => {
139
127
  ssh.on("close", (code) => {
140
128
  code == 0
141
129
  ? resolve(`dev.${this.boxname}.heiyu.space/${tag}`)
142
- : reject("在盒子中构建 image 失败");
143
- });
130
+ : reject("在盒子中构建 image 失败")
131
+ })
144
132
  }).finally(() => {
145
- fs.rmSync(contextTar);
146
- });
133
+ fs.rmSync(contextTar)
134
+ })
147
135
  }
148
136
  }