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.
- package/README.md +1 -14
- package/base-configs/base-cspell.js +83 -0
- package/base-configs/base-mocharc.js +14 -0
- package/{configs/.virmator/prettierrc-base.js → base-configs/base-prettierrc.js} +0 -0
- package/{configs/.virmator/tsconfig-base.json → base-configs/base-tsconfig.json} +0 -6
- package/{configs/.virmator/vite-base.ts → base-configs/base-vite.ts} +0 -0
- package/base-configs/test-files-glob.js +5 -0
- package/{configs/.virmator → base-configs}/vite-always-reload-plugin.ts +5 -3
- package/{configs/.virmator → base-configs}/web-test-runner-base.mjs +4 -5
- package/configs/.gitattributes +1 -0
- package/configs/.nvmrc +1 -0
- package/configs/.prettierignore +1 -1
- package/configs/.prettierrc.js +1 -1
- package/configs/{.mocharc.js → configs/.mocharc.js} +1 -1
- package/configs/{.virmator → configs}/vite.config.ts +1 -1
- package/configs/{.virmator → configs}/web-test-runner.config.mjs +1 -1
- package/configs/cspell.config.js +9 -0
- package/configs/gitignore.txt +1 -0
- package/configs/npmignore.txt +1 -0
- package/configs/package.json +9 -5
- package/configs/tsconfig.json +1 -1
- package/cspell.config.js +11 -0
- package/dist/{cli → api}/cli-color.d.ts +1 -0
- package/dist/{cli → api}/cli-color.js +1 -0
- package/dist/api/command/command-configs.d.ts +3 -0
- package/dist/api/command/command-configs.js +11 -0
- package/dist/api/command/command-description.d.ts +8 -0
- package/dist/{cli/cli-command/cli-command-help.js → api/command/command-description.js} +0 -0
- package/dist/api/command/command-executor.d.ts +28 -0
- package/dist/api/command/command-executor.js +7 -0
- package/dist/api/command/command-help.d.ts +8 -0
- package/dist/{package-name.js → api/command/command-help.js} +0 -2
- package/dist/api/command/command-logging.d.ts +11 -0
- package/dist/api/command/command-logging.js +17 -0
- package/dist/api/command/command-mapping.d.ts +7 -0
- package/dist/api/command/command-mapping.js +10 -0
- package/dist/api/command/command-messages.d.ts +1 -0
- package/dist/api/command/command-messages.js +10 -0
- package/dist/api/command/command-to-help-message.d.ts +9 -0
- package/dist/{cli/cli-command/cli-command-to-help-message.js → api/command/command-to-help-message.js} +41 -48
- package/dist/api/command/define-command-inputs.d.ts +14 -0
- package/dist/api/command/define-command-inputs.js +2 -0
- package/dist/api/command/define-command.d.ts +8 -0
- package/dist/api/command/define-command.js +25 -0
- package/dist/api/config/config-file-definition.d.ts +16 -0
- package/dist/api/config/config-file-definition.js +2 -0
- package/dist/api/config/config-paths.d.ts +7 -0
- package/dist/api/config/config-paths.js +8 -0
- package/dist/{cli → api}/config/copy-config.d.ts +5 -4
- package/dist/{cli → api}/config/copy-config.js +26 -28
- package/dist/api/create-virmator.d.ts +8 -0
- package/dist/api/create-virmator.js +65 -0
- package/dist/api/run-command/check-npm-deps.d.ts +7 -0
- package/dist/api/run-command/check-npm-deps.js +107 -0
- package/dist/api/run-command/extract-arguments.d.ts +6 -0
- package/dist/api/run-command/extract-arguments.js +37 -0
- package/dist/api/run-command/run-command-executor.d.ts +5 -0
- package/dist/api/run-command/run-command-executor.js +51 -0
- package/dist/api/run-command/run-extended-virmator.d.ts +10 -0
- package/dist/api/run-command/run-extended-virmator.js +53 -0
- package/dist/{cli/cli-command → api/run-command}/run-shell-command.d.ts +3 -3
- package/dist/{cli/cli-command → api/run-command}/run-shell-command.js +3 -3
- package/dist/api/virmator-types.d.ts +18 -0
- package/dist/api/virmator-types.js +2 -0
- package/dist/augments/fs.d.ts +5 -2
- package/dist/augments/fs.js +20 -8
- package/dist/augments/object.d.ts +3 -0
- package/dist/augments/object.js +33 -2
- package/dist/augments/path.d.ts +1 -0
- package/dist/augments/path.js +14 -0
- package/dist/augments/prettier.d.ts +1 -0
- package/dist/augments/prettier.js +47 -0
- package/dist/augments/string.d.ts +2 -0
- package/dist/augments/string.js +10 -0
- package/dist/augments/test.d.ts +2 -1
- package/dist/augments/test.js +7 -3
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +5 -0
- package/dist/{cli/cli-command-implementations → commands}/code-in-markdown.command.d.ts +3 -1
- package/dist/{cli/cli-command-implementations → commands}/code-in-markdown.command.js +23 -24
- package/dist/commands/compile.command.d.ts +14 -0
- package/dist/commands/compile.command.js +54 -0
- package/dist/commands/extra-configs/all-extra-configs.d.ts +2 -0
- package/dist/commands/extra-configs/all-extra-configs.js +44 -0
- package/dist/commands/extra-configs/combine-json-config.d.ts +2 -0
- package/dist/commands/extra-configs/combine-json-config.js +22 -0
- package/dist/commands/extra-configs/combine-text-config.d.ts +2 -0
- package/dist/{cli/config → commands/extra-configs}/combine-text-config.js +5 -5
- package/dist/{cli/config → commands/extra-configs}/create-default-package-json.d.ts +0 -0
- package/dist/{cli/config → commands/extra-configs}/create-default-package-json.js +30 -18
- package/dist/commands/format.command.d.ts +19 -0
- package/dist/{cli/cli-command-implementations → commands}/format.command.js +59 -33
- package/dist/commands/frontend.command.d.ts +15 -0
- package/dist/commands/frontend.command.js +78 -0
- package/dist/commands/init.command.d.ts +8 -0
- package/dist/commands/init.command.js +53 -0
- package/dist/commands/spellcheck.command.d.ts +12 -0
- package/dist/commands/spellcheck.command.js +54 -0
- package/dist/commands/test-web.command.d.ts +12 -0
- package/dist/commands/test-web.command.js +68 -0
- package/dist/commands/test.command.d.ts +12 -0
- package/dist/commands/test.command.js +67 -0
- package/dist/{cli/cli-command-implementations → commands}/update-configs.command.d.ts +3 -1
- package/dist/{cli/cli-command-implementations → commands}/update-configs.command.js +14 -10
- package/dist/file-paths/{virmator-package-paths.d.ts → package-paths.d.ts} +1 -1
- package/dist/file-paths/{virmator-package-paths.js → package-paths.js} +3 -4
- package/dist/index.d.ts +134 -1
- package/dist/index.js +55 -0
- package/dist/scripts/save-help-message.d.ts +1 -0
- package/dist/scripts/save-help-message.js +33 -0
- package/package.json +33 -28
- package/.gitattributes +0 -1
- package/.github/workflows/virmator-build-for-gh-pages.yml +0 -24
- package/.github/workflows/virmator-tagged-release.yml +0 -42
- package/.github/workflows/virmator-tests.yml +0 -26
- package/.mocharc.js +0 -9
- package/.prettierignore +0 -5
- package/configs/.cspell.json +0 -4
- package/configs/.virmator/.cspell-base.json +0 -81
- package/configs/.virmator/mocharc-base.js +0 -15
- package/configs/src/global.d.ts +0 -5
- package/dist/api/virmator-wrapper.d.ts +0 -5
- package/dist/api/virmator-wrapper.js +0 -9
- package/dist/cli/all-cli-command-definitions.d.ts +0 -56
- package/dist/cli/all-cli-command-definitions.js +0 -76
- package/dist/cli/cli-command/cli-command-help.d.ts +0 -8
- package/dist/cli/cli-command/cli-command-to-help-message.d.ts +0 -11
- package/dist/cli/cli-command/define-cli-command.d.ts +0 -41
- package/dist/cli/cli-command/define-cli-command.js +0 -29
- package/dist/cli/cli-command-implementations/compile.command.d.ts +0 -6
- package/dist/cli/cli-command-implementations/compile.command.js +0 -44
- package/dist/cli/cli-command-implementations/format.command.d.ts +0 -6
- package/dist/cli/cli-command-implementations/frontend.command.d.ts +0 -7
- package/dist/cli/cli-command-implementations/frontend.command.js +0 -45
- package/dist/cli/cli-command-implementations/init.command.d.ts +0 -6
- package/dist/cli/cli-command-implementations/init.command.js +0 -42
- package/dist/cli/cli-command-implementations/spellcheck.command.d.ts +0 -4
- package/dist/cli/cli-command-implementations/spellcheck.command.js +0 -40
- package/dist/cli/cli-command-implementations/test-web.command.d.ts +0 -4
- package/dist/cli/cli-command-implementations/test-web.command.js +0 -50
- package/dist/cli/cli-command-implementations/test.command.d.ts +0 -4
- package/dist/cli/cli-command-implementations/test.command.js +0 -53
- package/dist/cli/cli-flags/cli-flag-name.d.ts +0 -4
- package/dist/cli/cli-flags/cli-flag-name.js +0 -8
- package/dist/cli/cli-flags/cli-flag-values.d.ts +0 -4
- package/dist/cli/cli-flags/cli-flag-values.js +0 -19
- package/dist/cli/cli-messages.d.ts +0 -6
- package/dist/cli/cli-messages.js +0 -19
- package/dist/cli/cli.d.ts +0 -2
- package/dist/cli/cli.js +0 -54
- package/dist/cli/config/combine-text-config.d.ts +0 -2
- package/dist/cli/config/config-files.d.ts +0 -133
- package/dist/cli/config/config-files.js +0 -138
- package/dist/cli/is-global.d.ts +0 -1
- package/dist/cli/is-global.js +0 -10
- package/dist/cli/parse-arguments.d.ts +0 -8
- package/dist/cli/parse-arguments.js +0 -42
- package/dist/cli/run-cli-command.d.ts +0 -13
- package/dist/cli/run-cli-command.js +0 -52
- package/dist/cli/run-command.test-helper.d.ts +0 -28
- package/dist/cli/run-command.test-helper.js +0 -87
- package/dist/errors/virmator-cli.error.d.ts +0 -3
- package/dist/errors/virmator-cli.error.js +0 -10
- package/dist/errors/virmator-config-file.error.d.ts +0 -4
- package/dist/errors/virmator-config-file.error.js +0 -11
- package/dist/errors/virmator-invalid-command.error.d.ts +0 -5
- package/dist/errors/virmator-invalid-command.error.js +0 -11
- package/dist/errors/virmator-invalid-flags.error.d.ts +0 -5
- package/dist/errors/virmator-invalid-flags.error.js +0 -13
- package/dist/file-paths/repo-paths.d.ts +0 -2
- package/dist/file-paths/repo-paths.js +0 -6
- package/dist/file-paths/virmator-test-file-paths.d.ts +0 -44
- package/dist/logging.d.ts +0 -10
- package/dist/logging.js +0 -9
- package/dist/package-name.d.ts +0 -1
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.commandToHelpString = exports.flagToHelpString = exports.generateHelpMessage = exports.HelpMessageSyntax = void 0;
|
|
4
4
|
const augment_vir_1 = require("augment-vir");
|
|
5
|
-
const package_name_1 = require("../../package-name");
|
|
6
5
|
const cli_color_1 = require("../cli-color");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return flagToHelpString(flagName, cli_flag_values_1.cliFlagDescriptions[flagName], syntax);
|
|
14
|
-
})
|
|
15
|
-
.join('\n');
|
|
6
|
+
var HelpMessageSyntax;
|
|
7
|
+
(function (HelpMessageSyntax) {
|
|
8
|
+
HelpMessageSyntax["Cli"] = "cli";
|
|
9
|
+
HelpMessageSyntax["Markdown"] = "markdown";
|
|
10
|
+
})(HelpMessageSyntax = exports.HelpMessageSyntax || (exports.HelpMessageSyntax = {}));
|
|
11
|
+
function generateHelpMessage(packageBinName, commandDefinitions, syntax, cliWrapIfMoreThanThisManyColumns = 100) {
|
|
16
12
|
const commandsMessage = (0, augment_vir_1.getObjectTypedKeys)(commandDefinitions)
|
|
17
13
|
.sort()
|
|
18
14
|
.map((commandName) => {
|
|
@@ -20,53 +16,50 @@ function generateHelpMessage(commandDefinitions, syntax) {
|
|
|
20
16
|
if (!commandDefinition) {
|
|
21
17
|
throw new Error(`Command definition was missing for key "${commandName}"`);
|
|
22
18
|
}
|
|
23
|
-
return commandToHelpString(commandDefinition, syntax);
|
|
19
|
+
return commandToHelpString(packageBinName, commandDefinition, syntax);
|
|
24
20
|
})
|
|
25
21
|
.join('\n');
|
|
26
|
-
const helpMessage = combineHelpMessage(
|
|
27
|
-
return
|
|
22
|
+
const helpMessage = combineHelpMessage(packageBinName, commandsMessage, syntax);
|
|
23
|
+
return syntax === HelpMessageSyntax.Cli
|
|
24
|
+
? wrapLines(helpMessage, cliWrapIfMoreThanThisManyColumns)
|
|
25
|
+
: helpMessage;
|
|
28
26
|
}
|
|
29
27
|
exports.generateHelpMessage = generateHelpMessage;
|
|
30
|
-
var MessageSyntax;
|
|
31
|
-
(function (MessageSyntax) {
|
|
32
|
-
MessageSyntax["Bash"] = "bash";
|
|
33
|
-
MessageSyntax["Markdown"] = "markdown";
|
|
34
|
-
})(MessageSyntax = exports.MessageSyntax || (exports.MessageSyntax = {}));
|
|
35
28
|
const formatting = ((input) => input)({
|
|
36
29
|
h1: {
|
|
37
|
-
[
|
|
38
|
-
[
|
|
30
|
+
[HelpMessageSyntax.Cli]: `${cli_color_1.Color.Info}`,
|
|
31
|
+
[HelpMessageSyntax.Markdown]: '# ',
|
|
39
32
|
},
|
|
40
33
|
h2: {
|
|
41
|
-
[
|
|
42
|
-
[
|
|
34
|
+
[HelpMessageSyntax.Cli]: `${cli_color_1.Color.Bold}${cli_color_1.Color.Info}`,
|
|
35
|
+
[HelpMessageSyntax.Markdown]: '## ',
|
|
43
36
|
},
|
|
44
37
|
h3: {
|
|
45
|
-
[
|
|
46
|
-
[
|
|
38
|
+
[HelpMessageSyntax.Cli]: ``,
|
|
39
|
+
[HelpMessageSyntax.Markdown]: '### ',
|
|
47
40
|
},
|
|
48
41
|
reset: {
|
|
49
|
-
[
|
|
50
|
-
[
|
|
42
|
+
[HelpMessageSyntax.Cli]: `${cli_color_1.Color.Reset}`,
|
|
43
|
+
[HelpMessageSyntax.Markdown]: '',
|
|
51
44
|
},
|
|
52
45
|
indent: {
|
|
53
|
-
[
|
|
54
|
-
[
|
|
46
|
+
[HelpMessageSyntax.Cli]: ` `,
|
|
47
|
+
[HelpMessageSyntax.Markdown]: '',
|
|
55
48
|
},
|
|
56
49
|
colon: {
|
|
57
|
-
[
|
|
58
|
-
[
|
|
50
|
+
[HelpMessageSyntax.Cli]: `:`,
|
|
51
|
+
[HelpMessageSyntax.Markdown]: '',
|
|
59
52
|
},
|
|
60
53
|
bullet: {
|
|
61
|
-
[
|
|
62
|
-
[
|
|
54
|
+
[HelpMessageSyntax.Cli]: `- `,
|
|
55
|
+
[HelpMessageSyntax.Markdown]: ' - ',
|
|
63
56
|
},
|
|
64
57
|
});
|
|
65
58
|
function formatWithSyntax(key, syntax) {
|
|
66
59
|
return formatting[key][syntax];
|
|
67
60
|
}
|
|
68
61
|
function code(input, block, indent, syntax) {
|
|
69
|
-
if (syntax ===
|
|
62
|
+
if (syntax === HelpMessageSyntax.Markdown) {
|
|
70
63
|
if (block) {
|
|
71
64
|
return `\n${indent}\`\`\`\n${indent}${input
|
|
72
65
|
.split('\n')
|
|
@@ -85,10 +78,16 @@ function flagToHelpString(flagName, description, syntax) {
|
|
|
85
78
|
return `${indent(1, syntax)}${format('h2')}${code(flagName, false, '', syntax)}${format('reset')}${format('colon')}\n${indent(2, syntax)}${description.trim()}`;
|
|
86
79
|
}
|
|
87
80
|
exports.flagToHelpString = flagToHelpString;
|
|
88
|
-
function commandToHelpString(commandDefinition, syntax) {
|
|
81
|
+
function commandToHelpString(packageBinName, commandDefinition, syntax) {
|
|
82
|
+
const commandDescription = commandDefinition.createDescription({
|
|
83
|
+
packageBinName,
|
|
84
|
+
commandName: commandDefinition.commandName,
|
|
85
|
+
subCommands: commandDefinition.subCommands,
|
|
86
|
+
configFiles: commandDefinition.configFiles,
|
|
87
|
+
});
|
|
89
88
|
const format = (key) => formatWithSyntax(key, syntax);
|
|
90
89
|
const title = `${indent(1, syntax)}${format('h2')}${commandDefinition.commandName}${format('reset')}${format('colon')}`;
|
|
91
|
-
const description = commandDescriptionToMessage(
|
|
90
|
+
const description = commandDescriptionToMessage(commandDescription, syntax);
|
|
92
91
|
const subCommandDescriptions = subCommandDescriptionsToMessage(commandDefinition.subCommandDescriptions, syntax);
|
|
93
92
|
return `${title}\n${description}\n${subCommandDescriptions}\n`;
|
|
94
93
|
}
|
|
@@ -107,11 +106,11 @@ function indent(input, syntax) {
|
|
|
107
106
|
function sectionToString(section, extraIndent, syntax, bullets) {
|
|
108
107
|
const format = (key) => formatWithSyntax(key, syntax);
|
|
109
108
|
const sectionIndent = indent(2 + extraIndent, syntax);
|
|
110
|
-
const separator = syntax ===
|
|
109
|
+
const separator = syntax === HelpMessageSyntax.Cli || !bullets ? `:\n` : ': ';
|
|
111
110
|
const header = bullets ? '' : format('h3');
|
|
112
111
|
const title = section.title ? `${sectionIndent}${header}${section.title}${separator}` : '';
|
|
113
|
-
if (bullets && syntax ===
|
|
114
|
-
return `${format('bullet')}${title}${code(section.content, section.content.includes('\n'), syntax ===
|
|
112
|
+
if (bullets && syntax === HelpMessageSyntax.Markdown) {
|
|
113
|
+
return `${format('bullet')}${title}${code(section.content, section.content.includes('\n'), syntax === HelpMessageSyntax.Markdown && section.content.includes('\n') ? ' ' : '', syntax)}`;
|
|
115
114
|
}
|
|
116
115
|
else {
|
|
117
116
|
const contentIndent = section.title ? indent(3 + extraIndent, syntax) : sectionIndent;
|
|
@@ -131,25 +130,20 @@ function commandDescriptionToMessage(description, syntax) {
|
|
|
131
130
|
: '';
|
|
132
131
|
return `${sections}${examplesTitle}${examples}`;
|
|
133
132
|
}
|
|
134
|
-
function combineHelpMessage(
|
|
133
|
+
function combineHelpMessage(packageBinName, commandsText, syntax) {
|
|
135
134
|
const format = (key) => formatWithSyntax(key, syntax);
|
|
136
|
-
return `${formatting.h1[syntax]}${
|
|
137
|
-
${format('indent')}${code(`[npx] ${
|
|
135
|
+
return `${formatting.h1[syntax]}${packageBinName} usage${format('colon')}${format('reset')}
|
|
136
|
+
${format('indent')}${code(`[npx] ${packageBinName} [--flags] command subCommand`, true, '', syntax)}
|
|
138
137
|
|
|
139
138
|
${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 flags${format('colon')}${format('reset')}
|
|
142
|
-
${flagsText}
|
|
143
139
|
|
|
144
140
|
${format('h1')}Available commands${format('colon')}${format('reset')}
|
|
145
141
|
${commandsText}`;
|
|
146
142
|
}
|
|
147
|
-
exports.combineHelpMessage = combineHelpMessage;
|
|
148
143
|
function getIndent(line) {
|
|
149
144
|
var _a;
|
|
150
145
|
return (_a = (0, augment_vir_1.safeMatch)(line, /^(\s*)/)[0]) !== null && _a !== void 0 ? _a : '';
|
|
151
146
|
}
|
|
152
|
-
exports.getIndent = getIndent;
|
|
153
147
|
function wrapLines(input, limit) {
|
|
154
148
|
var _a, _b;
|
|
155
149
|
const lines = input.split('\n');
|
|
@@ -180,4 +174,3 @@ function wrapLines(input, limit) {
|
|
|
180
174
|
}
|
|
181
175
|
return lines.join('\n').trimEnd();
|
|
182
176
|
}
|
|
183
|
-
exports.wrapLines = wrapLines;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ConfigFileDefinition } from '../config/config-file-definition';
|
|
2
|
+
export declare type DefineCommandInputs<CommandName extends string = string> = Readonly<{
|
|
3
|
+
commandName: CommandName;
|
|
4
|
+
subCommandDescriptions: Readonly<Record<string, string>>;
|
|
5
|
+
configFiles: Readonly<Record<string, Readonly<ConfigFileDefinition>>>;
|
|
6
|
+
npmDeps: ReadonlyArray<string>;
|
|
7
|
+
}>;
|
|
8
|
+
export declare type SharedExecutorInputsAndCommandDefinition<DefineCommandInputsGeneric extends DefineCommandInputs> = DefineCommandInputsGeneric & {
|
|
9
|
+
allAvailableSubCommands: (keyof DefineCommandInputsGeneric['subCommandDescriptions'])[];
|
|
10
|
+
subCommands: SubCommandsMap<DefineCommandInputsGeneric>;
|
|
11
|
+
};
|
|
12
|
+
export declare type SubCommandsMap<DefineCommandInputsGeneric extends DefineCommandInputs> = {
|
|
13
|
+
[Prop in keyof DefineCommandInputsGeneric['subCommandDescriptions']]: Prop;
|
|
14
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CreateDescriptionsCallback } from './command-description';
|
|
2
|
+
import { CommandExecutor, CommandExecutorDefinition } from './command-executor';
|
|
3
|
+
import { DefineCommandInputs, SharedExecutorInputsAndCommandDefinition } from './define-command-inputs';
|
|
4
|
+
export declare type CommandDefinition<DefineCommandInputsGeneric extends DefineCommandInputs = DefineCommandInputs<string>> = SharedExecutorInputsAndCommandDefinition<DefineCommandInputsGeneric> & {
|
|
5
|
+
executor: CommandExecutor<DefineCommandInputsGeneric>;
|
|
6
|
+
createDescription: CreateDescriptionsCallback<DefineCommandInputsGeneric>;
|
|
7
|
+
};
|
|
8
|
+
export declare function defineCommand<DefineCommandInputsGeneric extends DefineCommandInputs>(defineCommandInputs: Readonly<DefineCommandInputsGeneric>, createDescription: CreateDescriptionsCallback<DefineCommandInputsGeneric>, inputExecutor: CommandExecutorDefinition<DefineCommandInputsGeneric>): CommandDefinition<DefineCommandInputsGeneric>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineCommand = void 0;
|
|
4
|
+
const augment_vir_1 = require("augment-vir");
|
|
5
|
+
function defineCommand(defineCommandInputs, createDescription, inputExecutor) {
|
|
6
|
+
const allAvailableSubCommands = (0, augment_vir_1.getObjectTypedKeys)(defineCommandInputs.subCommandDescriptions);
|
|
7
|
+
const subCommands = (0, augment_vir_1.mapObject)(defineCommandInputs.subCommandDescriptions, (key) => key);
|
|
8
|
+
const init = {
|
|
9
|
+
...defineCommandInputs,
|
|
10
|
+
allAvailableSubCommands,
|
|
11
|
+
subCommands,
|
|
12
|
+
};
|
|
13
|
+
const executor = (executorInputs) => {
|
|
14
|
+
return inputExecutor({
|
|
15
|
+
...executorInputs,
|
|
16
|
+
...init,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
...init,
|
|
21
|
+
executor,
|
|
22
|
+
createDescription,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.defineCommand = defineCommand;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare type UpdateConfigCallback = (copyFromContents: string, existingConfigContents: string, repoDir: string) => string | Promise<string>;
|
|
2
|
+
export declare 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
|
+
required: boolean;
|
|
16
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConfigFileDefinition } from './config-file-definition';
|
|
2
|
+
export declare type GetCopyToPathInputs = {
|
|
3
|
+
repoDir: string;
|
|
4
|
+
packageDir: string;
|
|
5
|
+
configFileDefinition: ConfigFileDefinition;
|
|
6
|
+
};
|
|
7
|
+
export declare function getCopyToPath({ repoDir, configFileDefinition }: GetCopyToPathInputs): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCopyToPath = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
function getCopyToPath({ repoDir, configFileDefinition }) {
|
|
6
|
+
return (0, path_1.join)(repoDir, configFileDefinition.copyToPathRelativeToRepoDir);
|
|
7
|
+
}
|
|
8
|
+
exports.getCopyToPath = getCopyToPath;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ConfigFileDefinition } from './config-
|
|
1
|
+
import { CommandLogging } from '../command/command-logging';
|
|
2
|
+
import { ConfigFileDefinition } from './config-file-definition';
|
|
3
3
|
export declare enum CopyConfigOperation {
|
|
4
4
|
/** Only update the config file if it exists and is marked as being able to be updated. */
|
|
5
5
|
Update = "update",
|
|
@@ -11,6 +11,7 @@ export declare enum CopyConfigOperation {
|
|
|
11
11
|
export declare type CopyConfigInputs = {
|
|
12
12
|
configFileDefinition: ConfigFileDefinition;
|
|
13
13
|
repoDir: string;
|
|
14
|
+
packageDir: string;
|
|
14
15
|
operation: CopyConfigOperation;
|
|
15
16
|
};
|
|
16
17
|
export declare type CopyConfigOutputs = {
|
|
@@ -19,8 +20,8 @@ export declare type CopyConfigOutputs = {
|
|
|
19
20
|
};
|
|
20
21
|
export declare function copyConfig(inputs: CopyConfigInputs): Promise<CopyConfigOutputs>;
|
|
21
22
|
export declare type CopyAllConfigFilesInputs = Omit<CopyConfigInputs, 'configFileDefinition'> & {
|
|
22
|
-
logging:
|
|
23
|
-
configFiles:
|
|
23
|
+
logging: CommandLogging;
|
|
24
|
+
configFiles: ReadonlyArray<ConfigFileDefinition>;
|
|
24
25
|
};
|
|
25
26
|
/** Returns success state. True if success, false is errors were encountered. */
|
|
26
27
|
export declare function copyAllConfigFiles(inputs: CopyAllConfigFilesInputs): Promise<boolean>;
|
|
@@ -6,7 +6,7 @@ const fs_1 = require("fs");
|
|
|
6
6
|
const promises_1 = require("fs/promises");
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const cli_color_1 = require("../cli-color");
|
|
9
|
-
const
|
|
9
|
+
const config_paths_1 = require("./config-paths");
|
|
10
10
|
var CopyConfigOperation;
|
|
11
11
|
(function (CopyConfigOperation) {
|
|
12
12
|
/** Only update the config file if it exists and is marked as being able to be updated. */
|
|
@@ -16,42 +16,36 @@ var CopyConfigOperation;
|
|
|
16
16
|
/** Only write the config file if it doesn't exist already or if it can be updated. */
|
|
17
17
|
CopyConfigOperation["Init"] = "init";
|
|
18
18
|
})(CopyConfigOperation = exports.CopyConfigOperation || (exports.CopyConfigOperation = {}));
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const copyToFileExists = (0, config_files_1.doesCopyToConfigPathExist)(inputs.configFileDefinition, inputs.repoDir);
|
|
23
|
-
let shouldWrite = false;
|
|
24
|
-
switch (inputs.operation) {
|
|
19
|
+
function checkIfShouldWrite({ configFileDefinition, operation, copyToPath, }) {
|
|
20
|
+
const fileExists = (0, fs_1.existsSync)(copyToPath);
|
|
21
|
+
switch (operation) {
|
|
25
22
|
case CopyConfigOperation.Init: {
|
|
26
|
-
|
|
27
|
-
shouldWrite = true;
|
|
28
|
-
}
|
|
29
|
-
break;
|
|
23
|
+
return !fileExists || !!configFileDefinition.updateExistingConfigFileCallback;
|
|
30
24
|
}
|
|
31
25
|
case CopyConfigOperation.Overwrite: {
|
|
32
|
-
|
|
33
|
-
break;
|
|
26
|
+
return true;
|
|
34
27
|
}
|
|
35
28
|
case CopyConfigOperation.Update: {
|
|
36
|
-
|
|
37
|
-
typeof inputs.configFileDefinition !== 'string' &&
|
|
38
|
-
(inputs.configFileDefinition.canBeUpdated ||
|
|
39
|
-
inputs.configFileDefinition.updateCallback)) {
|
|
40
|
-
shouldWrite = true;
|
|
41
|
-
}
|
|
42
|
-
break;
|
|
29
|
+
return fileExists && !!configFileDefinition.updateExistingConfigFileCallback;
|
|
43
30
|
}
|
|
44
31
|
}
|
|
32
|
+
}
|
|
33
|
+
async function copyConfig(inputs) {
|
|
34
|
+
const copyFromPath = inputs.configFileDefinition.copyFromInternalPath;
|
|
35
|
+
const copyToPath = (0, config_paths_1.getCopyToPath)(inputs);
|
|
36
|
+
const shouldWriteBasedOnOperation = checkIfShouldWrite({
|
|
37
|
+
configFileDefinition: inputs.configFileDefinition,
|
|
38
|
+
operation: inputs.operation,
|
|
39
|
+
copyToPath,
|
|
40
|
+
});
|
|
45
41
|
const currentRepoFileContents = (0, fs_1.existsSync)(copyToPath)
|
|
46
42
|
? (await (0, promises_1.readFile)(copyToPath)).toString()
|
|
47
43
|
: '';
|
|
48
44
|
const virmatorFileContents = (await (0, promises_1.readFile)(copyFromPath)).toString();
|
|
49
|
-
const writeContents = inputs.configFileDefinition.
|
|
50
|
-
? await inputs.configFileDefinition.
|
|
45
|
+
const writeContents = inputs.configFileDefinition.updateExistingConfigFileCallback
|
|
46
|
+
? await inputs.configFileDefinition.updateExistingConfigFileCallback(virmatorFileContents, currentRepoFileContents, inputs.repoDir)
|
|
51
47
|
: virmatorFileContents;
|
|
52
|
-
|
|
53
|
-
shouldWrite = false;
|
|
54
|
-
}
|
|
48
|
+
const shouldWrite = shouldWriteBasedOnOperation && currentRepoFileContents !== writeContents;
|
|
55
49
|
if (shouldWrite) {
|
|
56
50
|
await (0, promises_1.mkdir)((0, path_1.dirname)(copyToPath), { recursive: true });
|
|
57
51
|
await (0, promises_1.writeFile)(copyToPath, writeContents);
|
|
@@ -75,20 +69,24 @@ const failedOperation = {
|
|
|
75
69
|
/** Returns success state. True if success, false is errors were encountered. */
|
|
76
70
|
async function copyAllConfigFiles(inputs) {
|
|
77
71
|
const errors = [];
|
|
78
|
-
await (0, augment_vir_1.awaitedForEach)(
|
|
79
|
-
const
|
|
72
|
+
await (0, augment_vir_1.awaitedForEach)(inputs.configFiles.sort((a, b) => {
|
|
73
|
+
const aName = (0, path_1.basename)(a.copyToPathRelativeToRepoDir || a.copyFromInternalPath);
|
|
74
|
+
const bName = (0, path_1.basename)(b.copyToPathRelativeToRepoDir || b.copyFromInternalPath);
|
|
75
|
+
return aName.localeCompare(bName);
|
|
76
|
+
}), async (configFile) => {
|
|
80
77
|
try {
|
|
81
78
|
const result = await copyConfig({
|
|
82
79
|
configFileDefinition: configFile,
|
|
83
80
|
operation: inputs.operation,
|
|
84
81
|
repoDir: inputs.repoDir,
|
|
82
|
+
packageDir: inputs.packageDir,
|
|
85
83
|
});
|
|
86
84
|
if (result.shouldWrite) {
|
|
87
85
|
inputs.logging.stdout(`${cli_color_1.Color.Info}Successfully ${successfulOperation[inputs.operation]}${cli_color_1.Color.Reset} ${(0, path_1.basename)(result.copiedToPath)}`);
|
|
88
86
|
}
|
|
89
87
|
}
|
|
90
88
|
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.
|
|
89
|
+
const copyError = new Error(`${cli_color_1.Color.Fail}Failed to ${failedOperation[inputs.operation]}${cli_color_1.Color.Reset} ${(0, path_1.basename)(configFile.copyToPathRelativeToRepoDir || configFile.copyFromInternalPath)}: ${(0, augment_vir_1.extractErrorMessage)(error)}`);
|
|
92
90
|
errors.push(copyError);
|
|
93
91
|
}
|
|
94
92
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CommandDefinitionArrayToMapping } from './command/command-mapping';
|
|
2
|
+
import { CommandDefinition } from './command/define-command';
|
|
3
|
+
import { ExtendedVirmator, ExtendVirmatorInputs } from './virmator-types';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a wrapped instance of virmator from which all its CLI commands can be called. Arguments
|
|
6
|
+
* can be passed in to add to virmator default configs or overwrite them.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createVirmator<CommandDefinitionsGeneric extends ReadonlyArray<CommandDefinition<any>>>(inputs: ExtendVirmatorInputs<CommandDefinitionsGeneric>): ExtendedVirmator<CommandDefinitionArrayToMapping<CommandDefinitionsGeneric>>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createVirmator = void 0;
|
|
4
|
+
const augment_vir_1 = require("augment-vir");
|
|
5
|
+
const command_configs_1 = require("./command/command-configs");
|
|
6
|
+
const command_mapping_1 = require("./command/command-mapping");
|
|
7
|
+
const command_to_help_message_1 = require("./command/command-to-help-message");
|
|
8
|
+
const run_extended_virmator_1 = require("./run-command/run-extended-virmator");
|
|
9
|
+
/**
|
|
10
|
+
* Creates a wrapped instance of virmator from which all its CLI commands can be called. Arguments
|
|
11
|
+
* can be passed in to add to virmator default configs or overwrite them.
|
|
12
|
+
*/
|
|
13
|
+
function createVirmator(inputs) {
|
|
14
|
+
var _a;
|
|
15
|
+
const commandDefinitions = (_a = inputs.commandDefinitions) !== null && _a !== void 0 ? _a : [];
|
|
16
|
+
const commandMapping = (0, command_mapping_1.commandsToMapping)(commandDefinitions);
|
|
17
|
+
const allCommands = {
|
|
18
|
+
...{},
|
|
19
|
+
...commandMapping,
|
|
20
|
+
};
|
|
21
|
+
const cliHelpMessage = (0, command_to_help_message_1.generateHelpMessage)(inputs.packageBinName, allCommands !== null && allCommands !== void 0 ? allCommands : {}, command_to_help_message_1.HelpMessageSyntax.Cli);
|
|
22
|
+
const markdownHelpMessage = (0, command_to_help_message_1.generateHelpMessage)(inputs.packageBinName, allCommands, command_to_help_message_1.HelpMessageSyntax.Markdown);
|
|
23
|
+
const allConfigs = (0, command_configs_1.extractAllConfigs)(commandMapping);
|
|
24
|
+
async function run(allArgs, repoDir) {
|
|
25
|
+
return await (0, run_extended_virmator_1.runExtendedVirmator)({
|
|
26
|
+
allArgs,
|
|
27
|
+
repoDir,
|
|
28
|
+
packageBinName: inputs.packageBinName,
|
|
29
|
+
packageDir: inputs.packageRootDir,
|
|
30
|
+
commandMapping: allCommands,
|
|
31
|
+
allConfigs,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async function runInCli() {
|
|
35
|
+
try {
|
|
36
|
+
await run(process.argv, process.cwd());
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error((0, augment_vir_1.extractErrorMessage)(error));
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function extendVirmator(innerInputs) {
|
|
44
|
+
var _a;
|
|
45
|
+
const allCommandDefinitions = [
|
|
46
|
+
...commandDefinitions,
|
|
47
|
+
...((_a = innerInputs.commandDefinitions) !== null && _a !== void 0 ? _a : []),
|
|
48
|
+
];
|
|
49
|
+
return createVirmator({
|
|
50
|
+
...innerInputs,
|
|
51
|
+
commandDefinitions: allCommandDefinitions,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
packageBinName: inputs.packageBinName,
|
|
56
|
+
cliHelpMessage,
|
|
57
|
+
extend: extendVirmator,
|
|
58
|
+
markdownHelpMessage,
|
|
59
|
+
commandMapping: allCommands,
|
|
60
|
+
allConfigs,
|
|
61
|
+
runInCli,
|
|
62
|
+
run,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
exports.createVirmator = createVirmator;
|
|
@@ -0,0 +1,107 @@
|
|
|
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.updateDepsAsNeeded = void 0;
|
|
27
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
28
|
+
const augment_vir_1 = require("augment-vir");
|
|
29
|
+
const node_only_1 = require("augment-vir/dist/cjs/node-only");
|
|
30
|
+
const promises_1 = require("fs/promises");
|
|
31
|
+
const path_1 = require("path");
|
|
32
|
+
const semver = __importStar(require("semver"));
|
|
33
|
+
const cli_color_1 = require("../cli-color");
|
|
34
|
+
async function updateDepsAsNeeded(inputs) {
|
|
35
|
+
const upgradeVersions = await getVersionsToUpgradeTo(inputs);
|
|
36
|
+
const depsToUpdate = inputs.npmDeps
|
|
37
|
+
.map((npmDep, index) => {
|
|
38
|
+
const version = upgradeVersions[index];
|
|
39
|
+
if (version) {
|
|
40
|
+
return {
|
|
41
|
+
npmDep,
|
|
42
|
+
version,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
.filter(augment_vir_1.isTruthy);
|
|
50
|
+
await (0, augment_vir_1.awaitedForEach)(depsToUpdate, async (depDetails) => {
|
|
51
|
+
const depToInstall = `${depDetails.npmDep}@${depDetails.version}`;
|
|
52
|
+
console.info(`${cli_color_1.Color.Info}Installing ${depToInstall}...`);
|
|
53
|
+
await (0, node_only_1.runShellCommand)(`npm i -D ${depToInstall}`, {
|
|
54
|
+
cwd: inputs.repoDir,
|
|
55
|
+
rejectOnError: true,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.updateDepsAsNeeded = updateDepsAsNeeded;
|
|
60
|
+
async function getVersionsToUpgradeTo({ repoDir, packageDir, npmDeps, packageBinName, }) {
|
|
61
|
+
const listedDeps = await (0, node_only_1.runShellCommand)(`npm list --depth=0 2>&1`, { cwd: repoDir });
|
|
62
|
+
const currentRepoDepVersions = parseCurrentDeps(listedDeps.stdout);
|
|
63
|
+
const packageJson = JSON.parse((await (0, promises_1.readFile)((0, path_1.join)(packageDir, 'package.json'))).toString());
|
|
64
|
+
const packageDepVersions = {
|
|
65
|
+
...packageJson.devDependencies,
|
|
66
|
+
...packageJson.dependencies,
|
|
67
|
+
};
|
|
68
|
+
return npmDeps.map((npmDep) => {
|
|
69
|
+
var _a;
|
|
70
|
+
const currentRepoVersion = currentRepoDepVersions[npmDep];
|
|
71
|
+
const packageDepVersion = semver.clean((_a = packageDepVersions[npmDep]) !== null && _a !== void 0 ? _a : '');
|
|
72
|
+
if (!packageDepVersion) {
|
|
73
|
+
throw new Error(`No npm dep version listed for "${npmDep}" in ${packageBinName}'s dependencies.`);
|
|
74
|
+
}
|
|
75
|
+
if (!currentRepoVersion || semver.gt(packageDepVersion, currentRepoVersion)) {
|
|
76
|
+
return packageDepVersion;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function parseCurrentDeps(stdout) {
|
|
84
|
+
const lines = stdout.split('\n');
|
|
85
|
+
const depLines = lines.filter((line) => line.match(/\s*[├└]─/) && !line.match(/─\s*\(empty\)/));
|
|
86
|
+
const namesAndVersions = depLines.map((depLine) => {
|
|
87
|
+
const nameAndVersion = (0, augment_vir_1.safeMatch)((0, ansi_colors_1.stripColor)(depLine), /\s*[├└]─+\s*(?:UNMET DEPENDENCY\s*)?(.+)$/)[1];
|
|
88
|
+
if (!nameAndVersion) {
|
|
89
|
+
throw new Error(`Failed to retrieve dependency name and version from line "${depLine}"`);
|
|
90
|
+
}
|
|
91
|
+
return nameAndVersion;
|
|
92
|
+
});
|
|
93
|
+
const nameToVersionMap = namesAndVersions.reduce((accum, nameVersion) => {
|
|
94
|
+
const [, depName, depVersion,] = (0, augment_vir_1.safeMatch)(nameVersion, /(.+)@(.+)/);
|
|
95
|
+
const cleanedVersion = semver.clean(depVersion !== null && depVersion !== void 0 ? depVersion : '');
|
|
96
|
+
if (!depName || !cleanedVersion) {
|
|
97
|
+
console.error({ depLines, namesAndVersions });
|
|
98
|
+
throw new Error(`Failed to extract dep name and version from "${nameVersion}"`);
|
|
99
|
+
}
|
|
100
|
+
if (!semver.valid(cleanedVersion)) {
|
|
101
|
+
throw new Error(`Extracted dependency version is not valid: "${cleanedVersion}"`);
|
|
102
|
+
}
|
|
103
|
+
accum[depName] = cleanedVersion;
|
|
104
|
+
return accum;
|
|
105
|
+
}, {});
|
|
106
|
+
return nameToVersionMap;
|
|
107
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function getRelevantArgs(allArgs: string[], binName: string): string[];
|
|
2
|
+
export declare type ExtractSubCommandsOutput<T> = {
|
|
3
|
+
subCommands: T[];
|
|
4
|
+
filteredArgs: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare function extractSubCommands<T>(allArgs: string[], availableSubCommands: T[]): ExtractSubCommandsOutput<T>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractSubCommands = exports.getRelevantArgs = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const array_1 = require("../../augments/array");
|
|
6
|
+
function getRelevantArgs(allArgs, binName) {
|
|
7
|
+
const binIndex = allArgs.findIndex((arg) => {
|
|
8
|
+
return arg.includes((0, path_1.join)('', 'node_modules', '.bin', binName));
|
|
9
|
+
});
|
|
10
|
+
const firstJsOrTsIndex = allArgs.findIndex((arg) => {
|
|
11
|
+
return arg.match(/\.[tj]sx?$/);
|
|
12
|
+
});
|
|
13
|
+
const binWasFound = binIndex > -1;
|
|
14
|
+
const firstJsOrTsWasFound = firstJsOrTsIndex > -1;
|
|
15
|
+
const sliceIndexStart = binWasFound ? binIndex : firstJsOrTsWasFound ? firstJsOrTsIndex : 0;
|
|
16
|
+
return allArgs.slice(sliceIndexStart + 1);
|
|
17
|
+
}
|
|
18
|
+
exports.getRelevantArgs = getRelevantArgs;
|
|
19
|
+
function extractSubCommands(allArgs, availableSubCommands) {
|
|
20
|
+
let stillInSubCommands = true;
|
|
21
|
+
return allArgs.reduce((accum, currentArg) => {
|
|
22
|
+
if (stillInSubCommands) {
|
|
23
|
+
if ((0, array_1.isInTypedArray)(currentArg, availableSubCommands)) {
|
|
24
|
+
accum.subCommands.push(currentArg);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
stillInSubCommands = false;
|
|
28
|
+
accum.filteredArgs.push(currentArg);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
accum.filteredArgs.push(currentArg);
|
|
33
|
+
}
|
|
34
|
+
return accum;
|
|
35
|
+
}, { subCommands: [], filteredArgs: [] });
|
|
36
|
+
}
|
|
37
|
+
exports.extractSubCommands = extractSubCommands;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BashCommandExecutorOutput, CommandExecutorInputs } from '../command/command-executor';
|
|
2
|
+
import { CommandDefinition } from '../command/define-command';
|
|
3
|
+
import { DefineCommandInputs } from '../command/define-command-inputs';
|
|
4
|
+
export declare function createCommandString(executorOutput: BashCommandExecutorOutput): string;
|
|
5
|
+
export declare function runCommandExecutor<DefineCommandInputsGeneric extends DefineCommandInputs>(commandDefinition: CommandDefinition<DefineCommandInputsGeneric>, commandInputs: CommandExecutorInputs<DefineCommandInputsGeneric>): Promise<boolean>;
|