-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
323 lines (293 loc) · 10.9 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
const browserSync = require('browser-sync').create();
const chalk = require('chalk');
const del = require('del');
const gulp = require('gulp');
const prefixer = require('gulp-autoprefixer');
const babel = require('gulp-babel');
const minifyCss = require('gulp-clean-css');
const concat = require('gulp-concat');
const eslint = require('gulp-eslint');
const favicons = require('gulp-favicons');
const gulpIf = require('gulp-if');
const minifyImg = require('gulp-imagemin');
const minifyJson = require('gulp-jsonminify');
const rename = require('gulp-rename');
const sass = require('gulp-sass')(require('sass'));
const sassLint = require('gulp-sass-lint');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify-es').default;
const vueSfc = require('gulp-vue-single-file-component');
const config = require('./src/app/gulpfile.json');
const isEnv = require('./src/app/is-env');
const lint = require('./src/app/lint');
// copy audio files
function audio() {
return gulp.src([
config.sourcePath + 'audio/**'
])
.pipe(gulp.dest(config.publicPath + 'audio/'));
}
// initialize BrowserSync
function browserSyncInit(done) {
browserSync.init(config[config.browserSyncConfig]);
done();
}
// reload browser
function browserSyncReload(done) {
browserSync.reload();
done();
}
// lint chatbot js files
function chatbotLint() {
return lint(gulp, eslint, [
config.sourcePath + 'js/chatbot/**/*.js',
'chatbot.js',
'import-videos-folder.js',
'./data/migration/*.js',
'migration.js'
], 'import');
}
// clean up folders
function cleanUp() {
return del([
config.publicPath + 'audio/**/*',
config.publicPath + 'css/styles.*',
config.publicPath + 'font/**/*',
config.publicPath + 'img/**/*',
config.publicPath + 'js/require/**/*',
config.publicPath + 'js/vue/**/*',
config.publicPath + 'js/scripts.*',
config.publicPath + 'json/**/*',
config.publicPath + 'svg/**/*'
]);
}
// generate favicons
function favicon() {
return gulp.src('./src/img/favicon.png')
.pipe(favicons({
appName: 'Twitch Chatbot',
appShortName: 'Twitch Chatbot',
appDescription: 'Twitch Chatbot made with Vue Skeleton',
developerName: 'CodelineRed',
developerURL: 'https://codelinered.net/',
background: '#000',
path: '/img/favicons/',
url: 'https://tcb.codelinered.net/',
display: 'standalone',
orientation: 'portrait',
scope: '/',
start_url: '/#/',
version: 1.0,
logging: false,
html: 'index.html',
pipeHTML: true,
replace: true
}))
// .pipe(gulp.dest(config.systemPath + 'img/favicons/'))
.pipe(gulp.dest(config.publicPath + 'img/favicons/'));
}
// copy font files
function font() {
return gulp.src([
// 'node_modules/@fortawesome/fontawesome-free/webfonts/**',
'node_modules/slick-carousel/slick/fonts/**',
config.sourcePath + 'font/**'
])
.pipe(gulp.dest(config.publicPath + 'font/'));
}
// compress images
function img() {
return gulp.src(config.sourcePath + 'img/**/*.{png,gif,jpg,jpeg,ico,xml,json,svg}')
.pipe(minifyImg([
minifyImg.gifsicle({interlaced: true}),
minifyImg.mozjpeg({progressive: true}),
minifyImg.optipng({optimizationLevel: 5})
]))
.pipe(gulp.dest(config.publicPath + 'img/'));
}
// concatenate and uglify js files
function js() {
return gulp.src([
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap/dist/js/bootstrap.bundle.js',
// 'node_modules/@fortawesome/fontawesome-free/js/all.js',
'node_modules/skateboard/skateboard.min.js',
'node_modules/moment/moment.js',
'node_modules/chart.js/dist/Chart.bundle.js',
config.sourcePath + 'js/lib/**/*.js',
'node_modules/cssuseragent/cssua.js',
'node_modules/datatables.net/js/jquery.dataTables.js',
'node_modules/datatables.net-bs4/js/dataTables.bootstrap4.js',
'node_modules/vanilla-lazyload/dist/lazyload.js',
config.sourcePath + 'js/plugin/**/*.js',
config.sourcePath + 'js/module/**/*.js',
config.sourcePath + 'js/scripts.js'
])
.pipe(sourcemaps.init())
.pipe(concat('scripts.js'))
.pipe(gulpIf(isEnv(['test', 'prod'], config.env), uglify()))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(config.publicPath + 'js/'));
}
// lint js files
function jsLint() {
return lint(gulp, eslint, [config.sourcePath + 'js/{lib,module,plugin}/*.js', config.sourcePath + 'js/scripts.js'], 'js');
}
// uglify required js files
function jsRequire() {
let returnValue;
const modules = {
'require': 'node_modules/requirejs/require.js',
'vue': 'node_modules/vue/dist/vue.min.js',
'vue-router': 'node_modules/vue-router/dist/vue-router.min.js',
'vue-i18n': 'node_modules/vue-i18n/dist/vue-i18n.js',
'vue-ctk-date-time-picker': 'node_modules/vue-ctk-date-time-picker/dist/vue-ctk-date-time-picker.umd.js',
'fontawesome-svg-core': 'node_modules/@fortawesome/fontawesome-svg-core/index.js',
'free-brands-svg-icons': 'node_modules/@fortawesome/free-brands-svg-icons/index.js',
'free-regular-svg-icons': 'node_modules/@fortawesome/free-regular-svg-icons/index.js',
'free-solid-svg-icons': 'node_modules/@fortawesome/free-solid-svg-icons/index.js',
'vue-fontawesome': 'node_modules/@fortawesome/vue-fontawesome/index.js'
};
if (isEnv('dev', config.env)) {
modules['vue'] = 'node_modules/vue/dist/vue.js';
modules['vue-router'] = 'node_modules/vue-router/dist/vue-router.js';
}
const moduleKeys = Object.keys(modules);
for (const key of moduleKeys) {
returnValue = gulp.src(modules[key])
.pipe(rename({ basename: key }))
.pipe(gulpIf(isEnv(['test', 'prod'], config.env), uglify()))
.pipe(gulp.dest(config.publicPath + 'js/require/'));
}
return returnValue;
}
// copy all json files and minify
function json() {
return gulp.src([
config.sourcePath + 'json/**/*.json'
])
.pipe(minifyJson())
.pipe(gulp.dest(config.publicPath + 'json/'));
}
// processing scss to css and minify result
function scss() {
return gulp.src(config.sourcePath + 'scss/styles.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(prefixer({
overrideBrowserslist: ['last 2 versions'],
cascade: false
}))
.pipe(gulpIf(isEnv(['test', 'prod'], config.env), minifyCss({compatibility: 'ie8'})))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(config.publicPath + 'css/'));
}
// lint scss files
function scssLint() {
return lint(gulp, sassLint, [config.sourcePath + 'scss/**/*.scss'], 'scss');
}
// compress and copy svg files
function svg() {
return gulp.src([
// 'node_modules/@fortawesome/fontawesome-free/svgs/**',
// 'node_modules/@fortawesome/fontawesome-free/sprites/**',
config.sourcePath + 'svg/**/*.svg'
])
.pipe(minifyImg([
minifyImg.svgo({
plugins: [
{removeViewBox: true},
{cleanupIDs: false}
]
})
]))
.pipe(gulp.dest(config.publicPath + 'svg/'));
}
// transpile vue files
function vue() {
return gulp.src(config.sourcePath + 'js/vue/**/*.vue')
.pipe(vueSfc({ debug: false, loadCssMethod: 'loadCss' }))
.pipe(babel({ plugins: ['@babel/plugin-transform-modules-amd'] }))
.pipe(rename({ extname: '.js' }))
.pipe(gulpIf(isEnv(['test', 'prod'], config.env), uglify()))
.pipe(gulp.dest(config.publicPath + 'js/vue/'));
}
// transpile vue js files
function vueJs() {
return gulp.src(config.sourcePath + 'js/vue/**/*.js')
.pipe(babel({ plugins: ['@babel/plugin-transform-modules-amd'] }))
.pipe(gulpIf(isEnv(['test', 'prod'], config.env), uglify()))
.pipe(gulp.dest(config.publicPath + 'js/vue/'));
}
// lint vue js files
function vueJsLint() {
return lint(gulp, eslint, [config.sourcePath + 'js/vue/**/*.js'], 'import');
}
// lint vue files
function vueLint() {
return lint(gulp, eslint, [config.sourcePath + 'js/vue/**/*.vue'], 'vue');
}
// watch files
function watch() {
// watch audios
gulp.watch(config.sourcePath + 'audio/**', audio);
// watch fonts
gulp.watch(config.sourcePath + 'font/**', font);
// watch images
gulp.watch(config.sourcePath + 'img/**', img);
// watch js files
gulp.watch([
config.sourcePath + 'js/{lib,module,plugin}/*.js',
config.sourcePath + 'js/scripts.js'
], gulp.series(js, jsLint));
// watch require js files
gulp.watch(config.sourcePath + 'js/module/require-config.js', jsRequire);
// watch json files
gulp.watch(config.sourcePath + 'json/**', json);
// watch scss files
gulp.watch(config.sourcePath + 'scss/**', gulp.series(scss, scssLint));
// watch svg
gulp.watch(config.sourcePath + 'svg/**', svg);
// watch vue files
gulp.watch(config.sourcePath + 'js/vue/**', gulp.series(vue, vueJs, vueJsLint, vueLint));
// watch chatbot files
gulp.watch([
config.sourcePath + 'js/chatbot/**/*.js',
'chatbot.js',
'import-videos-folder.js',
'./data/migration/*.js',
'migration.js'
], gulp.series(chatbotLint));
}
// watch files and reload browser on file change
function watchAndReload() {
watch();
gulp.watch(config.publicPath + '**/*.{css,eot,html,ico,js,json,jpg,otf,png,svg,ttf,woff,woff2}', browserSyncReload);
}
exports.audio = audio;
exports.browserSyncInit = browserSyncInit;
exports.browserSyncReload = browserSyncReload;
exports.chatbotLint = chatbotLint;
exports.cleanUp = cleanUp;
exports.favicon = favicon;
exports.font = font;
exports.img = img;
exports.js = js;
exports.jsLint = jsLint;
exports.jsRequire = jsRequire;
exports.json = json;
exports.scss = scss;
exports.scssLint = scssLint;
exports.svg = svg;
exports.vue = vue;
exports.vueJs = vueJs;
exports.vueJsLint = vueJsLint;
exports.vueLint = vueLint;
exports.watch = watch;
exports.watchAndReload = watchAndReload;
// lintAll task
gulp.task('lintAll', gulp.series(scssLint, jsLint, vueJsLint, vueLint, chatbotLint));
// build task
gulp.task('build', gulp.series(cleanUp, audio, favicon, font, img, js, jsLint, jsRequire, json, scss, scssLint, svg, vue, vueJs, vueJsLint, vueLint, chatbotLint));
// default task if you just call "gulp"
gulp.task('default', gulp.parallel(watchAndReload, browserSyncInit));