Skip to content

Commit 3350810

Browse files
committed
Update gulp and related libraries
1 parent c2f4151 commit 3350810

3 files changed

Lines changed: 97 additions & 97 deletions

File tree

assets/src/fonts/.gitkeep

Whitespace-only changes.

gulpfile.js

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
18+
import { createRequire } from 'module';
19+
const require = createRequire(import.meta.url);
1820

1921
// Librerie NPM richieste per l'esecuzione
20-
const gulp = require('gulp');
21-
const merge = require('merge-stream');
22+
import gulp from 'gulp';
2223
const del = require('del');
2324
const gulpIf = require('gulp-if');
2425
const babel = require('gulp-babel');
2526

2627
// Minificatori
2728
const minifyJS = require('gulp-uglify');
2829
const minifyCSS = require('gulp-clean-css');
29-
const minifyJSON = require('gulp-json-minify');
30+
import autoprefixer from 'gulp-autoprefixer';
3031

3132
// Interpretatori CSS
3233
const sass = require('gulp-sass')(require('sass'));
3334
const less = require('gulp-less');
3435
const stylus = require('gulp-stylus');
35-
const autoprefixer = require('gulp-autoprefixer');
3636

3737
// Concatenatore
3838
const concat = require('gulp-concat');
@@ -42,13 +42,13 @@ const flatten = require('gulp-flatten');
4242
const rename = require('gulp-rename');
4343

4444
// Release
45-
const glob = require('globby');
4645
const md5File = require('md5-file')
47-
const fs = require('fs');
4846
const archiver = require('archiver');
4947
const shell = require('shelljs');
50-
const inquirer = require('inquirer');
51-
const { Readable } = require('node:stream');
48+
const { Readable } = require('stream');
49+
import * as fs from 'fs';
50+
import inquirer from 'inquirer';
51+
import { globby as glob } from 'globby';
5252

