@rpcbase/cli 0.8.0 → 0.12.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 CHANGED
@@ -6,34 +6,57 @@ require("dotenv").config({path: path.join(__dirname, "./.env")})
6
6
  const yargs = require("yargs/yargs")
7
7
  const {hideBin} = require("yargs/helpers")
8
8
 
9
- const default_command = require("./src/default_command")
9
+ const start_command = require("./src/start_command")
10
+ const print_versions = require("./src/print_versions")
10
11
  const update = require("./src/update")
11
12
 
12
- let is_command = false
13
-
14
- const args = yargs(hideBin(process.argv))
15
- .command(["update", "up"], "Update rb dependencies to latest version", () => {}, async(argv) => {
16
- is_command = true
13
+ yargs(hideBin(process.argv))
14
+ .command(["start", "*"], "Starts client, server, and infrastructure", (yargs) => {
15
+ yargs
16
+ .option("coverage", {
17
+ alias: "c",
18
+ type: "boolean",
19
+ default: false,
20
+ description: "Adds coverage instrumentation (always disabled in production)"
21
+ })
22
+ .option("verbose", {
23
+ type: "boolean",
24
+ default: false,
25
+ description: "Run with verbose logging"
26
+ })
27
+ .option("debug", {
28
+ type: "boolean",
29
+ default: false,
30
+ description: "Run with debug logging"
31
+ })
32
+ }, (argv) => {
33
+ if (argv.version) return print_versions()
34
+ start_command(argv)
35
+ })
36
+ // Update
37
+ .command(["update", "up"], "Update rb dependencies to latest version", (yargs) => {
38
+ yargs
39
+ .option("dry-run", {
40
+ type: "boolean",
41
+ default: false,
42
+ description: "Print output without writing any files"
43
+ })
44
+ }, async(argv) => {
45
+ if (argv.version) return print_versions()
17
46
  await update()
18
47
  })
48
+ // Ping
19
49
  .command("ping", "Ping", () => {}, (argv) => {
20
- is_command = true
50
+ if (argv.version) return print_versions()
21
51
  console.log("PING")
22
52
  })
23
- .option("coverage", {
24
- alias: "c",
53
+ // Global options
54
+ .version(false)
55
+ .option("version", {
56
+ alias: "v",
25
57
  type: "boolean",
26
- default: false,
27
- description: "Adds coverage instrumentation (always disabled in production)"
58
+ description: "Displays the @rpcbase/cli version"
28
59
  })
29
- // .option("version", {
30
- // alias: "v",
31
- // type: "boolean",
32
- // default: false,
33
- // // description: "Displays CLI version"
34
- // })
60
+ .help("h")
61
+ .alias("h", "help")
35
62
  .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.8.0",
3
+ "version": "0.12.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
- "chalk": "4.1.2",
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 chalk = require("chalk")
2
+ const colors = require("picocolors")
3
3
 
4
4
  const ERRORS = {
5
- INVALID_CWD: `expected to run in ${chalk.cyan("client/")} or ${chalk.cyan("server/server/")} or project root directory`
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,12 +1,21 @@
1
1
  /* @flow */
2
2
  const {execSync} = require("child_process")
3
- const chalk = require("chalk")
3
+ const os = require("os")
4
+ const colors = require("picocolors")
5
+
6
+ const {FORCE_DOCKER} = process.env
4
7
 
5
8
  const docker_runtime_check = () => {
9
+ // skip check on osx except when forcing docker
10
+ if (os.platform() === "darwin" && !FORCE_DOCKER) {
11
+ return
12
+ }
13
+
14
+
6
15
  try {
7
16
  execSync("docker version -f json")
8
17
  } catch (err) {
9
- console.log(chalk.cyan.bold("docker"), "exited with error")
18
+ console.log(colors.cyan("docker"), "exited with error")
10
19
  process.exit(1)
11
20
  }
12
21
  }
@@ -1,8 +1,8 @@
1
1
  /* @flow */
2
- const chalk = require("chalk")
2
+ const colors = require("picocolors")
3
3
 
4
4
  const exit_with_message = (message = "", code = 1) => {
5
- console.log(chalk.red("error:"), message)
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 chalk = require("chalk")
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 default_command = async(args) => {
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 coverage arg to client and server
43
- if (["client", "server"].includes(cfg.type) && args.coverage) {
44
- command = `${command} --coverage`
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${chalk.bold("exited due to configuration errors:")}`)
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 = default_command
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 chalk = require("chalk")
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 = `${chalk.bold.red("error:")} the following packages are missing from your ${chalk.bold("node_modules")}\n`
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 ${chalk.bold("yarn install")} to ensure dependencies are installed\n`
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 = `${chalk.bold.red("error:")} ${chalk.bold(".env")} misconfigurations\n`
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
- const chalk = require("chalk")
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 ${chalk.bold(val)} to be a valid port number`
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 ${chalk.bold(`'${val}'`)} to be a valid database name`
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(`${chalk.yellow.bold(k)} is missing`)
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(`${chalk.yellow.bold(k)} ${err}`)
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 chalk = require("chalk")
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(`${chalk.yellow.bold(k)} is missing in ${chalk.bold(rel_dir + "/")}`)
40
+ result_errors.push(`${colors.yellow(k)} is missing in ${colors.bold(rel_dir + "/")}`)
41
41
  }
42
42
  })
43
43