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

Commit b93afb5

Browse files
committed
Make plugins directory typescript compatible
1 parent aacc505 commit b93afb5

20 files changed

+82
-74
lines changed

src/plugins/apim/apimFunctionPlugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ApimService } from '../../services/apimService';
22

33
export class AzureApimFunctionPlugin {
4-
constructor(serverless, options) {
5-
this.serverless = serverless;
6-
this.options = options;
4+
hooks: any;
5+
6+
constructor(private serverless, private options) {
77

88
this.hooks = {
99
'after:deploy:function:deploy': this.deploy.bind(this)

src/plugins/apim/apimServicePlugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ApimService } from '../../services/apimService';
22

33
export class AzureApimServicePlugin {
4-
constructor(serverless, options) {
5-
this.serverless = serverless;
6-
this.options = options;
4+
hooks: any;
5+
6+
constructor(private serverless, private options) {
77

88
this.hooks = {
99
'after:deploy:deploy': this.deploy.bind(this)

src/plugins/deploy/azureDeployFunctionPlugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { FunctionAppService } from '../../services/functionAppService';
22

33
export class AzureDeployFunctionPlugin {
4-
constructor(serverless, options) {
5-
this.serverless = serverless;
6-
this.options = options;
4+
hooks: any;
5+
6+
constructor(private serverless, private options) {
77

88
this.hooks = {
99
'deploy:function:packageFunction': this.beforeDeploy.bind(this),

src/plugins/deploy/azureDeployPlugin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { ResourceService } from '../../services/resourceService';
22
import { FunctionAppService } from '../../services/functionAppService';
33

44
export class AzureDeployPlugin {
5-
constructor(serverless, options) {
6-
this.serverless = serverless;
7-
this.options = options;
5+
hooks: any;
6+
constructor(private serverless, private options) {
87

98
this.hooks = {
109
'before:deploy:deploy': this.beforeDeploy.bind(this),

src/plugins/invoke/azureInvoke.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
'use strict';
21

3-
const BbPromise = require('bluebird');
2+
import { Promise } from 'bluebird';
43
const invokeFunction = require('./lib/invokeFunction');
54
const getAdminKey = require('../../shared/getAdminKey');
6-
const path = require('path');
5+
import { join, isAbsolute } from 'path';
76

87
class AzureInvoke {
9-
constructor (serverless, options) {
8+
9+
hooks: any;
10+
provider: any;
11+
invokeFunction: any;
12+
getAdminKey: any;
13+
14+
constructor (private serverless, private options) {
1015
this.serverless = serverless;
1116
this.options = options;
1217
this.provider = this.serverless.getProvider('azure');
@@ -18,9 +23,9 @@ class AzureInvoke {
1823
);
1924

2025
if (this.options.path) {
21-
const absolutePath = path.isAbsolute(this.options.path)
26+
const absolutePath = isAbsolute(this.options.path)
2227
? this.options.path
23-
: path.join(this.serverless.config.servicePath, this.options.path);
28+
: join(this.serverless.config.servicePath, this.options.path);
2429

2530
if (!this.serverless.utils.fileExistsSync(absolutePath)) {
2631
throw new this.serverless.classes.Error('The file you provided does not exist.');
@@ -31,11 +36,11 @@ class AzureInvoke {
3136
this.hooks = {
3237

3338
// TODO: See ./lib/invokeFunction.js:L10
34-
'before:invoke:invoke': () => BbPromise.bind(this)
39+
'before:invoke:invoke': () => Promise.bind(this)
3540
.then(this.provider.initialize(this.serverless,this.options))
3641
.then(this.getAdminKey),
3742

38-
'invoke:invoke': () => BbPromise.bind(this)
43+
'invoke:invoke': () => Promise.bind(this)
3944
.then(this.provider.initialize(this.serverless,this.options))
4045
.then(this.invokeFunction)
4146
};

src/plugins/invoke/lib/invokeFunction.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use strict';
21

32
module.exports = {
43
invokeFunction () {

src/plugins/login/loginPlugin.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import open from 'open';
22
import { interactiveLoginWithAuthResponse, loginWithServicePrincipalSecretWithAuthResponse } from '@azure/ms-rest-nodeauth';
3+
import AzureProvider from '../../provider/azureProvider';
34

45
export class AzureLoginPlugin {
5-
constructor(serverless, options) {
6-
this.serverless = serverless;
7-
this.options = options;
6+
provider: AzureProvider;
7+
hooks: any;
8+
9+
constructor(private serverless, private options) {
810
this.provider = this.serverless.getProvider('azure');
911

1012
this.hooks = {
@@ -29,10 +31,6 @@ export class AzureLoginPlugin {
2931
await open('https://microsoft.com/devicelogin');
3032
authResult = await interactiveLoginWithAuthResponse();
3133
}
32-
33-
this.provider.credentials = authResult.credentials;
34-
this.provider.subscriptionId = authResult.subscriptionId || subscriptionId;
35-
this.provider.accessToken = authResult.credentials.tokenCache._entries[0].accessToken;
3634
this.serverless.variables.azureAccessToken = authResult.credentials.tokenCache._entries[0].accessToken;
3735
this.serverless.variables.azureCredentials = authResult.credentials;
3836
this.serverless.variables.subscriptionId = authResult.subscriptionId || subscriptionId;

src/plugins/logs/azureLogs.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
'use strict';
21

3-
const BbPromise = require('bluebird');
2+
import { Promise } from 'bluebird';
3+
import AzureProvider from '../../provider/azureProvider';
44
const retrieveLogs = require('./lib/retrieveLogs');
55

66
class AzureLogs {
7-
constructor (serverless, options) {
7+
provider: AzureProvider
8+
hooks: any;
9+
retrieveLogs: any;
10+
11+
constructor (private serverless, private options) {
812
this.serverless = serverless;
913
this.options = options;
1014
this.provider = this.serverless.getProvider('azure');
@@ -15,10 +19,10 @@ class AzureLogs {
1519
);
1620

1721
this.hooks = {
18-
'before:logs:logs': () => BbPromise.bind(this)
22+
'before:logs:logs': () => Promise.bind(this)
1923
.then(this.provider.initialize(this.serverless,this.options)),
2024

21-
'logs:logs': () => BbPromise.bind(this)
25+
'logs:logs': () => Promise.bind(this)
2226
.then(this.provider.initialize(this.serverless,this.options))
2327
.then(this.retrieveLogs)
2428
};

src/plugins/logs/lib/retrieveLogs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use strict';
21

32
module.exports = {
43
retrieveLogs () {

src/plugins/package/azurePackage.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
'use strict';
21

3-
const BbPromise = require('bluebird');
2+
import { Promise } from 'bluebird';
3+
import AzureProvider from '../../provider/azureProvider';
44
const compileEvents = require('./lib/compileEvents');
55
const webpackFunctionJson = require('./lib/webpackFunctionJson');
66

77
class AzurePackage {
8-
constructor (serverless, options) {
8+
provider: AzureProvider
9+
hooks: any;
10+
compileEvents: any;
11+
webpackFunctionJson: any;
12+
13+
constructor (private serverless, private options) {
914
this.serverless = serverless;
1015
this.options = options;
1116
this.provider = this.serverless.getProvider('azure');
@@ -17,12 +22,12 @@ class AzurePackage {
1722
);
1823

1924
this.hooks = {
20-
'package:setupProviderConfiguration': () => BbPromise.bind(this)
25+
'package:setupProviderConfiguration': () => Promise.bind(this)
2126
.then(() => this.serverless.cli.log('Building Azure Events Hooks'))
2227
.then(this.provider.initialize(this.serverless, this.options))
2328
.then(this.compileEvents),
2429

25-
'before:webpack:package:packageModules': () => BbPromise.bind(this)
30+
'before:webpack:package:packageModules': () => Promise.bind(this)
2631
.then(this.provider.initialize(this.serverless, this.options))
2732
.then(this.webpackFunctionJson.bind(this))
2833
};

src/plugins/package/azurePackageFunction.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
'use strict';
21

3-
const BbPromise = require('bluebird');
2+
import { Promise } from 'bluebird';
3+
import AzureProvider from '../../provider/azureProvider';
44
const compileEventsForFunction = require('./lib/compileEventsForFunction');
55

66
class AzurePackageFunction {
7-
constructor (serverless, options) {
7+
provider: AzureProvider;
8+
hooks: any;
9+
compileEventsForFunction: any;
10+
11+
constructor (private serverless, private options) {
812
this.serverless = serverless;
913
this.options = options;
1014
this.provider = this.serverless.getProvider('azure');
@@ -15,7 +19,7 @@ class AzurePackageFunction {
1519
);
1620

1721
this.hooks = {
18-
'before:deploy:function:packageFunction': () => BbPromise.bind(this)
22+
'before:deploy:function:packageFunction': () => Promise.bind(this)
1923
.then(() => this.serverless.cli.log('Building Azure Events Hooks'))
2024
.then(this.provider.initialize(this.serverless, this.options))
2125
.then(this.compileEventsForFunction),

src/plugins/package/lib/compileEvents.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
'use strict';
21

3-
const BbPromise = require('bluebird');
2+
import { Promise } from 'bluebird';
43
const utils = require('../../../shared/utils');
54

65
module.exports = {
@@ -13,7 +12,7 @@ module.exports = {
1312
createEventsPromises.push(this.provider.createEventsBindings(functionName, metaData.entryPoint, metaData.handlerPath, metaData.params));
1413
});
1514

16-
return BbPromise.all(createEventsPromises);
15+
return Promise.all(createEventsPromises);
1716
}
1817
};
1918

src/plugins/package/lib/compileEventsForFunction.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use strict';
21

32
const utils = require('../../../shared/utils');
43

src/plugins/package/lib/webpackFunctionJson.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict';
21
const fs = require('fs');
3-
const path = require('path');
4-
const BbPromise = require('bluebird');
5-
2+
import { join } from 'path';
3+
import { Promise } from 'bluebird';
64
module.exports = {
75
webpackFunctionJson () {
86
const webpackJsonPromises = [];
@@ -13,17 +11,17 @@ module.exports = {
1311
});
1412
}
1513

16-
return BbPromise.all(webpackJsonPromises);
14+
return Promise.all(webpackJsonPromises);
1715
}
1816
};
1917

2018
function moveJsonFile(functionName) {
21-
const dirPath = path.join(this.serverless.config.servicePath, '.webpack', functionName);
19+
const dirPath = join(this.serverless.config.servicePath, '.webpack', functionName);
2220
const jsonFileName = `${functionName}-function.json`;
23-
const jsonFileSrcPath = path.join(this.serverless.config.servicePath, jsonFileName);
24-
const jsonFileDestPath = path.join(dirPath, jsonFileName);
21+
const jsonFileSrcPath = join(this.serverless.config.servicePath, jsonFileName);
22+
const jsonFileDestPath = join(dirPath, jsonFileName);
2523

26-
const fileMovedPromise = new BbPromise((resolve) => {
24+
const fileMovedPromise = new Promise((resolve) => {
2725
if (fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()) {
2826
if (fs.existsSync(jsonFileSrcPath)) {
2927
this.serverless.cli.log(`Moving ${jsonFileName} to .webpack directory.`);

src/plugins/remove/azureRemove.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
'use strict';
21

3-
const BbPromise = require('bluebird');
2+
import { Promise } from 'bluebird';
3+
import AzureProvider from '../../provider/azureProvider';
44
const deleteResourceGroup = require('./lib/deleteResourceGroup');
55

66
class AzureRemove {
7-
constructor (serverless, options) {
7+
provider: AzureProvider;
8+
hooks: any;
9+
deleteResourceGroup: any;
10+
11+
constructor (private serverless, private options) {
812
this.serverless = serverless;
913
this.options = options;
1014
this.provider = this.serverless.getProvider('azure');
@@ -15,7 +19,7 @@ class AzureRemove {
1519
);
1620

1721
this.hooks = {
18-
'remove:remove': () => BbPromise.bind(this)
22+
'remove:remove': () => Promise.bind(this)
1923
.then(this.provider.initialize(this.serverless,this.options))
2024
.then(this.deleteResourceGroup)
2125
.then(() => this.serverless.cli.log('Service successfully removed'))

src/plugins/remove/lib/deleteResourceGroup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use strict';
21

32
module.exports = {
43
deleteResourceGroup () {

src/provider/azureProvider.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const BbPromise = require('bluebird');
2-
const path = require('path');
1+
import { Promise } from 'bluebird');import { join } from 'path';
32
const fs = require('fs');
43
const request = require('request');
54
const parseBindings = require('../shared/parseBindings');
@@ -224,7 +223,7 @@ export default class AzureProvider {
224223
}
225224

226225
uploadPackageJson() {
227-
const packageJsonFilePath = path.join(this.serverless.config.servicePath, 'package.json');
226+
const packageJsonFilePath = join(this.serverless.config.servicePath, 'package.json');
228227
this.serverless.cli.log('Uploading package.json...');
229228

230229
const requestUrl = `https://${functionAppName}${config.scmDomain}${config.scmVfsPath}package.json`;
@@ -261,7 +260,7 @@ export default class AzureProvider {
261260
const functionJSON = params.functionsJson;
262261
functionJSON.entryPoint = entryPoint;
263262
functionJSON.scriptFile = filePath;
264-
fs.writeFileSync(path.join(this.serverless.config.servicePath, functionName + '-function.json'), JSON.stringify(functionJSON, null, 4));
263+
fs.writeFileSync(join(this.serverless.config.servicePath, functionName + '-function.json'), JSON.stringify(functionJSON, null, 4));
265264
resolve();
266265
});
267266
}

src/services/baseService.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import axios from 'axios';
22

33
export class BaseService {
4-
constructor(serverless, options) {
5-
this.serverless = serverless;
6-
this.options = options;
4+
constructor(private serverless, private options) {
75

86
this.baseUrl = 'https://management.azure.com';
97
this.serviceName = serverless.service.service;

src/services/functionAppService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ export class FunctionAppService extends BaseService {
102102
this.serverless.cli.log(`-> Function package uploaded successfully: ${functionName}`);
103103

104104
// Rename function json
105-
const fromPath = path.join(functionName, `${functionName}-function.json`);
106-
const toPath = path.join(functionName, 'function.json');
105+
const fromPath = join(functionName, `${functionName}-function.json`);
106+
const toPath = join(functionName, 'function.json');
107107
const command = `mv ${fromPath} ${toPath}`;
108108
await this._runKuduCommand(functionApp, command);
109109
}
@@ -122,15 +122,15 @@ export class FunctionAppService extends BaseService {
122122
};
123123
}
124124

125-
let templateFilePath = path.join(__dirname, 'armTemplates', 'azuredeploy.json');
125+
let templateFilePath = join(__dirname, 'armTemplates', 'azuredeploy.json');
126126

127127
if (gitUrl) {
128-
templateFilePath = path.join(__dirname, 'armTemplates', 'azuredeployWithGit.json');
128+
templateFilePath = join(__dirname, 'armTemplates', 'azuredeployWithGit.json');
129129
}
130130

131131
if (this.serverless.service.provider.armTemplate) {
132132
this.serverless.cli.log(`-> Deploying custom ARM template: ${this.serverless.service.provider.armTemplate.file}`);
133-
templateFilePath = path.join(this.serverless.config.servicePath, this.serverless.service.provider.armTemplate.file);
133+
templateFilePath = join(this.serverless.config.servicePath, this.serverless.service.provider.armTemplate.file);
134134
const userParameters = this.serverless.service.provider.armTemplate.parameters;
135135
const userParametersKeys = Object.keys(userParameters);
136136

src/shared/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use strict';
21

32
const constants = {
43
type: 'type',

0 commit comments

Comments
 (0)