virmator 1.4.5 → 2.0.2

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 (57) hide show
  1. package/.cspell.json +1 -0
  2. package/.github/workflows/virmator-prerelease.yml +9 -4
  3. package/.github/workflows/virmator-tests.yml +1 -1
  4. package/.prettierignore +3 -2
  5. package/README.md +161 -1
  6. package/dist/augments/ansi-regex.d.ts +1 -0
  7. package/dist/augments/ansi-regex.js +27 -0
  8. package/dist/augments/string.d.ts +1 -0
  9. package/dist/augments/string.js +8 -0
  10. package/dist/cli/cli-util/cli-flags.js +7 -10
  11. package/dist/cli/cli-util/get-all-command-output.d.ts +4 -3
  12. package/dist/cli/cli-util/shell-command-wrapper.d.ts +1 -1
  13. package/dist/cli/cli-util/shell-command-wrapper.js +2 -2
  14. package/dist/cli/cli-util/update-configs.js +6 -5
  15. package/dist/cli/cli.js +1 -1
  16. package/dist/cli/commands/all-cli-commands.d.ts +2 -0
  17. package/dist/cli/commands/all-cli-commands.js +31 -27
  18. package/dist/cli/commands/cli-command.d.ts +10 -1
  19. package/dist/cli/commands/cli-command.js +1 -1
  20. package/dist/cli/commands/description-printing.d.ts +10 -0
  21. package/dist/cli/commands/description-printing.js +149 -0
  22. package/dist/cli/commands/implementations/code-in-markdown.command.js +29 -22
  23. package/dist/cli/commands/implementations/compile.command.js +20 -8
  24. package/dist/cli/commands/implementations/format.command.js +54 -40
  25. package/dist/cli/commands/implementations/init.command.js +13 -4
  26. package/dist/cli/commands/implementations/spellcheck.command.js +10 -1
  27. package/dist/cli/commands/implementations/test.command.js +30 -27
  28. package/dist/cli/commands/implementations/update-all-configs.command.js +23 -14
  29. package/dist/cli/commands/implementations/update-bare-configs.command.js +23 -15
  30. package/dist/cli/commands/run-command.js +2 -3
  31. package/dist/cli/config/config-key.d.ts +13 -9
  32. package/dist/cli/config/config-key.js +6 -4
  33. package/dist/cli/config/config-paths.js +11 -1
  34. package/dist/cli/config/config-read.js +1 -2
  35. package/dist/cli/config/copy-config.js +3 -3
  36. package/dist/cli/config/create-default-package-json.js +2 -2
  37. package/dist/cli/config/extendable-config.js +3 -3
  38. package/dist/errors/cli-command-error.js +3 -3
  39. package/dist/errors/cli-flag-error.js +3 -3
  40. package/dist/errors/config-file-error.js +1 -4
  41. package/dist/exportable-jest-config/jest-config.d.ts +3 -0
  42. package/dist/exportable-jest-config/jest-config.js +23 -0
  43. package/dist/exportable-jest-config/jest-setup.d.ts +1 -0
  44. package/dist/exportable-jest-config/jest-setup.js +11 -0
  45. package/dist/file-paths/virmator-repo-paths.js +4 -4
  46. package/dist/file-paths/{virmator-test-repos-paths.d.ts → virmator-test-file-paths.d.ts} +2 -0
  47. package/dist/index.d.ts +2 -0
  48. package/dist/index.js +6 -0
  49. package/dist/jest/jest-config.d.ts +3 -0
  50. package/dist/jest/jest-config.js +13 -0
  51. package/package.json +29 -23
  52. package/separate-configs/gitignore.txt +2 -0
  53. package/separate-configs/jest/jest-config.ts +24 -0
  54. package/separate-configs/jest/jest-setup.ts +12 -0
  55. package/separate-configs/npmignore.txt +7 -4
  56. package/tsconfig.json +13 -6
  57. package/dist/file-paths/virmator-test-repos-paths.js +0 -56
package/.cspell.json CHANGED
@@ -57,6 +57,7 @@
57
57
  "repo's",
58
58
  "repos",
59
59
  "rgba",
60
+ "stackoverflow",
60
61
  "stylelint",
61
62
  "stylelintrc",
62
63
  "tabbable",
@@ -3,17 +3,22 @@ name: branch-prerelease
3
3
  on:
