-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
231 lines (211 loc) · 7.32 KB
/
Copy pathGruntfile.js
File metadata and controls
231 lines (211 loc) · 7.32 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
"use strict";
module.exports = function (grunt) {
// Reads package.json and loads grunt tasks automatically
var loadGruntTasks = require('load-grunt-tasks');
loadGruntTasks(grunt);
// Time how long tasks take. Can help when optimizing build times
var timeGrunt = require('time-grunt');
timeGrunt(grunt);
// Load in our build configuration file.
var userConfig = require('./build.config.js');
// First version, the simple approach
/**
* This is the configuration object Grunt uses to give each plugin its
* instructions.
*/
var taskConfig = {
/**
* We read in our `package.json` file so we can access the package name and
* version. It's already there, so we don't repeat ourselves here.
*/
pkg: grunt.file.readJSON("package.json"),
/**
* The directories to delete when `grunt clean` is executed.
*/
clean: {
options: {
force: true
},
files: {
src: [
'build',
'dist'
]
}
},
/**
* The `copy` task just copies files from A to B. We use it here to copy
* our project assets (images, fonts, etc.) and javascripts into
* `build_dir`, and then to copy the assets to `compile_dir`.
*/
copy: {
build: {
src: [
'vendor/angular/angular.js',
'vendor/angular-sanitize/angular-sanitize.js',
'vendor/angular-translate/angular-translate.js',
'vendor/angular-translate-loader-static-files/angular-translate-loader-static-files.js',
'vendor/angular-ui-router/release/angular-ui-router.js',
'vendor/fsmQuestion/dist/fsmQuestion.js',
'vendor/angular-local-storage/dist/angular-local-storage.js',
'vendor/angular-mocks/angular-mocks.js',
'src/**/*',
'karma/helpers/**/*.js',
'karma/mocks/**/*.js'
],
dest: 'build',
expand: true
}
},
concat: {
compile_js: {
options: {},
src: [
'build/src/**/*.js',
'build/fsm*.js',
'!build/src/**/*.spec.js'
],
dest: 'dist/fsmQuestion.js'
}
},
html2js: {
/**
* These are the templates from `src/app`.
*/
app: {
options: {
base: 'build/src',
module: 'fsmQuestionTemplates'
},
src: ['build/**/*.html'],
dest: 'build/fsmQuestionTemplates.js'
}
},
/**
* The Karma configurations.
*/
karma: {
options: {
configFile: 'build/karma-unit.js'
},
unit: {
runnerPort: 9876,
background: true
},
continuous: {
singleRun: true
}
},
/**
* This task compiles the karma template so that changes to its file array
* don't have to be managed manually.
*
* NOTE: The ordering of the modules is important!
*/
karmaconfig: {
unit: {
dir: 'build',
src: [
'vendor/angular/angular.js',
'vendor/angular-sanitize/angular-sanitize.js',
'vendor/angular-translate/angular-translate.js',
'vendor/angular-translate-loader-static-files/angular-translate-loader-static-files.js',
'vendor/angular-ui-router/release/angular-ui-router.js',
'vendor/angular-local-storage/dist/angular-local-storage.js',
'vendor/angular-mocks/angular-mocks.js',
'src/**/*.js',
'!src/**/*.spec.js',
'karma/helpers/**/*.js',
'karma/mocks/**/*.js'
]
}
},
/**
* `jshint` defines the rules of our linter as well as which files we
* should check. This file, all javascript sources, and all our unit tests
* are linted based on the policies listed in `options`. But we can also
* specify exclusionary patterns by prefixing them with an exclamation
* point (!); this is useful when code comes from a third party but is
* nonetheless inside `src/`.
*/
jshint: {
src: [
'src'
],
test: [
'src'
],
gruntfile: [
'Gruntfile.js'
],
options: {
curly: true,
immed: true,
newcap: true,
noarg: true,
sub: true,
boss: false,
eqnull: false,
globalstrict: true,
jquery: true,
browser: true,
devel: true,
debug: true,
laxcomma: true,
globals: {
module: true,
require: true,
Modernizr: true,
angular: true,
_: true,
jQuery: true,
jasmine: true,
describe: true,
ddescribe: true,
xdescribe: true,
it: true,
xit: true,
expect: true,
beforeEach: true,
afterEach: true,
inject: true,
spyOn: true
}
}
}
};
grunt.initConfig(taskConfig);
/**
* The default task is to build and compile. When build and compile is finished
* the project opened in your browser served by the connect-server.
*/
grunt.registerTask( 'default', [ 'clean', 'jshint', 'copy', 'html2js', 'concat', 'karmaconfig', 'karma:continuous', 'karma:unit' ] );
/**
* In order to avoid having to specify manually the files needed for karma to
* run, we use grunt to manage the list for us. The `karma/*` files are
* compiled as grunt templates for use by Karma. Yay!
*/
grunt.registerMultiTask('karmaconfig', 'Process karma config templates', function () {
var jsFiles = filterForJS(this.filesSrc);
grunt.file.copy('karma/karma-unit.tpl.js', 'build/karma-unit.js', {
process: function (contents, path) {
return grunt.template.process(contents, {
data: {
scripts: jsFiles
}
});
}
});
});
/**
* A utility function to get all app JavaScript sources.
*/
function filterForJS(files) {
return files.filter(function (file) {
//console.log('File: ' + file);
return file.match(/\.js$/);
});
}
// TODO: 2. Bump up version property in bower.json.
// TODO: 3. Publish to git repo
};