5353
// Configurazione
5454
const config = {
@@ -78,6 +78,16 @@ const config = {
7878
};
7979
config.babelOptions.compact = !config.debug;
8080

81+
function waitPipes(pipes, done) {
82+
return Promise.all(
83+
pipes.map(pipe => new Promise((resolve, reject) => {
84+
pipe.on('end', resolve)
85+
}))
86+
).then(function () {
87+
done();
88+
});
89+
}
90+
8191
// Elaborazione e minificazione di JS
8292
const JS = gulp.parallel(() => {
8393
const vendor = [
@@ -139,12 +149,12 @@ const JS = gulp.parallel(() => {
139149
})
140150
.pipe(babel(config.babelOptions))
141151
.pipe(concat('app.min.js'))
142-
.pipe(gulpIf(!config.debug, minifyJS({compress:false})))
152+
.pipe(gulpIf(!config.debug, minifyJS({ compress: false })))
143153
.pipe(gulp.dest(config.production + '/' + config.paths.js));
144154
}, srcJS);
145155

146156
// Elaborazione e minificazione di JS personalizzati
147-
function srcJS() {
157+
export function srcJS(done) {
148158
const js = gulp.src([
149159
config.development + '/' + config.paths.js + '/base/*.js',
150160
])
@@ -161,7 +171,7 @@ function srcJS() {
161171
.pipe(gulpIf(!config.debug, minifyJS()))
162172
.pipe(gulp.dest(config.production + '/' + config.paths.js));
163173

164-
return merge(js, functions);
174+
return waitPipes([js, functions], done);
165175
}
166176

167177
// Elaborazione e minificazione di CSS
@@ -208,7 +218,7 @@ const CSS = gulp.parallel(() => {
208218
}, srcCSS);
209219

210220
// Elaborazione e minificazione di CSS personalizzati
211-
function srcCSS() {
221+
export function srcCSS(done) {
212222
const css = gulp.src([
213223
config.development + '/' + config.paths.css + '/*.{css,scss,less,styl}',
214224
])
@@ -230,17 +240,17 @@ function srcCSS() {
230240
.pipe(gulp.dest(config.production + '/' + config.paths.css));
231241

232242
const themes = gulp.src([
233-
config.development + '/' + config.paths.css + '/themes/*.{css,scss,less,styl}',
234-
config.nodeDirectory + '/admin-lte/dist/css/adminlte.min.css',
235-
])
236-
.pipe(gulpIf('*.scss', sass(), gulpIf('*.less', less(), gulpIf('*.styl', stylus()))))
237-
.pipe(autoprefixer())
238-
.pipe(gulpIf(!config.debug, minifyCSS(config.minifiers.css)))
239-
.pipe(concat('themes.min.css'))
240-
.pipe(flatten())
241-
.pipe(gulp.dest(config.production + '/' + config.paths.css));
242-
243-
return merge(css, print, themes);
243+
config.development + '/' + config.paths.css + '/themes/*.{css,scss,less,styl}',
244+
config.nodeDirectory + '/admin-lte/dist/css/adminlte.min.css',
245+
])
246+
.pipe(gulpIf('*.scss', sass(), gulpIf('*.less', less(), gulpIf('*.styl', stylus()))))
247+
.pipe(autoprefixer())
248+
.pipe(gulpIf(!config.debug, minifyCSS(config.minifiers.css)))
249+
.pipe(concat('themes.min.css'))
250+
.pipe(flatten())
251+
.pipe(gulp.dest(config.production + '/' + config.paths.css));
252+
253+
return waitPipes([css, print, themes], done);
244254
}
245255

246256

@@ -251,27 +261,27 @@ const images = srcImages;
251261
function srcImages() {
252262
return gulp.src([
253263
config.development + '/' + config.paths.images + '/**/*.{jpg,png,jpeg,gif}',
254-
])
264+
], {encoding: false})
255265
.pipe(gulp.dest(config.production + '/' + config.paths.images));
256266
}
257267

258-
function leaflet() {
259-
gulp.src([
268+
function leaflet(done) {
269+
const leaflet = gulp.src([
260270
config.nodeDirectory + '/leaflet.fullscreen/icon-fullscreen.svg',
261-
]).pipe(gulp.dest(config.production + '/' + config.paths.images + '/leaflet'));
262-
263-
gulp.src([
264271
config.development + '/' + config.paths.images + '/leaflet/*',
265-
]).pipe(gulp.dest(config.production + '/' + config.paths.images + '/leaflet'));
272+
], {encoding: false})
273+
.pipe(gulp.dest(config.production + '/' + config.paths.images + '/leaflet'));
266274

267-
return gulp.src([
275+
const images = gulp.src([
268276
config.nodeDirectory + '/leaflet/dist/images/*.{jpg,png,jpeg}',
269-
])
277+
], {encoding: false})
270278
.pipe(flatten())
271279
.pipe(gulp.dest(config.production + '/' + config.paths.images + '/leaflet'));
280+
281+
return waitPipes([images, leaflet], done);
272282
}
273283

274-
function wacom(){
284+
function wacom(done) {
275285
// Librerie da node_modules secondo package.json
276286
const vendor = [
277287
'clipper-lib/clipper.js',
@@ -307,7 +317,7 @@ function wacom(){
307317
// Prima copiamo il file WASM necessario
308318
const wasmStream = gulp.src([
309319
config.development + '/' + config.paths.js + '/wacom/common/libs/signature_sdk.wasm'
310-
])
320+
], {encoding: false})
311321
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/wacom/'));
312322

313323
// Poi processiamo i file JS che lo utilizzano
@@ -318,9 +328,8 @@ function wacom(){
318328
.pipe(concat('wacom.min.js'))
319329
.pipe(gulpIf(!config.debug, minifyJS()))
320330
.pipe(gulp.dest(config.production + '/' + config.paths.js));
321-
322-
// Usiamo merge per garantire che wasmStream sia completato prima di jsStream
323-
return merge(wasmStream, jsStream);
331+
332+
return waitPipes([jsStream, wasmStream], done);
324333
}
325334

326335
// Elaborazione dei fonts
@@ -343,7 +352,7 @@ const fonts = gulp.parallel(() => {
343352
vendor[i] = config.nodeDirectory + '/' + vendor[i];
344353
}
345354

346-
return gulp.src(vendor)
355+
return gulp.src(vendor, {encoding: false})
347356
.pipe(flatten())
348357
.pipe(gulp.dest(config.production + '/' + config.paths.fonts));
349358
}, srcFonts);
@@ -352,32 +361,31 @@ const fonts = gulp.parallel(() => {
352361
function srcFonts() {
353362
return gulp.src([
354363
config.development + '/' + config.paths.fonts + '/**/*.{otf,eot,svg,ttf,woff,woff2}',
355-
])
364+
], {encoding: false})
356365
.pipe(flatten())
357366
.pipe(gulp.dest(config.production + '/' + config.paths.fonts));
358367
}
359368

360-
function ckeditor() {
361-
362-
const ckeditor = gulp.src([
363-
config.nodeDirectory + '/ckeditor4/{adapters,lang,skins,plugins,core}/**/*.{js,json,css,png,gif,html}',
364-
config.nodeDirectory + '/ckeditor4/*.{js,css}',
365-
])
369+
function ckeditor(done) {
370+
const ckeditor = gulp.src([
371+
config.nodeDirectory + '/ckeditor4-full/{adapters,lang,skins,plugins,core}/**/*.{js,json,css,png,gif,html}',
372+
config.nodeDirectory + '/ckeditor4-full/*.{js,css}',
373+
], {encoding: false})
366374
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/ckeditor'));
367375

368376
const plugins = gulp.src([
369-
config.nodeDirectory + '/ckeditor/plugins/{emoji,autocomplete,textmatch,textwatcher}/**/*.{js,json,css,png,gif,html}',
370-
config.nodeDirectory + '/ckeditor-image-to-base/*.{js,json,css,png,gif,html}',
371-
])
377+
config.nodeDirectory + '/ckeditor4/plugins/{emoji,autocomplete,textmatch,textwatcher}/**/*.{js,json,css,png,gif,html}',
378+
//config.nodeDirectory + '/ckeditor-image-to-base/*.{js,json,css,png,gif,html}',
379+
], {encoding: false})
372380
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/ckeditor/plugins'));
373381

374-
return merge(ckeditor, plugins);
382+
return waitPipes([ckeditor, plugins], done);
375383
}
376384

377385
function colorpicker() {
378386
return gulp.src([
379387
config.nodeDirectory + '/bootstrap-colorpicker/dist/**/*.{jpg,png,jpeg}',
380-
])
388+
], {encoding: false})
381389
.pipe(flatten())
382390
.pipe(gulp.dest(config.production + '/' + config.paths.images + '/bootstrap-colorpicker'));
383391
}
@@ -415,44 +423,43 @@ function csrf() {
415423
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/csrf'));
416424
}
417425

418-
function pdfjs() {
426+
function pdfjs(done) {
419427
const web = gulp.src([
420-
config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-4.0.379-dist/web/**/*',
421-
'!' + config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-4.0.379-dist/web/cmaps/*',
422-
'!' + config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-4.0.379-dist/web/*.map',
423-
'!' + config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-4.0.379-dist/web/*.pdf',
424-
])
428+
config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-*-dist/web/**/*',
429+
'!' + config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-*-dist/web/cmaps/*',
430+
'!' + config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-*-dist/web/*.map',
431+
'!' + config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-*-dist/web/*.pdf',
432+
], {encoding: false})
425433
.pipe(gulp.dest(config.production + '/pdfjs/web'));
426434

427435
const build = gulp.src([
428-
config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-4.0.379-dist/build/*',
429-
'!' + config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-4.0.379-dist/build/*.map',
430-
])
436+
config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-*-dist/build/*',
437+
'!' + config.nodeDirectory + '/pdfjs-viewer-element/dist/pdfjs-*-dist/build/*.map',
438+
], {encoding: false})
431439
.pipe(gulp.dest(config.production + '/pdfjs/build'));
432440

433-
return merge(web, build);
441+
return waitPipes([web, build], done);
434442
}
435443

436444
function uaparser() {
437445
return gulp.src([
438446
config.nodeDirectory + '/ua-parser-js/dist/icons/mono/**/*',
439447
'!' + config.nodeDirectory + '/ua-parser-js/dist/icons/mono/LICENSE.md',
440-
])
441-
.pipe(gulp.dest(config.production + '/img/icons/'));
448+
], {encoding: false})
449+
.pipe(gulp.dest(config.production + '/' + config.paths.images + '/icons/'));
442450
}
443451