4
4
  workflow_run:
5
5
  workflows: ['tests']
6
- branches: '**'
7
6
  types:
8
7
  - completed
8
+ branches:
9
+ - '**'
10
+
11
+ # this is currently running on main no matter what, even when a different branch triggered "tests"
9
12
 
10
13
  jobs:
11
- package-release:
12
- name: 'package release'
14
+ branch-prerelease:
15
+ name: 'branch prerelease'
13
16
  runs-on: 'ubuntu-latest'
14
17
  if: ${{ github.event.workflow_run.conclusion == 'success' }}
15
18
  steps:
16
- - uses: actions/checkout@v1
19
+ - uses: actions/checkout@v3
20
+ with:
21
+ ref: 'update-commands'
17
22
  - name: Use Node.js 16.x
18
23
  uses: actions/setup-node@v1
19
24
  with:
@@ -12,7 +12,7 @@ jobs:
12
12
  fail-fast: false
13
13
  matrix:
14
14
  os: [ubuntu-latest, windows-latest, macos-latest]
15
- node-version: [12.x, 14.x, 16.x]
15
+ node-version: [14.x, 16.x]
16
16
  steps:
17
17
  - uses: actions/checkout@v1
18
18
  - name: Use Node.js ${{ matrix.node-version }}
package/.prettierignore CHANGED
@@ -1,5 +1,6 @@
1
1
  dist/
2
2
  node_modules/
3
3
  package-lock.json
4
- test-repos/format/
5
- extender-configs/
4
+ test-files/format/
5
+ extender-configs/
6
+ dist/vite/
package/README.md CHANGED
@@ -10,8 +10,168 @@ Centralize and automate all the things! So I don't have to copy pasta configs in
10
10
  npm -i D virmator
11
11
  ```
12
12
 
13
- # Help
13
+ # Usage
14
14
 
15
15
  ```bash
16
16
  npx virmator --help
