serverless-aliyun-function-compute-wnj
Version:
Provider plugin for the Serverless Framework v1.x which adds support for Aliyun Function Compute
54 lines (47 loc) • 1.88 kB
JavaScript
'use strict';
const _ = require('lodash');
const BbPromise = require('bluebird');
module.exports = {
removeFunctionsAndService() {
this.serverless.cli.log('Removing functions...');
const execRoleName = this.provider.getExecRoleName();
return BbPromise.bind(this)
.then(this.removeTableIfExists())
.then(this.removeFunctions)
.then(this.removeServiceIfExists)
.then(() => this.removeRoleAndPolicies(execRoleName));
},
removeFunctions() {
if (!this.fcFunctions.length) {
this.serverless.cli.log(`No functions to remove.`);
return BbPromise.resolve();
}
const serviceName = this.fcService.serviceName;
return BbPromise.mapSeries(this.fcFunctions, (func) => {
const funcName = func.functionName;
this.serverless.cli.log(`Removing function ${funcName} of service ${serviceName}...`);
return this.provider.deleteFunction(serviceName, funcName).then(() => {
this.serverless.cli.log(`Removed function ${funcName} of service ${serviceName}`);
});
});
},
removeServiceIfExists() {
if (!this.fcService) {
this.serverless.cli.log(`No services to remove.`);
return BbPromise.resolve();
}
const serviceName = this.fcService.serviceName;
this.serverless.cli.log(`Removing service ${serviceName}...`);
return this.provider.deleteService(serviceName).then(() => {
this.serverless.cli.log(`Removed service ${serviceName}`);
});
},
removeTableIfExists() {
const functionResources = this.serverless.service.resources.resources;
//filter out tables
const tableResources = _.filter(functionResources, (item) => this.provider.isTableType(item.type));
//this.serverless.cli.log(`tableResources: ${tableResources}`);
BbPromise.mapSeries(tableResources, (tableResource) =>
this.provider.deleteTable(tableResource));
}
};