forked from dougmoscrop/serverless-plugin-split-stacks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit-stacks.js
More file actions
76 lines (63 loc) · 2.25 KB
/
split-stacks.js
File metadata and controls
76 lines (63 loc) · 2.25 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
76
'use strict';
const _ = require('lodash');
const semver = require('semver');
const migrateResources = require('./lib/migrate-resources');
const replaceReferences = require('./lib/replace-references');
const replaceOutputs = require('./lib/replace-outputs');
const mergeStackResources = require('./lib/merge-stack-resources');
const writeNestedStacks = require('./lib/write-nested-stacks');
const logSummary = require('./lib/log-summary');
const utils = require('./lib/utils');
module.exports = class StackSplitter {
constructor(serverless, options) {
if (!semver.satisfies(serverless.version, '>= 1.13')) {
throw new Error('serverless-plugin-split-stacks requires serverless 1.13 or higher!');
}
this.serverless = serverless;
this.options = options;
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'after:aws:package:finalize:mergeCustomProviderResources': this.split.bind(this),
'aws:deploy:deploy:uploadArtifacts': this.upload.bind(this)
};
Object.assign(this,
utils,
{ migrateResources },
{ replaceReferences },
{ replaceOutputs },
{ mergeStackResources },
{ writeNestedStacks },
{ logSummary }
);
}
split() {
this.rootTemplate = this.serverless.service.provider.compiledCloudFormationTemplate;
this.resourcesById = Object.assign({}, this.rootTemplate.Resources);
this.resourceMigrations = {};
return Promise.resolve()
.then(() => this.migrateResources())
.then(() => this.replaceReferences())
.then(() => this.replaceOutputs())
.then(() => this.mergeStackResources())
.then(() => this.writeNestedStacks())
.then(() => this.logSummary());
}
upload() {
return this.getBucketName()
.then(bucket => {
const files = this.getNestedStackFiles();
return _.map(files, file => {
const params = {
Bucket: bucket,
Key: `${this.serverless.service.package.artifactDirectoryName}/${file.name}`,
Body: file.createReadStream(),
ContentType: 'application/json',
};
return this.provider.request('S3', 'putObject',
params,
this.options.stage,
this.options.region);
});
});
}
};