-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulp_upload_static_files.js
74 lines (64 loc) · 1.95 KB
/
gulp_upload_static_files.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
import awspublish from 'gulp-awspublish';
import gulp from 'gulp';
import rename from 'gulp-rename';
import { join } from 'path';
import { log } from 'gulp-util';
import { existsSync } from 'fs';
const bundle = process.env.STATIC_BUNDLE_URL;
const vendor = process.env.STATIC_VENDOR_URL;
const manifestPath = join(__dirname, '../../dist/static/js/manifest.json');
let manifestJSON = false;
gulp.task('upload-static-files', function publishAWS() {
const publisher = awspublish.create({
region: 'us-east-1',
params: {
Bucket: process.env.s3bucket
}
});
const headers = {
'Cache-Control': 'max-age=315360000, no-transform, public'
};
return gulp
.src('./dist/static/**/*')
.pipe(
rename(function renamePlugin(path) {
path.dirname = `/${bundle}/${path.dirname}`; // eslint-disable-line no-param-reassign
return path;
})
)
.pipe(awspublish.gzip())
.pipe(publisher.publish(headers))
.pipe(awspublish.reporter());
});
gulp.task('upload-vendor-file', function publishAWS() {
if (existsSync(manifestPath)) {
// eslint-disable-next-line global-require, import/no-dynamic-require
manifestJSON = require(manifestPath);
} else {
log(`Manifest file not found: ${manifestPath}`);
throw new Error(`Manifest file not found: ${manifestPath}`);
}
const publisher = awspublish.create({
region: 'us-east-1',
params: {
Bucket: process.env.s3bucket
}
});
const headers = {
'Cache-Control': 'max-age=315360000, no-transform, public'
};
return gulp
.src([
`./dist/static/js/${manifestJSON['vendor.js']}`,
`./dist/static/js/${manifestJSON['vendor.js.map']}`
])
.pipe(
rename(function renamePlugin(path) {
path.dirname = `/${vendor}/${path.dirname}`; // eslint-disable-line no-param-reassign
return path;
})
)
.pipe(awspublish.gzip())
.pipe(publisher.publish(headers))
.pipe(awspublish.reporter());
});