60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
var fs = require('fs');
|
|
var path = require('path');
|
|
var merge = require('merge-stream');
|
|
var gulp = require('gulp');
|
|
var sourcemaps = require('gulp-sourcemaps');
|
|
var coffee = require('gulp-coffee');
|
|
var pug = require('gulp-pug');
|
|
var insert = require('gulp-insert');
|
|
var uglify = require('gulp-uglify-es').default;
|
|
var concat = require('gulp-concat');
|
|
|
|
var paths = {
|
|
lib: 'client/lib/*.js',
|
|
coffee: 'client/scripts',
|
|
pug: 'client/pug/*.pug',
|
|
dest: 'static',
|
|
maps: 'maps'
|
|
};
|
|
|
|
gulp.task('lib', function(){
|
|
return gulp.src(paths.lib)
|
|
.pipe(sourcemaps.init())
|
|
.pipe(concat('lib.min.js'))
|
|
.pipe(sourcemaps.write(paths.maps))
|
|
.pipe(gulp.dest(paths.dest))
|
|
});
|
|
|
|
function getFolders(dir) {
|
|
return fs.readdirSync(dir)
|
|
.filter(function(file) {
|
|
return fs.statSync(path.join(dir, file)).isDirectory();
|
|
});
|
|
}
|
|
|
|
gulp.task('coffee', function(){
|
|
var folders = getFolders(paths.coffee);
|
|
|
|
var tasks = folders.map(function(folder) {
|
|
return gulp.src(path.join(paths.coffee, folder, '/**/*.coffee'))
|
|
.pipe(sourcemaps.init())
|
|
.pipe(concat(folder + '.min.js'))
|
|
.pipe(coffee({bare: true}))
|
|
.pipe(insert.transform(function(contents, file) {
|
|
return '$(function () {' + contents + '});';
|
|
}))
|
|
.pipe(uglify())
|
|
.pipe(sourcemaps.write(paths.maps))
|
|
.pipe(gulp.dest(paths.dest))
|
|
});
|
|
|
|
return merge(tasks);
|
|
});
|
|
|
|
gulp.task('pug', function(){
|
|
return gulp.src(paths.pug)
|
|
.pipe(pug())
|
|
.pipe(gulp.dest(paths.dest))
|
|
});
|
|
|
|
gulp.task('default', [ 'lib', 'coffee', 'pug' ]);
|