@rpcbase/cli 0.69.0-uiimport.0 → 0.70.0-fixdockerserver.0
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/package.json +1 -1
- package/src/helpers/docker_runtime_check.js +27 -1
- package/src/start_command.js +35 -97
package/package.json
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
+
const assert = require("assert")
|
|
2
3
|
const {execSync} = require("child_process")
|
|
3
4
|
const os = require("os")
|
|
4
5
|
const colors = require("picocolors")
|
|
5
6
|
|
|
6
7
|
|
|
8
|
+
const get_networks = () => {
|
|
9
|
+
const out = execSync("docker network ls --format=json")
|
|
10
|
+
const nets = out.toString().trim().split("\n")
|
|
11
|
+
.filter(l => !!l)
|
|
12
|
+
.map((l) => JSON.parse(l))
|
|
13
|
+
|
|
14
|
+
return nets
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
const docker_runtime_check = () => {
|
|
18
|
+
// check docker is running
|
|
8
19
|
try {
|
|
9
|
-
execSync("docker version
|
|
20
|
+
execSync("docker version --format=json")
|
|
10
21
|
} catch (err) {
|
|
11
22
|
console.log(colors.cyan("docker"), "exited with error")
|
|
12
23
|
process.exit(1)
|
|
13
24
|
}
|
|
25
|
+
|
|
26
|
+
// check network exists and create it if not
|
|
27
|
+
const {RB_APP_NAME} = process.env
|
|
28
|
+
assert(RB_APP_NAME, "missing RB_APP_NAME in env")
|
|
29
|
+
|
|
30
|
+
const net_name = `${RB_APP_NAME}-network`
|
|
31
|
+
|
|
32
|
+
const nets = get_networks()
|
|
33
|
+
|
|
34
|
+
const target_net = nets.find((n) => n.Name === net_name)
|
|
35
|
+
|
|
36
|
+
if (!target_net) {
|
|
37
|
+
execSync(`docker network create ${net_name}`)
|
|
38
|
+
console.log("created docker network:", net_name)
|
|
39
|
+
}
|
|
14
40
|
}
|
|
15
41
|
|
|
16
42
|
module.exports = docker_runtime_check
|
package/src/start_command.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
const debug = require("debug")("rb-cli")
|
|
2
|
+
// const debug = require("debug")("rb-cli")
|
|
3
3
|
const path = require("path")
|
|
4
|
-
const fs = require("fs")
|
|
5
4
|
const colors = require("picocolors")
|
|
6
|
-
const
|
|
7
|
-
const {exec} = require("child_process")
|
|
5
|
+
const {spawn} = require("child_process")
|
|
8
6
|
|
|
9
7
|
const {hideBin} = require("yargs/helpers")
|
|
10
8
|
|
|
@@ -15,109 +13,49 @@ const verify_project = require("./verify_project")
|
|
|
15
13
|
|
|
16
14
|
|
|
17
15
|
const start_command = async(args) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const run_configs = [
|
|
21
|
-
{
|
|
22
|
-
type: "client",
|
|
23
|
-
working_dir: path.join(cwd, "./client")
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
type: "server",
|
|
27
|
-
working_dir: path.join(cwd, "./server/server")
|
|
28
|
-
},
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
const run_commands = []
|
|
32
|
-
|
|
33
|
-
run_configs.forEach((cfg) => {
|
|
34
|
-
let name
|
|
35
|
-
let command
|
|
36
|
-
let prefixColor
|
|
37
|
-
// client
|
|
38
|
-
if (cfg.type === "client") {
|
|
39
|
-
name = "client"
|
|
40
|
-
// command = "yarn dev"
|
|
41
|
-
command = "./node_modules/.bin/bundler-client dev"
|
|
42
|
-
prefixColor = "#C678DD"
|
|
43
|
-
// server
|
|
44
|
-
} else if (cfg.type === "server") {
|
|
45
|
-
name = "server"
|
|
46
|
-
command = "./node_modules/.bin/bundler-server dev"
|
|
47
|
-
prefixColor = "#61AFEF"
|
|
48
|
-
// agent
|
|
49
|
-
} else if (cfg.type === "agent") {
|
|
50
|
-
name = "agent"
|
|
51
|
-
command = "./node_modules/.bin/rb agent"
|
|
52
|
-
prefixColor = "#4DB33D"
|
|
53
|
-
} else {
|
|
54
|
-
throw new Error("unknown cfg.type")
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// pass through listed args to client and server
|
|
58
|
-
if (["client", "server"].includes(cfg.type)) {
|
|
59
|
-
command = `${command} ${hideBin(process.argv).join(" ")}`
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// add command
|
|
63
|
-
run_commands.push({
|
|
64
|
-
name,
|
|
65
|
-
command,
|
|
66
|
-
prefixColor,
|
|
67
|
-
cwd: cfg.working_dir,
|
|
68
|
-
env: process.env,
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
// check if docker is installed and running
|
|
16
|
+
// check if docker is installed and running, and there is the proper network
|
|
73
17
|
docker_runtime_check()
|
|
74
18
|
|
|
75
19
|
// start the tailscale tunnel
|
|
76
|
-
|
|
20
|
+
console.log("Warning: tmp disabled tailscale tunnels")
|
|
21
|
+
// tailscale_tunnel.start(run_configs)
|
|
77
22
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const {result, commands} = concurrently(run_commands, {
|
|
81
|
-
killOthers: ["success", "failure"],
|
|
82
|
-
// prefix: "none",
|
|
83
|
-
handleInput: true,
|
|
84
|
-
defaultInputTarget: "server",
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
result
|
|
88
|
-
.then(() => {
|
|
89
|
-
console.log("Done.")
|
|
90
|
-
})
|
|
91
|
-
.catch((err) => {
|
|
92
|
-
if (project_errors?.length > 0) {
|
|
93
|
-
console.log(`\n${colors.bold("exited due to configuration errors:")}`)
|
|
94
|
-
project_errors.forEach((err) => {
|
|
95
|
-
console.log(err)
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
})
|
|
23
|
+
const cwd = process.cwd()
|
|
99
24
|
|
|
100
|
-
|
|
25
|
+
const working_dir = path.join(cwd, "./server/server")
|
|
26
|
+
const command = "./node_modules/.bin/bundler-server"
|
|
101
27
|
|
|
102
|
-
|
|
103
|
-
const configs = run_configs
|
|
104
|
-
.filter(({type}) => ["client", "server"].includes(type))
|
|
28
|
+
const ps = spawn(command, ["dev", ...hideBin(process.argv)], {cwd: working_dir, stdio: "inherit", shell: true})
|
|
105
29
|
|
|
106
|
-
|
|
30
|
+
ps.on("close", (code) => {
|
|
31
|
+
// tailscale_tunnel.stop(run_configs)
|
|
32
|
+
console.log("Done.")
|
|
33
|
+
})
|
|
107
34
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
35
|
+
// let project_errors
|
|
36
|
+
// result
|
|
37
|
+
// .then(() => {
|
|
38
|
+
// console.log("Done.")
|
|
39
|
+
// })
|
|
40
|
+
// .catch((err) => {
|
|
41
|
+
// if (project_errors?.length > 0) {
|
|
42
|
+
// console.log(`\n${colors.bold("exited due to configuration errors:")}`)
|
|
43
|
+
// project_errors.forEach((err) => {
|
|
44
|
+
// console.log(err)
|
|
45
|
+
// })
|
|
46
|
+
// }
|
|
47
|
+
// })
|
|
48
|
+
|
|
49
|
+
// project_errors = await verify_project(configs)
|
|
50
|
+
|
|
51
|
+
// if (project_errors.length > 0) {
|
|
52
|
+
// commands.forEach((c) => {
|
|
53
|
+
// c.kill()
|
|
54
|
+
// })
|
|
55
|
+
// }
|
|
113
56
|
|
|
114
57
|
// server cmd to stop tailscale serve
|
|
115
|
-
const server_command = commands.find((c) => c.name === "server")
|
|
116
|
-
|
|
117
|
-
server_command.process.on("close", () => {
|
|
118
|
-
tailscale_tunnel.stop(run_configs)
|
|
119
|
-
})
|
|
120
|
-
|
|
58
|
+
// const server_command = commands.find((c) => c.name === "server")
|
|
121
59
|
}
|
|
122
60
|
|
|
123
61
|
module.exports = start_command
|