17
17
  ```
18
+
19
+ Output from the help command:
20
+
21
+ <!-- usage below -->
22
+
23
+ ## virmator usage
24
+
25
+ ```
26
+ [npx] virmator [--flags] command subCommand
27
+ ```
28
+
29
+ `npx` 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).
30
+
31
+ ## available flags
32
+
33
+ ### `--extendable-config`
34
+
35
+ Not supported by all commands. Rather than updating the current command's relevant config file directly, commands will write an extendable config file so that the user can extend and override config values.
36
+
37
+ ### `--help`
38
+
39
+ Prints this help message.
40
+
41
+ ### `--no-write-config`
42
+
43
+ Prevents a command from overwriting its relevant config file (if one exists, which they usually do).
44
+
45
+ ### `--silent`
46
+
47
+ Turns off most logging.
48
+
49
+ ## available commands
50
+
51
+ ### code-in-markdown
52
+
53
+ Insert code snippets into markdown files. This uses the markdown-code-example-inserter package to expand code link comments inside of markdown files to actual markdown code blocks. See that package's README for more details but the basics are that you need a comment that looks like the following in your markdown file for this to do anything: `<!-- example-link: path/to/file.ts -->`
54
+
55
+ By default this command parses all markdown files in the repo (ignoring node_modules). Specific markdown files can be parsed by giving virmator extra parameters.
56
+
57
+ #### Examples
58
+
59
+ - default experience (usually all you need): `virmator code-in-markdown`
60
+ - override files to check to a single file: `virmator code-in-markdown only/this/one/file.md`
61
+ - override files to check to a group of files: `virmator code-in-markdown "only/this/dir/*.md"`
62
+
63
+ ### compile
64
+
65
+ compile typescript files
66
+ Pass any extra tsc flags to this command.
67
+
68
+ #### Examples
69
+
70
+ - no extra flags: `virmator compile`
71
+ - one extra flag: `virmator compile --noEmit`
72
+
73
+ ### format
74
+
75
+ Formats source files with Prettier.
76
+
77
+ #### operation commands:
78
+
79
+ This is optional but if provided it must come first. write is the default.
80
+ write: overwrites files to fix formatting.
81
+ check: checks the formatting, does not write to files
82
+
83
+ #### file extensions:
84
+
85
+ If only specific file extensions should be formatted, add the "--format-files" argument to this command. All following arguments will be treated as file extensions to be formatted. For example, the following command will overwrite files (because write is the default operation) only if they have the extension ".md" or ".json": virmator format --format-files md json
86
+
87
+ #### Prettier flags:
88
+
89
+ Any other arguments encountered between the operation command (if provided) and the "--format-files" marker are treated as extra arguments to Prettier and will be passed along.
90
+
91
+ #### Examples
92
+
93
+ - checks formatting for files: `virmator format check`
94
+ - checks formatting only for .md files: `virmator format check --format-files md`
95
+ - checks formatting only for .md and .json files: `virmator format check --format-files md json`
96
+ - fixes formatting for files:
97
+
98
+ ```
99
+ virmator format
100
+ virmator format write
101
+ ```
102
+
103
+ - examples with extra Prettier flags:
104
+ ```
105
+ virmator format --ignore-path .prettierignore
106
+ virmator format write --ignore-path .prettierignore
107
+ virmator format write --ignore-path .prettierignore --format-files md json
108
+ ```
109
+
110
+ ### help
111
+
112
+ Prints this help message.
113
+
114
+ ### test
115
+
116
+ Init everything, including package.json scripts.
117
+ If no package.json file is found, one is created and initialized.
118
+ Pass --force to this command to overwrite current package.json scripts.
119
+
120
+ ### spellcheck
121
+
122
+ Spellcheck code with cspell. Any extra arguments are passed directly to cspell.
123
+
124
+ ### test
125
+
126
+ Test all .test.ts files with jest. By default this command tests all .test.ts files in the current directory that are not .type.test.ts files. To override this behavior, pass in a custom config file with Jest's --config argument. The default Jest config file can be extended by importing it with "import {virmatorJestConfig} from 'virmator'". All other Jest inputs are also valid.
127
+
128
+ #### Examples
129
+
130
+ - `virmator test ./path/to/single/file.js`
131
+ - `virmator test "./**/single-file.js"`
132
+ - `virmator test "./dist/**/!(*.type).test.js"`
133
+
134
+ ### update-all-configs
135
+
136
+ Update all config files. This command accepts a list of config file keys as arguments. If no arguments are given, this command copies all config files.
137
+
138
+ #### list of possible arguments:
139
+
140
+ Cspell
141
+ JestConfig
142
+ JestSetup
143
+ PackageJson
144
+ Prettier
145
+ PrettierIgnore
146
+ TsConfig
147
+ GitAttributes
148
+ GitHubActionsPrerelease
149
+ GitHubActionsTaggedRelease
150
+ GitHubActionsTest
151
+ GitIgnore
152
+ NpmIgnore
153
+ VsCodeSettings
154
+
155
+ #### Examples
156
+
157
+ - update all config files: `virmator update-all-configs`
158
+ - update only Cspell and GitIgnore files: `virmator update-all-configs Cspell GitIgnore`
159
+
160
+ ### update-bare-configs
161
+
162
+ Update config files that aren't used in any virmator commands, like GitHub actions tests or VS Code Settings. This command accepts a list of bare config file keys as arguments. If no arguments are given, this command copies all the bare config files.
163
+
164
+ #### list of possible arguments:
165
+
166
+ GitAttributes
167
+ GitHubActionsPrerelease
168
+ GitHubActionsTaggedRelease
169
+ GitHubActionsTest
170
+ GitIgnore
171
+ NpmIgnore
172
+ VsCodeSettings
173
+
174
+ #### Examples
175
+
176
+ - update all bare config files: `virmator update-bare-configs`
177
+ - update only GitIgnore and NpmIgnore files: `virmator update-bare-configs GitIgnore NpmIgnore,`
@@ -0,0 +1 @@
1
+ export declare const ansiRegex: RegExp;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ansiRegex = void 0;
4
+ // cspell:disable
5
+ /*
6
+ Copied from
7
+ https://github.com/chalk/ansi-regex/blob/1b337add136eb520764634a328e2f6354398eee5/index.js
8
+ because the published ansi-regex package exports this in a manner that Jest can't handle and the
9
+ latest version of the package that doesn't do that has a security vulnerability. The package has
10
+ the following license from
11
+ https://github.com/chalk/ansi-regex/blob/1b337add136eb520764634a328e2f6354398eee5/license
12
+
13
+ MIT License
14
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+ */
22
+ // cspell:enable
23
+ const patterns = [
24
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
25
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
26
+ ];
27
+ exports.ansiRegex = new RegExp(patterns.join('|'), 'g');
@@ -0,0 +1 @@
1
+ export declare function stripColor(input: string): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stripColor = void 0;
4
+ const ansi_regex_1 = require("./ansi-regex");
5
+ function stripColor(input) {
6
+ return input.replace(ansi_regex_1.ansiRegex, '');
7
+ }
8
+ exports.stripColor = stripColor;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractArguments = exports.fillInCliFlags = exports.flagDescriptions = exports.defaultCliFlags = exports.CliFlagName = void 0;
4
- const node_1 = require("augment-vir/dist/node");
4
+ const augment_vir_1 = require("augment-vir");
5
5
  const cli_command_name_1 = require("./cli-command-name");
6
6
  var CliFlagName;
7
7
  (function (CliFlagName) {
@@ -17,13 +17,10 @@ exports.defaultCliFlags = {
17
17
  [CliFlagName.ExtendableConfig]: false,
18
18
  };
19
19
  exports.flagDescriptions = {
20
- [CliFlagName.Silent]: 'turns off most logging',
21
- [CliFlagName.NoWriteConfig]: `prevents a command from overwriting its relevant config file
22
- (if one exists, which they usually do)`,
23
- [CliFlagName.ExtendableConfig]: `not supported by all commands. Rather than updating the
24
- the current command's relevant config file directly, commands will write an extendable
25
- config file so that the user can extend and override config values.`,
26
- [CliFlagName.Help]: 'prints a help message',
20
+ [CliFlagName.Silent]: 'Turns off most logging.',
21
+ [CliFlagName.NoWriteConfig]: `Prevents a command from overwriting its relevant config file (if one exists, which they usually do).`,
22
+ [CliFlagName.ExtendableConfig]: `Not supported by all commands. Rather than updating the current command's relevant config file directly, commands will write an extendable config file so that the user can extend and override config values.`,
23
+ [CliFlagName.Help]: 'Prints this help message.',
27
24
  };
