forked from LHNCBC/ucum-lhc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
229 lines (210 loc) · 5.78 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
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
module.exports = function(grunt) {
// Load grunt tasks automatically as needed ("jit")
require('jit-grunt')(grunt, {
clean: 'grunt-contrib-clean',
cssmin: 'grunt-contrib-cssmin',
uglify: 'grunt-contrib-uglify',
mochaTest: 'grunt-mocha-test',
protractor: 'grunt-protractor-runner'
});
// Time how long tasks take. Just for fun
require('time-grunt')(grunt);
// Define the configuration for all the tasks
grunt.initConfig({
// clean out directories
clean: {
dist: { // the non-browser distribution files
files: [{
cwd: '.',
src: ['source-es5/*']
}]
} ,
browser: {
files: [{
cwd: '.',
src: ['source-es5/*', 'browser-dist/*']
}]
} ,
demo: {
files: [{
cwd: '.',
src: ['demo-es5/*']
}]
} ,
test: {
files: [{
cwd: '.',
src: ['test-es5/*']
}]
}
},
// use babel to translate ES6 files to ES5 files
babel: {
options: {
compact: false,
sourceMap: true,
presets: ['env']
},
dist: { // the non-browser distribution files
files: [{
expand: true,
cwd: '.',
flatten: true,
src: ['./source/*.js'],
dest: './source-es5'
}]
},
browser: {
files: [{
expand: true,
cwd: '.',
flatten: true,
src: ['./source/*.js'],
dest: './source-es5'
}]
},
demo: {
files: [{
expand: true,
cwd: '.',
flatten: true,
src: ['./demo/*.js'],
dest: './demo-es5'
}]
},
test: {
files: [{
expand: true,
cwd: '.',
flatten: true,
src: ['./test/*.js'],
dest: './test-es5'
}]
}
},
// use browserify to prepare the files for client-side use
browserify: {
browser: {
options: {
browserifyOptions: {
standalone: "ucumPkg"
}
},
files: [{dest: "./browser-dist/ucum-lhc.js",
src: ["./source-es5/ucumPkg.js"]}
]
},
demo: {
options: {
browserifyOptions: {
standalone: "demoPkg"
},
exclude: ['./source-es5/*.js']
},
files: [{dest: "./demo-dist/ucum-demo.js",
src: ["./demo-es5/main.js"]}
]
}
},
// use css min to minify the css files
cssmin: {
default: {
files: [ {
src: ['./demo-dist/stylesheets/ucumDemo.css'],
dest: './demo-dist/ucumDemo.min.css'
}]
}
} ,
// use uglify to minify the javascript files
uglify: {
options: { compress: true },
browser: {
files: {
'./browser-dist/ucum-lhc.min.js' : [ './browser-dist/ucum-lhc.js']
}
},
demo: {
files: {
'./demo-dist/ucum-demo.min.js' : ['./demo-dist/ucum-demo.js']
}
}
} ,
// using mocha for the tests
mochaTest: {
options: {
reporter: 'spec'
} ,
src: ['./test-es5/*.spec.js']
},
// watch application files to see if they need to be re-browserified,
// and bower components to see if they change
watch: {
scripts: {
files: ["./source/*.js", "./demo/*.js"],
tasks: ["browserify"]
},
files: ['bower_components/*'],
tasks: ['wiredep']
} ,
// ssi to include html files in demo.html
ssi: {
options: {
input: './demo/',
output: './',
matcher: 'demo*.html'
}
},
// grunt protractor runner task
protractor: {
options: {
configFile: "demo-test/ucumDemo-conf.js",
keepAlive: false,
noColor: false,
args: {}
} ,
all: {
options: {
browser: 'firefox'
}
}
} // end protractor task
}); // end grunt.initConfig
// load and register the tasks
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks("grunt-babel");
grunt.loadNpmTasks("grunt-browserify");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks('grunt-wiredep');
grunt.loadNpmTasks('grunt-mocha-test') ;
grunt.loadNpmTasks('grunt-protractor-runner');
grunt.registerTask('ssi', 'Flatten SSI includes in your HTML files.', function() {
var ssi = require( 'ssi' );
var opts = this.options();
var files = new ssi( opts.input, opts.output, opts.matcher) ;
files.compile();
});
grunt.registerTask("build:dist", ["clean:dist",
"babel:dist"]);
grunt.registerTask("build:browser", ["clean:browser",
"babel:browser",
"browserify:browser",
"uglify:browser"]);
grunt.registerTask("build:demo", ["clean:demo",
"ssi",
"babel:demo",
"browserify:demo",
"cssmin",
"uglify:demo"]);
grunt.registerTask("build:test", ["clean:test",
"babel:test"]);
grunt.registerTask("build", ["build:dist",
"build:browser",
"build:demo",
"build:test"]);
grunt.registerTask("test", ['build',
'mochaTest']);
// note that the webdriver manager must be running before the
// protractor tests will run. use webdriver-manager start & to
// start the manager and the selenium server
grunt.registerTask("runProtractor", ['protractor']);
};