forked from ichord/angular-coffee-AMD-seed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
229 lines (200 loc) · 6.55 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
"use strict"
lrSnippet = require("grunt-contrib-livereload/lib/utils").livereloadSnippet
mountFolder = (connect, dir) ->
connect.static require("path").resolve(dir)
module.exports = (grunt) ->
# load all grunt tasks
require("matchdep").filterDev("grunt-*").forEach grunt.loadNpmTasks
# configurable paths
yeomanConfig =
app: "app"
vendor: "app/vendor"
build: "build"
dist: "dist"
try
yeomanConfig.src = require("./bower.json").appPath or yeomanConfig.src
grunt.initConfig
yo: yeomanConfig
watch:
options:
livereload: true
nospawn: true
coffee:
files: ["<%= yo.app %>/scripts/**/{,*/}*.coffee"]
tasks: ["coffee:build"]
options:
events: ['changed', 'added']
coffeeTest:
files: ["test/spec/{,*/}*.coffee"]
tasks: ["coffee:test", "karma:unit:run"]
compass:
files: ["<%= yo.app %>/styles/{,*/}*.{scss,sass}"]
tasks: ["compass"]
statics:
files: ["<%= yo.app %>/{,*/}*.html", "<%= yo.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: (connect) ->
[lrSnippet, mountFolder(connect, yeomanConfig.build), mountFolder(connect, yeomanConfig.app)]
production:
options:
middleware: (connect) ->
[mountFolder(connect, yeomanConfig.dist)]
open:
server:
url: "http://<%= connect.options.hostname %>:<%= connect.options.port %>"
clean:
dist: "<%= yo.dist %>"
build: "<%= yo.build %>"
coffee:
# options:
# sourceMap: yes
# sourceRoot: './'
build:
expand: true
cwd: "<%= yo.app %>/scripts"
src: "**/{,*/}*.coffee"
dest: "<%= yo.build %>/scripts"
ext: ".js"
test:
expand: true
cwd: "test"
src: "**/{,*/}*.coffee"
dest: "<%= yo.build %>"
ext: ".js"
compass:
options:
sassDir: "<%= yo.app %>/styles"
cssDir: "<%= yo.build %>/styles"
# imagesDir: "<%= yo.app %>/images"
# javascriptsDir: "<%= yo.app %>/scripts"
# fontsDir: "<%= yo.app %>/styles/fonts"
# importPath: "<%= yo.vendor %>/foundation/scss"
relativeAssets: true
dev:
options:
debugInfo: true
imagemin:
dist:
files: [
expand: true
cwd: "<%= yo.app %>/images"
src: "{,*/}*.{png,jpg,jpeg}"
dest: "<%= yo.dist %>/images"
]
cssmin:
dist:
files:
"<%= yo.dist %>/styles/main.css": [
"<%= yo.build %>/styles/{,*/}*.css",
"<%= yo.app %>/styles/{,*/}*.css"
]
htmlmin:
dist:
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: "<%= yo.app %>"
src: ["*.html", "views/**/*.html"]
dest: "<%= yo.dist %>"
]
ngmin:
dist:
files: [
expand: true,
src: ["<%= yo.build %>/scripts/**/*.js"]
]
requirejs:
compile:
options:
name: "main"
baseUrl: "<%= yo.build %>/scripts"
mainConfigFile: "<%= yo.build %>/scripts/main.js"
out: "<%= yo.dist %>/scripts/main.js"
useminPrepare:
html: "<%= yo.build %>/index.html"
dest: "<%= yo.dist %>"
usemin:
html: ["<%= yo.dist %>/{,*/}*.html"]
css: ["<%= yo.dist %>/styles/{,*/}*.{/}*.css"]
rev:
dist:
files:
src: [
"<%= yo.dist %>/scripts/{,*/}*.js"
"<%= yo.dist %>/styles/{,*/}*.css"
"<%= yo.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}"
"<%= yo.dist %>/styles/fonts/*"
]
copy:
build:
files: [
expand: true, dot: false, cwd: "<%= yo.app %>", dest: "<%= yo.build %>",
src: [
"index.html", "vendor/pure/**/*.css",
"vendor/*/*.js", "vendor/json3/lib/*.js",
"!vendor/**/*.min.js", "!vendor/**/Gruntfile.js"
]
]
test:
files: [
expand: true, dot: false, cwd: "<%= yo.app %>", dest: "<%= yo.build %>",
src: [
"vendor/*/*.js", "vendor/json3/lib/*.js",
"!vendor/**/*.min.js", "!vendor/**/Gruntfile.js",
]
]
dist:
files: [
expand: true, dot: false, cwd: "<%= yo.app %>", dest: "<%= yo.dist %>",
src: ["*.{ico,txt}", "images/{,*/}*.{gif,webp}", "styles/fonts/*", "vendor/requirejs/require.js"]
]
karma:
options:
basePath: "<%= yo.build %>"
configFile: "karma.conf.js"
unit:
background: true
browsers: ['Chrome']
ci:
singleRun: true
browsers: ["PhantomJS"]
# just recreate changed coffee file
changedFiles = Object.create(null);
onChange = grunt.util._.debounce(->
grunt.config 'coffee.build.src', Object.keys(changedFiles)
changedFiles = Object.create(null);
, 200);
grunt.event.on 'watch', (action, filepath, target) ->
if grunt.file.isMatch grunt.config('watch.coffee.files'), filepath
filepath = filepath.replace( grunt.config('coffee.build.cwd')+'/', '' );
changedFiles[filepath] = action;
onChange();
# compile coffeescript, scss
grunt.registerTask "compile", ["coffee", "compass"]
# build all stuff for development and ready for production
grunt.registerTask "build", ["clean:build", "compile"]
# build production stuff
grunt.registerTask "min", ["useminPrepare", "imagemin", "concat", "cssmin", "htmlmin", "ngmin", "requirejs", "rev", "usemin"]
# for travis, CI testing
grunt.registerTask "ci", ["build", "copy:test", "karma:ci"]
# run testing while there is any things be changed
grunt.registerTask "autotest", ["karma:unit", "watch"]
# setup development env, autocompile, livereload and open the browers.
grunt.registerTask "dev", ["build", "connect:livereload", "open", "watch"]
# simulate production env.
grunt.registerTask "dist", ["clean:dist", "build", "copy:build", "min", "copy:dist", "connect:production", "open", "watch"]
grunt.registerTask "default", ["dev"]