28
25
  function fillInCliFlags(inputFlags) {
29
26
  return { ...exports.defaultCliFlags, ...(inputFlags || {}) };
@@ -31,11 +28,11 @@ function fillInCliFlags(inputFlags) {
31
28
  exports.fillInCliFlags = fillInCliFlags;
32
29
  function extractArguments(args) {
33
30
  const { inputFlags, invalidFlags, otherArgs, command } = args.reduce((accum, currentArg) => {
34
- if ((0, node_1.isEnumValue)(currentArg, cli_command_name_1.CliCommandName) && !accum.command) {
31
+ if ((0, augment_vir_1.isEnumValue)(currentArg, cli_command_name_1.CliCommandName) && !accum.command) {
35
32
  accum.command = currentArg;
36
33
  }
37
34
  else if (currentArg.startsWith('--')) {
38
- if ((0, node_1.isEnumValue)(currentArg, CliFlagName)) {
35
+ if ((0, augment_vir_1.isEnumValue)(currentArg, CliFlagName)) {
39
36
  accum.inputFlags[currentArg] = true;
40
37
  }
41
38
  else if (!accum.command) {
@@ -1,6 +1,7 @@
1
1
  import { CliCommandResult, CommandFunctionInput } from '../commands/cli-command';
2
- /** This is for testing purposes only. */
3
- export declare function getAllCommandOutput(commandImplementation: (inputs: CommandFunctionInput) => Promise<CliCommandResult>, inputs: CommandFunctionInput): Promise<{
2
+ export declare type AllCommandOutput = {
4
3
  stderr: string;
5
4
  stdout: string;
6
- } & CliCommandResult>;
5
+ } & CliCommandResult;
6
+ /** This is for testing purposes only. */
7
+ export declare function getAllCommandOutput(commandImplementation: (inputs: CommandFunctionInput) => Promise<CliCommandResult>, inputs: CommandFunctionInput): Promise<AllCommandOutput>;
@@ -1,4 +1,4 @@
1
- import { ShellOutput } from 'augment-vir/dist/node';
1
+ import { ShellOutput } from 'augment-vir/dist/node-only';
2
2
  import { CommandFunctionInput } from '../commands/cli-command';
3
3
  export declare type OutputFilter = (toPrint: string) => string;
4
4
  export declare type Filters = {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runVirmatorShellCommand = void 0;
4
- const node_1 = require("augment-vir/dist/node");
4
+ const node_only_1 = require("augment-vir/dist/node-only");
5
5
  const defaultFilter = (input) => input;
6
6
  function outputWrapper(callback, filter) {
7
7
  return (input) => {
@@ -15,7 +15,7 @@ async function runVirmatorShellCommand(command, { repoDir: cwd, stdoutCallback,
15
15
  stdoutFilter: defaultFilter,
16
16
  stderrFilter: defaultFilter,
17
17
  }) {
18
- const shellResults = await (0, node_1.runShellCommand)(command, {
18
+ const shellResults = await (0, node_only_1.runShellCommand)(command, {
19
19
  cwd,
20
20
  stdoutCallback: outputWrapper(stdoutCallback, stdoutFilter),
21
21
  stderrCallback: outputWrapper(stderrCallback, stderrFilter),
@@ -1,18 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateConfigs = void 0;
4
- const node_1 = require("augment-vir/dist/node");
5
- const fs_extra_1 = require("fs-extra");
4
+ const augment_vir_1 = require("augment-vir");
5
+ const fs_1 = require("fs");
6
6
  const cli_command_1 = require("../commands/cli-command");
7
7
  const format_command_1 = require("../commands/implementations/format.command");
8
8
  const copy_config_1 = require("../config/copy-config");
9
9
  const extendable_config_1 = require("../config/extendable-config");
10
10
  const cli_flags_1 = require("./cli-flags");
11
11
  async function updateConfigs(configKeysEnum, commandInputs) {
12
- const inputConfigFiles = (0, node_1.filterToEnumValues)(commandInputs.rawArgs, configKeysEnum);
12
+ const inputConfigFiles = (0, augment_vir_1.filterToEnumValues)(commandInputs.rawArgs, configKeysEnum);
13
13
  const configFilesToCopy = inputConfigFiles.length
14
14
  ? inputConfigFiles
15
- : (0, node_1.getEnumTypedValues)(configKeysEnum);
15
+ : (0, augment_vir_1.getEnumTypedValues)(configKeysEnum);
16
16
  let writtenFileCount = 0;
17
17
  const errors = [];
18
18
  await Promise.all(configFilesToCopy.map(async (configKey) => {
@@ -23,7 +23,7 @@ async function updateConfigs(configKeysEnum, commandInputs) {
23
23
  (0, extendable_config_1.isExtendableConfig)(configKey),
24
24
  repoDir: commandInputs.repoDir,
25
25
  });
26
- if (!(0, fs_extra_1.existsSync)(outputFilePath)) {
26
+ if (!(0, fs_1.existsSync)(outputFilePath)) {
27
27
  throw new Error(`Tried to write config file but it didn't actually get written: ${outputFilePath}`);
28
28
  }
29
29
  if (didWrite) {
@@ -47,6 +47,7 @@ async function updateConfigs(configKeysEnum, commandInputs) {
47
47
  commandInputs.stdoutCallback('All configs up to date.');
48
48
  }
49
49
  return {
50
+ command: undefined,
50
51
  success: !errors.length,
51
52
  };
52
53
  }
package/dist/cli/cli.js CHANGED
@@ -43,5 +43,5 @@ if (require.main === module) {
43
43
  cli(process.argv.slice(2));
44
44
  }
45
45
  else {
46
- throw new Error(`${__filename} should not be imported directly.`);
46
+ throw new Error(`${__filename} should not be imported directly. To run the cli from within the Virmator repo itself, use the following bash command: node dist/cli/cli.js`);
47
47
  }
@@ -1,11 +1,13 @@
1
1
  import { CliCommandName } from '../cli-util/cli-command-name';
2
2
  import { CliFlagName, CliFlags } from '../cli-util/cli-flags';
3
3
  import { CliCommandImplementation, CliCommandResult, CommandFunctionInput } from './cli-command';
4
+ import { MessageSyntax } from './description-printing';
4
5
  export declare function getUnsupportedFlags(currentFlags: CliFlags, flagSupport: Record<CliFlagName, boolean>): CliFlagName[];
5
6
  /**
6
7
  * The Help command implementation is in this file because it both depends on allCliCommands and is
7
8
  * depended on by allCliCommands.
8
9
  */
9
10
  export declare const helpImplementation: CliCommandImplementation;
11
+ export declare function generateHelpMessage(syntax: MessageSyntax): string;
10
12
  export declare function runHelpCommand({ stdoutCallback }: CommandFunctionInput): CliCommandResult;
11
13
  export declare const allCliCommands: Readonly<Record<CliCommandName, CliCommandImplementation>>;
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.allCliCommands = exports.runHelpCommand = exports.helpImplementation = exports.getUnsupportedFlags = void 0;
4
- const node_1 = require("augment-vir/dist/node");
5
- const package_name_1 = require("../../package-name");
6
- const cli_color_1 = require("../cli-util/cli-color");
3
+ exports.allCliCommands = exports.runHelpCommand = exports.generateHelpMessage = exports.helpImplementation = exports.getUnsupportedFlags = void 0;
4
+ const augment_vir_1 = require("augment-vir");
7
5
  const cli_command_name_1 = require("../cli-util/cli-command-name");
8
6
  const cli_flags_1 = require("../cli-util/cli-flags");
7
+ const description_printing_1 = require("./description-printing");
9
8
  const code_in_markdown_command_1 = require("./implementations/code-in-markdown.command");
10
9
  const compile_command_1 = require("./implementations/compile.command");
11
10
  const format_command_1 = require("./implementations/format.command");
@@ -17,7 +16,15 @@ const update_bare_configs_command_1 = require("./implementations/update-bare-con
17
16
  function createUnImplementedCommand(commandName) {
18
17
  return {
19
18
  commandName,
20
- description: 'not implemented yet',
19
+ description: {
20
+ sections: [
21
+ {
22
+ title: '',
23
+ content: 'not implemented yet',
24
+ },
25
+ ],
26
+ examples: [],
27
+ },
21
28
  implementation: () => {
22
29
  throw new Error('This command has not been implemented yet.');
23
30
  },
@@ -27,7 +34,7 @@ function createUnImplementedCommand(commandName) {
27
34
  };
28
35
  }
29
36
  function getUnsupportedFlags(currentFlags, flagSupport) {
30
- return (0, node_1.getObjectTypedKeys)(currentFlags).filter((currentFlag) => {
37
+ return (0, augment_vir_1.getObjectTypedKeys)(currentFlags).filter((currentFlag) => {
31
38
  if (currentFlags[currentFlag]) {
32
39
  return !flagSupport[currentFlag];
33
40
  }
@@ -44,39 +51,36 @@ exports.getUnsupportedFlags = getUnsupportedFlags;
44
51
  */
45
52
  exports.helpImplementation = {
46
53
  commandName: cli_command_name_1.CliCommandName.Help,
47
- description: cli_flags_1.flagDescriptions[cli_flags_1.CliFlagName.Help],
54
+ description: {
55
+ sections: [{ title: '', content: cli_flags_1.flagDescriptions[cli_flags_1.CliFlagName.Help] }],
56
+ examples: [],
57
+ },
48
58
  implementation: runHelpCommand,
49
59
  configFlagSupport: {
50
60
  [cli_flags_1.CliFlagName.NoWriteConfig]: false,
51
61
  },
52
62
  };
53
- function runHelpCommand({ stdoutCallback }) {
54
- const flagsMessage = (0, node_1.getEnumTypedValues)(cli_flags_1.CliFlagName)
63
+ function generateHelpMessage(syntax) {
64
+ const flagsMessage = (0, augment_vir_1.getEnumTypedValues)(cli_flags_1.CliFlagName)
55
65
  .sort()
56
66
  .map((flagName) => {
57
- return `${cli_color_1.Color.Bold}${cli_color_1.Color.Info} ${flagName}${cli_color_1.Color.Reset}: ${cli_flags_1.flagDescriptions[flagName].trim()}`;
67
+ return (0, description_printing_1.flagToHelpString)(flagName, cli_flags_1.flagDescriptions[flagName], syntax);
58
68
  })
59
- .join('\n ');
60
- const commandsMessage = (0, node_1.getEnumTypedValues)(cli_command_name_1.CliCommandName)
69
+ .join('\n');
70
+ const commandsMessage = (0, augment_vir_1.getEnumTypedValues)(cli_command_name_1.CliCommandName)
61
71
  .sort()
62
72
  .map((commandName) => {
63
- return `${cli_color_1.Color.Bold}${cli_color_1.Color.Info} ${commandName}${cli_color_1.Color.Reset}: ${exports.allCliCommands[commandName].description.trim()}`;
73
+ return (0, description_printing_1.commandToHelpString)(exports.allCliCommands[commandName], syntax);
64
74
  })
65
- .join('\n ');
66
- const helpMessage = `${cli_color_1.Color.Info} ${package_name_1.packageName} usage:${cli_color_1.Color.Reset}
67
- [npx] ${package_name_1.packageName} [--flags] command subCommand
68
-
69
- npx is needed when the command is run directly from the terminal
70
- (not scoped within an npm script) unless the package has been globally installed
71
- (which is not recommended).
72
-
73
- ${cli_color_1.Color.Info} available flags:${cli_color_1.Color.Reset}
74
- ${flagsMessage}
75
-
76
- ${cli_color_1.Color.Info} available commands:${cli_color_1.Color.Reset}
77
- ${commandsMessage}`;
78
- stdoutCallback(helpMessage);
75
+ .join('\n');
76
+ const helpMessage = (0, description_printing_1.combineHelpMessage)(flagsMessage, commandsMessage, syntax);
77
+ return helpMessage;
78
+ }
79
+ exports.generateHelpMessage = generateHelpMessage;
80
+ function runHelpCommand({ stdoutCallback }) {
81
+ stdoutCallback((0, description_printing_1.wrapLines)(generateHelpMessage(description_printing_1.MessageSyntax.Bash), 100));
79
82
  return {
83
+ command: undefined,
80
84
  success: true,
81
85
  };
82
86
  }
@@ -2,6 +2,7 @@ import { CliCommandName } from '../cli-util/cli-command-name';
2
2
  import { CliFlagName, CliFlags } from '../cli-util/cli-flags';
3
3
  import { CommandConfigKey } from '../config/config-key';
4
4
  export declare type CliCommandResult = {
5
+ command: string | undefined;
5
6
  success: boolean;
6
7
  };
7
8
  export declare function fillInCommandInput(commandInput?: PartialCommandFunctionInput | Partial<CommandFunctionInput>): Omit<CommandFunctionInput, 'stdoutCallback' | 'stderrCallback'>;
@@ -16,10 +17,18 @@ export declare const EmptyOutputCallbacks: Pick<CommandFunctionInput, 'stdoutCal
16
17
  export declare type PartialCommandFunctionInput = Omit<Partial<CommandFunctionInput>, 'cliFlags'> & {
17
18
  rawCliFlags?: Partial<Readonly<CliFlags>>;
18
19
  };
20
+ export declare type CliHelpSection = {
21
+ title: string;
22
+ content: string;
23
+ };
24
+ export declare type CliHelpDescription = {
25
+ sections: CliHelpSection[];
26
+ examples: CliHelpSection[];
27
+ };
19
28
  export declare type CliCommandImplementation = Readonly<{
20
29
  commandName: CliCommandName;
21
30
  configKeys?: CommandConfigKey[];
22
- description: string;
31
+ description: CliHelpDescription;
23
32
  implementation: CommandFunction;
24
33
  configFlagSupport: Readonly<Omit<Record<CliFlagName, boolean>, CliFlagName.Silent | CliFlagName.Help | CliFlagName.ExtendableConfig>>;
25
34
  }>;
@@ -28,7 +28,7 @@ function fillInCommandInput(commandInput) {
28
28
  }
29
29
  const rawCliFlags = extractRawFlags(commandInput);
30
30
  return {
31
- rawArgs: (commandInput === null || commandInput === void 0 ? void 0 : commandInput.rawArgs) || defaultCommandFunctionInput.rawArgs,
31
+ rawArgs: commandInput?.rawArgs || defaultCommandFunctionInput.rawArgs,
32
32
  cliFlags: (0, cli_flags_1.fillInCliFlags)(rawCliFlags),
33
33
  repoDir: commandInput.repoDir || defaultCommandFunctionInput.repoDir,
34
34
  };
@@ -0,0 +1,10 @@
1
+ import { CliCommandImplementation } from './cli-command';
2
+ export declare enum MessageSyntax {
3
+ Bash = "bash",
4
+ Markdown = "markdown"
5
+ }
6
+ 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 combineHelpMessage(flagsText: string, commandsText: string, syntax: MessageSyntax): string;
9
+ export declare function getIndent(line: string): string;
10
+ export declare function wrapLines(input: string, limit: number): string;