diff --git a/.travis.yml b/.travis.yml index 6792c74d8..613547d64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,4 @@ before_script: - npm install grunt-cli - bower install -script: "grunt test:travis" +script: "gulp test" diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index a09e92836..000000000 --- a/Gruntfile.js +++ /dev/null @@ -1,119 +0,0 @@ -var bower = require('bower'); - -module.exports = function(grunt) { - grunt.loadNpmTasks('grunt-contrib-clean'); - grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-contrib-copy'); - grunt.loadNpmTasks('grunt-hustler'); - grunt.loadNpmTasks('grunt-karma'); - grunt.loadNpmTasks('grunt-conventional-changelog'); - grunt.loadNpmTasks('grunt-contrib-watch'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-contrib-cssmin'); - - grunt.initConfig({ - - pkg: grunt.file.readJSON('package.json'), - - watch: { - files: ['src/**/*'], - tasks: ['build'], - }, - - karma: { - options: { - configFile: 'karma.conf.js' - }, - watch: { - // Does not work under Windows? - //background: true, - singleRun: false - }, - once: { - singleRun: true - }, - travis: { - singleRun: true, - browsers: ['PhantomJS', 'Firefox'] - } - }, - - changelog: { - options: { - dest: 'CHANGELOG.md' - } - }, - - clean: { - dist: ['dist/'], - tmp: ['.tmp/'] - }, - - ngTemplateCache: { - views: { - files: { - '.tmp/templates.js': 'src/**/*.tpl.html' - }, - options: { - trim: 'src/', - module: 'ui.select' - } - } - }, - - concat: { - dist: { - src: [ - 'src/select.js', - '.tmp/templates.js' - ], - dest: 'dist/select.js' - } - }, - - copy: { - dist: { - files: [{ - src: 'src/select.css', - dest: 'dist/select.css' - }] - } - }, - - uglify: { - options: { - banner: '/*!\n<%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %>\n<%= pkg.homepage %>\n*/\n', - sourceMap: true - }, - build: { - files: { - 'dist/select.min.js': ['dist/select.js'] - } - }, - compress: { - global_defs: { - "DEBUG": false - }, - dead_code: true - }, - }, - - cssmin: { - minify: { - options: { - banner: '/*!\n<%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %>\n<%= pkg.homepage %>\n*/\n', - }, - files: { - 'dist/select.min.css': ['src/select.css'] - } - } - } - - }); - - grunt.registerTask('default', ['test']); - grunt.registerTask('build', ['clean', 'ngTemplateCache', 'concat', 'copy', 'uglify:build', 'cssmin', 'clean:tmp']); - grunt.registerTask('test', ['build', 'karma:once']); - grunt.registerTask('test:watch', ['build', 'karma:watch']); - grunt.registerTask('test:travis', ['build', 'karma:travis']); -}; diff --git a/README.md b/README.md index 1e25cef97..5c50957a5 100644 --- a/README.md +++ b/README.md @@ -138,19 +138,18 @@ Or:
``` -## Run the tests - -Install [Node.js](http://nodejs.org/), then inside a console: -``` -npm update # Installs all Grunt dependencies (package.json) inside node_modules directory -bower update # Installs all ui-select dependencies (bower.json) inside bower_components directory -``` - -To run the tests: -``` -grunt build # Builds dist/select.js -grunt test # Launches Karma -``` +## Development +### Prepare your environment +* Install [Node.js](http://nodejs.org/) and NPM (should come with) +* Install global dev dependencies: `npm install -g bower gulp` +* Install local dev dependencies: `npm install && bower install` in repository directory + +### Development Commands + +* `gulp` to jshint, build and test +* `gulp build` to jshint and build +* `gulp test` for one-time test with karma (also build and jshint) +* `gulp watch` to watch src files to jshin, build and test when changed ## Contributing diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 000000000..1c8d29d79 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,101 @@ +var fs = require('fs'); +var gulp = require('gulp'); +var karma = require('karma').server; +var concat = require('gulp-concat'); +var jshint = require('gulp-jshint'); +var header = require('gulp-header'); +var rename = require('gulp-rename'); +var es = require('event-stream'); +var del = require('del'); +var uglify = require('gulp-uglify'); +var minifyHtml = require('gulp-minify-html'); +var minifyCSS = require('gulp-minify-css'); +var templateCache = require('gulp-angular-templatecache'); +var gutil = require('gulp-util'); +var plumber = require('gulp-plumber');//To prevent pipe breaking caused by errors at 'watch' + +var config = { + pkg : JSON.parse(fs.readFileSync('./package.json')), + banner: + '/*!\n' + + ' * <%= pkg.name %>\n' + + ' * <%= pkg.homepage %>\n' + + ' * Version: <%= pkg.version %> - <%= timestamp %>\n' + + ' * License: <%= pkg.license %>\n' + + ' */\n\n\n' +}; + +gulp.task('default', ['build','test']); +gulp.task('build', ['scripts', 'styles']); +gulp.task('test', ['build', 'karma']); + +gulp.task('watch', ['build','karma-watch'], function() { + gulp.watch(['src/**/*.{js,html}'], ['build']); +}); + +gulp.task('clean', function(cb) { + del(['dist'], cb); +}); + +gulp.task('scripts', ['clean'], function() { + + var buildTemplates = function () { + return gulp.src('src/**/*.html') + .pipe(minifyHtml({ + empty: true, + spare: true, + quotes: true + })) + .pipe(templateCache({module: 'ui.select'})); + }; + + var buildLib = function(){ + return gulp.src('src/select.js') + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(jshint()) + .pipe(jshint.reporter('jshint-stylish')) + .pipe(jshint.reporter('fail')); + }; + + return es.merge(buildLib(), buildTemplates()) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select.js')) + .pipe(header(config.banner, { + timestamp: (new Date()).toISOString(), pkg: config.pkg + })) + .pipe(gulp.dest('dist')) + .pipe(uglify({preserveComments: 'some'})) + .pipe(rename({ext:'.min.js'})) + .pipe(gulp.dest('dist')); + +}); + +gulp.task('styles', ['clean'], function() { + + return gulp.src('src/select.css') + .pipe(header(config.banner, { + timestamp: (new Date()).toISOString(), pkg: config.pkg + })) + .pipe(gulp.dest('dist')) + .pipe(minifyCSS()) + .pipe(rename({ext:'.min.css'})) + .pipe(gulp.dest('dist')); + +}); + +gulp.task('karma', ['build'], function() { + karma.start({configFile : __dirname +'/karma.conf.js', singleRun: true}); +}); + +gulp.task('karma-watch', ['build'], function() { + karma.start({configFile : __dirname +'/karma.conf.js', singleRun: false}); +}); + +var handleError = function (err) { + console.log(err.toString()); + this.emit('end'); +}; diff --git a/karma.conf.js b/karma.conf.js index 9a8c9fe82..ed948771a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -40,7 +40,7 @@ module.exports = function(config) { // - Safari (only Mac) // - PhantomJS // - IE (only Windows) - browsers: ['Chrome'], + browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'], // Continuous Integration mode // if true, it capture browsers, run tests and exit diff --git a/package.json b/package.json index 2e86341b4..95ac2e507 100644 --- a/package.json +++ b/package.json @@ -8,20 +8,26 @@ "version": "0.3.1", "devDependencies": { "bower": "~1.3", - "grunt": "~0.4", - "grunt-contrib-clean": "~0.4", - "grunt-contrib-concat": "~0.1", - "grunt-contrib-copy": "~0.5", - "grunt-contrib-cssmin": "^0.10.0", - "grunt-contrib-uglify": "^0.5.0", - "grunt-contrib-watch": "~0.6.1", - "grunt-conventional-changelog": "~1.1", - "grunt-hustler": "~4.0", - "grunt-karma": "~0.8", - "karma": "~0.12", - "karma-chrome-launcher": "~0.1", + "del": "~0.1.1", + "event-stream": "~3.1.0", + "gulp": "~3.8.5", + "gulp-angular-templatecache": "~1.2.1", + "gulp-concat": "~2.1.7", + "gulp-header": "~1.0.2", + "gulp-jshint": "1.6.4", + "gulp-minify-css": "~0.3.6", + "gulp-minify-html": "~0.1.0", + "gulp-plumber": "^0.6.3", + "gulp-rename": "~0.2.2", + "gulp-uglify": "~0.3.1", + "gulp-util": "^2.2.19", + "jshint-stylish": "~0.3.0", + "karma": "^0.12.16", + "karma-chrome-launcher": "^0.1.3", "karma-firefox-launcher": "~0.1", "karma-jasmine": "~0.2", - "karma-phantomjs-launcher": "~0.1" - } + "karma-ng-html2js-preprocessor": "^0.1.0", + "karma-phantomjs-launcher": "~0.1.4" + }, + "license": "MIT" }