virmator 3.0.5 → 4.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 (175) hide show
  1. package/README.md +1 -14
  2. package/base-configs/base-cspell.js +83 -0
  3. package/base-configs/base-mocharc.js +14 -0
  4. package/{configs/.virmator/prettierrc-base.js → base-configs/base-prettierrc.js} +0 -0
  5. package/{configs/.virmator/tsconfig-base.json → base-configs/base-tsconfig.json} +0 -6
  6. package/{configs/.virmator/vite-base.ts → base-configs/base-vite.ts} +0 -0
  7. package/base-configs/test-files-glob.js +5 -0
  8. package/{configs/.virmator → base-configs}/vite-always-reload-plugin.ts +5 -3
  9. package/{configs/.virmator → base-configs}/web-test-runner-base.mjs +4 -5
  10. package/configs/.gitattributes +1 -0
  11. package/configs/.nvmrc +1 -0
  12. package/configs/.prettierignore +1 -1
  13. package/configs/.prettierrc.js +1 -1
  14. package/configs/{.mocharc.js → configs/.mocharc.js} +1 -1
  15. package/configs/{.virmator → configs}/vite.config.ts +1 -1
  16. package/configs/{.virmator → configs}/web-test-runner.config.mjs +1 -1
  17. package/configs/cspell.config.js +9 -0
  18. package/configs/gitignore.txt +1 -0
  19. package/configs/npmignore.txt +1 -0
  20. package/configs/package.json +9 -5
  21. package/configs/tsconfig.json +1 -1
  22. package/cspell.config.js +11 -0
  23. package/dist/{cli → api}/cli-color.d.ts +1 -0
  24. package/dist/{cli → api}/cli-color.js +1 -0
  25. package/dist/api/command/command-configs.d.ts +3 -0
  26. package/dist/api/command/command-configs.js +11 -0
  27. package/dist/api/command/command-description.d.ts +8 -0
  28. package/dist/{cli/cli-command/cli-command-help.js → api/command/command-description.js} +0 -0
  29. package/dist/api/command/command-executor.d.ts +28 -0
  30. package/dist/api/command/command-executor.js +7 -0
  31. package/dist/api/command/command-help.d.ts +8 -0
  32. package/dist/{package-name.js → api/command/command-help.js} +0 -2
  33. package/dist/api/command/command-logging.d.ts +11 -0
  34. package/dist/api/command/command-logging.js +17 -0
  35. package/dist/api/command/command-mapping.d.ts +7 -0
  36. package/dist/api/command/command-mapping.js +10 -0
  37. package/dist/api/command/command-messages.d.ts +1 -0
  38. package/dist/api/command/command-messages.js +10 -0
  39. package/dist/api/command/command-to-help-message.d.ts +9 -0
  40. package/dist/{cli/cli-command/cli-command-to-help-message.js → api/command/command-to-help-message.js} +41 -48
  41. package/dist/api/command/define-command-inputs.d.ts +14 -0
  42. package/dist/api/command/define-command-inputs.js +2 -0
  43. package/dist/api/command/define-command.d.ts +8 -0
  44. package/dist/api/command/define-command.js +25 -0
  45. package/dist/api/config/config-file-definition.d.ts +16 -0
  46. package/dist/api/config/config-file-definition.js +2 -0
  47. package/dist/api/config/config-paths.d.ts +7 -0
  48. package/dist/api/config/config-paths.js +8 -0
  49. package/dist/{cli → api}/config/copy-config.d.ts +5 -4
  50. package/dist/{cli → api}/config/copy-config.js +26 -28
  51. package/dist/api/create-virmator.d.ts +8 -0
  52. package/dist/api/create-virmator.js +65 -0
  53. package/dist/api/run-command/check-npm-deps.d.ts +7 -0
  54. package/dist/api/run-command/check-npm-deps.js +107 -0
  55. package/dist/api/run-command/extract-arguments.d.ts +6 -0
  56. package/dist/api/run-command/extract-arguments.js +37 -0
  57. package/dist/api/run-command/run-command-executor.d.ts +5 -0
  58. package/dist/api/run-command/run-command-executor.js +51 -0
  59. package/dist/api/run-command/run-extended-virmator.d.ts +10 -0
  60. package/dist/api/run-command/run-extended-virmator.js +53 -0
  61. package/dist/{cli/cli-command → api/run-command}/run-shell-command.d.ts +3 -3
  62. package/dist/{cli/cli-command → api/run-command}/run-shell-command.js +3 -3
  63. package/dist/api/virmator-types.d.ts +18 -0
  64. package/dist/api/virmator-types.js +2 -0
  65. package/dist/augments/fs.d.ts +5 -2
  66. package/dist/augments/fs.js +20 -8
  67. package/dist/augments/object.d.ts +3 -0
  68. package/dist/augments/object.js +33 -2
  69. package/dist/augments/path.d.ts +1 -0
  70. package/dist/augments/path.js +14 -0
  71. package/dist/augments/prettier.d.ts +1 -0
  72. package/dist/augments/prettier.js +47 -0
  73. package/dist/augments/string.d.ts +2 -0
  74. package/dist/augments/string.js +10 -0
  75. package/dist/augments/test.d.ts +2 -1
  76. package/dist/augments/test.js +7 -3
  77. package/dist/cli.d.ts +2 -0
  78. package/dist/cli.js +5 -0
  79. package/dist/{cli/cli-command-implementations → commands}/code-in-markdown.command.d.ts +3 -1
  80. package/dist/{cli/cli-command-implementations → commands}/code-in-markdown.command.js +23 -24
  81. package/dist/commands/compile.command.d.ts +14 -0
  82. package/dist/commands/compile.command.js +54 -0
  83. package/dist/commands/extra-configs/all-extra-configs.d.ts +2 -0
  84. package/dist/commands/extra-configs/all-extra-configs.js +44 -0
  85. package/dist/commands/extra-configs/combine-json-config.d.ts +2 -0
  86. package/dist/commands/extra-configs/combine-json-config.js +22 -0
  87. package/dist/commands/extra-configs/combine-text-config.d.ts +2 -0
  88. package/dist/{cli/config → commands/extra-configs}/combine-text-config.js +5 -5
  89. package/dist/{cli/config → commands/extra-configs}/create-default-package-json.d.ts +0 -0
  90. package/dist/{cli/config → commands/extra-configs}/create-default-package-json.js +30 -18
  91. package/dist/commands/format.command.d.ts +19 -0
  92. package/dist/{cli/cli-command-implementations → commands}/format.command.js +59 -33
  93. package/dist/commands/frontend.command.d.ts +15 -0
  94. package/dist/commands/frontend.command.js +78 -0
  95. package/dist/commands/init.command.d.ts +8 -0
  96. package/dist/commands/init.command.js +53 -0
  97. package/dist/commands/spellcheck.command.d.ts +12 -0
  98. package/dist/commands/spellcheck.command.js +54 -0
  99. package/dist/commands/test-web.command.d.ts +12 -0
  100. package/dist/commands/test-web.command.js +68 -0
  101. package/dist/commands/test.command.d.ts +12 -0
  102. package/dist/commands/test.command.js +67 -0
  103. package/dist/{cli/cli-command-implementations → commands}/update-configs.command.d.ts +3 -1
  104. package/dist/{cli/cli-command-implementations → commands}/update-configs.command.js +14 -10
  105. package/dist/file-paths/{virmator-package-paths.d.ts → package-paths.d.ts} +1 -1
  106. package/dist/file-paths/{virmator-package-paths.js → package-paths.js} +3 -4
  107. package/dist/index.d.ts +134 -1
  108. package/dist/index.js +55 -0
  109. package/dist/scripts/save-help-message.d.ts +1 -0
  110. package/dist/scripts/save-help-message.js +33 -0
  111. package/package.json +33 -28
  112. package/.gitattributes +0 -1
  113. package/.github/workflows/virmator-build-for-gh-pages.yml +0 -24
  114. package/.github/workflows/virmator-tagged-release.yml +0 -42
  115. package/.github/workflows/virmator-tests.yml +0 -26
  116. package/.mocharc.js +0 -9
  117. package/.prettierignore +0 -5
  118. package/configs/.cspell.json +0 -4
  119. package/configs/.virmator/.cspell-base.json +0 -81
  120. package/configs/.virmator/mocharc-base.js +0 -15
  121. package/configs/src/global.d.ts +0 -5
  122. package/dist/api/virmator-wrapper.d.ts +0 -5
  123. package/dist/api/virmator-wrapper.js +0 -9
  124. package/dist/cli/all-cli-command-definitions.d.ts +0 -56
  125. package/dist/cli/all-cli-command-definitions.js +0 -76
  126. package/dist/cli/cli-command/cli-command-help.d.ts +0 -8
  127. package/dist/cli/cli-command/cli-command-to-help-message.d.ts +0 -11
  128. package/dist/cli/cli-command/define-cli-command.d.ts +0 -41
  129. package/dist/cli/cli-command/define-cli-command.js +0 -29
  130. package/dist/cli/cli-command-implementations/compile.command.d.ts +0 -6
  131. package/dist/cli/cli-command-implementations/compile.command.js +0 -44
  132. package/dist/cli/cli-command-implementations/format.command.d.ts +0 -6
  133. package/dist/cli/cli-command-implementations/frontend.command.d.ts +0 -7
  134. package/dist/cli/cli-command-implementations/frontend.command.js +0 -45
  135. package/dist/cli/cli-command-implementations/init.command.d.ts +0 -6
  136. package/dist/cli/cli-command-implementations/init.command.js +0 -42
  137. package/dist/cli/cli-command-implementations/spellcheck.command.d.ts +0 -4
  138. package/dist/cli/cli-command-implementations/spellcheck.command.js +0 -40
  139. package/dist/cli/cli-command-implementations/test-web.command.d.ts +0 -4
  140. package/dist/cli/cli-command-implementations/test-web.command.js +0 -50
  141. package/dist/cli/cli-command-implementations/test.command.d.ts +0 -4
  142. package/dist/cli/cli-command-implementations/test.command.js +0 -53
  143. package/dist/cli/cli-flags/cli-flag-name.d.ts +0 -4
  144. package/dist/cli/cli-flags/cli-flag-name.js +0 -8
  145. package/dist/cli/cli-flags/cli-flag-values.d.ts +0 -4
  146. package/dist/cli/cli-flags/cli-flag-values.js +0 -19
  147. package/dist/cli/cli-messages.d.ts +0 -6
  148. package/dist/cli/cli-messages.js +0 -19
  149. package/dist/cli/cli.d.ts +0 -2
  150. package/dist/cli/cli.js +0 -54
  151. package/dist/cli/config/combine-text-config.d.ts +0 -2
  152. package/dist/cli/config/config-files.d.ts +0 -133
  153. package/dist/cli/config/config-files.js +0 -138
  154. package/dist/cli/is-global.d.ts +0 -1
  155. package/dist/cli/is-global.js +0 -10
  156. package/dist/cli/parse-arguments.d.ts +0 -8
  157. package/dist/cli/parse-arguments.js +0 -42
  158. package/dist/cli/run-cli-command.d.ts +0 -13
  159. package/dist/cli/run-cli-command.js +0 -52
  160. package/dist/cli/run-command.test-helper.d.ts +0 -28
  161. package/dist/cli/run-command.test-helper.js +0 -87
  162. package/dist/errors/virmator-cli.error.d.ts +0 -3
  163. package/dist/errors/virmator-cli.error.js +0 -10
  164. package/dist/errors/virmator-config-file.error.d.ts +0 -4
  165. package/dist/errors/virmator-config-file.error.js +0 -11
  166. package/dist/errors/virmator-invalid-command.error.d.ts +0 -5
  167. package/dist/errors/virmator-invalid-command.error.js +0 -11
  168. package/dist/errors/virmator-invalid-flags.error.d.ts +0 -5
  169. package/dist/errors/virmator-invalid-flags.error.js +0 -13
  170. package/dist/file-paths/repo-paths.d.ts +0 -2
  171. package/dist/file-paths/repo-paths.js +0 -6
  172. package/dist/file-paths/virmator-test-file-paths.d.ts +0 -44
  173. package/dist/logging.d.ts +0 -10
  174. package/dist/logging.js +0 -9
  175. package/dist/package-name.d.ts +0 -1
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCommandExecutor = exports.createCommandString = void 0;
4
+ const augment_vir_1 = require("augment-vir");
5
+ const node_only_1 = require("augment-vir/dist/cjs/node-only");
6
+ const path_1 = require("path");
7
+ const cli_color_1 = require("../cli-color");
8
+ const command_executor_1 = require("../command/command-executor");
9
+ const copy_config_1 = require("../config/copy-config");
10
+ const run_shell_command_1 = require("./run-shell-command");
11
+ function createCommandString(executorOutput) {
12
+ const args = executorOutput.args.map((arg) => {
13
+ if (typeof arg !== 'string') {
14
+ if (arg.skipWindowsInterpolation) {
15
+ return arg;
16
+ }
17
+ else {
18
+ arg = arg.arg;
19
+ }
20
+ }
21
+ return (0, node_only_1.interpolationSafeWindowsPath)(arg);
22
+ });
23
+ const commandString = `${executorOutput.mainCommand} ${args.filter(augment_vir_1.isTruthy).join(' ')}`;
24
+ return commandString;
25
+ }
26
+ exports.createCommandString = createCommandString;
27
+ async function runCommandExecutor(commandDefinition, commandInputs) {
28
+ console.info(`${cli_color_1.Color.Info}running ${commandDefinition.commandName}...${cli_color_1.Color.Reset}`);
29
+ await (0, copy_config_1.copyAllConfigFiles)({
30
+ logging: commandInputs.logging,
31
+ configFiles: Object.values(commandDefinition.configFiles),
32
+ operation: copy_config_1.CopyConfigOperation.Init,
33
+ packageDir: commandInputs.packageDir,
34
+ repoDir: commandInputs.repoDir,
35
+ });
36
+ const executorOutput = await commandDefinition.executor(commandInputs);
37
+ if ((0, command_executor_1.isCompletedExecutor)(executorOutput)) {
38
+ return executorOutput.success;
39
+ }
40
+ else {
41
+ const commandString = createCommandString(executorOutput);
42
+ console.log(`${cli_color_1.Color.Faint}${(0, node_only_1.toPosixPath)((0, path_1.relative)(process.cwd(), commandString))}${cli_color_1.Color.Reset}`);
43
+ const commandResult = await (0, run_shell_command_1.runVirmatorShellCommand)(commandString, {
44
+ repoDir: commandInputs.repoDir,
45
+ logging: commandInputs.logging,
46
+ logTransforms: executorOutput.logTransforms,
47
+ });
48
+ return commandResult.exitCode === 0;
49
+ }
50
+ }
51
+ exports.runCommandExecutor = runCommandExecutor;
@@ -0,0 +1,10 @@
1
+ import { CommandMapping } from '../command/command-mapping';
2
+ import { ConfigFileDefinition } from '../config/config-file-definition';
3
+ export declare function runExtendedVirmator({ allArgs, allConfigs, commandMapping, packageBinName, packageDir, repoDir, }: {
4
+ allArgs: string[];
5
+ allConfigs: readonly ConfigFileDefinition[];
6
+ commandMapping: CommandMapping;
7
+ packageBinName: string;
8
+ packageDir: string;
9
+ repoDir: string;
10
+ }): Promise<void>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runExtendedVirmator = void 0;
4
+ const augment_vir_1 = require("augment-vir");
5
+ const command_logging_1 = require("../command/command-logging");
6
+ const command_messages_1 = require("../command/command-messages");
7
+ const check_npm_deps_1 = require("./check-npm-deps");
8
+ const extract_arguments_1 = require("./extract-arguments");
9
+ const run_command_executor_1 = require("./run-command-executor");
10
+ function availableCommandsString(commandMapping) {
11
+ return `\nAvailable commands:\n ${(0, augment_vir_1.getObjectTypedKeys)(commandMapping).join(', ')}\n`;
12
+ }
13
+ function getValidCommandDefinition(binName, commandMapping, givenCommandName) {
14
+ if (!givenCommandName) {
15
+ throw new Error(`Missing command name as first input to ${binName}.${availableCommandsString(commandMapping)}`);
16
+ }
17
+ const commandDefinition = commandMapping[givenCommandName];
18
+ if (!(0, augment_vir_1.typedHasOwnProperty)(commandMapping, givenCommandName) || !commandDefinition) {
19
+ throw new Error(`Invalid command "${givenCommandName} for ${binName}.${availableCommandsString(commandMapping)}"`);
20
+ }
21
+ return commandDefinition;
22
+ }
23
+ async function runExtendedVirmator({ allArgs, allConfigs, commandMapping, packageBinName, packageDir, repoDir, }) {
24
+ const args = (0, extract_arguments_1.getRelevantArgs)(allArgs, packageBinName);
25
+ const commandName = args[0];
26
+ const commandArgs = args.slice(1);
27
+ const commandDefinition = getValidCommandDefinition(packageBinName, commandMapping, commandName);
28
+ const logging = command_logging_1.defaultConsoleLogging;
29
+ const { subCommands: inputSubCommands, filteredArgs: filteredInputArgs } = (0, extract_arguments_1.extractSubCommands)(commandArgs, commandDefinition.allAvailableSubCommands);
30
+ await (0, check_npm_deps_1.updateDepsAsNeeded)({
31
+ npmDeps: commandDefinition.npmDeps,
32
+ packageBinName,
33
+ packageDir,
34
+ repoDir,
35
+ });
36
+ const commandInputs = {
37
+ logging,
38
+ repoDir,
39
+ inputSubCommands,
40
+ filteredInputArgs,
41
+ allConfigs,
42
+ packageDir,
43
+ };
44
+ const success = await (0, run_command_executor_1.runCommandExecutor)(commandDefinition, commandInputs);
45
+ const resultMessage = (0, command_messages_1.getCommandResultMessage)(commandName !== null && commandName !== void 0 ? commandName : '', success);
46
+ if (success) {
47
+ console.log(resultMessage);
48
+ }
49
+ else {
50
+ throw new Error(resultMessage);
51
+ }
52
+ }
53
+ exports.runExtendedVirmator = runExtendedVirmator;
@@ -1,8 +1,8 @@
1
1
  import { ShellOutput } from 'augment-vir/dist/cjs/node-only';
