virmator 1.4.4 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cspell.json +1 -0
- package/.github/workflows/virmator-tests.yml +1 -1
- package/.prettierignore +3 -2
- package/README.md +159 -1
- package/dist/cli/cli-util/cli-color.js +5 -1
- package/dist/cli/cli-util/cli-flags.js +7 -10
- package/dist/cli/cli-util/get-all-command-output.d.ts +4 -3
- package/dist/cli/cli-util/shell-command-wrapper.d.ts +1 -1
- package/dist/cli/cli-util/shell-command-wrapper.js +2 -2
- package/dist/cli/cli-util/update-configs.js +6 -5
- package/dist/cli/cli.js +1 -1
- package/dist/cli/commands/all-cli-commands.d.ts +2 -0
- package/dist/cli/commands/all-cli-commands.js +31 -27
- package/dist/cli/commands/cli-command.d.ts +10 -1
- package/dist/cli/commands/cli-command.js +1 -1
- package/dist/cli/commands/description-printing.d.ts +10 -0
- package/dist/cli/commands/description-printing.js +149 -0
- package/dist/cli/commands/implementations/code-in-markdown.command.js +29 -22
- package/dist/cli/commands/implementations/compile.command.js +20 -8
- package/dist/cli/commands/implementations/format.command.js +54 -40
- package/dist/cli/commands/implementations/init.command.js +13 -4
- package/dist/cli/commands/implementations/spellcheck.command.js +10 -1
- package/dist/cli/commands/implementations/test.command.js +23 -26
- package/dist/cli/commands/implementations/update-all-configs.command.js +23 -14
- package/dist/cli/commands/implementations/update-bare-configs.command.js +23 -15
- package/dist/cli/commands/run-command.js +2 -3
- package/dist/cli/config/config-key.d.ts +9 -9
- package/dist/cli/config/config-key.js +4 -4
- package/dist/cli/config/config-paths.js +1 -1
- package/dist/cli/config/config-read.js +1 -2
- package/dist/cli/config/copy-config.js +3 -3
- package/dist/cli/config/create-default-package-json.js +2 -2
- package/dist/cli/config/extendable-config.js +3 -3
- package/dist/errors/cli-command-error.js +3 -3
- package/dist/errors/cli-flag-error.js +3 -3
- package/dist/errors/config-file-error.js +1 -4
- package/dist/exportable-jest-config/jest-config-path.d.ts +1 -0
- package/dist/exportable-jest-config/jest-config-path.js +6 -0
- package/dist/exportable-jest-config/separate-jest-configs/jest-config.d.ts +3 -0
- package/dist/exportable-jest-config/separate-jest-configs/jest-config.js +25 -0
- package/dist/exportable-jest-config/separate-jest-configs/jest-setup.d.ts +1 -0
- package/dist/exportable-jest-config/separate-jest-configs/jest-setup.js +11 -0
- package/dist/file-paths/virmator-repo-paths.js +4 -4
- package/dist/file-paths/{virmator-test-repos-paths.d.ts → virmator-test-file-paths.d.ts} +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/jest/jest-config.d.ts +3 -0
- package/dist/jest/jest-config.js +12 -0
- package/package.json +29 -23
- package/separate-configs/gitignore.txt +2 -0
- package/separate-configs/jest/jest-config.ts +26 -0
- package/separate-configs/jest/jest-setup.ts +12 -0
- package/separate-configs/npmignore.txt +7 -4
- package/tsconfig.json +13 -6
- package/dist/file-paths/virmator-test-repos-paths.js +0 -56
package/.cspell.json
CHANGED
package/.prettierignore
CHANGED
package/README.md
CHANGED
|
@@ -10,8 +10,166 @@ 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
|
-
#
|
|
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
|
+
PackageJson
|
|
142
|
+
Prettier
|
|
143
|
+
PrettierIgnore
|
|
144
|
+
TsConfig
|
|
145
|
+
GitAttributes
|
|
146
|
+
GitHubActionsPrerelease
|
|
147
|
+
GitHubActionsTaggedRelease
|
|
148
|
+
GitHubActionsTest
|
|
149
|
+
GitIgnore
|
|
150
|
+
NpmIgnore
|
|
151
|
+
VsCodeSettings
|
|
152
|
+
|
|
153
|
+
#### Examples
|
|
154
|
+
|
|
155
|
+
- update all config files: `virmator update-all-configs`
|
|
156
|
+
- update only Cspell and GitIgnore files: `virmator update-all-configs Cspell GitIgnore`
|
|
157
|
+
|
|
158
|
+
### update-bare-configs
|
|
159
|
+
|
|
160
|
+
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.
|
|
161
|
+
|
|
162
|
+
#### list of possible arguments:
|
|
163
|
+
|
|
164
|
+
GitAttributes
|
|
165
|
+
GitHubActionsPrerelease
|
|
166
|
+
GitHubActionsTaggedRelease
|
|
167
|
+
GitHubActionsTest
|
|
168
|
+
GitIgnore
|
|
169
|
+
NpmIgnore
|
|
170
|
+
VsCodeSettings
|
|
171
|
+
|
|
172
|
+
#### Examples
|
|
173
|
+
|
|
174
|
+
- update all bare config files: `virmator update-bare-configs`
|
|
175
|
+
- update only GitIgnore and NpmIgnore files: `virmator update-bare-configs GitIgnore NpmIgnore,`
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -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
|
|
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]: '
|
|
21
|
-
[CliFlagName.NoWriteConfig]: `
|
|
22
|
-
|
|
23
|
-
[CliFlagName.
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
|
5
|
-
const
|
|
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,
|
|
12
|
+
const inputConfigFiles = (0, augment_vir_1.filterToEnumValues)(commandInputs.rawArgs, configKeysEnum);
|
|
13
13
|
const configFilesToCopy = inputConfigFiles.length
|
|
14
14
|
? inputConfigFiles
|
|
15
|
-
: (0,
|
|
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,
|
|
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
|
|
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:
|
|
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,
|
|
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:
|
|
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
|
|
54
|
-
const flagsMessage = (0,
|
|
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
|
|
67
|
+
return (0, description_printing_1.flagToHelpString)(flagName, cli_flags_1.flagDescriptions[flagName], syntax);
|
|
58
68
|
})
|
|
59
|
-
.join('\n
|
|
60
|
-
const commandsMessage = (0,
|
|
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
|
|
73
|
+
return (0, description_printing_1.commandToHelpString)(exports.allCliCommands[commandName], syntax);
|
|
64
74
|
})
|
|
65
|
-
.join('\n
|
|
66
|
-
const helpMessage =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
(
|
|
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:
|
|
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:
|
|
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;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapLines = exports.getIndent = exports.combineHelpMessage = exports.commandToHelpString = exports.flagToHelpString = exports.MessageSyntax = void 0;
|
|
4
|
+
const augment_vir_1 = require("augment-vir");
|
|
5
|
+
const package_name_1 = require("../../package-name");
|
|
6
|
+
const cli_color_1 = require("../cli-util/cli-color");
|
|
7
|
+
var MessageSyntax;
|
|
8
|
+
(function (MessageSyntax) {
|
|
9
|
+
MessageSyntax["Bash"] = "bash";
|
|
10
|
+
MessageSyntax["Markdown"] = "markdown";
|
|
11
|
+
})(MessageSyntax = exports.MessageSyntax || (exports.MessageSyntax = {}));
|
|
12
|
+
const formatting = ((input) => input)({
|
|
13
|
+
h2: {
|
|
14
|
+
[MessageSyntax.Bash]: `${cli_color_1.Color.Info}`,
|
|
15
|
+
[MessageSyntax.Markdown]: '## ',
|
|
16
|
+
},
|
|
17
|
+
h3: {
|
|
18
|
+
[MessageSyntax.Bash]: `${cli_color_1.Color.Bold}${cli_color_1.Color.Info}`,
|
|
19
|
+
[MessageSyntax.Markdown]: '### ',
|
|
20
|
+
},
|
|
21
|
+
h4: {
|
|
22
|
+
[MessageSyntax.Bash]: ``,
|
|
23
|
+
[MessageSyntax.Markdown]: '#### ',
|
|
24
|
+
},
|
|
25
|
+
reset: {
|
|
26
|
+
[MessageSyntax.Bash]: `${cli_color_1.Color.Reset}`,
|
|
27
|
+
[MessageSyntax.Markdown]: '',
|
|
28
|
+
},
|
|
29
|
+
indent: {
|
|
30
|
+
[MessageSyntax.Bash]: ` `,
|
|
31
|
+
[MessageSyntax.Markdown]: '',
|
|
32
|
+
},
|
|
33
|
+
colon: {
|
|
34
|
+
[MessageSyntax.Bash]: `:`,
|
|
35
|
+
[MessageSyntax.Markdown]: '',
|
|
36
|
+
},
|
|
37
|
+
bullet: {
|
|
38
|
+
[MessageSyntax.Bash]: `- `,
|
|
39
|
+
[MessageSyntax.Markdown]: ' - ',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
function formatWithSyntax(key, syntax) {
|
|
43
|
+
return formatting[key][syntax];
|
|
44
|
+
}
|
|
45
|
+
function code(input, block, indent, syntax) {
|
|
46
|
+
if (syntax === MessageSyntax.Markdown) {
|
|
47
|
+
if (block) {
|
|
48
|
+
return `\n${indent}\`\`\`\n${indent}${input
|
|
49
|
+
.split('\n')
|
|
50
|
+
.join(`\n${indent}`)}\n${indent}\`\`\`\n`;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return `${indent}\`${input}\``;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return input;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function flagToHelpString(flagName, description, syntax) {
|
|
61
|
+
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()}`;
|
|
63
|
+
}
|
|
64
|
+
exports.flagToHelpString = flagToHelpString;
|
|
65
|
+
function commandToHelpString(command, syntax) {
|
|
66
|
+
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`;
|
|
70
|
+
}
|
|
71
|
+
exports.commandToHelpString = commandToHelpString;
|
|
72
|
+
function indent(input, syntax) {
|
|
73
|
+
return formatWithSyntax('indent', syntax).repeat(input);
|
|
74
|
+
}
|
|
75
|
+
function sectionToString(section, extraIndent, syntax, bullets) {
|
|
76
|
+
const format = (key) => formatWithSyntax(key, syntax);
|
|
77
|
+
const sectionIndent = indent(2 + extraIndent, syntax);
|
|
78
|
+
const separator = syntax === MessageSyntax.Bash || !bullets ? `:\n` : ': ';
|
|
79
|
+
const header = bullets ? '' : format('h4');
|
|
80
|
+
const title = section.title ? `${sectionIndent}${header}${section.title}${separator}` : '';
|
|
81
|
+
if (bullets && syntax === MessageSyntax.Markdown) {
|
|
82
|
+
return `${format('bullet')}${title}${code(section.content, section.content.includes('\n'), syntax === MessageSyntax.Markdown && section.content.includes('\n') ? ' ' : '', syntax)}`;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const contentIndent = section.title ? indent(3 + extraIndent, syntax) : sectionIndent;
|
|
86
|
+
return `${title}${contentIndent}${section.content.split('\n').join(`\n${contentIndent}`)}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function commandDescriptionToMessage(description, syntax) {
|
|
90
|
+
const format = (key) => formatWithSyntax(key, syntax);
|
|
91
|
+
const sections = description.sections
|
|
92
|
+
.map((section) => sectionToString(section, 0, syntax, false))
|
|
93
|
+
.join('\n\n');
|
|
94
|
+
const examples = description.examples
|
|
95
|
+
.map((example) => sectionToString(example, 1, syntax, true))
|
|
96
|
+
.join('\n');
|
|
97
|
+
const examplesTitle = description.examples.length
|
|
98
|
+
? `\n\n${indent(2, syntax)}${format('h4')}Examples${format('reset')}${format('colon')}\n`
|
|
99
|
+
: '';
|
|
100
|
+
return `${sections}${examplesTitle}${examples}`;
|
|
101
|
+
}
|
|
102
|
+
function combineHelpMessage(flagsText, commandsText, syntax) {
|
|
103
|
+
const format = (key) => formatWithSyntax(key, syntax);
|
|
104
|
+
return `${formatting.h2[syntax]}${package_name_1.packageName} usage${format('colon')}${format('reset')}
|
|
105
|
+
${format('indent')}${code(`[npx] ${package_name_1.packageName} [--flags] command subCommand`, true, '', syntax)}
|
|
106
|
+
|
|
107
|
+
${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
|
+
|
|
109
|
+
${format('h2')}available flags${format('colon')}${format('reset')}
|
|
110
|
+
${flagsText}
|
|
111
|
+
|
|
112
|
+
${format('h2')}available commands${format('colon')}${format('reset')}
|
|
113
|
+
${commandsText}`;
|
|
114
|
+
}
|
|
115
|
+
exports.combineHelpMessage = combineHelpMessage;
|
|
116
|
+
function getIndent(line) {
|
|
117
|
+
return (0, augment_vir_1.safeMatch)(line, /^(\s*)/)[0] ?? '';
|
|
118
|
+
}
|
|
119
|
+
exports.getIndent = getIndent;
|
|
120
|
+
function wrapLines(input, limit) {
|
|
121
|
+
const lines = input.split('\n');
|
|
122
|
+
// using a for loop because the length of the array will get modified while iterating through it
|
|
123
|
+
for (let index = 0; index < lines.length; index++) {
|
|
124
|
+
const line = lines[index];
|
|
125
|
+
if (line && line.length > limit) {
|
|
126
|
+
const nextIndex = index + 1;
|
|
127
|
+
const nextLine = lines[nextIndex] ?? '';
|
|
128
|
+
const newLine = line.slice(0, limit);
|
|
129
|
+
lines[index] = newLine.trimEnd();
|
|
130
|
+
let wrappedPart = line.slice(limit);
|
|
131
|
+
// didn't wrap on a space, we need to shift a word down
|
|
132
|
+
if (!newLine.endsWith(' ') && !wrappedPart.startsWith(' ')) {
|
|
133
|
+
const lastWord = (0, augment_vir_1.safeMatch)(newLine, /(\s\S+$)/)[0] ?? '';
|
|
134
|
+
lines[index] = newLine.slice(0, -1 * lastWord.length).trimEnd();
|
|
135
|
+
wrappedPart = `${lastWord}${wrappedPart.trim()}`;
|
|
136
|
+
}
|
|
137
|
+
const currentIndent = getIndent(line);
|
|
138
|
+
const nextIndent = getIndent(nextLine);
|
|
139
|
+
if (currentIndent === nextIndent) {
|
|
140
|
+
lines[nextIndex] = `${currentIndent}${wrappedPart.trim()} ${nextLine.trim()}`;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
lines.splice(nextIndex, 0, `${currentIndent}${wrappedPart.trim()}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return lines.join('\n').trimEnd();
|
|
148
|
+
}
|
|
149
|
+
exports.wrapLines = wrapLines;
|