virmator 1.3.1 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/.cspell.json +1 -0
  2. package/.github/workflows/virmator-prerelease.yml +43 -0
  3. package/dist/cli/cli-util/cli-command-name.d.ts +1 -0
  4. package/dist/cli/cli-util/cli-command-name.js +1 -0
  5. package/dist/cli/cli-util/get-all-command-output.d.ts +6 -0
  6. package/dist/cli/cli-util/get-all-command-output.js +21 -0
  7. package/dist/cli/cli-util/shell-command-wrapper.d.ts +8 -0
  8. package/dist/cli/cli-util/shell-command-wrapper.js +25 -0
  9. package/dist/cli/cli-util/update-configs.d.ts +2 -3
  10. package/dist/cli/cli-util/update-configs.js +19 -33
  11. package/dist/cli/cli.js +2 -6
  12. package/dist/cli/commands/all-cli-commands.d.ts +2 -2
  13. package/dist/cli/commands/all-cli-commands.js +4 -4
  14. package/dist/cli/commands/cli-command.d.ts +4 -6
  15. package/dist/cli/commands/cli-command.js +5 -1
  16. package/dist/cli/commands/implementations/code-in-markdown.command.d.ts +3 -0
  17. package/dist/cli/commands/implementations/code-in-markdown.command.js +47 -0
  18. package/dist/cli/commands/implementations/compile.command.d.ts +1 -1
  19. package/dist/cli/commands/implementations/compile.command.js +5 -12
  20. package/dist/cli/commands/implementations/format.command.d.ts +1 -1
  21. package/dist/cli/commands/implementations/format.command.js +6 -9
  22. package/dist/cli/commands/implementations/init.command.d.ts +1 -1
  23. package/dist/cli/commands/implementations/init.command.js +8 -7
  24. package/dist/cli/commands/implementations/spellcheck.command.d.ts +1 -1
  25. package/dist/cli/commands/implementations/spellcheck.command.js +4 -15
  26. package/dist/cli/commands/implementations/test.command.d.ts +1 -1
  27. package/dist/cli/commands/implementations/test.command.js +6 -12
  28. package/dist/cli/commands/implementations/update-all-configs.command.d.ts +1 -1
  29. package/dist/cli/commands/implementations/update-all-configs.command.js +2 -2
  30. package/dist/cli/commands/implementations/update-bare-configs.command.d.ts +1 -1
  31. package/dist/cli/commands/implementations/update-bare-configs.command.js +2 -2
  32. package/dist/cli/commands/run-command.js +18 -16
  33. package/dist/cli/config/config-key.d.ts +4 -0
  34. package/dist/cli/config/config-key.js +2 -0
  35. package/dist/cli/config/config-paths.js +2 -0
  36. package/package.json +14 -9
package/.cspell.json CHANGED
@@ -13,6 +13,7 @@
13
13
  "accum",
14
14
  "adipiscing",
15
15
  "amet",
16
+ "andymckay",
16
17
  "argb",
17
18
  "autofix",
18
19
  "autofixable",
@@ -0,0 +1,43 @@
1
+ name: branch-prerelease
2
+
3
+ on:
4
+ workflow_run:
5
+ workflows: ['tests']
6
+ branches: '**'
7
+ types:
8
+ - completed
9
+
10
+ jobs:
11
+ package-release:
12
+ name: 'package release'
13
+ runs-on: 'ubuntu-latest'
14
+ if: ${{ github.event.workflow_run.conclusion == 'success' }}
15
+ steps:
16
+ - uses: actions/checkout@v1
17
+ - name: Use Node.js 14.x
18
+ uses: actions/setup-node@v1
19
+ with:
20
+ node-version: 14.x
21
+ - name: run test
22
+ run: |
23
+ npm ci
24
+ npm run test:full
25
+ - name: pack and set vars
26
+ id: vars
27
+ run: |
28
+ branchName="${GITHUB_REF#refs/*/}"
29
+ echo ::set-output name=short_ref::"$branchName"
30
+
31
+ originalTarName="$(npm pack)"
32
+ packageName="$(npm -s run env echo '$npm_package_name')"
33
+ timeStamp="$(date +%s)"
34
+ newTarName="$packageName-$timeStamp.tgz"
35
+ mv "$originalTarName" "$newTarName"
36
+ echo ::set-output name=tar_name::"$newTarName"
37
+ - uses: 'marvinpinto/action-automatic-releases@latest'
38
+ with:
39
+ repo_token: '${{ secrets.GITHUB_TOKEN }}'
40
+ automatic_release_tag: 'prerelease-${{ steps.vars.outputs.short_ref }}'
41
+ prerelease: true
42
+ files: |
43
+ ${{ steps.vars.outputs.tar_name }}
@@ -5,6 +5,7 @@ export declare enum CliCommandName {
5
5
  Init = "init",
6
6
  SpellCheck = "spellcheck",
7
7
  Test = "test",
8
+ CodeInMarkdown = "code-in-markdown",
8
9
  UpdateAllConfigs = "update-all-configs",
9
10
  UpdateBareConfigs = "update-bare-configs"
10
11
  }
@@ -9,6 +9,7 @@ var CliCommandName;
9
9
  CliCommandName["Init"] = "init";
10
10
  CliCommandName["SpellCheck"] = "spellcheck";
11
11
  CliCommandName["Test"] = "test";
12
+ CliCommandName["CodeInMarkdown"] = "code-in-markdown";
12
13
  CliCommandName["UpdateAllConfigs"] = "update-all-configs";
13
14
  CliCommandName["UpdateBareConfigs"] = "update-bare-configs";
14
15
  })(CliCommandName = exports.CliCommandName || (exports.CliCommandName = {}));
