forked from aws-samples/aws-serverless-workshops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
85 lines (74 loc) · 2.35 KB
/
gulpfile.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
const gulp = require('gulp');
const gutil = require('gulp-util');
const print = require('gulp-print');
const awspublish = require('gulp-awspublish');
const parallelize = require('concurrent-transform');
const through = require('through2');
const path = require('path');
const REGIONS = [
'ap-south-1',
'ap-northeast-1',
'ap-northeast-2',
'ap-southeast-2',
'eu-central-1',
'eu-west-1',
'eu-west-2',
'us-east-1',
'us-east-2',
'us-west-2',
];
gulp.task('renderRegions', () => {
gulp.src(['**/*.yaml', '!build/**/*.yaml'], { base: '..' })
.pipe(print())
.pipe(regionalize(REGIONS))
.pipe(gulp.dest('build/templates'));
});
gulp.task('upload', () => {
REGIONS.forEach((region) => {
const publisher = awspublish.create({
region: region,
params: {
Bucket: `wildrydes-${region}`,
},
});
gulp.src(['1_StaticWebHosting/website/**'], { base: '..' })
.pipe(parallelize(publisher.publish(), 10))
.pipe(awspublish.reporter());
gulp.src(`build/templates/${region}/**`)
.pipe(publisher.publish())
.pipe(awspublish.reporter());
});
});
gulp.task('default', () => {
gulp.src(['**/*.js', '!node_modules/**', '!**/vendor/**', '!**/website/js/vendor.js']).pipe(print());
});
function regionalize(regions) {
const regionalizer = function regionalizer(file, enc, callback) {
if (file.isNull()) {
callback(null, file);
return;
}
if (file.isStream()) {
callback(new gutil.PluginError('multiRender', 'Streaming not supported'));
return;
}
try {
regions.forEach((region) => {
const newFile = file.clone({
contents: false,
});
newFile.path = path.join(file.base, region, file.relative);
newFile.contents = regionalizeContents(file.contents, region);
this.push(newFile);
});
} catch (err) {
console.log("Error in regionalize: " + err);
callback(err, file.path);
}
callback();
};
return through.obj(regionalizer);
}
function regionalizeContents(contents, region) {
return new Buffer(contents.toString().replace('us-east-1', region));
}