Commit aaf2a8c1 authored by Guillaume Agniéray's avatar Guillaume Agniéray Committed by Johan Cwiklinski
Browse files

Start gulpfile.js rewrite

parent e894d29f
var gulp = require('gulp');
const { series, parallel } = require('gulp');
var del = require('del');
var uglify = require('gulp-uglify');
var cleanCSS = require('gulp-clean-css');
var merge = require('merge-stream');
var concat = require('gulp-concat');
var replace = require('gulp-replace');
var galette = {
'modules': './node_modules/',
'public': './galette/webroot/assets/'
};
var main_styles = [
'./galette/webroot/themes/default/galette.css',
'./node_modules/summernote/dist/summernote-lite.min.css',
];
var main_scripts = [
'./node_modules/jquery/dist/jquery.js',
'./node_modules/js-cookie/dist/js.cookie.min.js',
'./node_modules/summernote/dist/summernote-lite.min.js',
'./galette/webroot/js/common.js',
];
var main_assets = [
var gulp = require('gulp'),
del = require('del'),
uglify = require('gulp-uglify'),
cleanCSS = require('gulp-clean-css'),
merge = require('merge-stream'),
concat = require('gulp-concat'),
replace = require('gulp-replace')
;
var paths = {
galette: {
modules: './node_modules/',
public: './galette/webroot/assets/'
},
css: {
main: [
'./galette/webroot/themes/default/galette.css',
'./node_modules/summernote/dist/summernote-lite.min.css'
]
},
js: {
main: [
'./node_modules/jquery/dist/jquery.js',
'./node_modules/js-cookie/dist/js.cookie.min.js',
'./node_modules/summernote/dist/summernote-lite.min.js',
'./galette/webroot/js/common.js'
],
chartjs: [
'./node_modules/chart.js/dist/chart.min.js',
'./node_modules/chartjs-plugin-autocolors/dist/chartjs-plugin-autocolors.min.js',
'./node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.min.js'
],
sortablejs: [
'./node_modules/sortablejs/Sortable.min.js'
]
},
extras: [
{
'src': './node_modules/summernote/dist/font/*',
'dest': '/webfonts/'
src: './node_modules/summernote/dist/font/*',
dest: '/webfonts/'
}, {
'src': './node_modules/summernote/dist/lang/*.min.js',
'dest': '/js/lang/'
src: './node_modules/summernote/dist/lang/*.min.js',
dest: '/js/lang/'
}
];
const clean = function(cb) {
del([galette.public]);
cb();
]
};
function watch() {
//wilcards are mandatory for task not to run only once...
gulp.watch('./galette/webroot/themes/**/*.css', series(styles));
gulp.watch('./galette/webroot/js/*.js', series(scripts));
};
function clean() {
return del([paths.galette.public]);
}
function styles() {
var _dir = galette.public + '/css/';
var _dir = paths.galette.public + '/css/';
main = gulp.src(main_styles)
main = gulp.src(paths.css.main)
.pipe(replace('url(images/', 'url(../images/'))
.pipe(replace('url(font/', 'url(../webfonts/'))
.pipe(cleanCSS())
......@@ -57,49 +60,41 @@ function styles() {
.pipe(gulp.dest(_dir));
return merge(main);
};
}
function scripts() {
var _dir = galette.public + '/js/';
var _dir = paths.galette.public + '/js/';
main = gulp.src(main_scripts)
main = gulp.src(paths.js.main)
.pipe(concat('galette-main.bundle.min.js'))
.pipe(uglify())
.pipe(gulp.dest(_dir));
chartjs = gulp.src([
'./node_modules/chart.js/dist/chart.min.js',
'./node_modules/chartjs-plugin-autocolors/dist/chartjs-plugin-autocolors.min.js',
'./node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.min.js'
])
chartjs = gulp.src(paths.js.chartjs)
.pipe(concat('galette-chartjs.bundle.min.js'))
.pipe(gulp.dest(_dir));
sortablejs = gulp.src([
'./node_modules/sortablejs/Sortable.min.js',
])
sortablejs = gulp.src(paths.js.sortablejs)
.pipe(concat('galette-sortablejs.bundle.min.js'))
.pipe(gulp.dest(_dir));
return merge(main, chartjs, sortablejs);
};
}
function assets() {
main = main_assets.map(function (asset) {
return gulp.src(asset.src)
.pipe(gulp.dest(galette.public + asset.dest));
}
);
function extras() {
main = paths.extras.map(function (extra) {
return gulp.src(extra.src)
.pipe(gulp.dest(paths.galette.public + extra.dest));
}
);
return merge(main);
};
return merge(main);
}
exports.clean = clean;
exports.watch = watch;
exports.styles = styles;
exports.scripts = scripts;
exports.assets = assets;
exports.extras = extras;
exports.build = series(styles, scripts, assets);
exports.default = exports.build;
var build = gulp.series(clean, styles, scripts, extras);
exports.default = build;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment