@rpcbase/cli 0.38.0 → 0.40.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/bin.js +14 -3
- package/package.json +2 -1
- package/src/helpers/docker_runtime_check.js +0 -6
- package/src/helpers/get_run_configs.js +3 -7
- package/src/helpers/tailscale_tunnel.js +3 -2
- package/src/increment-pkg/get_gh_token.js +30 -0
- package/src/increment-pkg/index.js +125 -0
- package/src/start_command.js +2 -4
package/bin.js
CHANGED
|
@@ -8,10 +8,11 @@ require("dotenv").config({path: path.join(process.cwd(), "./.env")})
|
|
|
8
8
|
const yargs = require("yargs/yargs")
|
|
9
9
|
const {hideBin} = require("yargs/helpers")
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const increment_pkg = require("./src/increment-pkg")
|
|
12
12
|
const print_versions = require("./src/print_versions")
|
|
13
|
-
const
|
|
13
|
+
const start_command = require("./src/start_command")
|
|
14
14
|
const sync_dotenv = require("./src/sync-dotenv")
|
|
15
|
+
const update = require("./src/update")
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
yargs(hideBin(process.argv))
|
|
@@ -23,6 +24,11 @@ yargs(hideBin(process.argv))
|
|
|
23
24
|
default: false,
|
|
24
25
|
description: "Adds coverage instrumentation (always disabled in production)"
|
|
25
26
|
})
|
|
27
|
+
.option("docker", {
|
|
28
|
+
type: "boolean",
|
|
29
|
+
default: false,
|
|
30
|
+
description: "Run in docker"
|
|
31
|
+
})
|
|
26
32
|
.option("verbose", {
|
|
27
33
|
type: "boolean",
|
|
28
34
|
default: false,
|
|
@@ -34,7 +40,6 @@ yargs(hideBin(process.argv))
|
|
|
34
40
|
description: "Run with debug logging"
|
|
35
41
|
})
|
|
36
42
|
}, (argv) => {
|
|
37
|
-
console.log("IS start")
|
|
38
43
|
if (argv.version) return print_versions()
|
|
39
44
|
start_command(argv)
|
|
40
45
|
})
|
|
@@ -50,6 +55,12 @@ yargs(hideBin(process.argv))
|
|
|
50
55
|
if (argv.version) return print_versions()
|
|
51
56
|
await update()
|
|
52
57
|
})
|
|
58
|
+
// Increment pkg
|
|
59
|
+
.command(["increment-pkg <files...>"], "Bump a package version if necessary by checking its source on github", (yargs) => {
|
|
60
|
+
}, async(argv) => {
|
|
61
|
+
if (argv.version) return print_versions()
|
|
62
|
+
await increment_pkg(argv)
|
|
63
|
+
})
|
|
53
64
|
// sync-dotenv
|
|
54
65
|
.command("sync-dotenv [source_env] [dest_env]", "Compare and sync dotenv files", (yargs) => {
|
|
55
66
|
yargs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"license": "SSPL-1.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"rb": "./bin.js"
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"concurrently": "8.2.1",
|
|
14
14
|
"debug": "4.3.4",
|
|
15
15
|
"dotenv": "16.3.1",
|
|
16
|
+
"octokit": "2.1.0",
|
|
16
17
|
"parse-dotenv": "2.1.0",
|
|
17
18
|
"picocolors": "1.0.0",
|
|
18
19
|
"semver": "7.5.4",
|
|
@@ -3,14 +3,8 @@ const {execSync} = require("child_process")
|
|
|
3
3
|
const os = require("os")
|
|
4
4
|
const colors = require("picocolors")
|
|
5
5
|
|
|
6
|
-
const {CONTAINER_MODE} = process.env
|
|
7
6
|
|
|
8
7
|
const docker_runtime_check = () => {
|
|
9
|
-
// skip check on osx except when forcing docker
|
|
10
|
-
if (os.platform() === "darwin" && CONTAINER_MODE !== "docker") {
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
8
|
try {
|
|
15
9
|
execSync("docker version -f json")
|
|
16
10
|
} catch (err) {
|
|
@@ -5,13 +5,8 @@ const fs = require("fs")
|
|
|
5
5
|
const ERRORS = require("../errors")
|
|
6
6
|
const exit_with_message = require("./exit_with_message")
|
|
7
7
|
|
|
8
|
-
const {CONTAINER_MODE} = process.env
|
|
9
|
-
|
|
10
8
|
// run type is client | server | both
|
|
11
|
-
const get_run_configs = () => {
|
|
12
|
-
if (!["docker", "native"].includes(CONTAINER_MODE.trim()))
|
|
13
|
-
throw new Error("expected CONTAINER_MODE to be native|docker")
|
|
14
|
-
|
|
9
|
+
const get_run_configs = (args) => {
|
|
15
10
|
const cwd = process.cwd()
|
|
16
11
|
|
|
17
12
|
// check if running parent of rb project
|
|
@@ -62,8 +57,9 @@ const get_run_configs = () => {
|
|
|
62
57
|
|
|
63
58
|
if (run_configs) {
|
|
64
59
|
// check if there is server we add agent but in native mode only
|
|
60
|
+
// in docker mode, the agent is a container
|
|
65
61
|
const server = run_configs.find((rc) => rc.type === "server")
|
|
66
|
-
if (server &&
|
|
62
|
+
if (server && !args.docker) {
|
|
67
63
|
run_configs.push({
|
|
68
64
|
type: "agent",
|
|
69
65
|
working_dir: server.working_dir,
|
|
@@ -35,7 +35,7 @@ const start = (run_configs) => {
|
|
|
35
35
|
execSync(`${TAILSCALE_PATH} serve https:443 / http://127.0.0.1:${server_port}`, {stdio: "inherit"})
|
|
36
36
|
execSync(`${TAILSCALE_PATH} funnel 443 on`, {stdio: "inherit"})
|
|
37
37
|
} catch (err) {
|
|
38
|
-
console.log("
|
|
38
|
+
console.log("error starting tailscale, is the tailscale app running ?")
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -49,7 +49,8 @@ const stop = (run_configs) => {
|
|
|
49
49
|
execSync(`${TAILSCALE_PATH} serve https:443 / http://127.0.0.1:${server_port} off`, {stdio: "inherit"})
|
|
50
50
|
execSync(`${TAILSCALE_PATH} funnel 443 off`, {stdio: "inherit"})
|
|
51
51
|
} catch (err) {
|
|
52
|
-
console.log("TAILSCALE ERR", err)
|
|
52
|
+
// console.log("TAILSCALE ERR", err)
|
|
53
|
+
console.log("error stopping tailscale, it probably wasn't initally running. you can probably ignore it")
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
const fs = require("fs")
|
|
3
|
+
const path = require("path")
|
|
4
|
+
|
|
5
|
+
const get_gh_token = () => {
|
|
6
|
+
let token
|
|
7
|
+
|
|
8
|
+
const npmrc_path = path.join(process.cwd(), "./.npmrc")
|
|
9
|
+
const gh_token_path = path.join(process.cwd(), "./.gh_token")
|
|
10
|
+
|
|
11
|
+
if (fs.existsSync(npmrc_path)) {
|
|
12
|
+
const content = fs.readFileSync(npmrc_path, "utf8")
|
|
13
|
+
const match = content.match(/^\/\/npm\.pkg\.github\.com\/:_authToken=(\S+)$/m)
|
|
14
|
+
|
|
15
|
+
if (match) {
|
|
16
|
+
token = match[1]
|
|
17
|
+
}
|
|
18
|
+
} else if (fs.existsSync(gh_token_path)) {
|
|
19
|
+
try {
|
|
20
|
+
token = JSON.parse(fs.readFileSync(gh_token_path))
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.log("unable to parse token from .gh_token")
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
return token
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = get_gh_token
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
const fs = require("fs")
|
|
3
|
+
const path = require("path")
|
|
4
|
+
const {execSync} = require("child_process")
|
|
5
|
+
|
|
6
|
+
const colors = require("picocolors")
|
|
7
|
+
const Promise = require("bluebird")
|
|
8
|
+
const semver = require("semver")
|
|
9
|
+
const {Octokit} = require("octokit")
|
|
10
|
+
|
|
11
|
+
const get_gh_token = require("./get_gh_token")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const get_gh_client = () => {
|
|
15
|
+
const gh_token = get_gh_token()
|
|
16
|
+
|
|
17
|
+
if (!gh_token) return
|
|
18
|
+
|
|
19
|
+
const octokit = new Octokit({
|
|
20
|
+
auth: gh_token
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
return octokit
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const get_latest_live_version = async(pack_dir) => {
|
|
28
|
+
const octokit = get_gh_client()
|
|
29
|
+
|
|
30
|
+
if (!octokit) {
|
|
31
|
+
console.log(colors.bold(colors.yellow("rb increment-pkg:")), "unable to get a github client, do you have a token in .npmrc or .github_token ?")
|
|
32
|
+
process.exit(0)
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const origin_url = execSync("git remote get-url origin").toString().trim()
|
|
37
|
+
const owner = path.dirname(origin_url).split(":").pop()
|
|
38
|
+
const repo = path.basename(origin_url).replace(/\.git$/, "")
|
|
39
|
+
|
|
40
|
+
const remote_path = `pkg/${pack_dir}/package.json`
|
|
41
|
+
|
|
42
|
+
let res
|
|
43
|
+
try {
|
|
44
|
+
res = await octokit.request("GET /repos/{owner}/{repo}/contents/{path}", {
|
|
45
|
+
owner,
|
|
46
|
+
repo,
|
|
47
|
+
path: remote_path,
|
|
48
|
+
})
|
|
49
|
+
} catch (err) {
|
|
50
|
+
if (err.response.status === 404) {
|
|
51
|
+
console.log(`${owner}/${repo}/${remote_path} remote package not found, skipping version bump`)
|
|
52
|
+
return
|
|
53
|
+
} else {
|
|
54
|
+
console.log(err)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const file_contents = Buffer.from(res.data.content, "base64").toString()
|
|
59
|
+
const pack_obj = JSON.parse(file_contents)
|
|
60
|
+
const live_version = pack_obj.version
|
|
61
|
+
|
|
62
|
+
return live_version
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// lint-staged script to increment package version when any package in the pkg/ folder is modified
|
|
67
|
+
const increment_pkg = async(args) => {
|
|
68
|
+
const {files} = args
|
|
69
|
+
|
|
70
|
+
const touched_packages = {}
|
|
71
|
+
|
|
72
|
+
const packages_dir = path.join(process.cwd(), "./pkg")
|
|
73
|
+
|
|
74
|
+
files.forEach((f) => {
|
|
75
|
+
const rel_path = path.relative(packages_dir, f)
|
|
76
|
+
// get package dirname
|
|
77
|
+
const [pack_dir] = path.dirname(rel_path).split("/")
|
|
78
|
+
// check if it is actually a package
|
|
79
|
+
const pack_json_path = path.join(packages_dir, `./${pack_dir}/package.json`)
|
|
80
|
+
if (fs.existsSync(pack_json_path)) {
|
|
81
|
+
touched_packages[pack_dir] = true
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const process_package = async(pack_dir) => {
|
|
86
|
+
const local_pack_path = path.join(packages_dir, `./${pack_dir}/package.json`)
|
|
87
|
+
const local_pack = JSON.parse(fs.readFileSync(local_pack_path))
|
|
88
|
+
|
|
89
|
+
const local_version = local_pack.version
|
|
90
|
+
if (!local_version) {
|
|
91
|
+
// skipping because package has no local version
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const live_version = await get_latest_live_version(pack_dir)
|
|
96
|
+
|
|
97
|
+
if (!semver.valid(live_version)) {
|
|
98
|
+
console.log("warning:", "live version not valid, got:", JSON.stringify(live_version), "skipping")
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!semver.valid(local_version)) {
|
|
103
|
+
console.log("error:", "local version not valid, got:", JSON.stringify(local_version), "skipping")
|
|
104
|
+
process.exit(1)
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// if local_version == live_version -> bump
|
|
109
|
+
if (live_version && semver.eq(local_version, live_version)) {
|
|
110
|
+
const new_version = semver.inc(local_version, "minor")
|
|
111
|
+
|
|
112
|
+
console.log("bumped", local_pack.name, "to", new_version)
|
|
113
|
+
|
|
114
|
+
local_pack.version = new_version
|
|
115
|
+
fs.writeFileSync(local_pack_path, JSON.stringify(local_pack, null, 2) + "\n")
|
|
116
|
+
|
|
117
|
+
// add to git index, in case change was not triggered by package.json
|
|
118
|
+
execSync(`git add ${local_pack_path}`)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
await Promise.map(Object.keys(touched_packages), process_package)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
module.exports = increment_pkg
|
package/src/start_command.js
CHANGED
|
@@ -18,7 +18,7 @@ const verify_project = require("./verify_project")
|
|
|
18
18
|
// server native + docker + docker-native is way too complex
|
|
19
19
|
// either everything is native, or everything is in docker
|
|
20
20
|
const start_command = async(args) => {
|
|
21
|
-
const run_configs = get_run_configs()
|
|
21
|
+
const run_configs = get_run_configs(args)
|
|
22
22
|
|
|
23
23
|
const run_commands = []
|
|
24
24
|
|
|
@@ -49,7 +49,6 @@ const start_command = async(args) => {
|
|
|
49
49
|
command = `${command} ${hideBin(process.argv).join(" ")}`
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
52
|
// add command
|
|
54
53
|
run_commands.push({
|
|
55
54
|
name,
|
|
@@ -62,9 +61,8 @@ const start_command = async(args) => {
|
|
|
62
61
|
|
|
63
62
|
const has_server = run_configs.findIndex((c) => c.type === "server") > -1
|
|
64
63
|
|
|
65
|
-
// TODO: we shouldnt check in native mode
|
|
66
64
|
// check if docker is running
|
|
67
|
-
if (
|
|
65
|
+
if (args.docker) {
|
|
68
66
|
docker_runtime_check()
|
|
69
67
|
}
|
|
70
68
|
|