-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathmixin.core.js
133 lines (120 loc) · 3.75 KB
/
mixin.core.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const {
Mixin,
strategies: {
async: { callable: callableAsync },
},
} = require('hops-mixin');
const { trimSlashes } = require('pathifist');
const semver = require('semver');
const strip = require('strip-indent');
const {
engines: { node: nodeVersionRange },
} = require('./package.json');
const getAWSConfig = require('./lib/aws-config');
class LambdaMixin extends Mixin {
constructor(config, ...args) {
super(config, ...args);
this.awsConfig = getAWSConfig(this.config);
}
deployLambda(parameterOverrides) {
return require('./lib/deploy')(
{ hopsConfig: this.config, awsConfig: this.awsConfig },
this.options,
parameterOverrides,
typeof this.getLogger === 'function' ? this.getLogger() : null
);
}
destroyLambda() {
return require('./lib/destroy')(
{ hopsConfig: this.config, awsConfig: this.awsConfig },
this.options,
typeof this.getLogger === 'function' ? this.getLogger() : null
);
}
registerCommands(yargs) {
yargs.command('lambda', 'manage your lambda deployment', (yargs) =>
yargs
.usage('Usage: hops lambda <command>')
.command({
command: 'deploy',
describe: 'Deploys your hops application to AWS lambda',
handler: () => {
this.deployLambda({});
},
})
.command({
command: 'destroy',
describe:
'Delete all AWS resources created by this hops application.',
builder: {
'keep-bucket': {
type: 'boolean',
default: false,
describe: strip(`
Set this to true if you want to delete all files in
the S3 bucket but keep the bucket itself.
`),
},
'keep-files': {
type: 'boolean',
default: false,
describe: strip(`
Set this to true if you want to keep all files in the
S3 bucket.
`),
},
yes: {
type: 'boolean',
default: false,
describe: "Don't ask for confirmation.",
},
},
handler: () => {
this.destroyLambda();
},
})
.help('help')
.demandCommand()
);
}
handleArguments(argv) {
this.options = { ...this.options, ...argv };
}
diagnose({ pushWarning }) {
const { version: targetNodeVersion } = semver.coerce(
!this.config.node || this.config.node === 'current'
? process.version
: this.config.node
);
if (!semver.intersects(targetNodeVersion, nodeVersionRange)) {
pushWarning(
[
`AWS Lambda only supports the Node.js version range "${nodeVersionRange}".`,
'Please specify or use a Node.js version intersecting this range',
'in your Hops config (hops.node) to tell Babel for which version',
'it should transpile for.',
].join('\n')
);
}
if (
!this.awsConfig.domainName &&
(this.awsConfig.basePath.indexOf(this.awsConfig.stageName) !== 0 ||
trimSlashes(this.config.assetPath).indexOf(this.awsConfig.stageName) !==
0)
) {
pushWarning(
`When no custom domain is configured, the stageName (${this.awsConfig.stageName}) should be the first path segment in basePath (${this.awsConfig.basePath}) and assetPath (${this.config.assetPath}).`
);
}
if (this.awsConfig.domainName && !this.awsConfig.certificateArn) {
pushWarning(
'Setting a custom domain name also requires to specify the ACM certificate ARN.'
);
}
}
}
LambdaMixin.strategies = {
deployLambda: callableAsync,
destroyLambda: callableAsync,
};
module.exports = LambdaMixin;