virmator 2.0.5 → 3.0.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.
Files changed (183) hide show
  1. package/.github/workflows/virmator-build-for-gh-pages.yml +24 -0
  2. package/.github/workflows/virmator-tagged-release.yml +6 -4
  3. package/.github/workflows/virmator-tests.yml +4 -3
  4. package/.mocharc.js +9 -0
  5. package/.prettierignore +2 -3
  6. package/README.md +67 -82
  7. package/configs/.cspell.json +4 -0
  8. package/configs/.gitattributes +1 -0
  9. package/configs/.mocharc.js +8 -0
  10. package/configs/.prettierignore +6 -0
  11. package/configs/.prettierrc.js +13 -0
  12. package/{.cspell.json → configs/.virmator/.cspell-base.json} +5 -0
  13. package/configs/.virmator/mocharc-base.js +15 -0
  14. package/configs/.virmator/prettierrc-base.js +62 -0
  15. package/{tsconfig.json → configs/.virmator/tsconfig-base.json} +12 -8
  16. package/configs/.virmator/vite-always-reload-plugin.ts +90 -0
  17. package/configs/.virmator/vite-base.ts +11 -0
  18. package/configs/.virmator/vite.config.ts +8 -0
  19. package/configs/.virmator/web-test-runner-base.mjs +29 -0
  20. package/configs/.virmator/web-test-runner.config.mjs +8 -0
  21. package/{.vscode → configs/.vscode}/settings.json +13 -0
  22. package/configs/gitignore.txt +6 -0
  23. package/configs/npmignore.txt +13 -0
  24. package/configs/package.json +16 -0
  25. package/configs/src/global.d.ts +5 -0
  26. package/configs/tsconfig.json +3 -0
  27. package/dist/api/virmator-wrapper.d.ts +5 -0
  28. package/dist/api/virmator-wrapper.js +9 -0
  29. package/dist/augments/array.d.ts +1 -0
  30. package/dist/augments/array.js +7 -0
  31. package/dist/augments/fs.d.ts +5 -0
  32. package/dist/augments/fs.js +30 -0
  33. package/dist/augments/json.d.ts +1 -0
  34. package/dist/augments/json.js +12 -0
  35. package/dist/augments/object.d.ts +1 -0
  36. package/dist/augments/object.js +14 -0
  37. package/dist/augments/regexp.d.ts +1 -0
  38. package/dist/augments/regexp.js +7 -0
  39. package/dist/augments/test.d.ts +2 -0
  40. package/dist/augments/test.js +8 -0
  41. package/dist/augments/type.d.ts +1 -0
  42. package/dist/augments/type.js +2 -0
  43. package/dist/cli/all-cli-command-definitions.d.ts +54 -0
  44. package/dist/cli/all-cli-command-definitions.js +76 -0
  45. package/dist/cli/cli-color.d.ts +8 -0
  46. package/dist/cli/cli-color.js +12 -0
  47. package/dist/cli/cli-command/cli-command-help.d.ts +8 -0
  48. package/dist/cli/cli-command/cli-command-help.js +2 -0
  49. package/dist/cli/{commands/description-printing.d.ts → cli-command/cli-command-to-help-message.d.ts} +3 -2
  50. package/dist/cli/{commands/description-printing.js → cli-command/cli-command-to-help-message.js} +55 -21
  51. package/dist/cli/cli-command/define-cli-command.d.ts +41 -0
  52. package/dist/cli/cli-command/define-cli-command.js +29 -0
  53. package/dist/cli/cli-command/run-shell-command.d.ts +8 -0
  54. package/dist/cli/cli-command/run-shell-command.js +23 -0
  55. package/dist/cli/cli-command-implementations/code-in-markdown.command.d.ts +6 -0
  56. package/dist/cli/cli-command-implementations/code-in-markdown.command.js +67 -0
  57. package/dist/cli/cli-command-implementations/compile.command.d.ts +6 -0
  58. package/dist/cli/cli-command-implementations/compile.command.js +44 -0
  59. package/dist/cli/cli-command-implementations/format.command.d.ts +6 -0
  60. package/dist/cli/cli-command-implementations/format.command.js +116 -0
  61. package/dist/cli/cli-command-implementations/frontend.command.d.ts +7 -0
  62. package/dist/cli/cli-command-implementations/frontend.command.js +45 -0
  63. package/dist/cli/cli-command-implementations/init.command.d.ts +4 -0
  64. package/dist/cli/cli-command-implementations/init.command.js +31 -0
  65. package/dist/cli/cli-command-implementations/spellcheck.command.d.ts +4 -0
  66. package/dist/cli/cli-command-implementations/spellcheck.command.js +40 -0
  67. package/dist/cli/cli-command-implementations/test-web.command.d.ts +4 -0
  68. package/dist/cli/cli-command-implementations/test-web.command.js +50 -0
  69. package/dist/cli/cli-command-implementations/test.command.d.ts +4 -0
  70. package/dist/cli/cli-command-implementations/test.command.js +53 -0
  71. package/dist/cli/cli-command-implementations/update-configs.command.d.ts +4 -0
  72. package/dist/cli/cli-command-implementations/update-configs.command.js +31 -0
  73. package/dist/cli/cli-flags/cli-flag-name.d.ts +4 -0
  74. package/dist/cli/cli-flags/cli-flag-name.js +8 -0
  75. package/dist/cli/cli-flags/cli-flag-values.d.ts +4 -0
  76. package/dist/cli/cli-flags/cli-flag-values.js +19 -0
  77. package/dist/cli/cli-messages.d.ts +6 -0
  78. package/dist/cli/cli-messages.js +19 -0
  79. package/dist/cli/cli.js +27 -20
  80. package/dist/cli/config/combine-text-config.d.ts +2 -0
  81. package/dist/cli/config/combine-text-config.js +27 -0
  82. package/dist/cli/config/config-files.d.ts +133 -0
  83. package/dist/cli/config/config-files.js +138 -0
  84. package/dist/cli/config/copy-config.d.ts +25 -13
  85. package/dist/cli/config/copy-config.js +86 -86
  86. package/dist/cli/config/create-default-package-json.d.ts +1 -16
  87. package/dist/cli/config/create-default-package-json.js +37 -12
  88. package/dist/cli/is-global.d.ts +1 -0
  89. package/dist/cli/is-global.js +10 -0
  90. package/dist/cli/parse-arguments.d.ts +8 -0
  91. package/dist/cli/parse-arguments.js +42 -0
  92. package/dist/cli/run-cli-command.d.ts +13 -0
  93. package/dist/cli/run-cli-command.js +52 -0
  94. package/dist/cli/run-command.test-helper.d.ts +28 -0
  95. package/dist/cli/run-command.test-helper.js +87 -0
  96. package/dist/errors/virmator-cli.error.d.ts +3 -0
  97. package/dist/errors/virmator-cli.error.js +10 -0
  98. package/dist/errors/virmator-config-file.error.d.ts +4 -0
  99. package/dist/errors/virmator-config-file.error.js +11 -0
  100. package/dist/errors/virmator-invalid-command.error.d.ts +5 -0
  101. package/dist/errors/virmator-invalid-command.error.js +11 -0
  102. package/dist/errors/virmator-invalid-flags.error.d.ts +5 -0
  103. package/dist/errors/virmator-invalid-flags.error.js +13 -0
  104. package/dist/file-paths/virmator-package-paths.d.ts +11 -0
  105. package/dist/file-paths/virmator-package-paths.js +31 -0
  106. package/dist/file-paths/virmator-test-file-paths.d.ts +17 -7
  107. package/dist/index.d.ts +1 -2
  108. package/dist/index.js +0 -4
  109. package/dist/logging.d.ts +10 -0
  110. package/dist/logging.js +9 -0
  111. package/package.json +28 -22
  112. package/.prettierrc.js +0 -40
  113. package/dist/augments/ansi-regex.d.ts +0 -1
  114. package/dist/augments/ansi-regex.js +0 -27
  115. package/dist/augments/string.d.ts +0 -1
  116. package/dist/augments/string.js +0 -8
  117. package/dist/cli/cli-util/cli-color.d.ts +0 -8
  118. package/dist/cli/cli-util/cli-color.js +0 -35
  119. package/dist/cli/cli-util/cli-command-name.d.ts +0 -11
  120. package/dist/cli/cli-util/cli-command-name.js +0 -15
  121. package/dist/cli/cli-util/cli-flags.d.ts +0 -18
  122. package/dist/cli/cli-util/cli-flags.js +0 -63
  123. package/dist/cli/cli-util/cli-messages.d.ts +0 -7
  124. package/dist/cli/cli-util/cli-messages.js +0 -19
  125. package/dist/cli/cli-util/get-all-command-output.d.ts +0 -7
  126. package/dist/cli/cli-util/get-all-command-output.js +0 -21
  127. package/dist/cli/cli-util/shell-command-wrapper.d.ts +0 -8
  128. package/dist/cli/cli-util/shell-command-wrapper.js +0 -25
  129. package/dist/cli/cli-util/update-configs.d.ts +0 -3
  130. package/dist/cli/cli-util/update-configs.js +0 -54
  131. package/dist/cli/commands/all-cli-commands.d.ts +0 -13
  132. package/dist/cli/commands/all-cli-commands.js +0 -99
  133. package/dist/cli/commands/cli-command.d.ts +0 -35
  134. package/dist/cli/commands/cli-command.js +0 -40
  135. package/dist/cli/commands/implementations/code-in-markdown.command.d.ts +0 -3
  136. package/dist/cli/commands/implementations/code-in-markdown.command.js +0 -54
  137. package/dist/cli/commands/implementations/compile.command.d.ts +0 -3
  138. package/dist/cli/commands/implementations/compile.command.js +0 -49
  139. package/dist/cli/commands/implementations/format.command.d.ts +0 -16
  140. package/dist/cli/commands/implementations/format.command.js +0 -143
  141. package/dist/cli/commands/implementations/init.command.d.ts +0 -3
  142. package/dist/cli/commands/implementations/init.command.js +0 -55
  143. package/dist/cli/commands/implementations/spellcheck.command.d.ts +0 -3
  144. package/dist/cli/commands/implementations/spellcheck.command.js +0 -35
  145. package/dist/cli/commands/implementations/test.command.d.ts +0 -3
  146. package/dist/cli/commands/implementations/test.command.js +0 -49
  147. package/dist/cli/commands/implementations/update-all-configs.command.d.ts +0 -3
  148. package/dist/cli/commands/implementations/update-all-configs.command.js +0 -46
  149. package/dist/cli/commands/implementations/update-bare-configs.command.d.ts +0 -3
  150. package/dist/cli/commands/implementations/update-bare-configs.command.js +0 -46
  151. package/dist/cli/commands/run-command.d.ts +0 -3
  152. package/dist/cli/commands/run-command.js +0 -65
  153. package/dist/cli/config/config-key.d.ts +0 -35
  154. package/dist/cli/config/config-key.js +0 -25
  155. package/dist/cli/config/config-paths.d.ts +0 -3
  156. package/dist/cli/config/config-paths.js +0 -69
  157. package/dist/cli/config/config-read.d.ts +0 -7
  158. package/dist/cli/config/config-read.js +0 -91
  159. package/dist/cli/config/extendable-config.d.ts +0 -12
  160. package/dist/cli/config/extendable-config.js +0 -45
  161. package/dist/errors/cli-command-error.d.ts +0 -4
  162. package/dist/errors/cli-command-error.js +0 -12
  163. package/dist/errors/cli-flag-error.d.ts +0 -4
  164. package/dist/errors/cli-flag-error.js +0 -12
  165. package/dist/errors/config-file-error.d.ts +0 -3
  166. package/dist/errors/config-file-error.js +0 -7
  167. package/dist/exportable-jest-config/jest-config.d.ts +0 -3
  168. package/dist/exportable-jest-config/jest-config.js +0 -23
  169. package/dist/exportable-jest-config/jest-setup.d.ts +0 -1
  170. package/dist/exportable-jest-config/jest-setup.js +0 -11
  171. package/dist/file-paths/virmator-repo-paths.d.ts +0 -5
  172. package/dist/file-paths/virmator-repo-paths.js +0 -19
  173. package/dist/jest/jest-config.d.ts +0 -3
  174. package/dist/jest/jest-config.js +0 -13
  175. package/extender-configs/.cspell.json +0 -3
  176. package/extender-configs/.prettierrc.js +0 -3
  177. package/extender-configs/tsconfig.json +0 -3
  178. package/separate-configs/.prettierignore +0 -3
  179. package/separate-configs/gitignore.txt +0 -4
  180. package/separate-configs/jest/jest-config.ts +0 -24
  181. package/separate-configs/jest/jest-setup.ts +0 -12
  182. package/separate-configs/npmignore.txt +0 -20
  183. package/separate-configs/package.json +0 -9
