@rpcbase/cli 0.24.0 → 0.26.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/cli",
3
- "version": "0.24.0",
3
+ "version": "0.26.0",
4
4
  "license": "SSPL-1.0",
5
5
  "bin": {
6
6
  "rb": "./bin.js"
@@ -0,0 +1,19 @@
1
+ /* @flow */
2
+ const path = require("path")
3
+
4
+ const get_root_dir = (run_configs) => {
5
+ let project_root_dir
6
+ if (run_configs[0].type === "server") {
7
+ project_root_dir = path.join(run_configs[0].working_dir, "../../")
8
+ } else if (run_configs[0].type === "client") {
9
+ project_root_dir = path.join(run_configs[0].working_dir, "../")
10
+ }
11
+
12
+ if (!project_root_dir) {
13
+ throw new Error("unable to find project root dir")
14
+ }
15
+
16
+ return project_root_dir
17
+ }
18
+
19
+ module.exports = get_root_dir
@@ -0,0 +1,40 @@
1
+ /* @flow */
2
+ const path = require("path")
3
+ const fs = require("fs")
4
+ const dotenv = require("dotenv")
5
+ const {execSync} = require("child_process")
6
+
7
+ const get_root_dir = require("./get_root_dir")
8
+
9
+
10
+ const TAILSCALE_PATH = "/Applications/Tailscale.app/Contents/MacOS/Tailscale"
11
+
12
+ const get_port = (run_configs) => {
13
+ const project_root_dir = get_root_dir(run_configs)
14
+
15
+ const server_env_path = path.join(project_root_dir, "./server/server/.env")
16
+
17
+ const server_env_buf = fs.readFileSync(server_env_path)
18
+ const parsed_env = dotenv.parse(server_env_buf)
19
+
20
+ const port = parsed_env.SERVER_PORT
21
+ return port
22
+ }
23
+
24
+
25
+ const start = (run_configs) => {
26
+ const port = get_port(run_configs)
27
+
28
+ execSync(`${TAILSCALE_PATH} funnel 443 on`, {stdio: "inherit"})
29
+ execSync(`${TAILSCALE_PATH} serve https / http://127.0.0.1:${port}`, {stdio: "inherit"})
30
+ }
31
+
32
+
33
+ const stop = (run_configs) => {
34
+ const port = get_port(run_configs)
35
+
36
+ execSync(`${TAILSCALE_PATH} funnel 443 off`, {stdio: "inherit"})
37
+ execSync(`${TAILSCALE_PATH} serve https / http://127.0.0.1:${port} off`, {stdio: "inherit"})
38
+ }
39
+
40
+ module.exports = {start, stop}
@@ -4,10 +4,12 @@ const path = require("path")
4
4
  const fs = require("fs")
5
5
  const colors = require("picocolors")
6
6
  const concurrently = require("concurrently")
7
+ const {exec} = require("child_process")
7
8
 
8
9
  const docker_runtime_check = require("./helpers/docker_runtime_check")
9
10
  const exit_with_message = require("./helpers/exit_with_message")
10
11
  const get_run_configs = require("./helpers/get_run_configs")
12
+ const tailscale_tunnel = require("./helpers/tailscale_tunnel")
11
13
  const verify_project = require("./verify_project")
12
14
 
13
15
  // TODO: nuke this
@@ -17,6 +19,7 @@ const start_command = async(args) => {
17
19
  const run_configs = get_run_configs()
18
20
 
19
21
  const run_commands = []
22
+
20
23
  run_configs.forEach((cfg) => {
21
24
  let name
22
25
  let command
@@ -63,14 +66,21 @@ const start_command = async(args) => {
63
66
  })
64
67
  })
65
68
 
69
+ const has_server = run_configs.findIndex((c) => c.type === "server") > -1
70
+
71
+ // TODO: we shouldnt check in native mode
66
72
  // check if docker is running
67
- if (run_configs.filter((c) => c.type === "server").length > 0) {
73
+ if (has_server) {
68
74
  docker_runtime_check()
69
75
  }
70
76
 
71
- let project_errors
77
+ // check if we should run the tunnel
78
+ // uses tailscale
79
+ if (has_server) {
80
+ tailscale_tunnel.start(run_configs)
81
+ }
72
82
 
73
- // console.log("RUN COMMANDS", run_commands)
83
+ let project_errors
74
84
 
75
85
  const {result, commands} = concurrently(run_commands, {
76
86
  killOthers: ["success", "failure"],
@@ -104,6 +114,16 @@ const start_command = async(args) => {
104
114
  c.kill()
105
115
  })
106
116
  }
117
+
118
+
119
+ // server cmd to stop tailscale serve
120
+ const server_command = commands.find((c) => c.name === "server")
121
+ if (server_command) {
122
+ server_command.process.on("close", () => {
123
+ tailscale_tunnel.stop(run_configs)
124
+ })
125
+ }
126
+
107
127
  }
108
128
 
109
129
  module.exports = start_command
@@ -1,28 +1,13 @@
1
1
  /* @flow */
2
- const path = require("path")
3
- const _ = require("lodash")
2
+ const _flatten = require("lodash/flatten")
4
3
  const colors = require("picocolors")
5
4
  const Promise = require("bluebird")
6
5
 
6
+ const get_root_dir = require("../helpers/get_root_dir")
7
+
7
8
  const verify_packages_installed = require("./verify_packages_installed")
8
9
  const verify_env = require("./verify_env")
9
10
 
10
- const get_root_dir = (run_configs) => {
11
- let project_root_dir
12
- if (run_configs[0].type === "server") {
13
- project_root_dir = path.join(run_configs[0].working_dir, "../../")
14
- } else if (run_configs[0].type === "client") {
15
- project_root_dir = path.join(run_configs[0].working_dir, "../")
16
- }
17
-
18
- if (!project_root_dir) {
19
- throw new Error("unable to find project root dir")
20
- }
21
-
22
- return project_root_dir
23
- }
24
-
25
-
26
11
  const verify_project = async(run_configs) => {
27
12
  let result_errors = []
28
13
 
@@ -33,7 +18,7 @@ const verify_project = async(run_configs) => {
33
18
  const project_root_dir = get_root_dir(run_configs)
34
19
 
35
20
  // check if all installed packages match semver in package json file
36
- const deps_errors = _.flatten(
21
+ const deps_errors = _flatten(
37
22
  await Promise.map(run_configs.map(({working_dir}) => working_dir), verify_packages_installed(project_root_dir))
38
23
  )
39
24