@lazycatcloud/lzc-cli 1.2.25 → 1.2.27
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.
|
@@ -2,19 +2,21 @@ 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 } from "../utils.js";
|
|
5
|
+
import { isDebugMode, resolveDomain } from "../utils.js";
|
|
6
|
+
|
|
6
7
|
|
|
7
8
|
export class DebugBridge {
|
|
8
9
|
constructor() {
|
|
9
10
|
this.uid = shellApi.uid;
|
|
10
11
|
this.boxname = shellApi.boxname;
|
|
11
|
-
this.
|
|
12
|
-
|
|
13
|
-
}.heiyu.space`;
|
|
12
|
+
this.domain = `dev.${this.boxname}.heiyu.space`;
|
|
13
|
+
this.sshCmd = `ssh ${isDebugMode() ? "-vv" : ""} -p 22222 box@${this.domain}`;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
common(cmd, args) {
|
|
17
|
-
const
|
|
16
|
+
async common(cmd, args) {
|
|
17
|
+
const resolvedIp = await resolveDomain(this.domain);
|
|
18
|
+
const sshCmd = cmd.replace(this.domain, resolvedIp);
|
|
19
|
+
const ssh = spawnSync(sshCmd, args, {
|
|
18
20
|
shell: true,
|
|
19
21
|
encoding: "utf-8",
|
|
20
22
|
stdio: ["pipe", "pipe", "inherit"],
|
|
@@ -22,7 +24,7 @@ export class DebugBridge {
|
|
|
22
24
|
return new Promise((resolve, reject) => {
|
|
23
25
|
ssh.status == 0
|
|
24
26
|
? resolve(ssh.stdout)
|
|
25
|
-
: reject(`执行命令 ${
|
|
27
|
+
: reject(`执行命令 ${sshCmd} ${args.join(" ")} 出错\n${ssh.stderr ?? ""}`);
|
|
26
28
|
});
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -32,8 +34,9 @@ export class DebugBridge {
|
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
const stream = fs.createReadStream(lpkPath);
|
|
37
|
+
const resolvedIp = await resolveDomain(this.domain);
|
|
35
38
|
const ssh = spawn(
|
|
36
|
-
|
|
39
|
+
`ssh -p 22222 box@${resolvedIp}`,
|
|
37
40
|
[`install --uid ${this.uid} --pkgId ${pkgId}`],
|
|
38
41
|
{
|
|
39
42
|
shell: true,
|
|
@@ -69,8 +72,9 @@ export class DebugBridge {
|
|
|
69
72
|
];
|
|
70
73
|
const answers = await inquirer.prompt(questions);
|
|
71
74
|
if (answers.upload.toLowerCase() == "y") {
|
|
75
|
+
const resolvedIp = await resolveDomain(this.domain);
|
|
72
76
|
return this.common(`ssh-copy-id`, [
|
|
73
|
-
`-f -p 22222 box
|
|
77
|
+
`-f -p 22222 box@${resolvedIp}`,
|
|
74
78
|
]);
|
|
75
79
|
}
|
|
76
80
|
}
|
|
@@ -96,8 +100,9 @@ export class DebugBridge {
|
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
async devshell(appId, isUserApp, onconnect = null) {
|
|
103
|
+
const resolvedIp = await resolveDomain(this.domain);
|
|
99
104
|
const stream = spawn(
|
|
100
|
-
|
|
105
|
+
`ssh -p 22222 box@${resolvedIp}`,
|
|
101
106
|
[
|
|
102
107
|
"-t",
|
|
103
108
|
"devshell",
|
|
@@ -123,8 +128,9 @@ export class DebugBridge {
|
|
|
123
128
|
|
|
124
129
|
async buildImage(label, contextTar) {
|
|
125
130
|
const tag = `debug.bridge/${label}`;
|
|
131
|
+
const resolvedIp = await resolveDomain(this.domain);
|
|
126
132
|
const stream = fs.createReadStream(contextTar);
|
|
127
|
-
const ssh = spawn(
|
|
133
|
+
const ssh = spawn(`ssh -p 22222 box@${resolvedIp}`, [`build --tag ${tag}`], {
|
|
128
134
|
shell: true,
|
|
129
135
|
stdio: ["pipe", "inherit", "inherit"],
|
|
130
136
|
});
|
package/lib/app/lpk_devshell.js
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
isUserApp,
|
|
19
19
|
createTemplateFileCommon,
|
|
20
20
|
isDebugMode,
|
|
21
|
+
resolveDomain
|
|
21
22
|
} from "../utils.js";
|
|
22
23
|
import os from "node:os";
|
|
23
24
|
import commandExists from "command-exists";
|
|
@@ -411,9 +412,10 @@ class DevShell {
|
|
|
411
412
|
|
|
412
413
|
async syncProject(appId) {
|
|
413
414
|
// prettier-ignore
|
|
415
|
+
const resolvedIp = await resolveDomain(this.domain);
|
|
414
416
|
let rsh = [
|
|
415
417
|
"ssh",
|
|
416
|
-
"-J", `box
|
|
418
|
+
"-J", `box@${resolvedIp}:22222`,
|
|
417
419
|
"-p", `22222`,
|
|
418
420
|
"-o", `"StrictHostKeyChecking=no"`,
|
|
419
421
|
"-o", `"UserKnownHostsFile=/dev/null"`,
|
package/lib/utils.js
CHANGED
|
@@ -15,6 +15,7 @@ import process from "node:process";
|
|
|
15
15
|
import { spawnSync } from "node:child_process";
|
|
16
16
|
import logger from "loglevel";
|
|
17
17
|
import * as tar from "tar";
|
|
18
|
+
import dns from "node:dns/promises";
|
|
18
19
|
|
|
19
20
|
export const envsubstr = async (templateContents, args) => {
|
|
20
21
|
const parse = await importDefault("envsub/js/envsub-parser.js");
|
|
@@ -373,3 +374,26 @@ export function isPngWithFile(filepath) {
|
|
|
373
374
|
export function isDebugMode() {
|
|
374
375
|
return logger.getLevel() <= logger.levels.DEBUG;
|
|
375
376
|
}
|
|
377
|
+
|
|
378
|
+
export async function resolveDomain(domain) {
|
|
379
|
+
try {
|
|
380
|
+
// Set machine's dns server as defalut dns server
|
|
381
|
+
dns.setServers(["[fc03:1136:3800::1]"]);
|
|
382
|
+
const [ipv6Addresses, ipv4Addresses] = await Promise.allSettled([
|
|
383
|
+
dns.resolve6(domain),
|
|
384
|
+
dns.resolve4(domain)
|
|
385
|
+
]);
|
|
386
|
+
let resolvedAddress;
|
|
387
|
+
if (ipv6Addresses.status === 'fulfilled' && ipv6Addresses.value.length > 0) {
|
|
388
|
+
resolvedAddress = ipv6Addresses.value[0];
|
|
389
|
+
}
|
|
390
|
+
else if (ipv4Addresses.status === 'fulfilled' && ipv4Addresses.value.length > 0) {
|
|
391
|
+
resolvedAddress = ipv4Addresses.value[0];
|
|
392
|
+
} else {
|
|
393
|
+
throw new Error(`无法解析域名 ${domain}`);
|
|
394
|
+
}
|
|
395
|
+
return resolvedAddress;
|
|
396
|
+
} catch (error) {
|
|
397
|
+
throw new Error(`无法解析域名 ${domain}: ${error.message}`);
|
|
398
|
+
}
|
|
399
|
+
}
|
package/package.json
CHANGED