1

Gulpfile unification work

This commit is contained in:
Alex Yatskov 2014-10-03 10:29:23 +09:00
parent ae6d58255c
commit 24454ed966
2 changed files with 88 additions and 29 deletions

View File

@ -1,4 +1,5 @@
/* /*
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2014 Alex Yatskov Copyright (c) 2014 Alex Yatskov
@ -20,24 +21,75 @@
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 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 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
var concat = require('gulp-concat');
var gulp = require('gulp'); var gulp = require('gulp');
var inject = require('gulp-inject');
var jshint = require('gulp-jshint'); var jshint = require('gulp-jshint');
var nodemon = require('gulp-nodemon'); var mainBowerFiles = require('main-bower-files');
var minifyCss = require('gulp-minify-css');
var minifyHtml = require('gulp-minify-html');
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;
}
gulp.task('lint', function() { gulp.task('lint', function() {
gulp.src(['server/*.js']).pipe(jshint()); var scripts = ['*.js', 'client/scripts/*.js', 'server/*.js'];
gulp.src(scripts).pipe(jshint());
});
gulp.task('images', function() {
return gulp.src('client/images').pipe(gulp.dest('client/dist/images'));
});
gulp.task('fonts', function() {
return gulp.src('client/bower_components/bootstrap/fonts/*') .pipe(gulp.dest('client/dist/fonts'));
});
gulp.task('scripts', function() {
var scripts = ['client/scripts/*.js'].concat(getBowerFiles('.js'));
return gulp.src(scripts).pipe(concat('scripts.js')).pipe(uglify()).pipe(gulp.dest('client/dist'));
});
gulp.task('styles', function() {
var styles = ['client/styles/*.css'].concat(getBowerFiles('.css'));
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'));
});
gulp.task('html_dist', ['scripts', 'styles'], function() {
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'));
}); });
gulp.task('develop', function() { gulp.task('develop', function() {
var options = { var options = {script: 'server/server.js', ext: 'js', port: 8000};
script: 'server/server.js',
ext: 'js',
port: 8000
};
return nodemon(options).on('change', ['lint']); return nodemon(options).on('change', ['lint']);
}); });
gulp.task('default', ['lint', 'develop']); gulp.task('dev', ['lint', 'html_dev']);
gulp.task('dist', ['lint', 'fonts', 'images', 'scripts', 'styles', 'html_dist']);
gulp.task('server', ['lint', 'develop']);

View File

@ -14,7 +14,14 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"gulp": "^3.8.8", "gulp": "^3.8.8",
"gulp-concat": "^2.4.1",
"gulp-inject": "^1.0.2",
"gulp-jshint": "^1.8.5", "gulp-jshint": "^1.8.5",
"gulp-nodemon": "^1.0.4" "gulp-minify-css": "^0.3.10",
"gulp-minify-html": "^0.1.5",
"gulp-nodemon": "^1.0.4",
"gulp-replace": "^0.4.0",
"gulp-uglify": "^1.0.1",
"main-bower-files": "^2.0.0"
} }
} }