-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
174 lines (143 loc) · 4.37 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Imports
let gulp = require('gulp'),
sass = require('gulp-sass')(require('sass')),
del = require('del'),
newer = require('gulp-newer'),
browserSync = require('browser-sync'),
cleanCSS = require('gulp-clean-css'),
nunjucksRender = require('gulp-nunjucks-render'),
i18n = require('gulp-html-i18n'),
data = require('gulp-data'),
Techy = require('techy-cms').gulp({root: 'blog/'}),
concat = require('gulp-concat'),
terser = require('gulp-terser'),
reload = browserSync.reload;
// TASKS
// Clean previous build
gulp.task('clean', function(done){
// Deletes all files from dist/
del.sync(['dist/', 'dist-lang/'], {force: true});
del.sync('app/static/css/style.css');
done()
});
// Nunjucks + data + i18n
gulp.task('html', function(){
// Gets all .html files in pages
return gulp.src('app/**/*.html')
// Adds data from newsroom.json
.pipe(data(function() {
return require('./app/data/newsroom.json')
}))
// Adds data from versions.json
.pipe(data(function() {
return require('./app/data/versions.json')
}))
// Renders template with nunjucks
.pipe(nunjucksRender({
path: ['app/templates/']
}))
.pipe(i18n({
langDir: 'lang', // takes translations from /lang/
createLangDirs: true,
defaultLang: 'en',
fallback: 'en',
delimiters: ['$(',')$']
}))
.pipe(gulp.dest('dist'));
});
// Compile Sass into CSS
gulp.task('sass', function(){
return gulp.src('scss/style.scss')
.pipe(sass()) // Compiles styles.scss to css
.pipe(cleanCSS({compatibility: 'ie9'})) // Minifies CSS
.pipe(gulp.dest('app/static/css'))
.pipe(reload({
stream: true
}))
});
// Copy special files to dist
gulp.task('copy-special', function(){
return gulp.src(['app/bitcoin.pdf'])
.pipe(newer('dist/')) // Only get the modified files
.pipe(gulp.dest('dist/'))
});
// Concat and minify JavaScript
gulp.task('js', function() {
const files = [
'node_modules/jquery/dist/jquery.slim.min.js',
'node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
'node_modules/aos/dist/aos.js',
'node_modules/@fancyapps/fancybox/dist/jquery.fancybox.min.js',
'js/*.js'
];
return gulp.src(files)
.pipe(concat('scripts.js'))
// Minify JS
.pipe(terser())
.pipe(gulp.dest('dist/static/js/'));
});
// Copy all static files
gulp.task('copy-static', function(done){
// Add AOS library from node_modules
gulp.src('node_modules/aos/dist/aos.js')
.pipe(gulp.dest('dist/static/js/'));
// Add Fancybox CSS
gulp.src(['app/static/css/style.css',
'node_modules/@fancyapps/fancybox/dist/jquery.fancybox.min.css'])
.pipe(concat('style.css'))
.pipe(gulp.dest('dist/static/css/'))
// Copy everything from app/static
gulp.src('app/static/**/*.*', {ignore: ['app/static/js/custom.js',
'app/static/css/*']})
.pipe(gulp.dest('dist/static/'));
done();
});
gulp.task('reload', function(done){
reload();
done();
});
// Techy CMS
gulp.task('techy', function(done){
gulp.src(['blog/**/*.md', '!blog/example.md'])
.pipe(Techy())
.pipe(gulp.dest('./app/newsroom/'));
done();
});
// Watch for changes
gulp.task('watch', function(done){
// Watch HTML pages
gulp.watch('app/**/*.html', gulp.series('copy-special', 'html',
'copy-static', 'reload'));
// Watch Nunjucks templates
gulp.watch('app/templates/', gulp.series('html', 'reload'));
// Watch SCSS files
gulp.watch('scss/**/*.scss', gulp.series('sass', 'copy-static'));
// Watch static files
gulp.watch('app/static/**/*', gulp.series('copy-static', 'reload'));
// Watch translations
gulp.watch('lang/**/*.yaml', gulp.series('html', 'reload'));
// Watch Techy CMS files
gulp.watch('blog/**/*', gulp.series('techy', 'html'));
// Watch JS files
gulp.watch('js/*.js', gulp.series('js', 'reload'));
done();
});
// Starts browserSync
gulp.task('serve', function(done){
browserSync({
server: {
baseDir: './dist',
index: "index.html",
serveStaticOptions: {
extensions: ['html']
}
}
});
done();
});
// Default task
gulp.task('default', gulp.series('clean', 'techy', 'sass', 'html',
'copy-static', 'copy-special', 'js', 'serve', 'watch'));
// Deployment task
gulp.task('build', gulp.series('clean', 'techy', 'sass', 'html',
'copy-static', 'copy-special', 'js'));