From c4fb5aa3abdc1c26b8fb8f51150b3e7b078fe674 Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Sat, 8 Mar 2014 10:03:39 -0700 Subject: [PATCH] chore(build): windows error improvements, better cssmin --- config/version.template.json | 6 ++++ gulpfile.js | 57 ++++++++++++++++++++++++------------ package.json | 4 +-- 3 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 config/version.template.json diff --git a/config/version.template.json b/config/version.template.json new file mode 100644 index 000000000..0902d94c2 --- /dev/null +++ b/config/version.template.json @@ -0,0 +1,6 @@ +{ + "version": "<%= pkg.version %>", + "codename": "<%= pkg.codename %>", + "date": "<%= date %>", + "time": "<%= time %>" +} diff --git a/gulpfile.js b/gulpfile.js index 15248c797..23f862598 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,7 +4,6 @@ var connect = require('connect'); var dgeni = require('dgeni'); var http = require('http'); var cp = require('child_process'); -var fs = require('fs'); var gulp = require('gulp'); var pkg = require('./package.json'); var through = require('through'); @@ -13,10 +12,10 @@ var argv = require('minimist')(process.argv.slice(2)); var bump = require('gulp-bump'); var concat = require('gulp-concat'); -var cssmin = require('gulp-cssmin'); var gulpif = require('gulp-if'); var header = require('gulp-header'); var jshint = require('gulp-jshint'); +var minifyCss = require('gulp-minify-css'); var rename = require('gulp-rename'); var sass = require('gulp-sass'); var stripDebug = require('gulp-strip-debug'); @@ -28,7 +27,7 @@ var banner = _.template(buildConfig.banner, { pkg: pkg }); var IS_RELEASE_BUILD = !!argv.release; if (IS_RELEASE_BUILD) { - gutil.log(gutil.colors.red('--release=true:'), + gutil.log(gutil.colors.red('--release:'), 'Building release version (minified, debugs stripped)...' ); } @@ -40,7 +39,9 @@ gulp.task('docs', function() { dgeni('docs/docs.config.js').generateDocs(); }); +var IS_WATCH = false; gulp.task('watch', function() { + IS_WATCH = true; gulp.watch('js/**/*.js', ['bundle', 'docs']); gulp.watch('docs/**/*', ['docs']); gulp.watch('scss/**/*.scss', ['sass']); @@ -54,6 +55,7 @@ gulp.task('bundle', [ 'scripts', 'scripts-ng', 'vendor', + 'version', ], function() { IS_RELEASE_BUILD && gulp.src(buildConfig.ionicBundleFiles.map(function(src) { return src.replace(/.js$/, '.min.js'); @@ -62,16 +64,6 @@ gulp.task('bundle', [ .pipe(concat('ionic.bundle.min.js')) .pipe(gulp.dest(buildConfig.distJs)); - var d = new Date(); - fs.writeFileSync('dist/version.json', JSON.stringify({ - version: pkg.version, - codename: pkg.codename, - date: d.toISOString().substring(0,10), - time: pad(d.getUTCHours()) + - ':' + pad(d.getUTCMinutes()) + - ':' + pad(d.getUTCSeconds()) - }, null, 2)); - return gulp.src(buildConfig.ionicBundleFiles) .pipe(header(buildConfig.bundleBanner)) .pipe(concat('ionic.bundle.js')) @@ -125,18 +117,47 @@ gulp.task('scripts-ng', function() { .pipe(gulp.dest(buildConfig.distJs)); }); -gulp.task('sass', function() { - return gulp.src('scss/ionic.scss') +gulp.task('sass', function(done) { + gulp.src('scss/ionic.scss') .pipe(header(banner)) - .pipe(sass()) + .pipe(sass({ + onError: function(err) { + //If we're watching, don't exit on error + if (IS_WATCH) { + console.log(gutil.colors.red(err)); + } else { + done(err); + } + } + })) .pipe(concat('ionic.css')) .pipe(gulp.dest(buildConfig.distCss)) - .pipe(gulpif(IS_RELEASE_BUILD, cssmin())) + .pipe(gulpif(IS_RELEASE_BUILD, minifyCss({ + keepSpecialComments: 0 + }))) .pipe(header(banner)) .pipe(rename({ extname: '.min.css' })) - .pipe(gulp.dest(buildConfig.distCss)); + .pipe(gulp.dest(buildConfig.distCss)) + .on('end', done); }); +gulp.task('version', function() { + var d = new Date(); + var date = d.toISOString().substring(0,10); + var time = pad(d.getUTCHours()) + + ':' + pad(d.getUTCMinutes()) + + ':' + pad(d.getUTCSeconds()); + return gulp.src('config/version.template.json') + .pipe(template({ + pkg: pkg, + date: date, + time: time + })) + .pipe(rename('version.json')) + .pipe(gulp.dest('dist')); +}); + + gulp.task('sauce-connect', sauceConnect); gulp.task('cloudtest', ['protractor-sauce'], function(cb) { diff --git a/package.json b/package.json index 9185c198e..2de3251bb 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "jshint-stylish": "^0.1.5", "gulp-template": "^0.1.1", "gulp-concat": "^2.1.7", - "gulp-cssmin": "^0.1.3", "gulp-jshint": "^1.5.0", "gulp-strip-debug": "^0.2.0", "gulp-sass": "^0.7.1", @@ -36,7 +35,8 @@ "canonical-path": "0.0.2", "lodash": "^2.4.1", "winston": "^0.7.2", - "minimist": "0.0.8" + "minimist": "0.0.8", + "gulp-minify-css": "^0.3.0" }, "licenses": [ {