virmator 2.0.7 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/.github/workflows/virmator-build-for-gh-pages.yml +24 -0
  2. package/.github/workflows/virmator-tagged-release.yml +8 -4
  3. package/.github/workflows/virmator-tests.yml +4 -3
  4. package/.mocharc.js +9 -0
  5. package/.prettierignore +2 -3
  6. package/README.md +67 -82
  7. package/configs/.cspell.json +4 -0
  8. package/configs/.gitattributes +1 -0
  9. package/configs/.mocharc.js +8 -0
  10. package/configs/.prettierignore +6 -0
  11. package/configs/.prettierrc.js +13 -0
  12. package/{.cspell.json → configs/.virmator/.cspell-base.json} +5 -0
  13. package/configs/.virmator/mocharc-base.js +15 -0
  14. package/configs/.virmator/prettierrc-base.js +62 -0
  15. package/{tsconfig.json → configs/.virmator/tsconfig-base.json} +12 -8
  16. package/configs/.virmator/vite-always-reload-plugin.ts +90 -0
  17. package/configs/.virmator/vite-base.ts +11 -0
  18. package/configs/.virmator/vite.config.ts +8 -0
  19. package/configs/.virmator/web-test-runner-base.mjs +29 -0
  20. package/configs/.virmator/web-test-runner.config.mjs +8 -0
  21. package/{.vscode → configs/.vscode}/settings.json +12 -0
  22. package/configs/gitignore.txt +6 -0
  23. package/configs/npmignore.txt +13 -0
  24. package/configs/package.json +16 -0
  25. package/configs/src/global.d.ts +5 -0
  26. package/configs/tsconfig.json +3 -0
  27. package/dist/api/virmator-wrapper.d.ts +5 -0
  28. package/dist/api/virmator-wrapper.js +9 -0
  29. package/dist/augments/array.d.ts +1 -0
  30. package/dist/augments/array.js +7 -0
  31. package/dist/augments/fs.d.ts +5 -0
  32. package/dist/augments/fs.js +30 -0
  33. package/dist/augments/json.d.ts +1 -0
  34. package/dist/augments/json.js +12 -0
  35. package/dist/augments/object.d.ts +1 -0
  36. package/dist/augments/object.js +14 -0
  37. package/dist/augments/regexp.d.ts +1 -0
  38. package/dist/augments/regexp.js +7 -0
  39. package/dist/augments/test.d.ts +2 -0
  40. package/dist/augments/test.js +8 -0
  41. package/dist/augments/type.d.ts +1 -0
  42. package/dist/augments/type.js +2 -0
  43. package/dist/cli/all-cli-command-definitions.d.ts +54 -0
  44. package/dist/cli/all-cli-command-definitions.js +76 -0
  45. package/dist/cli/cli-color.d.ts +8 -0
  46. package/dist/cli/cli-color.js +12 -0
  47. package/dist/cli/cli-command/cli-command-help.d.ts +8 -0
  48. package/dist/cli/cli-command/cli-command-help.js +2 -0
  49. package/dist/cli/{commands/description-printing.d.ts → cli-command/cli-command-to-help-message.d.ts} +3 -2
  50. package/dist/cli/{commands/description-printing.js → cli-command/cli-command-to-help-message.js} +55 -21
  51. package/dist/cli/cli-command/define-cli-command.d.ts +41 -0
  52. package/dist/cli/cli-command/define-cli-command.js +29 -0
  53. package/dist/cli/cli-command/run-shell-command.d.ts +8 -0
  54. package/dist/cli/cli-command/run-shell-command.js +23 -0
  55. package/dist/cli/cli-command-implementations/code-in-markdown.command.d.ts +6 -0
  56. package/dist/cli/cli-command-implementations/code-in-markdown.command.js +67 -0
  57. package/dist/cli/cli-command-implementations/compile.command.d.ts +6 -0
  58. package/dist/cli/cli-command-implementations/compile.command.js +44 -0
  59. package/dist/cli/cli-command-implementations/format.command.d.ts +6 -0
  60. package/dist/cli/cli-command-implementations/format.command.js +116 -0
  61. package/dist/cli/cli-command-implementations/frontend.command.d.ts +7 -0
  62. package/dist/cli/cli-command-implementations/frontend.command.js +45 -0
  63. package/dist/cli/cli-command-implementations/init.command.d.ts +4 -0
  64. package/dist/cli/cli-command-implementations/init.command.js +31 -0
  65. package/dist/cli/cli-command-implementations/spellcheck.command.d.ts +4 -0
  66. package/dist/cli/cli-command-implementations/spellcheck.command.js +40 -0
  67. package/dist/cli/cli-command-implementations/test-web.command.d.ts +4 -0
  68. package/dist/cli/cli-command-implementations/test-web.command.js +50 -0
  69. package/dist/cli/cli-command-implementations/test.command.d.ts +4 -0
  70. package/dist/cli/cli-command-implementations/test.command.js +53 -0
  71. package/dist/cli/cli-command-implementations/update-configs.command.d.ts +4 -0
  72. package/dist/cli/cli-command-implementations/update-configs.command.js +31 -0
  73. package/dist/cli/cli-flags/cli-flag-name.d.ts +4 -0
  74. package/dist/cli/cli-flags/cli-flag-name.js +8 -0
  75. package/dist/cli/cli-flags/cli-flag-values.d.ts +4 -0
  76. package/dist/cli/cli-flags/cli-flag-values.js +19 -0
  77. package/dist/cli/cli-messages.d.ts +6 -0
  78. package/dist/cli/cli-messages.js +19 -0
  79. package/dist/cli/cli.js +27 -20
  80. package/dist/cli/config/combine-text-config.d.ts +2 -0
  81. package/dist/cli/config/combine-text-config.js +27 -0
  82. package/dist/cli/config/config-files.d.ts +133 -0
  83. package/dist/cli/config/config-files.js +138 -0
  84. package/dist/cli/config/copy-config.d.ts +25 -13
  85. package/dist/cli/config/copy-config.js +86 -86
  86. package/dist/cli/config/create-default-package-json.d.ts +1 -16
  87. package/dist/cli/config/create-default-package-json.js +37 -12
  88. package/dist/cli/is-global.d.ts +1 -0
  89. package/dist/cli/is-global.js +10 -0
  90. package/dist/cli/parse-arguments.d.ts +8 -0
  91. package/dist/cli/parse-arguments.js +42 -0
  92. package/dist/cli/run-cli-command.d.ts +13 -0
  93. package/dist/cli/run-cli-command.js +52 -0
  94. package/dist/cli/run-command.test-helper.d.ts +28 -0
  95. package/dist/cli/run-command.test-helper.js +87 -0
  96. package/dist/errors/virmator-cli.error.d.ts +3 -0
  97. package/dist/errors/virmator-cli.error.js +10 -0
  98. package/dist/errors/virmator-config-file.error.d.ts +4 -0
  99. package/dist/errors/virmator-config-file.error.js +11 -0
  100. package/dist/errors/virmator-invalid-command.error.d.ts +5 -0
  101. package/dist/errors/virmator-invalid-command.error.js +11 -0
  102. package/dist/errors/virmator-invalid-flags.error.d.ts +5 -0
  103. package/dist/errors/virmator-invalid-flags.error.js +13 -0
  104. package/dist/file-paths/virmator-package-paths.d.ts +11 -0
  105. package/dist/file-paths/virmator-package-paths.js +31 -0
  106. package/dist/file-paths/virmator-test-file-paths.d.ts +17 -7
  107. package/dist/index.d.ts +1 -2
  108. package/dist/index.js +0 -4
  109. package/dist/logging.d.ts +10 -0
  110. package/dist/logging.js +9 -0
  111. package/package.json +26 -20
  112. package/.prettierrc.js +0 -40
  113. package/dist/augments/ansi-regex.d.ts +0 -1
  114. package/dist/augments/ansi-regex.js +0 -27
  115. package/dist/augments/string.d.ts +0 -1
  116. package/dist/augments/string.js +0 -8
  117. package/dist/cli/cli-util/cli-color.d.ts +0 -8
  118. package/dist/cli/cli-util/cli-color.js +0 -35
  119. package/dist/cli/cli-util/cli-command-name.d.ts +0 -11
  120. package/dist/cli/cli-util/cli-command-name.js +0 -15
  121. package/dist/cli/cli-util/cli-flags.d.ts +0 -18
  122. package/dist/cli/cli-util/cli-flags.js +0 -63
  123. package/dist/cli/cli-util/cli-messages.d.ts +0 -7
  124. package/dist/cli/cli-util/cli-messages.js +0 -19
  125. package/dist/cli/cli-util/get-all-command-output.d.ts +0 -7
  126. package/dist/cli/cli-util/get-all-command-output.js +0 -21
  127. package/dist/cli/cli-util/shell-command-wrapper.d.ts +0 -8
  128. package/dist/cli/cli-util/shell-command-wrapper.js +0 -25
  129. package/dist/cli/cli-util/update-configs.d.ts +0 -3
  130. package/dist/cli/cli-util/update-configs.js +0 -54
  131. package/dist/cli/commands/all-cli-commands.d.ts +0 -13
  132. package/dist/cli/commands/all-cli-commands.js +0 -99
  133. package/dist/cli/commands/cli-command.d.ts +0 -35
  134. package/dist/cli/commands/cli-command.js +0 -40
  135. package/dist/cli/commands/implementations/code-in-markdown.command.d.ts +0 -3
  136. package/dist/cli/commands/implementations/code-in-markdown.command.js +0 -54
  137. package/dist/cli/commands/implementations/compile.command.d.ts +0 -3
  138. package/dist/cli/commands/implementations/compile.command.js +0 -49
  139. package/dist/cli/commands/implementations/format.command.d.ts +0 -16
  140. package/dist/cli/commands/implementations/format.command.js +0 -143
  141. package/dist/cli/commands/implementations/init.command.d.ts +0 -3
  142. package/dist/cli/commands/implementations/init.command.js +0 -55
  143. package/dist/cli/commands/implementations/spellcheck.command.d.ts +0 -3
  144. package/dist/cli/commands/implementations/spellcheck.command.js +0 -35
  145. package/dist/cli/commands/implementations/test.command.d.ts +0 -3
  146. package/dist/cli/commands/implementations/test.command.js +0 -49
  147. package/dist/cli/commands/implementations/update-all-configs.command.d.ts +0 -3
  148. package/dist/cli/commands/implementations/update-all-configs.command.js +0 -46
  149. package/dist/cli/commands/implementations/update-bare-configs.command.d.ts +0 -3
  150. package/dist/cli/commands/implementations/update-bare-configs.command.js +0 -46
  151. package/dist/cli/commands/run-command.d.ts +0 -3
  152. package/dist/cli/commands/run-command.js +0 -65
  153. package/dist/cli/config/config-key.d.ts +0 -35
  154. package/dist/cli/config/config-key.js +0 -25
  155. package/dist/cli/config/config-paths.d.ts +0 -3
  156. package/dist/cli/config/config-paths.js +0 -69
  157. package/dist/cli/config/config-read.d.ts +0 -7
  158. package/dist/cli/config/config-read.js +0 -91
  159. package/dist/cli/config/extendable-config.d.ts +0 -12
  160. package/dist/cli/config/extendable-config.js +0 -45
  161. package/dist/errors/cli-command-error.d.ts +0 -4
  162. package/dist/errors/cli-command-error.js +0 -12
  163. package/dist/errors/cli-flag-error.d.ts +0 -4
  164. package/dist/errors/cli-flag-error.js +0 -12
  165. package/dist/errors/config-file-error.d.ts +0 -3
  166. package/dist/errors/config-file-error.js +0 -7
  167. package/dist/exportable-jest-config/jest-config.d.ts +0 -3
  168. package/dist/exportable-jest-config/jest-config.js +0 -23
  169. package/dist/exportable-jest-config/jest-setup.d.ts +0 -1
  170. package/dist/exportable-jest-config/jest-setup.js +0 -11
  171. package/dist/file-paths/virmator-repo-paths.d.ts +0 -5
  172. package/dist/file-paths/virmator-repo-paths.js +0 -19
  173. package/dist/jest/jest-config.d.ts +0 -3
  174. package/dist/jest/jest-config.js +0 -13
  175. package/extender-configs/.cspell.json +0 -3
  176. package/extender-configs/.prettierrc.js +0 -3
  177. package/extender-configs/tsconfig.json +0 -3
  178. package/separate-configs/.prettierignore +0 -3
  179. package/separate-configs/gitignore.txt +0 -4
  180. package/separate-configs/jest/jest-config.ts +0 -24
  181. package/separate-configs/jest/jest-setup.ts +0 -12
  182. package/separate-configs/npmignore.txt +0 -20
  183. package/separate-configs/package.json +0 -9
