Skip to content

Commit 331dccf

Browse files
author
Dimitar Tachev
authored
Merge pull request #5234 from NativeScript/tachev/resolve-command-hook
feat: expose a resolveCommand hook allowing cloud publishing though a simple redirect
2 parents 732f1a0 + 96d7749 commit 331dccf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/common/dispatchers.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import * as queue from "./queue";
22
import * as path from "path";
3+
import { hook } from "./helpers";
34

45
export class CommandDispatcher implements ICommandDispatcher {
56
constructor(private $logger: ILogger,
7+
// required by the hooksService
8+
protected $injector: IInjector,
69
private $cancellation: ICancellationService,
710
private $commandsService: ICommandsService,
811
private $staticConfig: Config.IStaticConfig,
@@ -24,7 +27,7 @@ export class CommandDispatcher implements ICommandDispatcher {
2427
}
2528

2629
let commandName = this.getCommandName();
27-
const commandArguments = this.$options.argv._.slice(1);
30+
let commandArguments = this.$options.argv._.slice(1);
2831
const lastArgument: string = _.last(commandArguments);
2932

3033
if (this.$options.help) {
@@ -36,6 +39,8 @@ export class CommandDispatcher implements ICommandDispatcher {
3639
commandName = "help";
3740
}
3841

42+
({ commandName, commandArguments, argv: process.argv } = await this.resolveCommand(commandName, commandArguments, process.argv));
43+
3944
await this.$cancellation.begin("cli");
4045

4146
await this.$commandsService.tryExecuteCommand(commandName, commandArguments);
@@ -45,6 +50,12 @@ export class CommandDispatcher implements ICommandDispatcher {
4550
return this.$commandsService.completeCommand();
4651
}
4752

53+
@hook("resolveCommand")
54+
private async resolveCommand(commandName: string, commandArguments: string[], argv: string[]) {
55+
// just a hook point
56+
return { commandName, commandArguments, argv };
57+
}
58+
4859
private getCommandName(): string {
4960
const remaining: string[] = this.$options.argv._;
5061
if (remaining.length > 0) {

0 commit comments

Comments
 (0)