forked from appleboy/html5-template-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
258 lines (252 loc) · 9.6 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
module.exports = (grunt) ->
# build time
filetime = Date.now();
# Project configuration
project_config =
app: 'app'
output: 'output'
grunt.initConfig
pkg: project_config
shell:
bower:
command: 'node node_modules/.bin/bower install'
options:
stdout: true
stderr: true
callback: (err, stdout, stderr, cb) ->
console.log('Install bower package compeletely.')
cb()
build:
command: 'node node_modules/requirejs/bin/r.js -o build/self.build.js'
options:
stdout: true
stderr: true
release:
command: 'node node_modules/requirejs/bin/r.js -o build/app.build.js'
options:
stdout: true
stderr: true
test:
command: './node_modules/.bin/mocha --reporter spec test/test.js'
options:
stdout: true
stderr: true
bower:
install:
options:
cleanup: false
install: true
verbose: true
copy: false
cleanup:
options:
cleanup: true
verbose: true
install: false
copy: false
requirejs:
build:
options:
baseUrl: '<%= pkg.app %>/assets/js/'
name: 'main'
out: '<%= pkg.app %>/assets/js/main-built.js'
mainConfigFile: '<%= pkg.app %>/assets/js/main.js'
preserveLicenseComments: false
paths:
jquery: '../vendor/jquery/jquery'
release:
options:
###
support generate Source Maps, make sure requirejs version in 2.1.2
optimize: 'uglify2'
generateSourceMaps: true
###
appDir: "<%= pkg.app %>/"
baseUrl: "assets/js/"
dir: "<%= pkg.output %>"
name: "main"
mainConfigFile: '<%= pkg.app %>/assets/js/main.js'
preserveLicenseComments: false
fileExclusionRegExp: /^(\.|node_modules)/
paths:
jquery: '../vendor/jquery/jquery'
livereload:
port: 35729
express:
dev:
options:
script: 'build/server.js'
connect:
livereload:
options:
hostname: '0.0.0.0'
port: 4000
base: '.'
regarde:
html:
files: ['<%= pkg.app %>/**/*.{html,htm}']
tasks: ['livereload']
events: true
scss:
files: ['<%= pkg.app %>/**/*.scss'],
tasks: ['compass:dev']
events: true
css:
files: ['<%= pkg.app %>/**/*.css'],
tasks: ['livereload']
events: true
js:
files: '<%= pkg.app %>/**/*.js',
tasks: ['livereload']
events: true
coffee:
files: '**/*.coffee',
tasks: ['coffee']
events: true
compass:
dev:
options:
###
Load config from config.rb file
basePath: '<%= pkg.app %>/assets'
config: 'config.rb'
###
sassDir: '<%= pkg.app %>/assets/sass'
cssDir: '<%= pkg.app %>/assets/css'
imagesDir: '<%= pkg.app %>/assets/images'
javascriptsDir: '<%= pkg.app %>/assets/js'
outputStyle: 'nested'
relativeAssets: true
noLineComments: true
environment: 'development'
release:
options:
force: true
sassDir: '<%= pkg.output %>/assets/sass'
cssDir: '<%= pkg.output %>/assets/css'
imagesDir: '<%= pkg.output %>/assets/images'
javascriptsDir: '<%= pkg.output %>/assets/js'
outputStyle: 'compressed'
relativeAssets: true
noLineComments: true
environment: 'production'
cssmin:
release:
report: 'gzip'
expand: true
cwd: '<%= pkg.output %>/assets/css'
src: ['*.css']
dest: '<%= pkg.output %>/assets/css'
coffee:
dev:
expand: true,
cwd: '<%= pkg.app %>/assets/coffeescript/',
src: ['**/*.coffee'],
dest: '<%= pkg.app %>/assets/js/',
ext: '.js'
options:
bare: true
test:
files:
'test/test.js': 'test/test.coffee'
server:
files:
'build/server.js': 'build/server.coffee'
options:
bare: true
grunt:
files:
'Gruntfile.js': 'Gruntfile.coffee'
options:
bare: true
clean:
options:
force: true
js: '<%= pkg.output %>/assets/js'
release: [
'<%= pkg.output %>/build.txt'
'<%= pkg.output %>/assets/coffeescript'
'<%= pkg.output %>/assets/sass'
'<%= pkg.output %>/assets/vendor'
'<%= pkg.output %>/.sass-cache'
]
cleanup: [
'<%= pkg.output %>'
'<%= pkg.app %>/assets/vendor'
'<%= pkg.app %>/assets/js/main-built.js'
'<%= pkg.app %>/assets/js/main-built.js.map'
'<%= pkg.app %>/assets/js/main-built.js.src'
'node_modules'
'.sass-cache'
]
copy:
release:
files: [
{src: '<%= pkg.app %>/.htaccess', dest: '<%= pkg.output %>/.htaccess'}
{src: '<%= pkg.output %>/assets/vendor/requirejs/require.js', dest: '<%= pkg.output %>/assets/js/require.js'}
{src: '<%= pkg.app %>/assets/js/main-built.js', dest: '<%= pkg.output %>/assets/js/' + filetime + '.js'}
]
replace:
release:
src: '<%= pkg.output %>/index.html'
dest: '<%= pkg.output %>/index.html'
replacements: [
{
from: 'js/main'
to: 'js/' + filetime
},
{
from: 'vendor/requirejs/'
to: 'js/'
}
]
htmlmin:
options:
removeComments: true
collapseWhitespace: true
dev:
files:
'<%= pkg.app %>/index.html': '<%= pkg.app %>/index.html'
release:
files:
'<%= pkg.output %>/index.html': '<%= pkg.app %>/index.html'
mocha_phantomjs:
all: 'test/**/*.html'
grunt.event.on 'watch', (action, filepath) ->
grunt.log.writeln filepath + ' has ' + action
grunt.event.on 'regarde:file', (status, name, filepath, tasks, spawn) ->
grunt.log.writeln 'File ' + filepath + ' ' + status + '. Tasks: ' + tasks
grunt.registerTask 'init', () ->
grunt.log.writeln 'Initial project'
(grunt.file.exists project_config.app + '/assets/vendor') || grunt.task.run 'bower:install'
grunt.registerTask 'release', () ->
grunt.log.writeln 'deploy project'
(grunt.file.exists project_config.app + '/assets/vendor') || grunt.task.run 'bower:install'
grunt.task.run ['requirejs:build', 'requirejs:release', 'cssmin:release', 'clean:js']
grunt.file.mkdir project_config.output + '/assets/js'
grunt.task.run 'copy:release'
grunt.task.run 'htmlmin:release'
grunt.task.run 'replace:release'
grunt.task.run 'clean:release'
# run local server by grunt-contrib-connect plugin
grunt.registerTask 'default', ['init', 'livereload-start', 'connect', 'regarde']
# run local express server.
#grunt.registerTask 'default', ['init', 'express:dev', 'livereload-start', 'regarde']
grunt.registerTask 'cleanup', ['clean:cleanup']
grunt.registerTask 'test', ['release', 'shell:test', 'mocha_phantomjs']
# Dependencies
grunt.loadNpmTasks 'grunt-shell'
grunt.loadNpmTasks 'grunt-regarde'
grunt.loadNpmTasks 'grunt-contrib-connect'
grunt.loadNpmTasks 'grunt-contrib-livereload'
grunt.loadNpmTasks 'grunt-contrib-compass'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-copy'
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-text-replace'
grunt.loadNpmTasks 'grunt-contrib-htmlmin'
grunt.loadNpmTasks 'grunt-requirejs'
grunt.loadNpmTasks 'grunt-bower-task'
grunt.loadNpmTasks 'grunt-contrib-cssmin'
grunt.loadNpmTasks 'grunt-express-server'
grunt.loadNpmTasks 'grunt-mocha-phantomjs'