@@ -0,0 +1,6 @@
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<{
4
+ stderr: string;
5
+ stdout: string;
6
+ } & CliCommandResult>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAllCommandOutput = void 0;
4
+ /** This is for testing purposes only. */
5
+ async function getAllCommandOutput(commandImplementation, inputs) {
6
+ const logs = {
7
+ stderr: [],
8
+ stdout: [],
9
+ };
10
+ const result = await commandImplementation({
11
+ ...inputs,
12
+ stderrCallback: (stderr) => logs.stderr.push(stderr),
13
+ stdoutCallback: (stdout) => logs.stdout.push(stdout),
14
+ });
15
+ return {
16
+ stdout: logs.stdout.join(''),
17
+ stderr: logs.stderr.join(''),
18
+ ...result,
19
+ };
20
+ }
21
+ exports.getAllCommandOutput = getAllCommandOutput;
@@ -0,0 +1,8 @@
1
+ import { ShellOutput } from 'augment-vir/dist/node';
2
+ import { CommandFunctionInput } from '../commands/cli-command';
3
+ export declare type OutputFilter = (toPrint: string) => string;
4
+ export declare type Filters = {
5
+ stdoutFilter: OutputFilter;
6
+ stderrFilter: OutputFilter;
7
+ };
8
+ export declare function runVirmatorShellCommand(command: string, { repoDir: cwd, stdoutCallback, stderrCallback, }: Pick<CommandFunctionInput, 'repoDir' | 'stdoutCallback' | 'stderrCallback'>, { stdoutFilter, stderrFilter }?: Partial<Filters>): Promise<ShellOutput>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runVirmatorShellCommand = void 0;
4
+ const node_1 = require("augment-vir/dist/node");
5
+ const defaultFilter = (input) => input;
6
+ function outputWrapper(callback, filter) {
7
+ return (input) => {
8
+ const stringInput = input.toString();
9
+ if (filter(stringInput)) {
10
+ callback(stringInput);
11
+ }
12
+ };
13
+ }
14
+ async function runVirmatorShellCommand(command, { repoDir: cwd, stdoutCallback, stderrCallback, }, { stdoutFilter = defaultFilter, stderrFilter = defaultFilter } = {
15
+ stdoutFilter: defaultFilter,
16
+ stderrFilter: defaultFilter,
17
+ }) {
18
+ const shellResults = await (0, node_1.runShellCommand)(command, {
19
+ cwd,
20
+ stdoutCallback: outputWrapper(stdoutCallback, stdoutFilter),
21
+ stderrCallback: outputWrapper(stderrCallback, stderrFilter),
22
+ });
23
+ return shellResults;
24
+ }
25
+ exports.runVirmatorShellCommand = runVirmatorShellCommand;
@@ -1,4 +1,3 @@
1
- import { CliCommandResult } from '../commands/cli-command';
1
+ import { CliCommandResult, CommandFunctionInput } from '../commands/cli-command';
2
2
  import { ConfigKey } from '../config/config-key';
3
- import { CliFlags } from './cli-flags';
4
- export declare function updateConfigs<T extends ConfigKey>(rawArgs: string[], cliFlags: Required<Readonly<CliFlags>>, configKeysEnum: Record<string, T>, repoDir: string): Promise<CliCommandResult>;
3
+ export declare function updateConfigs<T extends ConfigKey>(configKeysEnum: Record<string, T>, commandInputs: CommandFunctionInput): Promise<CliCommandResult>;
@@ -3,65 +3,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateConfigs = void 0;
4
4
  const node_1 = require("augment-vir/dist/node");
5
5
  const fs_extra_1 = require("fs-extra");
6
+ const cli_command_1 = require("../commands/cli-command");
6
7
  const format_command_1 = require("../commands/implementations/format.command");
7
8
  const copy_config_1 = require("../config/copy-config");
8
9
  const extendable_config_1 = require("../config/extendable-config");
9
10
  const cli_flags_1 = require("./cli-flags");
