virmator 12.0.4 → 13.0.1

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 (158) hide show
  1. package/README.md +224 -129
  2. package/dist/cli.d.ts +1 -1
  3. package/dist/cli.js +21 -5
  4. package/dist/index.d.ts +1416 -1310
  5. package/dist/index.js +25 -63
  6. package/dist/tests/test-virmator.mock.d.ts +3 -0
  7. package/dist/tests/test-virmator.mock.js +5 -0
  8. package/package.json +25 -69
  9. package/src/cli.ts +29 -0
  10. package/src/index.ts +26 -0
  11. package/src/tests/test-virmator.mock.ts +13 -0
  12. package/base-configs/base-cspell.js +0 -272
  13. package/base-configs/base-mocharc.cjs +0 -20
  14. package/base-configs/base-nyc.js +0 -40
  15. package/base-configs/base-prettierrc.js +0 -32
  16. package/base-configs/base-web-test-runner.mjs +0 -137
  17. package/base-configs/test-files-glob.js +0 -13
  18. package/base-configs/tsconfig.base.json +0 -32
  19. package/configs/.gitattributes +0 -2
  20. package/configs/.github/workflows/build-for-gh-pages.yml +0 -24
  21. package/configs/.github/workflows/tagged-release.yml +0 -41
  22. package/configs/.github/workflows/tests.yml +0 -25
  23. package/configs/.nvmrc +0 -1
  24. package/configs/.prettierignore +0 -11
  25. package/configs/.prettierrc.js +0 -13
  26. package/configs/.vscode/settings.json +0 -50
  27. package/configs/LICENSE-CC0 +0 -121
  28. package/configs/LICENSE-MIT +0 -21
  29. package/configs/configs/dep-cruiser.config.ts +0 -22
  30. package/configs/configs/mocha.config.cjs +0 -8
  31. package/configs/configs/ncu.config.ts +0 -12
  32. package/configs/configs/nyc.config.js +0 -7
  33. package/configs/configs/typedoc.config.ts +0 -20
  34. package/configs/configs/vite.config.ts +0 -14
  35. package/configs/configs/web-test-runner.config.mjs +0 -21
  36. package/configs/cspell.config.cjs +0 -11
  37. package/configs/dep-cruiser.config.ts +0 -22
  38. package/configs/gitignore.txt +0 -13
  39. package/configs/ncu.config.ts +0 -13
  40. package/configs/npmignore.txt +0 -26
  41. package/configs/package.json +0 -23
  42. package/configs/src/index.html +0 -12
  43. package/configs/src/ui/elements/vir-app.element.ts +0 -10
  44. package/configs/tsconfig.json +0 -16
  45. package/configs/www-static/_redirects +0 -1
  46. package/configs/www-static/index.css +0 -7
  47. package/cspell.config.cjs +0 -13
  48. package/dist/api/command/command-configs.d.ts +0 -3
  49. package/dist/api/command/command-configs.js +0 -10
  50. package/dist/api/command/command-description.d.ts +0 -8
  51. package/dist/api/command/command-description.js +0 -2
  52. package/dist/api/command/command-executor.d.ts +0 -30
  53. package/dist/api/command/command-executor.js +0 -6
  54. package/dist/api/command/command-help.d.ts +0 -8
  55. package/dist/api/command/command-help.js +0 -2
  56. package/dist/api/command/command-logging.d.ts +0 -11
  57. package/dist/api/command/command-logging.js +0 -17
  58. package/dist/api/command/command-mapping.d.ts +0 -7
  59. package/dist/api/command/command-mapping.js +0 -9
  60. package/dist/api/command/command-messages.d.ts +0 -1
  61. package/dist/api/command/command-messages.js +0 -9
  62. package/dist/api/command/command-to-help-message.d.ts +0 -9
  63. package/dist/api/command/command-to-help-message.js +0 -175
  64. package/dist/api/command/define-command-inputs.d.ts +0 -22
  65. package/dist/api/command/define-command-inputs.js +0 -8
  66. package/dist/api/command/define-command.d.ts +0 -22
  67. package/dist/api/command/define-command.js +0 -41
  68. package/dist/api/config/config-file-definition.d.ts +0 -15
  69. package/dist/api/config/config-file-definition.js +0 -2
  70. package/dist/api/config/config-paths.d.ts +0 -7
  71. package/dist/api/config/config-paths.js +0 -7
  72. package/dist/api/config/copy-config.d.ts +0 -27
  73. package/dist/api/config/copy-config.js +0 -98
  74. package/dist/api/create-virmator.d.ts +0 -8
  75. package/dist/api/create-virmator.js +0 -67
  76. package/dist/api/run-command/check-npm-deps.d.ts +0 -8
  77. package/dist/api/run-command/check-npm-deps.js +0 -111
  78. package/dist/api/run-command/extract-arguments.d.ts +0 -6
  79. package/dist/api/run-command/extract-arguments.js +0 -36
  80. package/dist/api/run-command/run-command-executor.d.ts +0 -5
  81. package/dist/api/run-command/run-command-executor.js +0 -50
  82. package/dist/api/run-command/run-extended-virmator.d.ts +0 -10
  83. package/dist/api/run-command/run-extended-virmator.js +0 -53
  84. package/dist/api/run-command/run-shell-command.d.ts +0 -8
  85. package/dist/api/run-command/run-shell-command.js +0 -21
  86. package/dist/api/virmator-types.d.ts +0 -18
  87. package/dist/api/virmator-types.js +0 -2
  88. package/dist/augments/array.d.ts +0 -1
  89. package/dist/augments/array.js +0 -6
  90. package/dist/augments/console.d.ts +0 -9
  91. package/dist/augments/console.js +0 -43
  92. package/dist/augments/fs.d.ts +0 -11
  93. package/dist/augments/fs.js +0 -71
  94. package/dist/augments/git.d.ts +0 -1
  95. package/dist/augments/git.js +0 -12
  96. package/dist/augments/json.d.ts +0 -1
  97. package/dist/augments/json.js +0 -11
  98. package/dist/augments/npm.d.ts +0 -11
  99. package/dist/augments/npm.js +0 -52
  100. package/dist/augments/object.d.ts +0 -4
  101. package/dist/augments/object.js +0 -44
  102. package/dist/augments/path.d.ts +0 -1
  103. package/dist/augments/path.js +0 -12
  104. package/dist/augments/prettier.d.ts +0 -1
  105. package/dist/augments/prettier.js +0 -52
  106. package/dist/augments/regexp.d.ts +0 -1
  107. package/dist/augments/regexp.js +0 -6
  108. package/dist/augments/string.d.ts +0 -2
  109. package/dist/augments/string.js +0 -9
  110. package/dist/augments/type.d.ts +0 -1
  111. package/dist/augments/type.js +0 -2
  112. package/dist/augments/typescript-config-file.d.ts +0 -5
  113. package/dist/augments/typescript-config-file.js +0 -62
  114. package/dist/commands/compile.command.d.ts +0 -84
  115. package/dist/commands/compile.command.js +0 -58
  116. package/dist/commands/deps.command.d.ts +0 -144
  117. package/dist/commands/deps.command.js +0 -208
  118. package/dist/commands/docs.command.d.ts +0 -99
  119. package/dist/commands/docs.command.js +0 -192
  120. package/dist/commands/extra-configs/all-extra-configs.d.ts +0 -2
  121. package/dist/commands/extra-configs/all-extra-configs.js +0 -71
  122. package/dist/commands/extra-configs/combine-json-config.d.ts +0 -2
  123. package/dist/commands/extra-configs/combine-json-config.js +0 -21
  124. package/dist/commands/extra-configs/combine-text-config.d.ts +0 -2
  125. package/dist/commands/extra-configs/combine-text-config.js +0 -26
  126. package/dist/commands/extra-configs/create-default-package-json.d.ts +0 -1
  127. package/dist/commands/extra-configs/create-default-package-json.js +0 -86
  128. package/dist/commands/format.command.d.ts +0 -215
  129. package/dist/commands/format.command.js +0 -157
  130. package/dist/commands/frontend.command.d.ts +0 -149
  131. package/dist/commands/frontend.command.js +0 -140
  132. package/dist/commands/init.command.d.ts +0 -163
  133. package/dist/commands/init.command.js +0 -53
  134. package/dist/commands/publish.command.d.ts +0 -33
  135. package/dist/commands/publish.command.js +0 -193
  136. package/dist/commands/spellcheck.command.d.ts +0 -74
  137. package/dist/commands/spellcheck.command.js +0 -60
  138. package/dist/commands/test-web.command.d.ts +0 -189
  139. package/dist/commands/test-web.command.js +0 -125
  140. package/dist/commands/test.command.d.ts +0 -224
  141. package/dist/commands/test.command.js +0 -100
  142. package/dist/commands/update-configs.command.d.ts +0 -33
  143. package/dist/commands/update-configs.command.js +0 -35
  144. package/dist/compiled-base-configs/base-dep-cruiser.config.d.ts +0 -195
  145. package/dist/compiled-base-configs/base-dep-cruiser.config.js +0 -206
  146. package/dist/compiled-base-configs/base-ncu.d.ts +0 -6
  147. package/dist/compiled-base-configs/base-ncu.js +0 -16
  148. package/dist/compiled-base-configs/base-typedoc.d.ts +0 -3
  149. package/dist/compiled-base-configs/base-typedoc.js +0 -36
  150. package/dist/compiled-base-configs/base-vite.d.ts +0 -27
  151. package/dist/compiled-base-configs/base-vite.js +0 -74
  152. package/dist/compiled-base-configs/vite-always-reload-plugin.d.ts +0 -10
  153. package/dist/compiled-base-configs/vite-always-reload-plugin.js +0 -99
  154. package/dist/file-paths/package-paths.d.ts +0 -12
  155. package/dist/file-paths/package-paths.js +0 -46
  156. package/dist/scripts/save-help-message.d.ts +0 -1
  157. package/dist/scripts/save-help-message.js +0 -33
  158. package/mocha.config.cjs +0 -16
