virmator 2.0.5 → 3.0.0

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 +6 -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 +13 -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 +28 -22
  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
@@ -0,0 +1,6 @@
1
+ export declare const cliErrorMessages: {
2
+ missingCliCommand: string;
3
+ commandNotFound(commandName: string): string;
4
+ missingConfigFile(commandName: string, configFileNames: string[]): string;
5
+ };
6
+ export declare function getResultMessage(commandName: string, success: boolean): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getResultMessage = exports.cliErrorMessages = void 0;
4
+ const cli_color_1 = require("./cli-color");
5
+ exports.cliErrorMessages = {
6
+ missingCliCommand: `Missing a command for virmator. Run "virmator help" for details.`,
7
+ commandNotFound(commandName) {
8
+ return `No command found by the name of "${commandName}"`;
9
+ },
10
+ missingConfigFile(commandName, configFileNames) {
11
+ return `Failed to run "${commandName}". Missing the following config file(s): ${configFileNames.join(', ')}`;
12
+ },
13
+ };
14
+ function getResultMessage(commandName, success) {
15
+ const specificColor = success ? cli_color_1.Color.Success : cli_color_1.Color.Fail;
16
+ const specificPhrase = success ? 'succeeded' : 'failed';
17
+ return `${cli_color_1.Color.Bold}${specificColor}${commandName} ${specificPhrase}.${cli_color_1.Color.Reset}`;
18
+ }
19
+ exports.getResultMessage = getResultMessage;
package/dist/cli/cli.js CHANGED
@@ -2,43 +2,50 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.cli = void 0;
5
- const cli_command_error_1 = require("../errors/cli-command-error");
6
- const cli_flag_error_1 = require("../errors/cli-flag-error");
7
- const cli_command_name_1 = require("./cli-util/cli-command-name");
8
- const cli_flags_1 = require("./cli-util/cli-flags");
9
- const cli_messages_1 = require("./cli-util/cli-messages");
10
- const run_command_1 = require("./commands/run-command");
5
+ const augment_vir_1 = require("augment-vir");
6
+ const virmator_invalid_command_error_1 = require("../errors/virmator-invalid-command.error");
7
+ const virmator_invalid_flags_error_1 = require("../errors/virmator-invalid-flags.error");
8
+ const all_cli_command_definitions_1 = require("./all-cli-command-definitions");
9
+ const cli_flag_name_1 = require("./cli-flags/cli-flag-name");
10
+ const cli_messages_1 = require("./cli-messages");
11
+ const parse_arguments_1 = require("./parse-arguments");
12
+ const run_cli_command_1 = require("./run-cli-command");
11
13
  async function cli(rawArgs) {
12
14
  try {
13
- const { flags, invalidFlags, args, command } = (0, cli_flags_1.extractArguments)(rawArgs);
15
+ const { flags, invalidFlags, args, commandName } = (0, parse_arguments_1.parseArguments)(rawArgs);
16
+ const cliCommandName = flags[cli_flag_name_1.CliFlagName.Help] ? all_cli_command_definitions_1.builtInCommandNames.help : commandName;
17
+ if (!cliCommandName) {
18
+ throw new virmator_invalid_command_error_1.VirmatorInvalidCommandError(cli_messages_1.cliErrorMessages.missingCliCommand, Object.values(all_cli_command_definitions_1.builtInCommandNames));
19
+ }
14
20
  if (invalidFlags.length) {
15
- throw new cli_flag_error_1.CliFlagError(invalidFlags);
21
+ throw new virmator_invalid_flags_error_1.VirmatorInvalidFlagsError(invalidFlags);
16
22
  }
17
- const cliCommand = flags[cli_flags_1.CliFlagName.Help] ? cli_command_name_1.CliCommandName.Help : command;
18
- if (!cliCommand) {
19
- throw new cli_command_error_1.VirmatorCliCommandError(cli_messages_1.cliErrorMessages.missingCliCommand);
23
+ const shouldLogStatus = cliCommandName !== all_cli_command_definitions_1.builtInCommandNames.help && !flags[cli_flag_name_1.CliFlagName.Silent];
24
+ if (shouldLogStatus) {
25
+ console.info(`running ${cliCommandName}...`);
20
26
  }
21
- if (cliCommand !== cli_command_name_1.CliCommandName.Help && !flags[cli_flags_1.CliFlagName.Silent]) {
22
- console.info(`running ${cliCommand}...`);
27
+ const commandDefinition = all_cli_command_definitions_1.allCliCommandDefinitions[cliCommandName];
28
+ if (!commandDefinition) {
29
+ throw new Error(cli_messages_1.cliErrorMessages.commandNotFound(cliCommandName));
23
30
  }
24
- const commandResult = await (0, run_command_1.runCommand)(cliCommand, {
25
- rawArgs: args,
26
- rawCliFlags: flags,
31
+ const commandResult = await (0, run_cli_command_1.runCommand)(commandDefinition, {
32
+ otherArgs: args,
33
+ cliFlags: flags,
34
+ repoDir: process.cwd(),
27
35
  });
28
- if (cliCommand !== cli_command_name_1.CliCommandName.Help && !flags[cli_flags_1.CliFlagName.Silent]) {
29
- console.info((0, cli_messages_1.getResultMessage)(cliCommand, commandResult.success));
36
+ if (shouldLogStatus) {
37
+ console.info((0, cli_messages_1.getResultMessage)(cliCommandName, commandResult.success));
30
38
  }
31
39
  process.exit(commandResult.success ? 0 : 1);
32
40
  }
33
41
  catch (error) {
34
- console.error(String(error));
42
+ console.error((0, augment_vir_1.extractErrorMessage)(error));
35
43
  process.exit(1);
36
44
  }
37
45
  }
38
46
  exports.cli = cli;
39
47
  // To run the cli from within this repo itself, use the following bash command:
40
48
  // node dist/cli/cli.js
41
- // if you haven't compiled you'll also need to run npm run compile beforehand (and after all changes)
42
49
  if (require.main === module) {
43
50
  cli(process.argv.slice(2));
44
51
  }
@@ -0,0 +1,2 @@
1
+ import { ConfigFileCopyCallback } from './config-files';
2
+ export declare const combineTextConfig: ConfigFileCopyCallback;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.combineTextConfig = void 0;
4
+ const augment_vir_1 = require("augment-vir");
5
+ function formatContents(input) {
6
+ return input
7
+ .split('\n')
8
+ .map((line) => line.trim())
9
+ .filter(augment_vir_1.isTruthy)
10
+ .sort();
11
+ }
12
+ const combineTextConfig = (newConfigContents, existingConfigContents) => {
13
+ const sortedNew = formatContents(newConfigContents);
14
+ const sortedExisting = formatContents(existingConfigContents);
15
+ let existingLinesAppended = false;
16
+ sortedExisting.forEach((existingLine) => {
17
+ if (!sortedNew.includes(existingLine) && !sortedNew.includes(`${existingLine}/`)) {
18
+ if (!existingLinesAppended) {
19
+ sortedNew.push('');
20
+ existingLinesAppended = true;
21
+ }
22
+ sortedNew.push(existingLine);
23
+ }
24
+ });
25
+ return sortedNew.join('\n');
26
+ };
27
+ exports.combineTextConfig = combineTextConfig;
@@ -0,0 +1,133 @@
1
+ import { createDefaultPackageJson } from './create-default-package-json';
2
+ export declare type ConfigFileCopyCallback = (copyFromContents: string, existingConfigContents: string, repoDir: string) => string | Promise<string>;
3
+ export declare type ConfigFileDefinition = {
4
+ path: string;
5
+ copyToPath?: string;
6
+ /**
7
+ * Name to rename the config file to when copying it to a repo.
8
+ *
9
+ * Example: this is needed for the .npmignore config file because npm won't publish .npmignore,
10
+ * so it's saved in virmator configs as npmignore.txt. Upon copying, we must then rename it.
11
+ */
12
+ copyName?: string;
13
+ /**
14
+ * Used to modify the file contents before copying it over to a repo. The returned string should
15
+ * be the new file contents.
16
+ */
17
+ updateCallback?: ConfigFileCopyCallback;
18
+ canBeUpdated?: boolean;
19
+ };
20
+ export declare function doesCopyToConfigPathExist(configFileDefinition: ConfigFileDefinition, repoDir: string): boolean;
21
+ export declare function getCopyToPath(configFileDefinition: ConfigFileDefinition, repoDir: string): string;
22
+ export declare const configFiles: {
23
+ /** Base config for spellchecking, contains a huge list of preset words defined within virmator. */
24
+ cSpellBase: {
25
+ path: string;
26
+ canBeUpdated: true;
27
+ };
28
+ /**
29
+ * Config for spellchecking. Extends the base config. Allows individual repos to add custom
30
+ * words while still using the virmator defined list of words.
31
+ */
32
+ cSpell: {
33
+ path: string;
34
+ };
35
+ /** Primarily fixes line ending issues on Windows machines. */
36
+ gitAttributes: {
37
+ path: string;
38
+ updateCallback: ConfigFileCopyCallback;
39
+ };
40
+ gitIgnore: {
41
+ path: string;
42
+ copyName: string;
43
+ updateCallback: ConfigFileCopyCallback;
44
+ };
45
+ /** Provides a GitHub Actions workflow for building deploying to GitHub Pages */
46
+ gitHubActionsGhPagesBuild: {
47
+ path: string;
48
+ copyToPath: string;
49
+ canBeUpdated: true;
50
+ };
51
+ /** Provides a GitHub Actions workflow for bundling releases for each version tag. */
52
+ gitHubActionsTaggedRelease: {
53
+ path: string;
54
+ copyToPath: string;
55
+ canBeUpdated: true;
56
+ };
57
+ /** Provides a GitHub Actions workflow to run all tests. */
58
+ gitHubActionsTest: {
59
+ path: string;
60
+ copyToPath: string;
61
+ canBeUpdated: true;
62
+ };
63
+ /** Ignores files for npm publish. */
64
+ npmIgnore: {
65
+ path: string;
66
+ copyName: string;
67
+ updateCallback: ConfigFileCopyCallback;
68
+ };
69
+ /** Provides some defaults for package.json properties. */
70
+ packageJson: {
71
+ path: string;
72
+ updateCallback: typeof createDefaultPackageJson;
73
+ };
74
+ /** All the base configs for prettier. */
75
+ prettierBase: {
76
+ path: string;
77
+ canBeUpdated: true;
78
+ };
79
+ /** Prettier config that inherits the base config and can be changed on a per-repo basis. */
80
+ prettier: {
81
+ path: string;
82
+ };
83
+ /** Ignore certain files in the formatting process. */
84
+ prettierIgnore: {
85
+ path: string;
86
+ updateCallback: ConfigFileCopyCallback;
87
+ };
88
+ /** Provides base configuration for ts config. */
89
+ tsConfigBase: {
90
+ path: string;
91
+ canBeUpdated: true;
92
+ };
93
+ /**
94
+ * Configuration for the TypeScript compiler. Based on the base configuration above and can be
95
+ * configured on a per-repo basis without interfering with the virmator config.
96
+ */
97
+ tsConfig: {
98
+ path: string;
99
+ };
100
+ /** VS Code settings. */
101
+ vsCodeSettings: {
102
+ path: string;
103
+ };
104
+ /** Global types. Specifically used at the moment to block un-imported test functions. */
105
+ globalTypes: {
106
+ path: string;
107
+ };
108
+ mochaBase: {
109
+ path: string;
110
+ canBeUpdated: true;
111
+ };
112
+ mocha: {
113
+ path: string;
114
+ };
115
+ viteBase: {
116
+ path: string;
117
+ canBeUpdated: true;
118
+ };
119
+ viteReloadPlugin: {
120
+ path: string;
121
+ canBeUpdated: true;
122
+ };
123
+ vite: {
124
+ path: string;
125
+ };
126
+ webTestRunnerBase: {
127
+ path: string;
128
+ canBeUpdated: true;
129
+ };
130
+ webTestRunner: {
131
+ path: string;
132
+ };
133
+ };
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configFiles = exports.getCopyToPath = exports.doesCopyToConfigPathExist = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const regexp_1 = require("../../augments/regexp");
7
+ const virmator_package_paths_1 = require("../../file-paths/virmator-package-paths");
8
+ const combine_text_config_1 = require("./combine-text-config");
9
+ const create_default_package_json_1 = require("./create-default-package-json");
10
+ function doesCopyToConfigPathExist(configFileDefinition, repoDir) {
11
+ return (0, fs_1.existsSync)(getCopyToPath(configFileDefinition, repoDir));
12
+ }
13
+ exports.doesCopyToConfigPathExist = doesCopyToConfigPathExist;
14
+ function getCopyToPath(configFileDefinition, repoDir) {
15
+ const replacedDir = configFileDefinition.copyToPath
16
+ ? (0, path_1.join)(repoDir, configFileDefinition.copyToPath, (0, path_1.basename)(configFileDefinition.path))
17
+ : configFileDefinition.path.replace(virmator_package_paths_1.virmatorConfigsDir, repoDir);
18
+ if (configFileDefinition.copyName) {
19
+ const replacedFileName = replacedDir.replace(new RegExp(`${(0, regexp_1.sanitizeStringForRegExpCreation)((0, path_1.basename)(replacedDir))}$`), configFileDefinition.copyName);
20
+ return replacedFileName;
21
+ }
22
+ else {
23
+ return replacedDir;
24
+ }
25
+ }
26
+ exports.getCopyToPath = getCopyToPath;
27
+ exports.configFiles = ((input) => input)({
28
+ /** Base config for spellchecking, contains a huge list of preset words defined within virmator. */
29
+ cSpellBase: {
30
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.dotVirmator, '.cspell-base.json'),
31
+ canBeUpdated: true,
32
+ },
33
+ /**
34
+ * Config for spellchecking. Extends the base config. Allows individual repos to add custom
35
+ * words while still using the virmator defined list of words.
36
+ */
37
+ cSpell: {
38
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigsDir, '.cspell.json'),
39
+ },
40
+ /** Primarily fixes line ending issues on Windows machines. */
41
+ gitAttributes: {
42
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigsDir, '.gitattributes'),
43
+ updateCallback: combine_text_config_1.combineTextConfig,
44
+ },
45
+ gitIgnore: {
46
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigsDir, 'gitignore.txt'),
47
+ copyName: '.gitignore',
48
+ updateCallback: combine_text_config_1.combineTextConfig,
49
+ },
50
+ /** Provides a GitHub Actions workflow for building deploying to GitHub Pages */
51
+ gitHubActionsGhPagesBuild: {
52
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.gitHubWorkflows, 'virmator-build-for-gh-pages.yml'),
53
+ copyToPath: (0, path_1.join)('.github', 'workflows'),
54
+ canBeUpdated: true,
55
+ },
56
+ /** Provides a GitHub Actions workflow for bundling releases for each version tag. */
57
+ gitHubActionsTaggedRelease: {
58
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.gitHubWorkflows, 'virmator-tagged-release.yml'),
59
+ copyToPath: (0, path_1.join)('.github', 'workflows'),
60
+ canBeUpdated: true,
61
+ },
62
+ /** Provides a GitHub Actions workflow to run all tests. */
63
+ gitHubActionsTest: {
64
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.gitHubWorkflows, 'virmator-tests.yml'),
65
+ copyToPath: (0, path_1.join)('.github', 'workflows'),
66
+ canBeUpdated: true,
67
+ },
68
+ /** Ignores files for npm publish. */
69
+ npmIgnore: {
70
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigsDir, 'npmignore.txt'),
71
+ copyName: '.npmignore',
72
+ updateCallback: combine_text_config_1.combineTextConfig,
73
+ },
74
+ /** Provides some defaults for package.json properties. */
75
+ packageJson: {
76
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigsDir, 'package.json'),
77
+ updateCallback: create_default_package_json_1.createDefaultPackageJson,
78
+ },
79
+ /** All the base configs for prettier. */
80
+ prettierBase: {
81
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.dotVirmator, 'prettierrc-base.js'),
82
+ canBeUpdated: true,
83
+ },
84
+ /** Prettier config that inherits the base config and can be changed on a per-repo basis. */
85
+ prettier: {
86
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigsDir, '.prettierrc.js'),
87
+ },
88
+ /** Ignore certain files in the formatting process. */
89
+ prettierIgnore: {
90
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigsDir, '.prettierignore'),
91
+ updateCallback: combine_text_config_1.combineTextConfig,
92
+ },
93
+ /** Provides base configuration for ts config. */
94
+ tsConfigBase: {
95
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.dotVirmator, 'tsconfig-base.json'),
96
+ canBeUpdated: true,
97
+ },
98
+ /**
99
+ * Configuration for the TypeScript compiler. Based on the base configuration above and can be
100
+ * configured on a per-repo basis without interfering with the virmator config.
101
+ */
102
+ tsConfig: {
103
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigsDir, 'tsconfig.json'),
104
+ },
105
+ /** VS Code settings. */
106
+ vsCodeSettings: {
107
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.vsCode, 'settings.json'),
108
+ },
109
+ /** Global types. Specifically used at the moment to block un-imported test functions. */
110
+ globalTypes: {
111
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.src, 'global.d.ts'),
112
+ },
113
+ mochaBase: {
114
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.dotVirmator, 'mocharc-base.js'),
115
+ canBeUpdated: true,
116
+ },
117
+ mocha: {
118
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigsDir, '.mocharc.js'),
119
+ },
120
+ viteBase: {
121
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.dotVirmator, 'vite-base.ts'),
122
+ canBeUpdated: true,
123
+ },
124
+ viteReloadPlugin: {
125
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.dotVirmator, 'vite-always-reload-plugin.ts'),
126
+ canBeUpdated: true,
127
+ },
128
+ vite: {
129
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.dotVirmator, 'vite.config.ts'),
130
+ },
131
+ webTestRunnerBase: {
132
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.dotVirmator, 'web-test-runner-base.mjs'),
133
+ canBeUpdated: true,
134
+ },
135
+ webTestRunner: {
136
+ path: (0, path_1.join)(virmator_package_paths_1.virmatorConfigs.dotVirmator, 'web-test-runner.config.mjs'),
137
+ },
138
+ });
@@ -1,14 +1,26 @@
1
- import { ConfigKey } from './config-key';
2
- export declare type CopyConfigLog = {
3
- stderr: boolean;
4
- log: string;
5
- };
6
- export declare function copyConfig({ configKey, forceExtendableConfig, repoDir, }: {
7
- configKey: ConfigKey;
8
- forceExtendableConfig: boolean;
1
+ import { CliLogging } from '../../logging';
2
+ import { ConfigFileDefinition } from './config-files';
3
+ export declare enum CopyConfigOperation {
4
+ /** Only update the config file if it exists and is marked as being able to be updated. */
5
+ Update = "update",
6
+ /** Overwrite config file, even if it already exists in the repo. */
7
+ Overwrite = "overwrite",
8
+ /** Only write the config file if it doesn't exist already or if it can be updated. */
9
+ Init = "init"
10
+ }
11
+ export declare type CopyConfigInputs = {
12
+ configFileDefinition: ConfigFileDefinition;
9
13
  repoDir: string;
10
- }): Promise<{
11
- logs: CopyConfigLog[];
12
- outputFilePath: string;
13
- didWrite: boolean;
14
- }>;
14
+ operation: CopyConfigOperation;
15
+ };
16
+ export declare type CopyConfigOutputs = {
17
+ copiedToPath: string;
18
+ shouldWrite: boolean;
19
+ };
20
+ export declare function copyConfig(inputs: CopyConfigInputs): Promise<CopyConfigOutputs>;
21
+ export declare type CopyAllConfigFilesInputs = Omit<CopyConfigInputs, 'configFileDefinition'> & {
22
+ logging: CliLogging;
23
+ configFiles: Record<string, ConfigFileDefinition>;
24
+ };
25
+ /** Returns success state. True if success, false is errors were encountered. */
26
+ export declare function copyAllConfigFiles(inputs: CopyAllConfigFilesInputs): Promise<boolean>;
@@ -1,100 +1,100 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.copyConfig = void 0;
4
- const node_only_1 = require("augment-vir/dist/node-only");
5
- const fs_extra_1 = require("fs-extra");
3
+ exports.copyAllConfigFiles = exports.copyConfig = exports.CopyConfigOperation = void 0;
4
+ const augment_vir_1 = require("augment-vir");
5
+ const fs_1 = require("fs");
6
+ const promises_1 = require("fs/promises");
6
7
  const path_1 = require("path");
