intershell 0.3.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 +301 -0
- package/dist/commands/ci/act.d.ts +13 -0
- package/dist/commands/ci/act.d.ts.map +1 -0
- package/dist/commands/ci/act.js +89 -0
- package/dist/commands/ci/act.js.map +1 -0
- package/dist/commands/ci/attach-affected.d.ts +12 -0
- package/dist/commands/ci/attach-affected.d.ts.map +1 -0
- package/dist/commands/ci/attach-affected.js +83 -0
- package/dist/commands/ci/attach-affected.js.map +1 -0
- package/dist/commands/ci/attach-service-ports.d.ts +10 -0
- package/dist/commands/ci/attach-service-ports.d.ts.map +1 -0
- package/dist/commands/ci/attach-service-ports.js +25 -0
- package/dist/commands/ci/attach-service-ports.js.map +1 -0
- package/dist/commands/commit-check.d.ts +13 -0
- package/dist/commands/commit-check.d.ts.map +1 -0
- package/dist/commands/commit-check.js +110 -0
- package/dist/commands/commit-check.js.map +1 -0
- package/dist/commands/commit.d.ts +16 -0
- package/dist/commands/commit.d.ts.map +1 -0
- package/dist/commands/commit.js +91 -0
- package/dist/commands/commit.js.map +1 -0
- package/dist/commands/dev/check.d.ts +13 -0
- package/dist/commands/dev/check.d.ts.map +1 -0
- package/dist/commands/dev/check.js +91 -0
- package/dist/commands/dev/check.js.map +1 -0
- package/dist/commands/dev/cleanup.d.ts +10 -0
- package/dist/commands/dev/cleanup.d.ts.map +1 -0
- package/dist/commands/dev/cleanup.js +28 -0
- package/dist/commands/dev/cleanup.js.map +1 -0
- package/dist/commands/dev/rm.d.ts +12 -0
- package/dist/commands/dev/rm.d.ts.map +1 -0
- package/dist/commands/dev/rm.js +49 -0
- package/dist/commands/dev/rm.js.map +1 -0
- package/dist/commands/dev/setup.d.ts +10 -0
- package/dist/commands/dev/setup.d.ts.map +1 -0
- package/dist/commands/dev/setup.js +40 -0
- package/dist/commands/dev/setup.js.map +1 -0
- package/dist/commands/local/cleanup.d.ts +12 -0
- package/dist/commands/local/cleanup.d.ts.map +1 -0
- package/dist/commands/local/cleanup.js +62 -0
- package/dist/commands/local/cleanup.js.map +1 -0
- package/dist/commands/local/setup.d.ts +11 -0
- package/dist/commands/local/setup.d.ts.map +1 -0
- package/dist/commands/local/setup.js +55 -0
- package/dist/commands/local/setup.js.map +1 -0
- package/dist/commands/local/vscode.d.ts +17 -0
- package/dist/commands/local/vscode.d.ts.map +1 -0
- package/dist/commands/local/vscode.js +94 -0
- package/dist/commands/local/vscode.js.map +1 -0
- package/dist/commands/update-package-json.d.ts +12 -0
- package/dist/commands/update-package-json.d.ts.map +1 -0
- package/dist/commands/update-package-json.js +82 -0
- package/dist/commands/update-package-json.js.map +1 -0
- package/dist/commands/version/apply.d.ts +16 -0
- package/dist/commands/version/apply.d.ts.map +1 -0
- package/dist/commands/version/apply.js +120 -0
- package/dist/commands/version/apply.js.map +1 -0
- package/dist/commands/version/ci.d.ts +12 -0
- package/dist/commands/version/ci.d.ts.map +1 -0
- package/dist/commands/version/ci.js +67 -0
- package/dist/commands/version/ci.js.map +1 -0
- package/dist/commands/version/prepare.d.ts +19 -0
- package/dist/commands/version/prepare.d.ts.map +1 -0
- package/dist/commands/version/prepare.js +153 -0
- package/dist/commands/version/prepare.js.map +1 -0
- package/dist/core/colorify.d.ts +21 -0
- package/dist/core/colorify.d.ts.map +1 -0
- package/dist/core/colorify.js +56 -0
- package/dist/core/colorify.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/types.d.ts +181 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/wrapshell.d.ts +19 -0
- package/dist/core/wrapshell.d.ts.map +1 -0
- package/dist/core/wrapshell.js +323 -0
- package/dist/core/wrapshell.js.map +1 -0
- package/dist/entities/affected/affected.d.ts +4 -0
- package/dist/entities/affected/affected.d.ts.map +1 -0
- package/dist/entities/affected/affected.js +20 -0
- package/dist/entities/affected/affected.js.map +1 -0
- package/dist/entities/affected/affected.test.d.ts +2 -0
- package/dist/entities/affected/affected.test.d.ts.map +1 -0
- package/dist/entities/affected/affected.test.js +305 -0
- package/dist/entities/affected/affected.test.js.map +1 -0
- package/dist/entities/affected/index.d.ts +2 -0
- package/dist/entities/affected/index.d.ts.map +1 -0
- package/dist/entities/affected/index.js +2 -0
- package/dist/entities/affected/index.js.map +1 -0
- package/dist/entities/branch/branch.d.ts +8 -0
- package/dist/entities/branch/branch.d.ts.map +1 -0
- package/dist/entities/branch/branch.js +74 -0
- package/dist/entities/branch/branch.js.map +1 -0
- package/dist/entities/branch/branch.test.d.ts +2 -0
- package/dist/entities/branch/branch.test.d.ts.map +1 -0
- package/dist/entities/branch/branch.test.js +316 -0
- package/dist/entities/branch/branch.test.js.map +1 -0
- package/dist/entities/branch/branch.types.d.ts +6 -0
- package/dist/entities/branch/branch.types.d.ts.map +1 -0
- package/dist/entities/branch/branch.types.js +2 -0
- package/dist/entities/branch/branch.types.js.map +1 -0
- package/dist/entities/branch/index.d.ts +3 -0
- package/dist/entities/branch/index.d.ts.map +1 -0
- package/dist/entities/branch/index.js +3 -0
- package/dist/entities/branch/index.js.map +1 -0
- package/dist/entities/commit/commit.d.ts +15 -0
- package/dist/entities/commit/commit.d.ts.map +1 -0
- package/dist/entities/commit/commit.js +196 -0
- package/dist/entities/commit/commit.js.map +1 -0
- package/dist/entities/commit/commit.test.d.ts +26 -0
- package/dist/entities/commit/commit.test.d.ts.map +1 -0
- package/dist/entities/commit/commit.test.js +550 -0
- package/dist/entities/commit/commit.test.js.map +1 -0
- package/dist/entities/commit/commit.types.d.ts +49 -0
- package/dist/entities/commit/commit.types.d.ts.map +1 -0
- package/dist/entities/commit/commit.types.js +31 -0
- package/dist/entities/commit/commit.types.js.map +1 -0
- package/dist/entities/commit/index.d.ts +3 -0
- package/dist/entities/commit/index.d.ts.map +1 -0
- package/dist/entities/commit/index.js +3 -0
- package/dist/entities/commit/index.js.map +1 -0
- package/dist/entities/commit/pr.d.ts +11 -0
- package/dist/entities/commit/pr.d.ts.map +1 -0
- package/dist/entities/commit/pr.js +201 -0
- package/dist/entities/commit/pr.js.map +1 -0
- package/dist/entities/commit/pr.test.d.ts +2 -0
- package/dist/entities/commit/pr.test.d.ts.map +1 -0
- package/dist/entities/commit/pr.test.js +782 -0
- package/dist/entities/commit/pr.test.js.map +1 -0
- package/dist/entities/compose/compose.d.ts +18 -0
- package/dist/entities/compose/compose.d.ts.map +1 -0
- package/dist/entities/compose/compose.js +197 -0
- package/dist/entities/compose/compose.js.map +1 -0
- package/dist/entities/compose/compose.test.d.ts +2 -0
- package/dist/entities/compose/compose.test.d.ts.map +1 -0
- package/dist/entities/compose/compose.test.js +406 -0
- package/dist/entities/compose/compose.test.js.map +1 -0
- package/dist/entities/compose/compose.types.d.ts +77 -0
- package/dist/entities/compose/compose.types.d.ts.map +1 -0
- package/dist/entities/compose/compose.types.js +2 -0
- package/dist/entities/compose/compose.types.js.map +1 -0
- package/dist/entities/compose/index.d.ts +3 -0
- package/dist/entities/compose/index.d.ts.map +1 -0
- package/dist/entities/compose/index.js +3 -0
- package/dist/entities/compose/index.js.map +1 -0
- package/dist/entities/entities.shell.d.ts +29 -0
- package/dist/entities/entities.shell.d.ts.map +1 -0
- package/dist/entities/entities.shell.js +27 -0
- package/dist/entities/entities.shell.js.map +1 -0
- package/dist/entities/entities.shell.test.d.ts +2 -0
- package/dist/entities/entities.shell.test.d.ts.map +1 -0
- package/dist/entities/entities.shell.test.js +23 -0
- package/dist/entities/entities.shell.test.js.map +1 -0
- package/dist/entities/index.d.ts +12 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +12 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/entities/intershell-config/intershell-config.d.ts +11 -0
- package/dist/entities/intershell-config/intershell-config.d.ts.map +1 -0
- package/dist/entities/intershell-config/intershell-config.default.d.ts +188 -0
- package/dist/entities/intershell-config/intershell-config.default.d.ts.map +1 -0
- package/dist/entities/intershell-config/intershell-config.default.js +225 -0
- package/dist/entities/intershell-config/intershell-config.default.js.map +1 -0
- package/dist/entities/intershell-config/intershell-config.js +132 -0
- package/dist/entities/intershell-config/intershell-config.js.map +1 -0
- package/dist/entities/intershell-config/intershell-config.test.d.ts +2 -0
- package/dist/entities/intershell-config/intershell-config.test.d.ts.map +1 -0
- package/dist/entities/intershell-config/intershell-config.test.js +102 -0
- package/dist/entities/intershell-config/intershell-config.test.js.map +1 -0
- package/dist/entities/intershell-config/intershell-config.types.d.ts +103 -0
- package/dist/entities/intershell-config/intershell-config.types.d.ts.map +1 -0
- package/dist/entities/intershell-config/intershell-config.types.js +2 -0
- package/dist/entities/intershell-config/intershell-config.types.js.map +1 -0
- package/dist/entities/package/index.d.ts +4 -0
- package/dist/entities/package/index.d.ts.map +1 -0
- package/dist/entities/package/index.js +4 -0
- package/dist/entities/package/index.js.map +1 -0
- package/dist/entities/package/package.d.ts +49 -0
- package/dist/entities/package/package.d.ts.map +1 -0
- package/dist/entities/package/package.js +234 -0
- package/dist/entities/package/package.js.map +1 -0
- package/dist/entities/package/package.shell.d.ts +48 -0
- package/dist/entities/package/package.shell.d.ts.map +1 -0
- package/dist/entities/package/package.shell.js +118 -0
- package/dist/entities/package/package.shell.js.map +1 -0
- package/dist/entities/package/package.test.d.ts +23 -0
- package/dist/entities/package/package.test.d.ts.map +1 -0
- package/dist/entities/package/package.test.js +637 -0
- package/dist/entities/package/package.test.js.map +1 -0
- package/dist/entities/package/package.types.d.ts +48 -0
- package/dist/entities/package/package.types.d.ts.map +1 -0
- package/dist/entities/package/package.types.js +2 -0
- package/dist/entities/package/package.types.js.map +1 -0
- package/dist/entities/package-changelog/index.d.ts +4 -0
- package/dist/entities/package-changelog/index.d.ts.map +1 -0
- package/dist/entities/package-changelog/index.js +4 -0
- package/dist/entities/package-changelog/index.js.map +1 -0
- package/dist/entities/package-changelog/package-changelog.d.ts +20 -0
- package/dist/entities/package-changelog/package-changelog.d.ts.map +1 -0
- package/dist/entities/package-changelog/package-changelog.js +59 -0
- package/dist/entities/package-changelog/package-changelog.js.map +1 -0
- package/dist/entities/package-changelog/package-changelog.types.d.ts +25 -0
- package/dist/entities/package-changelog/package-changelog.types.d.ts.map +1 -0
- package/dist/entities/package-changelog/package-changelog.types.js +2 -0
- package/dist/entities/package-changelog/package-changelog.types.js.map +1 -0
- package/dist/entities/package-changelog/template.d.ts +20 -0
- package/dist/entities/package-changelog/template.d.ts.map +1 -0
- package/dist/entities/package-changelog/template.default.d.ts +10 -0
- package/dist/entities/package-changelog/template.default.d.ts.map +1 -0
- package/dist/entities/package-changelog/template.default.js +85 -0
- package/dist/entities/package-changelog/template.default.js.map +1 -0
- package/dist/entities/package-changelog/template.js +90 -0
- package/dist/entities/package-changelog/template.js.map +1 -0
- package/dist/entities/package-commits/dependency-analyzer.d.ts +35 -0
- package/dist/entities/package-commits/dependency-analyzer.d.ts.map +1 -0
- package/dist/entities/package-commits/dependency-analyzer.js +169 -0
- package/dist/entities/package-commits/dependency-analyzer.js.map +1 -0
- package/dist/entities/package-commits/dependency-analyzer.test.d.ts +2 -0
- package/dist/entities/package-commits/dependency-analyzer.test.d.ts.map +1 -0
- package/dist/entities/package-commits/dependency-analyzer.test.js +25 -0
- package/dist/entities/package-commits/dependency-analyzer.test.js.map +1 -0
- package/dist/entities/package-commits/index.d.ts +3 -0
- package/dist/entities/package-commits/index.d.ts.map +1 -0
- package/dist/entities/package-commits/index.js +3 -0
- package/dist/entities/package-commits/index.js.map +1 -0
- package/dist/entities/package-commits/package-commits.d.ts +33 -0
- package/dist/entities/package-commits/package-commits.d.ts.map +1 -0
- package/dist/entities/package-commits/package-commits.js +149 -0
- package/dist/entities/package-commits/package-commits.js.map +1 -0
- package/dist/entities/package-commits/package-commits.test.d.ts +2 -0
- package/dist/entities/package-commits/package-commits.test.d.ts.map +1 -0
- package/dist/entities/package-commits/package-commits.test.js +40 -0
- package/dist/entities/package-commits/package-commits.test.js.map +1 -0
- package/dist/entities/package-tags/index.d.ts +2 -0
- package/dist/entities/package-tags/index.d.ts.map +1 -0
- package/dist/entities/package-tags/index.js +2 -0
- package/dist/entities/package-tags/index.js.map +1 -0
- package/dist/entities/package-tags/package-tags.d.ts +24 -0
- package/dist/entities/package-tags/package-tags.d.ts.map +1 -0
- package/dist/entities/package-tags/package-tags.js +197 -0
- package/dist/entities/package-tags/package-tags.js.map +1 -0
- package/dist/entities/package-tags/package-tags.test.d.ts +2 -0
- package/dist/entities/package-tags/package-tags.test.d.ts.map +1 -0
- package/dist/entities/package-tags/package-tags.test.js +60 -0
- package/dist/entities/package-tags/package-tags.test.js.map +1 -0
- package/dist/entities/package-version/index.d.ts +3 -0
- package/dist/entities/package-version/index.d.ts.map +1 -0
- package/dist/entities/package-version/index.js +3 -0
- package/dist/entities/package-version/index.js.map +1 -0
- package/dist/entities/package-version/package-version.d.ts +16 -0
- package/dist/entities/package-version/package-version.d.ts.map +1 -0
- package/dist/entities/package-version/package-version.js +166 -0
- package/dist/entities/package-version/package-version.js.map +1 -0
- package/dist/entities/package-version/package-version.test.d.ts +2 -0
- package/dist/entities/package-version/package-version.test.d.ts.map +1 -0
- package/dist/entities/package-version/package-version.test.js +113 -0
- package/dist/entities/package-version/package-version.test.js.map +1 -0
- package/dist/entities/package-version/package-version.types.d.ts +31 -0
- package/dist/entities/package-version/package-version.types.d.ts.map +1 -0
- package/dist/entities/package-version/package-version.types.js +2 -0
- package/dist/entities/package-version/package-version.types.js.map +1 -0
- package/dist/entities/tag/index.d.ts +3 -0
- package/dist/entities/tag/index.d.ts.map +1 -0
- package/dist/entities/tag/index.js +3 -0
- package/dist/entities/tag/index.js.map +1 -0
- package/dist/entities/tag/tag.d.ts +24 -0
- package/dist/entities/tag/tag.d.ts.map +1 -0
- package/dist/entities/tag/tag.js +168 -0
- package/dist/entities/tag/tag.js.map +1 -0
- package/dist/entities/tag/tag.test.d.ts +2 -0
- package/dist/entities/tag/tag.test.d.ts.map +1 -0
- package/dist/entities/tag/tag.test.js +638 -0
- package/dist/entities/tag/tag.test.js.map +1 -0
- package/dist/entities/tag/tag.types.d.ts +35 -0
- package/dist/entities/tag/tag.types.d.ts.map +1 -0
- package/dist/entities/tag/tag.types.js +2 -0
- package/dist/entities/tag/tag.types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -0
- package/src/commands/ci/act.ts +95 -0
- package/src/commands/ci/attach-affected.ts +93 -0
- package/src/commands/ci/attach-service-ports.ts +31 -0
- package/src/commands/commit-check.ts +124 -0
- package/src/commands/commit.ts +103 -0
- package/src/commands/dev/check.ts +117 -0
- package/src/commands/dev/cleanup.ts +34 -0
- package/src/commands/dev/rm.ts +66 -0
- package/src/commands/dev/setup.ts +48 -0
- package/src/commands/local/cleanup.ts +74 -0
- package/src/commands/local/setup.ts +68 -0
- package/src/commands/local/vscode.ts +118 -0
- package/src/commands/update-package-json.ts +104 -0
- package/src/commands/version/apply.ts +156 -0
- package/src/commands/version/ci.ts +85 -0
- package/src/commands/version/prepare.ts +217 -0
- package/src/core/colorify.ts +61 -0
- package/src/core/index.ts +3 -0
- package/src/core/types.ts +262 -0
- package/src/core/wrapshell.ts +388 -0
- package/src/entities/affected/affected.test.ts +427 -0
- package/src/entities/affected/affected.ts +22 -0
- package/src/entities/affected/index.ts +1 -0
- package/src/entities/branch/branch.test.ts +348 -0
- package/src/entities/branch/branch.ts +89 -0
- package/src/entities/branch/branch.types.ts +5 -0
- package/src/entities/branch/index.ts +2 -0
- package/src/entities/commit/commit.test.ts +769 -0
- package/src/entities/commit/commit.ts +245 -0
- package/src/entities/commit/commit.types.ts +81 -0
- package/src/entities/commit/index.ts +2 -0
- package/src/entities/commit/pr.test.ts +860 -0
- package/src/entities/commit/pr.ts +241 -0
- package/src/entities/compose/compose.test.ts +496 -0
- package/src/entities/compose/compose.ts +251 -0
- package/src/entities/compose/compose.types.ts +88 -0
- package/src/entities/compose/index.ts +2 -0
- package/src/entities/entities.shell.test.ts +35 -0
- package/src/entities/entities.shell.ts +81 -0
- package/src/entities/index.ts +11 -0
- package/src/entities/intershell-config/intershell-config.default.ts +229 -0
- package/src/entities/intershell-config/intershell-config.test.ts +117 -0
- package/src/entities/intershell-config/intershell-config.ts +143 -0
- package/src/entities/intershell-config/intershell-config.types.ts +118 -0
- package/src/entities/package/index.ts +3 -0
- package/src/entities/package/package.shell.ts +124 -0
- package/src/entities/package/package.test.ts +830 -0
- package/src/entities/package/package.ts +267 -0
- package/src/entities/package/package.types.ts +49 -0
- package/src/entities/package-changelog/index.ts +3 -0
- package/src/entities/package-changelog/package-changelog.ts +81 -0
- package/src/entities/package-changelog/package-changelog.types.ts +30 -0
- package/src/entities/package-changelog/template.default.ts +109 -0
- package/src/entities/package-changelog/template.ts +118 -0
- package/src/entities/package-commits/dependency-analyzer.test.ts +29 -0
- package/src/entities/package-commits/dependency-analyzer.ts +194 -0
- package/src/entities/package-commits/index.ts +2 -0
- package/src/entities/package-commits/package-commits.test.ts +44 -0
- package/src/entities/package-commits/package-commits.ts +191 -0
- package/src/entities/package-tags/index.ts +1 -0
- package/src/entities/package-tags/package-tags.test.ts +73 -0
- package/src/entities/package-tags/package-tags.ts +234 -0
- package/src/entities/package-version/index.ts +2 -0
- package/src/entities/package-version/package-version.test.ts +141 -0
- package/src/entities/package-version/package-version.ts +234 -0
- package/src/entities/package-version/package-version.types.ts +35 -0
- package/src/entities/tag/index.ts +2 -0
- package/src/entities/tag/tag.test.ts +844 -0
- package/src/entities/tag/tag.ts +208 -0
- package/src/entities/tag/tag.types.ts +37 -0
- package/src/index.ts +7 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the InterShell CLI framework
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Basic CLI types
|
|
6
|
+
export interface KeyPress {
|
|
7
|
+
sequence: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
ctrl: boolean;
|
|
10
|
+
meta: boolean;
|
|
11
|
+
shift: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ValidationResult<T = unknown> {
|
|
15
|
+
isValid: boolean;
|
|
16
|
+
value?: T;
|
|
17
|
+
error?: string;
|
|
18
|
+
warnings?: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ValidationError {
|
|
22
|
+
message: string;
|
|
23
|
+
field?: string;
|
|
24
|
+
code?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Event system types
|
|
28
|
+
export type EventHandler<T = unknown> = (data: T) => void | Promise<void>;
|
|
29
|
+
|
|
30
|
+
export interface EventEmitter<TEvents extends Record<string, unknown> = Record<string, unknown>> {
|
|
31
|
+
on<K extends keyof TEvents>(event: K, handler: EventHandler<TEvents[K]>): void;
|
|
32
|
+
off<K extends keyof TEvents>(event: K, handler: EventHandler<TEvents[K]>): void;
|
|
33
|
+
emit<K extends keyof TEvents>(event: K, data: TEvents[K]): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// State management types
|
|
37
|
+
export type StateListener<TState> = (state: TState, prevState: TState) => void;
|
|
38
|
+
|
|
39
|
+
export interface StateManager<TState> {
|
|
40
|
+
getState(): TState;
|
|
41
|
+
setState(newState: TState): void;
|
|
42
|
+
subscribe(listener: StateListener<TState>): () => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Script configuration types
|
|
46
|
+
export type ArgOption = {
|
|
47
|
+
short?: string; // pay attention, this turned optional! in affects the logic
|
|
48
|
+
long: string;
|
|
49
|
+
description: string;
|
|
50
|
+
examples?: string[];
|
|
51
|
+
} & (
|
|
52
|
+
| {
|
|
53
|
+
required: true;
|
|
54
|
+
type: "string" | "boolean" | "number";
|
|
55
|
+
validator: (value: string) => boolean | string | Promise<boolean | string>;
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
required: false;
|
|
59
|
+
type: "string" | "boolean" | "number";
|
|
60
|
+
defaultValue?: string | boolean | number;
|
|
61
|
+
validator: (value: string) => boolean | string | Promise<boolean | string>;
|
|
62
|
+
}
|
|
63
|
+
| {
|
|
64
|
+
required: true;
|
|
65
|
+
type: "string[]" | "number[]"; // there is no multi boolean anymore, we must use type conditionals
|
|
66
|
+
validator: (value: string[]) => boolean | string | Promise<boolean | string>;
|
|
67
|
+
}
|
|
68
|
+
| {
|
|
69
|
+
required: false;
|
|
70
|
+
type: "string[]" | "number[]";
|
|
71
|
+
defaultValue?: string[] | number[];
|
|
72
|
+
validator: (value: string[]) => boolean | string | Promise<boolean | string>;
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
export interface ScriptConfig {
|
|
77
|
+
name: string;
|
|
78
|
+
description: string;
|
|
79
|
+
usage?: string;
|
|
80
|
+
examples?: string[];
|
|
81
|
+
options: ArgOption[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type ScriptHandler<TConfig extends ScriptConfig> = (
|
|
85
|
+
args: InferArgs<TConfig>,
|
|
86
|
+
console: Console,
|
|
87
|
+
) => Promise<void> | void;
|
|
88
|
+
|
|
89
|
+
export interface ScriptInstance<TConfig extends ScriptConfig> {
|
|
90
|
+
config: TConfig;
|
|
91
|
+
handler: ScriptHandler<TConfig>;
|
|
92
|
+
run(args?: Partial<InferArgs<TConfig>>): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Utility type to infer argument types from config
|
|
96
|
+
export type InferArgs<TConfig extends ScriptConfig> = {
|
|
97
|
+
[K in TConfig["options"][number] as K["long"] extends `--${infer Name}`
|
|
98
|
+
? Name
|
|
99
|
+
: never]: K extends { required: true; type: infer T }
|
|
100
|
+
? T extends "string[]" | "number[]"
|
|
101
|
+
? string[] | number[]
|
|
102
|
+
: T extends "string"
|
|
103
|
+
? string
|
|
104
|
+
: T extends "boolean"
|
|
105
|
+
? boolean
|
|
106
|
+
: T extends "number"
|
|
107
|
+
? number
|
|
108
|
+
: never
|
|
109
|
+
: K extends { required: false; type: infer T; defaultValue: infer D }
|
|
110
|
+
? T extends "string[]" | "number[]"
|
|
111
|
+
? (string[] | number[]) | D
|
|
112
|
+
: T extends "string"
|
|
113
|
+
? string | D
|
|
114
|
+
: T extends "boolean"
|
|
115
|
+
? boolean | D
|
|
116
|
+
: T extends "number"
|
|
117
|
+
? number | D
|
|
118
|
+
: never
|
|
119
|
+
: K extends { required: false; type: infer T }
|
|
120
|
+
? T extends "string[]" | "number[]"
|
|
121
|
+
? (string[] | number[]) | undefined
|
|
122
|
+
: T extends "string"
|
|
123
|
+
? string | undefined
|
|
124
|
+
: T extends "boolean"
|
|
125
|
+
? boolean | undefined
|
|
126
|
+
: T extends "number"
|
|
127
|
+
? number | undefined
|
|
128
|
+
: never
|
|
129
|
+
: never;
|
|
130
|
+
} & {
|
|
131
|
+
verbose?: boolean;
|
|
132
|
+
quiet?: boolean;
|
|
133
|
+
"dry-run"?: boolean;
|
|
134
|
+
help?: boolean;
|
|
135
|
+
debug?: boolean;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// Hook system types
|
|
139
|
+
export interface HookContext<TConfig extends ScriptConfig> {
|
|
140
|
+
script: ScriptInstance<TConfig>;
|
|
141
|
+
args: InferArgs<TConfig>;
|
|
142
|
+
startTime: number;
|
|
143
|
+
error?: Error;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type Hook<TConfig extends ScriptConfig, TReturn = void> = (
|
|
147
|
+
context: HookContext<TConfig>,
|
|
148
|
+
) => Promise<TReturn> | TReturn;
|
|
149
|
+
|
|
150
|
+
export interface HookSystem<TConfig extends ScriptConfig> {
|
|
151
|
+
beforeRun: Hook<TConfig>[];
|
|
152
|
+
afterRun: Hook<TConfig, unknown>[];
|
|
153
|
+
onError: Hook<TConfig>[];
|
|
154
|
+
onValidation: Hook<TConfig, ValidationResult>[];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Color system types
|
|
158
|
+
export type ColorFunction = (text: string) => string;
|
|
159
|
+
|
|
160
|
+
export interface ColorSystem {
|
|
161
|
+
// Basic colors
|
|
162
|
+
red: ColorFunction;
|
|
163
|
+
green: ColorFunction;
|
|
164
|
+
blue: ColorFunction;
|
|
165
|
+
yellow: ColorFunction;
|
|
166
|
+
cyan: ColorFunction;
|
|
167
|
+
magenta: ColorFunction;
|
|
168
|
+
white: ColorFunction;
|
|
169
|
+
black: ColorFunction;
|
|
170
|
+
gray: ColorFunction;
|
|
171
|
+
grey: ColorFunction;
|
|
172
|
+
|
|
173
|
+
// Styles
|
|
174
|
+
bold: ColorFunction;
|
|
175
|
+
italic: ColorFunction;
|
|
176
|
+
underline: ColorFunction;
|
|
177
|
+
strikethrough: ColorFunction;
|
|
178
|
+
|
|
179
|
+
// Advanced colors
|
|
180
|
+
rgb(r: number, g: number, b: number): ColorFunction;
|
|
181
|
+
hsl(h: number, s: number, l: number): ColorFunction;
|
|
182
|
+
hex(color: string): ColorFunction;
|
|
183
|
+
|
|
184
|
+
// Effects
|
|
185
|
+
gradient(colors: string[]): ColorFunction;
|
|
186
|
+
rainbow: ColorFunction;
|
|
187
|
+
|
|
188
|
+
// Utilities
|
|
189
|
+
strip(text: string): string;
|
|
190
|
+
supportsColor(): boolean;
|
|
191
|
+
enable(): void;
|
|
192
|
+
disable(): void;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// CLI Tools types
|
|
196
|
+
export interface QuickAction {
|
|
197
|
+
key: string;
|
|
198
|
+
label: string;
|
|
199
|
+
description: string;
|
|
200
|
+
shortcut?: string;
|
|
201
|
+
action: () => void | Promise<void>;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface SelectConfig {
|
|
205
|
+
multiple?: boolean;
|
|
206
|
+
clearScreen?: boolean;
|
|
207
|
+
showCursor?: boolean;
|
|
208
|
+
exitOnCtrlC?: boolean;
|
|
209
|
+
quickActions?: QuickAction[];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface PromptConfig {
|
|
213
|
+
clearScreen?: boolean;
|
|
214
|
+
allowEmpty?: boolean;
|
|
215
|
+
showCursor?: boolean;
|
|
216
|
+
exitOnCtrlC?: boolean;
|
|
217
|
+
quickActions?: QuickAction[];
|
|
218
|
+
onLeft?: () => void;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface ConfirmConfig {
|
|
222
|
+
clearScreen?: boolean;
|
|
223
|
+
defaultValue?: boolean;
|
|
224
|
+
exitOnCtrlC?: boolean;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Interactive CLI types
|
|
228
|
+
export interface InteractiveCLIOptions {
|
|
229
|
+
enableRawMode?: boolean;
|
|
230
|
+
exitOnCtrlC?: boolean;
|
|
231
|
+
clearOnExit?: boolean;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export interface InteractiveCLI {
|
|
235
|
+
// Core methods
|
|
236
|
+
select(question: string, options: string[], config?: SelectConfig): Promise<string[]>;
|
|
237
|
+
prompt(question: string, config?: PromptConfig): Promise<string>;
|
|
238
|
+
confirm(question: string, config?: ConfirmConfig): Promise<boolean>;
|
|
239
|
+
|
|
240
|
+
// Screen management
|
|
241
|
+
clearScreen(): void;
|
|
242
|
+
showCursor(): void;
|
|
243
|
+
hideCursor(): void;
|
|
244
|
+
|
|
245
|
+
// Event handling
|
|
246
|
+
onKeyPress(callback: (key: KeyPress) => void): void;
|
|
247
|
+
offKeyPress(callback: (key: KeyPress) => void): void;
|
|
248
|
+
|
|
249
|
+
// Lifecycle
|
|
250
|
+
cleanup(): void;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Framework-specific types (will be extended by interactive package)
|
|
254
|
+
export interface FrameworkOptions {
|
|
255
|
+
debug?: boolean;
|
|
256
|
+
logLevel?: "error" | "warn" | "info" | "debug";
|
|
257
|
+
enableHotkeys?: boolean;
|
|
258
|
+
enableHistory?: boolean;
|
|
259
|
+
maxHistorySize?: number;
|
|
260
|
+
renderMode?: "immediate" | "debounced" | "throttled";
|
|
261
|
+
renderDelay?: number;
|
|
262
|
+
}
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { existsSync, statSync } from "node:fs";
|
|
2
|
+
import { colorify } from "./colorify";
|
|
3
|
+
import type {
|
|
4
|
+
ArgOption,
|
|
5
|
+
HookContext,
|
|
6
|
+
HookSystem,
|
|
7
|
+
InferArgs,
|
|
8
|
+
ScriptConfig,
|
|
9
|
+
ScriptHandler,
|
|
10
|
+
ScriptInstance,
|
|
11
|
+
} from "./types";
|
|
12
|
+
|
|
13
|
+
const validators = {
|
|
14
|
+
nonEmpty: (value: string): boolean | string => {
|
|
15
|
+
if (value.trim().length === 0) {
|
|
16
|
+
return "Value cannot be empty";
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
},
|
|
20
|
+
boolean: (value: string): boolean | string => {
|
|
21
|
+
const lowerValue = value.toLowerCase();
|
|
22
|
+
if (lowerValue === "true" || lowerValue === "1" || lowerValue === "yes") {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (lowerValue === "false" || lowerValue === "0" || lowerValue === "no") {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return "Value must be a boolean (true/false, 1/0, yes/no)";
|
|
29
|
+
},
|
|
30
|
+
number: (value: string): boolean | string => {
|
|
31
|
+
const num = Number(value);
|
|
32
|
+
if (Number.isNaN(num) || !Number.isFinite(num)) {
|
|
33
|
+
return "Value must be a valid number";
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
},
|
|
37
|
+
integer: (value: string): boolean | string => {
|
|
38
|
+
const num = Number(value);
|
|
39
|
+
if (Number.isNaN(num) || !Number.isFinite(num) || !Number.isInteger(num)) {
|
|
40
|
+
return "Value must be an integer";
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
},
|
|
44
|
+
fileExists: (filePath: string): boolean | string => {
|
|
45
|
+
try {
|
|
46
|
+
const file = Bun.file(filePath);
|
|
47
|
+
if (!file.size) {
|
|
48
|
+
return `File "${filePath}" not found.`;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
} catch {
|
|
52
|
+
return `File "${filePath}" not found.`;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
directoryExists: (path: string): boolean | string => {
|
|
56
|
+
try {
|
|
57
|
+
const exists = existsSync(path) && statSync(path).isDirectory();
|
|
58
|
+
if (!exists) {
|
|
59
|
+
return `Directory does not exist: ${path}`;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
return `Error checking directory: ${error instanceof Error ? error.message : String(error)}`;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
enum:
|
|
67
|
+
(allowedValues: string[]) =>
|
|
68
|
+
(value: string): boolean | string => {
|
|
69
|
+
if (!allowedValues.includes(value)) {
|
|
70
|
+
return `Invalid value "${value}". Valid values: ${allowedValues.join(", ")}`;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
},
|
|
74
|
+
regex:
|
|
75
|
+
(pattern: RegExp, message?: string) =>
|
|
76
|
+
(value: string): boolean | string => {
|
|
77
|
+
if (!pattern.test(value)) {
|
|
78
|
+
return message || `Value must match pattern: ${pattern}`;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
},
|
|
82
|
+
custom:
|
|
83
|
+
<T>(validator: (value: string) => T | string) =>
|
|
84
|
+
(value: string): boolean | string => {
|
|
85
|
+
try {
|
|
86
|
+
const result = validator(value);
|
|
87
|
+
if (typeof result === "string") {
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
return error instanceof Error ? error.message : String(error);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
url: (value: string): boolean | string => {
|
|
96
|
+
try {
|
|
97
|
+
new URL(value);
|
|
98
|
+
return true;
|
|
99
|
+
} catch {
|
|
100
|
+
return "Value must be a valid URL";
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
email: (value: string): boolean | string => {
|
|
104
|
+
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
105
|
+
if (!emailRegex.test(value)) {
|
|
106
|
+
return "Value must be a valid email address";
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
},
|
|
110
|
+
semver: (value: string): boolean | string => {
|
|
111
|
+
const semverRegex =
|
|
112
|
+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
113
|
+
if (!semverRegex.test(value)) {
|
|
114
|
+
return "Value must be a valid semantic version (e.g., 1.0.0)";
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
},
|
|
118
|
+
} as const;
|
|
119
|
+
|
|
120
|
+
const defaultConfig = {
|
|
121
|
+
name: "Script",
|
|
122
|
+
description: "A CLI script",
|
|
123
|
+
options: [
|
|
124
|
+
{
|
|
125
|
+
short: "-v",
|
|
126
|
+
long: "--verbose",
|
|
127
|
+
description: "Enable verbose logging",
|
|
128
|
+
required: false,
|
|
129
|
+
type: "boolean" as const,
|
|
130
|
+
defaultValue: true,
|
|
131
|
+
validator: validators.boolean,
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
short: "-q",
|
|
135
|
+
long: "--quiet",
|
|
136
|
+
description: "Suppress output",
|
|
137
|
+
required: false,
|
|
138
|
+
type: "boolean" as const,
|
|
139
|
+
defaultValue: false,
|
|
140
|
+
validator: validators.boolean,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
short: "",
|
|
144
|
+
long: "--dry-run",
|
|
145
|
+
description: "Show what would happen without executing",
|
|
146
|
+
required: false,
|
|
147
|
+
type: "boolean" as const,
|
|
148
|
+
defaultValue: false,
|
|
149
|
+
validator: validators.boolean,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
short: "-h",
|
|
153
|
+
long: "--help",
|
|
154
|
+
description: "Show help information",
|
|
155
|
+
required: false,
|
|
156
|
+
type: "boolean" as const,
|
|
157
|
+
defaultValue: false,
|
|
158
|
+
validator: validators.boolean,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
} as const satisfies ScriptConfig;
|
|
162
|
+
|
|
163
|
+
class WrapShell<TConfig extends ScriptConfig> {
|
|
164
|
+
private config: TConfig;
|
|
165
|
+
private hooks: Partial<HookSystem<TConfig>> = {};
|
|
166
|
+
|
|
167
|
+
constructor(config: TConfig) {
|
|
168
|
+
this.config = config;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
static createScript<TConfig extends ScriptConfig>(
|
|
172
|
+
config: TConfig,
|
|
173
|
+
handler: ScriptHandler<TConfig>,
|
|
174
|
+
): ScriptInstance<TConfig> {
|
|
175
|
+
const wrapShell = new WrapShell(config);
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
config,
|
|
179
|
+
handler,
|
|
180
|
+
run: async (passedArgs?: InferArgs<TConfig>) => {
|
|
181
|
+
const context: HookContext<TConfig> = {
|
|
182
|
+
startTime: Date.now(),
|
|
183
|
+
args:
|
|
184
|
+
passedArgs ||
|
|
185
|
+
(await wrapShell.parseArgs().catch((e) => {
|
|
186
|
+
wrapShell.showHelp(null);
|
|
187
|
+
console.error(e);
|
|
188
|
+
process.exit(1);
|
|
189
|
+
})),
|
|
190
|
+
script: { config, handler, run: async () => {} },
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
if (wrapShell.hooks.beforeRun) {
|
|
195
|
+
for (const hook of wrapShell.hooks.beforeRun) {
|
|
196
|
+
await hook(context);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const enhancedConsole = wrapShell.createEnhancedConsole(context.args);
|
|
201
|
+
const result = await handler(context.args, enhancedConsole);
|
|
202
|
+
|
|
203
|
+
if (wrapShell.hooks.afterRun) {
|
|
204
|
+
for (const hook of wrapShell.hooks.afterRun) {
|
|
205
|
+
await hook(context);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return result;
|
|
210
|
+
} catch (error) {
|
|
211
|
+
if (wrapShell.hooks.onError) {
|
|
212
|
+
for (const hook of wrapShell.hooks.onError) {
|
|
213
|
+
await hook({ ...context, error: error as Error });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!context.args.debug) {
|
|
218
|
+
(error as Error).stack = undefined;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private async parseArgs(): Promise<InferArgs<TConfig>> {
|
|
228
|
+
const args = process.argv.slice(2);
|
|
229
|
+
const result: Record<string, unknown> = {};
|
|
230
|
+
const allOptions = [...defaultConfig.options, ...this.config.options];
|
|
231
|
+
|
|
232
|
+
allOptions.forEach((option) => {
|
|
233
|
+
const key = option.long.replace("--", "");
|
|
234
|
+
if (
|
|
235
|
+
option.required === false &&
|
|
236
|
+
"defaultValue" in option &&
|
|
237
|
+
option.defaultValue !== undefined
|
|
238
|
+
) {
|
|
239
|
+
result[key] = option.defaultValue;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
for (let i = 0; i < args.length; i++) {
|
|
244
|
+
const arg = args[i];
|
|
245
|
+
const nextArg = args[i + 1];
|
|
246
|
+
|
|
247
|
+
if (arg === "-h" || arg === "--help") {
|
|
248
|
+
this.showHelp(result as InferArgs<TConfig>);
|
|
249
|
+
process.exit(0);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const option = allOptions.find((opt) => opt.short === arg || opt.long === arg);
|
|
253
|
+
if (option) {
|
|
254
|
+
const key = option.long.replace("--", "");
|
|
255
|
+
|
|
256
|
+
if (option.type === "boolean") {
|
|
257
|
+
result[key] = true;
|
|
258
|
+
} else if (nextArg && !nextArg.startsWith("-")) {
|
|
259
|
+
result[key] = nextArg;
|
|
260
|
+
i++;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
await this.validateParsedArgs(result, allOptions);
|
|
266
|
+
|
|
267
|
+
return result as InferArgs<TConfig>;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private async validateParsedArgs(
|
|
271
|
+
args: Record<string, unknown>,
|
|
272
|
+
options: readonly ArgOption[],
|
|
273
|
+
): Promise<void> {
|
|
274
|
+
for (const option of options) {
|
|
275
|
+
const key = option.long.replace("--", "");
|
|
276
|
+
const value = args[key];
|
|
277
|
+
|
|
278
|
+
if (option.required && (value === undefined || value === null || value === "")) {
|
|
279
|
+
throw new Error(`Required option ${option.long} is missing`);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (value !== undefined && option.validator) {
|
|
283
|
+
let validation: boolean | string | Promise<boolean | string>;
|
|
284
|
+
|
|
285
|
+
if (option.type === "string[]" || option.type === "number[]") {
|
|
286
|
+
// For array types, pass the array directly
|
|
287
|
+
if (Array.isArray(value)) {
|
|
288
|
+
validation = await (
|
|
289
|
+
option.validator as (value: string[]) => boolean | string | Promise<boolean | string>
|
|
290
|
+
)(value);
|
|
291
|
+
} else {
|
|
292
|
+
throw new Error(`Expected array for ${option.long}, got ${typeof value}`);
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
// For single value types, convert to string
|
|
296
|
+
validation = await (
|
|
297
|
+
option.validator as (value: string) => boolean | string | Promise<boolean | string>
|
|
298
|
+
)(String(value));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (typeof validation === "string") {
|
|
302
|
+
throw new Error(`Invalid value for ${option.long}: ${validation}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
private createEnhancedConsole(args: InferArgs<TConfig>): Console {
|
|
309
|
+
const originalConsole = console;
|
|
310
|
+
|
|
311
|
+
return Object.assign({}, originalConsole, {
|
|
312
|
+
log: (...props: Parameters<typeof console.log>) => {
|
|
313
|
+
if (!("quiet" in args) || !args.quiet) {
|
|
314
|
+
originalConsole.log(...props);
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
info: (...props: Parameters<typeof console.info>) => {
|
|
318
|
+
if (!("quiet" in args) || !args.quiet) {
|
|
319
|
+
originalConsole.warn(...props);
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
warn: (...props: Parameters<typeof console.warn>) => {
|
|
323
|
+
if (!("quiet" in args) || !args.quiet) {
|
|
324
|
+
originalConsole.warn(...props);
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
error: (...props: Parameters<typeof console.error>) => {
|
|
328
|
+
originalConsole.error(...props);
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private showHelp(args: InferArgs<TConfig> | null): void {
|
|
334
|
+
const xConsole = this.createEnhancedConsole(args || ({} as InferArgs<TConfig>));
|
|
335
|
+
xConsole.log(colorify.blue(this.config.name));
|
|
336
|
+
xConsole.log(this.config.description);
|
|
337
|
+
xConsole.log();
|
|
338
|
+
|
|
339
|
+
if (this.config.usage) {
|
|
340
|
+
xConsole.log("Usage:");
|
|
341
|
+
xConsole.log(` ${this.config.usage}\n`);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const allOptions = [...defaultConfig.options, ...this.config.options];
|
|
345
|
+
if (allOptions.length > 0) {
|
|
346
|
+
xConsole.log("Options:");
|
|
347
|
+
allOptions.forEach((option) => {
|
|
348
|
+
const shortFlag = option.short ? `${option.short}, ` : " ";
|
|
349
|
+
const required = option.required ? colorify.red(" (required)") : "";
|
|
350
|
+
xConsole.log(` ${shortFlag}${option.long}${required}`);
|
|
351
|
+
xConsole.log(` ${option.description}`);
|
|
352
|
+
});
|
|
353
|
+
xConsole.log();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (this.config.examples && this.config.examples.length > 0) {
|
|
357
|
+
xConsole.log("Examples:");
|
|
358
|
+
this.config.examples.forEach((example) => {
|
|
359
|
+
xConsole.log(` ${colorify.gray(example)}`);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
static hooks = {
|
|
365
|
+
beforeRun: <TConfig extends ScriptConfig>(
|
|
366
|
+
hook: (context: HookContext<TConfig>) => Promise<void> | void,
|
|
367
|
+
) => hook,
|
|
368
|
+
afterRun: <TConfig extends ScriptConfig>(
|
|
369
|
+
hook: (context: HookContext<TConfig>) => Promise<void> | void,
|
|
370
|
+
) => hook,
|
|
371
|
+
onError: <TConfig extends ScriptConfig>(
|
|
372
|
+
hook: (context: HookContext<TConfig> & { error: Error }) => Promise<void> | void,
|
|
373
|
+
) => hook,
|
|
374
|
+
onValidation: <TConfig extends ScriptConfig>(
|
|
375
|
+
hook: (context: HookContext<TConfig>) => Promise<void> | void,
|
|
376
|
+
) => hook,
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
static validators = validators;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export function createScript<TConfig extends ScriptConfig>(
|
|
383
|
+
config: TConfig,
|
|
384
|
+
handler: ScriptHandler<TConfig>,
|
|
385
|
+
): ScriptInstance<TConfig> {
|
|
386
|
+
return WrapShell.createScript(config, handler);
|
|
387
|
+
}
|
|
388
|
+
createScript.validators = validators;
|