@rpcbase/cli 0.9.0 → 0.13.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 +47 -22
- package/package.json +3 -3
- package/src/errors.js +2 -2
- package/src/helpers/docker_runtime_check.js +2 -2
- package/src/helpers/exit_with_message.js +2 -2
- package/src/print_versions.js +15 -0
- package/src/{default_command.js → start_command.js} +16 -7
- package/src/verify_project/index.js +4 -4
- package/src/verify_project/thresholds.schema.json +28 -0
- package/src/verify_project/verify_env.js +6 -5
- package/src/verify_project/verify_packages_installed.js +2 -2
package/bin.js
CHANGED
|
@@ -1,39 +1,64 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* @flow */
|
|
3
3
|
process.title = "rb"
|
|
4
|
+
// load .env
|
|
4
5
|
const path = require("path")
|
|
5
|
-
require("dotenv").config({path: path.join(
|
|
6
|
+
require("dotenv").config({path: path.join(process.cwd(), "./.env")})
|
|
7
|
+
//
|
|
6
8
|
const yargs = require("yargs/yargs")
|
|
7
9
|
const {hideBin} = require("yargs/helpers")
|
|
8
10
|
|
|
9
|
-
const
|
|
11
|
+
const start_command = require("./src/start_command")
|
|
12
|
+
const print_versions = require("./src/print_versions")
|
|
10
13
|
const update = require("./src/update")
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
yargs(hideBin(process.argv))
|
|
16
|
+
.command(["start", "*"], "Starts client, server, and infrastructure", (yargs) => {
|
|
17
|
+
yargs
|
|
18
|
+
.option("coverage", {
|
|
19
|
+
alias: "c",
|
|
20
|
+
type: "boolean",
|
|
21
|
+
default: false,
|
|
22
|
+
description: "Adds coverage instrumentation (always disabled in production)"
|
|
23
|
+
})
|
|
24
|
+
.option("verbose", {
|
|
25
|
+
type: "boolean",
|
|
26
|
+
default: false,
|
|
27
|
+
description: "Run with verbose logging"
|
|
28
|
+
})
|
|
29
|
+
.option("debug", {
|
|
30
|
+
type: "boolean",
|
|
31
|
+
default: false,
|
|
32
|
+
description: "Run with debug logging"
|
|
33
|
+
})
|
|
34
|
+
}, (argv) => {
|
|
35
|
+
if (argv.version) return print_versions()
|
|
36
|
+
start_command(argv)
|
|
37
|
+
})
|
|
38
|
+
// Update
|
|
39
|
+
.command(["update", "up"], "Update rb dependencies to latest version", (yargs) => {
|
|
40
|
+
yargs
|
|
41
|
+
.option("dry-run", {
|
|
42
|
+
type: "boolean",
|
|
43
|
+
default: false,
|
|
44
|
+
description: "Print output without writing any files"
|
|
45
|
+
})
|
|
46
|
+
}, async(argv) => {
|
|
47
|
+
if (argv.version) return print_versions()
|
|
17
48
|
await update()
|
|
18
49
|
})
|
|
50
|
+
// Ping
|
|
19
51
|
.command("ping", "Ping", () => {}, (argv) => {
|
|
20
|
-
|
|
52
|
+
if (argv.version) return print_versions()
|
|
21
53
|
console.log("PING")
|
|
22
54
|
})
|
|
23
|
-
|
|
24
|
-
|
|
55
|
+
// Global options
|
|
56
|
+
.version(false)
|
|
57
|
+
.option("version", {
|
|
58
|
+
alias: "v",
|
|
25
59
|
type: "boolean",
|
|
26
|
-
|
|
27
|
-
description: "Adds coverage instrumentation (always disabled in production)"
|
|
60
|
+
description: "Displays the @rpcbase/cli version"
|
|
28
61
|
})
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// type: "boolean",
|
|
32
|
-
// default: false,
|
|
33
|
-
// // description: "Displays CLI version"
|
|
34
|
-
// })
|
|
62
|
+
.help("h")
|
|
63
|
+
.alias("h", "help")
|
|
35
64
|
.parse()
|
|
36
|
-
|
|
37
|
-
if (!is_command) {
|
|
38
|
-
default_command(args)
|
|
39
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"license": "SSPL-1.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"rb": "./bin.js"
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"bluebird": "3.7.2",
|
|
13
|
-
"
|
|
14
|
-
"concurrently": "7.2.1",
|
|
13
|
+
"concurrently": "7.2.2",
|
|
15
14
|
"debug": "4.3.4",
|
|
16
15
|
"dotenv": "16.0.1",
|
|
16
|
+
"picocolors": "1.0.0",
|
|
17
17
|
"semver": "7.3.7",
|
|
18
18
|
"validator": "13.7.0",
|
|
19
19
|
"yargs": "17.5.1"
|
package/src/errors.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
const
|
|
2
|
+
const colors = require("picocolors")
|
|
3
3
|
|
|
4
4
|
const ERRORS = {
|
|
5
|
-
INVALID_CWD: `expected to run in ${
|
|
5
|
+
INVALID_CWD: `expected to run in ${colors.cyan("client/")} or ${colors.cyan("server/server/")} or project root directory`
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
module.exports = ERRORS
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
const {execSync} = require("child_process")
|
|
3
3
|
const os = require("os")
|
|
4
|
-
const
|
|
4
|
+
const colors = require("picocolors")
|
|
5
5
|
|
|
6
6
|
const {FORCE_DOCKER} = process.env
|
|
7
7
|
|
|
@@ -15,7 +15,7 @@ const docker_runtime_check = () => {
|
|
|
15
15
|
try {
|
|
16
16
|
execSync("docker version -f json")
|
|
17
17
|
} catch (err) {
|
|
18
|
-
console.log(
|
|
18
|
+
console.log(colors.cyan("docker"), "exited with error")
|
|
19
19
|
process.exit(1)
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
const
|
|
2
|
+
const colors = require("picocolors")
|
|
3
3
|
|
|
4
4
|
const exit_with_message = (message = "", code = 1) => {
|
|
5
|
-
console.log(
|
|
5
|
+
console.log(colors.red("error:"), message)
|
|
6
6
|
|
|
7
7
|
// TODO: sentry(?) report error
|
|
8
8
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
const {execSync} = require("child_process")
|
|
3
|
+
|
|
4
|
+
const colors = require("picocolors")
|
|
5
|
+
|
|
6
|
+
const package = require("../package.json")
|
|
7
|
+
|
|
8
|
+
const print_versions = () => {
|
|
9
|
+
console.log(`${colors.cyan("rb")} v${package.version}`)
|
|
10
|
+
|
|
11
|
+
const node_out = execSync("node -v")
|
|
12
|
+
console.log(`${colors.green("node")} ${node_out.toString().trim()}`)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = print_versions
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const debug = require("debug")("rb-cli")
|
|
3
3
|
const path = require("path")
|
|
4
4
|
const fs = require("fs")
|
|
5
|
-
const
|
|
5
|
+
const colors = require("picocolors")
|
|
6
6
|
const concurrently = require("concurrently")
|
|
7
7
|
|
|
8
8
|
const docker_runtime_check = require("./helpers/docker_runtime_check")
|
|
@@ -13,7 +13,7 @@ const verify_project = require("./verify_project")
|
|
|
13
13
|
// TODO: nuke this
|
|
14
14
|
// server native + docker + docker-native is way too complex
|
|
15
15
|
// either everything is native, or everything is in docker
|
|
16
|
-
const
|
|
16
|
+
const start_command = async(args) => {
|
|
17
17
|
const run_configs = get_run_configs()
|
|
18
18
|
|
|
19
19
|
const run_commands = []
|
|
@@ -39,11 +39,20 @@ const default_command = async(args) => {
|
|
|
39
39
|
prefixColor = "#4DB33D"
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
// pass through
|
|
43
|
-
if (["client", "server"].includes(cfg.type)
|
|
44
|
-
|
|
42
|
+
// pass through listed args to client and server
|
|
43
|
+
if (["client", "server"].includes(cfg.type)) {
|
|
44
|
+
if (args.coverage) {
|
|
45
|
+
command = `${command} --coverage`
|
|
46
|
+
}
|
|
47
|
+
if (args.debug) {
|
|
48
|
+
command = `${command} --debug`
|
|
49
|
+
}
|
|
50
|
+
if (args.verbose) {
|
|
51
|
+
command = `${command} --verbose`
|
|
52
|
+
}
|
|
45
53
|
}
|
|
46
54
|
|
|
55
|
+
|
|
47
56
|
// add command
|
|
48
57
|
run_commands.push({
|
|
49
58
|
name,
|
|
@@ -72,7 +81,7 @@ const default_command = async(args) => {
|
|
|
72
81
|
})
|
|
73
82
|
.catch((err) => {
|
|
74
83
|
if (project_errors?.length > 0) {
|
|
75
|
-
console.log(`\n${
|
|
84
|
+
console.log(`\n${colors.bold("exited due to configuration errors:")}`)
|
|
76
85
|
project_errors.forEach((err) => {
|
|
77
86
|
console.log(err)
|
|
78
87
|
})
|
|
@@ -94,4 +103,4 @@ const default_command = async(args) => {
|
|
|
94
103
|
}
|
|
95
104
|
}
|
|
96
105
|
|
|
97
|
-
module.exports =
|
|
106
|
+
module.exports = start_command
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
const path = require("path")
|
|
3
3
|
const _ = require("lodash")
|
|
4
|
-
const
|
|
4
|
+
const colors = require("picocolors")
|
|
5
5
|
const Promise = require("bluebird")
|
|
6
6
|
|
|
7
7
|
const verify_packages_installed = require("./verify_packages_installed")
|
|
@@ -34,18 +34,18 @@ const verify_project = async(run_configs) => {
|
|
|
34
34
|
)
|
|
35
35
|
|
|
36
36
|
if (deps_errors.length > 0) {
|
|
37
|
-
let error_str = `${
|
|
37
|
+
let error_str = `${colors.red("error:")} the following packages are missing from your ${colors.bold("node_modules")}\n`
|
|
38
38
|
deps_errors.forEach((err) => {
|
|
39
39
|
error_str += ` ${err}\n`
|
|
40
40
|
})
|
|
41
|
-
error_str += `\n run ${
|
|
41
|
+
error_str += `\n run ${colors.bold("yarn install")} to ensure dependencies are installed\n`
|
|
42
42
|
result_errors.push(error_str)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// get env file from server and validate required services and ports
|
|
46
46
|
const env_errors = await verify_env(project_root_dir)
|
|
47
47
|
if (env_errors.length > 0) {
|
|
48
|
-
let error_str = `${
|
|
48
|
+
let error_str = `${colors.red("error:")} ${colors.bold(".env")} misconfigurations\n`
|
|
49
49
|
env_errors.forEach((err) => {
|
|
50
50
|
error_str += ` ${err}\n`
|
|
51
51
|
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schemas.rpcbase.com/schemas/thresholds.schema.json",
|
|
4
|
+
"title": "thresholds",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"statements": {
|
|
8
|
+
"type": "number",
|
|
9
|
+
"minimum": 0,
|
|
10
|
+
"maximum": 100,
|
|
11
|
+
},
|
|
12
|
+
"branches": {
|
|
13
|
+
"type": "number",
|
|
14
|
+
"minimum": 0,
|
|
15
|
+
"maximum": 100,
|
|
16
|
+
},
|
|
17
|
+
"functions": {
|
|
18
|
+
"type": "number",
|
|
19
|
+
"minimum": 0,
|
|
20
|
+
"maximum": 100,
|
|
21
|
+
},
|
|
22
|
+
"lines": {
|
|
23
|
+
"type": "number",
|
|
24
|
+
"minimum": 0,
|
|
25
|
+
"maximum": 100,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
const fs = require("fs")
|
|
3
3
|
const path = require("path")
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
const colors = require("picocolors")
|
|
5
6
|
const dotenv = require("dotenv")
|
|
6
7
|
const validator = require("validator")
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
const validate_port = (val) => {
|
|
10
11
|
if (!validator.isPort(val)) {
|
|
11
|
-
return `expected ${
|
|
12
|
+
return `expected ${colors.bold(val)} to be a valid port number`
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -31,7 +32,7 @@ const SERVICES = [
|
|
|
31
32
|
"DATABASE_PORT": validate_port,
|
|
32
33
|
"DATABASE_NAME": (val) => {
|
|
33
34
|
if (!/^[$A-Z_][0-9A-Z_$-]*$/i.test(val)) {
|
|
34
|
-
return `expected ${
|
|
35
|
+
return `expected ${colors.bold(`'${val}'`)} to be a valid database name`
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
},
|
|
@@ -65,13 +66,13 @@ const verify_env = async(root_dir) => {
|
|
|
65
66
|
const env_val = parsed_env[k]
|
|
66
67
|
|
|
67
68
|
if (!env_val) {
|
|
68
|
-
result_errors.push(`${
|
|
69
|
+
result_errors.push(`${colors.yellow(k)} is missing`)
|
|
69
70
|
return
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
const err = val_fn(env_val)
|
|
73
74
|
if (err) {
|
|
74
|
-
result_errors.push(`${
|
|
75
|
+
result_errors.push(`${colors.yellow(k)} ${err}`)
|
|
75
76
|
}
|
|
76
77
|
})
|
|
77
78
|
})
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const path = require("path")
|
|
3
3
|
const fs = require("fs")
|
|
4
4
|
const util = require("util")
|
|
5
|
-
const
|
|
5
|
+
const colors = require("picocolors")
|
|
6
6
|
const semverSatisfies = require("semver/functions/satisfies")
|
|
7
7
|
|
|
8
8
|
const exec = util.promisify(require("child_process").exec)
|
|
@@ -37,7 +37,7 @@ const verify_packages_installed = (root_dir) => async(wd) => {
|
|
|
37
37
|
|
|
38
38
|
Object.keys(deps).forEach((k) => {
|
|
39
39
|
if (!installed[k]) {
|
|
40
|
-
result_errors.push(`${
|
|
40
|
+
result_errors.push(`${colors.yellow(k)} is missing in ${colors.bold(rel_dir + "/")}`)
|
|
41
41
|
}
|
|
42
42
|
})
|
|
43
43
|
|