goke 6.3.1 → 6.4.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 +104 -32
- package/dist/__test__/index.test.js +23 -0
- package/dist/__test__/just-bash.test.d.ts +5 -0
- package/dist/__test__/just-bash.test.d.ts.map +1 -0
- package/dist/__test__/just-bash.test.js +97 -0
- package/dist/__test__/types.test-d.js +10 -4
- package/dist/goke.d.ts +33 -13
- package/dist/goke.d.ts.map +1 -1
- package/dist/goke.js +113 -41
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/just-bash.d.ts +23 -0
- package/dist/just-bash.d.ts.map +1 -0
- package/dist/just-bash.js +65 -0
- package/dist/runtime-browser.d.ts +31 -0
- package/dist/runtime-browser.d.ts.map +1 -0
- package/dist/runtime-browser.js +47 -0
- package/dist/runtime-node.d.ts +8 -0
- package/dist/runtime-node.d.ts.map +1 -0
- package/dist/runtime-node.js +27 -0
- package/package.json +9 -1
- package/src/__test__/index.test.ts +31 -0
- package/src/__test__/just-bash.test.ts +124 -0
- package/src/__test__/types.test-d.ts +10 -4
- package/src/goke.ts +143 -44
- package/src/index.ts +2 -2
- package/src/just-bash.ts +90 -0
- package/src/runtime-browser.ts +59 -0
- package/src/runtime-node.ts +29 -0
package/dist/goke.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"goke.d.ts","sourceRoot":"","sources":["../src/goke.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"goke.d.ts","sourceRoot":"","sources":["../src/goke.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAW,MAAM,UAAU,CAAA;AAkN/D,cAAM,MAAM;IAwBD,OAAO,EAAE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AO,CAAC,OAAO,EAAE,cAAc;IAK/B;;;;OAIG;IACH,QAAQ,IAAI,MAAM;IAOlB;;;;OAIG;IACH,UAAU;IAIV;;;OAGG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,EAAE,YAAY,UAAQ;IAwBrF;;;OAGG;IACH,aAAa;IAIb,OAAO,CAAC,aAAa;IAgBrB,mBAAmB;IAKnB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAYtB;;OAEG;IACH,KAAK,CACH,IAAI,WAAoB,EACxB;IACE,oDAAoD;IACpD,GAAU,GACX;;KAAK,GACL,UAAU;IA2Ib,OAAO,CAAC,GAAG;IA6HX,iBAAiB;CA0FlB;AAID,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAA;AAC7F,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,CAAA;AACjE,eAAe,IAAI,CAAA"}
|
package/dist/goke.js
CHANGED
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
* - createConsole: factory for console-like objects from output streams
|
|
10
10
|
* - Utility functions: string helpers, bracket parsing, dot-prop access
|
|
11
11
|
*/
|
|
12
|
-
import { EventEmitter } from 'events';
|
|
13
12
|
import pc from 'picocolors';
|
|
14
13
|
import mri from "./mri.js";
|
|
15
14
|
import { GokeError, coerceBySchema, extractJsonSchema, extractSchemaMetadata, isStandardSchema } from "./coerce.js";
|
|
15
|
+
import { createJustBashCommand as createJustBashCommandBridge } from './just-bash.js';
|
|
16
|
+
import { EventEmitter, openInBrowser, process } from '#runtime';
|
|
16
17
|
// ─── Node.js platform constants ───
|
|
17
18
|
const processArgs = process.argv;
|
|
18
19
|
const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
@@ -238,6 +239,9 @@ class Option {
|
|
|
238
239
|
this.isBoolean = true;
|
|
239
240
|
}
|
|
240
241
|
}
|
|
242
|
+
clone() {
|
|
243
|
+
return new Option(this.rawName, this.schema ?? this.description);
|
|
244
|
+
}
|
|
241
245
|
}
|
|
242
246
|
class Command {
|
|
243
247
|
rawName;
|
|
@@ -255,6 +259,7 @@ class Command {
|
|
|
255
259
|
examples;
|
|
256
260
|
helpCallback;
|
|
257
261
|
globalCommand;
|
|
262
|
+
_hidden;
|
|
258
263
|
constructor(rawName, description, config = {}, cli) {
|
|
259
264
|
this.rawName = rawName;
|
|
260
265
|
this.description = description;
|
|
@@ -296,6 +301,10 @@ class Command {
|
|
|
296
301
|
this.aliasNames.push(name);
|
|
297
302
|
return this;
|
|
298
303
|
}
|
|
304
|
+
hidden() {
|
|
305
|
+
this._hidden = true;
|
|
306
|
+
return this;
|
|
307
|
+
}
|
|
299
308
|
action(callback) {
|
|
300
309
|
this.commandAction = callback;
|
|
301
310
|
return this;
|
|
@@ -353,7 +362,7 @@ class Command {
|
|
|
353
362
|
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
|
354
363
|
const terminalWidth = Math.max(this.cli.columns, 40);
|
|
355
364
|
if (showCommands) {
|
|
356
|
-
const commandRows = commands.map((command) => {
|
|
365
|
+
const commandRows = commands.filter((command) => !command._hidden).map((command) => {
|
|
357
366
|
const displayName = command.rawName.trim() === '' ? name : command.rawName;
|
|
358
367
|
// Hide deprecated options from subcommand help output
|
|
359
368
|
const displayOptions = command.isDefaultCommand ? [] : command.options.filter((o) => !o.deprecated);
|
|
@@ -546,6 +555,29 @@ class GlobalCommand extends Command {
|
|
|
546
555
|
super('@@global@@', '', {}, cli);
|
|
547
556
|
}
|
|
548
557
|
}
|
|
558
|
+
const cloneCommandInto = (source, cli) => {
|
|
559
|
+
const target = source instanceof GlobalCommand
|
|
560
|
+
? new GlobalCommand(cli)
|
|
561
|
+
: new Command(source.rawName, source.description, { ...source.config }, cli);
|
|
562
|
+
target.aliasNames = [...source.aliasNames];
|
|
563
|
+
target.usageText = source.usageText;
|
|
564
|
+
target.versionNumber = source.versionNumber;
|
|
565
|
+
target.examples = [...source.examples];
|
|
566
|
+
target.helpCallback = source.helpCallback;
|
|
567
|
+
target.commandAction = source.commandAction;
|
|
568
|
+
target._hidden = source._hidden;
|
|
569
|
+
target.options = source.options.map((option) => option.clone());
|
|
570
|
+
target.globalCommand = cli.globalCommand;
|
|
571
|
+
return target;
|
|
572
|
+
};
|
|
573
|
+
class GokeProcessExit extends Error {
|
|
574
|
+
code;
|
|
575
|
+
constructor(code) {
|
|
576
|
+
super(`process.exit(${code})`);
|
|
577
|
+
this.name = 'GokeProcessExit';
|
|
578
|
+
this.code = code;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
549
581
|
/**
|
|
550
582
|
* Creates a console-like object that writes to the given output streams.
|
|
551
583
|
*
|
|
@@ -561,6 +593,12 @@ function createConsole(stdout, stderr) {
|
|
|
561
593
|
error(...args) {
|
|
562
594
|
stderr.write(args.map(String).join(' ') + '\n');
|
|
563
595
|
},
|
|
596
|
+
warn(...args) {
|
|
597
|
+
stderr.write(args.map(String).join(' ') + '\n');
|
|
598
|
+
},
|
|
599
|
+
info(...args) {
|
|
600
|
+
stdout.write(args.map(String).join(' ') + '\n');
|
|
601
|
+
},
|
|
564
602
|
};
|
|
565
603
|
}
|
|
566
604
|
// ─── Error formatting ───
|
|
@@ -636,6 +674,46 @@ class Goke extends EventEmitter {
|
|
|
636
674
|
this.globalCommand = new GlobalCommand(this);
|
|
637
675
|
this.globalCommand.usage('<command> [options]');
|
|
638
676
|
}
|
|
677
|
+
clone(options) {
|
|
678
|
+
const cloned = new Goke(this.name, {
|
|
679
|
+
stdout: options?.stdout ?? this.stdout,
|
|
680
|
+
stderr: options?.stderr ?? this.stderr,
|
|
681
|
+
argv: options?.argv ?? this.#defaultArgv,
|
|
682
|
+
columns: options?.columns ?? this.columns,
|
|
683
|
+
exit: options?.exit ?? this.exit,
|
|
684
|
+
});
|
|
685
|
+
cloned.showHelpOnExit = this.showHelpOnExit;
|
|
686
|
+
cloned.showVersionOnExit = this.showVersionOnExit;
|
|
687
|
+
cloned.globalCommand = cloneCommandInto(this.globalCommand, cloned);
|
|
688
|
+
cloned.commands = this.commands.map((command) => cloneCommandInto(command, cloned));
|
|
689
|
+
for (const command of cloned.commands) {
|
|
690
|
+
command.globalCommand = cloned.globalCommand;
|
|
691
|
+
}
|
|
692
|
+
cloned.middlewares = this.middlewares.map((middleware) => ({ action: middleware.action }));
|
|
693
|
+
for (const eventName of this.eventNames()) {
|
|
694
|
+
for (const listener of this.listeners(eventName)) {
|
|
695
|
+
cloned.on(eventName, listener);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return cloned;
|
|
699
|
+
}
|
|
700
|
+
createExecutionContext(argv = this.rawArgs) {
|
|
701
|
+
return {
|
|
702
|
+
console: this.console,
|
|
703
|
+
process: {
|
|
704
|
+
argv,
|
|
705
|
+
stdout: this.stdout,
|
|
706
|
+
stderr: this.stderr,
|
|
707
|
+
exit: (code) => {
|
|
708
|
+
this.exit(code);
|
|
709
|
+
throw new GokeProcessExit(code);
|
|
710
|
+
},
|
|
711
|
+
},
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
async createJustBashCommand(options) {
|
|
715
|
+
return createJustBashCommandBridge(this, options);
|
|
716
|
+
}
|
|
639
717
|
/**
|
|
640
718
|
* Add a global usage text.
|
|
641
719
|
*
|
|
@@ -666,15 +744,16 @@ class Goke extends EventEmitter {
|
|
|
666
744
|
* options (e.g. setting up logging, initializing state).
|
|
667
745
|
*
|
|
668
746
|
* The callback receives the parsed options object, typed according to all
|
|
669
|
-
* `.option()` calls that precede this `.use()` in the chain
|
|
747
|
+
* `.option()` calls that precede this `.use()` in the chain, plus an injected
|
|
748
|
+
* execution context with `{ console, process }` for portable output and exits.
|
|
670
749
|
*
|
|
671
750
|
* @example
|
|
672
751
|
* ```ts
|
|
673
752
|
* cli
|
|
674
753
|
* .option('--verbose', z.boolean().default(false).describe('Verbose'))
|
|
675
|
-
* .use((options) => {
|
|
754
|
+
* .use((options, { console }) => {
|
|
676
755
|
* if (options.verbose) {
|
|
677
|
-
*
|
|
756
|
+
* console.log('verbose mode enabled')
|
|
678
757
|
* }
|
|
679
758
|
* })
|
|
680
759
|
* ```
|
|
@@ -1031,6 +1110,7 @@ class Goke extends EventEmitter {
|
|
|
1031
1110
|
}
|
|
1032
1111
|
runMatchedCommand() {
|
|
1033
1112
|
const { args, options, matchedCommand: command } = this;
|
|
1113
|
+
const executionContext = this.createExecutionContext();
|
|
1034
1114
|
if (!command || !command.commandAction)
|
|
1035
1115
|
return;
|
|
1036
1116
|
try {
|
|
@@ -1055,6 +1135,7 @@ class Goke extends EventEmitter {
|
|
|
1055
1135
|
}
|
|
1056
1136
|
});
|
|
1057
1137
|
actionArgs.push(options);
|
|
1138
|
+
actionArgs.push(executionContext);
|
|
1058
1139
|
const executeAction = () => command.commandAction.apply(this, actionArgs);
|
|
1059
1140
|
const handleAsyncError = (err) => {
|
|
1060
1141
|
if (err instanceof Error) {
|
|
@@ -1071,58 +1152,49 @@ class Goke extends EventEmitter {
|
|
|
1071
1152
|
let asyncChain = null;
|
|
1072
1153
|
for (const mw of this.middlewares) {
|
|
1073
1154
|
if (asyncChain) {
|
|
1074
|
-
asyncChain = asyncChain.then(() => mw.action(options));
|
|
1155
|
+
asyncChain = asyncChain.then(() => mw.action(options, executionContext));
|
|
1075
1156
|
}
|
|
1076
1157
|
else {
|
|
1077
1158
|
try {
|
|
1078
|
-
const mwResult = mw.action(options);
|
|
1159
|
+
const mwResult = mw.action(options, executionContext);
|
|
1079
1160
|
if (isPromiseLike(mwResult)) {
|
|
1080
1161
|
asyncChain = mwResult;
|
|
1081
1162
|
}
|
|
1082
1163
|
}
|
|
1083
1164
|
catch (err) {
|
|
1165
|
+
if (err instanceof GokeProcessExit) {
|
|
1166
|
+
throw err;
|
|
1167
|
+
}
|
|
1084
1168
|
handleAsyncError(err);
|
|
1085
1169
|
return;
|
|
1086
1170
|
}
|
|
1087
1171
|
}
|
|
1088
1172
|
}
|
|
1089
|
-
const
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
// ─── openInBrowser ───
|
|
1100
|
-
/**
|
|
1101
|
-
* Open a URL in the default browser.
|
|
1102
|
-
* In non-TTY environments (CI, piped output, agents), prints the URL to stdout instead.
|
|
1103
|
-
*/
|
|
1104
|
-
function openInBrowser(url) {
|
|
1105
|
-
if (!process.stdout.isTTY) {
|
|
1106
|
-
console.error(url);
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1109
|
-
const { execSync } = require('child_process');
|
|
1110
|
-
const platform = process.platform;
|
|
1111
|
-
try {
|
|
1112
|
-
if (platform === 'darwin') {
|
|
1113
|
-
execSync(`open ${JSON.stringify(url)}`, { stdio: 'ignore' });
|
|
1173
|
+
const catchAsyncError = (err) => {
|
|
1174
|
+
if (err instanceof GokeProcessExit) {
|
|
1175
|
+
throw err;
|
|
1176
|
+
}
|
|
1177
|
+
handleAsyncError(err);
|
|
1178
|
+
};
|
|
1179
|
+
if (asyncChain) {
|
|
1180
|
+
return asyncChain
|
|
1181
|
+
.then(executeAction)
|
|
1182
|
+
.catch(catchAsyncError);
|
|
1114
1183
|
}
|
|
1115
|
-
|
|
1116
|
-
|
|
1184
|
+
try {
|
|
1185
|
+
const result = executeAction();
|
|
1186
|
+
return isPromiseLike(result)
|
|
1187
|
+
? result.catch(catchAsyncError)
|
|
1188
|
+
: result;
|
|
1117
1189
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1190
|
+
catch (err) {
|
|
1191
|
+
if (err instanceof GokeProcessExit) {
|
|
1192
|
+
throw err;
|
|
1193
|
+
}
|
|
1194
|
+
handleAsyncError(err);
|
|
1195
|
+
return;
|
|
1120
1196
|
}
|
|
1121
1197
|
}
|
|
1122
|
-
catch {
|
|
1123
|
-
// fallback: print the URL if open fails
|
|
1124
|
-
console.error(url);
|
|
1125
|
-
}
|
|
1126
1198
|
}
|
|
1127
|
-
export { createConsole, Command, openInBrowser };
|
|
1199
|
+
export { createConsole, Command, GokeProcessExit, openInBrowser };
|
|
1128
1200
|
export default Goke;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ import { Command } from "./goke.js";
|
|
|
8
8
|
declare const goke: (name?: string, options?: GokeOptions) => Goke<{}>;
|
|
9
9
|
export default goke;
|
|
10
10
|
export { goke, Goke, Command };
|
|
11
|
-
export { createConsole, openInBrowser } from "./goke.js";
|
|
12
|
-
export type { GokeOutputStream, GokeConsole, GokeOptions } from "./goke.js";
|
|
11
|
+
export { createConsole, GokeProcessExit, openInBrowser } from "./goke.js";
|
|
12
|
+
export type { GokeOutputStream, GokeConsole, GokeExecutionContext, GokeOptions, GokeProcess } from "./goke.js";
|
|
13
13
|
export type { StandardTypedV1, StandardJSONSchemaV1, JsonSchema } from "./coerce.js";
|
|
14
14
|
export { GokeError, coerceBySchema, extractJsonSchema, wrapJsonSchema, isStandardSchema, extractSchemaMetadata } from "./coerce.js";
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC;;;GAGG;AACH,QAAA,MAAM,IAAI,GAAI,aAAS,EAAE,UAAU,WAAW,aAA4B,CAAA;AAE1E,eAAe,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC;;;GAGG;AACH,QAAA,MAAM,IAAI,GAAI,aAAS,EAAE,UAAU,WAAW,aAA4B,CAAA;AAE1E,eAAe,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,oBAAoB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAC9G,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACpF,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -7,5 +7,5 @@ import { Command } from "./goke.js";
|
|
|
7
7
|
const goke = (name = '', options) => new Goke(name, options);
|
|
8
8
|
export default goke;
|
|
9
9
|
export { goke, Goke, Command };
|
|
10
|
-
export { createConsole, openInBrowser } from "./goke.js";
|
|
10
|
+
export { createConsole, GokeProcessExit, openInBrowser } from "./goke.js";
|
|
11
11
|
export { GokeError, coerceBySchema, extractJsonSchema, wrapJsonSchema, isStandardSchema, extractSchemaMetadata } from "./coerce.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime adapter that exposes a goke CLI as a JustBash-compatible custom command.
|
|
3
|
+
*
|
|
4
|
+
* Structural types here are based on JustBash source definitions:
|
|
5
|
+
* - https://github.com/vercel-labs/just-bash/blob/main/src/custom-commands.ts
|
|
6
|
+
* - https://github.com/vercel-labs/just-bash/blob/main/src/types.ts
|
|
7
|
+
*/
|
|
8
|
+
import Goke from './goke.js';
|
|
9
|
+
interface JustBashExecResult {
|
|
10
|
+
stdout: string;
|
|
11
|
+
stderr: string;
|
|
12
|
+
exitCode: number;
|
|
13
|
+
}
|
|
14
|
+
interface JustBashCommand {
|
|
15
|
+
name: string;
|
|
16
|
+
trusted: true;
|
|
17
|
+
execute(args: string[]): Promise<JustBashExecResult>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createJustBashCommand(cli: Goke<any>, options?: {
|
|
20
|
+
name?: string;
|
|
21
|
+
}): JustBashCommand;
|
|
22
|
+
export type { JustBashCommand, JustBashExecResult };
|
|
23
|
+
//# sourceMappingURL=just-bash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"just-bash.d.ts","sourceRoot":"","sources":["../src/just-bash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,IAAyB,MAAM,WAAW,CAAA;AAGjD,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,IAAI,CAAA;IACb,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;CACrD;AAcD,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EACd,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1B,eAAe,CAiDjB;AAED,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime adapter that exposes a goke CLI as a JustBash-compatible custom command.
|
|
3
|
+
*
|
|
4
|
+
* Structural types here are based on JustBash source definitions:
|
|
5
|
+
* - https://github.com/vercel-labs/just-bash/blob/main/src/custom-commands.ts
|
|
6
|
+
* - https://github.com/vercel-labs/just-bash/blob/main/src/types.ts
|
|
7
|
+
*/
|
|
8
|
+
import { GokeProcessExit } from './goke.js';
|
|
9
|
+
function createTextCaptureStream() {
|
|
10
|
+
const chunks = [];
|
|
11
|
+
return {
|
|
12
|
+
get text() {
|
|
13
|
+
return chunks.join('');
|
|
14
|
+
},
|
|
15
|
+
write(data) {
|
|
16
|
+
chunks.push(data);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function createJustBashCommand(cli, options) {
|
|
21
|
+
const name = options?.name ?? cli.name;
|
|
22
|
+
if (!name) {
|
|
23
|
+
throw new Error('createJustBashCommand() requires the CLI to have a name');
|
|
24
|
+
}
|
|
25
|
+
if (name.split(/\s+/).length > 1) {
|
|
26
|
+
throw new Error('JustBash custom command names must be a single token');
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
name,
|
|
30
|
+
trusted: true,
|
|
31
|
+
async execute(args) {
|
|
32
|
+
const stdout = createTextCaptureStream();
|
|
33
|
+
const stderr = createTextCaptureStream();
|
|
34
|
+
const argv = ['node', name, ...args];
|
|
35
|
+
const cloned = cli.clone({
|
|
36
|
+
stdout,
|
|
37
|
+
stderr,
|
|
38
|
+
argv,
|
|
39
|
+
exit: (code) => {
|
|
40
|
+
throw new GokeProcessExit(code);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
cloned.name = name;
|
|
44
|
+
try {
|
|
45
|
+
cloned.parse(argv, { run: false });
|
|
46
|
+
await cloned.runMatchedCommand();
|
|
47
|
+
return {
|
|
48
|
+
stdout: stdout.text,
|
|
49
|
+
stderr: stderr.text,
|
|
50
|
+
exitCode: 0,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error instanceof GokeProcessExit) {
|
|
55
|
+
return {
|
|
56
|
+
stdout: stdout.text,
|
|
57
|
+
stderr: stderr.text,
|
|
58
|
+
exitCode: error.code,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe runtime stubs for goke core.
|
|
3
|
+
*/
|
|
4
|
+
type Listener = (...args: any[]) => void;
|
|
5
|
+
declare class EventEmitter {
|
|
6
|
+
#private;
|
|
7
|
+
on(eventName: string | symbol, listener: Listener): this;
|
|
8
|
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
|
9
|
+
eventNames(): (string | symbol)[];
|
|
10
|
+
listeners(eventName: string | symbol): Listener[];
|
|
11
|
+
}
|
|
12
|
+
declare const process: {
|
|
13
|
+
argv: string[];
|
|
14
|
+
arch: string;
|
|
15
|
+
platform: string;
|
|
16
|
+
version: string;
|
|
17
|
+
stdout: {
|
|
18
|
+
columns: number;
|
|
19
|
+
isTTY: boolean;
|
|
20
|
+
write(_data: string): void;
|
|
21
|
+
};
|
|
22
|
+
stderr: {
|
|
23
|
+
columns: number;
|
|
24
|
+
isTTY: boolean;
|
|
25
|
+
write(_data: string): void;
|
|
26
|
+
};
|
|
27
|
+
exit(code: number): never;
|
|
28
|
+
};
|
|
29
|
+
declare function openInBrowser(_url: string): void;
|
|
30
|
+
export { EventEmitter, openInBrowser, process };
|
|
31
|
+
//# sourceMappingURL=runtime-browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-browser.d.ts","sourceRoot":"","sources":["../src/runtime-browser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,KAAK,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;AAExC,cAAM,YAAY;;IAGhB,EAAE,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,QAAQ;IAOjD,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;IAS/C,UAAU;IAIV,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAGrC;AAQD,QAAA,MAAM,OAAO;UACC,MAAM,EAAE;;;;;;;qBAJP,MAAM;;;;;qBAAN,MAAM;;eAUR,MAAM,GAAG,KAAK;CAK1B,CAAA;AAED,iBAAS,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEzC;AAED,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe runtime stubs for goke core.
|
|
3
|
+
*/
|
|
4
|
+
class EventEmitter {
|
|
5
|
+
#listeners = new Map();
|
|
6
|
+
on(eventName, listener) {
|
|
7
|
+
const listeners = this.#listeners.get(eventName) ?? [];
|
|
8
|
+
listeners.push(listener);
|
|
9
|
+
this.#listeners.set(eventName, listeners);
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
emit(eventName, ...args) {
|
|
13
|
+
const listeners = this.#listeners.get(eventName);
|
|
14
|
+
if (!listeners || listeners.length === 0)
|
|
15
|
+
return false;
|
|
16
|
+
for (const listener of listeners) {
|
|
17
|
+
listener(...args);
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
eventNames() {
|
|
22
|
+
return [...this.#listeners.keys()];
|
|
23
|
+
}
|
|
24
|
+
listeners(eventName) {
|
|
25
|
+
return [...(this.#listeners.get(eventName) ?? [])];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const createOutputStream = () => ({
|
|
29
|
+
columns: Number.POSITIVE_INFINITY,
|
|
30
|
+
isTTY: false,
|
|
31
|
+
write(_data) { },
|
|
32
|
+
});
|
|
33
|
+
const process = {
|
|
34
|
+
argv: [],
|
|
35
|
+
arch: 'browser',
|
|
36
|
+
platform: 'browser',
|
|
37
|
+
version: 'browser',
|
|
38
|
+
stdout: createOutputStream(),
|
|
39
|
+
stderr: createOutputStream(),
|
|
40
|
+
exit(code) {
|
|
41
|
+
throw new Error(`process.exit(${code}) is not available in the browser runtime. Pass a custom exit handler to goke(...).`);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
function openInBrowser(_url) {
|
|
45
|
+
// Browser builds should decide how to surface URLs themselves.
|
|
46
|
+
}
|
|
47
|
+
export { EventEmitter, openInBrowser, process };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js runtime bindings for goke core.
|
|
3
|
+
*/
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
declare const process: NodeJS.Process;
|
|
6
|
+
declare function openInBrowser(url: string): void;
|
|
7
|
+
export { EventEmitter, openInBrowser, process };
|
|
8
|
+
//# sourceMappingURL=runtime-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-node.d.ts","sourceRoot":"","sources":["../src/runtime-node.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC,QAAA,MAAM,OAAO,gBAAqB,CAAA;AAElC,iBAAS,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAiBxC;AAED,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js runtime bindings for goke core.
|
|
3
|
+
*/
|
|
4
|
+
import { execSync } from 'child_process';
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
const process = globalThis.process;
|
|
7
|
+
function openInBrowser(url) {
|
|
8
|
+
if (!process.stdout.isTTY) {
|
|
9
|
+
process.stderr.write(url + '\n');
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
if (process.platform === 'darwin') {
|
|
14
|
+
execSync(`open ${JSON.stringify(url)}`, { stdio: 'ignore' });
|
|
15
|
+
}
|
|
16
|
+
else if (process.platform === 'win32') {
|
|
17
|
+
execSync(`start "" ${JSON.stringify(url)}`, { stdio: 'ignore' });
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
execSync(`xdg-open ${JSON.stringify(url)}`, { stdio: 'ignore' });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
process.stderr.write(url + '\n');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export { EventEmitter, openInBrowser, process };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goke",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Simple yet powerful framework for building command-line apps. Inspired by cac.",
|
|
6
6
|
"repository": {
|
|
@@ -21,6 +21,14 @@
|
|
|
21
21
|
],
|
|
22
22
|
"main": "./dist/index.js",
|
|
23
23
|
"types": "./dist/index.d.ts",
|
|
24
|
+
"imports": {
|
|
25
|
+
"#runtime": {
|
|
26
|
+
"types": "./src/runtime-node.ts",
|
|
27
|
+
"development": "./src/runtime-node.ts",
|
|
28
|
+
"node": "./dist/runtime-node.js",
|
|
29
|
+
"default": "./dist/runtime-browser.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
24
32
|
"exports": {
|
|
25
33
|
"./package.json": "./package.json",
|
|
26
34
|
".": {
|
|
@@ -1836,6 +1836,37 @@ describe('schema description and default extraction', () => {
|
|
|
1836
1836
|
expect(stdout.text).not.toContain('--legacy')
|
|
1837
1837
|
expect(stdout.text).not.toContain('Deprecated global')
|
|
1838
1838
|
})
|
|
1839
|
+
|
|
1840
|
+
test('hidden commands are not shown in help output', () => {
|
|
1841
|
+
const stdout = createTestOutputStream()
|
|
1842
|
+
const cli = goke('mycli', { stdout })
|
|
1843
|
+
|
|
1844
|
+
cli.command('visible', 'A visible command')
|
|
1845
|
+
cli.command('secret', 'A hidden command').hidden()
|
|
1846
|
+
|
|
1847
|
+
cli.help()
|
|
1848
|
+
cli.parse(['node', 'bin', '--help'], { run: false })
|
|
1849
|
+
|
|
1850
|
+
expect(stdout.text).toContain('visible')
|
|
1851
|
+
expect(stdout.text).toContain('A visible command')
|
|
1852
|
+
expect(stdout.text).not.toContain('secret')
|
|
1853
|
+
expect(stdout.text).not.toContain('A hidden command')
|
|
1854
|
+
})
|
|
1855
|
+
|
|
1856
|
+
test('hidden command still parses and runs', () => {
|
|
1857
|
+
const cli = gokeTestable('mycli')
|
|
1858
|
+
|
|
1859
|
+
let result: any = {}
|
|
1860
|
+
cli
|
|
1861
|
+
.command('secret', 'A hidden command')
|
|
1862
|
+
.hidden()
|
|
1863
|
+
.option('--value <v>', z.string().describe('some value'))
|
|
1864
|
+
.action((options) => { result = options })
|
|
1865
|
+
|
|
1866
|
+
cli.parse(['node', 'bin', 'secret', '--value', 'hello'])
|
|
1867
|
+
|
|
1868
|
+
expect(result.value).toBe('hello')
|
|
1869
|
+
})
|
|
1839
1870
|
})
|
|
1840
1871
|
|
|
1841
1872
|
describe('helpText()', () => {
|