Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 22aa4f1

Browse files
authored
feat: Add hooks type to base plugin, document plugin options for CLI help (#245)
- [x] Added `commands` to all plugins - [x] Added `resourceGroup`, `stage`, `region` and `subscriptionId` to all CLI commands that need to log into Azure - [x] Refactored `hooks` and `commands` to exist at the `BasePlugin` level - [x] Added type `ServerlessHookMap` Resolves AB#802 and AB#795
1 parent 9e3fcac commit 22aa4f1

File tree

13 files changed

+114
-16
lines changed

13 files changed

+114
-16
lines changed

src/models/serverless.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ export interface ServerlessCommand {
8888
commands?: ServerlessCommandMap;
8989
}
9090

91+
export interface ServerlessHookMap {
92+
[eventName: string]: Promise<any>;
93+
}
94+
9195
export interface ServerlessCommandMap {
9296
[command: string]: ServerlessCommand;
9397
}

src/plugins/apim/azureApimFunctionPlugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { ApimService } from "../../services/apimService";
33
import { AzureBasePlugin } from "../azureBasePlugin";
44

55
export class AzureApimFunctionPlugin extends AzureBasePlugin {
6-
public hooks: { [eventName: string]: Promise<any> };
76

87
public constructor(serverless: Serverless, options: Serverless.Options) {
98
super(serverless, options);

src/plugins/apim/azureApimServicePlugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { ApimService } from "../../services/apimService";
33
import { AzureBasePlugin } from "../azureBasePlugin";
44

55
export class AzureApimServicePlugin extends AzureBasePlugin {
6-
public hooks: { [eventName: string]: Promise<any> };
76

87
public constructor(serverless: Serverless, options: Serverless.Options) {
98
super(serverless, options);

src/plugins/azureBasePlugin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { Guard } from "../shared/guard";
22
import Serverless from "serverless";
33
import { Utils } from "../shared/utils";
4+
import { ServerlessCommandMap, ServerlessHookMap } from "../models/serverless";
45

56
export abstract class AzureBasePlugin<TOptions=Serverless.Options> {
7+
8+
public hooks: ServerlessHookMap
9+
protected commands: ServerlessCommandMap;
10+
611
public constructor(
712
protected serverless: Serverless,
813
protected options: TOptions,

src/plugins/deploy/azureDeployPlugin.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { ResourceService } from "../../services/resourceService";
66
import { AzureBasePlugin } from "../azureBasePlugin";
77

88
export class AzureDeployPlugin extends AzureBasePlugin<AzureLoginOptions> {
9-
public hooks: { [eventName: string]: Promise<any> };
109
public commands: any;
1110

1211
public constructor(serverless: Serverless, options: AzureLoginOptions) {
@@ -25,13 +24,39 @@ export class AzureDeployPlugin extends AzureBasePlugin<AzureLoginOptions> {
2524
lifecycleEvents: [
2625
"list"
2726
]
27+
},
28+
options: {
29+
resourceGroup: {
30+
usage: "Resource group for the service",
31+
shortcut: "g",
32+
},
33+
stage: {
34+
usage: "Stage of service",
35+
shortcut: "s"
36+
},
37+
region: {
38+
usage: "Region of service",
39+
shortcut: "r"
40+
},
41+
subscriptionId: {
42+
usage: "Sets the Azure subscription ID",
43+
shortcut: "i",
44+
},
2845
}
2946
},
3047
options: {
3148
resourceGroup: {
3249
usage: "Resource group for the service",
3350
shortcut: "g",
3451
},
52+
stage: {
53+
usage: "Stage of service",
54+
shortcut: "s"
55+
},
56+
region: {
57+
usage: "Region of service",
58+
shortcut: "r"
59+
},
3560
subscriptionId: {
3661
usage: "Sets the Azure subscription ID",
3762
shortcut: "i",

src/plugins/func/azureFuncPlugin.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { FuncService } from "../../services/funcService";
33
import { AzureBasePlugin } from "../azureBasePlugin";
44

55
export class AzureFuncPlugin extends AzureBasePlugin {
6-
public hooks: { [eventName: string]: Promise<any> };
7-
public commands: any;
86
private service: FuncService;
97

108
public constructor(serverless: Serverless, options: Serverless.Options) {

src/plugins/invoke/azureInvokePlugin.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
import fs from "fs";
12
import { isAbsolute, join } from "path";
23
import Serverless from "serverless";
34
import { InvokeService } from "../../services/invokeService";
4-
import fs from "fs";
5-
import { ServerlessCommandMap } from "../../models/serverless";
65
import { AzureBasePlugin } from "../azureBasePlugin";
76

87
export class AzureInvokePlugin extends AzureBasePlugin {
9-
public hooks: { [eventName: string]: Promise<any> };
10-
private commands: ServerlessCommandMap;
8+
119
private invokeService: InvokeService;
10+
1211
public constructor(serverless: Serverless, options: Serverless.Options) {
1312
super(serverless, options);
1413
const path = this.options["path"];
@@ -31,6 +30,22 @@ export class AzureInvokePlugin extends AzureBasePlugin {
3130
usage: "Invoke command",
3231
lifecycleEvents: ["invoke"],
3332
options: {
33+
resourceGroup: {
34+
usage: "Resource group for the service",
35+
shortcut: "g",
36+
},
37+
stage: {
38+
usage: "Stage of service",
39+
shortcut: "s"
40+
},
41+
region: {
42+
usage: "Region of service",
43+
shortcut: "r"
44+
},
45+
subscriptionId: {
46+
usage: "Sets the Azure subscription ID",
47+
shortcut: "i",
48+
},
3449
function: {
3550
usage: "Function to call",
3651
shortcut: "f",

src/plugins/login/azureLoginPlugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { AzureBasePlugin } from "../azureBasePlugin";
44
import { loginHooks } from "./loginHooks";
55

66
export class AzureLoginPlugin extends AzureBasePlugin<AzureLoginOptions> {
7-
public hooks: { [eventName: string]: Promise<any> };
87

98
public constructor(serverless: Serverless, options: AzureLoginOptions) {
109
super(serverless, options);

src/plugins/logs/azureLogsPlugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import AzureProvider from "../../provider/azureProvider";
33
import { AzureBasePlugin } from "../azureBasePlugin";
44

55
export class AzureLogsPlugin extends AzureBasePlugin {
6-
public hooks: { [eventName: string]: Promise<any> };
76

87
private provider: AzureProvider;
98

src/plugins/offline/azureOfflinePlugin.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { OfflineService } from "../../services/offlineService";
33
import { AzureBasePlugin } from "../azureBasePlugin";
44

55
export class AzureOfflinePlugin extends AzureBasePlugin {
6-
public hooks: { [eventName: string]: Promise<any> };
7-
public commands: any;
86
private offlineService: OfflineService;
97

108
public constructor(serverless: Serverless, options: Serverless.Options) {

0 commit comments

Comments
 (0)