forked from devcode-it/openstamanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·389 lines (337 loc) · 11.1 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
// Librerie NPM richieste per l'esecuzione
var gulp = require('gulp');
var merge = require('merge-stream');
var del = require('del');
var debug = require('gulp-debug');
var shell = require('shelljs');
var mainBowerFiles = require('main-bower-files');
var gulpIf = require('gulp-if');
// Minificatori
var minifyJS = require('gulp-uglify');
var minifyCSS = require('gulp-clean-css');
var minifyJSON = require('gulp-json-minify');
// Interpretatori CSS
var sass = require('gulp-sass');
var less = require('gulp-less');
var stylus = require('gulp-stylus');
var autoprefixer = require('gulp-autoprefixer');
// Concatenatore
var concat = require('gulp-concat');
// Altro
var flatten = require('gulp-flatten');
var rename = require('gulp-rename');
var inquirer = require('inquirer');
// Configurazione
var config = {
production: 'assets/dist', // Cartella di destinazione
development: 'assets/src', // Cartella dei file di personalizzazione
debug: false,
main: {
bowerDirectory: './node_modules',
bowerJson: './package.json',
},
paths: {
js: 'js',
css: 'css',
images: 'img',
fonts: 'fonts'
}
};
// Elaborazione e minificazione di JS
const JS = gulp.parallel(() => {
return gulp.src(mainBowerFiles('**/*.js', {
paths: config.main,
debugging: config.debug,
}))
.pipe(concat('app.min.js'))
.pipe(minifyJS())
.pipe(gulp.dest(config.production + '/' + config.paths.js));
}, srcJS);
// Elaborazione e minificazione di JS personalizzati
function srcJS() {
var js = gulp.src([
config.development + '/' + config.paths.js + '/*.js',
])
.pipe(concat('custom.min.js'))
.pipe(minifyJS())
.pipe(gulp.dest(config.production + '/' + config.paths.js));
var indip = gulp.src([
config.development + '/' + config.paths.js + '/functions/*.js',
])
.pipe(concat('functions.min.js'))
//.pipe(minifyJS())
.pipe(gulp.dest(config.production + '/' + config.paths.js));
return merge(js, indip);
}
// Elaborazione e minificazione di CSS
const CSS = gulp.parallel(() => {
return gulp.src(mainBowerFiles('**/*.{css,scss,less,styl}', {
paths: config.main,
debugging: config.debug,
}))
.pipe(gulpIf('*.scss', sass(), gulpIf('*.less', less(), gulpIf('*.styl', stylus()))))
.pipe(autoprefixer())
.pipe(minifyCSS({
rebase: false,
}))
.pipe(concat('app.min.css'))
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.css));
}, srcCSS);
// Elaborazione e minificazione di CSS personalizzati
function srcCSS() {
var css = gulp.src([
config.development + '/' + config.paths.css + '/*.{css,scss,less,styl}',
])
.pipe(gulpIf('*.scss', sass(), gulpIf('*.less', less(), gulpIf('*.styl', stylus()))))
.pipe(autoprefixer())
.pipe(minifyCSS({
rebase: false,
}))
.pipe(concat('style.min.css'))
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.css));
var print = gulp.src([
config.development + '/' + config.paths.css + '/print/*.{css,scss,less,styl}',
config.bowerDirectory + '/fullcalendar/fullcalendar.print.css',
], {
allowEmpty: true
})
.pipe(gulpIf('*.scss', sass(), gulpIf('*.less', less(), gulpIf('*.styl', stylus()))))
.pipe(autoprefixer())
.pipe(minifyCSS({
rebase: false,
}))
.pipe(concat('print.min.css'))
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.css));
var themes = gulp.src([
config.development + '/' + config.paths.css + '/themes/*.{css,scss,less,styl}',
])
.pipe(gulpIf('*.scss', sass(), gulpIf('*.less', less(), gulpIf('*.styl', stylus()))))
.pipe(autoprefixer())
.pipe(minifyCSS({
rebase: false,
}))
.pipe(concat('themes.min.css'))
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.css));
return merge(css, print, themes);
}
// Elaborazione delle immagini
const images = srcImages;
/*
gulp.parallel(() => {*/
//var src = mainBowerFiles('**/*.{jpg,png,jpeg,gif}', {
/*
paths: config.main,
debugging: config.debug,
});
return gulp.src(src, {
allowEmpty: true
})
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.images));
}, srcImages);
*/
// Elaborazione delle immagini personalizzate
function srcImages() {
return gulp.src([
config.development + '/' + config.paths.images + '/**/*.{jpg,png,jpeg,gif}',
])
.pipe(gulp.dest(config.production + '/' + config.paths.images));
}
// Elaborazione dei fonts
const fonts = gulp.parallel(() => {
return gulp.src(mainBowerFiles('**/*.{otf,eot,svg,ttf,woff,woff2}', {
paths: config.main,
debugging: config.debug,
}))
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.fonts));
}, srcFonts);
// Elaborazione dei fonts personalizzati
function srcFonts() {
return gulp.src([
config.development + '/' + config.paths.fonts + '/**/*.{otf,eot,svg,ttf,woff,woff2}',
])
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.fonts));
}
function ckeditor() {
return gulp.src([
config.main.bowerDirectory + '/ckeditor/{adapters,lang,skins,plugins}/**/*.{js,json,css,png}',
config.main.bowerDirectory + '/ckeditor/*.{js,css}',
])
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/ckeditor'));
}
function colorpicker() {
return gulp.src([
config.main.bowerDirectory + '/bootstrap-colorpicker/dist/**/*.{jpg,png,jpeg}',
])
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.images + '/bootstrap-colorpicker'));
}
function password_strength(){
return gulp.src([
config.main.bowerDirectory + '/pwstrength-bootstrap/dist/*.js',
])
.pipe(concat('password.min.js'))
.pipe(minifyJS())
.pipe(gulp.dest(config.production + '/password-strength'));
}
function hotkeys() {
return gulp.src([
config.main.bowerDirectory + '/hotkeys-js/dist/hotkeys.min.js',
])
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/hotkeys-js'));
}
function chartjs() {
return gulp.src([
config.main.bowerDirectory + '/chart.js/dist/Chart.min.js',
])
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/chartjs'));
}
function csrf() {
return gulp.src([
'./vendor/owasp/csrf-protector-php/js/csrfprotector.js',
])
.pipe(flatten())
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/csrf'));
}
function pdfjs() {
var web = gulp.src([
config.main.bowerDirectory + '/pdf/web/**/*',
'!' + config.main.bowerDirectory + '/pdf/web/cmaps/*',
'!' + config.main.bowerDirectory + '/pdf/web/*.map',
'!' + config.main.bowerDirectory + '/pdf/web/*.pdf',
])
.pipe(gulp.dest(config.production + '/pdfjs/web'));
var build = gulp.src([
config.main.bowerDirectory + '/pdf/build/*',
'!' + config.main.bowerDirectory + '/pdf/build/*.map',
])
.pipe(gulp.dest(config.production + '/pdfjs/build'));
return merge(web, build);
}
// Elaborazione e minificazione delle informazioni sull'internazionalizzazione
function i18n() {
return gulp.src([
config.main.bowerDirectory + '/**/{i18n,lang,locale,locales}/*.{js,json}',
config.development + '/' + config.paths.js + '/i18n/**/*.{js,json}',
'!' + config.main.bowerDirectory + '/**/{src,plugins}/**',
'!' + config.main.bowerDirectory + '/ckeditor/**',
'!' + config.main.bowerDirectory + '/summernote/**',
'!' + config.main.bowerDirectory + '/jquery-ui/**',
])
//.pipe(gulpIf('*.js', minifyJS(), gulpIf('*.json', minifyJSON())))
.pipe(gulpIf('!*.min.*', rename({
suffix: '.min'
})))
.pipe(flatten({
includeParents: 1
}))
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/i18n'));
}
// PHP DebugBar assets
function phpDebugBar() {
return gulp.src([
'./vendor/maximebf/debugbar/src/DebugBar/Resources/**/*',
'!./vendor/maximebf/debugbar/src/DebugBar/Resources/vendor/**/*',
])
.pipe(gulpIf('*.css', minifyCSS(), gulpIf('*.js', minifyJS())))
.pipe(gulp.dest(config.production + '/php-debugbar'));
}
// Operazioni per la release
function release(done) {
var archiver = require('archiver');
var fs = require('fs');
// Rimozione file indesiderati
del([
'./vendor/tecnickcom/tcpdf/fonts/*',
'!./vendor/tecnickcom/tcpdf/fonts/*helvetica*',
'./vendor/mpdf/mpdf/tmp/*',
'./vendor/mpdf/mpdf/ttfonts/*',
'!./vendor/mpdf/mpdf/ttfonts/DejaVuinfo.txt',
'!./vendor/mpdf/mpdf/ttfonts/DejaVu*Condensed*',
'./vendor/maximebf/debugbar/src/DebugBar/Resources/vendor/*',
'./vendor/respect/validation/tests/*',
]);
// Impostazione dello zip
var output = fs.createWriteStream('./release.zip');
var archive = archiver('zip');
output.on('close', function () {
console.log('ZIP completato!');
});
archive.on('error', function (err) {
throw err;
});
archive.pipe(output);
// Aggiunta dei file
archive.glob('**/*', {
dot: true,
ignore: [
'.git/**',
'node_modules/**',
'backup/**',
'files/**',
'logs/**',
'config.inc.php',
'**/*.lock',
'**/*.phar',
'**/*.log',
'**/*.zip',
'**/*.bak',
'**/*.jar',
'**/*.txt',
'**/~*',
]
});
// Eccezioni
archive.file('backup/.htaccess');
archive.file('files/.htaccess');
archive.file('files/my_impianti/componente.ini');
archive.file('logs/.htaccess');
// Aggiunta del commit corrente nel file REVISION
archive.append(shell.exec('git rev-parse --short HEAD', {
silent: true
}).stdout, {
name: 'REVISION'
});
// Opzioni sulla release
inquirer.prompt([{
type: 'input',
name: 'version',
message: 'Numero di versione:',
}, {
type: 'confirm',
name: 'beta',
message: 'Versione beta?',
default: false,
}]).then(function (result) {
version = result.version;
if (result.beta) {
version += 'beta';
}
archive.append(version, {
name: 'VERSION'
});
// Completamento dello zip
archive.finalize();
done();
});
}
// Pulizia
function clean() {
return del([config.production]);
}
// Operazioni di default per la generazione degli assets
const bower = gulp.series(clean, gulp.parallel(JS, CSS, images, fonts, phpDebugBar, ckeditor, colorpicker, i18n, pdfjs, hotkeys, chartjs, password_strength, csrf));
// Debug su CSS e JS
exports.srcJS = srcJS;
exports.srcCSS = srcCSS;
exports.bower = bower;
exports.release = release;
exports.default = bower;