7
- const config_file_error_1 = require("../../errors/config-file-error");
8
- const cli_flags_1 = require("../cli-util/cli-flags");
9
- const config_paths_1 = require("./config-paths");
10
- const config_read_1 = require("./config-read");
11
- const extendable_config_1 = require("./extendable-config");
12
- async function isConfigFileExtending(configKey, repoDir) {
13
- if (!(0, extendable_config_1.isExtendableConfig)(configKey)) {
14
- return false;
15
- }
16
- const fileContents = await (0, config_read_1.readRepoConfigFile)(configKey, repoDir, false);
17
- return (0, extendable_config_1.isConfigExtending)(configKey, fileContents);
18
- }
19
- const ifUndesiredMessage = `If this is undesired, use the ${cli_flags_1.CliFlagName.NoWriteConfig} flag to prevent config file updates.`;
20
- async function copyConfig({ configKey, forceExtendableConfig, repoDir, }) {
21
- const logs = [];
22
- let outputFilePath;
23
- let shouldWriteConfig;
24
- const virmatorConfigContents = await (0, config_read_1.readUpdatedVirmatorConfigFile)(configKey, repoDir, false);
25
- const repoConfigPath = (0, path_1.join)(repoDir, (0, config_paths_1.getRepoConfigFilePath)(configKey, false));
26
- const repoConfigExists = (0, fs_extra_1.existsSync)(repoConfigPath);
27
- const shouldExtend = (repoConfigExists && (await isConfigFileExtending(configKey, repoDir))) ||
28
- forceExtendableConfig;
29
- if (!repoConfigExists) {
30
- logs.push({
31
- stderr: true,
32
- log: `Config file not found, creating new file: ${repoConfigPath}\n${ifUndesiredMessage}`,
33
- });
34
- }
35
- if (shouldExtend && (0, extendable_config_1.isExtendableConfig)(configKey)) {
36
- if (!(0, extendable_config_1.isExtendableConfig)(configKey)) {
37
- throw new config_file_error_1.ConfigFileError(`Extendable config files are not supported for ${configKey}`);
38
- }
39
- if (!repoConfigExists) {
40
- // if extender config file does not exist, create it
41
- const extenderContents = await (0, config_read_1.readUpdatedVirmatorConfigFile)(configKey, repoDir, true);
42
- await (0, node_only_1.writeFileAndDir)(repoConfigPath, extenderContents);
43
- }
44
- const repoExtendableConfigPath = (0, path_1.join)(repoDir, (0, extendable_config_1.getExtendableBaseConfigName)(configKey));
45
- const repoExtendableConfigExists = (0, fs_extra_1.existsSync)(repoExtendableConfigPath);
46
- if (repoExtendableConfigExists) {
47
- // if the extendable config already exists, check if we need to update it
48
- const repoExtendableConfigContents = await (0, config_read_1.readRepoConfigFile)(configKey, repoDir, true);
49
- if (repoExtendableConfigContents !== virmatorConfigContents) {
50
- // only write when we need to update the file
51
- logs.push({
52
- stderr: false,
53
- log: `Updating ${repoExtendableConfigPath}\n${ifUndesiredMessage}`,
54
- });
55
- shouldWriteConfig = true;
56
- }
57
- else {
58
- shouldWriteConfig = false;
8
+ const cli_color_1 = require("../cli-color");
9
+ const config_files_1 = require("./config-files");
10
+ var CopyConfigOperation;
11
+ (function (CopyConfigOperation) {
12
+ /** Only update the config file if it exists and is marked as being able to be updated. */
13
+ CopyConfigOperation["Update"] = "update";
14
+ /** Overwrite config file, even if it already exists in the repo. */
15
+ CopyConfigOperation["Overwrite"] = "overwrite";
16
+ /** Only write the config file if it doesn't exist already or if it can be updated. */
17
+ CopyConfigOperation["Init"] = "init";
18
+ })(CopyConfigOperation = exports.CopyConfigOperation || (exports.CopyConfigOperation = {}));
19
+ async function copyConfig(inputs) {
20
+ const copyFromPath = inputs.configFileDefinition.path;
21
+ const copyToPath = (0, config_files_1.getCopyToPath)(inputs.configFileDefinition, inputs.repoDir);
22
+ const copyToFileExists = (0, config_files_1.doesCopyToConfigPathExist)(inputs.configFileDefinition, inputs.repoDir);
23
+ let shouldWrite = false;
24
+ switch (inputs.operation) {
25
+ case CopyConfigOperation.Init: {
26
+ if (!copyToFileExists) {
27
+ shouldWrite = true;
59
28
  }
29
+ break;
60
30
  }
61
- else {
62
- // when the extendable config file is not already found, we always write it
63
- logs.push({
64
- stderr: true,
65
- log: `Extendable config file not found, creating new file: ${repoExtendableConfigPath}\n`,
66
- });
67
- shouldWriteConfig = true;
31
+ case CopyConfigOperation.Overwrite: {
32
+ shouldWrite = true;
33
+ break;
68
34
  }
69
- outputFilePath = repoExtendableConfigPath;
70
- }
71
- else {
72
- if (repoConfigExists) {
73
- const currentConfigPathContents = await (0, config_read_1.readRepoConfigFile)(configKey, repoDir, false);
74
- // only update the config file when they differ
75
- if (currentConfigPathContents !== virmatorConfigContents) {
76
- logs.push({
77
- stderr: false,
78
- log: `Updating ${repoConfigPath}`,
79
- });
80
- shouldWriteConfig = true;
35
+ case CopyConfigOperation.Update: {
36
+ if (copyToFileExists &&
37
+ typeof inputs.configFileDefinition !== 'string' &&
38
+ (inputs.configFileDefinition.canBeUpdated ||
39
+ inputs.configFileDefinition.updateCallback)) {
40
+ shouldWrite = true;
81
41
  }
82
- else {
83
- shouldWriteConfig = false;
84
- }
85
- }
86
- else {
87
- shouldWriteConfig = true;
42
+ break;
88
43
  }
89
- outputFilePath = repoConfigPath;
90
44
  }
91
- if (shouldWriteConfig) {
92
- await (0, node_only_1.writeFileAndDir)(outputFilePath, virmatorConfigContents);
45
+ const currentRepoFileContents = (0, fs_1.existsSync)(copyToPath)
46
+ ? (await (0, promises_1.readFile)(copyToPath)).toString()
47
+ : '';
48
+ const virmatorFileContents = (await (0, promises_1.readFile)(copyFromPath)).toString();
49
+ const writeContents = inputs.configFileDefinition.updateCallback
50
+ ? await inputs.configFileDefinition.updateCallback(virmatorFileContents, currentRepoFileContents, inputs.repoDir)
51
+ : virmatorFileContents;
52
+ if (currentRepoFileContents === writeContents) {
53
+ shouldWrite = false;
54
+ }
55
+ if (shouldWrite) {
56
+ await (0, promises_1.mkdir)((0, path_1.dirname)(copyToPath), { recursive: true });
57
+ await (0, promises_1.writeFile)(copyToPath, writeContents);
93
58
  }
94
59
  return {
95
- logs,
96
- outputFilePath,
97
- didWrite: shouldWriteConfig,
60
+ copiedToPath: copyToPath,
61
+ shouldWrite,
98
62
  };
99
63
  }
100
64
  exports.copyConfig = copyConfig;
65
+ const successfulOperation = {
66
+ [CopyConfigOperation.Init]: 'copied',
67
+ [CopyConfigOperation.Overwrite]: 'overwrote',
68
+ [CopyConfigOperation.Update]: 'updated',
69
+ };
70
+ const failedOperation = {
71
+ [CopyConfigOperation.Init]: 'copy',
72
+ [CopyConfigOperation.Overwrite]: 'overwrite',
73
+ [CopyConfigOperation.Update]: 'update',
74
+ };
75
+ /** Returns success state. True if success, false is errors were encountered. */
76
+ async function copyAllConfigFiles(inputs) {
77
+ const errors = [];
78
+ await (0, augment_vir_1.awaitedForEach)(Object.keys(inputs.configFiles).sort(), async (configKey) => {
79
+ const configFile = inputs.configFiles[configKey];
80
+ try {
81
+ const result = await copyConfig({
82
+ configFileDefinition: configFile,
83
+ operation: inputs.operation,
84
+ repoDir: inputs.repoDir,
85
+ });
86
+ if (result.shouldWrite) {
87
+ inputs.logging.stdout(`${cli_color_1.Color.Info}Successfully ${successfulOperation[inputs.operation]}${cli_color_1.Color.Reset} ${(0, path_1.basename)(result.copiedToPath)}`);
88
+ }
89
+ }
90
+ catch (error) {
91
+ const copyError = new Error(`${cli_color_1.Color.Fail}Failed to ${failedOperation[inputs.operation]}${cli_color_1.Color.Reset} ${(0, path_1.basename)(configFile.path)}: ${(0, augment_vir_1.extractErrorMessage)(error)}`);
92
+ errors.push(copyError);
93
+ }
94
+ });
95
+ errors.forEach((error) => {
96
+ inputs.logging.stderr(error.message);
97
+ });
98
+ return !errors.length;
99
+ }
100
+ exports.copyAllConfigFiles = copyAllConfigFiles;
@@ -1,16 +1 @@
1
- export declare function createDefaultPackageJson(repoDir: string): Promise<{
2
- name: string;
3
- homepage?: string;
4
- bugs?: {
5
- url: string;
6
- };
7
- repository?: {
8
- type: string;
9
- url: string;
10
- };
11
- author?: {
12
- name: string;
13
- url: string;
14
- };
15
- scripts: object;
16
- }>;
1
+ export declare function createDefaultPackageJson(copyFromContents: string, existingConfigContents: string, repoDir: string): Promise<string>;