forked from onlicar/serverless-package-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (41 loc) · 1.19 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, { log }) {
this.log = log;
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.beforePackage.bind(this),
'after:package:finalize': this.afterPackage.bind(this)
};
this.handleExit();
}
beforePackage() {
// Symlink common folders
return Promise.all(this.options.common.map(commonFolder => {
this.symlinked = true;
return symlink.createFolder(commonFolder, this.serverless);
}))
.then(() => {
this.log.success('Common packaging complete');
});
}
afterPackage() {
if(this.symlinked) {
this.options.common.forEach(commonFolder => {
symlink.removeFolder(commonFolder);
});
}
}
handleExit(func) {
['SIGINT', 'SIGTERM', 'SIGQUIT']
.forEach(signal => process.on(signal, () => {
this.afterPackage();
}));
}
}
module.exports = PackageCommon;