@rpcbase/cli 0.49.0 → 0.58.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.
@@ -0,0 +1 @@
1
+ {"fullyTracked":false,"platform":"linux","arch":"x64","nodeVersion":"v18.19.0","command":"node ../../scripts/prflow/apply-prerelease-versions.js $BRANCH_NAME","extraArgs":[],"clean":true,"files":{},"output":[],"dependencies":{},"env":{}}
File without changes
File without changes
package/bin.js CHANGED
@@ -13,6 +13,7 @@ const print_versions = require("./src/print_versions")
13
13
  const start_command = require("./src/start_command")
14
14
  const sync_dotenv = require("./src/sync-dotenv")
15
15
  const update = require("./src/update")
16
+ const wait_for = require("./src/wait-for")
16
17
 
17
18
 
18
19
  yargs(hideBin(process.argv))
@@ -81,6 +82,10 @@ yargs(hideBin(process.argv))
81
82
  if (argv.version) return print_versions()
82
83
  await sync_dotenv(argv.source_env, argv.dest_env)
83
84
  })
85
+ // wait-for
86
+ .command("wait-for", "", () => {}, (argv) => {
87
+ wait_for()
88
+ })
84
89
  // Ping
85
90
  .command("ping", "Ping", () => {}, (argv) => {
86
91
  if (argv.version) return print_versions()
package/package.json CHANGED
@@ -1,13 +1,38 @@
1
1
  {
2
2
  "name": "@rpcbase/cli",
3
- "version": "0.49.0",
3
+ "version": "0.58.0",
4
4
  "license": "SSPL-1.0",
5
5
  "bin": {
6
6
  "rb": "./bin.js"
7
7
  },
8
+ "publishConfig": {
9
+ "registry": "https://registry.npmjs.org/"
10
+ },
8
11
  "scripts": {
9
12
  "test": "echo \"no test specified exiting with code 0\" && exit 0"
10
13
  },
14
+ "wireit": {
15
+ "apply-version": {
16
+ "command": "node ../../scripts/prflow/apply-prerelease-versions.js $BRANCH_NAME"
17
+ },
18
+ "release": {
19
+ "command": "npm publish --tag $NPM_RELEASE_CHANNEL | tee publish-output.txt",
20
+ "dependencies": [
21
+ "apply-version"
22
+ ],
23
+ "files": [
24
+ "package.json"
25
+ ],
26
+ "output": [
27
+ "publish-output.txt"
28
+ ],
29
+ "env": {
30
+ "NPM_RELEASE_CHANNEL": {
31
+ "external": true
32
+ }
33
+ }
34
+ }
35
+ },
11
36
  "dependencies": {
12
37
  "bluebird": "3.7.2",
13
38
  "concurrently": "8.2.1",
File without changes
@@ -52,6 +52,7 @@ const get_run_configs = (args) => {
52
52
  ]
53
53
  } else {
54
54
  console.log("TODO: server get_run_configs:handle edge case here")
55
+ console.log("process.cwd:", process.cwd())
55
56
  }
56
57
  }
57
58
 
@@ -2,15 +2,19 @@
2
2
  const path = require("path")
3
3
  const fs = require("fs")
4
4
  const dotenv = require("dotenv")
5
- const {execSync} = require("child_process")
5
+ const child_process = require("child_process")
6
+ const util = require("util")
6
7
 
7
8
  const get_root_dir = require("./get_root_dir")
8
9
 
9
10
 
11
+ const exec = util.promisify(child_process.exec)
12
+
10
13
  const TAILSCALE_PATH = "/Applications/Tailscale.app/Contents/MacOS/Tailscale"
11
14
 
12
15
  const has_tailscale = process.platform === "darwin" && fs.existsSync(TAILSCALE_PATH)
13
16
 
17
+
14
18
  const get_port = (run_configs) => {
15
19
  const project_root_dir = get_root_dir(run_configs)
16
20
 
@@ -26,29 +30,48 @@ const get_port = (run_configs) => {
26
30
  }
27
31
 
28
32
 
29
- const start = (run_configs) => {
33
+ const check_status = async() => {
34
+ try {
35
+ const {stdout, stderr} = await exec(`${TAILSCALE_PATH} funnel status --json`)
36
+ const out = JSON.parse(stdout)
37
+ return typeof out === "object"
38
+ } catch (err) {
39
+ //
40
+ }
41
+ return false
42
+ }
43
+
44
+ const start = async(run_configs) => {
30
45
  if (!has_tailscale) return
31
46
 
47
+ const should_ts_start = await check_status()
48
+
49
+ if (!should_ts_start) return
50
+
32
51
  const {server_port, wss_port} = get_port(run_configs)
33
52
  try {
34
- execSync(`${TAILSCALE_PATH} funnel --bg --set-path /wss --https=${wss_port} http://127.0.0.1:${wss_port}`, {stdio: "inherit"})
35
- execSync(`${TAILSCALE_PATH} funnel --bg --set-path / --https=443 http://127.0.0.1:${server_port}`, {stdio: "inherit"})
53
+ await exec(`${TAILSCALE_PATH} funnel --bg --set-path / --https=443 http://127.0.0.1:${server_port}`, {stdio: "inherit"})
54
+ if (wss_port) {
55
+ await exec(`${TAILSCALE_PATH} funnel --bg --set-path /wss --https=${wss_port} http://127.0.0.1:${wss_port}`, {stdio: "inherit"})
56
+ }
36
57
  } catch (err) {
37
58
  console.log("error starting tailscale, is the tailscale app running ?")
38
59
  }
39
60
  }
40
61
 
41
62
 
42
- const stop = (run_configs) => {
63
+ const stop = async(run_configs) => {
43
64
  if (!has_tailscale) return
44
65
 
45
66
  const {server_port, wss_port} = get_port(run_configs)
46
67
  try {
47
- execSync(`${TAILSCALE_PATH} funnel --https=${wss_port} off`, {stdio: "inherit"})
48
- execSync(`${TAILSCALE_PATH} funnel --https=443 off`, {stdio: "inherit"})
68
+ await exec(`${TAILSCALE_PATH} funnel --https=443 off`, {stdio: "inherit"})
69
+ if (wss_port) {
70
+ await exec(`${TAILSCALE_PATH} funnel --https=${wss_port} off`)
71
+ }
49
72
  } catch (err) {
50
73
  // console.log("TAILSCALE ERR", err)
51
- console.log("error stopping tailscale, it probably wasn't initally running. you can probably ignore it")
74
+ console.log("error stopping tailscale, it probably wasn't initally running. you can ignore it")
52
75
  }
53
76
  }
54
77
 
@@ -0,0 +1,21 @@
1
+ /* @flow */
2
+ const path = require("path")
3
+ const {execSync} = require("child_process");
4
+
5
+ const wait_for = () => {
6
+ process.title = "rb-wait-for"
7
+
8
+ const args = process.argv.slice(3).join(" ")
9
+
10
+ const script_path = path.join(__dirname, "./wait-for.sh")
11
+
12
+ const command = `${script_path} ${args}`
13
+
14
+ try {
15
+ execSync(command, {stdio: "inherit"})
16
+ } catch (error) {
17
+ console.error(`wait-for execution failed: ${error}`)
18
+ }
19
+ }
20
+
21
+ module.exports = wait_for
@@ -0,0 +1,81 @@
1
+ #!/bin/sh
2
+
3
+ # original script: https://github.com/eficode/wait-for/blob/master/wait-for
4
+
5
+ TIMEOUT=120
6
+ QUIET=0
7
+
8
+ echoerr() {
9
+ if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
10
+ }
11
+
12
+ usage() {
13
+ exitcode="$1"
14
+ cat << USAGE >&2
15
+ Usage:
16
+ $cmdname host:port [-t timeout] [-- command args]
17
+ -q | --quiet Do not output any status messages
18
+ -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
19
+ -- COMMAND ARGS Execute command with args after the test finishes
20
+ USAGE
21
+ exit "$exitcode"
22
+ }
23
+
24
+ wait_for() {
25
+ for i in `seq $TIMEOUT` ; do
26
+ nc -z "$HOST" "$PORT" > /dev/null 2>&1
27
+
28
+ result=$?
29
+ if [ $result -eq 0 ] ; then
30
+ if [ $# -gt 0 ] ; then
31
+ exec "$@"
32
+ fi
33
+ exit 0
34
+ fi
35
+ sleep 1
36
+ done
37
+ echo "wait-for::Operation timed out" >&2
38
+ exit 1
39
+ }
40
+
41
+ while [ $# -gt 0 ]
42
+ do
43
+ case "$1" in
44
+ *:* )
45
+ HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
46
+ PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
47
+ shift 1
48
+ ;;
49
+ -q | --quiet)
50
+ QUIET=1
51
+ shift 1
52
+ ;;
53
+ -t)
54
+ TIMEOUT="$2"
55
+ if [ "$TIMEOUT" = "" ]; then break; fi
56
+ shift 2
57
+ ;;
58
+ --timeout=*)
59
+ TIMEOUT="${1#*=}"
60
+ shift 1
61
+ ;;
62
+ --)
63
+ shift
64
+ break
65
+ ;;
66
+ --help)
67
+ usage 0
68
+ ;;
69
+ *)
70
+ echoerr "Unknown argument: $1"
71
+ usage 1
72
+ ;;
73
+ esac
74
+ done
75
+
76
+ if [ "$HOST" = "" -o "$PORT" = "" ]; then
77
+ echoerr "Error: you need to provide a host and port to test."
78
+ usage 2
79
+ fi
80
+
81
+ wait_for "$@"
@@ -1,8 +0,0 @@
1
- /* @flow */
2
-
3
- const {syncEnv} = require("./index")
4
-
5
-
6
- const res = syncEnv(".env", ".env.sample")
7
-
8
- // console.log("FNDE", res)