1

Simplify gulp

This commit is contained in:
Alex Yatskov 2015-02-27 17:15:15 +09:00
parent fb2c0c9419
commit ba3f2e6acd
6 changed files with 26 additions and 115 deletions

3
client/.gitignore vendored
View File

@ -1,4 +1 @@
bower_components bower_components
dist
index.html
props.html

View File

@ -1,113 +1,34 @@
/* /*
* Copyright (c) 2015 <name of copyright holder>
The MIT License (MIT) * Author: Alex Yatskov <alex@foosoft.net>
*
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
Permission is hereby granted, free of charge, to any person obtaining a copy * the Software without restriction, including without limitation the rights to
of this software and associated documentation files (the "Software"), to deal * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
in the Software without restriction, including without limitation the rights * the Software, and to permit persons to whom the Software is furnished to do so,
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * subject to the following conditions:
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 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
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.
*/ */
var concat = require('gulp-concat');
var gulp = require('gulp'); var gulp = require('gulp');
var inject = require('gulp-inject');
var install = require('gulp-install'); var install = require('gulp-install');
var mainBowerFiles = require('main-bower-files');
var minifyCss = require('gulp-minify-css');
var minifyHtml = require('gulp-minify-html');
var nodemon = require('gulp-nodemon'); var nodemon = require('gulp-nodemon');
var path = require('path');
var replace = require('gulp-replace');
var uglify = require('gulp-uglify');
function getBowerFiles(extension) { gulp.task('default', function() {
var allPaths = mainBowerFiles({paths: 'client'}); return nodemon({script: 'server/server.js', ext: 'js html'}).on('change', ['default']);
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('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 = getBowerFiles('.js').concat(['client/scripts/*.js']);
return gulp.src(scripts).pipe(concat('scripts.js')).pipe(uglify()).pipe(gulp.dest('client/dist'));
});
gulp.task('styles', function() {
var styles = getBowerFiles('.css').concat(['client/styles/*.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/*.html';
var options = {addRootSlash: false, ignorePath: 'client'};
return gulp.src(target).pipe(inject(sources, options)).pipe(gulp.dest('client'));
});
gulp.task('html_dist', ['fonts', 'images', 'scripts', 'styles'], function() {
var sources = gulp.src(['client/dist/*.js', 'client/dist/*.css'], {read: false});
var target = 'client/html/*.html';
var options = {addRootSlash: false, ignorePath: 'client/dist'};
return gulp.src(target).pipe(inject(sources, options)).pipe(minifyHtml()).pipe(gulp.dest('client/dist'));
});
gulp.task('dev', ['html_dev'], function() {
var options = {
script: 'server/server.js',
ext: 'js html',
ignore: ['client/*.html'],
args: ['client']
};
return nodemon(options).on('change', ['html_dev']);
});
gulp.task('dist', ['html_dist'], function() {
var options = {
script: 'server/server.js',
ext: 'js html css',
ignore: ['client/dist/*'],
args: ['client/dist']
};
return nodemon(options).on('change', ['html_dist']);
}); });
gulp.task('install', function() { gulp.task('install', function() {
gulp.src(['client/bower.json', 'server/package.json', 'scrape/package.json']).pipe(install()); gulp.src(['client/bower.json', 'server/package.json', 'scrape/package.json']).pipe(install());
}); });
gulp.task('default', ['dev']);

View File

@ -14,15 +14,8 @@
"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-install": "^0.2.0", "gulp-install": "^0.2.0",
"gulp-minify-css": "^0.3.10",
"gulp-minify-html": "^0.1.5",
"gulp-nodemon": "^1.0.4", "gulp-nodemon": "^1.0.4",
"gulp-replace": "^0.4.0",
"gulp-uglify": "^1.0.1",
"main-bower-files": "^2.0.0",
"jsonfile": "~2.0.0" "jsonfile": "~2.0.0"
} }
} }

View File

@ -50,5 +50,5 @@ function main(staticFiles, port) {
} }
if (require.main === module) { if (require.main === module) {
main(process.argv[2] || 'client', 3000); main('client', 3000);
} }