Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #507 from cbmi/cdn-gruntfile
Browse files Browse the repository at this point in the history
Add support for CDN build in Gruntfile
  • Loading branch information
naegelyd committed Apr 2, 2014
2 parents dc89c21 + db6cc1b commit 2cbaf54
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
local
build
dist
cdn
components
css/style.css
css/vocab/
Expand Down
103 changes: 74 additions & 29 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# concatentation
# - `dist` - Final output for release purposes. This carries over to the master
# branch to be copied in the root of the repo.
# - `cdn` - Final output for deployment on CDNs. This includes *only* Cilantro
# files, no source maps, and no third-party libraries.
#
# Each Grunt task has a target named `local` which performs copying,
# compiling or symlinking in the `local` directory for development.
Expand All @@ -27,6 +29,17 @@ module.exports = (grunt) ->
grunt.log.ok cmd
shell.exec cmd

vendorModules = [
'jquery'
'backbone'
'underscore'
'marionette'
'highcharts'
'bootstrap'
'json2'
'loglevel'
]

grunt.initConfig
pkg: pkg

Expand All @@ -35,6 +48,7 @@ module.exports = (grunt) ->
localDir: 'local'
buildDir: 'build'
distDir: 'dist'
cdnDir: 'cdn'

serve:
forever:
Expand All @@ -48,7 +62,7 @@ module.exports = (grunt) ->

watch:
grunt:
tasks: ['jasmine:local:build']
tasks: ['local']
files: ['Gruntfile.coffee']

coffee:
Expand All @@ -66,30 +80,27 @@ module.exports = (grunt) ->

tests:
tasks: ['jasmine:local:build']
files: ['<%= specDir %>/**/*']
files: ['<%= specDir %>/**/**/**/*']

sass:
tasks: ['sass:local']
files: ['<%= srcDir %>/scss/**/*']
files: ['<%= srcDir %>/scss/**/**/**/*']


coffee:
options:
bare: true

# Output to 'local' for development
local:
options:
sourceMap: true

expand: true
cwd: '<%= srcDir %>/coffee'
dest: '<%= localDir %>/js'
src: '**/*.coffee'
rename: (dest, src) ->
dest + '/' + src.replace('.coffee', '.js')

# Compiles files to the 'build' directory for distribution
build:
expand: true
cwd: '<%= srcDir %>/coffee'
Expand All @@ -100,10 +111,13 @@ module.exports = (grunt) ->


sass:
options:
sourcemap: true

local:
options:
trace: true
sourcemap: true
style: 'expanded'

files:
'<%= localDir %>/css/style.css': '<%= srcDir %>/scss/style.scss'
Expand All @@ -116,6 +130,14 @@ module.exports = (grunt) ->
files:
'<%= distDir %>/css/style.css': '<%= srcDir %>/scss/style.scss'

cdn:
options:
quiet: true
sourcemap: false
style: 'compressed'

files:
'<%= cdnDir %>/css/style.css': '<%= srcDir %>/scss/style.scss'

copy:
local:
Expand Down Expand Up @@ -180,6 +202,13 @@ module.exports = (grunt) ->
dest: '<%= distDir %>'
]

cdn:
files: [
expand: true
cwd: '<%= srcDir %>/img'
src: ['checkmark.png']
dest: '<%= cdnDir %>/img'
]

symlink:
options:
Expand All @@ -196,27 +225,16 @@ module.exports = (grunt) ->
baseUrl: '.'
inlineText: true
preserveLicenseComments: false
generateSourceMaps: true
wrap: false
logLevel: 1
throwWhen:
optimize: true

modules: [
name: pkg.name
exclude: [
'jquery'
'backbone'
'underscore'
'marionette'
'highcharts'
'bootstrap'
'json2'
'loglevel'
]
exclude: vendorModules
]

# Post analysis of built files
done: (done, output) ->
dups = require('rjs-build-analysis').duplicates(output)
if dups.length > 0
Expand All @@ -227,24 +245,39 @@ module.exports = (grunt) ->

dist:
options:
appDir: 'build/js'
dir: 'dist/js'
appDir: '<%= buildDir %>/js'
dir: '<%= distDir %>/js'
optimize: 'uglify2'
removeCombined: true
generateSourceMaps: true
removeCombined: false

cdn:
options:
appDir: '<%= buildDir %>/js'
dir: '<%= cdnDir %>/js'
optimize: 'uglify2'
generateSourceMaps: false
removeCombined: true

clean:
local: ['local']
build: ['build']
dist: ['dist']
local: ['<%= localDir %>']
build: ['<%= buildDir %>']
dist: ['<%= distDir %>']
cdn: ['<%= cdnDir %>']
postdist: [
'<%= distDir %>/js/templates'
]

postcdn: [
'<%= cdnDir %>/js/templates'
'<%= cdnDir %>/js/require.js'
].concat(vendorModules.map (mod) ->
'<%= cdnDir %>/js/' + mod + '.js')

release: [
'<%= localDir %>/js/build.txt'
'<%= localDir %>/js/**/**/**/**/*.map'
'<%= localDir %>/css/**/*.map'
'<%= distDir %>/js/build.txt'
'<%= cdnDir %>/js/build.txt'
]


Expand Down Expand Up @@ -311,7 +344,6 @@ module.exports = (grunt) ->
'<%= srcDir %>/js/json2.js'
'<%= srcDir %>/js/loglevel.js'
'<%= srcDir %>/js/marionette.js'
'<%= srcDir %>/js/modernizr.js'
'<%= srcDir %>/js/require.js'
'<%= srcDir %>/js/text.js'
'<%= srcDir %>/js/tpl.js'
Expand Down Expand Up @@ -440,12 +472,23 @@ module.exports = (grunt) ->
'clean:postdist'
]

grunt.registerTask 'cdn', 'Creates a build for CDN distribution', [
'clean:build'
'coffee:build'
'copy:build'
'clean:cdn'
'requirejs:cdn'
'sass:cdn'
'copy:cdn'
'clean:postcdn'
]

grunt.registerTask 'work', 'Performs the initial local build and starts a watch process', [
'local'
'watch'
]

grunt.registerTask 'test', 'Compiles local CoffeeScript files and uses Jasmine', [
grunt.registerTask 'test', 'Runs the headless test suite', [
'coffee:local'
'copy:local'
'symlink'
Expand Down Expand Up @@ -541,11 +584,13 @@ module.exports = (grunt) ->
grunt.registerTask 'release-help', 'Prints the post-release steps', ->
grunt.log.ok 'Push the code and tags: git push && git push --tags'
grunt.log.ok "Go to #{ pkg.homepage }/releases to update the release descriptions and upload the binaries"
grunt.log.ok 'The CDN-ready files have been updated'

grunt.registerTask 'release', 'Builds the distribution files, creates the release binaries, and creates a Git tag', [
'bump-final'
'local'
'dist'
'cdn'
'clean:release'
'release-binaries'
'tag-release'
Expand Down
4 changes: 0 additions & 4 deletions src/js/modernizr.js

This file was deleted.

0 comments on commit 2cbaf54

Please sign in to comment.