forked from flipstarter/flipstarter.cash
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
101 lines (89 loc) · 2.47 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
const gulp = require('gulp'),
sass = require('gulp-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'),
reload = browserSync.reload;
// TASKS
gulp.task('clean', function(done){
// Deletes all files from dist/
del.sync('dist/', {force: true});
done()
});
// Internationalization
gulp.task('i18n', function(){
return gulp.src('dist-lang/**/*.html')
.pipe(i18n({
langDir: 'lang', // takes translations from /lang/
createLangDirs: true,
defaultLang: 'en',
fallback: 'en',
delimiters: ['$(',')$']
}))
.pipe(gulp.dest('dist'));
});
// Nunjucks
gulp.task('nunjucks', function() {
// Gets all .html files in pages
return gulp.src('app/**/*.html')
// Renders template with nunjucks
.pipe(nunjucksRender({
path: ['app/templates/']
}))
// Outputs files in dist-lang folder
.pipe(gulp.dest('dist-lang'))
});
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 all static files
gulp.task('copy-static', function(){
// Copy feather-icons files from node_modules
gulp.src('node_modules/feather-icons/dist/*')
.pipe(gulp.dest('dist/static/'));
return gulp.src('app/static/**/*.*', {base: './app/static/'})
.pipe(gulp.dest('dist/static/'));
});
gulp.task('reload', function(done){
reload();
done();
});
// Watch for changes
gulp.task('watch', function(done){
// Watch HTML pages
gulp.watch('app/**/*.html', gulp.series('nunjucks', 'i18n', 'copy-static',
'reload'));
// Watch SCSS files
gulp.watch('scss/**/*.scss', gulp.series('sass', 'copy-static'));
// Watch translations
gulp.watch('lang/**/*.yaml', gulp.series('i18n', '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', 'sass', 'nunjucks', 'i18n',
'copy-static', 'serve', 'watch'));
// Deployment task
gulp.task('build', gulp.series('clean', 'sass', 'nunjucks', 'i18n',
'copy-static'));