@@ -4,21 +4,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createDefaultPackageJson = void 0;
7
- const promises_1 = require("fs/promises");
7
+ const augment_vir_1 = require("augment-vir");
8
8
  const path_1 = require("path");
9
9
  const simple_git_1 = __importDefault(require("simple-git"));
10
- const config_key_1 = require("./config-key");
11
- const config_paths_1 = require("./config-paths");
12
- async function createDefaultPackageJson(repoDir) {
13
- const virmatorPackageJson = JSON.parse((await (0, promises_1.readFile)((0, config_paths_1.getVirmatorConfigFilePath)(config_key_1.ConfigKey.PackageJson, false))).toString());
10
+ const json_1 = require("../../augments/json");
11
+ async function createDefaultPackageJson(copyFromContents, existingConfigContents, repoDir) {
12
+ var _a;
13
+ const baseVirmatorPackageJson = JSON.parse(copyFromContents);
14
+ if (!(0, augment_vir_1.isObject)(baseVirmatorPackageJson)) {
15
+ throw new Error(`Failed to parse virmator's config version of package json file.`);
16
+ }
17
+ const currentRepoPackageJson = (_a = (0, json_1.jsonParseOrUndefined)(existingConfigContents)) !== null && _a !== void 0 ? _a : {};
18
+ if (!(0, augment_vir_1.isObject)(currentRepoPackageJson)) {
19
+ throw new Error(`Failed to parse current repo's package json file.`);
20
+ }
21
+ const combinedScripts = combineScripts(baseVirmatorPackageJson, currentRepoPackageJson);
14
22
  const gitProperties = await getGitProperties(repoDir);
15
- return {
16
- ...virmatorPackageJson,
17
- ...gitProperties,
23
+ const newPackageJson = {
18
24
  name: (0, path_1.basename)(repoDir),
25
+ ...currentRepoPackageJson,
26
+ ...baseVirmatorPackageJson,
27
+ ...gitProperties,
28
+ scripts: combinedScripts,
19
29
  };
30
+ return await JSON.stringify(newPackageJson);
20
31
  }
21
32
  exports.createDefaultPackageJson = createDefaultPackageJson;
33
+ function combineScripts(virmatorPackageJson, currentRepoPackageJson) {
34
+ const scripts = {
35
+ ...currentRepoPackageJson.scripts,
36
+ };
37
+ (0, augment_vir_1.getObjectTypedKeys)(virmatorPackageJson.scripts).forEach((key) => {
38
+ const virmatorValue = virmatorPackageJson[key];
39
+ const currentRepoValue = currentRepoPackageJson[key];
40
+ if (!scripts.hasOwnProperty(key) ||
41
+ (key === 'test' && currentRepoValue === `echo \"Error: no test specified\" && exit 1`)) {
42
+ scripts[key] = virmatorValue;
43
+ }
44
+ });
45
+ return scripts;
46
+ }
22
47
  async function getGitProperties(repoDir) {
23
48
  const git = (0, simple_git_1.default)(repoDir);
24
49
  const remotes = await git.getRemotes(true);
@@ -31,9 +56,9 @@ async function getGitProperties(repoDir) {
31
56
  }
32
57
  }
33
58
  function createGitHubUrls(ref) {
34
- const repoUrl = ref.replace(/^.*github.com:/, '').replace(/\.git$/, '');
35
- const gitHubUrl = `https://github.com/${repoUrl}`;
36
- const user = repoUrl.replace(/\/[^\/]+$/, '');
59
+ const repoPath = ref.replace(/^.*github.com:/, '').replace(/\.git$/, '');
60
+ const gitHubUrl = `https://github.com/${repoPath}`;
61
+ const user = repoPath.replace(/\/[^\/]+$/, '');
37
62
  return {
38
63
  homepage: gitHubUrl,
39
64
  bugs: {
@@ -41,7 +66,7 @@ function createGitHubUrls(ref) {
41
66
  },
42
67
  repository: {
43
68
  type: 'git',
44
- url: `${gitHubUrl}`,
69
+ url: gitHubUrl,
45
70
  },
46
71
  author: {
47
72
  name: user,
@@ -0,0 +1 @@
1
+ export declare function isRunningFromGlobalInstallation(): Promise<boolean>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRunningFromGlobalInstallation = void 0;
4
+ const node_only_1 = require("augment-vir/dist/cjs/node-only");
5
+ const virmator_package_paths_1 = require("../file-paths/virmator-package-paths");
6
+ async function isRunningFromGlobalInstallation() {
7
+ const npmGlobalPath = (await (0, node_only_1.runShellCommand)(`npm root -g`)).stdout;
8
+ return virmator_package_paths_1.virmatorPackageDir.startsWith(npmGlobalPath);
9
+ }
10
+ exports.isRunningFromGlobalInstallation = isRunningFromGlobalInstallation;
@@ -0,0 +1,8 @@
1
+ import { CliFlagValues } from './cli-flags/cli-flag-values';
2
+ export declare type ParsedArguments = {
3
+ flags: CliFlagValues;
4
+ invalidFlags: string[];
5
+ args: string[];
6
+ commandName: string | undefined;
7
+ };
8
+ export declare function parseArguments(args: string[]): Required<ParsedArguments>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseArguments = void 0;
4
+ const augment_vir_1 = require("augment-vir");
5
+ const all_cli_command_definitions_1 = require("./all-cli-command-definitions");
6
+ const cli_flag_name_1 = require("./cli-flags/cli-flag-name");
7
+ const cli_flag_values_1 = require("./cli-flags/cli-flag-values");
8
+ function parseArguments(args) {
9
+ const { inputFlags, invalidFlags, otherArgs, commandName } = args.reduce((accum, currentArg) => {
10
+ if (currentArg in all_cli_command_definitions_1.allCliCommandDefinitions && !accum.commandName) {
11
+ accum.commandName = currentArg;
12
+ }
13
+ else if (currentArg.startsWith('--')) {
14
+ if ((0, augment_vir_1.isEnumValue)(currentArg, cli_flag_name_1.CliFlagName)) {
15
+ accum.inputFlags[currentArg] = true;
16
+ }
17
+ else if (!accum.commandName) {
18
+ accum.invalidFlags.push(currentArg);
19
+ }
20
+ else {
21
+ accum.otherArgs.push(currentArg);
22
+ }
23
+ }
24
+ else {
25
+ accum.otherArgs.push(currentArg);
26
+ }
27
+ return accum;
28
+ }, {
29
+ inputFlags: {},
30
+ invalidFlags: [],
31
+ otherArgs: [],
32
+ commandName: undefined,
33
+ });
34
+ const cliFlags = (0, cli_flag_values_1.fillInCliFlagValues)(inputFlags);
35
+ return {
36
+ flags: cliFlags,
37
+ invalidFlags,
38
+ args: otherArgs,
39
+ commandName,
40
+ };
41
+ }
42
+ exports.parseArguments = parseArguments;
@@ -0,0 +1,13 @@
1
+ import { CliCommandDefinition, CliCommandExecutorOutput } from './cli-command/define-cli-command';
2
+ import { CliFlagValues } from './cli-flags/cli-flag-values';
3
+ export declare type RunCommandInputs = {
4
+ cliFlags: CliFlagValues;
5
+ otherArgs: string[];
6
+ repoDir: string;
7
+ };
8
+ export declare function runCommand(commandDefinition: CliCommandDefinition, runCommandInputs: RunCommandInputs): Promise<CliCommandExecutorOutput>;
9
+ export declare type ExtractSubCommandsOutput<T> = {
10
+ subCommands: T[];
11
+ filteredArgs: string[];
12
+ };
13
+ export declare function extractSubCommands<T>(allArgs: string[], availableSubCommands: T[]): ExtractSubCommandsOutput<T>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractSubCommands = exports.runCommand = void 0;
4
+ const array_1 = require("../augments/array");
5
+ const logging_1 = require("../logging");
6
+ const all_cli_command_definitions_1 = require("./all-cli-command-definitions");
7
+ const cli_flag_name_1 = require("./cli-flags/cli-flag-name");
8
+ async function runCommand(commandDefinition, runCommandInputs) {
9
+ if (runCommandInputs.cliFlags[cli_flag_name_1.CliFlagName.Help]) {
10
+ commandDefinition = all_cli_command_definitions_1.builtInCliCommandDefinitions.help;
11
+ }
12
+ const logging = runCommandInputs.cliFlags[cli_flag_name_1.CliFlagName.Silent] &&
13
+ commandDefinition.commandName !== all_cli_command_definitions_1.builtInCommandNames.help
14
+ ? logging_1.noCliLogging
15
+ : {
16
+ stdout: (input) => {
17
+ console.info(input.replace(/\n$/, ''));
18
+ },
19
+ stderr: (input) => {
20
+ console.error(input.replace(/\n$/, ''));
21
+ },
22
+ };
23
+ const { subCommands: inputSubCommands, filteredArgs: filteredInputArgs } = extractSubCommands(runCommandInputs.otherArgs, commandDefinition.allAvailableSubCommands);
24
+ const commandInputs = {
25
+ logging,
26
+ repoDir: process.cwd(),
27
+ inputSubCommands,
28
+ filteredInputArgs,
29
+ };
30
+ const commandResult = await commandDefinition.executor(commandInputs);
31
+ return commandResult;
32
+ }
33
+ exports.runCommand = runCommand;
34
+ function extractSubCommands(allArgs, availableSubCommands) {
35
+ let stillInSubCommands = true;
36
+ return allArgs.reduce((accum, currentArg) => {
37
+ if (stillInSubCommands) {
38
+ if ((0, array_1.isInTypedArray)(currentArg, availableSubCommands)) {
39
+ accum.subCommands.push(currentArg);
40
+ }
41
+ else {
42
+ stillInSubCommands = false;
43
+ accum.filteredArgs.push(currentArg);
44
+ }
45
+ }
46
+ else {
47
+ accum.filteredArgs.push(currentArg);
48
+ }
49
+ return accum;
50
+ }, { subCommands: [], filteredArgs: [] });
51
+ }
52
+ exports.extractSubCommands = extractSubCommands;
@@ -0,0 +1,28 @@
1
+ import { ArrayElement, Overwrite } from 'augment-vir';
2
+ import { ShellOutput } from 'augment-vir/dist/cjs/node-only';
3
+ import { CliCommandDefinition } from './cli-command/define-cli-command';
4
+ declare type RunCliCommandInputs<T extends CliCommandDefinition> = {
5
+ commandDefinition: T;
6
+ subCommand?: ArrayElement<T['allAvailableSubCommands']> | undefined;
7
+ extraArgs?: string[];
8
+ cwd: string;
9
+ debug?: boolean;
10
+ filesShouldNotChange?: boolean;
11
+ recursiveFileReading?: boolean;
12
+ };
13
+ export declare function runCliCommandForTest<T extends CliCommandDefinition>(inputs: RunCliCommandInputs<T>, expectations?: Omit<Overwrite<ShellOutput, {
14
+ stderr: string | RegExp;
15
+ stdout: string | RegExp;
16
+ }>, 'error'>, message?: string): Promise<{
17
+ results: ShellOutput;
18
+ dirFileNamesBefore: string[];
19
+ dirFileNamesAfter: string[];
20
+ dirFileContentsBefore: import("../augments/fs").DirContents;
21
+ dirFileContentsAfter: import("../augments/fs").DirContents;
22
+ changedFiles: Partial<{
23
+ [x: string]: any;
24
+ }>;
25
+ newFiles: string[];
26
+ durationMs: number;
27
+ }>;
28
+ export {};
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCliCommandForTest = void 0;
4
+ const augment_vir_1 = require("augment-vir");
5
+ const node_only_1 = require("augment-vir/dist/cjs/node-only");
6
+ const chai_1 = require("chai");
7
+ const promises_1 = require("fs/promises");
8
+ const path_1 = require("path");
9
+ const fs_1 = require("../augments/fs");
10
+ const object_1 = require("../augments/object");
11
+ const virmator_package_paths_1 = require("../file-paths/virmator-package-paths");
12
+ const cliPath = (0, path_1.join)(virmator_package_paths_1.virmatorDistDir, 'cli', 'cli.js');
13
+ async function runCliCommandForTest(inputs, expectations, message = '') {
14
+ var _a, _b, _c;
15
+ const recursiveFileReading = !!inputs.recursiveFileReading;
16
+ const cliCommand = (0, node_only_1.interpolationSafeWindowsPath)(cliPath);
17
+ const subCommand = (_a = inputs.subCommand) !== null && _a !== void 0 ? _a : '';
18
+ const extraArgs = (_c = (_b = inputs.extraArgs) === null || _b === void 0 ? void 0 : _b.join(' ')) !== null && _c !== void 0 ? _c : '';
19
+ const commandString = `node ${cliCommand} ${inputs.commandDefinition.commandName} ${subCommand} ${extraArgs}`;
20
+ const dirFileNamesBefore = (await (0, promises_1.readdir)(inputs.cwd)).sort();
21
+ const dirFileContentsBefore = await (0, fs_1.readAllDirContents)(inputs.cwd, recursiveFileReading);
22
+ const beforeTimestamp = Date.now();
23
+ const results = await (0, node_only_1.runShellCommand)(commandString, {
24
+ cwd: inputs.cwd,
25
+ ...(inputs.debug
26
+ ? {
27
+ hookUpToConsole: true,
28
+ }
29
+ : {}),
30
+ });
31
+ const afterTimestamp = Date.now();
32
+ const durationMs = afterTimestamp - beforeTimestamp;
33
+ const dirFileNamesAfter = (await (0, promises_1.readdir)(inputs.cwd)).sort();
34
+ const dirFileContentsAfter = await (0, fs_1.readAllDirContents)(inputs.cwd, recursiveFileReading);
35
+ const newFiles = dirFileNamesAfter.filter((afterFile) => !dirFileNamesBefore.includes(afterFile));
36
+ const changedFiles = (0, object_1.filterObject)(dirFileContentsAfter, (afterContents, key) => {
37
+ const beforeContents = dirFileContentsBefore[key];
38
+ return beforeContents !== afterContents;
39
+ });
40
+ if (expectations) {
41
+ const errors = [];
42
+ (0, augment_vir_1.getObjectTypedKeys)(expectations).forEach((expectationKey) => {
43
+ const expectation = expectations[expectationKey];
44
+ const result = results[expectationKey];
45
+ const expectationMessage = expectation instanceof RegExp ? String(expectation) : expectation;
46
+ // this is logged separately so that special characters (like color codes) are visible
47
+ const mismatch = JSON.stringify({
48
+ [`${message}${message ? '-' : ''}actual-${expectationKey}`]: result,
49
+ [`${message}${message ? '-' : ''}expected-${expectationKey}`]: expectationMessage,
50
+ }, null, 4);
51
+ const mismatchMessage = `\n${mismatch}\n`;
52
+ try {
53
+ if (expectation instanceof RegExp) {
54
+ chai_1.assert.match(String(result), expectation, mismatchMessage);
55
+ }
56
+ else {
57
+ chai_1.assert.strictEqual(result, expectation, mismatchMessage);
58
+ }
59
+ }
60
+ catch (error) {
61
+ if (expectation instanceof RegExp) {
62
+ console.info(expectation, { expectation }, String(expectation));
63
+ }
64
+ console.info(result);
65
+ errors.push(new Error((0, augment_vir_1.extractErrorMessage)(error)));
66
+ }
67
+ });
68
+ if (errors.length) {
69
+ throw (0, augment_vir_1.combineErrors)(errors);
70
+ }
71
+ }
72
+ if (inputs.filesShouldNotChange) {
73
+ chai_1.assert.deepEqual(dirFileNamesBefore, dirFileNamesAfter, 'new files should not have been generated');
74
+ chai_1.assert.deepEqual(dirFileContentsBefore, dirFileContentsAfter, 'file contents should not have changed');
75
+ }
76
+ return {
77
+ results,
78
+ dirFileNamesBefore,
79
+ dirFileNamesAfter,
80
+ dirFileContentsBefore,
81
+ dirFileContentsAfter,
82
+ changedFiles,
83
+ newFiles,
84
+ durationMs,
85
+ };
86
+ }
87
+ exports.runCliCommandForTest = runCliCommandForTest;
@@ -0,0 +1,3 @@
1
+ export declare class VirmatorCliError extends Error {
2
+ name: string;
3
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VirmatorCliError = void 0;
4
+ class VirmatorCliError extends Error {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.name = 'VirmatorCliError';
8
+ }
9
+ }
10
+ exports.VirmatorCliError = VirmatorCliError;
@@ -0,0 +1,4 @@
1
+ import { VirmatorCliError } from './virmator-cli.error';
2
+ export declare class VirmatorConfigFileError extends VirmatorCliError {
3
+ readonly name = "VirmatorConfigFileError";
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VirmatorConfigFileError = void 0;
4
+ const virmator_cli_error_1 = require("./virmator-cli.error");
5
+ class VirmatorConfigFileError extends virmator_cli_error_1.VirmatorCliError {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.name = 'VirmatorConfigFileError';
9
+ }
10
+ }
11
+ exports.VirmatorConfigFileError = VirmatorConfigFileError;
@@ -0,0 +1,5 @@
1
+ import { VirmatorCliError } from './virmator-cli.error';
2
+ export declare class VirmatorInvalidCommandError extends VirmatorCliError {
3
+ name: string;
4
+ constructor(message: string, allowedCommands: string[]);
5
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VirmatorInvalidCommandError = void 0;
4
+ const virmator_cli_error_1 = require("./virmator-cli.error");
5
+ class VirmatorInvalidCommandError extends virmator_cli_error_1.VirmatorCliError {
6
+ constructor(message, allowedCommands) {
7
+ super(`${message}\nExpected one of the following: ${allowedCommands.join(', ')}`);
8
+ this.name = 'VirmatorInvalidCommandError';
9
+ }
10
+ }
11
+ exports.VirmatorInvalidCommandError = VirmatorInvalidCommandError;
@@ -0,0 +1,5 @@
1
+ import { VirmatorCliError } from './virmator-cli.error';
2
+ export declare class VirmatorInvalidFlagsError extends VirmatorCliError {
3
+ readonly name = "VirmatorInvalidFlagsError";
4
+ constructor(invalidFlags: string[]);
5
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VirmatorInvalidFlagsError = void 0;
4
+ const augment_vir_1 = require("augment-vir");
5
+ const cli_flag_values_1 = require("../cli/cli-flags/cli-flag-values");
6
+ const virmator_cli_error_1 = require("./virmator-cli.error");
7
+ class VirmatorInvalidFlagsError extends virmator_cli_error_1.VirmatorCliError {
8
+ constructor(invalidFlags) {
9
+ super(`Invalid flags given: ${invalidFlags.join(',')}\nValid flags: ${(0, augment_vir_1.getObjectTypedKeys)((0, cli_flag_values_1.fillInCliFlagValues)()).join(',')}`);
10
+ this.name = 'VirmatorInvalidFlagsError';
11
+ }
12
+ }
13
+ exports.VirmatorInvalidFlagsError = VirmatorInvalidFlagsError;
@@ -0,0 +1,11 @@
1
+ export declare const virmatorPackageDir: string;
2
+ export declare const virmatorDistDir: string;
3
+ export declare const virmatorConfigsDir: string;
4
+ export declare const virmatorConfigs: {
5
+ dotVirmator: string;
6
+ gitHubWorkflows: string;
7
+ vsCode: string;
8
+ src: string;
9
+ };
10
+ export declare function getNpmBinPath(command: string): string;
11
+ export declare function relativeToVirmatorRoot(fullPath: string): string;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.relativeToVirmatorRoot = exports.getNpmBinPath = exports.virmatorConfigs = exports.virmatorConfigsDir = exports.virmatorDistDir = exports.virmatorPackageDir = void 0;
4
+ const node_only_1 = require("augment-vir/dist/cjs/node-only");
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ exports.virmatorPackageDir = (0, path_1.dirname)((0, path_1.dirname)(__dirname));
8
+ exports.virmatorDistDir = (0, path_1.join)(exports.virmatorPackageDir, 'dist');
9
+ exports.virmatorConfigsDir = (0, path_1.join)(exports.virmatorPackageDir, 'configs');
10
+ exports.virmatorConfigs = {
11
+ dotVirmator: (0, path_1.join)(exports.virmatorConfigsDir, '.virmator'),
12
+ gitHubWorkflows: (0, path_1.join)(exports.virmatorPackageDir, '.github', 'workflows'),
13
+ vsCode: (0, path_1.join)(exports.virmatorConfigsDir, '.vscode'),
14
+ src: (0, path_1.join)(exports.virmatorConfigsDir, 'src'),
15
+ };
16
+ const virmatorNodeBin = (0, path_1.join)(exports.virmatorPackageDir, 'node_modules', '.bin');
17
+ function getNpmBinPath(command) {
18
+ const virmatorBinPath = (0, path_1.join)(virmatorNodeBin, command);
19
+ const actualBinPath = (0, fs_1.existsSync)(virmatorBinPath)
20
+ ? virmatorBinPath
21
+ : (0, path_1.join)(exports.virmatorPackageDir, '..', '.bin', command);
22
+ if (!(0, fs_1.existsSync)(actualBinPath)) {
23
+ throw new Error(`Could not find npm bin path for "${command}"`);
24
+ }
25
+ return (0, node_only_1.interpolationSafeWindowsPath)(actualBinPath);
26
+ }
27
+ exports.getNpmBinPath = getNpmBinPath;
28
+ function relativeToVirmatorRoot(fullPath) {
29
+ return (0, path_1.relative)(exports.virmatorPackageDir, fullPath);
30
+ }
31
+ exports.relativeToVirmatorRoot = relativeToVirmatorRoot;
@@ -1,6 +1,11 @@
1
- import { CliCommandName } from '../cli/cli-util/cli-command-name';
1
+ import { CliCommandDefinition } from '../cli/cli-command/define-cli-command';
2
2
  export declare function createNodeModulesSymLinkForTests(dir: string): Promise<string>;
3
- export declare function getCommandTestRepoDir(command: CliCommandName): string;
3
+ export declare function getCommandTestRepoDir(command: CliCommandDefinition): string;
4
+ export declare const testCodeInMarkdownDirPath: string;
5
+ export declare const testCodeInMarkdownPaths: {
6
+ fixedReadme: string;
7
+ brokenReadme: string;
8
+ };
4
9
  export declare const testFormatPaths: {
5
10
  validRepo: string;
6
11
  invalidRepo: string;
@@ -18,17 +23,22 @@ export declare const testTestPaths: {
18
23
  validRepo: string;
19
24
  invalidRepo: string;
20
25
  multiRepo: string;
21
- runInBandTestRepo: string;
26
+ serialTestRepo: string;
22
27
  };
23
- export declare const spellcheckTestPaths: {
28
+ export declare const testSpellcheckPaths: {
24
29
  validRepo: string;
25
30
  invalidRepo: string;
26
31
  hiddenStuffRepo: string;
27
32
  };
28
- export declare const updateBareConfigsTestPaths: {
33
+ export declare const testTestWebPaths: {
34
+ passRepo: string;
35
+ failRepo: string;
36
+ };
37
+ export declare const testInitPaths: {
29
38
  emptyRepo: string;
30
39
  };
31
- export declare const updateAllConfigsTestPaths: {
32
- fullPackageJsonRepo: string;
40
+ export declare const testUpdateConfigsPaths: {
41
+ partialRepo: string;
42
+ partialRepoPrettierBase: string;
33
43
  };
34
44
  export declare const virmatorReadme: string;
package/dist/index.d.ts CHANGED
@@ -1,2 +1 @@
1
- /** This is exported so that it can be extended if needed. */
2
- export { virmatorJestConfig } from './exportable-jest-config/jest-config';
1
+ export {};
package/dist/index.js CHANGED
@@ -1,6 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.virmatorJestConfig = void 0;
4
- /** This is exported so that it can be extended if needed. */
5
- var jest_config_1 = require("./exportable-jest-config/jest-config");
6
- Object.defineProperty(exports, "virmatorJestConfig", { enumerable: true, get: function () { return jest_config_1.virmatorJestConfig; } });
@@ -0,0 +1,10 @@
1
+ export declare type LogCallback = (thingToLog: string) => void;
2
+ export declare type CliLogging = {
3
+ stdout: LogCallback;
4
+ stderr: LogCallback;
5
+ };
6
+ export declare const noCliLogging: Readonly<Required<CliLogging>>;
7
+ export declare type CliLogs = Record<keyof CliLogging, string>;
8
+ export declare const noLogTransforms: LogTransform;
9
+ export declare type LogTransform = (thingToTransform: string) => string;
10
+ export declare type LogTransforms = Partial<Record<keyof CliLogging, LogTransform>>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noLogTransforms = exports.noCliLogging = void 0;
4
+ exports.noCliLogging = {
5
+ stderr: () => { },
6
+ stdout: () => { },
7
+ };
8
+ const noLogTransforms = (input) => input;
9
+ exports.noLogTransforms = noLogTransforms;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virmator",
3
- "version": "2.0.7",
3
+ "version": "3.0.2",
4
4
  "description": "Handle all the stuffs in one package.",
5
5
  "keywords": [
6
6
  "automation",
@@ -31,37 +31,43 @@
31
31
  "format": "npm run format:base -- --write",
32
32
  "format:base": "prettier \"./**/*.+(ts|json|html|css|md|js)\"",
33
33
  "format:check": "npm run format:base -- --check",
34
- "prepublishOnly": "npm install && npm run test:full",
34
+ "prepublishOnly": "npm run test:full",
35
35
  "readme:check": "npm run compile && ts-node -r tsconfig-paths/register src/scripts/save-help-message.ts check && md-code --check README.md",
36
36
  "readme:update": "npm run compile && ts-node -r tsconfig-paths/register src/scripts/save-help-message.ts && md-code README.md",
37
37
  "spellcheck": "cspell \"{*,.*,**/{.*,*}/**/{.*,*}}\" --exclude \"test-files/spellcheck/invalid-spellcheck-repo/**/*\" --exclude \"extender-configs\"",
38
- "test": "npm install && npm run compile && jest --runInBand --config ./src/jest/jest-config.ts",
38
+ "test": "npm install && npm run compile && mocha --config .mocharc.js",
39
39
  "test:full": "npm run test && npm run spellcheck -- --no-progress && npm run format:check && npm run readme:check",
40
40
  "test:help": "ts-node -r tsconfig-paths/register src/cli/cli.ts --help"
41
41
  },
42
42
  "dependencies": {
43
- "@types/jest": "27.5.0",
44
- "ansi-styles": "5.2.0",
45
- "augment-vir": "2.1.0",
46
- "cspell": "5.20.0",
47
- "fs-extra": "10.1.0",
48
- "jest": "28.0.3",
49
- "markdown-code-example-inserter": "0.1.7",
50
- "prettier": "2.6.2",
43
+ "@open-wc/testing": "3.1.6",
44
+ "@types/chai": "4.3.1",
45
+ "@types/mocha": "9.1.1",
46
+ "@web/dev-server-esbuild": "0.3.1",
47
+ "@web/test-runner": "0.13.31",
48
+ "@web/test-runner-commands": "0.6.3",
49
+ "@web/test-runner-playwright": "0.8.9",
50
+ "ansi-colors": "4.1.3",
51
+ "augment-vir": "2.3.0",
52
+ "chai": "4.3.6",
53
+ "cspell": "6.4.1",
54
+ "markdown-code-example-inserter": "0.1.11",
55
+ "mocha": "10.0.0",
56
+ "prettier": "2.7.1",
51
57
  "prettier-plugin-jsdoc": "0.3.38",
52
- "prettier-plugin-multiline-arrays": "1.0.0",
53
- "prettier-plugin-organize-imports": "2.3.4",
54
- "prettier-plugin-packagejson": "2.2.17",
58
+ "prettier-plugin-multiline-arrays": "1.1.0",
59
+ "prettier-plugin-organize-imports": "3.0.0",
60
+ "prettier-plugin-packagejson": "2.2.18",
55
61
  "prettier-plugin-sort-json": "0.0.2",
56
- "simple-git": "3.7.1",
57
- "ts-jest": "28.0.1",
58
- "ts-node": "10.7.0",
62
+ "prettier-plugin-toml": "0.3.1",
63
+ "simple-git": "3.10.0",
64
+ "ts-node": "10.9.1",
59
65
  "tsconfig-paths": "4.0.0",
60
- "typescript": "4.6.4"
66
+ "typescript": "4.7.4",
67
+ "vite": "3.0.2"
61
68
  },
62
69
  "devDependencies": {
63
- "@types/fs-extra": "9.0.13",
64
- "@types/node": "17.0.31"
70
+ "@types/node": "18.0.6"
65
71
  },
66
72
  "engines": {
67
73
  "node": ">=14",
package/.prettierrc.js DELETED
@@ -1,40 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const plugins = [
5
- 'prettier-plugin-sort-json',
6
- 'prettier-plugin-packagejson',
7
- 'prettier-plugin-multiline-arrays',
8
- 'prettier-plugin-organize-imports',
9
- 'prettier-plugin-jsdoc',
10
- ].map((pluginName) => {
11
- // account for installations where deps are flattened and installations where they're nested
12
- const defaultPath = `./node_modules/${pluginName}`;
13
- if (fs.existsSync(path.resolve(__dirname, defaultPath))) {
14
- return defaultPath;
15
- } else {
16
- return `./node_modules/virmator/node_modules/${pluginName}`;
17
- }
18
- });
19
-
20
- /**
21
- * @typedef {import('prettier-plugin-multiline-arrays').MultilineArrayOptions} MultilineOptions
22
- *
23
- * @typedef {import('prettier').Options} PrettierOptions
24
- * @type {PrettierOptions & MultilineOptions}
25
- */
26
- const prettierConfig = {
27
- arrowParens: 'always',
28
- bracketSpacing: false,
29
- endOfLine: 'lf',
30
- htmlWhitespaceSensitivity: 'ignore',
31
- jsonRecursiveSort: true,
32
- bracketSameLine: false,
33
- plugins,
34
- printWidth: 100,
35
- singleQuote: true,
36
- tabWidth: 4,
37
- trailingComma: 'all',
38
- };
39
-
40
- module.exports = prettierConfig;
@@ -1 +0,0 @@
1
- export declare const ansiRegex: RegExp;