444452
// Elaborazione e minificazione delle informazioni sull'internazionalizzazione
445453
function i18n() {
446454
return gulp.src([
447455
config.nodeDirectory + '/**/{i18n,lang,locale,locales}/*.{js,json}',
448-
config.development + '/' + config.paths.js + '/i18n/**/*.{js,json}',
456+
//config.development + '/' + config.paths.js + '/i18n/**/*.{js,json}',
449457
config.nodeDirectory + '/moment/min/locales.js',
450458
'!' + config.nodeDirectory + '/**/{src,plugins}/**',
451-
'!' + config.nodeDirectory + '/ckeditor4/**',
452-
'!' + config.nodeDirectory + '/summernote/**',
459+
'!' + config.nodeDirectory + '/ckeditor4-full/**',
460+
//'!' + config.nodeDirectory + '/summernote/**',
453461
'!' + config.nodeDirectory + '/jquery-ui/**',
454462
])
455-
//.pipe(gulpIf('*.js', minifyJS(), gulpIf('*.json', minifyJSON())))
456463
.pipe(gulpIf('!*.min.*', rename({
457464
suffix: '.min'
458465
})))
@@ -464,9 +471,9 @@ function i18n() {
464471

465472

466473
// Operazioni per la release
467-
function release(done) {
474+
export function release(done) {
468475
// Impostazione dello zip
469-
let output = fs.createWriteStream('./release.zip', {flags: 'w'});
476+
let output = fs.createWriteStream('./release.zip', { flags: 'w' });
470477
let archive = archiver('zip');
471478

472479
output.on('close', function () {
@@ -538,14 +545,14 @@ function release(done) {
538545
archive.file('logs/.htaccess', {});
539546

540547
// Aggiunta del file dei checksum
541-
let checksumFile = fs.createWriteStream('./checksum.json', {flags: 'w'});
548+
let checksumFile = fs.createWriteStream('./checksum.json', { flags: 'w' });
542549
checksumFile.write(JSON.stringify(checksum));
543550
checksumFile.close();
544551
archive.file('checksum.json', {});
545552

546553
// Aggiunta del file per il controllo di integrità del database
547554
var bufferStream = new Readable();
548-
555+
549556
bufferStream.push(shell.exec('php update/structure.php', {
550557
silent: true
551558
}).stdout);
@@ -606,25 +613,18 @@ function release(done) {
606613
}).catch(err => {
607614
console.error('Si è verificato un errore:', err);
608615
});
609-
610616
});
611617
}
612618

613619
// Pulizia
614-
function clean() {
620+
export function clean() {
615621
return del([config.production]);
616-
}
622+
};
617623

618624
// Operazioni di default per la generazione degli assets
619-
const bower = gulp.series(clean, gulp.parallel(JS, CSS, images, fonts, ckeditor, colorpicker, i18n, pdfjs, uaparser, hotkeys, chartjs, password_strength, csrf, leaflet, wacom));
620-
621-
// Debug su CSS e JS
622-
exports.srcJS = srcJS;
623-
exports.srcCSS = srcCSS;
625+
export const bower = gulp.series(clean, gulp.parallel(JS, CSS, images, fonts, ckeditor, colorpicker, i18n, pdfjs, hotkeys, chartjs, password_strength, csrf, leaflet, wacom, uaparser));
624626

625-
exports.bower = bower;
626-
exports.release = release;
627-
exports.default = bower;
627+
export default bower;
628628

629629
// Watch task - lanciato con `gulp watch`, resta in attesa e ogni volta che viene modificato un asset in src
630630
// viene aggiornata la dist

0 commit comments

Comments
 (0)