Skip to content

Commit

Permalink
modernization of buildscripts
Browse files Browse the repository at this point in the history
upgrade to karma to 0.10
upgrade grunt-watch -> no need for 2 extra parallel
grunt command for karma and livereload
added incremental build for coffee scripts. only modified files are recompiled
Suppress depend on grunt-hustler in favor of equivalent single module (ngTemplateCache->html2js)
put requiregen task in its own grunt module
  • Loading branch information
Pierre Tardy committed Aug 10, 2013
1 parent c1b7e5b commit 88dee4c
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 341 deletions.
141 changes: 53 additions & 88 deletions www/Gruntfile.coffee
Expand Up @@ -2,6 +2,20 @@ path = require 'path'

# Build configurations.
module.exports = (grunt) ->
changedFiles = {}
firstPass = true
grunt.event.on "watch", (action, filepath) ->
firstPass = false
changedFiles[filepath] = action
# allows incremental build using watch
hasChanged = (filepath) ->
if firstPass
return true
if changedFiles.hasOwnProperty(filepath)
delete changedFiles[filepath]
return true
return false

grunt.initConfig
# Deletes buildbot_www and temp directories.
# The temp directory is used during the build process.
Expand All @@ -25,6 +39,7 @@ module.exports = (grunt) ->
dest: './.temp/'
expand: true
ext: '.js'
filter: hasChanged
]
testscripts:
files: [
Expand All @@ -33,6 +48,7 @@ module.exports = (grunt) ->
dest: './.temp/scripts/test/'
expand: true
ext: '.js'
filter: hasChanged
]
options:
sourceMap: true
Expand Down Expand Up @@ -65,15 +81,13 @@ module.exports = (grunt) ->
# if a module has been loaded in previous layers, it wont be loaded again
# so that you can use global regular expression in the end
'libs/jquery'
'libs/angular' # angular needs jquery before or will use internal jqlite
'libs/.*' # remaining libs before app
'test/libs/.*' # test libs in dev mode
'test/dataspec' # test mocks in dev mode
'test/mocks/.*' # test mocks in dev mode
'app' # app needs libs
'(routes|views|config)'
'[^/]*/[^/]*' # remaining angularjs components
'test/scenarios/.*' # test scenarios in dev mode
'libs/angular' # angular needs jquery before or will use internal jqlite
'libs/*' # remaining libs before app
'test/libs/*' # test libs in dev mode
'test/dataspec' # test mocks in dev mode
'test/mocks/*' # test mocks in dev mode
'app' # app needs libs
'{routes,views,config,*/**}' # remaining angularjs components
'run' # run has to be in the end, because it is triggering angular's own DI
]
dest: '.temp/scripts/main.js'
Expand Down Expand Up @@ -147,7 +161,7 @@ module.exports = (grunt) ->
dest: './buildbot_www/'
expand: true
,
'./buildbot_www/index.html': './.temp/index.min.html'
'./buildbot_www/index.html': './.temp/index.html'
,
'./buildbot_www/require.js': './src/scripts/libs/require.js'
]
Expand Down Expand Up @@ -202,35 +216,12 @@ module.exports = (grunt) ->
files:
'./.temp/styles/styles.css': './src/styles/styles.less'

# Minifiy index.html.
minifyHtml:
prod:
files:
'./.temp/index.min.html': './.temp/index.html'

# Gathers all views and creates a file to push views directly into the $templateCache
# This will produce a file with the following content.
#
# angular.module('app').run(['$templateCache', function ($templateCache) {
# $templateCache.put('/views/directives/tab.html', '<div class="tab-pane" ng-class="{active: selected}" ng-transclude></div>');
# $templateCache.put('/views/directives/tabs.html', '<div class="tabbable"> <ul class="nav nav-tabs"> <li ng-repeat="tab in tabs" ng-class="{active:tab.selected}"> <a href="http://localhost:3005/scripts/views.js" ng-click="select(tab)">{{tab.caption}}</a> </li> </ul> <div class="tab-content" ng-transclude></div> </div>');
# [...]
# }]);
#
# This file is then included in the output automatically. AngularJS will use it instead of going to the file system for the views, saving requests. Notice that the view content is actually minified. :)
ngTemplateCache:
html2js:
views:
files:
'./.temp/scripts/views.js': './.temp/views/**/*.html'
files: './.temp/scripts/views.js':'./.temp/views/**/*.html'
options:
trim: './.temp/'

# Restart server when server sources have changed, notify all browsers on change.
regarde:
buildbot_www:
files: './buildbot_www/**'
tasks: 'livereload'

