doc-detective 2.11.0-dev.3 → 2.11.0-dev.5

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.
@@ -58,5 +58,6 @@
58
58
  "telemetry": {
59
59
  "send": true,
60
60
  "userId": "Doc Detective Repo"
61
- }
61
+ },
62
+ "defaultCommand": "runTests"
62
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doc-detective",
3
- "version": "2.11.0-dev.3",
3
+ "version": "2.11.0-dev.5",
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.15.0-dev.0",
35
- "doc-detective-core": "^2.11.0-dev.3",
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
  },
Binary file
package/src/index.js CHANGED
@@ -5,6 +5,18 @@ const { setArgs, setConfig, outputResults, setMeta } = require("./utils");
5
5
  const { argv } = require("node:process");
6
6
  const path = require("path");
7
7
  const fs = require("fs");
8
+ const prompt = require("prompt-sync")();
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) ret.push(commands[i]);
16
+ }
17
+ return ret;
18
+ };
19
+ }
8
20
 
9
21
  // Run
10
22
  setMeta();
@@ -17,7 +29,7 @@ async function main(argv) {
17
29
  (arg) => arg.endsWith("doc-detective") || arg.endsWith("index.js")
18
30
  );
19
31
  // `command` is the next argument after `doc-detective` or `src/index.js`
20
- const command = argv[index + 1];
32
+ let command = argv[index + 1];
21
33
  // Set args
22
34
  argv = setArgs(argv);
23
35
  // Get .doc-detective.json config, if it exists
@@ -28,6 +40,26 @@ async function main(argv) {
28
40
  }
29
41
  // Set config
30
42
  config = setConfig(config, argv);
43
+ command = command || config.defaultCommand;
44
+ // If no command, prompt user to select a command
45
+ if (command !== "runTests" && command !== "runCoverage") {
46
+ const ask = `
47
+ Welcome to Doc Detective. Choose a command:
48
+ - 'runTests' - Run tests defined in specifications and documentation source files.
49
+ - 'runCoverage' - Calculate test coverage of doc content.
50
+
51
+ You can skip this next time by running 'npx doc-detective <command>'. You can also set 'defaultCommand' in your .doc-detective.json config file.
52
+
53
+ For more info, visit https://doc-detective.com.
54
+
55
+ Command: `;
56
+ command = prompt({
57
+ ask,
58
+ value: "runTests",
59
+ autocomplete: complete(["runTests", "runCoverage"]),
60
+ });
61
+ }
62
+
31
63
  // Run command
32
64
  let results = {};
33
65
  let outputDir;
@@ -41,7 +73,8 @@ async function main(argv) {
41
73
  outputReportType = "testResults";
42
74
  results = await runTests(config);
43
75
  } else {
44
- throw new Error(`Command ${command} not found`);
76
+ console.error(`Sorry, that's not a recognized command. Please try again.`);
77
+ process.exit(1);
45
78
  }
46
79
  // Output results
47
80
  const outputPath = path.resolve(