@@ -0,0 +1,8 @@
1
+ import baseConfig from './web-test-runner-base.mjs';
2
+
3
+ /** @type {import('@web/test-runner').TestRunnerConfig} */
4
+ const webTestRunnerConfig = {
5
+ ...baseConfig,
6
+ };
7
+
8
+ export default webTestRunnerConfig;
@@ -1,22 +1,34 @@
1
1
  {
2
+ "[css]": {
3
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
4
+ },
2
5
  "[html]": {
3
6
  "editor.defaultFormatter": "esbenp.prettier-vscode"
4
7
  },
5
8
  "[javascript]": {
6
9
  "editor.defaultFormatter": "esbenp.prettier-vscode"
7
10
  },
11
+ "[javascriptreact]": {
12
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
13
+ },
8
14
  "[json]": {
9
15
  "editor.defaultFormatter": "esbenp.prettier-vscode"
10
16
  },
11
17
  "[jsonc]": {
12
18
  "editor.defaultFormatter": "esbenp.prettier-vscode"
13
19
  },
20
+ "[less]": {
21
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
22
+ },
14
23
  "[markdown]": {
15
24
  "editor.defaultFormatter": "esbenp.prettier-vscode"
16
25
  },
17
26
  "[scss]": {
18
27
  "editor.defaultFormatter": "esbenp.prettier-vscode"
19
28
  },
29
+ "[toml]": {
30
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
31
+ },
20
32
  "[typescript]": {
21
33
  "editor.defaultFormatter": "esbenp.prettier-vscode"
22
34
  },
@@ -25,5 +37,6 @@
25
37
  },
