2017-08-04 16:28:16 +02:00
|
|
|
// Librerie NPM richieste per l'esecuzione
|
|
|
|
var gulp = require('gulp');
|
|
|
|
var del = require('del');
|
|
|
|
var debug = require('gulp-debug');
|
|
|
|
var util = require('gulp-util');
|
|
|
|
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');
|
2017-12-30 12:05:09 +01:00
|
|
|
var inquirer = require('inquirer');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
gulp.task('JS', function () {
|
|
|
|
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));
|
|
|
|
|
|
|
|
gulp.start('srcJS');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Elaborazione e minificazione di JS personalizzati
|
|
|
|
gulp.task('srcJS', function () {
|
|
|
|
gulp.src([
|
|
|
|
config.development + '/' + config.paths.js + '/*.js',
|
|
|
|
])
|
|
|
|
.pipe(concat('custom.min.js'))
|
|
|
|
.pipe(minifyJS())
|
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.js));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Elaborazione e minificazione di CSS
|
|
|
|
gulp.task('CSS', function () {
|
|
|
|
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({
|
|
|
|
browsers: 'last 2 version',
|
|
|
|
}))
|
|
|
|
.pipe(minifyCSS({
|
|
|
|
rebase: false,
|
|
|
|
}))
|
|
|
|
.pipe(concat('app.min.css'))
|
|
|
|
.pipe(flatten())
|
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.css));
|
|
|
|
|
|
|
|
gulp.start('srcCSS');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Elaborazione e minificazione di CSS personalizzati
|
|
|
|
gulp.task('srcCSS', function () {
|
|
|
|
gulp.src([
|
|
|
|
config.development + '/' + config.paths.css + '/*.{css,scss,less,styl}',
|
|
|
|
])
|
|
|
|
.pipe(gulpIf('*.scss', sass(), gulpIf('*.less', less(), gulpIf('*.styl', stylus()))))
|
|
|
|
.pipe(autoprefixer({
|
|
|
|
browsers: 'last 2 version',
|
|
|
|
}))
|
|
|
|
.pipe(minifyCSS({
|
|
|
|
rebase: false,
|
|
|
|
}))
|
|
|
|
.pipe(concat('style.min.css'))
|
|
|
|
.pipe(flatten())
|
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.css));
|
|
|
|
|
|
|
|
gulp.src([
|
|
|
|
config.development + '/' + config.paths.css + '/print/*.{css,scss,less,styl}',
|
|
|
|
config.bowerDirectory + '/fullcalendar/fullcalendar.print.css',
|
|
|
|
])
|
|
|
|
.pipe(gulpIf('*.scss', sass(), gulpIf('*.less', less(), gulpIf('*.styl', stylus()))))
|
|
|
|
.pipe(autoprefixer({
|
|
|
|
browsers: 'last 2 version',
|
|
|
|
}))
|
|
|
|
.pipe(minifyCSS({
|
|
|
|
rebase: false,
|
|
|
|
}))
|
|
|
|
.pipe(concat('print.min.css'))
|
|
|
|
.pipe(flatten())
|
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.css));
|
|
|
|
|
|
|
|
gulp.src([
|
|
|
|
config.development + '/' + config.paths.css + '/themes/*.{css,scss,less,styl}',
|
2018-06-26 17:31:58 +02:00
|
|
|
config.main.bowerDirectory + '/admin-lte/dist/css/skins/_all-skins.css',
|
2017-08-04 16:28:16 +02:00
|
|
|
])
|
|
|
|
.pipe(gulpIf('*.scss', sass(), gulpIf('*.less', less(), gulpIf('*.styl', stylus()))))
|
|
|
|
.pipe(autoprefixer({
|
|
|
|
browsers: 'last 2 version',
|
|
|
|
}))
|
|
|
|
.pipe(minifyCSS({
|
|
|
|
rebase: false,
|
|
|
|
}))
|
|
|
|
.pipe(concat('themes.min.css'))
|
|
|
|
.pipe(flatten())
|
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.css));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Elaborazione delle immagini
|
|
|
|
gulp.task('images', function () {
|
|
|
|
gulp.src(mainBowerFiles('**/*.{jpg,png,jpeg,gif}', {
|
|
|
|
paths: config.main,
|
|
|
|
debugging: config.debug,
|
|
|
|
}))
|
|
|
|
.pipe(flatten())
|
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.images));
|
|
|
|
|
|
|
|
gulp.start('srcImages');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Elaborazione delle immagini personalizzate
|
|
|
|
gulp.task('srcImages', function () {
|
|
|
|
gulp.src([
|
|
|
|
config.development + '/' + config.paths.images + '/**/*.{jpg,png,jpeg,gif}',
|
|
|
|
])
|
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.images));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Elaborazione dei fonts
|
|
|
|
gulp.task('fonts', function () {
|
|
|
|
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));
|
|
|
|
|
|
|
|
gulp.start('srcFonts');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Elaborazione dei fonts personalizzati
|
|
|
|
gulp.task('srcFonts', function () {
|
|
|
|
gulp.src([
|
|
|
|
config.development + '/' + config.paths.fonts + '/**/*.{otf,eot,svg,ttf,woff,woff2}',
|
|
|
|
])
|
|
|
|
.pipe(flatten())
|
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.fonts));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('ckeditor', function () {
|
|
|
|
gulp.src([
|
2017-09-22 14:37:18 +02:00
|
|
|
config.main.bowerDirectory + '/ckeditor/{adapters,lang,skins,plugins}/**/*.{js,json,css,png}',
|
2017-08-04 16:28:16 +02:00
|
|
|
])
|
2017-09-22 14:37:18 +02:00
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/ckeditor'));
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
gulp.src([
|
2017-09-22 14:37:18 +02:00
|
|
|
config.main.bowerDirectory + '/ckeditor/*.{js,css}',
|
2017-08-04 16:28:16 +02:00
|
|
|
])
|
2017-09-22 14:37:18 +02:00
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/ckeditor'));
|
2017-08-04 16:28:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('colorpicker', function () {
|
|
|
|
gulp.src([
|
|
|
|
config.main.bowerDirectory + '/bootstrap-colorpicker/dist/**/*.{jpg,png,jpeg}',
|
|
|
|
])
|
|
|
|
.pipe(flatten())
|
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.images + '/bootstrap-colorpicker'));
|
|
|
|
});
|
|
|
|
|
2019-07-18 18:33:56 +02:00
|
|
|
gulp.task('password-strength', function () {
|
|
|
|
gulp.src([
|
|
|
|
config.main.bowerDirectory + '/pwstrength-bootstrap/dist/*.js',
|
|
|
|
])
|
|
|
|
.pipe(concat('password.min.js'))
|
|
|
|
.pipe(minifyJS())
|
|
|
|
.pipe(gulp.dest(config.production + '/password-strength'));
|
|
|
|
});
|
|
|
|
|
2017-09-18 15:45:47 +02:00
|
|
|
gulp.task('chartjs', function () {
|
|
|
|
gulp.src([
|
|
|
|
config.main.bowerDirectory + '/chart.js/dist/Chart.min.js',
|
|
|
|
])
|
|
|
|
.pipe(flatten())
|
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/chartjs'));
|
|
|
|
});
|
|
|
|
|
2018-07-08 18:25:36 +02:00
|
|
|
gulp.task('csrf', function () {
|
|
|
|
gulp.src([
|
|
|
|
'./vendor/owasp/csrf-protector-php/js/csrfprotector.js',
|
|
|
|
])
|
|
|
|
.pipe(flatten())
|
|
|
|
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/csrf'));
|
|
|
|
});
|
|
|
|
|
2017-12-30 14:13:11 +01:00
|
|
|
gulp.task('pdfjs', function () {
|
|
|
|
gulp.src([
|
2018-05-05 14:54:47 +02:00
|
|
|
config.main.bowerDirectory + '/pdf/web/**/*',
|
|
|
|
'!' + config.main.bowerDirectory + '/pdf/web/cmaps/*',
|
|
|
|
'!' + config.main.bowerDirectory + '/pdf/web/*.map',
|
|
|
|
'!' + config.main.bowerDirectory + '/pdf/web/*.pdf',
|
2017-12-30 14:13:11 +01:00
|
|
|
])
|
|
|
|
.pipe(gulp.dest(config.production + '/pdfjs/web'));
|
|
|
|
|
2017-12-20 14:05:14 +01:00
|
|
|
gulp.src([
|
2018-05-05 14:54:47 +02:00
|
|
|
config.main.bowerDirectory + '/pdf/build/*',
|
|
|
|
'!' + config.main.bowerDirectory + '/pdf/build/*.map',
|
2017-12-20 14:05:14 +01:00
|
|
|
])
|
2017-12-30 14:13:11 +01:00
|
|
|
.pipe(gulp.dest(config.production + '/pdfjs/build'));
|
2017-12-20 14:05:14 +01:00
|
|
|
});
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Elaborazione e minificazione delle informazioni sull'internazionalizzazione
|
|
|
|
gulp.task('i18n', function () {
|
|
|
|
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 + '/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
|
|
|
|
gulp.task('php-debugbar', function () {
|
|
|
|
gulp.src([
|
|
|
|
'./vendor/maximebf/debugbar/src/DebugBar/Resources/**/*',
|
2017-10-16 11:57:45 +02:00
|
|
|
'!./vendor/maximebf/debugbar/src/DebugBar/Resources/vendor/**/*',
|
2017-08-04 16:28:16 +02:00
|
|
|
])
|
|
|
|
.pipe(gulpIf('*.css', minifyCSS(), gulpIf('*.js', minifyJS())))
|
|
|
|
.pipe(gulp.dest(config.production + '/php-debugbar'));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Operazioni per la release
|
|
|
|
gulp.task('release', function () {
|
|
|
|
var archiver = require('archiver');
|
|
|
|
var fs = require('fs');
|
|
|
|
|
2017-12-30 12:05:09 +01:00
|
|
|
// Rimozione file indesiderati
|
2017-08-04 16:28:16 +02:00
|
|
|
del([
|
|
|
|
'./vendor/tecnickcom/tcpdf/fonts/*',
|
|
|
|
'!./vendor/tecnickcom/tcpdf/fonts/*helvetica*',
|
2018-01-02 17:01:47 +01:00
|
|
|
'./vendor/mpdf/mpdf/tmp/*',
|
2017-09-08 13:24:48 +02:00
|
|
|
'./vendor/mpdf/mpdf/ttfonts/*',
|
2018-01-13 09:54:08 +01:00
|
|
|
'!./vendor/mpdf/mpdf/ttfonts/DejaVuinfo.txt',
|
|
|
|
'!./vendor/mpdf/mpdf/ttfonts/DejaVu*Condensed*',
|
2017-10-16 11:57:45 +02:00
|
|
|
'./vendor/maximebf/debugbar/src/DebugBar/Resources/vendor/*',
|
2018-06-26 14:26:40 +02:00
|
|
|
'./vendor/respect/validation/tests/*',
|
2017-08-04 16:28:16 +02:00
|
|
|
]);
|
|
|
|
|
2017-12-30 12:05:09 +01:00
|
|
|
// Impostazione dello zip
|
2017-08-04 16:28:16 +02:00
|
|
|
var output = fs.createWriteStream('./release.zip');
|
|
|
|
var archive = archiver('zip');
|
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
output.on('close', function () {
|
2017-08-07 13:07:18 +02:00
|
|
|
console.log('ZIP completato!');
|
2017-08-04 16:28:16 +02:00
|
|
|
});
|
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
archive.on('error', function (err) {
|
2017-08-04 16:28:16 +02:00
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
|
|
|
|
archive.pipe(output);
|
|
|
|
|
2017-12-30 12:05:09 +01:00
|
|
|
// Aggiunta dei file
|
2017-08-04 16:28:16 +02:00
|
|
|
archive.glob('**/*', {
|
|
|
|
dot: true,
|
|
|
|
ignore: [
|
2017-08-04 18:46:02 +02:00
|
|
|
'.git/**',
|
2017-08-04 16:28:16 +02:00
|
|
|
'node_modules/**',
|
|
|
|
'backup/**',
|
|
|
|
'files/**',
|
2017-08-07 13:07:18 +02:00
|
|
|
'logs/**',
|
2017-08-04 16:28:16 +02:00
|
|
|
'config.inc.php',
|
2018-09-03 17:28:43 +02:00
|
|
|
'**/*.lock',
|
|
|
|
'**/*.phar',
|
2017-08-04 16:28:16 +02:00
|
|
|
'**/*.log',
|
|
|
|
'**/*.zip',
|
|
|
|
'**/*.bak',
|
2018-09-03 17:28:43 +02:00
|
|
|
'**/*.jar',
|
|
|
|
'**/*.txt',
|
2017-08-04 16:28:16 +02:00
|
|
|
'**/~*',
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2017-12-30 12:05:09 +01:00
|
|
|
// Eccezioni
|
2017-08-04 16:28:16 +02:00
|
|
|
archive.file('backup/.htaccess');
|
|
|
|
archive.file('files/.htaccess');
|
|
|
|
archive.file('files/my_impianti/componente.ini');
|
2017-08-07 13:07:18 +02:00
|
|
|
archive.file('logs/.htaccess');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-12-30 12:05:09 +01:00
|
|
|
// Aggiunta del commit corrente nel file REVISION
|
|
|
|
archive.append(shell.exec('git rev-parse --short HEAD', {
|
|
|
|
silent: true
|
|
|
|
}).stdout, {
|
|
|
|
name: 'REVISION'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Opzioni sulla release
|
2017-12-30 12:10:06 +01:00
|
|
|
inquirer.prompt([{
|
|
|
|
type: 'input',
|
|
|
|
name: 'version',
|
|
|
|
message: 'Numero di versione:',
|
|
|
|
}, {
|
2017-12-30 12:05:09 +01:00
|
|
|
type: 'confirm',
|
|
|
|
name: 'beta',
|
|
|
|
message: 'Versione beta?',
|
|
|
|
default: false,
|
2017-12-30 12:10:06 +01:00
|
|
|
}]).then(function (result) {
|
|
|
|
version = result.version;
|
|
|
|
|
2017-12-30 12:05:09 +01:00
|
|
|
if (result.beta) {
|
2017-12-30 12:10:06 +01:00
|
|
|
version += 'beta';
|
2017-12-30 12:05:09 +01:00
|
|
|
}
|
|
|
|
|
2017-12-30 12:10:06 +01:00
|
|
|
archive.append(version, {
|
|
|
|
name: 'VERSION'
|
|
|
|
});
|
|
|
|
|
2017-12-30 12:05:09 +01:00
|
|
|
// Completamento dello zip
|
|
|
|
archive.finalize();
|
2018-09-20 12:05:22 +02:00
|
|
|
});
|
2017-08-04 16:28:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Pulizia
|
|
|
|
gulp.task('clean', function () {
|
|
|
|
return del([config.production]);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Operazioni di default per la generazione degli assets
|
|
|
|
gulp.task('bower', ['clean'], function () {
|
|
|
|
gulp.start('JS');
|
|
|
|
gulp.start('CSS');
|
|
|
|
gulp.start('images');
|
|
|
|
gulp.start('fonts');
|
|
|
|
gulp.start('other');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Operazioni particolari per la generazione degli assets
|
|
|
|
gulp.task('other', ['clean'], function () {
|
|
|
|
gulp.start('ckeditor');
|
|
|
|
gulp.start('colorpicker');
|
2019-07-18 18:33:56 +02:00
|
|
|
gulp.start('password-strength');
|
2017-12-19 10:11:08 +01:00
|
|
|
gulp.start('i18n');
|
2017-12-20 14:05:14 +01:00
|
|
|
|
2017-12-30 14:13:11 +01:00
|
|
|
gulp.start('pdfjs');
|
2017-12-20 14:05:14 +01:00
|
|
|
gulp.start('chartjs');
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
gulp.start('php-debugbar');
|
2018-07-08 18:25:36 +02:00
|
|
|
gulp.start('csrf');
|
2017-08-04 16:28:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('default', ['clean', 'bower']);
|