forked from abdojulari/transcript-editor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
143 lines (117 loc) · 3.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
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
const {
src,
dest,
parallel,
series,
watch
} = require('gulp');
// Load plugins
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
// const autoprefixer = require('gulp-autoprefixer');
const cssnano = require('gulp-cssnano');
const concat = require('gulp-concat');
const clean = require('gulp-clean');
// const imagemin = require('gulp-imagemin');
const changed = require('gulp-changed');
// for templates
const map = require('vinyl-map');
const path = require('path');
const include = require('gulp-include');
// const browsersync = require('browser-sync').create();
// Clean assets
function clear() {
return src('./public/assets/*', {
read: false
})
.pipe(clean());
}
// JS function
function defaultjs() {
const source = ['./gulp/js/default.js']
return src(source)
// .pipe(changed(source))
.pipe(include())
.pipe(concat('default.js'), {newLine: "\n\n"})
// .pipe(uglify())
.pipe(rename({
extname: '.min.js'
}))
.pipe(dest('./public/assets/js/'))
}
function adminjs() {
const source = ['./gulp/js/admin.js']
return src(source)
// .pipe(changed(source))
.pipe(include())
.pipe(concat('admin.js'), {newLine: "\n\n"})
// .pipe(uglify())
.pipe(rename({
extname: '.min.js'
}))
.pipe(dest('./public/assets/js/'))
}
// CSS function
function css() {
const source = './gulp/scss/**/*.scss';
return src(source)
// .pipe(changed(source))
.pipe(sass())
.pipe(rename({
extname: '.min.css'
}))
.pipe(cssnano())
.pipe(dest('./public/assets/css/'))
}
function templates() {
const source = './gulp/templates/**/*.ejs';
return src(source)
.pipe(changed(source))
.pipe(map(function(contents, filename){
contents = contents.toString();
var name = 'TEMPLATES';
filename = path.basename(filename);
contents = 'window.'+name+'=window.'+name+' || {}; window.'+name+'["'+filename+'"] = \'' + contents.replace(/'/g, "\\'").replace(/(\r\n|\n|\r)/gm,"") + '\';'
return contents;
}))
.pipe(concat('templates.js'))
// .pipe(uglify())
.pipe(dest('./public/assets/js/'))
}
function cacheBust() {
var cbString = new Date().getTime()
const source = './public/*html';
return src(source)
.pipe(map(function(contents, filename) {
contents = contents.toString().replace(/v=\d+/g, function() {
return "v=" + cbString
})
return contents
}))
.pipe(dest("./public/"))
}
// Optimize images
// function img() {
// return src('./src/img/*')
// .pipe(imagemin())
// .pipe(dest('./assets/img'));
// }
// Watch files
// function watchFiles() {
// watch('./src/scss/*', css);
// watch('./src/js/*', js);
// watch('./src/img/*', img);
// }
// BrowserSync
// function browserSync() {
// browsersync.init({
// server: {
// baseDir: './'
// },
// port: 3000
// });
// }
// Tasks to define the execution of the functions simultaneously or in series
// exports.watch = parallel(watchFiles, browserSync);
exports.default = series(clear, parallel(defaultjs, adminjs, css, templates, cacheBust));