2014-10-02 10:21:41 +00:00
|
|
|
/*
|
2014-10-03 01:29:23 +00:00
|
|
|
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
|
|
|
Copyright (c) 2014 Alex Yatskov
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
2014-10-02 10:21:41 +00:00
|
|
|
*/
|
|
|
|
|
2014-10-03 02:12:30 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-10-03 01:29:23 +00:00
|
|
|
var concat = require('gulp-concat');
|
|
|
|
var gulp = require('gulp');
|
|
|
|
var inject = require('gulp-inject');
|
|
|
|
var jshint = require('gulp-jshint');
|
|
|
|
var mainBowerFiles = require('main-bower-files');
|
|
|
|
var minifyCss = require('gulp-minify-css');
|
|
|
|
var minifyHtml = require('gulp-minify-html');
|
2014-10-03 02:12:30 +00:00
|
|
|
var nodemon = require('gulp-nodemon');
|
2014-10-03 01:29:23 +00:00
|
|
|
var path = require('path');
|
|
|
|
var replace = require('gulp-replace');
|
|
|
|
var uglify = require('gulp-uglify');
|
|
|
|
|
|
|
|
function getBowerFiles(extension) {
|
|
|
|
var allPaths = mainBowerFiles({paths: 'client'});
|
|
|
|
|
|
|
|
var resultPaths = [];
|
|
|
|
for (var i = 0, count = allPaths.length; i < count; ++i) {
|
|
|
|
if (path.extname(allPaths[i]).toLowerCase() == extension) {
|
|
|
|
resultPaths.push(allPaths[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultPaths;
|
|
|
|
}
|
2014-10-02 10:21:41 +00:00
|
|
|
|
|
|
|
gulp.task('lint', function() {
|
2014-10-03 01:29:23 +00:00
|
|
|
var scripts = ['*.js', 'client/scripts/*.js', 'server/*.js'];
|
|
|
|
gulp.src(scripts).pipe(jshint());
|
2014-10-02 10:21:41 +00:00
|
|
|
});
|
|
|
|
|
2014-10-03 01:29:23 +00:00
|
|
|
gulp.task('images', function() {
|
2014-10-03 02:12:30 +00:00
|
|
|
return gulp.src('client/images/*').pipe(gulp.dest('client/dist/images'));
|
2014-10-03 01:29:23 +00:00
|
|
|
});
|
2014-10-02 10:21:41 +00:00
|
|
|
|
2014-10-03 01:29:23 +00:00
|
|
|
gulp.task('fonts', function() {
|
|
|
|
return gulp.src('client/bower_components/bootstrap/fonts/*') .pipe(gulp.dest('client/dist/fonts'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('scripts', function() {
|
2014-10-03 02:12:30 +00:00
|
|
|
var scripts = getBowerFiles('.js').concat(['client/scripts/*.js']);
|
2014-10-03 01:29:23 +00:00
|
|
|
return gulp.src(scripts).pipe(concat('scripts.js')).pipe(uglify()).pipe(gulp.dest('client/dist'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('styles', function() {
|
2014-10-03 02:12:30 +00:00
|
|
|
var styles = getBowerFiles('.css').concat(['client/styles/*.css']);
|
|
|
|
console.log(styles);
|
2014-10-03 01:29:23 +00:00
|
|
|
return gulp.src(styles).pipe(replace('../fonts/', './fonts/')).pipe(concat('styles.css')).pipe(minifyCss()).pipe(gulp.dest('client/dist'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('html_dev', function() {
|
|
|
|
var sources = gulp.src(getBowerFiles('.css').concat(getBowerFiles('.js')).concat(['client/scripts/*.js', 'client/styles/*.css']), {read: false});
|
|
|
|
var target = 'client/html/index.html';
|
|
|
|
var options = {addRootSlash: false, ignorePath: 'client'};
|
|
|
|
return gulp.src(target).pipe(inject(sources, options)).pipe(gulp.dest('client'));
|
|
|
|
});
|
|
|
|
|
2014-10-03 02:12:30 +00:00
|
|
|
gulp.task('html_dist', ['fonts', 'images', 'scripts', 'styles'], function() {
|
2014-10-03 01:29:23 +00:00
|
|
|
var sources = gulp.src(['client/dist/*.js', 'client/dist/*.css'], {read: false});
|
|
|
|
var options = {addRootSlash: false, ignorePath: 'client/dist'};
|
|
|
|
var target = 'client/html/index.html';
|
|
|
|
return gulp.src(target).pipe(inject(sources, options)).pipe(minifyHtml()).pipe(gulp.dest('client/dist'));
|
|
|
|
});
|
|
|
|
|
2014-10-03 02:12:30 +00:00
|
|
|
gulp.task('dev', ['lint', 'html_dev'], function() {
|
|
|
|
var options = {script: 'server/server.js', ext: 'js', port: 8000, args: ['client']};
|
|
|
|
return nodemon(options).on('change', ['lint']);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('dist', ['html_dist'], function() {
|
|
|
|
var options = {script: 'server/server.js', ext: 'js', port: 8000, args: ['client/dist']};
|
2014-10-02 10:21:41 +00:00
|
|
|
return nodemon(options).on('change', ['lint']);
|
|
|
|
});
|
|
|
|
|
2014-10-03 02:12:30 +00:00
|
|
|
gulp.task('default', ['dev']);
|