-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGruntfile.coffee
127 lines (108 loc) · 3.59 KB
/
Gruntfile.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
module.exports = ( grunt ) ->
path = require( 'path' )
grunt.initConfig
pkg: grunt.file.readJSON( 'package.json' )
# Watch files and run the appropriate task on that file when it is
# changed.
watch:
components:
files: [ 'frontend/components/**/*.js' ]
tasks: [ 'copy:components', 'coffee:requirejs', 'requirejs' ]
scripts:
files: [ 'frontend/coffeescript/**/*.coffee' ]
tasks: [ 'copy:components', 'coffee:requirejs', 'requirejs' ]
styles:
files: [ 'frontend/sass/**/*.scss' ]
tasks: [ 'sass:dev' ]
images:
files: [ 'frontend/img/**/*' ]
tasks: [ 'copy:img' ]
# Copy the appropriate bower components to our <vendor> folder
bower:
install:
options:
targetDir: '<%= pkg.static_dir %>'
layout: (type, component) ->
switch type
when 'js' then 'js/vendor'
when 'css' then 'css'
when 'font' then 'fonts'
else type
# Compile all javascript and place into our intermediary folder for
# RequireJS optimization
coffee:
requirejs:
options:
bare: true
expand: true
cwd: 'frontend/coffeescript'
src: [ '**/*.coffee' ]
dest: 'build/js'
ext: '.js'
sass:
dev:
files:
'<%= pkg.static_dir %>/css/layout.css': 'frontend/sass/layout.scss'
prod:
options:
outputStyle: 'compressed'
files:
'<%= pkg.static_dir %>/css/layout.css': 'frontend/sass/layout.scss'
copy:
css:
expand: true
cwd: 'frontend/css'
src: [ '**/*' ]
dest: '<%= pkg.static_dir %>/css'
# Javascript components specifically go into an intermediary folder
# due to a two-stage build-process with Require-JS
components:
expand: true
cwd: 'frontend/components'
src: [ '**/*.js' ]
dest: 'build/js/vendor'
img:
expand: true
cwd: 'frontend/img'
src: [ '**/*.png', '**/*.jpg' ]
dest: '<%= pkg.static_dir %>/img'
requirejs:
compile:
options:
appDir: 'build'
mainConfigFile: 'build/js/common.js'
dir: '<%= pkg.static_dir %>'
keepBuildDir: true
optimize: if grunt.option('target') and grunt.option('target') is 'prod' then 'uglify' else 'none'
optimizeCss: 'none'
modules: [ {
name: '../common'
include: [ 'jquery',
'app/dashboard/main',
'app/dashboard/views',
'app/viz/main',
'app/viz/views',
'app/webform/main',
'app/webform/views' ]
}]
grunt.loadNpmTasks( 'grunt-bower-task' )
grunt.loadNpmTasks( 'grunt-contrib-watch' )
grunt.loadNpmTasks( 'grunt-contrib-requirejs' )
grunt.loadNpmTasks( 'grunt-contrib-coffee' )
grunt.loadNpmTasks( 'grunt-sass' )
grunt.loadNpmTasks( 'grunt-contrib-copy' )
grunt.registerTask( 'default', [ 'watch' ] )
# Run through Javascript/CSS compilation process,
# add --target=prod to minify Javascript assets.
grunt.registerTask( 'build', [
'bower',
'copy:components',
'coffee:requirejs',
'requirejs',
# Compile SCSS
'sass:dev',
# Finally copy oher basic components over to
# <static> folder
'copy:components',
'copy:css',
'copy:img' ] )