-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
75 lines (61 loc) · 2.43 KB
/
index.js
File metadata and controls
75 lines (61 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
export default class SelectiveFunctionDeploy {
constructor(serverless, options, { log }) {
this.serverless = serverless;
this.options = options;
this.log = log;
this.logPrefix = '[serverless-selective-function-deploy]:';
this.setupFunctionProperties();
this.setupHooks();
}
setupHooks() {
this.hooks = {
'after:package:cleanup': () => this.excludeNonDeployableFunctions(),
};
}
setupFunctionProperties() {
this.serverless.configSchemaHandler.defineFunctionProperties('aws', {
properties: {
toDeploy: { type: 'boolean' },
},
required: [],
});
}
excludeNonDeployableFunctions() {
const allFunctions = this.getAllFunctions();
if (allFunctions.length === 0) {
return;
}
const excludedFunctions = [];
const toDeployFunctions = [];
for (const functionName of allFunctions) {
const func = this.getFunction(functionName);
const { toDeploy = true } = func;
if (typeof toDeploy !== 'boolean') {
throw new this.serverless.classes.Error('toDeploy property must be a boolean');
}
if (!toDeploy) {
this.excludeFunctionFromDeployment(functionName);
excludedFunctions.push(functionName);
} else {
toDeployFunctions.push(functionName);
}
}
if (excludedFunctions.length > 0 || toDeployFunctions.length > 0) {
this.log.verbose(`${this.logPrefix} Pre-deployment function summary:`);
this.log.verbose(`${this.logPrefix} Excluded ${excludedFunctions.length} function(s): ${excludedFunctions.join(', ')}`);
this.log.verbose(`${this.logPrefix} Included ${toDeployFunctions.length} function(s): ${toDeployFunctions.join(', ')}`);
}
const summaryLog = `${this.logPrefix} Excluded ${excludedFunctions.length} function(s) from deployment, deploying ${toDeployFunctions.length} of ${allFunctions.length} function(s).`;
const verbosePrompt = !this.options.verbose ? ' For more details, use --verbose command.' : '';
this.log.notice(summaryLog + verbosePrompt);
}
excludeFunctionFromDeployment(functionName) {
delete this.serverless.service.functions[functionName];
}
getAllFunctions() {
return this.serverless.service.getAllFunctions();
}
getFunction(functionName) {
return this.serverless.service.getFunction(functionName);
}
}