26
38
  "editor.formatOnSave": true,
27
39
  "editor.rulers": [100],
40
+ "editor.wordWrapColumn": 100,
28
41
  "typescript.tsdk": "node_modules/typescript/lib"
29
42
  }
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ /Icon?
3
+ coverage/
4
+ dist/
5
+ graphics/
6
+ node_modules/
@@ -0,0 +1,13 @@
1
+ .*
2
+ *.test-helper.ts
3
+ *.test.d.ts
4
+ *.test.js
5
+ *.test.ts
6
+ **/*/readme-examples/
7
+ **/*/test/
8
+ /Icon?
9
+ coverage/
10
+ graphics/
11
+ src/
12
+ test-files/
13
+ tsconfig*.json
@@ -0,0 +1,16 @@
1
+ {
2
+ "license": "MIT",
3
+ "main": "dist/index.js",
4
+ "types": "dist/index.d.ts",
5
+ "scripts": {
6
+ "compile": "rm -rf dist && tsc --project tsconfig.json",
7
+ "docs:update": "virmator code-in-markdown",
8
+ "format": "virmator format write",
9
+ "prepublishOnly": "npm run compile && npm run test:full",
10
+ "spellcheck": "virmator spellcheck",
11
+ "start": "npm install && vite --force --config .virmator/vite/vite.config.ts",
12
+ "test": "virmator test",
13
+ "test:full": "npm run test:types && npm test && npm run spellcheck && virmator format check",
14
+ "test:types": "tsc --noEmit"
15
+ }
16
+ }
@@ -0,0 +1,5 @@
1
+ /** This file helps ensure that test calls are imported from the correct package. */
2
+
3
+ declare var it: "Don't use this directly, instead import it from Mocha.";
4
+ declare var expect: "Don't use this directly, instead import this from Chai.";
5
+ declare var describe: "Don't use this directly, instead import describe from Mocha.";
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "./.virmator/tsconfig-base.json"
3
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Creates a wrapped instance of virmator from which all its CLI commands can be called. Arguments
3
+ * can be passed in to
4
+ */
5
+ export declare function createVirmatorWrapper(): void;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createVirmatorWrapper = void 0;
4
+ /**
5
+ * Creates a wrapped instance of virmator from which all its CLI commands can be called. Arguments
6
+ * can be passed in to
7
+ */
8
+ function createVirmatorWrapper() { }
9
+ exports.createVirmatorWrapper = createVirmatorWrapper;
@@ -0,0 +1 @@
1
+ export declare function isInTypedArray<T>(input: any, array: T[]): input is T;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isInTypedArray = void 0;
4
+ function isInTypedArray(input, array) {
5
+ return array.includes(input);
6
+ }
7
+ exports.isInTypedArray = isInTypedArray;
@@ -0,0 +1,5 @@
1
+ export interface DirContents {
2
+ [key: string]: string | DirContents;
3
+ }
4
+ export declare function clearDirectoryContents(dirPath: string): Promise<void>;
5
+ export declare function readAllDirContents(dir: string, recursive?: boolean): Promise<DirContents>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readAllDirContents = exports.clearDirectoryContents = void 0;
4
+ const promises_1 = require("fs/promises");
5
+ const path_1 = require("path");
6
+ async function clearDirectoryContents(dirPath) {
7
+ await (0, promises_1.rm)(dirPath, { recursive: true });
8
+ await (0, promises_1.mkdir)(dirPath);
9
+ }
10
+ exports.clearDirectoryContents = clearDirectoryContents;
11
+ async function readAllDirContents(dir, recursive = false) {
12
+ const fileNames = await (0, promises_1.readdir)(dir);
13
+ const allFileContents = await Promise.all(fileNames.map(async (fileName) => {
14
+ const filePath = (0, path_1.join)(dir, fileName);
15
+ const isFile = (await (0, promises_1.stat)(filePath)).isFile();
16
+ return isFile
17
+ ? (await (0, promises_1.readFile)(filePath)).toString()
18
+ : recursive
19
+ ? await readAllDirContents(filePath, recursive)
20
+ : '';
21
+ }));
22
+ const mappedFileContents = fileNames.reduce((accum, fileName, index) => {
23
+ var _a;
24
+ const fileContents = (_a = allFileContents[index]) !== null && _a !== void 0 ? _a : '';
25
+ accum[fileName] = fileContents;
26
+ return accum;
27
+ }, {});
28
+ return mappedFileContents;
29
+ }
30
+ exports.readAllDirContents = readAllDirContents;
@@ -0,0 +1 @@
1
+ export declare function jsonParseOrUndefined(input: string): any | undefined;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jsonParseOrUndefined = void 0;
4
+ function jsonParseOrUndefined(input) {
5
+ try {
6
+ return JSON.parse(input);
7
+ }
8
+ catch (error) {
9
+ return undefined;
10
+ }
11
+ }
12
+ exports.jsonParseOrUndefined = jsonParseOrUndefined;
@@ -0,0 +1 @@
1
+ export declare function filterObject<T extends object>(fullObject: Readonly<T>, callback: (value: T[keyof T], key: keyof T, fullObject: Readonly<T>) => boolean): Partial<T>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterObject = void 0;
4
+ const augment_vir_1 = require("augment-vir");
5
+ function filterObject(fullObject, callback) {
6
+ return (0, augment_vir_1.getEnumTypedKeys)(fullObject).reduce((accum, key) => {
7
+ const value = fullObject[key];
8
+ if (callback(value, key, fullObject)) {
9
+ accum[key] = value;
10
+ }
11
+ return accum;
12
+ }, {});
13
+ }
14
+ exports.filterObject = filterObject;
@@ -0,0 +1 @@
1
+ export declare function sanitizeStringForRegExpCreation(inputString: string): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitizeStringForRegExpCreation = void 0;
4
+ function sanitizeStringForRegExpCreation(inputString) {
5
+ return inputString.replace(/\//g, '\\/').replace(/(\(|\)|\[|\]|\.|\}|\{|\||\+)/g, '\\$1');
6
+ }
7
+ exports.sanitizeStringForRegExpCreation = sanitizeStringForRegExpCreation;
@@ -0,0 +1,2 @@
1
+ import { Constructor } from './type';
2
+ export declare function assertInstanceOf<T>(input: unknown, classConstructor: Constructor<T>): asserts input is T;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertInstanceOf = void 0;
4
+ const chai_1 = require("chai");
5
+ function assertInstanceOf(input, classConstructor) {
6
+ chai_1.assert.instanceOf(input, classConstructor);
7
+ }
8
+ exports.assertInstanceOf = assertInstanceOf;
@@ -0,0 +1 @@
1
+ export declare type Constructor<T> = new (...args: any[]) => T;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,54 @@
1
+ import { ArrayElement } from 'augment-vir';
2
+ import { CliCommandDefinition } from './cli-command/define-cli-command';
3
+ declare const allCommandsArray: readonly [CliCommandDefinition<{
4
+ commandName: "code-in-markdown";
5
+ subCommandDescriptions: {
6
+ readonly check: "Check that markdown files have their examples inserted and are up-to-date.";
7
+ };
8
+ }>, CliCommandDefinition<{
9
+ commandName: "compile";
10
+ subCommandDescriptions: {
11
+ readonly check: "Run type checking without emitting compiled files.";
12
+ };
13
+ }>, CliCommandDefinition<{
14
+ commandName: "help";
15
+ subCommandDescriptions: {};
16
+ }>, CliCommandDefinition<{
17
+ commandName: "format";
18
+ subCommandDescriptions: {
19
+ readonly check: "check formatting without overwriting files.";
20
+ };
21
+ }>, CliCommandDefinition<{
22
+ commandName: "spellcheck";
23
+ subCommandDescriptions: {};
24
+ }>, CliCommandDefinition<{
25
+ commandName: "test";
26
+ subCommandDescriptions: {};
27
+ }>, CliCommandDefinition<{
28
+ commandName: "test-web";
29
+ subCommandDescriptions: {};
30
+ }>, CliCommandDefinition<{
31
+ commandName: "init";
32
+ subCommandDescriptions: {};
33
+ }>, CliCommandDefinition<{
34
+ commandName: "update-configs";
35
+ subCommandDescriptions: {};
36
+ }>, CliCommandDefinition<{
37
+ commandName: "frontend";
38
+ subCommandDescriptions: {
39
+ readonly build: "Builds and bundles the frontend for deployment.";
40
+ readonly preview: "Builds and previews the built output.";
41
+ };
42
+ }>];
43
+ export declare type BuiltInCommandName = ArrayElement<typeof allCommandsArray>['commandName'];
44
+ export declare const builtInCliCommandDefinitions: Readonly<Record<"code-in-markdown" | "compile" | "format" | "test" | "frontend" | "init" | "spellcheck" | "test-web" | "update-configs" | "help", CliCommandDefinition<Readonly<{
45
+ commandName: string;
46
+ subCommandDescriptions: Readonly<Record<string, string>>;
47
+ }>>>>;
48
+ export declare const allCliCommandDefinitions: Record<string, CliCommandDefinition<Readonly<{
49
+ commandName: string;
50
+ subCommandDescriptions: Readonly<Record<string, string>>;
51
+ }>>>;
52
+ export declare const builtInCommandNames: Record<BuiltInCommandName, BuiltInCommandName>;
53
+ export declare const allowedInGlobalInstallation: Set<"code-in-markdown" | "compile" | "format" | "test" | "frontend" | "init" | "spellcheck" | "test-web" | "update-configs" | "help">;
54
+ export {};
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.allowedInGlobalInstallation = exports.builtInCommandNames = exports.allCliCommandDefinitions = exports.builtInCliCommandDefinitions = void 0;
4
+ const augment_vir_1 = require("augment-vir");
5
+ const code_in_markdown_command_1 = require("./cli-command-implementations/code-in-markdown.command");
6
+ const compile_command_1 = require("./cli-command-implementations/compile.command");
7
+ const format_command_1 = require("./cli-command-implementations/format.command");
8
+ const frontend_command_1 = require("./cli-command-implementations/frontend.command");
9
+ const init_command_1 = require("./cli-command-implementations/init.command");
10
+ const spellcheck_command_1 = require("./cli-command-implementations/spellcheck.command");
11
+ const test_web_command_1 = require("./cli-command-implementations/test-web.command");
12
+ const test_command_1 = require("./cli-command-implementations/test.command");
13
+ const update_configs_command_1 = require("./cli-command-implementations/update-configs.command");
14
+ const cli_command_to_help_message_1 = require("./cli-command/cli-command-to-help-message");
15
+ const define_cli_command_1 = require("./cli-command/define-cli-command");
16
+ function createUnimplementedCommand(commandName) {
17
+ return (0, define_cli_command_1.defineCliCommand)({
18
+ commandName,
19
+ subCommandDescriptions: {},
20
+ }, () => {
21
+ return {
22
+ sections: [
23
+ {
24
+ content: 'This command has not been implemented yet',
25
+ title: '',
26
+ },
27
+ ],
28
+ examples: [],
29
+ };
30
+ }, () => {
31
+ throw new Error(`The "${commandName}" command has not been implemented yet.`);
32
+ });
33
+ }
34
+ const helpCommandDefinition = (0, define_cli_command_1.defineCliCommand)({
35
+ commandName: 'help',
36
+ subCommandDescriptions: {},
37
+ }, () => {
38
+ return {
39
+ sections: [
40
+ {
41
+ title: '',
42
+ content: 'Prints this help output.',
43
+ },
44
+ ],
45
+ examples: [],
46
+ };
47
+ }, (inputs) => {
48
+ inputs.logging.stdout((0, cli_command_to_help_message_1.wrapLines)((0, cli_command_to_help_message_1.generateHelpMessage)(exports.allCliCommandDefinitions, cli_command_to_help_message_1.MessageSyntax.Bash), 100));
49
+ return {
50
+ fullExecutedCommand: '',
51
+ success: true,
52
+ };
53
+ });
54
+ const allCommandsArray = [
55
+ code_in_markdown_command_1.codeInMarkdownCommandDefinition,
56
+ compile_command_1.compileCommandDefinition,
57
+ helpCommandDefinition,
58
+ format_command_1.formatCommandDefinition,
59
+ spellcheck_command_1.spellcheckCommandDefinition,
60
+ test_command_1.testCommandDefinition,
61
+ test_web_command_1.testWebCommandDefinition,
62
+ init_command_1.initCommandDefinition,
63
+ update_configs_command_1.updateConfigsCommandDefinition,
64
+ frontend_command_1.frontendCommandDefinition,
65
+ // createUnimplementedCommand('publish'),
66
+ ];
67
+ exports.builtInCliCommandDefinitions = allCommandsArray.reduce((accum, entry) => {
68
+ accum[entry.commandName] = entry;
69
+ return accum;
70
+ }, {});
71
+ exports.allCliCommandDefinitions = exports.builtInCliCommandDefinitions;
72
+ exports.builtInCommandNames = (0, augment_vir_1.mapObject)(exports.builtInCliCommandDefinitions, (key) => key);
73
+ exports.allowedInGlobalInstallation = new Set([
74
+ helpCommandDefinition,
75
+ init_command_1.initCommandDefinition,
76
+ ].map((commandDefinition) => commandDefinition.commandName));
@@ -0,0 +1,8 @@
1
+ export declare const Color: {
2
+ Info: string;
3
+ Fail: string;
4
+ Warn: string;
5
+ Success: string;
6
+ Reset: string;
7
+ Bold: string;
8
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Color = void 0;
4
+ const ansi_colors_1 = require("ansi-colors");
5
+ exports.Color = {
6
+ Info: ansi_colors_1.styles.blue.open,
7
+ Fail: ansi_colors_1.styles.red.open,
8
+ Warn: ansi_colors_1.styles.yellow.open,
9
+ Success: ansi_colors_1.styles.green.open,
10
+ Reset: ansi_colors_1.styles.reset.open,
11
+ Bold: ansi_colors_1.styles.bold.open,
12
+ };
@@ -0,0 +1,8 @@
1
+ export declare type CliHelpSection = Readonly<{
2
+ title: string;
3
+ content: string;
4
+ }>;
5
+ export declare type CliCommandDescription = Readonly<{
6
+ sections: Readonly<CliHelpSection[]>;
7
+ examples: Readonly<CliHelpSection[]>;
8
+ }>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +1,11 @@
1
- import { CliCommandImplementation } from './cli-command';
1
+ import { CliCommandDefinition } from './define-cli-command';
2
+ export declare function generateHelpMessage(commandDefinitions: Record<string, CliCommandDefinition>, syntax: MessageSyntax): string;
2
3
  export declare enum MessageSyntax {
3
4
  Bash = "bash",
4
5
  Markdown = "markdown"
5
6
  }
6
7
  export declare function flagToHelpString(flagName: string, description: string, syntax: MessageSyntax): string;
7
- export declare function commandToHelpString(command: CliCommandImplementation, syntax: MessageSyntax): string;
8
+ export declare function commandToHelpString(commandDefinition: CliCommandDefinition, syntax: MessageSyntax): string;
8
9
  export declare function combineHelpMessage(flagsText: string, commandsText: string, syntax: MessageSyntax): string;
9
10
  export declare function getIndent(line: string): string;
10
11
  export declare function wrapLines(input: string, limit: number): string;
@@ -1,26 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapLines = exports.getIndent = exports.combineHelpMessage = exports.commandToHelpString = exports.flagToHelpString = exports.MessageSyntax = void 0;
3
+ exports.wrapLines = exports.getIndent = exports.combineHelpMessage = exports.commandToHelpString = exports.flagToHelpString = exports.MessageSyntax = exports.generateHelpMessage = void 0;
4
4
  const augment_vir_1 = require("augment-vir");
5
5
  const package_name_1 = require("../../package-name");
6
- const cli_color_1 = require("../cli-util/cli-color");
6
+ const cli_color_1 = require("../cli-color");
7
+ const cli_flag_name_1 = require("../cli-flags/cli-flag-name");
8
+ const cli_flag_values_1 = require("../cli-flags/cli-flag-values");
9
+ function generateHelpMessage(commandDefinitions, syntax) {
10
+ const flagsMessage = (0, augment_vir_1.getEnumTypedValues)(cli_flag_name_1.CliFlagName)
11
+ .sort()
12
+ .map((flagName) => {
13
+ return flagToHelpString(flagName, cli_flag_values_1.cliFlagDescriptions[flagName], syntax);
14
+ })
15
+ .join('\n');
16
+ const commandsMessage = (0, augment_vir_1.getObjectTypedKeys)(commandDefinitions)
17
+ .sort()
18
+ .map((commandName) => {
19
+ const commandDefinition = commandDefinitions[commandName];
20
+ if (!commandDefinition) {
21
+ throw new Error(`Command definition was missing for key "${commandName}"`);
22
+ }
23
+ return commandToHelpString(commandDefinition, syntax);
24
+ })
25
+ .join('\n');
26
+ const helpMessage = combineHelpMessage(flagsMessage, commandsMessage, syntax);
27
+ return helpMessage;
28
+ }
29
+ exports.generateHelpMessage = generateHelpMessage;
7
30
  var MessageSyntax;
8
31
  (function (MessageSyntax) {
9
32
  MessageSyntax["Bash"] = "bash";
10
33
  MessageSyntax["Markdown"] = "markdown";
11
34
  })(MessageSyntax = exports.MessageSyntax || (exports.MessageSyntax = {}));
12
35
  const formatting = ((input) => input)({
13
- h2: {
36
+ h1: {
14
37
  [MessageSyntax.Bash]: `${cli_color_1.Color.Info}`,
15
- [MessageSyntax.Markdown]: '## ',
38
+ [MessageSyntax.Markdown]: '# ',
16
39
  },
17
- h3: {
40
+ h2: {
18
41
  [MessageSyntax.Bash]: `${cli_color_1.Color.Bold}${cli_color_1.Color.Info}`,
19
- [MessageSyntax.Markdown]: '### ',
42
+ [MessageSyntax.Markdown]: '## ',
20
43
  },
21
- h4: {
44
+ h3: {
22
45
  [MessageSyntax.Bash]: ``,
23
- [MessageSyntax.Markdown]: '#### ',
46
+ [MessageSyntax.Markdown]: '### ',
24
47
  },
25
48
  reset: {
26
49
  [MessageSyntax.Bash]: `${cli_color_1.Color.Reset}`,
@@ -59,16 +82,25 @@ function code(input, block, indent, syntax) {
59
82
  }
60
83
  function flagToHelpString(flagName, description, syntax) {
61
84
  const format = (key) => formatWithSyntax(key, syntax);
62
- return `${indent(1, syntax)}${format('h3')}${code(flagName, false, '', syntax)}${format('reset')}${format('colon')}\n${indent(2, syntax)}${description.trim()}`;
85
+ return `${indent(1, syntax)}${format('h2')}${code(flagName, false, '', syntax)}${format('reset')}${format('colon')}\n${indent(2, syntax)}${description.trim()}`;
63
86
  }
64
87
  exports.flagToHelpString = flagToHelpString;
65
- function commandToHelpString(command, syntax) {
88
+ function commandToHelpString(commandDefinition, syntax) {
66
89
  const format = (key) => formatWithSyntax(key, syntax);
67
- const title = `${indent(1, syntax)}${format('h3')}${command.commandName}${format('reset')}${format('colon')}`;
68
- const description = commandDescriptionToMessage(command.description, syntax);
69
- return `${title}\n${description}\n`;
90
+ const title = `${indent(1, syntax)}${format('h2')}${commandDefinition.commandName}${format('reset')}${format('colon')}`;
91
+ const description = commandDescriptionToMessage(commandDefinition.commandDescription, syntax);
92
+ const subCommandDescriptions = subCommandDescriptionsToMessage(commandDefinition.subCommandDescriptions, syntax);
93
+ return `${title}\n${description}\n${subCommandDescriptions}\n`;
70
94
  }
71
95
  exports.commandToHelpString = commandToHelpString;
96
+ function subCommandDescriptionsToMessage(subCommandDescriptions, syntax) {
97
+ return (0, augment_vir_1.getObjectTypedKeys)(subCommandDescriptions).reduce((accum, currentKey, index) => {
98
+ const keyDescription = subCommandDescriptions[currentKey];
99
+ const leadingLine = index > 0 ? '\n\n' : '';
100
+ const fullDescription = `${leadingLine}${formatWithSyntax('h3', syntax)}${currentKey}${formatWithSyntax('colon', syntax)}\n${indent(2, syntax)}${keyDescription}`;
101
+ return accum + fullDescription;
102
+ }, '');
103
+ }
72
104
  function indent(input, syntax) {
73
105
  return formatWithSyntax('indent', syntax).repeat(input);
74
106
  }
@@ -76,7 +108,7 @@ function sectionToString(section, extraIndent, syntax, bullets) {
76
108
  const format = (key) => formatWithSyntax(key, syntax);
77
109
  const sectionIndent = indent(2 + extraIndent, syntax);
78
110
  const separator = syntax === MessageSyntax.Bash || !bullets ? `:\n` : ': ';
79
- const header = bullets ? '' : format('h4');
111
+ const header = bullets ? '' : format('h3');
80
112
  const title = section.title ? `${sectionIndent}${header}${section.title}${separator}` : '';
81
113
  if (bullets && syntax === MessageSyntax.Markdown) {
82
114
  return `${format('bullet')}${title}${code(section.content, section.content.includes('\n'), syntax === MessageSyntax.Markdown && section.content.includes('\n') ? ' ' : '', syntax)}`;
@@ -95,42 +127,44 @@ function commandDescriptionToMessage(description, syntax) {
95
127
  .map((example) => sectionToString(example, 1, syntax, true))
96
128
  .join('\n');
97
129
  const examplesTitle = description.examples.length
98
- ? `\n\n${indent(2, syntax)}${format('h4')}Examples${format('reset')}${format('colon')}\n`
130
+ ? `\n\n${indent(2, syntax)}${format('h3')}Examples${format('reset')}${format('colon')}\n`
99
131
  : '';
100
132
  return `${sections}${examplesTitle}${examples}`;
101
133
  }
102
134
  function combineHelpMessage(flagsText, commandsText, syntax) {
103
135
  const format = (key) => formatWithSyntax(key, syntax);
104
- return `${formatting.h2[syntax]}${package_name_1.packageName} usage${format('colon')}${format('reset')}
136
+ return `${formatting.h1[syntax]}${package_name_1.packageName} usage${format('colon')}${format('reset')}
105
137
  ${format('indent')}${code(`[npx] ${package_name_1.packageName} [--flags] command subCommand`, true, '', syntax)}
106
138
 
107
139
  ${format('indent')}${code('npx', false, '', syntax)} is needed when the command is run directly from the terminal (not scoped within an npm script) unless the package has been globally installed (which will work just fine but I wouldn't recommend, simply because I prefer explicit dependencies).
108
140
 
109
- ${format('h2')}available flags${format('colon')}${format('reset')}
141
+ ${format('h1')}Available flags${format('colon')}${format('reset')}
110
142
  ${flagsText}
111
143
 
112
- ${format('h2')}available commands${format('colon')}${format('reset')}
144
+ ${format('h1')}Available commands${format('colon')}${format('reset')}
113
145
  ${commandsText}`;
114
146
  }
115
147
  exports.combineHelpMessage = combineHelpMessage;
116
148
  function getIndent(line) {
117
- return (0, augment_vir_1.safeMatch)(line, /^(\s*)/)[0] ?? '';
149
+ var _a;
150
+ return (_a = (0, augment_vir_1.safeMatch)(line, /^(\s*)/)[0]) !== null && _a !== void 0 ? _a : '';
118
151
  }
119
152
  exports.getIndent = getIndent;
120
153
  function wrapLines(input, limit) {
154
+ var _a, _b;
121
155
  const lines = input.split('\n');
122
156
  // using a for loop because the length of the array will get modified while iterating through it
123
157
  for (let index = 0; index < lines.length; index++) {
124
158
  const line = lines[index];
125
159
  if (line && line.length > limit) {
126
160
  const nextIndex = index + 1;
127
- const nextLine = lines[nextIndex] ?? '';
161
+ const nextLine = (_a = lines[nextIndex]) !== null && _a !== void 0 ? _a : '';
128
162
  const newLine = line.slice(0, limit);
129
163
  lines[index] = newLine.trimEnd();
130
164
  let wrappedPart = line.slice(limit);
131
165
  // didn't wrap on a space, we need to shift a word down
132
166
  if (!newLine.endsWith(' ') && !wrappedPart.startsWith(' ')) {
133
- const lastWord = (0, augment_vir_1.safeMatch)(newLine, /(\s\S+$)/)[0] ?? '';
167
+ const lastWord = (_b = (0, augment_vir_1.safeMatch)(newLine, /(\s\S+$)/)[0]) !== null && _b !== void 0 ? _b : '';
134
168
  lines[index] = newLine.slice(0, -1 * lastWord.length).trimEnd();
135
169
  wrappedPart = `${lastWord}${wrappedPart.trim()}`;
136
170
  }
@@ -0,0 +1,41 @@
1
+ import { CliLogging } from '../../logging';
2
+ import { CliCommandDescription } from './cli-command-help';
3
+ export declare type CliCommandExecutorInputs<InputsGeneric extends DefineCliCommandInputs = DefineCliCommandInputs> = {
4
+ filteredInputArgs: string[];
5
+ inputSubCommands: (keyof InputsGeneric['subCommandDescriptions'])[];
6
+ repoDir: string;
7
+ logging: CliLogging;
8
+ };
9
+ export declare type FullCliCommandExecutorInputs<InputsGeneric extends DefineCliCommandInputs> = {
10
+ filteredInputArgs: string[];
11
+ inputSubCommands: (keyof InputsGeneric['subCommandDescriptions'])[];
12
+ repoDir: string;
13
+ logging: CliLogging;
14
+ } & SharedExecutorInputsAndCommandDefinition<InputsGeneric>;
15
+ export declare type CliCommandExecutor<InputsGeneric extends DefineCliCommandInputs> = (inputs: CliCommandExecutorInputs<InputsGeneric>) => Promise<CliCommandExecutorOutput> | CliCommandExecutorOutput;
16
+ export declare type FullCliCommandExecutor<InputsGeneric extends DefineCliCommandInputs> = (inputs: FullCliCommandExecutorInputs<InputsGeneric>) => Promise<CliCommandExecutorOutput> | CliCommandExecutorOutput;
17
+ export declare type CliCommandExecutorOutput = {
18
+ fullExecutedCommand: string;
19
+ success: boolean;
20
+ };
21
+ export declare type DefineCliCommandInputs<CommandName extends string = string> = Readonly<{
22
+ commandName: CommandName;
23
+ subCommandDescriptions: Readonly<Record<string, string>>;
24
+ }>;
25
+ declare type SubCommandsMap<InputsGeneric extends DefineCliCommandInputs> = {
26
+ [Prop in keyof InputsGeneric['subCommandDescriptions']]: Prop;
27
+ };
28
+ declare type SharedExecutorInputsAndCommandDefinition<InputsGeneric extends DefineCliCommandInputs> = InputsGeneric & {
29
+ allAvailableSubCommands: (keyof InputsGeneric['subCommandDescriptions'])[];
30
+ subCommands: SubCommandsMap<InputsGeneric>;
31
+ };
32
+ export declare type CliCommandDefinition<InputsGeneric extends DefineCliCommandInputs = DefineCliCommandInputs> = SharedExecutorInputsAndCommandDefinition<InputsGeneric> & {
33
+ executor: CliCommandExecutor<InputsGeneric>;
34
+ commandDescription: CliCommandDescription;
35
+ };
36
+ declare type CreateDescriptionsInputs<InputsGeneric extends DefineCliCommandInputs> = Pick<InputsGeneric, 'commandName'> & {
37
+ subCommands: SubCommandsMap<InputsGeneric>;
38
+ };
39
+ declare type CreateDescriptionsCallback<InputsGeneric extends DefineCliCommandInputs> = (inputs: CreateDescriptionsInputs<InputsGeneric>) => CliCommandDescription;
40
+ export declare function defineCliCommand<InputsGeneric extends DefineCliCommandInputs>(inputs: Readonly<InputsGeneric>, createDescription: CreateDescriptionsCallback<InputsGeneric>, inputExecutor: FullCliCommandExecutor<InputsGeneric>): CliCommandDefinition<InputsGeneric>;
41
+ export {};