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

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) {

src/plugins/package/azurePackagePlugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export class AzurePackagePlugin extends AzureBasePlugin {
88
private bindingsCreated: boolean = false;
99
private packageService: PackageService;
1010
public provider: AzureProvider;
11-
public hooks: { [eventName: string]: Promise<any> };
1211

1312
public constructor(serverless: Serverless, options: Serverless.Options) {
1413
super(serverless, options);

src/plugins/remove/azureRemovePlugin.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,37 @@ import { ResourceService } from "../../services/resourceService";
33
import { AzureBasePlugin } from "../azureBasePlugin";
44

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

87
public constructor(serverless: Serverless, options: Serverless.Options) {
98
super(serverless, options);
9+
10+
this.commands = {
11+
remove: {
12+
usage: "Remove service resource group (USE WITH CAUTION)",
13+
lifecycleEvents: [
14+
"remove"
15+
],
16+
options: {
17+
resourceGroup: {
18+
usage: "Resource group for the service",
19+
shortcut: "g",
20+
},
21+
stage: {
22+
usage: "Stage of service",
23+
shortcut: "s"
24+
},
25+
region: {
26+
usage: "Region of service",
27+
shortcut: "r"
28+
},
29+
subscriptionId: {
30+
usage: "Sets the Azure subscription ID",
31+
shortcut: "i",
32+
},
33+
}
34+
}
35+
}
36+
1037
this.hooks = {
1138
"remove:remove": this.remove.bind(this)
1239
};

src/plugins/rollback/azureRollbackPlugin.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,41 @@ import { AzureBasePlugin } from "../azureBasePlugin";
66
* Plugin for rolling back Function App Service to previous deployment
77
*/
88
export class AzureRollbackPlugin extends AzureBasePlugin {
9-
public hooks: { [eventName: string]: Promise<any> };
109

1110
public constructor(serverless: Serverless, options: Serverless.Options) {
1211
super(serverless, options);
12+
13+
this.commands = {
14+
rollback: {
15+
usage: "Rollback command",
16+
lifecycleEvents: [
17+
"rollback"
18+
],
19+
options: {
20+
timestamp: {
21+
usage: "Timestamp of previous deployment",
22+
shortcut: "t",
23+
},
24+
resourceGroup: {
25+
usage: "Resource group for the service",
26+
shortcut: "g",
27+
},
28+
stage: {
29+
usage: "Stage of service",
30+
shortcut: "s"
31+
},
32+
region: {
33+
usage: "Region of service",
34+
shortcut: "r"
35+
},
36+
subscriptionId: {
37+
usage: "Sets the Azure subscription ID",
38+
shortcut: "i",
39+
},
40+
}
41+
}
42+
}
43+
1344
this.hooks = {
1445
"rollback:rollback": this.rollback.bind(this)
1546
};

0 commit comments

Comments
 (0)