-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
50 lines (41 loc) · 1.24 KB
/
index.js
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
'use strict';
const symlink = require('./src/symlink');
class PackageCommon {
constructor(serverless, options) {
this.serverless = serverless;
this.options = Object.assign({
common: []
}, this.serverless.service.custom && this.serverless.service.custom.packageCommon || {});
this.symlinked = false;
this.hooks = {
'before:package:createDeploymentArtifacts': this.beforeDeploy.bind(this),
'after:deploy:deploy': this.afterDeploy.bind(this)
};
this.handleExit();
}
beforeDeploy() {
// Symlink common folders
return Promise.all(this.options.common.map(commonFolder => {
this.symlinked = true;
return symlink.createFolder(commonFolder, this.serverless);
}))
.then(() => {
this.serverless.cli.log(`[serverless-package-common] Package Common is complete`);
});
}
afterDeploy() {
if(this.symlinked) {
this.options.common.forEach(commonFolder => {
const target = commonFolder.replace(/..\//g, '');
symlink.removeFolder(target);
});
}
}
handleExit(func) {
['SIGINT', 'SIGTERM', 'SIGQUIT']
.forEach(signal => process.on(signal, () => {
this.afterDeploy();
}));
}
}
module.exports = PackageCommon;