1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-14 00:46:38 -05:00

Update gulpfile for gulp 4.0.0

This commit is contained in:
Jack Foltz 2018-07-24 19:39:34 -04:00
parent 55ee7161a0
commit af50379a59
Signed by: foltik
GPG Key ID: 303F88F996E95541

View File

@ -1,22 +1,25 @@
var gulp = require('gulp'); 'use strict';
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var evstream = require('event-stream');
var cleanCSS = require('gulp-clean-css');
var nodemon = require('gulp-nodemon');
var path = require('path');
gulp.task('start', function() { const gulp = require('gulp');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const source = require('vinyl-source-stream');
const browserify = require('browserify');
const es = require('event-stream');
const cleanCSS = require('gulp-clean-css');
const nodemon = require('gulp-nodemon');
const path = require('path');
gulp.task('start', (done) => {
nodemon({ nodemon({
script: 'server.js', script: 'server.js',
ignore: '*.*' ignore: '*.*'
}); });
}) done();
});
gulp.task('watch', function () { gulp.task('watch', (done) => {
nodemon({ nodemon({
script: 'server.js', script: 'server.js',
ext: 'js html css', ext: 'js html css',
@ -28,111 +31,101 @@ gulp.task('watch', function () {
tasks: function (changedFiles) { tasks: function (changedFiles) {
var tasks = []; var tasks = [];
changedFiles.forEach(function (file) { changedFiles.forEach(function (file) {
if (path.extname(file) === '.js' && !~tasks.indexOf('minjs')) if (path.extname(file) === '.js' && !~tasks.indexOf('MakeJS'))
tasks.push('minjs'); tasks.push('MakeJS');
if (path.extname(file) === '.css' && !~tasks.indexOf('mincss')) if (path.extname(file) === '.css' && !~tasks.indexOf('MakeCSS'))
tasks.push('mincss'); tasks.push('MakeCSS');
}); });
return tasks; return tasks;
} }
}).on('restart?', function () { }).on('restart?', function () {
gulp.start('default'); gulp.task('default')();
}); });
}); });
gulp.task('default', function () { gulp.task('MinifyCSS', () => {
gulp.start('minjs'); const files = [
gulp.start('mincss');
});
gulp.task('mincss', function () {
var files = [
{ {
src: 'app/public/css/form.css', src: 'app/public/css/form.css',
name: 'form.min.css' dest: 'form.min.css'
}, },
{ {
src: 'app/public/css/home.css', src: 'app/public/css/home.css',
name: 'home.min.css' dest: 'home.min.css'
}, },
{ {
src: 'app/public/css/panel.css', src: 'app/public/css/panel.css',
name: 'panel.min.css' dest: 'panel.min.css'
}, },
{ {
src: 'app/public/css/index.css', src: 'app/public/css/index.css',
name: 'index.min.css' dest: 'index.min.css'
} }
]; ];
var tasks = files.map(function (entry) { const tasks = files.map(file =>
return gulp.src(entry.src) gulp.src(file.src)
.pipe(cleanCSS()) .pipe(cleanCSS())
.pipe(rename(entry.name)) .pipe(rename(file.dest))
.pipe(gulp.dest('public/css')));
return es.merge(tasks)
.pipe(gulp.dest('public/css')); .pipe(gulp.dest('public/css'));
}); });
return evstream.merge.apply(null, tasks); gulp.task('MinifyJS', () => {
}) const files = [
gulp.task('minjs', function () {
gulp.start('concatjs');
gulp.start('browserify');
});
gulp.task('concatjs', function () {
var files = [
{ {
src: [ src: [
'app/public/services/*.js', 'app/public/services/*.js',
'app/public/panel/**/*.js' 'app/public/panel/**/*.js'
], ],
name: 'panel.min.js' dest: 'panel.min.js'
}, },
{ {
src: [ src: [
'app/public/services/*.js', 'app/public/services/*.js',
'app/public/shimapan/**/*.js' 'app/public/shimapan/**/*.js'
], ],
name: 'shimapan.min.js' dest: 'shimapan.min.js'
}, },
{ {
src: 'app/public/index/*.js', src: 'app/public/index/*.js',
name: 'index.min.js' dest: 'index.min.js'
} }
]; ];
var tasks = files.map(function (entry) { const tasks = files.map(file =>
return gulp.src(entry.src) gulp.src(file.src)
.pipe(concat(entry.name)) .pipe(concat(file.dest))
.pipe(uglify().on('error', function(err) { .pipe(uglify())
console.log(err.toString()); );
}))
return es.merge(tasks)
.pipe(gulp.dest('public/js')); .pipe(gulp.dest('public/js'));
}); });
return evstream.merge.apply(null, tasks); gulp.task('BrowserifyJS', () => {
}) const files = [
gulp.task('browserify', ['concatjs'], function () {
var files = [
{ {
src: 'public/js/shimapan.min.js', src: 'public/js/shimapan.min.js',
name: 'shimapan.bundle.js' dest: 'shimapan.bundle.js'
}, }, {
{
src: 'public/js/panel.min.js', src: 'public/js/panel.min.js',
name: 'panel.bundle.js' dest: 'panel.bundle.js'
} }
]; ];
var tasks = files.map(function (entry) { const tasks = files.map(entry =>
return browserify({entries: [entry.src]}) browserify({entries: [entry.src], debug: true}).bundle()
.bundle() .pipe(source(entry.dest))
.pipe(source(entry.src)) );
.pipe(rename(entry.name))
return es.merge(tasks)
.pipe(gulp.dest('public/js')); .pipe(gulp.dest('public/js'));
}); });
return evstream.merge.apply(null, tasks); gulp.task('MakeJS', gulp.series('MinifyJS', 'BrowserifyJS'));
}); gulp.task('MakeCSS', gulp.series('MinifyCSS'));
gulp.task('default', gulp.parallel('MakeJS', 'MakeCSS'));