@rpcbase/cli 0.7.0 → 0.11.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.7.0",
3
+ "version": "0.11.0",
4
4
  "license": "SSPL-1.0",
5
5
  "bin": {
6
6
  "rb": "./bin.js"
@@ -10,12 +10,12 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "bluebird": "3.7.2",
13
- "chalk": "4.1.2",
14
- "concurrently": "7.0.0",
13
+ "concurrently": "7.2.1",
15
14
  "debug": "4.3.4",
16
- "dotenv": "16.0.0",
17
- "semver": "7.3.5",
15
+ "dotenv": "16.0.1",
16
+ "picocolors": "1.0.0",
17
+ "semver": "7.3.7",
18
18
  "validator": "13.7.0",
19
- "yargs": "17.4.0"
19
+ "yargs": "17.5.1"
20
20
  }
21
21
  }
@@ -2,19 +2,22 @@
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
+ const docker_runtime_check = require("./helpers/docker_runtime_check")
8
9
  const exit_with_message = require("./helpers/exit_with_message")
9
10
  const get_run_configs = require("./helpers/get_run_configs")
10
- const docker_runtime_check = require("./helpers/docker_runtime_check")
11
11
  const verify_project = require("./verify_project")
12
12
 
13
-
13
+ // TODO: nuke this
14
+ // server native + docker + docker-native is way too complex
15
+ // either everything is native, or everything is in docker
14
16
  const default_command = async(args) => {
15
17
  const run_configs = get_run_configs()
16
18
 
17
- const run_commands = run_configs.map((cfg) => {
19
+ const run_commands = []
20
+ run_configs.forEach((cfg) => {
18
21
  let name
19
22
  let command
20
23
  let prefixColor
@@ -41,15 +44,16 @@ const default_command = async(args) => {
41
44
  command = `${command} --coverage`
42
45
  }
43
46
 
44
- // command, name, prefixColor, env, cwd
45
- return {
47
+ // add command
48
+ run_commands.push({
46
49
  name,
47
50
  command,
48
51
  prefixColor,
49
52
  cwd: cfg.working_dir
50
- }
53
+ })
51
54
  })
52
55
 
56
+ // check if docker is running
53
57
  if (run_configs.filter((c) => c.type === "server").length > 0) {
54
58
  docker_runtime_check()
55
59
  }
@@ -68,7 +72,7 @@ const default_command = async(args) => {
68
72
  })
69
73
  .catch((err) => {
70
74
  if (project_errors?.length > 0) {
71
- console.log(`\n${chalk.bold("exited due to configuration errors:")}`)
75
+ console.log(`\n${colors.bold("exited due to configuration errors:")}`)
72
76
  project_errors.forEach((err) => {
73
77
  console.log(err)
74
78
  })
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
 
@@ -5,11 +5,11 @@ const fs = require("fs")
5
5
  const ERRORS = require("../errors")
6
6
  const exit_with_message = require("./exit_with_message")
7
7
 
8
-
9
8
  // run type is client | server | both
10
9
  const get_run_configs = () => {
11
10
  const cwd = process.cwd()
12
11
 
12
+
13
13
  // check if running parent of rb project
14
14
  const dir_contents = fs.readdirSync(cwd)
15
15
  const is_parent_dir = dir_contents.includes("client") && dir_contents.includes("server")
@@ -57,6 +57,8 @@ const get_run_configs = () => {
57
57
  working_dir: path.join(cwd, "../infrastructure")
58
58
  },
59
59
  ]
60
+ } else {
61
+ console.log("TODO: server get_run_configs:handle edge case here")
60
62
  }
61
63
  }
62
64
 
@@ -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