From d93a66dc507f11114e00f1f21ae4bbb7ce75dd92 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Sun, 20 Oct 2013 08:50:28 +0200 Subject: [PATCH] Grunt - as proposed by Yeoman. Not yet fully working.. --- .gitignore | 2 + .jshintrc | 24 ++++ Gruntfile.js | 320 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 10 +- package.json | 32 ++++++ 5 files changed, 385 insertions(+), 3 deletions(-) create mode 100644 .jshintrc create mode 100644 Gruntfile.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index cd972ac4..5ecc2c4a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ npm-debug.log .idea/* */images/Thumbs.db **/.DS_Store +node_modules +*~ diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..40377ba2 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,24 @@ +{ + "node": true, + "browser": true, + "esnext": true, + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 2, + "latedef": true, + "newcap": true, + "noarg": true, + "quotmark": "single", + "regexp": true, + "undef": true, + "unused": true, + "strict": true, + "trailing": true, + "smarttabs": true, + "globals": { + "angular": false + } +} diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 00000000..8e5633fd --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,320 @@ +// Generated on 2013-10-20 using generator-angular 0.3.0 +'use strict'; +var LIVERELOAD_PORT = 35729; +var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT }); +var mountFolder = function (connect, dir) { + return connect.static(require('path').resolve(dir)); +}; + +// # Globbing +// for performance reasons we're only matching one level down: +// 'test/spec/{,*/}*.js' +// use this if you want to recursively match all subfolders: +// 'test/spec/**/*.js' + +module.exports = function (grunt) { + // load all grunt tasks + require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); + + // configurable paths + var yeomanConfig = { + app: 'app', + dist: 'dist' + }; + + try { + yeomanConfig.app = require('./bower.json').appPath || yeomanConfig.app; + } catch (e) {} + + grunt.initConfig({ + yeoman: yeomanConfig, + watch: { + coffee: { + files: ['<%= yeoman.app %>/scripts/{,*/}*.coffee'], + tasks: ['coffee:dist'] + }, + coffeeTest: { + files: ['test/spec/{,*/}*.coffee'], + tasks: ['coffee:test'] + }, + livereload: { + options: { + livereload: LIVERELOAD_PORT + }, + files: [ + '<%= yeoman.app %>/{,*/}*.html', + '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css', + '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js', + '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}' + ] + } + }, + connect: { + options: { + port: 9000, + // Change this to '0.0.0.0' to access the server from outside. + hostname: 'localhost' + }, + livereload: { + options: { + middleware: function (connect) { + return [ + lrSnippet, + mountFolder(connect, '.tmp'), + mountFolder(connect, yeomanConfig.app) + ]; + } + } + }, + test: { + options: { + middleware: function (connect) { + return [ + mountFolder(connect, '.tmp'), + mountFolder(connect, 'test') + ]; + } + } + }, + dist: { + options: { + middleware: function (connect) { + return [ + mountFolder(connect, yeomanConfig.dist) + ]; + } + } + } + }, + open: { + server: { + url: 'http://localhost:<%= connect.options.port %>' + } + }, + clean: { + dist: { + files: [{ + dot: true, + src: [ + '.tmp', + '<%= yeoman.dist %>/*', + '!<%= yeoman.dist %>/.git*' + ] + }] + }, + server: '.tmp' + }, + jshint: { + options: { + jshintrc: '.jshintrc' + }, + all: [ + 'Gruntfile.js', + '<%= yeoman.app %>/scripts/{,*/}*.js' + ] + }, + coffee: { + dist: { + files: [{ + expand: true, + cwd: '<%= yeoman.app %>/scripts', + src: '{,*/}*.coffee', + dest: '.tmp/scripts', + ext: '.js' + }] + }, + test: { + files: [{ + expand: true, + cwd: 'test/spec', + src: '{,*/}*.coffee', + dest: '.tmp/spec', + ext: '.js' + }] + } + }, + // not used since Uglify task does concat, + // but still available if needed + /*concat: { + dist: {} + },*/ + rev: { + dist: { + files: { + src: [ + '<%= yeoman.dist %>/scripts/{,*/}*.js', + '<%= yeoman.dist %>/styles/{,*/}*.css', + '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}', + '<%= yeoman.dist %>/styles/fonts/*' + ] + } + } + }, + useminPrepare: { + html: '<%= yeoman.app %>/index.html', + options: { + dest: '<%= yeoman.dist %>' + } + }, + usemin: { + html: ['<%= yeoman.dist %>/{,*/}*.html'], + css: ['<%= yeoman.dist %>/styles/{,*/}*.css'], + options: { + dirs: ['<%= yeoman.dist %>'] + } + }, + imagemin: { + dist: { + files: [{ + expand: true, + cwd: '<%= yeoman.app %>/images', + src: '{,*/}*.{png,jpg,jpeg}', + dest: '<%= yeoman.dist %>/images' + }] + } + }, + cssmin: { + // By default, your `index.html` will take care of + // minification. This option is pre-configured if you do not wish to use + // Usemin blocks. + // dist: { + // files: { + // '<%= yeoman.dist %>/styles/main.css': [ + // '.tmp/styles/{,*/}*.css', + // '<%= yeoman.app %>/styles/{,*/}*.css' + // ] + // } + // } + }, + htmlmin: { + dist: { + options: { + /*removeCommentsFromCDATA: true, + // https://github.com/yeoman/grunt-usemin/issues/44 + //collapseWhitespace: true, + collapseBooleanAttributes: true, + removeAttributeQuotes: true, + removeRedundantAttributes: true, + useShortDoctype: true, + removeEmptyAttributes: true, + removeOptionalTags: true*/ + }, + files: [{ + expand: true, + cwd: '<%= yeoman.app %>', + src: ['*.html', 'views/*.html'], + dest: '<%= yeoman.dist %>' + }] + } + }, + // Put files not handled in other tasks here + copy: { + dist: { + files: [{ + expand: true, + dot: true, + cwd: '<%= yeoman.app %>', + dest: '<%= yeoman.dist %>', + src: [ + '*.{ico,png,txt}', + '.htaccess', + 'bower_components/**/*', + 'images/{,*/}*.{gif,webp,svg}', + 'styles/fonts/*' + ] + }, { + expand: true, + cwd: '.tmp/images', + dest: '<%= yeoman.dist %>/images', + src: [ + 'generated/*' + ] + }] + } + }, + concurrent: { + server: [ + 'coffee:dist' + ], + test: [ + 'coffee' + ], + dist: [ + 'coffee', + 'imagemin', + 'htmlmin' + ] + }, + karma: { + unit: { + configFile: 'karma.conf.js', + singleRun: true + } + }, + cdnify: { + dist: { + html: ['<%= yeoman.dist %>/*.html'] + } + }, + ngmin: { + dist: { + files: [{ + expand: true, + cwd: '<%= yeoman.dist %>/scripts', + src: '*.js', + dest: '<%= yeoman.dist %>/scripts' + }] + } + }, + uglify: { + dist: { + files: { + '<%= yeoman.dist %>/scripts/scripts.js': [ + '<%= yeoman.dist %>/scripts/scripts.js' + ] + } + } + } + }); + + grunt.registerTask('server', function (target) { + if (target === 'dist') { + return grunt.task.run(['build', 'open', 'connect:dist:keepalive']); + } + + grunt.task.run([ + 'clean:server', + 'concurrent:server', + 'connect:livereload', + 'open', + 'watch' + ]); + }); + + grunt.registerTask('test', [ + 'clean:server', + 'concurrent:test', + 'connect:test', + 'karma' + ]); + + grunt.registerTask('build', [ + 'clean:dist', + 'useminPrepare', + 'concurrent:dist', + 'concat', + 'copy', + 'cdnify', + 'ngmin', + 'cssmin', + 'uglify', + 'rev', + 'usemin' + ]); + + grunt.registerTask('default', [ + 'jshint', + 'test', + 'build' + ]); +}; diff --git a/README.md b/README.md index 895ae107..8da80cc6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # prototype-app -Repository for putting prototype work from Thoughtworks HSP around building single page web app +Repository for putting prototype work from Thoughtworks HSP around building single page web app for Mifos X. ## Overview Video To get a good overview of the code layout, and recommendations going ahead on the Angular.js Prototype application, please watch this video recording of a session taken by Silvio from ThoughtWorks: @@ -18,16 +18,18 @@ To get a good overview of the code layout, and recommendations going ahead on th 2. Clone this respository to your local filesystem -3. To download the dependencies, first install bower: +3. To download the dependencies, and be able to build, first install bower & grunt: ``` npm install -g bower +npm install -g grunt-cli ``` -4. Next run a clean install on the project root folder: +4. Next pull the runtime and build time dependencies by running bower and npm install on the project root folder: ``` bower install +npm install ``` Done. @@ -45,6 +47,8 @@ bower search Just open test/SpecRunner.html in the browser. + + ## Background The Mifos project (http://www.mifos.org/about) was originally setup and guided by Grameen Foundation. It has been open source since inception but in recent years the community for open source microfinance (http://www.openmf.org) took over maintanance and future development of the Mifos project. diff --git a/package.json b/package.json new file mode 100644 index 00000000..b95985c3 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "yeomanagain", + "version": "0.0.0", + "dependencies": {}, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-contrib-copy": "~0.4.1", + "grunt-contrib-concat": "~0.3.0", + "grunt-contrib-coffee": "~0.7.0", + "grunt-contrib-uglify": "~0.2.0", + "grunt-contrib-compass": "~0.3.0", + "grunt-contrib-jshint": "~0.6.0", + "grunt-contrib-cssmin": "~0.6.0", + "grunt-contrib-connect": "~0.3.0", + "grunt-contrib-clean": "~0.4.1", + "grunt-contrib-htmlmin": "~0.1.3", + "grunt-contrib-imagemin": "~0.1.4", + "grunt-contrib-watch": "~0.4.0", + "grunt-usemin": "~0.1.11", + "grunt-rev": "~0.1.0", + "grunt-karma": "~0.4.3", + "grunt-open": "~0.2.0", + "grunt-concurrent": "~0.3.0", + "matchdep": "~0.1.2", + "connect-livereload": "~0.2.0", + "grunt-google-cdn": "~0.2.0", + "grunt-ngmin": "~0.0.2" + }, + "engines": { + "node": ">=0.8.0" + } +}