-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGruntfile.js
More file actions
346 lines (326 loc) · 9.29 KB
/
Copy pathGruntfile.js
File metadata and controls
346 lines (326 loc) · 9.29 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
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/* global module */
module.exports = function(grunt) {
var sourceFolder = 'src';
var developmentFolder = 'dev';
var buildFolder = 'dist';
// middleware for grunt.connect
var middleware = function(connect, options, middlewares) {
// inject a custom middleware into the array of default middlewares for proxy page
var proxypage = require('proxypage');
var proxyRe = /\/proxy\/proxy.ashx/i;
var proxyMiddleware = function(req, res, next) {
if (!proxyRe.test(req.url)) {
return next();
}
proxypage.proxy(req, res);
};
middlewares.unshift(proxyMiddleware);
middlewares.unshift(connect.json()); //body parser, see https://github.com/senchalabs/connect/wiki/Connect-3.0
middlewares.unshift(connect.urlencoded()); //body parser
return middlewares;
};
// Configure Tasks
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
tag: {
banner: '/*\n' +
' * <%= pkg.name %>\n' +
' * @version <%= pkg.version %>\n' +
' * @author <%= pkg.author %>\n' +
' * @repo: <%= pkg.repository %>\n' +
' * built: <%= grunt.template.today("yyyy-mm-dd") %>\n' +
' */'
},
clean: {
build: {
src: [buildFolder]
},
dev: {
src: [
developmentFolder + '/*.html',
developmentFolder + '/css',
developmentFolder + '/images',
developmentFolder + '/js/*',
'!' + developmentFolder + '/js/libs/**'
]
}
},
copy: {
build: {
cwd: sourceFolder,
dest: buildFolder,
expand: true,
src: ['**', '!**/*.styl', '!**/*.md']
},
dev: {
cwd: sourceFolder + '/stylus',
dest: sourceFolder + '/css',
expand: true,
src: ['**', '!**/*.styl', '!**/*.md']
}
},
cssmin: {
build: {
cwd: buildFolder,
dest: buildFolder,
expand: true,
src: ['**/*.css'],
options: {
banner: '<%= tag.banner %>'
}
}
},
htmlmin: {
build: {
files: [{
cwd: sourceFolder,
dest: buildFolder,
expand: true,
src: ['**/*.html']
}],
options: {
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeComments: true
}
}
},
jshint: {
build: {
dest: buildFolder,
src: [sourceFolder + '/**/*.js'],
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
}
},
dev: {
dest: developmentFolder,
expand: true,
src: [sourceFolder + '/**/*.js'],
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
}
}
},
stylus: {
build: {
files: [{
cwd: sourceFolder + '/stylus',
dest: buildFolder + '/css',
expand: true,
ext: '.css',
src: ['**/*.styl', '!**/mixins.styl', '!**/variables.styl']
}],
options: {
compress: false,
linenos: false
}
},
dev: {
files: [{
cwd: sourceFolder + '/stylus',
dest: sourceFolder + '/css',
expand: true,
ext: '.css',
src: ['**/*.styl', '!**/mixins.styl', '!**/variables.styl']
}],
options: {
compress: false,
linenos: false
}
},
dev_widgets: {
files: [{
cwd: sourceFolder + '/js',
dest: sourceFolder + '/js',
expand: true,
ext: '.css',
src: ['**/*.styl', '!**/mixins.styl', '!**/variables.styl']
}],
options: {
compress: false,
linenos: false
}
}
},
uglify: {
build: {
files: [{
cwd: sourceFolder,
dest: buildFolder,
expand: true,
ext: '.js',
src: ['**/*.js']
}],
options: {
banner: '<%= tag.banner %>\n',
compress: {
drop_console: true
},
preserveComments: false
}
}
},
watch: {
// 'dev-assets': {
// files: [sourceFolder + '/**', '!' + sourceFolder + '/**/*.styl'],
// tasks: ['dev-assets']
// },
// 'dev-scripts': {
// files: [sourceFolder + '/**/*.js'],
// tasks: ['dev-scripts']
// },
'dev-stylesheets': {
files: [sourceFolder + '/**/*.styl'],
tasks: ['dev-stylesheets']
},
stylusVarsChanged: {
files: [sourceFolder + 'stylus/variables.style', sourceFolder + 'stylus/mixins.style'],
tasks: ['stylus:dev']
}
},
exec: {
bower: {
cwd: '.',
command: 'bower install',
stdout: true,
stderr: true
}
},
'bower-install-simple': {
options: {
color: true,
directory: 'src/js'
},
prod: {
options: {
production: true
}
},
dev: {
options: {
production: false
}
}
},
esri_slurp: {
options: {
version: '3.12'
},
dev: {
options: {
beautify: true
},
dest: 'src/js/esri'
},
travis: {
dest: 'src/js/esri'
}
},
connect: {
dev: {
options: {
port: 3000,
base: sourceFolder,
hostname: '*',
middleware: middleware
}
},
build: {
options: {
port: 3001,
base: buildFolder,
hostname: '*',
middleware: middleware
}
}
},
open: {
dev_browser: {
path: 'http://localhost:3000/index.html'
},
build_browser: {
path: 'http://localhost:3001/index.html'
}
},
compress: {
build: {
options: {
archive: 'dist/viewer.zip'
},
files: [{
expand: true,
cwd: 'dist/viewer',
src: ['**']
}]
}
},
intern: {
dev: {
options: {
runType: 'runner', // defaults to 'client'
config: 'tests/intern',
reporters: ['console'],
suites: ['tests/unit/example']
}
}
},
dojo: {
prod: {
options: {
// You can also specify options to be used in all your tasks
profiles: ['profiles/build.profile.js'] // Profile for build
}
},
stage: {
options: {
// You can also specify options to be used in all your tasks
profiles: ['profiles/stage.build.profile.js', 'profiles/build.profile.js'] // Profile for build
}
},
options: {
// You can also specify options to be used in all your tasks
dojo: 'src/js/dojo/dojo.js', // Path to dojo.js file in dojo source
load: 'build', // Optional: Utility to bootstrap (Default: 'build')
releaseDir: '../dist/js',
require: './src/js/core/bootstrap.js', // Optional: Module to require for the build (Default: nothing)
basePath: './src'
}
}
});
// Load Tasks
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-stylus');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-newer');
//grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-esri-slurp');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('intern');
grunt.loadNpmTasks('grunt-bower-install-simple');
grunt.loadNpmTasks('grunt-dojo');
// Development Tasks
grunt.registerTask('dev-assets', 'Copies the assets', ['newer:copy:dev']);
grunt.registerTask('dev-scripts', 'Lints the JavaScript files.', ['newer:jshint:dev']);
grunt.registerTask('dev-stylesheets', 'Creates the stylesheets.', ['newer:stylus:dev' /*, 'newer:autoprefixer:dev'*/ ]);
// Production Build Tasks
grunt.registerTask('assets', 'Copies and compiles the assets.', ['copy:build', 'htmlmin']);
grunt.registerTask('scripts', 'Lints, cleans and compiles the JavaScript files.', ['jshint:build', 'uglify:build']);
grunt.registerTask('stylesheets', 'Compiles the stylesheets.', ['stylus:build', 'autoprefixer:build', 'cssmin:build']);
// User-called Tasks
grunt.registerTask('build', 'Validates, cleans, compiles, and copies assets to the build directory', ['clean:build', 'assets', 'stylesheets', 'scripts']);
grunt.registerTask('dev', 'Validates and copies assets to the development build directory.', ['clean:dev', 'dev-assets', 'dev-stylesheets', 'dev-scripts']);
grunt.registerTask('clean-dev', 'Cleans the development build directory', ['clean:dev']);
grunt.registerTask('setup', 'Gets JS dependencies and slurps esri js.', ['bower-install-simple:dev', 'esri_slurp:dev']);
grunt.registerTask('test', 'Run unit tests with intern', ['intern:dev']);
grunt.registerTask('default', 'Watches the project for changes, and automatically performs a development build.', ['stylus:dev', 'stylus:dev_widgets', 'copy:dev', 'connect:dev', 'open:dev_browser', 'watch']);
};