-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
218 lines (198 loc) · 7.16 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
const browserSync = require('browser-sync').create();
const del = require('del');
const gulp = require('gulp');
const prefixer = require('gulp-autoprefixer');
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 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 config = require('./gulpfiles/app/gulpfile.json');
const isEnv = require('./gulpfiles/app/is-env');
const lint = require('./gulpfiles/app/lint');
// initialize BrowserSync
function browserSyncInit(done) {
browserSync.init(config[config.browserSyncConfig]);
done();
}
// reload browser
function browserSyncReload(done) {
browserSync.reload();
done();
}
// clean up folders
function cleanUp() {
return del([
config.publicPath + 'css/styles.*',
config.publicPath + 'font/**/*',
config.publicPath + 'img/**/*',
config.publicPath + 'js/scripts.*',
config.publicPath + 'json/**/*',
config.publicPath + 'svg/**/*'
]);
}
// generate favicons
function favicon() {
return gulp.src('./gulpfiles/img/favicon.png')
.pipe(favicons({
appName: 'File Sharing',
appShortName: 'File Sharing',
appDescription: 'Platform to upload, download and share files',
developerName: 'CodelineRed',
developerURL: 'https://codelinered.net/',
background: '#ff2525',
path: '',
url: 'https://fs.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.publicPath + 'img/favicons/'));
}
// copy font files
function font() {
return gulp.src([
'node_modules/@fortawesome/fontawesome-free/webfonts/**',
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}),
minifyImg.svgo({
plugins: [
{removeViewBox: true},
{cleanupIDs: false}
]
})
]))
.pipe(gulp.dest(config.publicPath + 'img/'));
}
// concatinate 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',
config.sourcePath + 'js/lib/**/*.js',
'node_modules/cookieconsent/src/cookieconsent.js',
'node_modules/cssuseragent/cssua.js',
'node_modules/datatables.net/js/jquery.dataTables.js',
'node_modules/datatables.net-bs5/js/dataTables.bootstrap5.js',
'node_modules/string-format-js/format.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/**/*.js'], 'js');
}
// 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/'));
}
// watch files
function watch() {
// watch fonts
gulp.watch(config.sourcePath + 'font/**', font);
// watch images
gulp.watch(config.sourcePath + 'img/**', img);
// watch favicon
gulp.watch(config.sourcePath + 'img/favicon.png', favicon);
// watch js files
gulp.watch(config.sourcePath + 'js/**', gulp.series(js, jsLint));
// 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 files and reload browser on file change
function watchAndReload() {
watch();
gulp.watch(config.publicPath + '**/*.{css,eot,ico,js,json,jpg,otf,png,svg,ttf,woff,woff2}', browserSyncReload);
gulp.watch('{templates,locale,config,src}/**/*.{php,twig}', browserSyncReload);
}
exports.browserSyncInit = browserSyncInit;
exports.browserSyncReload = browserSyncReload;
exports.cleanUp = cleanUp;
exports.favicon = favicon;
exports.font = font;
exports.img = img;
exports.js = js;
exports.jsLint = jsLint;
exports.json = json;
exports.scss = scss;
exports.scssLint = scssLint;
exports.svg = svg;
exports.watch = watch;
exports.watchAndReload = watchAndReload;
// lintAll task
gulp.task('lintAll', gulp.series(jsLint, scssLint));
// build task
gulp.task('build', gulp.series(cleanUp, favicon, font, img, js, jsLint, json, scss, scssLint, svg));
// default task if just called gulp
gulp.task('default', gulp.parallel(watchAndReload, browserSyncInit));