1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-12-10 21:48:03 -05:00
shimapan/gulpfile.js

137 lines
3.3 KiB
JavaScript
Raw Normal View History

var gulp = require('gulp');
2017-10-12 17:26:35 -04:00
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');
2017-10-12 17:26:35 -04:00
2017-10-20 17:43:19 -04:00
gulp.task('start', function() {
nodemon({
script: 'server.js',
ignore: '*.*'
});
})
gulp.task('watch', function () {
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) {
if (path.extname(file) === '.js' && !~tasks.indexOf('minjs'))
tasks.push('minjs');
if (path.extname(file) === '.css' && !~tasks.indexOf('mincss'))
tasks.push('mincss');
});
return tasks;
}
}).on('restart?', function () {
gulp.start('default');
});
2017-10-14 15:17:16 -04:00
});
gulp.task('default', function () {
gulp.start('minjs');
gulp.start('mincss');
2017-10-14 15:17:16 -04:00
});
2017-10-12 17:26:35 -04:00
gulp.task('mincss', function () {
var files = [
{
2017-10-20 16:46:14 -04:00
src: 'app/public/css/form.css',
name: 'form.min.css'
},
{
2017-10-20 16:46:14 -04:00
src: 'app/public/css/home.css',
name: 'home.min.css'
},
{
2017-10-20 16:46:14 -04:00
src: 'app/public/css/panel.css',
name: 'panel.min.css'
},
{
2017-10-20 16:46:14 -04:00
src: 'app/public/css/index.css',
name: 'index.min.css'
}
];
var tasks = files.map(function (entry) {
return gulp.src(entry.src)
.pipe(cleanCSS())
.pipe(rename(entry.name))
.pipe(gulp.dest('public/css'));
});
return evstream.merge.apply(null, tasks);
})
gulp.task('minjs', function () {
gulp.start('concatjs');
gulp.start('browserify');
});
gulp.task('concatjs', function () {
var files = [
{
src: [
2017-10-20 16:46:14 -04:00
'app/public/services/*.js',
'app/public/panel/**/*.js'
],
name: 'panel.min.js'
},
{
src: [
2017-10-20 16:46:14 -04:00
'app/public/services/*.js',
'app/public/shimapan/**/*.js'
],
name: 'shimapan.min.js'
2017-10-20 16:46:14 -04:00
},
{
src: 'app/public/index/*.js',
name: 'index.min.js'
}
];
var tasks = files.map(function (entry) {
return gulp.src(entry.src)
.pipe(concat(entry.name))
.pipe(uglify())
2017-10-20 16:46:14 -04:00
.pipe(gulp.dest('public/js'));
});
return evstream.merge.apply(null, tasks);
})
gulp.task('browserify', ['concatjs'], function () {
var files = [
{
2017-10-20 16:46:14 -04:00
src: 'public/js/shimapan.min.js',
name: 'shimapan.bundle.js'
},
{
2017-10-20 16:46:14 -04:00
src: 'public/js/panel.min.js',
name: 'panel.bundle.js'
}
];
var tasks = files.map(function (entry) {
return browserify({entries: [entry.src]})
.bundle()
.pipe(source(entry.src))
.pipe(rename(entry.name))
2017-10-20 16:46:14 -04:00
.pipe(gulp.dest('public/js'));
});
return evstream.merge.apply(null, tasks);
2017-10-12 17:26:35 -04:00
});