doc-detective 2.11.0-dev.1 → 2.11.0-dev.4

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,62 @@
1
+ {
2
+ "envVariables": "./samples/variables.env",
3
+ "input": ".",
4
+ "output": ".",
5
+ "recursive": true,
6
+ "logLevel": "info",
7
+ "runTests": {
8
+ "detectSteps": true,
9
+ "input": "./samples/doc-content.md",
10
+ "output": "./samples",
11
+ "recursive": true,
12
+ "mediaDirectory": "./samples",
13
+ "downloadDirectory": "./samples"
14
+ },
15
+ "fileTypes": [
16
+ {
17
+ "name": "Markdown",
18
+ "extensions": [".md"],
19
+ "testStartStatementOpen": "[comment]: # (test start",
20
+ "testStartStatementClose": ")",
21
+ "testIgnoreStatement": "[comment]: # (test ignore)",
22
+ "testEndStatement": "[comment]: # (test end)",
23
+ "stepStatementOpen": "[comment]: # (step",
24
+ "stepStatementClose": ")",
25
+ "markup": [
26
+ {
27
+ "name": "Hyperlink",
28
+ "regex": ["(?<=(?<!!)\\[[\\w\\s]+\\]\\().*?(?=\\))"],
29
+ "actions": ["checkLink"]
30
+ },
31
+ {
32
+ "name": "Navigation link",
33
+ "regex": ["(?<=([Oo]pen|[Cc]lick) (?<!!)\\[[\\w\\s]+\\]\\().*?(?=\\))"],
34
+ "actions": ["goTo"]
35
+ },
36
+ {
37
+ "name": "Onscreen text",
38
+ "regex": ["(?<=\\*\\*)[\\w\\s]+?(?=\\*\\*)"],
39
+ "actions": ["find"]
40
+ },
41
+ {
42
+ "name": "Image",
43
+ "regex": ["(?<=\\!\\[.*?\\]\\().*?(?=\\))"],
44
+ "actions": [
45
+ {
46
+ "name": "saveScreenshot",
47
+ "params": {
48
+ "directory": "samples",
49
+ "maxVariation": 5,
50
+ "overwrite": "byVariation"
51
+ }
52
+ }
53
+ ]
54
+ }
55
+ ]
56
+ }
57
+ ],
58
+ "telemetry": {
59
+ "send": true,
60
+ "userId": "Doc Detective Repo"
61
+ }
62
+ }
package/README.md CHANGED
@@ -4,12 +4,11 @@
4
4
  [![Discord Shield](https://img.shields.io/badge/chat-on%20discord-purple)](https://discord.gg/2M7wXEThfF)
5
5
  [![Docs Shield](https://img.shields.io/badge/docs-doc--detective.com-blue)](https://doc-detective.com)
6
6
 
7
-
8
- Doc Detective is an open-source documentation testing framework that makes it easy to keep your docs accurate and up-to-date. You write low-code (soon no-code) tests, and Doc Detective runs them directly against your product to make sure your docs match your user experience. Whether it’s a UI-based process or a series of API calls, Doc Detective can help you find doc bugs before your users do.
7
+ Doc Detective is doc content testing framework that makes it easy to keep your docs accurate and up-to-date. You write tests, and Doc Detective runs them directly against your product to make sure your docs match your user experience. Whether it’s a UI-based process or a series of API calls, Doc Detective can help you find doc bugs before your users do.
9
8
 
10
9
  Doc Detective ingests test specifications and text files, parses them for testable actions, then executes those actions in a browser. The results (PASS/FAIL and context) are output as a JSON object so that other pieces of infrastructure can parse and manipulate them as needed.
11
10
 
12
- This project handles test parsing and web-based UI testing--it doesn't support results reporting or notifications. This framework is a part of testing infrastructures and needs to be complemented by other components.
11
+ This project handles test parsing and web-based UI testing---it doesn't support results reporting or notifications. This framework is a part of testing infrastructures and needs to be complemented by other components.
13
12
 
14
13
  ## Components
15
14
 
@@ -21,84 +20,80 @@ Doc Detective has multiple components to integrate with your workflows as you ne
21
20
 
22
21
  ## Install
23
22
 
24
- > The following sections cover running Doc Detective as a CLI tool. To use Doc Detective via another interface (like as an NPM package), [see the docs](https://doc-detective.com).
25
-
26
- You can run Doc Detective as a CLI tool with Node:
27
-
28
- 0. Install prerequisites:
23
+ 1. Install prerequisites:
29
24
 
30
- - [Node.js](https://nodejs.org/) (tested on 18.16.0)
25
+ - [Node.js](https://nodejs.org/) (tested on v18 and v20)
31
26
 
32
- 1. In a terminal, clone the repo and install dependencies:
27
+ 1. In a terminal, install Doc Detective globally:
33
28
 
34
29
  ```bash
35
- git clone https://github.com/doc-detective/doc-detective.git
36
- cd doc-detective
37
- npm install
30
+ npm i -g doc-detective
38
31
  ```
39
32
 
40
- ## Run tests
33
+ If you don't install Doc Detective globally, you'll be prompted to install the first time you run an `npx` command.
34
+
35
+ ## (Optional) Get sample files
41
36
 
42
- To run your tests, use the `runTests` command and specify your test file with the `--input` argument. For example, to run tests in a file named `doc-content.md` in the `samples` directory (like in this repo!), run the following command:
37
+ To test a few samples, clone the repo and navigate to the `samples` directory:
43
38
 
44
39
  ```bash
45
- npm run runTests -- --input ./samples/doc-content.md
40
+ git clone https://github.com/doc-detective/doc-detective.git
41
+ cd doc-detective/samples
46
42
  ```
47
43
 
48
- To customize your test, file type, and directory options, create a [`config.json`](https://doc-detective.com/reference/schemas/config.html) file and reference it with the `--config` argument.
44
+ ## Run tests
45
+
46
+ To run your tests, use the `runTests` command:
49
47
 
50
48
  ```bash
51
- npm run runTests -- --config ./samples/config.json
49
+ npx doc-detective runTests
52
50
  ```
53
51
 
54
- You can override `config.json` options with command-line arguments. For example, to run tests in a file named `tests.spec.json` in the `samples` directory, run the following command:
52
+ By default, Doc Detective scans the current directory for valid tests, but you can specify your test file with the `--input` argument. For example, to run tests in a file named `doc-content-inline-tests.md`, run the following command:
55
53
 
56
54
  ```bash
57
- npm run runTests -- --config ./samples/config.json --input ./samples/tests.spec.json
55
+ npx doc-detective runTests --input doc-content-inline-tests.md
58
56
  ```
59
57
 
60
- To see all available options, use the `--help` argument:
58
+ To customize your test, file type, and directory options, create a `.doc-detective.json` [config](https://doc-detective.com/reference/schemas/config.html) file. If a `.doc-detective.json` file exists in the directory when you run the comment, Doc Detective loads the config. Otherwise, you can specify a config path with the `--config` argument.
61
59
 
62
60
  ```bash
63
- npm run runTests -- --help
61
+ npx doc-detective runTests --config .doc-detective.json
64
62
  ```
65
63
 
66
- ## Check your test coverage
67
-
68
- You can check the test coverage of your documentation source files with the `runCoverage` command, specifying the source file or directory of source files with the `--input` argument. Doc Detective identifies potential areas of test coverage with file-format-specific regex, and supports CommonMark syntax natively. If you want to test coverage of a file with different syntax, update your the `fileTypes` object of your [`config.json`](https://doc-detective.com/reference/schemas/config.html) file accordingly.
64
+ **Note**: All paths are relative to the current working directory, regardless where the config file is located.
69
65
 
66
+ You can override config options with command-line arguments. For example, to run tests in a file named `tests.spec.json`, even if that isn't included in your config, run the following command:
70
67
 
71
68
  ```bash
72
- npm run runCoverage -- --config ./samples/config.json --input ./samples/doc-content.md
69
+ npx doc-detective runTests --config .doc-detective.json --input tests.spec.json
73
70
  ```
74
71
 
75
- To see all available options, use the `--help` argument:
72
+ ## Check your test coverage
73
+
74
+ You can check the test coverage of your documentation source files with the `runCoverage` command, specifying the source file or directory of source files with the `--input` argument. Doc Detective identifies potential areas of test coverage with file-format-specific regex, and supports CommonMark syntax natively. If you want to test coverage of a file with different syntax, update your the `fileTypes` object of your [config](https://doc-detective.com/reference/schemas/config.html) file accordingly.
76
75
 
77
76
  ```bash
78
- npm run runCoverage -- --help
77
+ npx doc-detective runCoverage --config .doc-detective.json --input doc-content.md
79
78
  ```
80
79
 
81
- ## Suggest tests for coverage gaps (Experimental)
82
-
83
- The `suggestTests` command provides experimental support for suggesting tests for coverage gaps identifying during test coverage analysis. However, the `suggestTests` command is highly experimental, so usage of the command is left as an exercise for the user.
84
-
85
80
  ## Concepts
86
81
 
87
- - [**Test specification**](https://doc-detective.com/reference/schemas/specification.html): A group of tests to run in one or more contexts. Conceptually parallel to a document.
88
- - [**Test**](https://doc-detective.com/reference/schemas/test.html): A sequence of steps to perform. Conceptually parallel to a procedure.
89
- - **Step**: A portion of a test that includes a single action. Conceptually parallel to a step in a procedure.
90
- - **Action**: The task a performed in a step. Doc Detective supports a variety of actions:
91
- - [**checkLink**](https://doc-detective.com/reference/schemas/checkLink.html): Check if a URL returns an acceptable status code from a GET request.
92
- - [**find**](https://doc-detective.com/reference/schemas/find.html): Check if an element exists with the specified selector.
93
- - [**goTo**](https://doc-detective.com/reference/schemas/goTo.html): Navigate to a specified URL.
94
- - [**httpRequest**](https://doc-detective.com/reference/schemas/httpRequest.html): Perform a generic HTTP request, for example to an API.
95
- - [**runShell**](https://doc-detective.com/reference/schemas/runShell.html): Perform a native shell command.
96
- - [**saveScreenshot**](https://doc-detective.com/reference/schemas/saveScreenshot.html): Take a screenshot in PNG format.
97
- - [**setVariables**](https://doc-detective.com/reference/schemas/setVariables.html): Load environment variables from a `.env` file.
98
- - [**startRecording**](https://doc-detective.com/reference/schemas/startRecording.html) and [**stopRecording**](https://doc-detective.com/reference/schemas/stopRecording.html): Capture a video of test execution.
99
- - [**typeKeys**](https://doc-detective.com/reference/schemas/typeKeys.html): Type keys. To type special keys, begin and end the string with `$` and use the special key’s enum. For example, to type the Escape key, enter `$ESCAPE$`.
100
- - [**wait**](https://doc-detective.com/reference/schemas/wait.html): Pause before performing the next action.
101
- - [**Context**](https://doc-detective.com/reference/schemas/context.html): An application and platforms that support the tests.
82
+ - [**Test specification**](https://doc-detective.com/reference/schemas/specification.html): A group of tests to run in one or more contexts. Conceptually parallel to a document.
83
+ - [**Test**](https://doc-detective.com/reference/schemas/test.html): A sequence of steps to perform. Conceptually parallel to a procedure.
84
+ - **Step**: A portion of a test that includes a single action. Conceptually parallel to a step in a procedure.
85
+ - **Action**: The task a performed in a step. Doc Detective supports a variety of actions:
86
+ - [**checkLink**](https://doc-detective.com/reference/schemas/checkLink.html): Check if a URL returns an acceptable status code from a GET request.
87
+ - [**find**](https://doc-detective.com/reference/schemas/find.html): Check if an element exists with the specified selector.
88
+ - [**goTo**](https://doc-detective.com/reference/schemas/goTo.html): Navigate to a specified URL.
89
+ - [**httpRequest**](https://doc-detective.com/reference/schemas/httpRequest.html): Perform a generic HTTP request, for example to an API.
90
+ - [**runShell**](https://doc-detective.com/reference/schemas/runShell.html): Perform a native shell command.
91
+ - [**saveScreenshot**](https://doc-detective.com/reference/schemas/saveScreenshot.html): Take a screenshot in PNG format.
92
+ - [**setVariables**](https://doc-detective.com/reference/schemas/setVariables.html): Load environment variables from a `.env` file.
93
+ - [**startRecording**](https://doc-detective.com/reference/schemas/startRecording.html) and [**stopRecording**](https://doc-detective.com/reference/schemas/stopRecording.html): Capture a video of test execution.
94
+ - [**typeKeys**](https://doc-detective.com/reference/schemas/typeKeys.html): Type keys. To type special keys, begin and end the string with `$` and use the special key’s enum. For example, to type the Escape key, enter `$ESCAPE$`.
95
+ - [**wait**](https://doc-detective.com/reference/schemas/wait.html): Pause before performing the next action.
96
+ - [**Context**](https://doc-detective.com/reference/schemas/context.html): An application and platforms that support the tests.
102
97
 
103
98
  ## Roadmap
104
99
 
@@ -108,9 +103,23 @@ Future updates may include support for the following items:
108
103
  - Platforms: iOS, Android
109
104
  - Commands: `suggestTests` stable release
110
105
 
106
+ ## Develop
107
+
108
+ To develop Doc Detective, clone the repo and install dependencies:
109
+
110
+ ```bash
111
+ git clone https://github.com/doc-detective/doc-detective.git
112
+ cd doc-detective
113
+ npm i
114
+ ```
115
+
116
+ To run commands, use the same `npx` commands as above.
117
+
118
+ Make sure you review the [contributions guide](CONTRIBUTIONS.md) before submitting a pull request.
119
+
111
120
  ## Contributions
112
121
 
113
- Looking to help out? See our [contributions guide](https://github.com/doc-detective/doc-detective/blob/main/CONTRIBUTIONS.md) for more info. If you can't contribute code, you can still help by reporting issues, suggesting new features, improving the documentation, or sponsoring the project.
122
+ Looking to help out? See our [contributions guide](CONTRIBUTIONS.md) for more info. If you can't contribute code, you can still help by reporting issues, suggesting new features, improving the documentation, or sponsoring the project.
114
123
 
115
124
  ## License
116
125
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doc-detective",
3
- "version": "2.11.0-dev.1",
3
+ "version": "2.11.0-dev.4",
4
4
  "description": "Treat doc content as testable assertions to validate doc accuracy and product UX.",
5
5
  "bin": {
6
6
  "doc-detective": "src/index.js"
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "homepage": "https://github.com/doc-detective/doc-detective#readme",
33
33
  "dependencies": {
34
- "doc-detective-common": "^1.14.0",
35
- "doc-detective-core": "^2.11.0-dev.1",
34
+ "doc-detective-common": "^1.15.0-dev.1",
35
+ "doc-detective-core": "^2.11.0-dev.4",
36
36
  "prompt-sync": "^4.2.0",
37
37
  "yargs": "^17.7.2"
38
38
  },
@@ -1,11 +1,12 @@
1
1
  {
2
- "envVariables": "./samples/variables.env",
2
+ "envVariables": "./variables.env",
3
3
  "input": ".",
4
4
  "output": ".",
5
5
  "recursive": true,
6
- "logLevel": "debug",
6
+ "logLevel": "info",
7
7
  "runTests": {
8
- "input": "./samples/doc-content.md",
8
+ "detectSteps": true,
9
+ "input": "./doc-content.md",
9
10
  "output": ".",
10
11
  "setup": "",
11
12
  "cleanup": "",
@@ -15,7 +16,7 @@
15
16
  "contexts": [
16
17
  {
17
18
  "app": {
18
- "name": "firefox",
19
+ "name": "chrome",
19
20
  "options": {
20
21
  "width": 1200,
21
22
  "height": 800,
@@ -71,7 +72,7 @@
71
72
  {
72
73
  "name": "saveScreenshot",
73
74
  "params": {
74
- "directory": "samples",
75
+ "directory": ".",
75
76
  "maxVariation": 5,
76
77
  "overwrite": "byVariation"
77
78
  }
@@ -83,7 +84,7 @@
83
84
  ],
84
85
  "integrations": {},
85
86
  "telemetry": {
86
- "send": false,
87
- "userId": "Doc Detective"
87
+ "send": true,
88
+ "userId": "Doc Detective Samples"
88
89
  }
89
90
  }
@@ -6,23 +6,24 @@
6
6
 
7
7
  [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com"})
8
8
 
9
- - The landing page discusses what Doc Detective is, what it does, and who might find it useful.
10
- - [Get started](https://doc-detective.com/get-started.html) covers how to quickly get up and running with Doc Detective.
9
+ The landing page discusses what Doc Detective is, what it does, and who might find it useful.
11
10
 
12
- [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/get-started.html"})
11
+ - [Get started](https://doc-detective.com/get-started.html) covers how to quickly get up and running with Doc Detective.
13
12
 
14
- - The [references](https://doc-detective.com/reference/) detail the various JSON objects that Doc Detective expects for [configs](https://doc-detective.com/reference/schemas/config.html), [test specifications](https://doc-detective.com/reference/schemas/specification.html), [tests](https://doc-detective.com/reference/schemas/test), actions, and more. Open [typeKeys](https://doc-detective.com/reference/schemas/typeKeys.html)--or any other schema--and you'll find three sections: **Description**, **Fields**, and **Examples**.
13
+ [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/get-started.html"})
15
14
 
16
- [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/"})
17
- [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/schemas/config.html"})
18
- [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/schemas/specification.html"})
19
- [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/schemas/test.html"})
20
- [comment]: # (step {"action":"goTo", "url":"https://doc-detective.com/reference/schemas/typeKeys.html"})
21
- [comment]: # (step {"action":"find", "selector":"h2#description", "matchText":"Description"})
22
- [comment]: # (step {"action":"find", "selector":"h2#fields", "matchText":"Fields"})
23
- [comment]: # (step {"action":"find", "selector":"h2#examples", "matchText":"Examples"})
15
+ - The [references](https://doc-detective.com/reference/) detail the various JSON objects that Doc Detective expects for [configs](https://doc-detective.com/reference/schemas/config.html), [test specifications](https://doc-detective.com/reference/schemas/specification.html), [tests](https://doc-detective.com/reference/schemas/test), actions, and more. Open [typeKeys](https://doc-detective.com/reference/schemas/typeKeys.html)--or any other schema--and you'll find three sections: **Description**, **Fields**, and **Examples**.
24
16
 
25
- ![](reference.png)
26
- [comment]: # (step {"action":"saveScreenshot", "path":"reference.png", "directory":"samples", "maxVariation":5, "overwrite":"byVariation"})
17
+ [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/"})
18
+ [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/schemas/config.html"})
19
+ [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/schemas/specification.html"})
20
+ [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/schemas/test.html"})
21
+ [comment]: # (step {"action":"goTo", "url":"https://doc-detective.com/reference/schemas/typeKeys.html"})
22
+ [comment]: # (step {"action":"find", "selector":"h2#description", "matchText":"Description"})
23
+ [comment]: # (step {"action":"find", "selector":"h2#fields", "matchText":"Fields"})
24
+ [comment]: # (step {"action":"find", "selector":"h2#examples", "matchText":"Examples"})
25
+
26
+ ![Search results.](reference.png)
27
27
 
28
+ [comment]: # (step {"action":"saveScreenshot", "path":"reference.png", "directory":"samples", "maxVariation":5, "overwrite":"byVariation"})
28
29
  [comment]: # (test end)
@@ -2,8 +2,8 @@
2
2
 
3
3
  [Doc Detective documentation](https://doc-detective.com) is split into a few key sections:
4
4
 
5
- - The landing page discusses what Doc Detective is, what it does, and who might find it useful.
6
- - [Get started](https://doc-detective.com/get-started.html) covers how to quickly get up and running with Doc Detective.
7
- - The [references](https://doc-detective.com/reference/) detail the various JSON objects that Doc Detective expects for [configs](https://doc-detective.com/reference/schemas/config.html), [test specifications](https://doc-detective.com/reference/schemas/specification.html), [tests](https://doc-detective.com/reference/schemas/test), actions, and more. Open [typeKeys](https://doc-detective.com/reference/schemas/typeKeys.html)--or any other schema--and you'll find three sections: **Description**, **Fields**, and **Examples**.
5
+ - The landing page discusses what Doc Detective is, what it does, and who might find it useful.
6
+ - [Get started](https://doc-detective.com/get-started.html) covers how to quickly get up and running with Doc Detective.
7
+ - The [references](https://doc-detective.com/reference/) detail the various JSON objects that Doc Detective expects for [configs](https://doc-detective.com/reference/schemas/config.html), [test specifications](https://doc-detective.com/reference/schemas/specification.html), [tests](https://doc-detective.com/reference/schemas/test), actions, and more. Open [typeKeys](https://doc-detective.com/reference/schemas/typeKeys.html)--or any other schema--and you'll find three sections: **Description**, **Fields**, and **Examples**.
8
8
 
9
- ![](reference.png)
9
+ ![Search results.](reference.png)
package/src/index.js CHANGED
@@ -1,21 +1,60 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const { runTests, runCoverage } = require("doc-detective-core");
4
- const { setArgs, setConfig, outputResults } = require("./utils");
4
+ const { setArgs, setConfig, outputResults, setMeta } = require("./utils");
5
5
  const { argv } = require("node:process");
6
6
  const path = require("path");
7
+ const fs = require("fs");
8
+ const prompt = require("prompt-sync")();
7
9
 
10
+ function complete(commands) {
11
+ return function (str) {
12
+ var i;
13
+ var ret = [];
14
+ for (i=0; i< commands.length; i++) {
15
+ if (commands[i].indexOf(str) == 0)
16
+ ret.push(commands[i]);
17
+ }
18
+ return ret;
19
+ };
20
+ };
21
+
22
+ // Run
23
+ setMeta();
8
24
  main(argv);
9
25
 
10
- // Run tests
26
+ // Run
11
27
  async function main(argv) {
12
28
  // Find index of `doc-detective` or `run` in argv
13
- const index = argv.findIndex((arg) => arg.endsWith("doc-detective") || arg.endsWith("index.js"));
29
+ const index = argv.findIndex(
30
+ (arg) => arg.endsWith("doc-detective") || arg.endsWith("index.js")
31
+ );
14
32
  // `command` is the next argument after `doc-detective` or `src/index.js`
15
- const command = argv[index + 1];
16
- // Set args and config
33
+ let command = argv[index + 1];
34
+ // If no command, prompt user to select a command
35
+ if (command !== "runTests" && command !== "runCoverage") {
36
+ const ask = `
37
+ Welcome to Doc Detective. Choose a command:
38
+ - 'runTests' - Run tests defined in specifications and documentation source files.
39
+ - 'runCoverage' - Calculate test coverage of doc content.
40
+
41
+ You can skip this next time by running 'npx doc-detective <command>'. You can also set 'defaultCommand' in your .doc-detective.json config file.
42
+
43
+ For more info, visit https://doc-detective.com.
44
+
45
+ Command: `;
46
+ command = prompt({ask, value: "runTests", autocomplete: complete(["runTests", "runCoverage"])});
47
+ }
48
+ // Set args
17
49
  argv = setArgs(argv);
18
- const config = setConfig({}, argv);
50
+ // Get .doc-detective.json config, if it exists
51
+ const configPath = path.resolve(process.cwd(), ".doc-detective.json");
52
+ let config = {};
53
+ if (fs.existsSync(configPath)) {
54
+ config = require(configPath);
55
+ }
56
+ // Set config
57
+ config = setConfig(config, argv);
19
58
  // Run command
20
59
  let results = {};
21
60
  let outputDir;
@@ -29,7 +68,8 @@ async function main(argv) {
29
68
  outputReportType = "testResults";
30
69
  results = await runTests(config);
31
70
  } else {
32
- throw new Error(`Command ${command} not found`);
71
+ console.error(`Sorry, that's not a recognized command. Please try again.`);
72
+ process.exit(1);
33
73
  }
34
74
  // Output results
35
75
  const outputPath = path.resolve(
package/src/utils.js CHANGED
@@ -4,11 +4,13 @@ const { validate } = require("doc-detective-common");
4
4
  const path = require("path");
5
5
  const fs = require("fs");
6
6
  const { spawn } = require("child_process");
7
+ const os = require("os");
7
8
 
8
9
  exports.setArgs = setArgs;
9
10
  exports.setConfig = setConfig;
10
11
  exports.outputResults = outputResults;
11
12
  exports.spawnCommand = spawnCommand;
13
+ exports.setMeta = setMeta;
12
14
 
13
15
  // Define args
14
16
  function setArgs(args) {
@@ -87,7 +89,11 @@ function setConfig(config, args) {
87
89
  if (args.output) config.output = args.output;
88
90
  if (args.recursive) config.recursive = args.recursive;
89
91
  if (args.logLevel) config.logLevel = args.logLevel;
90
- if ((args.setup || args.cleanup || args.input || args.output ) && !config.runTests) config.runTests = {};
92
+ if (
93
+ (args.setup || args.cleanup || args.input || args.output) &&
94
+ !config.runTests
95
+ )
96
+ config.runTests = {};
91
97
  if (args.input) config.runTests.input = args.input;
92
98
  if (args.output) config.runTests.output = args.output;
93
99
  if (args.setup) config.runTests.setup = args.setup;
@@ -154,4 +160,29 @@ async function spawnCommand(cmd, args) {
154
160
  });
155
161
 
156
162
  return { stdout, stderr, exitCode };
157
- }
163
+ }
164
+
165
+ function setMeta() {
166
+ const platformMap = {
167
+ win32: "windows",
168
+ darwin: "mac",
169
+ linux: "linux",
170
+ };
171
+
172
+ // Set meta
173
+ const meta =
174
+ process.env["DOC_DETECTIVE_META"] !== undefined
175
+ ? JSON.parse(process.env["DOC_DETECTIVE_META"])
176
+ : {};
177
+ const package = require("../package.json");
178
+ meta.distribution = "doc-detective";
179
+ meta.dist_version = package.version;
180
+ meta.dist_platform = platformMap[os.platform()];
181
+ meta.dist_platform_version = os.release();
182
+ meta.dist_platform_arch = os.arch();
183
+ meta.dist_deployment = meta.dist_deployment || "node";
184
+ meta.dist_deployment_version =
185
+ meta.dist_deployment_version || process.version;
186
+ meta.dist_interface = meta.dist_interface || "cli";
187
+ process.env["DOC_DETECTIVE_META"] = JSON.stringify(meta);
188
+ }