@rpcbase/cli 0.25.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.25.0",
3
+ "version": "0.26.0",
4
4
  "license": "SSPL-1.0",
5
5
  "bin": {
6
6
  "rb": "./bin.js"
@@ -15,7 +15,6 @@
15
15
  "dotenv": "16.0.1",
16
16
  "picocolors": "1.0.0",
17
17
  "semver": "7.3.7",
18
- "tunnelmole": "2.1.2",
19
18
  "validator": "13.7.0",
20
19
  "yargs": "17.6.2"
21
20
  }
@@ -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
@@ -73,13 +75,9 @@ const start_command = async(args) => {
73
75
  }
74
76
 
75
77
  // check if we should run the tunnel
78
+ // uses tailscale
76
79
  if (has_server) {
77
- run_commands.push({
78
- name: "tunnel",
79
- command: "./node_modules/.bin/tunnelmole 80",
80
- prefixColor: "#F00",
81
- cwd: process.cwd(),
82
- })
80
+ tailscale_tunnel.start(run_configs)
83
81
  }
84
82
 
85
83
  let project_errors
@@ -116,6 +114,16 @@ const start_command = async(args) => {
116
114
  c.kill()
117
115
  })
118
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
+
119
127
  }
120
128
 
121
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