-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
170 lines (151 loc) · 5.03 KB
/
Gruntfile.js
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
/*jshint camelcase: false */
/*global module:false */
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
zatacka: {
files: {
'build/application.min.js': ['build/application.js']
}
}
},
/*
A simple ordered concatenation strategy.
This will start at app/app.js and begin
adding dependencies in the correct order
writing their string contents into
'build/application.js'
Additionally it will wrap them in evals
with @ sourceURL statements so errors, log
statements and debugging will reference
the source files by line number.
You would set this option to false for
production.
*/
neuter: {
options: {
includeSourceURL: true
},
'build/application.js': 'app/app.js'
},
concat: {
options: {
stripBanners: true,
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */'
},
dist: {
src: ['dependencies/jquery.js',
'dependencies/handlebars.js',
'dependencies/ember.js',
'app/**/*.js'],
dest: 'build/application.js'
}
},
/*
Watch files for changes.
Changes in dependencies/ember.js or application javascript
will trigger the neuter task.
Changes to any templates will trigger the ember_templates
task (which writes a new compiled file into dependencies/)
and then neuter all the files again.
*/
watch: {
application_code: {
files: ['dependencies/ember.js', 'app/**/*.js'],
tasks: ['concat']
},
handlebars_templates: {
files: ['app/**/*.hbs'],
tasks: ['ember_templates', 'neuter']
}
},
/*
Runs all .html files found in the test/ directory through PhantomJS.
Prints the report in your terminal.
*/
qunit: {
all: ['test/**/*.html']
},
/*
Reads the projects .jshintrc file and applies coding
standards. Doesn't lint the dependencies or test
support files.
*/
jshint: {
all: ['Gruntfile.js', 'app/**/*.js', 'test/**/*.js', '!dependencies/*.*', '!test/support/*.*'],
options: {
jshintrc: '.jshintrc'
}
},
/*
Finds Handlebars templates and precompiles them into functions.
The provides two benefits:
1. Templates render much faster
2. We only need to include the handlebars-runtime microlib
and not the entire Handlebars parser.
Files will be written out to dependencies/compiled/templates.js
which is required within the project files so will end up
as part of our application.
The compiled result will be stored in
Ember.TEMPLATES keyed on their file path (with the 'app/templates' stripped)
*/
ember_templates: {
options: {
templateName: function(sourceFile) {
return sourceFile.replace(/app\/templates\//, '');
}
},
'dependencies/compiled/templates.js': ["app/templates/*.hbs"]
},
/*
Find all the <whatever>_test.js files in the test folder.
These will get loaded via script tags when the task is run.
This gets run as part of the larger 'test' task registered
below.
*/
build_test_runner_file: {
all: ['test/**/*_test.js']
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-neuter');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-ember-templates');
grunt.loadNpmTasks('grunt-contrib-concat');
/*
A task to build the test runner html file that get place in
/test so it will be picked up by the qunit task. Will
place a single <script> tag into the body for every file passed to
its coniguration above in the grunt.initConfig above.
*/
grunt.registerMultiTask('build_test_runner_file', 'Creates a test runner file.', function(){
var tmpl = grunt.file.read('test/support/runner.html.tmpl');
var renderingContext = {
data: {
files: this.filesSrc.map(function(fileSrc){
return fileSrc.replace('test/', '');
})
}
};
grunt.file.write('test/runner.html', grunt.template.process(tmpl, renderingContext));
});
/*
A task to run the application's unit tests via the command line.
It will
- convert all the handlebars templates into compile functions
- combine these files + application files in order
- lint the result
- build an html file with a script tag for each test file
- headlessy load this page and print the test runner results
*/
grunt.registerTask('test', ['ember_templates', 'neuter', 'jshint', 'build_test_runner_file', 'qunit']);
/*
Default task. Compiles templates, neuters application code, and begins
watching for changes.
*/
grunt.registerTask('default', ['concat', 'watch']);
};