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.
- package/.cspell.json +1 -0
- package/.github/workflows/virmator-prerelease.yml +9 -4
- package/.github/workflows/virmator-tests.yml +1 -1
- package/.prettierignore +3 -2
- package/README.md +161 -1
- package/dist/augments/ansi-regex.d.ts +1 -0
- package/dist/augments/ansi-regex.js +27 -0
- package/dist/augments/string.d.ts +1 -0
- package/dist/augments/string.js +8 -0
- 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 +30 -27
- 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 +13 -9
- package/dist/cli/config/config-key.js +6 -4
- package/dist/cli/config/config-paths.js +11 -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.d.ts +3 -0
- package/dist/exportable-jest-config/jest-config.js +23 -0
- package/dist/exportable-jest-config/jest-setup.d.ts +1 -0
- package/dist/exportable-jest-config/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 +13 -0
- package/package.json +29 -23
- package/separate-configs/gitignore.txt +2 -0
- package/separate-configs/jest/jest-config.ts +24 -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
|
@@ -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;
|
|
@@ -1,33 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runCodeInMarkdownCommand = exports.codeInMarkdownCommandImplementation = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_only_1 = require("augment-vir/dist/node-only");
|
|
5
5
|
const virmator_repo_paths_1 = require("../../../file-paths/virmator-repo-paths");
|
|
6
6
|
const cli_command_name_1 = require("../../cli-util/cli-command-name");
|
|
7
7
|
const cli_flags_1 = require("../../cli-util/cli-flags");
|
|
8
8
|
const shell_command_wrapper_1 = require("../../cli-util/shell-command-wrapper");
|
|
9
9
|
exports.codeInMarkdownCommandImplementation = {
|
|
10
10
|
commandName: cli_command_name_1.CliCommandName.CodeInMarkdown,
|
|
11
|
-
description:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
virmator ${cli_command_name_1.CliCommandName.CodeInMarkdown}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
virmator ${cli_command_name_1.CliCommandName.CodeInMarkdown}
|
|
30
|
-
|
|
11
|
+
description: {
|
|
12
|
+
sections: [
|
|
13
|
+
{
|
|
14
|
+
title: '',
|
|
15
|
+
content: `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 -->\``,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
title: '',
|
|
19
|
+
content: `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.`,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
examples: [
|
|
23
|
+
{
|
|
24
|
+
title: 'default experience (usually all you need)',
|
|
25
|
+
content: `virmator ${cli_command_name_1.CliCommandName.CodeInMarkdown}`,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
title: 'override files to check to a single file',
|
|
29
|
+
content: `virmator ${cli_command_name_1.CliCommandName.CodeInMarkdown} only/this/one/file.md`,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
title: 'override files to check to a group of files',
|
|
33
|
+
content: `virmator ${cli_command_name_1.CliCommandName.CodeInMarkdown} "only/this/dir/*.md"`,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
31
37
|
implementation: runCodeInMarkdownCommand,
|
|
32
38
|
configFlagSupport: {
|
|
33
39
|
[cli_flags_1.CliFlagName.NoWriteConfig]: false,
|
|
@@ -36,11 +42,12 @@ exports.codeInMarkdownCommandImplementation = {
|
|
|
36
42
|
const mdCodePath = (0, virmator_repo_paths_1.getNpmBinPath)('md-code');
|
|
37
43
|
async function runCodeInMarkdownCommand(inputs) {
|
|
38
44
|
const args = inputs.rawArgs.length
|
|
39
|
-
? (0,
|
|
45
|
+
? (0, node_only_1.interpolationSafeWindowsPath)(inputs.rawArgs.join(' '))
|
|
40
46
|
: `\"./**/*.md\"`;
|
|
41
47
|
const mdCodeCommand = `${mdCodePath} ${args}`;
|
|
42
48
|
const results = await (0, shell_command_wrapper_1.runVirmatorShellCommand)(mdCodeCommand, inputs);
|
|
43
49
|
return {
|
|
50
|
+
command: mdCodeCommand,
|
|
44
51
|
success: !results.error,
|
|
45
52
|
};
|
|
46
53
|
}
|
|
@@ -9,14 +9,25 @@ const shell_command_wrapper_1 = require("../../cli-util/shell-command-wrapper");
|
|
|
9
9
|
const config_key_1 = require("../../config/config-key");
|
|
10
10
|
exports.compileImplementation = {
|
|
11
11
|
commandName: cli_command_name_1.CliCommandName.Compile,
|
|
12
|
-
description:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
description: {
|
|
13
|
+
sections: [
|
|
14
|
+
{
|
|
15
|
+
title: '',
|
|
16
|
+
content: `compile typescript files
|
|
17
|
+
Pass any extra tsc flags to this command.`,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
examples: [
|
|
21
|
+
{
|
|
22
|
+
title: `no extra flags`,
|
|
23
|
+
content: `${package_name_1.packageName} ${cli_command_name_1.CliCommandName.Compile}`,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
title: `one extra flag`,
|
|
27
|
+
content: `${package_name_1.packageName} ${cli_command_name_1.CliCommandName.Compile} --noEmit`,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
20
31
|
implementation: runCompileCommand,
|
|
21
32
|
configKeys: [config_key_1.ConfigKey.TsConfig],
|
|
22
33
|
configFlagSupport: {
|
|
@@ -31,6 +42,7 @@ async function runCompileCommand(inputs) {
|
|
|
31
42
|
.join(' ')}`;
|
|
32
43
|
const results = await (0, shell_command_wrapper_1.runVirmatorShellCommand)(compileCommand, inputs);
|
|
33
44
|
return {
|
|
45
|
+
command: compileCommand,
|
|
34
46
|
success: !results.error,
|
|
35
47
|
};
|
|
36
48
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractFormatArgs = exports.runFormatCommand = exports.formatImplementation = exports.filesMarkerArg = exports.defaultFormatArgs = exports.FormatOperation = void 0;
|
|
4
|
-
const
|
|
4
|
+
const augment_vir_1 = require("augment-vir");
|
|
5
5
|
const virmator_repo_paths_1 = require("../../../file-paths/virmator-repo-paths");
|
|
6
6
|
const package_name_1 = require("../../../package-name");
|
|
7
7
|
const cli_command_name_1 = require("../../cli-util/cli-command-name");
|
|
@@ -31,42 +31,53 @@ exports.defaultFormatArgs = {
|
|
|
31
31
|
exports.filesMarkerArg = '--format-files';
|
|
32
32
|
exports.formatImplementation = {
|
|
33
33
|
commandName: cli_command_name_1.CliCommandName.Format,
|
|
34
|
-
description:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
and the "${exports.filesMarkerArg}" marker are treated as extra arguments to Prettier and
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
34
|
+
description: {
|
|
35
|
+
sections: [
|
|
36
|
+
{
|
|
37
|
+
title: '',
|
|
38
|
+
content: 'Formats source files with Prettier.',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
title: 'operation commands',
|
|
42
|
+
content: `This is optional but if provided it must come first. ${FormatOperation.Write} is the default.
|
|
43
|
+
${FormatOperation.Write}: overwrites files to fix formatting.
|
|
44
|
+
${FormatOperation.Check}: checks the formatting, does not write to files`,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
title: 'file extensions',
|
|
48
|
+
content: `If only specific file extensions should be formatted, add the "${exports.filesMarkerArg}" 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 ${FormatOperation.Write} is the default operation) only if they have the extension ".md" or ".json": ${package_name_1.packageName} ${cli_command_name_1.CliCommandName.Format} ${exports.filesMarkerArg} md json`,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
title: 'Prettier flags',
|
|
52
|
+
content: `Any other arguments encountered between the operation command (if provided) and the "${exports.filesMarkerArg}" marker are treated as extra arguments to Prettier and will be passed along.`,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
examples: [
|
|
56
|
+
{
|
|
57
|
+
title: 'checks formatting for files',
|
|
58
|
+
content: `${package_name_1.packageName} ${cli_command_name_1.CliCommandName.Format} ${FormatOperation.Check}`,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
title: 'checks formatting only for .md files',
|
|
62
|
+
content: `${package_name_1.packageName} ${cli_command_name_1.CliCommandName.Format} ${FormatOperation.Check} ${exports.filesMarkerArg} md`,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
title: 'checks formatting only for .md and .json files',
|
|
66
|
+
content: `${package_name_1.packageName} ${cli_command_name_1.CliCommandName.Format} ${FormatOperation.Check} ${exports.filesMarkerArg} md json`,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
title: 'fixes formatting for files',
|
|
70
|
+
content: `${package_name_1.packageName} ${cli_command_name_1.CliCommandName.Format}
|
|
71
|
+
${package_name_1.packageName} ${cli_command_name_1.CliCommandName.Format} ${FormatOperation.Write}`,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
title: `examples with extra Prettier flags`,
|
|
75
|
+
content: `${package_name_1.packageName} ${cli_command_name_1.CliCommandName.Format} --ignore-path .prettierignore
|
|
76
|
+
${package_name_1.packageName} ${cli_command_name_1.CliCommandName.Format} ${FormatOperation.Write} --ignore-path .prettierignore
|
|
77
|
+
${package_name_1.packageName} ${cli_command_name_1.CliCommandName.Format} ${FormatOperation.Write} --ignore-path .prettierignore ${exports.filesMarkerArg} md json`,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
70
81
|
configKeys: [
|
|
71
82
|
config_key_1.ConfigKey.Prettier,
|
|
72
83
|
config_key_1.ConfigKey.PrettierIgnore,
|
|
@@ -80,7 +91,9 @@ const prettierPath = (0, virmator_repo_paths_1.getNpmBinPath)('prettier');
|
|
|
80
91
|
async function runFormatCommand(inputs) {
|
|
81
92
|
const args = extractFormatArgs(inputs.rawArgs);
|
|
82
93
|
const operationFlag = args.operation === FormatOperation.Check ? '--check' : '--write';
|
|
83
|
-
const
|
|
94
|
+
const fileExtensions = `\"./**/*.+(${args.fileExtensions.join('|')})\"`;
|
|
95
|
+
const hasNonFlags = args.prettierFlags.some((flag) => !flag.startsWith('-'));
|
|
96
|
+
const prettierCommand = `${prettierPath} --color ${args.prettierFlags.join(' ')} ${hasNonFlags ? '' : fileExtensions} ${operationFlag}`;
|
|
84
97
|
const results = await (0, shell_command_wrapper_1.runVirmatorShellCommand)(prettierCommand, inputs, {
|
|
85
98
|
stdoutFilter: (stdout) => stdout
|
|
86
99
|
// only relevant when running the check command
|
|
@@ -89,17 +102,18 @@ async function runFormatCommand(inputs) {
|
|
|
89
102
|
.replace('All matched files use Prettier code style!\n', ''),
|
|
90
103
|
});
|
|
91
104
|
return {
|
|
105
|
+
command: prettierCommand,
|
|
92
106
|
success: !results.error,
|
|
93
107
|
};
|
|
94
108
|
}
|
|
95
109
|
exports.runFormatCommand = runFormatCommand;
|
|
96
110
|
function extractFormatArgs(rawArgs) {
|
|
97
111
|
let addingFileExtensions = false;
|
|
98
|
-
const operation = (0,
|
|
112
|
+
const operation = (0, augment_vir_1.isEnumValue)(rawArgs[0], FormatOperation)
|
|
99
113
|
? rawArgs[0]
|
|
100
114
|
: FormatOperation.Write;
|
|
101
115
|
const extractedArgs = rawArgs.reduce((accum, currentRawArg, index) => {
|
|
102
|
-
if (index === 0 && (0,
|
|
116
|
+
if (index === 0 && (0, augment_vir_1.isEnumValue)(rawArgs[index], FormatOperation)) {
|
|
103
117
|
return accum;
|
|
104
118
|
}
|
|
105
119
|
else if (currentRawArg === exports.filesMarkerArg) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runInitCommand = exports.initCommandImplementation = void 0;
|
|
4
|
-
const
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
5
|
const cli_command_name_1 = require("../../cli-util/cli-command-name");
|
|
6
6
|
const cli_flags_1 = require("../../cli-util/cli-flags");
|
|
7
7
|
const config_key_1 = require("../../config/config-key");
|
|
@@ -11,9 +11,17 @@ const format_command_1 = require("./format.command");
|
|
|
11
11
|
const update_all_configs_command_1 = require("./update-all-configs.command");
|
|
12
12
|
exports.initCommandImplementation = {
|
|
13
13
|
commandName: cli_command_name_1.CliCommandName.Test,
|
|
14
|
-
description:
|
|
14
|
+
description: {
|
|
15
|
+
sections: [
|
|
16
|
+
{
|
|
17
|
+
title: '',
|
|
18
|
+
content: `Init everything, including package.json scripts.
|
|
15
19
|
If no package.json file is found, one is created and initialized.
|
|
16
20
|
Pass --force to this command to overwrite current package.json scripts.`,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
examples: [],
|
|
24
|
+
},
|
|
17
25
|
implementation: runInitCommand,
|
|
18
26
|
configFlagSupport: {
|
|
19
27
|
[cli_flags_1.CliFlagName.NoWriteConfig]: true,
|
|
@@ -35,12 +43,13 @@ async function runInitCommand(inputs) {
|
|
|
35
43
|
error = catchError;
|
|
36
44
|
}
|
|
37
45
|
return {
|
|
46
|
+
command: undefined,
|
|
38
47
|
success: !error,
|
|
39
48
|
};
|
|
40
49
|
}
|
|
41
50
|
exports.runInitCommand = runInitCommand;
|
|
42
51
|
async function updatePackageJson(repoDir) {
|
|
43
52
|
const repoPackageJsonPath = (0, config_paths_1.getRepoConfigFilePath)(config_key_1.ConfigKey.PackageJson, false);
|
|
44
|
-
const finalPackageJsonContents = (0, config_read_1.readUpdatedVirmatorConfigFile)(config_key_1.ConfigKey.PackageJson, repoDir, false);
|
|
45
|
-
await (0,
|
|
53
|
+
const finalPackageJsonContents = await (0, config_read_1.readUpdatedVirmatorConfigFile)(config_key_1.ConfigKey.PackageJson, repoDir, false);
|
|
54
|
+
await (0, promises_1.writeFile)(repoPackageJsonPath, finalPackageJsonContents);
|
|
46
55
|
}
|
|
@@ -8,7 +8,15 @@ const shell_command_wrapper_1 = require("../../cli-util/shell-command-wrapper");
|
|
|
8
8
|
const config_key_1 = require("../../config/config-key");
|
|
9
9
|
exports.spellcheckCommandImplementation = {
|
|
10
10
|
commandName: cli_command_name_1.CliCommandName.SpellCheck,
|
|
11
|
-
description:
|
|
11
|
+
description: {
|
|
12
|
+
sections: [
|
|
13
|
+
{
|
|
14
|
+
title: '',
|
|
15
|
+
content: `Spellcheck code with cspell. Any extra arguments are passed directly to cspell.`,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
examples: [],
|
|
19
|
+
},
|
|
12
20
|
implementation: runSpellcheckCommand,
|
|
13
21
|
configKeys: [config_key_1.ConfigKey.Cspell],
|
|
14
22
|
configFlagSupport: {
|
|
@@ -20,6 +28,7 @@ async function runSpellcheckCommand(inputs) {
|
|
|
20
28
|
const spellcheckCommand = `${cSpellPath} --color "{*,.*,**/{.*,*}/**/{.*,*}}" ${inputs.rawArgs.join(' ')}`;
|
|
21
29
|
const results = await (0, shell_command_wrapper_1.runVirmatorShellCommand)(spellcheckCommand, inputs);
|
|
22
30
|
return {
|
|
31
|
+
command: spellcheckCommand,
|
|
23
32
|
success: !results.error,
|
|
24
33
|
};
|
|
25
34
|
}
|
|
@@ -1,45 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runTestCommand = exports.testCommandImplementation = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_only_1 = require("augment-vir/dist/node-only");
|
|
5
|
+
const config_key_1 = require("../../../cli/config/config-key");
|
|
6
|
+
const config_paths_1 = require("../../../cli/config/config-paths");
|
|
5
7
|
const virmator_repo_paths_1 = require("../../../file-paths/virmator-repo-paths");
|
|
6
8
|
const cli_command_name_1 = require("../../cli-util/cli-command-name");
|
|
7
9
|
const cli_flags_1 = require("../../cli-util/cli-flags");
|
|
8
10
|
const shell_command_wrapper_1 = require("../../cli-util/shell-command-wrapper");
|
|
9
|
-
const compile_command_1 = require("./compile.command");
|
|
10
11
|
exports.testCommandImplementation = {
|
|
11
12
|
commandName: cli_command_name_1.CliCommandName.Test,
|
|
12
|
-
description:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
description: {
|
|
14
|
+
sections: [
|
|
15
|
+
{
|
|
16
|
+
title: '',
|
|
17
|
+
content: `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.`,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
examples: [
|
|
21
|
+
{ title: '', content: `virmator test ./path/to/single/file.js` },
|
|
22
|
+
{ title: '', content: `virmator test "./**/single-file.js"` },
|
|
23
|
+
{ title: '', content: `virmator test "./dist/**/!(*.type).test.js"` },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
22
26
|
implementation: runTestCommand,
|
|
27
|
+
configKeys: [
|
|
28
|
+
config_key_1.CommandConfigKey.JestSetup,
|
|
29
|
+
config_key_1.CommandConfigKey.JestConfig,
|
|
30
|
+
],
|
|
23
31
|
configFlagSupport: {
|
|
24
|
-
[cli_flags_1.CliFlagName.NoWriteConfig]:
|
|
32
|
+
[cli_flags_1.CliFlagName.NoWriteConfig]: true,
|
|
25
33
|
},
|
|
26
34
|
};
|
|
27
|
-
const
|
|
35
|
+
const jestPath = (0, virmator_repo_paths_1.getNpmBinPath)('jest');
|
|
28
36
|
async function runTestCommand(inputs) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const testCommand = `${testVirPath} ${args}`;
|
|
37
|
-
const results = await (0, shell_command_wrapper_1.runVirmatorShellCommand)(testCommand, inputs, {
|
|
38
|
-
stdoutFilter: (logString) =>
|
|
39
|
-
// weird looking hex codes here are for color codes from test-vir
|
|
40
|
-
logString.replace('\x1B[1m\x1B[32mAll tests passed.\x1B[0m\n', ''),
|
|
41
|
-
});
|
|
37
|
+
const args = inputs.rawArgs.length ? inputs.rawArgs.join(' ') : '';
|
|
38
|
+
const defaultConfigPath = (0, config_paths_1.getRepoConfigFilePath)(config_key_1.CommandConfigKey.JestConfig, false);
|
|
39
|
+
const configPath = args.includes('--config ') || args.includes('-c ')
|
|
40
|
+
? ''
|
|
41
|
+
: `--config ${(0, node_only_1.interpolationSafeWindowsPath)(defaultConfigPath)}`;
|
|
42
|
+
const testCommand = `${jestPath} --colors ${configPath} ${args}`;
|
|
43
|
+
const results = await (0, shell_command_wrapper_1.runVirmatorShellCommand)(testCommand, inputs);
|
|
42
44
|
return {
|
|
45
|
+
command: testCommand,
|
|
43
46
|
success: !results.error,
|
|
44
47
|
};
|
|
45
48
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runUpdateAllConfigsCommand = exports.updateAllConfigsCommandImplementation = void 0;
|
|
4
|
-
const
|
|
4
|
+
const augment_vir_1 = require("augment-vir");
|
|
5
5
|
const package_name_1 = require("../../../package-name");
|
|
6
6
|
const cli_command_name_1 = require("../../cli-util/cli-command-name");
|
|
7
7
|
const cli_flags_1 = require("../../cli-util/cli-flags");
|
|
@@ -13,19 +13,28 @@ const exampleFlags = [
|
|
|
13
13
|
];
|
|
14
14
|
exports.updateAllConfigsCommandImplementation = {
|
|
15
15
|
commandName: cli_command_name_1.CliCommandName.UpdateAllConfigs,
|
|
16
|
-
description:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
description: {
|
|
17
|
+
sections: [
|
|
18
|
+
{
|
|
19
|
+
title: '',
|
|
20
|
+
content: `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.`,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
title: 'list of possible arguments',
|
|
24
|
+
content: (0, augment_vir_1.getEnumTypedValues)(config_key_1.ConfigKey).join('\n'),
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
examples: [
|
|
28
|
+
{
|
|
29
|
+
title: `update all config files`,
|
|
30
|
+
content: `${package_name_1.packageName} ${cli_command_name_1.CliCommandName.UpdateAllConfigs}`,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
title: `update only ${(0, augment_vir_1.joinWithFinalConjunction)(exampleFlags)} files`,
|
|
34
|
+
content: `${package_name_1.packageName} ${cli_command_name_1.CliCommandName.UpdateAllConfigs} ${exampleFlags.join(' ')}`,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
29
38
|
implementation: runUpdateAllConfigsCommand,
|
|
30
39
|
configFlagSupport: {
|
|
31
40
|
[cli_flags_1.CliFlagName.NoWriteConfig]: false,
|