base: './.temp/'
# RequireJS optimizer configuration for both scripts and styles.
# This configuration is only used in the 'prod' build.
# The optimizer will scan the main file, walk the dependency tree, and write the output in dependent sequence to a single file.
Expand Down Expand Up @@ -291,30 +282,29 @@ module.exports = (grunt) ->
timestamp: "<%= grunt.template.today() %>"
environment: 'prod'

# Runs unit tests using karma (formerly testacular)
# Runs unit tests using karma
karma:
options:
autoWatch: true
colors: true
configFile: './karma.conf.js'
keepalive: true
autoWatch: false
background: true
reporters: ['progress']
frameworks: ['jasmine', 'requirejs'],
files: [
'./buildbot_www/scripts/test/main.js'
{pattern: 'buildbot_www/scripts/**/*.js', included: false},
{pattern: 'buildbot_www/scripts/**/*.js.map', included: false},
]
singleRun: false
chrome:
options:
browsers: ['Chrome']
firefox:
options:
browsers: ['Firefox']
pjs:
dev:
options:
browsers: ['PhantomJS']
browsers: (grunt.option('browsers') or 'Chrome,Firefox,PhantomJS').split(",")
ci:
options:
background: false
autoWatch: false
colors: false
browsers: ['PhantomJS']
configFile: './karma.conf.js'
singleRun: true

# Sets up file watchers and runs tasks when watched files are changed.
Expand All @@ -326,20 +316,17 @@ module.exports = (grunt) ->
'copy:index'
]
scripts:
files: ['./src/scripts/**']
files: ['./src/scripts/**', './test/scripts/**']
tasks: [
'coffee:scripts'
'copy:js'
'copy:scripts'
'copy:src'
]
testscripts:
files: ['./test/scripts/**']
tasks: [
'coffee:testscripts'
'copy:js'
'copy:scripts'
'copy:src'
'karma:dev:run'
]
options:
spawn: false,
styles:
files: './src/styles/**/*.less'
tasks: [
Expand All @@ -352,6 +339,9 @@ module.exports = (grunt) ->
'jade:views'
'copy:views'
]
livereload:
files: './buildbot_www/**'
options: {livereload: true}

# Register grunt tasks supplied by grunt-contrib-*.
# Referenced in package.json.
Expand All @@ -368,20 +358,17 @@ module.exports = (grunt) ->
grunt.loadNpmTasks 'grunt-contrib-concat'


# Register grunt tasks supplied by grunt-hustler.
# Register grunt tasks supplied by grunt-html2js.
# Referenced in package.json.
# https://github.com/CaryLandholt/grunt-hustler
grunt.loadNpmTasks 'grunt-hustler'

# Recommended watcher for LiveReload
grunt.loadNpmTasks 'grunt-regarde'
# https://github.com/karlgoldstein/grunt-html2js
grunt.loadNpmTasks 'grunt-html2js'

# Register grunt tasks supplied by grunt-karma.
# Referenced in package.json.
# https://github.com/Dignifiedquire/grunt-karma
grunt.loadNpmTasks 'grunt-karma'
grunt.loadNpmTasks 'grunt-requiregen'

grunt.loadTasks 'tasks'

grunt.registerTask 'dataspec', ->
done = @async()
Expand All @@ -399,28 +386,6 @@ module.exports = (grunt) ->
'default'
'karma:ci'
]
# For developing, run the karma test suite in watch mode (in parallel with the dev mode ("grunt dev"))
# grunt chrometest
grunt.registerTask 'chrometest', [
'karma:chrome'
]
# grunt fftest
grunt.registerTask 'fftest', [
'karma:firefox'
]
# grunt pjstest
grunt.registerTask 'pjstest', [
'karma:pjs'
]

# Starts a reload server
# Enter the following command at the command line to execute this task:
# grunt reloadserver
# this must be done in parallel with "grunt dev"
grunt.registerTask 'reloadserver', [
'livereload-start'
'regarde'
]

# Compiles the app with non-optimized build settings and places the build artifacts in the buildbot_www directory.
# Enter the following command at the command line to execute this build task:
Expand All @@ -447,6 +412,7 @@ module.exports = (grunt) ->
# grunt dev
grunt.registerTask 'dev', [
'default'
'karma:dev'
'watch',
]

Expand All @@ -464,9 +430,8 @@ module.exports = (grunt) ->
'less'
'jade:views'
'imagemin'
'ngTemplateCache'
'html2js'
'requirejs'
'jade:prod'
'minifyHtml'
'copy:prod'
]
18 changes: 0 additions & 18 deletions www/karma.conf.js

This file was deleted.

0 comments on commit 88dee4c

Please sign in to comment.