@@ -1,13 +0,0 @@
1
- import {RunOptions} from 'npm-check-updates';
2
- import {baseNcuConfig} from 'virmator/dist/compiled-base-configs/base-ncu';
3
-
4
- export const ncuConfig: RunOptions = {
5
- ...baseNcuConfig,
6
- // exclude these
7
- reject: [
8
- ...baseNcuConfig.reject,
9
- 'glob',
10
- ],
11
- // include only these
12
- filter: [],
13
- };
@@ -1,26 +0,0 @@
1
- .*
2
- .not-committed/
3
- *.book-helper.*
4
- *.book.*
5
- *.d.ts.map
6
- *.test-helper.*
7
- *.test.*
8
- *.tgz
9
- **/*/readme-examples/
10
- **/*/test/
11
- /configs/
12
- /coverage/
13
- /cspell.config.cjs
14
- /graphics/
15
- /Icon?
16
- /src/
17
- /www-static/
18
- bash-scripts/
19
- dist-docs/
20
- generated-config-*
21
- index.html
22
- test-files/
23
- todo.md
24
- ts.out/
25
- tsconfig.tsbuildinfo
26
- tsconfig*.json
@@ -1,23 +0,0 @@
1
- {
2
- "license": "(MIT or CC0 1.0)",
3
- "main": "dist/index.js",
4
- "types": "dist/index.d.ts",
5
- "scripts": {
6
- "build": "virmator frontend build",
7
- "compile": "virmator compile",
8
- "docs": "virmator docs",
9
- "format": "virmator format",
10
- "preview": "virmator frontend preview",
11
- "publish": "virmator publish \"npm run compile && npm run test:all\"",
12
- "start": "virmator frontend",
13
- "test": "virmator test",
14
- "test:all": "concurrently --colors --kill-others-on-fail -c auto --names types,tests,spelling,format,docs,deps \"npm run test:types\" \"npm run test:coverage\" \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\" \"npm run test:deps\"",
15
- "test:coverage": "npm run test coverage",
16
- "test:deps": "virmator deps check",
17
- "test:docs": "virmator docs check",
18
- "test:format": "virmator format check",
19
- "test:spelling": "virmator spellcheck",
20
- "test:types": "tsc --noEmit",
21
- "test:web": "virmator test-web"
22
- }
23
- }
@@ -1,12 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>Page Name</title>
5
- <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
6
- <script type="module" src="./ui/elements/vir-app.element.ts"></script>
7
- <link rel="stylesheet" type="text/css" href="/index.css" />
8
- </head>
9
- <body>
10
- <vir-app></vir-app>
11
- </body>
12
- </html>
@@ -1,10 +0,0 @@
1
- import {defineElementNoInputs, html} from 'element-vir';
2
-
3
- export const VirApp = defineElementNoInputs({
4
- tagName: 'vir-app',
5
- renderCallback() {
6
- return html`
7
- Vir App goes here!
8
- `;
9
- },
10
- });
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./dist",
4
- "rootDir": "./src"
5
- },
6
- "exclude": [
7
- "./configs",
8
- "./coverage",
9
- "./dist",
10
- "./dist-*",
11
- "./node_modules",
12
- "./test-files",
13
- "./ts.out"
14
- ],
15
- "extends": "virmator/base-configs/tsconfig.base.json"
16
- }
@@ -1 +0,0 @@
1
- /* /index.html 200
@@ -1,7 +0,0 @@
1
- html,
2
- body {
3
- margin: 0;
4
- padding: 0;
5
- height: 100%;
6
- width: 100%;
7
- }
package/cspell.config.cjs DELETED
@@ -1,13 +0,0 @@
1
- const {baseConfig} = require('./base-configs/base-cspell.js');
2
-
3
- module.exports = {
4
- ...baseConfig,
5
- ignorePaths: [
6
- ...baseConfig.ignorePaths,
7
- './test-files/spellcheck/bad',
8
- './test-files/test-expectations.json',
9
- ],
10
- words: [
11
- ...baseConfig.words,
12
- ],
13
- };
@@ -1,3 +0,0 @@
1
- import { ConfigFileDefinition } from '../config/config-file-definition';
2
- import { CommandMapping } from './command-mapping';
3
- export declare function extractAllConfigs(commandMapping: CommandMapping): ReadonlyArray<ConfigFileDefinition>;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractAllConfigs = extractAllConfigs;
4
- const common_1 = require("@augment-vir/common");
5
- function extractAllConfigs(commandMapping) {
6
- const configFiles = (0, common_1.getObjectTypedValues)(commandMapping)
7
- .map((commandDefinition) => (0, common_1.getObjectTypedValues)(commandDefinition.configFiles))
8
- .flat();
9
- return configFiles;
10
- }
@@ -1,8 +0,0 @@
1
- import { CommandDescription } from './command-help';
2
- import { DefineCommandInputs, SubCommandsMap } from './define-command-inputs';
3
- export type CreateDescriptionsInputs<DefineCommandInputsGeneric extends DefineCommandInputs> = Pick<DefineCommandInputsGeneric, 'commandName'> & {
4
- packageBinName: string;
5
- subCommands: SubCommandsMap<DefineCommandInputsGeneric>;
6
- configFiles: DefineCommandInputsGeneric['configFiles'];
7
- };
8
- export type CreateDescriptionsCallback<DefineCommandInputsGeneric extends DefineCommandInputs> = (inputs: CreateDescriptionsInputs<DefineCommandInputsGeneric>) => CommandDescription;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,30 +0,0 @@
1
- import { MaybePromise } from '@augment-vir/common';
2
- import { ConfigFileDefinition } from '../config/config-file-definition';
3
- import { CommandLogging, CommandLogTransforms } from './command-logging';
4
- import { DefineCommandInputs, SharedExecutorInputsAndCommandDefinition } from './define-command-inputs';
5
- export type CommandExecutorInputs<DefineCommandInputsGeneric extends DefineCommandInputs = DefineCommandInputs> = {
6
- filteredInputArgs: string[];
7
- inputSubCommands: (keyof DefineCommandInputsGeneric['subCommandDescriptions'])[];
8
- repoDir: string;
9
- allConfigs: ReadonlyArray<ConfigFileDefinition>;
10
- packageDir: string;
11
- logging: CommandLogging;
12
- packageBinName: string;
13
- };
14
- export type CommandExecutorDefinitionInputs<DefineCommandInputsGeneric extends DefineCommandInputs = DefineCommandInputs> = CommandExecutorInputs<DefineCommandInputsGeneric> & SharedExecutorInputsAndCommandDefinition<DefineCommandInputsGeneric>;
15
- export type DetailedArg = {
16
- arg: string;
17
- skipWindowsInterpolation: true;
18
- };
19
- export type SuccessOnlyExecutorOutput = {
20
- success: boolean;
21
- };
22
- export type BashCommandExecutorOutput = {
23
- logTransforms?: CommandLogTransforms;
24
- args: (string | DetailedArg)[];
25
- postExecute?: () => MaybePromise<void>;
26
- };
27
- export declare function isCompletedExecutor(executorOutput: CommandExecutorOutput): executorOutput is SuccessOnlyExecutorOutput;
28
- export type CommandExecutorOutput = BashCommandExecutorOutput | SuccessOnlyExecutorOutput;
29
- export type CommandExecutorDefinition<DefineCommandInputsGeneric extends DefineCommandInputs> = (inputs: CommandExecutorDefinitionInputs<DefineCommandInputsGeneric>) => Promise<CommandExecutorOutput> | CommandExecutorOutput;
30
- export type CommandExecutor<DefineCommandInputsGeneric extends DefineCommandInputs> = (inputs: CommandExecutorInputs<DefineCommandInputsGeneric>) => Promise<CommandExecutorOutput> | CommandExecutorOutput;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isCompletedExecutor = isCompletedExecutor;
4
- function isCompletedExecutor(executorOutput) {
5
- return 'success' in executorOutput;
6
- }
@@ -1,8 +0,0 @@
1
- export type HelpSection = Readonly<{
2
- title: string;
3
- content: string;
4
- }>;
5
- export type CommandDescription = Readonly<{
6
- sections: Readonly<HelpSection[]>;
7
- examples: Readonly<HelpSection[]>;
8
- }>;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +0,0 @@
1
- export type CommandLogCallback = (thingToLog: string) => void;
2
- export type CommandLogging = {
3
- stdout: CommandLogCallback;
4
- stderr: CommandLogCallback;
5
- };
6
- export declare const noCommandLogging: Readonly<Required<CommandLogging>>;
7
- export declare const defaultConsoleLogging: Readonly<Required<CommandLogging>>;
8
- export type CommandLogs = Record<keyof CommandLogging, string>;
9
- export declare const identityCommandLogTransform: CommandLogTransform;
10
- export type CommandLogTransform = (thingToTransform: string) => string;
11
- export type CommandLogTransforms = Partial<Record<keyof CommandLogging, CommandLogTransform>>;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.identityCommandLogTransform = exports.defaultConsoleLogging = exports.noCommandLogging = void 0;
4
- exports.noCommandLogging = {
5
- stderr: () => { },
6
- stdout: () => { },
7
- };
8
- exports.defaultConsoleLogging = {
9
- stdout: (input) => {
10
- process.stdout.write(input.replace(/\n$/, '') + '\n');
11
- },
12
- stderr: (input) => {
13
- process.stderr.write(input.replace(/\n$/, '') + '\n');
14
- },
15
- };
16
- const identityCommandLogTransform = (input) => input;
17
- exports.identityCommandLogTransform = identityCommandLogTransform;
@@ -1,7 +0,0 @@
1
- import { ArrayElement } from '@augment-vir/common';
2
- import { CommandDefinition } from './define-command';
3
- export type CommandMapping = Record<string, CommandDefinition>;
4
- export declare function commandsToMapping(commands: ReadonlyArray<CommandDefinition>): Readonly<CommandMapping>;
5
- export type CommandDefinitionArrayToMapping<DefinitionArray extends ReadonlyArray<CommandDefinition>> = {
6
- [CommandName in ArrayElement<DefinitionArray>['commandName']]: CommandDefinition;
7
- };
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.commandsToMapping = commandsToMapping;
4
- function commandsToMapping(commands) {
5
- return commands.reduce((mapping, currentCommandDefinition) => {
6
- mapping[currentCommandDefinition.commandName] = currentCommandDefinition;
7
- return mapping;
8
- }, {});
9
- }
@@ -1 +0,0 @@
1
- export declare function getCommandResultMessage(commandName: string, success: boolean): string;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCommandResultMessage = getCommandResultMessage;
4
- const node_js_1 = require("@augment-vir/node-js");
5
- function getCommandResultMessage(commandName, success) {
6
- const specificColor = success ? node_js_1.logColors.success : node_js_1.logColors.error;
7
- const specificPhrase = success ? 'succeeded' : 'failed';
8
- return `${node_js_1.logColors.bold}${specificColor}${commandName} ${specificPhrase}.${node_js_1.logColors.reset}`;
9
- }
@@ -1,9 +0,0 @@
1
- import { CommandMapping } from './command-mapping';
2
- import { CommandDefinition } from './define-command';
3
- export declare enum HelpMessageSyntax {
4
- Cli = "cli",
5
- Markdown = "markdown"
6
- }
7
- export declare function generateHelpMessage(packageBinName: string, commandDefinitions: Readonly<CommandMapping>, syntax: HelpMessageSyntax, cliWrapIfMoreThanThisManyColumns?: number): string;
8
- export declare function flagToHelpString(flagName: string, description: string, syntax: HelpMessageSyntax): string;
9
- export declare function commandToHelpString(packageBinName: string, commandDefinition: CommandDefinition, syntax: HelpMessageSyntax): string;
@@ -1,175 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HelpMessageSyntax = void 0;
4
- exports.generateHelpMessage = generateHelpMessage;
5
- exports.flagToHelpString = flagToHelpString;
6
- exports.commandToHelpString = commandToHelpString;
7
- const common_1 = require("@augment-vir/common");
8
- const node_js_1 = require("@augment-vir/node-js");
9
- var HelpMessageSyntax;
10
- (function (HelpMessageSyntax) {
11
- HelpMessageSyntax["Cli"] = "cli";
12
- HelpMessageSyntax["Markdown"] = "markdown";
13
- })(HelpMessageSyntax || (exports.HelpMessageSyntax = HelpMessageSyntax = {}));
14
- function generateHelpMessage(packageBinName, commandDefinitions, syntax, cliWrapIfMoreThanThisManyColumns = 100) {
15
- const commandsMessage = [...(0, common_1.getObjectTypedKeys)(commandDefinitions)]
16
- .sort()
17
- .map((commandName) => {
18
- const commandDefinition = commandDefinitions[commandName];
19
- if (!commandDefinition) {
20
- throw new Error(`Command definition was missing for key "${commandName}"`);
21
- }
22
- return commandToHelpString(packageBinName, commandDefinition, syntax);
23
- })
24
- .join('\n');
25
- const helpMessage = combineHelpMessage(packageBinName, commandsMessage, syntax);
26
- return syntax === HelpMessageSyntax.Cli
27
- ? wrapLines(helpMessage, cliWrapIfMoreThanThisManyColumns)
28
- : helpMessage;
29
- }
30
- const formatting = ((input) => input)({
31
- h1: {
32
- [HelpMessageSyntax.Cli]: `${node_js_1.logColors.info}`,
33
- [HelpMessageSyntax.Markdown]: '# ',
34
- },
35
- h2: {
36
- [HelpMessageSyntax.Cli]: `${node_js_1.logColors.bold}${node_js_1.logColors.info}`,
37
- [HelpMessageSyntax.Markdown]: '## ',
38
- },
39
- h3: {
40
- [HelpMessageSyntax.Cli]: ``,
41
- [HelpMessageSyntax.Markdown]: '### ',
42
- },
43
- reset: {
44
- [HelpMessageSyntax.Cli]: `${node_js_1.logColors.reset}`,
45
- [HelpMessageSyntax.Markdown]: '',
46
- },
47
- indent: {
48
- [HelpMessageSyntax.Cli]: ` `,
49
- [HelpMessageSyntax.Markdown]: '',
50
- },
51
- colon: {
52
- [HelpMessageSyntax.Cli]: `:`,
53
- [HelpMessageSyntax.Markdown]: '',
54
- },
55
- bullet: {
56
- [HelpMessageSyntax.Cli]: `- `,
57
- [HelpMessageSyntax.Markdown]: ' - ',
58
- },
59
- });
60
- function formatWithSyntax(key, syntax) {
61
- return formatting[key][syntax];
62
- }
63
- function code(input, block, indent, syntax) {
64
- if (syntax === HelpMessageSyntax.Markdown) {
65
- if (block) {
66
- return `\n${indent}\`\`\`\n${indent}${input
67
- .split('\n')
68
- .join(`\n${indent}`)}\n${indent}\`\`\`\n`;
69
- }
70
- else {
71
- return `${indent}\`${input}\``;
72
- }
73
- }
74
- else {
75
- return input;
76
- }
77
- }
78
- function flagToHelpString(flagName, description, syntax) {
79
- const format = (key) => formatWithSyntax(key, syntax);
80
- return `${indent(1, syntax)}${format('h2')}${code(flagName, false, '', syntax)}${format('reset')}${format('colon')}\n${indent(2, syntax)}${description.trim()}`;
81
- }
82
- function commandToHelpString(packageBinName, commandDefinition, syntax) {
83
- const commandDescription = commandDefinition.createDescription({
84
- packageBinName,
85
- commandName: commandDefinition.commandName,
86
- subCommands: commandDefinition.subCommands,
87
- configFiles: commandDefinition.configFiles,
88
- });
89
- const format = (key) => formatWithSyntax(key, syntax);
90
- const title = `${indent(1, syntax)}${format('h2')}${commandDefinition.commandName}${format('reset')}${format('colon')}`;
91
- const description = commandDescriptionToMessage(commandDescription, syntax);
92
- const subCommandDescriptions = subCommandDescriptionsToMessage(commandDefinition.subCommandDescriptions, syntax);
93
- return `${title}\n${description}\n${subCommandDescriptions}\n`;
94
- }
95
- function subCommandDescriptionsToMessage(subCommandDescriptions, syntax) {
96
- return (0, common_1.getObjectTypedKeys)(subCommandDescriptions).reduce((accum, currentKey, index) => {
97
- const keyDescription = subCommandDescriptions[currentKey];
98
- const leadingLine = index > 0 ? '\n\n' : '';
99
- const fullDescription = `${leadingLine}${formatWithSyntax('h3', syntax)}${currentKey}${formatWithSyntax('colon', syntax)}\n${indent(2, syntax)}${keyDescription}`;
100
- return accum + fullDescription;
101
- }, '');
102
- }
103
- function indent(input, syntax) {
104
- return formatWithSyntax('indent', syntax).repeat(input);
105
- }
106
- function sectionToString(section, extraIndent, syntax, bullets) {
107
- const format = (key) => formatWithSyntax(key, syntax);
108
- const sectionIndent = indent(2 + extraIndent, syntax);
109
- const separator = syntax === HelpMessageSyntax.Cli || !bullets ? `:\n` : ': ';
110
- const header = bullets ? '' : format('h3');
111
- const title = section.title ? `${sectionIndent}${header}${section.title}${separator}` : '';
112
- if (bullets && syntax === HelpMessageSyntax.Markdown) {
113
- const isBlock = section.content.includes('\n');
114
- return `${format('bullet')}${title}${isBlock ? '\n' : ''}${code(section.content, isBlock, syntax === HelpMessageSyntax.Markdown && isBlock ? ' ' : '', syntax)}`;
115
- }
116
- else {
117
- const contentIndent = section.title ? indent(3 + extraIndent, syntax) : sectionIndent;
118
- return `${title}${contentIndent}${section.content.split('\n').join(`\n${contentIndent}`)}`;
119
- }
120
- }
121
- function commandDescriptionToMessage(description, syntax) {
122
- const format = (key) => formatWithSyntax(key, syntax);
123
- const sections = description.sections
124
- .map((section) => sectionToString(section, 0, syntax, false))
125
- .join('\n\n');
126
- const examples = description.examples
127
- .map((example) => sectionToString(example, 1, syntax, true))
128
- .join('\n');
129
- const examplesTitle = description.examples.length
130
- ? `\n\n${indent(2, syntax)}${format('h3')}Examples${format('reset')}${format('colon')}\n`
131
- : '';
132
- return `${sections}${examplesTitle}${examples}`;
133
- }
134
- function combineHelpMessage(packageBinName, commandsText, syntax) {
135
- const format = (key) => formatWithSyntax(key, syntax);
136
- return `${formatting.h1[syntax]}${packageBinName} usage${format('colon')}${format('reset')}
137
- ${format('indent')}${code(`[npx] ${packageBinName} [--flags] command subCommand`, true, '', syntax)}
138
-
139
- ${format('indent')}${code('npx', false, '', syntax)} is needed when the command is run directly from the terminal (not scoped within an npm script) unless the package has been globally installed (which will work just fine but I wouldn't recommend, simply because I prefer explicit dependencies).
140
-
141
- ${format('h1')}Available commands${format('colon')}${format('reset')}
142
- ${commandsText}`;
143
- }
144
- function getIndent(line) {
145
- return (0, common_1.safeMatch)(line, /^(\s*)/)[0] ?? '';
146
- }
147
- function wrapLines(input, limit) {
148
- const lines = input.split('\n');
149
- // using a for loop because the length of the array will get modified while iterating through it
150
- for (let index = 0; index < lines.length; index++) {
151
- const line = lines[index];
152
- if (line && line.length > limit) {
153
- const nextIndex = index + 1;
154
- const nextLine = lines[nextIndex] ?? '';
155
- const newLine = line.slice(0, limit);
156
- lines[index] = newLine.trimEnd();
157
- let wrappedPart = line.slice(limit);
158
- // didn't wrap on a space, we need to shift a word down
159
- if (!newLine.endsWith(' ') && !wrappedPart.startsWith(' ')) {
160
- const lastWord = (0, common_1.safeMatch)(newLine, /(\s\S+$)/)[0] ?? '';
161
- lines[index] = newLine.slice(0, -1 * lastWord.length).trimEnd();
162
- wrappedPart = `${lastWord}${wrappedPart.trim()}`;
163
- }
164
- const currentIndent = getIndent(line);
165
- const nextIndent = getIndent(nextLine);
166
- if (currentIndent === nextIndent) {
167
- lines[nextIndex] = `${currentIndent}${wrappedPart.trim()} ${nextLine.trim()}`;
168
- }
169
- else {
170
- lines.splice(nextIndex, 0, `${currentIndent}${wrappedPart.trim()}`);
171
- }
172
- }
173
- }
174
- return lines.join('\n').trimEnd();
175
- }
@@ -1,22 +0,0 @@
1
- import { ConfigFileDefinition } from '../config/config-file-definition';
2
- export declare enum NpmDepTypeEnum {
3
- Regular = "regular",
4
- Dev = "dev"
5
- }
6
- export type NpmDep = {
7
- name: string;
8
- type: NpmDepTypeEnum;
9
- };
10
- export type DefineCommandInputs<CommandName extends string = string> = Readonly<{
11
- commandName: CommandName;
12
- subCommandDescriptions: Readonly<Record<string, string>> | Readonly<{}>;
13
- configFiles: Readonly<Record<string, Readonly<ConfigFileDefinition>>> | Readonly<{}>;
14
- npmDeps: ReadonlyArray<NpmDep>;
15
- }>;
16
- export type SharedExecutorInputsAndCommandDefinition<DefineCommandInputsGeneric extends DefineCommandInputs> = DefineCommandInputsGeneric & {
17
- allAvailableSubCommands: ReadonlyArray<keyof DefineCommandInputsGeneric['subCommandDescriptions'] extends string ? keyof DefineCommandInputsGeneric['subCommandDescriptions'] : never>;
18
- subCommands: SubCommandsMap<DefineCommandInputsGeneric>;
19
- };
20
- export type SubCommandsMap<DefineCommandInputsGeneric extends DefineCommandInputs> = {
21
- [Prop in keyof DefineCommandInputsGeneric['subCommandDescriptions']]: Prop extends string ? Prop : never;
22
- };
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NpmDepTypeEnum = void 0;
4
- var NpmDepTypeEnum;
5
- (function (NpmDepTypeEnum) {
6
- NpmDepTypeEnum["Regular"] = "regular";
7
- NpmDepTypeEnum["Dev"] = "dev";
8
- })(NpmDepTypeEnum || (exports.NpmDepTypeEnum = NpmDepTypeEnum = {}));
@@ -1,22 +0,0 @@
1
- import { IsAny } from 'type-fest';
2
- import { CreateDescriptionsCallback } from './command-description';
3
- import { CommandExecutor, CommandExecutorDefinition } from './command-executor';
4
- import { DefineCommandInputs, SharedExecutorInputsAndCommandDefinition } from './define-command-inputs';
5
- export type ExtendCallback<DefineCommandInputsGeneric extends DefineCommandInputs = DefineCommandInputs<any>> = (inputs: {
6
- defineCommandInputs: Readonly<DefineCommandInputsGeneric>;
7
- createDescription: CreateDescriptionsCallback<DefineCommandInputsGeneric>;
8
- inputExecutor: CommandExecutorDefinition<DefineCommandInputsGeneric>;
9
- }) => CommandDefinition<DefineCommandInputsGeneric>;
10
- export type CommandDefinition<DefineCommandInputsGeneric extends DefineCommandInputs = any> = IsAny<DefineCommandInputsGeneric> extends true ? AnyCommandDefinition : SharedExecutorInputsAndCommandDefinition<DefineCommandInputsGeneric> & {
11
- executor: CommandExecutor<DefineCommandInputsGeneric>;
12
- createDescription: CreateDescriptionsCallback<DefineCommandInputsGeneric>;
13
- extend: ExtendCallback<DefineCommandInputsGeneric>;
14
- };
15
- export type AnyCommandDefinition = DefineCommandInputs & {
16
- allAvailableSubCommands: ReadonlyArray<string>;
17
- subCommands: Record<string, string>;
18
- executor: CommandExecutor<any>;
19
- createDescription: CreateDescriptionsCallback<any>;
20
- extend: ExtendCallback<any>;
21
- };
22
- export declare function defineCommand<DefineCommandInputsGeneric extends DefineCommandInputs>(defineCommandInputs: Readonly<DefineCommandInputsGeneric>, createDescription: CreateDescriptionsCallback<DefineCommandInputsGeneric>, inputExecutor: CommandExecutorDefinition<DefineCommandInputsGeneric>): CommandDefinition<DefineCommandInputsGeneric>;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineCommand = defineCommand;
4
- const common_1 = require("@augment-vir/common");
5
- function defineCommand(defineCommandInputs, createDescription, inputExecutor) {
6
- const allAvailableSubCommands = (0, common_1.getObjectTypedKeys)(defineCommandInputs.subCommandDescriptions);
7
- const subCommands = (0, common_1.mapObjectValues)(defineCommandInputs.subCommandDescriptions, (key) => key);
8
- const init = {
9
- ...defineCommandInputs,
10
- allAvailableSubCommands,
11
- subCommands,
12
- };
13
- const executor = async (executorInputs) => {
14
- return await inputExecutor({
15
- ...executorInputs,
16
- ...init,
17
- });
18
- };
19
- function extend(inputs) {
20
- return defineCommand({
21
- ...defineCommandInputs,
22
- ...inputs.defineCommandInputs,
23
- }, (callbackInputs) => {
24
- return {
25
- ...createDescription(callbackInputs),
26
- ...inputs.createDescription?.(callbackInputs),
27
- };
28
- }, async (callbackInputs) => {
29
- return {
30
- ...(await inputExecutor(callbackInputs)),
31
- ...(await inputs.inputExecutor?.(callbackInputs)),
32
- };
33
- });
34
- }
35
- return {
36
- ...init,
37
- executor,
38
- createDescription,
39
- extend,
40
- };
41
- }
@@ -1,15 +0,0 @@
1
- export type UpdateConfigCallback = (copyFromContents: string, existingConfigContents: string, repoDir: string) => string | Promise<string>;
2
- export type ConfigFileDefinition = {
3
- /** Path to the config file to copy. */
4
- copyFromInternalPath: string;
5
- /**
6
- * Path to the new file, relative to the repo root directory using this package, to which this
7
- * file should be copied.
8
- */
9
- copyToPathRelativeToRepoDir: string;
10
- /**
11
- * Used to modify the file contents before copying it over to a repo. The returned string should
12
- * be the new file contents.
13
- */
14
- updateExistingConfigFileCallback?: UpdateConfigCallback;
15
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
1
- import { ConfigFileDefinition } from './config-file-definition';
2
- export type GetCopyToPathInputs = {
3
- repoDir: string;
4
- packageDir: string;
5
- configFileDefinition: ConfigFileDefinition;
6
- };
7
- export declare function getCopyToPath({ repoDir, configFileDefinition }: GetCopyToPathInputs): string;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCopyToPath = getCopyToPath;
4
- const path_1 = require("path");
5
- function getCopyToPath({ repoDir, configFileDefinition }) {
6
- return (0, path_1.join)(repoDir, configFileDefinition.copyToPathRelativeToRepoDir);
7
- }
@@ -1,27 +0,0 @@
1
- import { CommandLogging } from '../command/command-logging';
2
- import { ConfigFileDefinition } from './config-file-definition';
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 type CopyConfigInputs = {
12
- configFileDefinition: ConfigFileDefinition;
13
- repoDir: string;
14
- packageDir: string;
15
- operation: CopyConfigOperation;
16
- };
17
- export type CopyConfigOutputs = {
18
- copiedToPath: string;
19
- shouldWrite: boolean;
20
- };
21
- export declare function copyConfig(inputs: CopyConfigInputs): Promise<CopyConfigOutputs>;
22
- export type CopyAllConfigFilesInputs = Omit<CopyConfigInputs, 'configFileDefinition'> & {
23
- logging: CommandLogging;
24
- configFiles: ReadonlyArray<ConfigFileDefinition>;
25
- };
26
- /** Returns success state. True if success, false is errors were encountered. */
27
- export declare function copyAllConfigFiles(inputs: CopyAllConfigFilesInputs): Promise<boolean>;