/
package.js
71 lines (63 loc) · 2.22 KB
/
package.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const BbPromise = require('bluebird');
const path = require('path');
const ServerlessError = require('../../serverless-error');
const cliCommandsSchema = require('../../cli/commands-schema');
const zipService = require('./lib/zip-service');
const packageService = require('./lib/package-service');
class Package {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.servicePath = this.serverless.serviceDir || '';
this.packagePath =
this.options.package ||
this.serverless.service.package.path ||
path.join(this.servicePath || '.', '.serverless');
Object.assign(this, packageService, zipService);
this.commands = {
package: {
...cliCommandsSchema.get('package'),
commands: {
function: {
type: 'entrypoint',
lifecycleEvents: ['package'],
},
},
},
};
this.hooks = {
'initialize': () => {
const usesIncludeOrExclude = (packageConfig = {}) =>
packageConfig.include || packageConfig.exclude;
if (
usesIncludeOrExclude(this.serverless.service.package || {}) ||
Object.values(this.serverless.service.functions).some((func) =>
usesIncludeOrExclude(func.package)
) ||
Object.values(this.serverless.service.layers || {}).some((func) => {
if (func != null) return usesIncludeOrExclude(func.package);
return false;
})
) {
this.serverless._logDeprecation(
'PACKAGE_PATTERNS',
'Support for "package.include" and "package.exclude" will be removed in the next' +
' major release. Please use "package.patterns" instead'
);
}
},
'package:createDeploymentArtifacts': async () =>
BbPromise.bind(this).then(this.packageService),
'package:function:package': async () => {
if (this.options.function) {
return BbPromise.resolve(this.packageFunction(this.options.function));
}
return BbPromise.reject(
new ServerlessError('Function name must be set', 'PACKAGE_MISSING_FUNCTION_OPTION')
);
},
};
}
}
module.exports = Package;