1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-12-04 19:32:20 -05:00
shimapan/gulpfile.js

135 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-07-24 19:39:34 -04:00
'use strict';
2017-10-12 17:26:35 -04:00
2018-07-24 19:39:34 -04:00
const gulp = require('gulp');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
2018-08-14 05:12:58 -04:00
//const uglify = require('gulp-uglify');
const uglifyes = require('uglify-es');
const composer = require('gulp-uglify/composer');
const uglify = composer(uglifyes, console);
2018-07-24 19:39:34 -04:00
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) => {
2017-10-20 17:43:19 -04:00
nodemon({
script: 'server.js',
ignore: '*.*'
});
2018-07-24 19:39:34 -04:00
done();
});
2017-10-20 17:43:19 -04:00
2018-07-24 19:39:34 -04:00
gulp.task('watch', (done) => {
nodemon({
script: 'server.js',
ext: 'js html css',
env: {'NODE_ENV': 'dev'},
2017-10-20 16:46:14 -04:00
watch: [
'app/',
'config/'
],
tasks: function (changedFiles) {
var tasks = [];
changedFiles.forEach(function (file) {
2018-07-24 19:39:34 -04:00
if (path.extname(file) === '.js' && !~tasks.indexOf('MakeJS'))
tasks.push('MakeJS');
if (path.extname(file) === '.css' && !~tasks.indexOf('MakeCSS'))
tasks.push('MakeCSS');
});
return tasks;
}
}).on('restart?', function () {
2018-07-24 19:39:34 -04:00
gulp.task('default')();
});
2017-10-14 15:17:16 -04:00
});
2018-07-24 19:39:34 -04:00
gulp.task('MinifyCSS', () => {
const files = [
{
2017-10-20 16:46:14 -04:00
src: 'app/public/css/form.css',
2018-07-24 19:39:34 -04:00
dest: 'form.min.css'
},
{
2017-10-20 16:46:14 -04:00
src: 'app/public/css/home.css',
2018-07-24 19:39:34 -04:00
dest: 'home.min.css'
},
{
2017-10-20 16:46:14 -04:00
src: 'app/public/css/panel.css',
2018-07-24 19:39:34 -04:00
dest: 'panel.min.css'
},
{
2017-10-20 16:46:14 -04:00
src: 'app/public/css/index.css',
2018-07-24 19:39:34 -04:00
dest: 'index.min.css'
}
];
2018-07-24 19:39:34 -04:00
const tasks = files.map(file =>
gulp.src(file.src)
.pipe(cleanCSS())
2018-07-24 19:39:34 -04:00
.pipe(rename(file.dest))
.pipe(gulp.dest('public/css')));
2018-07-24 19:39:34 -04:00
return es.merge(tasks)
.pipe(gulp.dest('public/css'));
});
2018-07-24 19:39:34 -04:00
gulp.task('MinifyJS', () => {
const files = [
{
src: [
2017-10-20 16:46:14 -04:00
'app/public/services/*.js',
'app/public/panel/**/*.js'
],
2018-07-24 19:39:34 -04:00
dest: 'panel.min.js'
},
{
src: [
2017-10-20 16:46:14 -04:00
'app/public/services/*.js',
'app/public/shimapan/**/*.js'
],
2018-07-24 19:39:34 -04:00
dest: 'shimapan.min.js'
2017-10-20 16:46:14 -04:00
},
{
src: 'app/public/index/*.js',
2018-07-24 19:39:34 -04:00
dest: 'index.min.js'
}
];
2018-07-24 19:39:34 -04:00
const tasks = files.map(file =>
gulp.src(file.src)
.pipe(concat(file.dest))
.pipe(uglify())
);
2018-07-24 19:39:34 -04:00
return es.merge(tasks)
.pipe(gulp.dest('public/js'));
});
2018-07-24 19:39:34 -04:00
gulp.task('BrowserifyJS', () => {
const files = [
{
2017-10-20 16:46:14 -04:00
src: 'public/js/shimapan.min.js',
2018-07-24 19:39:34 -04:00
dest: 'shimapan.bundle.js'
}, {
2017-10-20 16:46:14 -04:00
src: 'public/js/panel.min.js',
2018-07-24 19:39:34 -04:00
dest: 'panel.bundle.js'
}
];
2018-07-24 19:39:34 -04:00
const tasks = files.map(entry =>
browserify({entries: [entry.src], debug: true}).bundle()
.pipe(source(entry.dest))
);
2018-07-24 19:39:34 -04:00
return es.merge(tasks)
.pipe(gulp.dest('public/js'));
2017-10-12 17:26:35 -04:00
});
2018-07-24 19:39:34 -04:00
gulp.task('MakeJS', gulp.series('MinifyJS', 'BrowserifyJS'));
gulp.task('MakeCSS', gulp.series('MinifyCSS'));
gulp.task('default', gulp.parallel('MakeJS', 'MakeCSS'));