10
- async function updateConfigs(rawArgs, cliFlags, configKeysEnum, repoDir) {
11
- const inputConfigFiles = (0, node_1.filterToEnumValues)(rawArgs, configKeysEnum);
11
+ async function updateConfigs(configKeysEnum, commandInputs) {
12
+ const inputConfigFiles = (0, node_1.filterToEnumValues)(commandInputs.rawArgs, configKeysEnum);
12
13
  const configFilesToCopy = inputConfigFiles.length
13
14
  ? inputConfigFiles
14
15
  : (0, node_1.getEnumTypedValues)(configKeysEnum);
16
+ let writtenFileCount = 0;
15
17
  const errors = [];
16
- const writtenFiles = [];
17
- const failedFiles = [];
18
18
  await Promise.all(configFilesToCopy.map(async (configKey) => {
19
19
  try {
20
20
  const { outputFilePath, didWrite } = await (0, copy_config_1.copyConfig)({
21
21
  configKey,
22
- forceExtendableConfig: cliFlags[cli_flags_1.CliFlagName.ExtendableConfig] && (0, extendable_config_1.isExtendableConfig)(configKey),
23
- repoDir,
22
+ forceExtendableConfig: commandInputs.cliFlags[cli_flags_1.CliFlagName.ExtendableConfig] &&
23
+ (0, extendable_config_1.isExtendableConfig)(configKey),
24
+ repoDir: commandInputs.repoDir,
24
25
  });
25
26
  if (!(0, fs_extra_1.existsSync)(outputFilePath)) {
26
27
  throw new Error(`Tried to write config file but it didn't actually get written: ${outputFilePath}`);
27
28
  }
28
29
  if (didWrite) {
29
- writtenFiles.push({
30
- key: configKey,
31
- path: outputFilePath,
30
+ await (0, format_command_1.runFormatCommand)({
31
+ rawArgs: [outputFilePath],
32
+ cliFlags: commandInputs.cliFlags,
33
+ repoDir: commandInputs.repoDir,
34
+ ...cli_command_1.EmptyOutputCallbacks,
32
35
  });
36
+ writtenFileCount++;
37
+ commandInputs.stdoutCallback(`Wrote ${configKey} to ${outputFilePath}`);
33
38
  }
34
39
  }
35
40
  catch (error) {
36
41
  errors.push(error);
37
- failedFiles.push(configKey);
42
+ commandInputs.stderrCallback(`Failed to write config file for ${configKey}`);
43
+ commandInputs.stderrCallback(String(error));
38
44
  }
39
45
  }));
40
- // only format the newly updated config files
41
- const filePaths = writtenFiles.map((writtenFile) => writtenFile.path);
42
- await (0, format_command_1.runFormatCommand)({ rawArgs: filePaths, cliFlags, repoDir });
46
+ if (!errors.length && !writtenFileCount) {
47
+ commandInputs.stdoutCallback('All configs up to date.');
48
+ }
43
49
  return {
44
- stdout: writtenFiles.length
45
- ? writtenFiles
46
- .map((writtenFile) => {
47
- return `Wrote ${writtenFile.key} to ${writtenFile.path}`;
48
- })
49
- .join('\n')
50
- : 'All configs up to date.',
51
- stderr: failedFiles
52
- .map((failedFile) => {
53
- return `Failed to write config file for ${failedFile}`;
54
- })
55
- .join('\n'),
56
50
  success: !errors.length,
57
- error: errors.length
58
- ? new Error(`Failed to write config files for the following reasons: ${errors
59
- .map((error, index) => {
60
- return `${failedFiles[index]} failed: ${String(error)}`;
61
- })
62
- .join('\n')}`)
63
- : undefined,
64
- printCommandResult: true,
65
51
  };
66
52
  }
67
53
  exports.updateConfigs = updateConfigs;
package/dist/cli/cli.js CHANGED
@@ -9,7 +9,6 @@ const cli_flags_1 = require("./cli-util/cli-flags");
9
9
  const cli_messages_1 = require("./cli-util/cli-messages");
10
10
  const run_command_1 = require("./commands/run-command");
11
11
  async function cli(rawArgs) {
12
- var _a;
13
12
  try {
14
13
  const { flags, invalidFlags, args, command } = (0, cli_flags_1.extractArguments)(rawArgs);
15
14
  if (invalidFlags.length) {
@@ -26,13 +25,10 @@ async function cli(rawArgs) {
26
25
  rawArgs: args,
27
26
  rawCliFlags: flags,
28
27
  });
29
- const exitCode = (_a = commandResult.exitCode) !== null && _a !== void 0 ? _a : (commandResult.success ? 0 : 1);
30
- if (cliCommand !== cli_command_name_1.CliCommandName.Help &&
31
- !flags[cli_flags_1.CliFlagName.Silent] &&
32
- commandResult.printCommandResult) {
28
+ if (cliCommand !== cli_command_name_1.CliCommandName.Help && !flags[cli_flags_1.CliFlagName.Silent]) {
33
29
  console.info((0, cli_messages_1.getResultMessage)(cliCommand, commandResult.success));
34
30
  }
35
- process.exit(exitCode);
31
+ process.exit(commandResult.success ? 0 : 1);
36
32
  }
37
33
  catch (error) {
38
34
  console.error(String(error));
@@ -1,11 +1,11 @@
1
1
  import { CliCommandName } from '../cli-util/cli-command-name';
2
2
  import { CliFlagName, CliFlags } from '../cli-util/cli-flags';
3
- import { CliCommandImplementation, CliCommandResult } from './cli-command';
3
+ import { CliCommandImplementation, CliCommandResult, CommandFunctionInput } from './cli-command';
4
4
  export declare function getUnsupportedFlags(currentFlags: CliFlags, flagSupport: Record<CliFlagName, boolean>): CliFlagName[];
5
5
  /**
6
6
  * The Help command implementation is in this file because it both depends on allCliCommands and is
7
7
  * depended on by allCliCommands.
8
8
  */
9
9
  export declare const helpImplementation: CliCommandImplementation;
10
- export declare function runHelpCommand(): CliCommandResult;
10
+ export declare function runHelpCommand({ stdoutCallback }: CommandFunctionInput): CliCommandResult;
11
11
  export declare const allCliCommands: Readonly<Record<CliCommandName, CliCommandImplementation>>;
@@ -6,6 +6,7 @@ const package_name_1 = require("../../package-name");
6
6
  const cli_color_1 = require("../cli-util/cli-color");
7
7
  const cli_command_name_1 = require("../cli-util/cli-command-name");
8
8
  const cli_flags_1 = require("../cli-util/cli-flags");
9
+ const code_in_markdown_command_1 = require("./implementations/code-in-markdown.command");
9
10
  const compile_command_1 = require("./implementations/compile.command");
10
11
  const format_command_1 = require("./implementations/format.command");
11
12
  const init_command_1 = require("./implementations/init.command");
@@ -49,7 +50,7 @@ exports.helpImplementation = {
49
50
  [cli_flags_1.CliFlagName.NoWriteConfig]: false,
50
51
  },
51
52
  };
52
- function runHelpCommand() {
53
+ function runHelpCommand({ stdoutCallback }) {
53
54
  const flagsMessage = (0, node_1.getEnumTypedValues)(cli_flags_1.CliFlagName)
54
55
  .sort()
55
56
  .map((flagName) => {
@@ -74,11 +75,9 @@ function runHelpCommand() {
74
75
 
75
76
  ${cli_color_1.Color.Info} available commands:${cli_color_1.Color.Reset}
76
77
  ${commandsMessage}`;
78
+ stdoutCallback(helpMessage);
77
79
  return {
78
80
  success: true,
79
- stdout: helpMessage,
80
- stderr: '',
81
- printCommandResult: true,
82
81
  };
83
82
  }
84
83
  exports.runHelpCommand = runHelpCommand;
@@ -92,4 +91,5 @@ exports.allCliCommands = {
92
91
  [cli_command_name_1.CliCommandName.Test]: test_command_1.testCommandImplementation,
93
92
  [cli_command_name_1.CliCommandName.UpdateAllConfigs]: update_all_configs_command_1.updateAllConfigsCommandImplementation,
94
93
  [cli_command_name_1.CliCommandName.UpdateBareConfigs]: update_bare_configs_command_1.updateBareConfigsCommandImplementation,
94
+ [cli_command_name_1.CliCommandName.CodeInMarkdown]: code_in_markdown_command_1.codeInMarkdownCommandImplementation,
95
95
  };
@@ -3,18 +3,16 @@ import { CliFlagName, CliFlags } from '../cli-util/cli-flags';
3
3
  import { CommandConfigKey } from '../config/config-key';
4
4
  export declare type CliCommandResult = {
5
5
  success: boolean;
6
- stdout?: string | undefined;
7
- stderr?: string | undefined;
8
- error?: unknown | undefined;
9
- exitCode?: number;
10
- printCommandResult: boolean;
11
6
  };
12
- export declare function fillInCommandInput(commandInput?: PartialCommandFunctionInput | Partial<CommandFunctionInput>): CommandFunctionInput;
7
+ export declare function fillInCommandInput(commandInput?: PartialCommandFunctionInput | Partial<CommandFunctionInput>): Omit<CommandFunctionInput, 'stdoutCallback' | 'stderrCallback'>;
13
8
  export declare type CommandFunctionInput = Readonly<{
14
9
  rawArgs: string[];
15
10
  cliFlags: Required<Readonly<CliFlags>>;
16
11
  repoDir: string;
12
+ stdoutCallback: (stdout: string) => void;
13
+ stderrCallback: (stderr: string) => void;
17
14
  }>;
15
+ export declare const EmptyOutputCallbacks: Pick<CommandFunctionInput, 'stdoutCallback' | 'stderrCallback'>;
18
16
  export declare type PartialCommandFunctionInput = Omit<Partial<CommandFunctionInput>, 'cliFlags'> & {
19
17
  rawCliFlags?: Partial<Readonly<CliFlags>>;
20
18
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fillInCommandInput = void 0;
3
+ exports.EmptyOutputCallbacks = exports.fillInCommandInput = void 0;
4
4
  const repo_paths_1 = require("../../file-paths/repo-paths");
5
5
  const cli_flags_1 = require("../cli-util/cli-flags");
6
6
  function extractRawFlags(commandInput) {
@@ -34,3 +34,7 @@ function fillInCommandInput(commandInput) {
34
34
  };
35
35
  }
36
36
  exports.fillInCommandInput = fillInCommandInput;
37
+ exports.EmptyOutputCallbacks = {
38
+ stdoutCallback: () => { },
39
+ stderrCallback: () => { },
40
+ };
@@ -0,0 +1,3 @@
1
+ import { CliCommandImplementation, CliCommandResult, CommandFunctionInput } from '../cli-command';
2
+ export declare const codeInMarkdownCommandImplementation: CliCommandImplementation;
3
+ export declare function runCodeInMarkdownCommand(inputs: CommandFunctionInput): Promise<CliCommandResult>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCodeInMarkdownCommand = exports.codeInMarkdownCommandImplementation = void 0;
4
+ const node_1 = require("augment-vir/dist/node");
5
+ const virmator_repo_paths_1 = require("../../../file-paths/virmator-repo-paths");
6
+ const cli_command_name_1 = require("../../cli-util/cli-command-name");
7
+ const cli_flags_1 = require("../../cli-util/cli-flags");
8
+ const shell_command_wrapper_1 = require("../../cli-util/shell-command-wrapper");
9
+ exports.codeInMarkdownCommandImplementation = {
10
+ commandName: cli_command_name_1.CliCommandName.CodeInMarkdown,
11
+ description: `Insert code snippets into markdown files.
12
+ This uses the markdown-code-example-inserter package to expand code link comments
13
+ inside of markdown files to actual markdown code blocks. See that package's
14
+ README for more details but the basics are that you need a comment that looks
15
+ like the following in your markdown file for this to do anything:
16
+
17
+ <!-- example-link: path/to/file.ts -->
18
+
19
+ By default this command parses all markdown files in the repo (ignoring
20
+ node_modules). Specific markdown files can be parsed by giving virmator
21
+ extra parameters.
22
+
23
+ examples:
24
+ # default experience (usually all you need)
25
+ virmator ${cli_command_name_1.CliCommandName.CodeInMarkdown}
26
+ # override files to check to a single file
27
+ virmator ${cli_command_name_1.CliCommandName.CodeInMarkdown} only/this/one/file.md
28
+ # override files to check to a group of files
29
+ virmator ${cli_command_name_1.CliCommandName.CodeInMarkdown} "only/this/dir/*.md"
30
+ `,
31
+ implementation: runCodeInMarkdownCommand,
32
+ configFlagSupport: {
33
+ [cli_flags_1.CliFlagName.NoWriteConfig]: false,
34
+ },
35
+ };
36
+ const mdCodePath = (0, virmator_repo_paths_1.getNpmBinPath)('md-code');
37
+ async function runCodeInMarkdownCommand(inputs) {
38
+ const args = inputs.rawArgs.length
39
+ ? (0, node_1.interpolationSafeWindowsPath)(inputs.rawArgs.join(' '))
40
+ : `\"./**/*.md\"`;
41
+ const mdCodeCommand = `${mdCodePath} ${args}`;
42
+ const results = await (0, shell_command_wrapper_1.runVirmatorShellCommand)(mdCodeCommand, inputs);
43
+ return {
44
+ success: !results.error,
45
+ };
46
+ }
47
+ exports.runCodeInMarkdownCommand = runCodeInMarkdownCommand;
@@ -1,3 +1,3 @@
1
1
  import { CliCommandImplementation, CliCommandResult, CommandFunctionInput } from '../cli-command';
2
2
  export declare const compileImplementation: CliCommandImplementation;
3
- export declare function runCompileCommand({ rawArgs, repoDir, }: CommandFunctionInput): Promise<CliCommandResult>;
3
+ export declare function runCompileCommand(inputs: CommandFunctionInput): Promise<CliCommandResult>;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCompileCommand = exports.compileImplementation = void 0;
4
- const node_1 = require("augment-vir/dist/node");
5
4
  const virmator_repo_paths_1 = require("../../../file-paths/virmator-repo-paths");
6
5
  const package_name_1 = require("../../../package-name");
7
6
  const cli_command_name_1 = require("../../cli-util/cli-command-name");
8
7
  const cli_flags_1 = require("../../cli-util/cli-flags");
8
+ 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,
@@ -24,21 +24,14 @@ exports.compileImplementation = {
24
24
  },
25
25
  };
26
26
  const tscPath = (0, virmator_repo_paths_1.getNpmBinPath)('tsc');
27
- async function runCompileCommand({ rawArgs, repoDir, }) {
28
- var _a, _b;
29
- const resetCommand = rawArgs.join(' ').includes('--noEmit') ? '' : 'rm -rf dist && ';
30
- const compileCommand = `${resetCommand}${tscPath} --pretty ${rawArgs
27
+ async function runCompileCommand(inputs) {
28
+ const resetCommand = inputs.rawArgs.join(' ').includes('--noEmit') ? '' : 'rm -rf dist && ';
29
+ const compileCommand = `${resetCommand}${tscPath} --pretty ${inputs.rawArgs
31
30
  .map((arg) => `"${arg}"`)
32
31
  .join(' ')}`;
33
- const results = await (0, node_1.runBashCommand)(compileCommand, repoDir);
34
- const keepError = !(((_a = results.error) === null || _a === void 0 ? void 0 : _a.message.trim().startsWith('Command failed:')) &&
35
- ((_b = results.error) === null || _b === void 0 ? void 0 : _b.message.trim().split('\n').length) <= 1);
32
+ const results = await (0, shell_command_wrapper_1.runVirmatorShellCommand)(compileCommand, inputs);
36
33
  return {
37
34
  success: !results.error,
38
- stdout: results.stdout,
39
- stderr: results.stderr,
40
- error: keepError ? results.error : undefined,
41
- printCommandResult: true,
42
35
  };
43
36
  }
44
37
  exports.runCompileCommand = runCompileCommand;
@@ -11,6 +11,6 @@ declare type FormatArgs = Required<Readonly<{
11
11
  export declare const defaultFormatArgs: FormatArgs;
12
12
  export declare const filesMarkerArg: "--format-files";
13
13
  export declare const formatImplementation: CliCommandImplementation;
14
- export declare function runFormatCommand({ rawArgs, repoDir, }: CommandFunctionInput): Promise<CliCommandResult>;
14
+ export declare function runFormatCommand(inputs: CommandFunctionInput): Promise<CliCommandResult>;
15
15
  export declare function extractFormatArgs(rawArgs: string[]): FormatArgs;
16
16
  export {};
@@ -6,6 +6,7 @@ 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");
8
8
  const cli_flags_1 = require("../../cli-util/cli-flags");
9
+ const shell_command_wrapper_1 = require("../../cli-util/shell-command-wrapper");
9
10
  const config_key_1 = require("../../config/config-key");
10
11
  var FormatOperation;
11
12
  (function (FormatOperation) {
@@ -63,19 +64,15 @@ exports.formatImplementation = {
63
64
  },
64
65
  };
65
66
  const prettierPath = (0, virmator_repo_paths_1.getNpmBinPath)('prettier');
66
- async function runFormatCommand({ rawArgs, repoDir, }) {
67
- var _a;
68
- const args = extractFormatArgs(rawArgs);
67
+ async function runFormatCommand(inputs) {
68
+ const args = extractFormatArgs(inputs.rawArgs);
69
69
  const operationFlag = args.operation === FormatOperation.Check ? '--check' : '--write';
70
70
  const prettierCommand = `${prettierPath} --color ${args.prettierFlags.join(' ')} \"./**/*.+(${args.fileExtensions.join('|')})\" ${operationFlag}`;
71
- const results = await (0, node_1.runBashCommand)(prettierCommand, repoDir);
72
- const keepError = !((_a = results.error) === null || _a === void 0 ? void 0 : _a.message.includes('Forgot to run Prettier?'));
71
+ const results = await (0, shell_command_wrapper_1.runVirmatorShellCommand)(prettierCommand, inputs, {
72
+ stdoutFilter: (stdout) => stdout.replace('Checking formatting...\n', ''),
73
+ });
73
74
  return {
74
75
  success: !results.error,
75
- stdout: results.stdout.replace('Checking formatting...\n', ''),
76
- stderr: results.stderr,
77
- error: keepError ? results.error : undefined,
78
- printCommandResult: true,
79
76
  };
80
77
  }
81
78
  exports.runFormatCommand = runFormatCommand;
@@ -1,3 +1,3 @@
1
1
  import { CliCommandImplementation, CliCommandResult, CommandFunctionInput } from '../cli-command';
2
2
  export declare const initCommandImplementation: CliCommandImplementation;
3
- export declare function runInitCommand({ cliFlags, repoDir, }: CommandFunctionInput): Promise<CliCommandResult>;
3
+ export declare function runInitCommand(inputs: CommandFunctionInput): Promise<CliCommandResult>;
@@ -19,22 +19,23 @@ exports.initCommandImplementation = {
19
19
  [cli_flags_1.CliFlagName.NoWriteConfig]: true,
20
20
  },
21
21
  };
22
- async function runInitCommand({ cliFlags, repoDir, }) {
22
+ async function runInitCommand(inputs) {
23
23
  let error;
24
24
  try {
25
- if (!cliFlags[cli_flags_1.CliFlagName.NoWriteConfig]) {
26
- await updatePackageJson(repoDir);
27
- await (0, update_all_configs_command_1.runUpdateAllConfigsCommand)({ rawArgs: [], cliFlags, repoDir });
25
+ if (!inputs.cliFlags[cli_flags_1.CliFlagName.NoWriteConfig]) {
26
+ await updatePackageJson(inputs.repoDir);
27
+ await (0, update_all_configs_command_1.runUpdateAllConfigsCommand)({
28
+ ...inputs,
29
+ rawArgs: [],
30
+ });
28
31
  }
29
- await (0, format_command_1.runFormatCommand)({ rawArgs: [], cliFlags, repoDir });
32
+ await (0, format_command_1.runFormatCommand)({ ...inputs, rawArgs: [] });
30
33
  }
31
34
  catch (catchError) {
32
35
  error = catchError;
33
36
  }
34
37
  return {
35
38
  success: !error,
36
- error: error,
37
- printCommandResult: true,
38
39
  };
39
40
  }
40
41
  exports.runInitCommand = runInitCommand;
@@ -1,3 +1,3 @@
1
1
  import { CliCommandImplementation, CliCommandResult, CommandFunctionInput } from '../cli-command';
2
2
  export declare const spellcheckCommandImplementation: CliCommandImplementation;
3
- export declare function runSpellcheckCommand({ rawArgs, repoDir, }: CommandFunctionInput): Promise<CliCommandResult>;
3
+ export declare function runSpellcheckCommand(inputs: CommandFunctionInput): Promise<CliCommandResult>;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runSpellcheckCommand = exports.spellcheckCommandImplementation = void 0;
4
- const node_1 = require("augment-vir/dist/node");
5
4
  const virmator_repo_paths_1 = require("../../../file-paths/virmator-repo-paths");
6
5
  const cli_command_name_1 = require("../../cli-util/cli-command-name");
7
6
  const cli_flags_1 = require("../../cli-util/cli-flags");
7
+ 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,
@@ -16,22 +16,11 @@ exports.spellcheckCommandImplementation = {
16
16
  },
17
17
  };
18
18
  const cSpellPath = (0, virmator_repo_paths_1.getNpmBinPath)('cspell');
19
- async function runSpellcheckCommand({ rawArgs, repoDir, }) {
20
- var _a;
21
- const spellcheckCommand = `${cSpellPath} --color "{*,.*,**/{.*,*}/**/{.*,*}}" ${rawArgs.join(' ')}`;
22
- const results = await (0, node_1.runBashCommand)(spellcheckCommand, repoDir);
23
- const keepError = !((_a = results.error) === null || _a === void 0 ? void 0 : _a.message.includes('CSpell: Files checked'));
19
+ async function runSpellcheckCommand(inputs) {
20
+ const spellcheckCommand = `${cSpellPath} --color "{*,.*,**/{.*,*}/**/{.*,*}}" ${inputs.rawArgs.join(' ')}`;
21
+ const results = await (0, shell_command_wrapper_1.runVirmatorShellCommand)(spellcheckCommand, inputs);
24
22
  return {
25
- /** Stdout for cspell is always an explanation of the unknown words, when they exist. */
26
- stdout: results.stdout,
27
- /**
28
- * When there's an error, stderr duplicates the error message, so it can be ignored.
29
- * Otherwise, stderr is the list of checked files.
30
- */
31
- stderr: results.error ? undefined : results.stderr,
32
23
  success: !results.error,
33
- error: keepError ? results.error : undefined,
34
- printCommandResult: true,
35
24
  };
36
25
  }
37
26
  exports.runSpellcheckCommand = runSpellcheckCommand;
@@ -1,3 +1,3 @@
1
1
  import { CliCommandImplementation, CliCommandResult, CommandFunctionInput } from '../cli-command';
2
2
  export declare const testCommandImplementation: CliCommandImplementation;
3
- export declare function runTestCommand({ rawArgs, repoDir, cliFlags, }: CommandFunctionInput): Promise<CliCommandResult>;
3
+ export declare function runTestCommand(inputs: CommandFunctionInput): Promise<CliCommandResult>;
@@ -5,6 +5,7 @@ const node_1 = require("augment-vir/dist/node");
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
+ const shell_command_wrapper_1 = require("../../cli-util/shell-command-wrapper");
8
9
  const compile_command_1 = require("./compile.command");
9
10
  exports.testCommandImplementation = {
10
11
  commandName: cli_command_name_1.CliCommandName.Test,
@@ -24,25 +25,18 @@ exports.testCommandImplementation = {
24
25
  },
25
26
  };
26
27
  const testVirPath = (0, virmator_repo_paths_1.getNpmBinPath)('test-vir');
27
- async function runTestCommand({ rawArgs, repoDir, cliFlags, }) {
28
- var _a, _b;
29
- const compileResult = await (0, compile_command_1.runCompileCommand)({ rawArgs: [], repoDir, cliFlags });
28
+ async function runTestCommand(inputs) {
29
+ const compileResult = await (0, compile_command_1.runCompileCommand)({ ...inputs, rawArgs: [] });
30
30
  if (!compileResult.success) {
31
31
  return compileResult;
32
32
  }
33
- const args = rawArgs.length
34
- ? (0, node_1.interpolationSafeWindowsPath)(rawArgs.join(' '))
33
+ const args = inputs.rawArgs.length
34
+ ? (0, node_1.interpolationSafeWindowsPath)(inputs.rawArgs.join(' '))
35
35
  : `\"./dist/**/!(*.type).test.js\"`;
36
36
  const testCommand = `${testVirPath} ${args}`;
37
- const results = await (0, node_1.runBashCommand)(testCommand, repoDir);
38
- const keepError = !(((_a = results.error) === null || _a === void 0 ? void 0 : _a.message.match(/\d+\s+tests?\s+failed/)) &&
39
- ((_b = results.error) === null || _b === void 0 ? void 0 : _b.message.trim().split('\n').length) <= 2);
37
+ const results = await (0, shell_command_wrapper_1.runVirmatorShellCommand)(testCommand, inputs);
40
38
  return {
41
- stdout: results.stdout.trim(),
42
- stderr: results.stderr.trim(),
43
39
  success: !results.error,
44
- error: keepError ? results.error : undefined,
45
- printCommandResult: false,
46
40
  };
47
41
  }
48
42
  exports.runTestCommand = runTestCommand;
@@ -1,3 +1,3 @@
1
1
  import { CliCommandImplementation, CliCommandResult, CommandFunctionInput } from '../cli-command';
2
2
  export declare const updateAllConfigsCommandImplementation: CliCommandImplementation;
3
- export declare function runUpdateAllConfigsCommand({ rawArgs, cliFlags, repoDir, }: CommandFunctionInput): Promise<CliCommandResult>;
3
+ export declare function runUpdateAllConfigsCommand(inputs: CommandFunctionInput): Promise<CliCommandResult>;
@@ -28,7 +28,7 @@ exports.updateAllConfigsCommandImplementation = {
28
28
  [cli_flags_1.CliFlagName.NoWriteConfig]: false,
29
29
  },
30
30
  };
31
- async function runUpdateAllConfigsCommand({ rawArgs, cliFlags, repoDir, }) {
32
- return await (0, update_configs_1.updateConfigs)(rawArgs, cliFlags, config_key_1.ConfigKey, repoDir);
31
+ async function runUpdateAllConfigsCommand(inputs) {
32
+ return await (0, update_configs_1.updateConfigs)(config_key_1.ConfigKey, inputs);
33
33
  }
34
34
  exports.runUpdateAllConfigsCommand = runUpdateAllConfigsCommand;
@@ -1,3 +1,3 @@
1
1
  import { CliCommandImplementation, CliCommandResult, CommandFunctionInput } from '../cli-command';
2
2
  export declare const updateBareConfigsCommandImplementation: CliCommandImplementation;
3
- export declare function runUpdateBareConfigsCommand({ rawArgs, cliFlags, repoDir, }: CommandFunctionInput): Promise<CliCommandResult>;
3
+ export declare function runUpdateBareConfigsCommand(inputs: CommandFunctionInput): Promise<CliCommandResult>;
@@ -29,7 +29,7 @@ exports.updateBareConfigsCommandImplementation = {
29
29
  [cli_flags_1.CliFlagName.NoWriteConfig]: false,
30
30
  },
31
31
  };
32
- async function runUpdateBareConfigsCommand({ rawArgs, cliFlags, repoDir, }) {
33
- return await (0, update_configs_1.updateConfigs)(rawArgs, cliFlags, config_key_1.BareConfigKey, repoDir);
32
+ async function runUpdateBareConfigsCommand(inputs) {
33
+ return await (0, update_configs_1.updateConfigs)(config_key_1.BareConfigKey, inputs);
34
34
  }
35
35
  exports.runUpdateBareConfigsCommand = runUpdateBareConfigsCommand;
@@ -43,22 +43,24 @@ async function runCommand(command, commandInput) {
43
43
  });
44
44
  }));
45
45
  }
46
- const commandResult = await commandImplementation.implementation((0, cli_command_1.fillInCommandInput)({
47
- ...commandInput,
48
- cliFlags,
49
- rawArgs: commandInput.rawArgs || [],
50
- }));
51
- if (!cliFlags[cli_flags_1.CliFlagName.Silent] || command === cli_command_name_1.CliCommandName.Help) {
52
- if (commandResult.stdout) {
53
- console.info(commandResult.stdout);
54
- }
55
- if (commandResult.stderr) {
56
- console.error(commandResult.stderr);
57
- }
58
- }
59
- if (commandResult.error) {
60
- throw commandResult.error;
61
- }
46
+ const loggers = cliFlags[cli_flags_1.CliFlagName.Silent] && command !== cli_command_name_1.CliCommandName.Help
47
+ ? cli_command_1.EmptyOutputCallbacks
48
+ : {
49
+ stdoutCallback: (input) => {
50
+ console.info(input.replace(/\n\n$/, '\n'));
51
+ },
52
+ stderrCallback: (input) => {
53
+ console.error(input.replace(/\n\n$/, '\n'));
54
+ },
55
+ };
56
+ const commandResult = await commandImplementation.implementation({
57
+ ...(0, cli_command_1.fillInCommandInput)({
58
+ ...commandInput,
59
+ cliFlags,
60
+ rawArgs: commandInput.rawArgs || [],
61
+ }),
62
+ ...loggers,
63
+ });
62
64
  return commandResult;
63
65
  }
64
66
  exports.runCommand = runCommand;
@@ -2,6 +2,8 @@
2
2
  export declare enum BareConfigKey {
3
3
  GitAttributes = "GitAttributes",
4
4
  GitHubActionsTest = "GitHubActionsTest",
5
+ GitHubActionsTaggedRelease = "GitHubActionsTaggedRelease",
6
+ GitHubActionsPrerelease = "GitHubActionsPrerelease",
5
7
  GitIgnore = "GitIgnore",
6
8
  NpmIgnore = "NpmIgnore",
7
9
  PrettierIgnore = "PrettierIgnore",
@@ -17,6 +19,8 @@ export declare enum CommandConfigKey {
17
19
  export declare const ConfigKey: {
18
20
  GitAttributes: BareConfigKey.GitAttributes;
19
21
  GitHubActionsTest: BareConfigKey.GitHubActionsTest;
22
+ GitHubActionsTaggedRelease: BareConfigKey.GitHubActionsTaggedRelease;
23
+ GitHubActionsPrerelease: BareConfigKey.GitHubActionsPrerelease;
20
24
  GitIgnore: BareConfigKey.GitIgnore;
21
25
  NpmIgnore: BareConfigKey.NpmIgnore;
22
26
  PrettierIgnore: BareConfigKey.PrettierIgnore;
@@ -6,6 +6,8 @@ var BareConfigKey;
6
6
  (function (BareConfigKey) {
7
7
  BareConfigKey["GitAttributes"] = "GitAttributes";
8
8
  BareConfigKey["GitHubActionsTest"] = "GitHubActionsTest";
9
+ BareConfigKey["GitHubActionsTaggedRelease"] = "GitHubActionsTaggedRelease";
10
+ BareConfigKey["GitHubActionsPrerelease"] = "GitHubActionsPrerelease";
9
11
  BareConfigKey["GitIgnore"] = "GitIgnore";
10
12
  BareConfigKey["NpmIgnore"] = "NpmIgnore";
11
13
  BareConfigKey["PrettierIgnore"] = "PrettierIgnore";
@@ -16,6 +16,8 @@ const configFileMap = {
16
16
  [config_key_1.ConfigKey.Cspell]: '.cspell.json',
17
17
  [config_key_1.ConfigKey.GitAttributes]: '.gitattributes',
18
18
  [config_key_1.ConfigKey.GitHubActionsTest]: (0, path_1.join)('.github', 'workflows', 'virmator-tests.yml'),
19
+ [config_key_1.ConfigKey.GitHubActionsPrerelease]: (0, path_1.join)('.github', 'workflows', 'virmator-prerelease.yml'),
20
+ [config_key_1.ConfigKey.GitHubActionsTaggedRelease]: (0, path_1.join)('.github', 'workflows', 'virmator-tagged-release.yml'),
19
21
  [config_key_1.ConfigKey.GitIgnore]: {
20
22
  virmator: (0, path_1.join)(virmator_repo_paths_1.relativeSeparateConfigsDir, 'gitignore.txt'),
21
23
  repo: '.gitignore',
package/package.json CHANGED
@@ -1,8 +1,15 @@
1
1
  {
2
2
  "name": "virmator",
3
- "version": "1.3.1",
3
+ "version": "1.3.5",
4
4
  "description": "Handle all the stuffs in one package.",
5
- "keywords": [],
5
+ "keywords": [
6
+ "automation",
7
+ "template",
8
+ "vir",
9
+ "formatting",
10
+ "spellcheck",
11
+ "config"
12
+ ],
6
13
  "homepage": "https://github.com/electrovir/virmator",
7
14
  "bugs": {
8
15
  "url": "https://github.com/electrovir/virmator/issues"
@@ -23,32 +30,30 @@
23
30
  "format:base": "prettier \"./**/*.+(ts|json|html|css|md|js)\"",
24
31
  "format:check": "npm run format:base -- --check",
25
32
  "prepublishOnly": "npm install && npm run test:full",
26
- "sanitize": "npm run compile && node dist/sanitizer/sanitize-for-test-file-cli.js",
27
- "sanitize:all": "./bulk-sanitize.sh files/downloads",
28
- "sanitize:no-compile": "node dist/sanitizer/sanitize-for-test-file-cli.js",
29
33
  "spellcheck": "cspell \"{*,.*,**/{.*,*}/**/{.*,*}}\" --exclude \"test-repos/spellcheck/invalid-spellcheck-repo/**/*\" --exclude \"extender-configs\"",
30
34
  "test": "npm run compile && test-vir \"./dist/**/!(*.type).test.js\"",
31
35
  "test:file": "ts-node ./scripts/test-specific-file.ts",
32
- "test:full": "npm run test && npm run spellcheck -- --no-progress && npm run format:check",
36
+ "test:full": "npm run test && npm run spellcheck -- --no-progress && npm run format:check && md-code --check README.md",
33
37
  "test:help": "npm run compile && node dist/cli/cli.js --help"
34
38
  },
35
39
  "dependencies": {
36
40
  "ansi-styles": "5.2.0",
37
- "augment-vir": "^1.1.0",
41
+ "augment-vir": "^1.2.1",
38
42
  "cspell": "^5.12.3",
39
43
  "fs-extra": "^10.0.0",
44
+ "markdown-code-example-inserter": "^0.1.5",
40
45
  "prettier": "^2.4.1",
41
46
  "prettier-plugin-jsdoc": "^0.3.24",
42
47
  "prettier-plugin-organize-imports": "^2.3.4",
43
48
  "prettier-plugin-packagejson": "^2.2.13",
44
49
  "prettier-plugin-sort-json": "^0.0.2",
45
50
  "simple-git": "^2.46.0",
46
- "test-vir": "^0.2.1",
51
+ "test-vir": "^0.2.3",
47
52
  "typescript": "^4.4.4"
48
53
  },
49
54
  "devDependencies": {
50
55
  "@types/fs-extra": "^9.0.13",
51
- "@types/node": "^16.10.4",
56
+ "@types/node": "^16.11.1",
52
57
  "ts-node": "^10.3.0"
53
58
  },
54
59
  "engines": {