-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
102 lines (85 loc) · 2.58 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const gulp = require('gulp');
const autoprefixer = require('gulp-autoprefixer');
const clean = require('gulp-clean');
const exec = require('child_process').exec;
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-terser');
const concat = require('gulp-concat');
const imagemin = require('imagemin');
const argv = require('minimist')(process.argv.slice(2));
const awspublish = require('gulp-awspublish');
const invalidate = require('gulp-cloudfront-invalidate');
const parallelize = require('concurrent-transform');
const config = {
production: {
baseUrl: 'https://docs.gateway.clearhaus.com/',
aws: {
region: process.env.AWS_REGION,
params: {
Bucket: 'clrhs-prod-nonpci-docs-gateway'
},
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
distribution: 'E78MG8DOLYAEP',
paths: ['/*']
}
}
}
function uglifyCSS() {
return gulp.src('src/css/*.css')
.pipe(autoprefixer({
cascade: false
}))
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(gulp.dest('website/static/css'))
};
function prepJS() {
return gulp.src(['src/js/typed.js', 'src/js/main.js'])
.pipe(concat('jsbundle.js'))
.pipe(uglify())
.pipe(gulp.dest('website/static/js'))
};
function prepFonts() {
return gulp.src('src/fonts/*')
.pipe(gulp.dest('website/static/fonts'))
}
function prepBinaries() {
return gulp.src('src/*.pdf', 'src/*.txt')
.pipe(gulp.dest('website/static'))
}
function appBundle() {
return gulp.src('dist/appBundle.js')
.pipe(gulp.dest('website/static/js'))
};
function imageMIN() {
return imagemin(['src/img/**/*'],
{
destination: 'website/static/img',
}
)
}
function hugoClean() {
return gulp.src('website/public', { read: false })
.pipe(clean());
};
function hugoBuild() {
const baseUrl = config[argv.env] ? config[argv.env].baseUrl : config['production'].baseUrl;
const command = 'hugo -v -b "' + baseUrl + '" --source=website';
return exec(command, function (err, stdout) {
console.log(stdout);
});
};
const hugoPrep = gulp.parallel(uglifyCSS, prepJS, prepFonts, prepBinaries, imageMIN);
const build = gulp.series(hugoPrep, hugoBuild);
function publish() {
const options = config[argv.env].aws;
const publisher = awspublish.create(options);
return gulp.src('website/public/**')
.pipe(parallelize(publisher.publish(), 10))
.pipe(publisher.sync())
.pipe(awspublish.reporter())
.pipe(invalidate(options));
};
exports.update = hugoPrep;
exports.build = build;
exports.deploy = gulp.series(build, publish);