2
- import { CliLogging, LogTransforms } from '../../logging';
2
+ import { CommandLogging, CommandLogTransforms } from '../command/command-logging';
3
3
  export declare type RunVirmatorShellCommandOptions = {
4
4
  repoDir: string;
5
- logging: CliLogging;
6
- logTransforms?: LogTransforms | undefined;
5
+ logging: CommandLogging;
6
+ logTransforms?: CommandLogTransforms | undefined;
7
7
  };
8
8
  export declare function runVirmatorShellCommand(command: string, { repoDir: cwd, logging, logTransforms }: RunVirmatorShellCommandOptions): Promise<ShellOutput>;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runVirmatorShellCommand = void 0;
4
4
  const node_only_1 = require("augment-vir/dist/cjs/node-only");
5
- const logging_1 = require("../../logging");
5
+ const command_logging_1 = require("../command/command-logging");
6
6
  function logWrapper(handleLog, logTransformer) {
7
7
  return (input) => {
8
8
  const callbackString = logTransformer(input.toString());
@@ -15,8 +15,8 @@ async function runVirmatorShellCommand(command, { repoDir: cwd, logging, logTran
15
15
  var _a, _b;
16
16
  const shellResults = await (0, node_only_1.runShellCommand)(command, {
17
17
  cwd,
18
- stdoutCallback: logWrapper(logging.stdout, (_a = logTransforms === null || logTransforms === void 0 ? void 0 : logTransforms.stdout) !== null && _a !== void 0 ? _a : logging_1.noLogTransforms),
19
- stderrCallback: logWrapper(logging.stderr, (_b = logTransforms === null || logTransforms === void 0 ? void 0 : logTransforms.stderr) !== null && _b !== void 0 ? _b : logging_1.noLogTransforms),
18
+ stdoutCallback: logWrapper(logging.stdout, (_a = logTransforms === null || logTransforms === void 0 ? void 0 : logTransforms.stdout) !== null && _a !== void 0 ? _a : command_logging_1.identityCommandLogTransform),
19
+ stderrCallback: logWrapper(logging.stderr, (_b = logTransforms === null || logTransforms === void 0 ? void 0 : logTransforms.stderr) !== null && _b !== void 0 ? _b : command_logging_1.identityCommandLogTransform),
20
20
  });
21
21
  return shellResults;
22
22
  }
@@ -0,0 +1,18 @@
1
+ import { CommandDefinitionArrayToMapping, CommandMapping } from './command/command-mapping';
2
+ import { CommandDefinition } from './command/define-command';
3
+ import { ConfigFileDefinition } from './config/config-file-definition';
4
+ export declare type ExtendVirmatorInputs<CommandDefinitionsGeneric extends ReadonlyArray<CommandDefinition>> = Readonly<{
5
+ packageBinName: string;
6
+ packageRootDir: string;
7
+ commandDefinitions?: CommandDefinitionsGeneric;
8
+ }>;
9
+ export declare type ExtendedVirmator<CommandMappingGeneric extends Readonly<CommandMapping>> = Readonly<{
10
+ packageBinName: string;
11
+ cliHelpMessage: string;
12
+ markdownHelpMessage: string;
13
+ commandMapping: CommandMappingGeneric;
14
+ extend: <CommandDefinitionsGeneric extends ReadonlyArray<CommandDefinition<any>>>(inputs: ExtendVirmatorInputs<CommandDefinitionsGeneric>) => ExtendedVirmator<CommandDefinitionArrayToMapping<CommandDefinitionsGeneric>>;
15
+ allConfigs: ReadonlyArray<ConfigFileDefinition>;
16
+ runInCli: () => Promise<void>;
17
+ run: (allArgs: string[], repoDir: string) => Promise<void>;
18
+ }>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,8 @@
1
1
  export interface DirContents {
2
2
  [key: string]: string | DirContents;
3
3
  }
4
- export declare function clearDirectoryContents(dirPath: string): Promise<void>;
5
- export declare function readAllDirContents(dir: string, recursive?: boolean): Promise<DirContents>;
4
+ export declare function readAllDirContents({ dir, recursive, }: {
5
+ dir: string;
6
+ recursive?: boolean;
7
+ }): Promise<DirContents>;
8
+ export declare function writeFiles(dir: string, allFileContents: DirContents): Promise<void>;
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readAllDirContents = exports.clearDirectoryContents = void 0;
3
+ exports.writeFiles = exports.readAllDirContents = void 0;
4
+ const augment_vir_1 = require("augment-vir");
4
5
  const promises_1 = require("fs/promises");
5
6
  const path_1 = require("path");
6
- async function clearDirectoryContents(dirPath) {
7
- await (0, promises_1.rm)(dirPath, { recursive: true });
8
- await (0, promises_1.mkdir)(dirPath);
9
- }
10
- exports.clearDirectoryContents = clearDirectoryContents;
11
- async function readAllDirContents(dir, recursive = false) {
7
+ async function readAllDirContents({ dir, recursive = false, }) {
12
8
  const fileNames = await (0, promises_1.readdir)(dir);
13
9
  const allFileContents = await Promise.all(fileNames.map(async (fileName) => {
14
10
  const filePath = (0, path_1.join)(dir, fileName);
@@ -16,7 +12,7 @@ async function readAllDirContents(dir, recursive = false) {
16
12
  return isFile
17
13
  ? (await (0, promises_1.readFile)(filePath)).toString()
18
14
  : recursive
19
- ? await readAllDirContents(filePath, recursive)
15
+ ? await readAllDirContents({ dir: filePath, recursive })
20
16
  : '';
21
17
  }));
22
18
  const mappedFileContents = fileNames.reduce((accum, fileName, index) => {
@@ -28,3 +24,19 @@ async function readAllDirContents(dir, recursive = false) {
28
24
  return mappedFileContents;
29
25
  }
30
26
  exports.readAllDirContents = readAllDirContents;
27
+ async function writeFiles(dir, allFileContents) {
28
+ await (0, augment_vir_1.awaitedForEach)(Object.keys(allFileContents), async (fileOrDirName) => {
29
+ const value = allFileContents[fileOrDirName];
30
+ const currentPath = (0, path_1.join)(dir, fileOrDirName);
31
+ if (typeof value === 'string') {
32
+ await (0, promises_1.writeFile)(currentPath, value);
33
+ }
34
+ else if (!value) {
35
+ throw new Error(`Failed to find file file under "${fileOrDirName}"`);
36
+ }
37
+ else {
38
+ await writeFiles(currentPath, value);
39
+ }
40
+ });
41
+ }
42
+ exports.writeFiles = writeFiles;
@@ -1 +1,4 @@
1
+ import { Overwrite } from 'augment-vir';
1
2
  export declare function filterObject<T extends object>(fullObject: Readonly<T>, callback: (value: T[keyof T], key: keyof T, fullObject: Readonly<T>) => boolean): Partial<T>;
3
+ export declare function deeplyCombineObjects<OriginalObjectGeneric extends object, OverwriteObjectGeneric extends object>(originalObject: OriginalObjectGeneric, overwriteObject: OverwriteObjectGeneric): Overwrite<OriginalObjectGeneric, OverwriteObjectGeneric>;
4
+ export declare function filterToDifferentValues<T extends object>(baseObject: T, changedObject: T): Partial<T>;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filterObject = void 0;
3
+ exports.filterToDifferentValues = exports.deeplyCombineObjects = exports.filterObject = void 0;
4
4
  const augment_vir_1 = require("augment-vir");
5
5
  function filterObject(fullObject, callback) {
6
- return (0, augment_vir_1.getEnumTypedKeys)(fullObject).reduce((accum, key) => {
6
+ return (0, augment_vir_1.getObjectTypedKeys)(fullObject).reduce((accum, key) => {
7
7
  const value = fullObject[key];
8
8
  if (callback(value, key, fullObject)) {
9
9
  accum[key] = value;
@@ -12,3 +12,34 @@ function filterObject(fullObject, callback) {
12
12
  }, {});
13
13
  }
14
14
  exports.filterObject = filterObject;
15
+ function deeplyCombineObjects(originalObject, overwriteObject) {
16
+ return (0, augment_vir_1.getObjectTypedKeys)(overwriteObject).reduce((accum, currentKey) => {
17
+ const currentNewValue = overwriteObject[currentKey];
18
+ const currentOldValue = (0, augment_vir_1.typedHasOwnProperty)(originalObject, currentKey) && originalObject[currentKey];
19
+ if ((0, augment_vir_1.isObject)(currentOldValue) && (0, augment_vir_1.isObject)(currentNewValue)) {
20
+ accum[currentKey] = deeplyCombineObjects(currentOldValue, currentNewValue);
21
+ }
22
+ else {
23
+ accum[currentKey] = currentNewValue;
24
+ }
25
+ return accum;
26
+ }, originalObject);
27
+ }
28
+ exports.deeplyCombineObjects = deeplyCombineObjects;
29
+ function filterToDifferentValues(baseObject, changedObject) {
30
+ return (0, augment_vir_1.getObjectTypedKeys)(baseObject).reduce((accum, key) => {
31
+ const beforeValue = baseObject[key];
32
+ const afterValue = changedObject[key];
33
+ if ((0, augment_vir_1.isObject)(beforeValue) && (0, augment_vir_1.isObject)(afterValue)) {
34
+ const innerDiff = filterToDifferentValues(beforeValue, afterValue);
35
+ if (Object.keys(innerDiff).length) {
36
+ accum[key] = filterToDifferentValues(beforeValue, afterValue);
37
+ }
38
+ }
39
+ else if (beforeValue !== afterValue) {
40
+ accum[key] = afterValue;
41
+ }
42
+ return accum;
43
+ }, {});
44
+ }
45
+ exports.filterToDifferentValues = filterToDifferentValues;
@@ -0,0 +1 @@
1
+ export declare function getFirstPartOfRelativePath(from: string, to: string): string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFirstPartOfRelativePath = void 0;
4
+ const path_1 = require("path");
5
+ function getFirstPartOfRelativePath(from, to) {
6
+ const relativePath = (0, path_1.relative)(from, to);
7
+ const split = relativePath.split(path_1.sep);
8
+ const firstPart = split[0];
9
+ if (!firstPart) {
10
+ throw new Error(`First pat of path was empty from: "${from}" to "${to}"`);
11
+ }
12
+ return firstPart;
13
+ }
14
+ exports.getFirstPartOfRelativePath = getFirstPartOfRelativePath;
@@ -0,0 +1 @@
1
+ export declare function formatCode(text: string, filePath: string): Promise<string>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.formatCode = void 0;
27
+ const fs_1 = require("fs");
28
+ const path_1 = require("path");
29
+ const prettier_1 = require("prettier");
30
+ async function formatCode(text, filePath) {
31
+ const repoPrettierRc = await Promise.resolve().then(() => __importStar(require(findNearestConfig(process.cwd()))));
32
+ const repoConfig = repoPrettierRc;
33
+ return (0, prettier_1.format)(text, {
34
+ ...repoConfig,
35
+ filepath: filePath,
36
+ });
37
+ }
38
+ exports.formatCode = formatCode;
39
+ function findNearestConfig(dir) {
40
+ const currentDirConfig = (0, path_1.join)(dir, '.prettierrc.js');
41
+ if ((0, fs_1.existsSync)(currentDirConfig)) {
42
+ return currentDirConfig;
43
+ }
44
+ else {
45
+ return findNearestConfig((0, path_1.dirname)(dir));
46
+ }
47
+ }
@@ -0,0 +1,2 @@
1
+ export declare type NonEmptyString<ExactStringGeneric extends string> = ExactStringGeneric extends '' ? never : ExactStringGeneric;
2
+ export declare function ensureNonEmptyString<StringGeneric extends string>(inputString: NonEmptyString<StringGeneric>): StringGeneric;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureNonEmptyString = void 0;
4
+ function ensureNonEmptyString(inputString) {
5
+ if (!inputString) {
6
+ throw new Error(`Expected a non-empty string.`);
7
+ }
8
+ return inputString;
9
+ }
10
+ exports.ensureNonEmptyString = ensureNonEmptyString;
@@ -1,2 +1,3 @@
1
1
  import { Constructor } from './type';
2
- export declare function assertInstanceOf<T>(input: unknown, classConstructor: Constructor<T>): asserts input is T;
2
+ export declare function assertInstanceOf<T>(input: unknown, classConstructor: Constructor<T>, message?: string): asserts input is T;
3
+ export declare function assertString(input: unknown, message?: string): asserts input is string;
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertInstanceOf = void 0;
3
+ exports.assertString = exports.assertInstanceOf = void 0;
4
4
  const chai_1 = require("chai");
5
- function assertInstanceOf(input, classConstructor) {
6
- chai_1.assert.instanceOf(input, classConstructor);
5
+ function assertInstanceOf(input, classConstructor, message) {
6
+ chai_1.assert.instanceOf(input, classConstructor, message);
7
7
  }
8
8
  exports.assertInstanceOf = assertInstanceOf;
9
+ function assertString(input, message) {
10
+ chai_1.assert.typeOf(input, 'string', message);
11
+ }
12
+ exports.assertString = assertString;
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const index_1 = require("./index");
5
+ index_1.virmator.runInCli();
@@ -1,6 +1,8 @@
1
- export declare const codeInMarkdownCommandDefinition: import("../cli-command/define-cli-command").CliCommandDefinition<{
1
+ export declare const codeInMarkdownCommandDefinition: import("../api/command/define-command").CommandDefinition<{
2
2
  commandName: "code-in-markdown";
3
3
  subCommandDescriptions: {
4
4
  readonly check: "Check that markdown files have their examples inserted and are up-to-date.";
5
5
  };
6
+ configFiles: {};
7
+ npmDeps: readonly ["markdown-code-example-inserter"];
6
8
  }>;
@@ -1,17 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.codeInMarkdownCommandDefinition = 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
- const package_name_1 = require("../../package-name");
7
- const define_cli_command_1 = require("../cli-command/define-cli-command");
8
- const run_shell_command_1 = require("../cli-command/run-shell-command");
9
- exports.codeInMarkdownCommandDefinition = (0, define_cli_command_1.defineCliCommand)({
4
+ const define_command_1 = require("../api/command/define-command");
5
+ const package_paths_1 = require("../file-paths/package-paths");
6
+ exports.codeInMarkdownCommandDefinition = (0, define_command_1.defineCommand)({
10
7
  commandName: 'code-in-markdown',
11
8
  subCommandDescriptions: {
12
9
  check: 'Check that markdown files have their examples inserted and are up-to-date.',
13
10
  },
14
- }, ({ commandName }) => {
11
+ configFiles: {},
12
+ npmDeps: ['markdown-code-example-inserter'],
13
+ }, ({ commandName, packageBinName }) => {
15
14
  return {
16
15
  sections: [
17
16
  {
@@ -20,7 +19,7 @@ exports.codeInMarkdownCommandDefinition = (0, define_cli_command_1.defineCliComm
20
19
  },
21
20
  {
22
21
  title: '',
23
- content: `By default this command parses all markdown files in the repo (ignoring node_modules). Specific markdown files can be parsed by giving ${package_name_1.packageName} extra parameters.`,
22
+ content: `By default this command parses all markdown files in the repo (ignoring node_modules). Specific markdown files can be parsed by giving ${packageBinName} extra parameters.`,
24
23
  },
25
24
  {
26
25
  title: '',
@@ -30,38 +29,38 @@ exports.codeInMarkdownCommandDefinition = (0, define_cli_command_1.defineCliComm
30
29
  examples: [
31
30
  {
32
31
  title: 'default experience (usually all you need)',
33
- content: `${package_name_1.packageName} ${commandName}`,
32
+ content: `${packageBinName} ${commandName}`,
34
33
  },
35
34
  {
36
35
  title: 'checking if files are up-to-date',
37
- content: `${package_name_1.packageName} ${commandName} check`,
36
+ content: `${packageBinName} ${commandName} check`,
38
37
  },
39
38
  {
40
39
  title: 'override files to check to a single file',
41
- content: `${package_name_1.packageName} ${commandName} only/this/one/file.md`,
40
+ content: `${packageBinName} ${commandName} only/this/one/file.md`,
42
41
  },
43
42
  {
44
43
  title: 'override files to check to a group of files',
45
- content: `${package_name_1.packageName} ${commandName} "only/this/dir/*.md"`,
44
+ content: `${packageBinName} ${commandName} "only/this/dir/*.md"`,
46
45
  },
47
46
  ],
48
47
  };
49
- }, async (inputs) => {
48
+ }, (inputs) => {
50
49
  const args = inputs.filteredInputArgs.length
51
- ? (0, node_only_1.interpolationSafeWindowsPath)(inputs.filteredInputArgs.join(' '))
52
- : `\"./**/*.md\"`;
50
+ ? inputs.filteredInputArgs
51
+ : [`\"./**/*.md\"`];
53
52
  const subCommand = inputs.inputSubCommands.includes(inputs.subCommands.check)
54
53
  ? '--check'
55
54
  : '';
56
- const mdCodeCommand = `${(0, virmator_package_paths_1.getNpmBinPath)('md-code')} ${subCommand} ${args}`;
57
- const results = await (0, run_shell_command_1.runVirmatorShellCommand)(mdCodeCommand, {
58
- ...inputs,
59
- logTransforms: {
60
- stderr: (stderrInput) => stderrInput.replace('Run without --check to update.', 'Run without the "check" sub-command in order to update.'),
61
- },
62
- });
55
+ const logTransforms = {
56
+ stderr: (stderrInput) => stderrInput.replace('Run without --check to update.', 'Run without the "check" sub-command in order to update.'),
57
+ };
63
58
  return {
64
- fullExecutedCommand: mdCodeCommand,
65
- success: !results.exitCode,
59
+ mainCommand: (0, package_paths_1.getNpmBinPath)('md-code'),
60
+ logTransforms,
61
+ args: [
62
+ subCommand,
63
+ ...args,
64
+ ],
66
65
  };
67
66
  });
@@ -0,0 +1,14 @@
1
+ export declare const compileCommandDefinition: import("../api/command/define-command").CommandDefinition<{
2
+ commandName: "compile";
3
+ subCommandDescriptions: {
4
+ readonly check: "Run type checking without emitting compiled files.";
5
+ };
6
+ configFiles: {
7
+ readonly tsConfig: {
8
+ readonly copyFromInternalPath: string;
9
+ readonly copyToPathRelativeToRepoDir: "tsconfig.json";
10
+ readonly required: true;
11
+ };
12
+ };
13
+ npmDeps: readonly ["typescript"];
14
+ }>;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compileCommandDefinition = void 0;
4
+ const path_1 = require("path");
5
+ const define_command_1 = require("../api/command/define-command");
6
+ const package_paths_1 = require("../file-paths/package-paths");
7
+ exports.compileCommandDefinition = (0, define_command_1.defineCommand)({
8
+ commandName: 'compile',
9
+ subCommandDescriptions: {
10
+ check: 'Run type checking without emitting compiled files.',
11
+ },
12
+ configFiles: {
13
+ tsConfig: {
14
+ copyFromInternalPath: (0, path_1.join)(package_paths_1.virmatorConfigsDir, 'tsconfig.json'),
15
+ copyToPathRelativeToRepoDir: 'tsconfig.json',
16
+ required: true,
17
+ },
18
+ },
19
+ npmDeps: ['typescript'],
20
+ }, ({ commandName, packageBinName }) => {
21
+ return {
22
+ sections: [
23
+ {
24
+ title: '',
25
+ content: `compile typescript files
26
+ Pass any extra tsc flags to this command.`,
27
+ },
28
+ ],
29
+ examples: [
30
+ {
31
+ title: `no extra flags`,
32
+ content: `${packageBinName} ${commandName}`,
33
+ },
34
+ {
35
+ title: `one extra flag`,
36
+ content: `${packageBinName} ${commandName} --noEmit`,
37
+ },
38
+ ],
39
+ };
40
+ }, (inputs) => {
41
+ const shouldNotEmit = inputs.filteredInputArgs.join(' ').includes('--noEmit') ||
42
+ inputs.inputSubCommands.includes(inputs.subCommands.check);
43
+ const resetCommand = shouldNotEmit ? '' : 'rm -rf dist && ';
44
+ const noEmit = shouldNotEmit ? '--noEmit' : '';
45
+ const mainCommand = `${resetCommand}${(0, package_paths_1.getNpmBinPath)('tsc')}`;
46
+ return {
47
+ mainCommand,
48
+ args: [
49
+ '--pretty',
50
+ noEmit,
51
+ ...inputs.filteredInputArgs.map((arg) => `"${arg}"`),
52
+ ],
53
+ };
54
+ });
@@ -0,0 +1,2 @@
1
+ import { ConfigFileDefinition } from '../../api/config/config-file-definition';
2
+ export declare const nonCommandConfigs: ReadonlyArray<ConfigFileDefinition>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonCommandConfigs = void 0;
4
+ const path_1 = require("path");
5
+ const package_paths_1 = require("../../file-paths/package-paths");
6
+ const combine_json_config_1 = require("./combine-json-config");
7
+ const combine_text_config_1 = require("./combine-text-config");
8
+ const create_default_package_json_1 = require("./create-default-package-json");
9
+ exports.nonCommandConfigs = [
10
+ {
11
+ copyFromInternalPath: (0, path_1.join)(package_paths_1.virmatorConfigsDir, '.gitattributes'),
12
+ copyToPathRelativeToRepoDir: '.gitattributes',
13
+ required: true,
14
+ },
15
+ {
16
+ copyFromInternalPath: (0, path_1.join)(package_paths_1.virmatorConfigsDir, '.nvmrc'),
17
+ copyToPathRelativeToRepoDir: '.nvmrc',
18
+ required: true,
19
+ },
20
+ {
21
+ copyFromInternalPath: (0, path_1.join)(package_paths_1.virmatorConfigsDir, 'gitignore.txt'),
22
+ updateExistingConfigFileCallback: combine_text_config_1.combineTextConfig,
23
+ copyToPathRelativeToRepoDir: '.gitignore',
24
+ required: true,
25
+ },
26
+ {
27
+ copyFromInternalPath: (0, path_1.join)(package_paths_1.virmatorConfigsDir, 'npmignore.txt'),
28
+ updateExistingConfigFileCallback: combine_text_config_1.combineTextConfig,
29
+ copyToPathRelativeToRepoDir: '.npmignore',
30
+ required: true,
31
+ },
32
+ {
33
+ copyFromInternalPath: (0, path_1.join)(package_paths_1.virmatorConfigsDir, 'package.json'),
34
+ copyToPathRelativeToRepoDir: 'package.json',
35
+ updateExistingConfigFileCallback: create_default_package_json_1.createDefaultPackageJson,
36
+ required: true,
37
+ },
38
+ {
39
+ copyFromInternalPath: (0, path_1.join)(package_paths_1.virmatorConfigsDir, '.vscode', 'settings.json'),
40
+ copyToPathRelativeToRepoDir: (0, path_1.join)('.vscode', 'settings.json'),
41
+ updateExistingConfigFileCallback: combine_json_config_1.combineJsonConfig,
42
+ required: true,
43
+ },
44
+ ];
@@ -0,0 +1,2 @@
1
+ import { UpdateConfigCallback } from '../../api/config/config-file-definition';
2
+ export declare function combineJsonConfig(...[newConfigContents, existingConfigContents,]: Parameters<UpdateConfigCallback>): Promise<string>;