aboutsummaryrefslogtreecommitdiff
path: root/gulpfile.js
diff options
context:
space:
mode:
Diffstat (limited to 'gulpfile.js')
-rw-r--r--gulpfile.js135
1 files changed, 92 insertions, 43 deletions
diff --git a/gulpfile.js b/gulpfile.js
index b37e899..2030db9 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -1,51 +1,100 @@
-// include gulp
-var gulp = require('gulp');
-
-// include plugins
-var jshint = require('gulp-jshint');
-var changed = require('gulp-changed');
-var minifyHTML = require('gulp-minify-html');
-var concat = require('gulp-concat');
-var stripDebug = require('gulp-strip-debug');
-var uglify = require('gulp-uglify');
-var autoprefix = require('gulp-autoprefixer');
-var minifyCSS = require('gulp-minify-css');
-
-// Default task
-gulp.task('default', ['jshint', 'htmlpage', 'scripts', 'styles'], function(){
-});
+// see https://github.com/tugberkugurlu/gulp-bootswatch-sample/
+
+var gulp = require('gulp'),
+ minifycss = require('gulp-minify-css'),
+ concat = require('gulp-concat'),
+ less = require('gulp-less'),
+ gulpif = require('gulp-if'),
+ order = require('gulp-order'),
+ gutil = require('gulp-util'),
+ rename = require('gulp-rename'),
+ foreach = require('gulp-foreach'),
+ debug = require('gulp-debug'),
+ path =require('path'),
+ merge = require('merge-stream'),
+ del = require('del');
-// JS hint task
-gulp.task('jshint', function(){
- gulp.src('./src/scripts/*.js')
- .pipe(jshint())
- .pipe(jshint.reporter('default'));
+var bootswatch_theme = 'superhero';
+
+gulp.task('default', ['clean'], function() {
+ gulp.start('fonts', 'styles');
});
-// minify new/changed HTML
-gulp.task('htmlpage', function(){
- var src = './src/*.html';
- var dst = './build';
- gulp.src(src)
- .pipe(changed(dst))
- .pipe(minifyHTML())
- .pipe(gulp.dest(dst));
+gulp.task('clean', function(cb) {
+ del(['assets/css', 'assets/js', 'assets/less', 'assets/img', 'assets/fonts'], cb)
});
-// JS concat, strip debugging and minify
-gulp.task('scripts', function(){
- gulp.src(['./src/scripts/lib.js', './src/scripts/*.js'])
- .pipe(concat('script.js'))
- .pipe(stripDebug())
- .pipe(uglify())
- .pipe(gulp.dest('./build/scripts'));
+gulp.task('fonts', function() {
+
+ var fileList = [
+ 'bower_components/bootstrap/dist/fonts/*',
+ 'bower_components/fontawesome/fonts/*'
+ ];
+
+ return gulp.src(fileList)
+ .pipe(gulp.dest('assets/fonts'));
});
-// CSS concat, auto-prefix and minify
-gulp.task('styles', function(){
- gulp.src(['./src/styles/*.css'])
- .pipe(concat('styles.css'))
- .pipe(autoprefix('last 2 versions'))
- .pipe(minifyCSS())
- .pipe(gulp.dest('./build/styles/'));
+gulp.task('styles', function() {
+
+ var baseContent = '@import "bower_components/bootstrap/less/bootstrap.less";@import "bower_components/bootswatch/' + bootswatch_theme + '/variables.less";@import "bower_components/bootswatch/' + bootswatch_theme + '/bootswatch.less";@import "bower_components/bootstrap/less/utilities.less";';
+ var isBootswatchFile = function(file) {
+ var suffix = 'bootswatch.less';
+ return file.path.indexOf(suffix, file.path.length - suffix.length) !== -1;
+ }
+
+ var isBootstrapFile = function(file) {
+ var suffix = 'bootstrap-',
+ fileName = path.basename(file.path);
+
+ return fileName.indexOf(suffix) == 0;
+ }
+
+ var fileList = [
+ 'client/less/main.less',
+ 'bower_components/bootswatch/**/bootswatch.less',
+ 'bower_components/fontawesome/css/font-awesome.css'
+ ];
+
+ return gulp.src(fileList)
+ .pipe(gulpif(isBootswatchFile, foreach(function(stream, file) {
+ var themeName = path.basename(path.dirname(file.path)),
+ content = replaceAll(baseContent, bootswatch_theme, themeName),
+ file = string_src('bootstrap-' + themeName + '.less', content);
+
+ return file;
+ })))
+ .pipe(less())
+ .pipe(gulp.dest('assets/css'))
+ .pipe(gulpif(isBootstrapFile, foreach(function(stream, file) {
+ var fileName = path.basename(file.path),
+ themeName = fileName.substring(fileName.indexOf('-') + 1, fileName.indexOf('.'));
+
+ // http://stackoverflow.com/questions/21719833/gulp-how-to-add-src-files-in-the-middle-of-a-pipe
+ // https://github.com/gulpjs/gulp/blob/master/docs/recipes/using-multiple-sources-in-one-task.md
+ return merge(stream, gulp.src(['assets/css/font-awesome.css', 'assets/css/main.css']))
+ .pipe(concat('style-' + themeName + ".css"))
+ .pipe(gulp.dest('assets/css'))
+ .pipe(rename({suffix: '.min'}))
+ .pipe(minifycss())
+ .pipe(gulp.dest('assets/css'));
+ })))
});
+
+// http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript
+function escapeRegExp(string) {
+ return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
+}
+
+function replaceAll(string, find, replace) {
+ return string.replace(new RegExp(escapeRegExp(find), 'g'), replace);
+}
+
+function string_src(filename, string) {
+ var src = require('stream').Readable({ objectMode: true })
+ src._read = function () {
+ this.push(new gutil.File({ cwd: "", base: "", path: filename, contents: new Buffer(string) }))
+ this.push(null)
+ }
+ return src
+} \ No newline at end of file