-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgruntfile.coffee
More file actions
169 lines (146 loc) · 5 KB
/
gruntfile.coffee
File metadata and controls
169 lines (146 loc) · 5 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# ---------------------------------
# IMPORTS
# ---------------------------------
globals = require './grunt/globals'
utils = require './grunt/utils'
# helper methods
# converts an array of EVEN length to a hash/key object.
# useful for the sass compile as <% %> coffee syntax is out of scope when executed inside Gruntfile.coffee
helpers =
arrayToHash: (array)->
i = 0
hash = {}
while i < array.length
hash[ array[i] ] = array[i+1]
i+=2
hash
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON("package.json")
banners:
credits: "/**\n * method7 <%= pkg.name %>-<%= pkg.version %> <%= grunt.template.today('dd/mm/yyyy') %>\n * @author: <%= pkg.authors %>\n **/\n"
# watch for changes in files
watch:
files: [
'gruntfile.coffee'
'grunt/*.coffee'
'source/json/*'
'source/templates/*.html'
'source/coffee/*.coffee'
'source/coffee/**/*.coffee'
'source/js/*.js'
'source/**/*.scss'
'source/sass/default.scss'
]
tasks: ['devtasks']
# percolator compile coffee files.
percolator:
app:
source: 'source/coffee'
output: 'deploy/static/js/app.js'
main: 'app.coffee' # use app.coffee to extend applocation
compile: true
helper:
source: 'source/coffee'
output: 'deploy/static/js/helpers.js'
main: 'helpers.coffee' # use helpers.coffee to store handlebars helper methods and jQuery functions
compile: true
# compile handlebars templates - http://danburzo.ro/grunt/chapters/handlebars/
handlebars:
options:
namespace: '<%= pkg.name %>.templates'
processName: (filePath) ->
return filePath.replace(/^source\/templates\//, '').replace(/\.html$/, '')
all:
files:
"deploy/static/js/templates.js": ["source/templates/**/*.html"]
# compile sass
sass:
dist:
options:
noCache: true
files:
'deploy/static/css/style.css': 'source/scss/default.scss'
# concat vendors
#concat:
#vendors:
#src: ['source/vendors/*.js'],
#dest: 'deploy/static/js/vendors.js'
# concat vendors
concat:
vendors:
files: helpers.arrayToHash [
# output path
"deploy/static/js/vendors.js",[
# vendor files
"source/vendors/jquery-1.11.0.min.js"
"source/vendors/underscore-min.js"
"source/vendors/backbone.min.js"
"source/vendors/handlebars.runtime-v1.3.0.js"
"source/vendors/modernizr-v2.7.1.js"
"source/vendors/bootstrap/affix.js"
"source/vendors/bootstrap/alert.js"
"source/vendors/bootstrap/button.js"
"source/vendors/bootstrap/carousel.js"
"source/vendors/bootstrap/collapse.js"
"source/vendors/bootstrap/dropdown.js"
"source/vendors/bootstrap/tab.js"
"source/vendors/bootstrap/transition.js"
"source/vendors/bootstrap/scrollspy.js"
"source/vendors/bootstrap/modal.js"
"source/vendors/bootstrap/tooltip.js"
"source/vendors/bootstrap/popover.js"
] ]
# minify css
cssmin:
add_banner:
options:
banner: "<%= banners.credits %>"
files: [
"deploy/static/css/style.min.css": "deploy/static/css/style.css"]
# uglify javascript
uglify:
options:
banner: "<%= banners.credits %>"
mangle: true
my_target:
files: [
'deploy/static/js/app.min.js': ['deploy/static/js/app.js'],
'deploy/static/js/vendors.min.js': ['deploy/static/js/vendors.js']
]
# copy files
copy:
main:
expand: true
cwd: 'source/json/'
src: '**'
dest: 'deploy/static/json/'
flatten: false
filter: 'isFile'
# clean files
clean: ["deploy/static/json"]
# list of grunt tasks to run on dev or deploy
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-contrib-sass'
grunt.loadNpmTasks 'grunt-contrib-concat'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-contrib-cssmin'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-coffee-percolator'
grunt.loadNpmTasks 'grunt-contrib-handlebars'
grunt.loadNpmTasks 'grunt-contrib-copy'
grunt.loadNpmTasks 'grunt-contrib-clean'
# develop the site
grunt.registerTask 'default', =>
grunt.task.run 'version-output'
grunt.task.run 'devtasks'
grunt.task.run 'watch'
# deploy the site
grunt.registerTask 'deploy', =>
grunt.task.run 'deploytasks'
grunt.registerTask 'version-output', ()->
utils.generateVersioningOutput @async()
null
# Tasks
grunt.registerTask 'devtasks',[ 'clean','concat:vendors', 'copy', 'handlebars', 'percolator', 'sass']
grunt.registerTask 'deploytasks', ['version-output', 'concat:vendors', 'percolator', 'sass', 'concat:vendors', 'uglify', 'cssmin']