This repository has been archived by the owner on Oct 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Gruntfile.js
234 lines (227 loc) · 8.25 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
230
231
232
233
234
module.exports = function (grunt) {
'use strict';
require('load-grunt-tasks')(grunt, {
pattern: ['grunt-*', '!grunt-lib-phantomjs']
});
require('time-grunt')(grunt);
var config = {
src: 'src',
spec: 'spec',
web: 'web',
pkg: require('./package.json'),
banner: grunt.file.read('./LICENSE_BANNER'),
jsFiles: module.exports.jsFiles
};
grunt.initConfig({
conf: config,
concat: {
options : {
process: true,
sourceMap: true,
banner : '<%= conf.banner %>'
},
js: {
src: '<%= conf.jsFiles %>',
dest: '<%= conf.pkg.name %>.js'
}
},
uglify: {
jsmin: {
options: {
mangle: true,
compress: true,
sourceMap: true,
banner : '<%= conf.banner %>'
},
src: '<%= conf.pkg.name %>.js',
dest: '<%= conf.pkg.name %>.min.js'
}
},
eslint: {
source: {
src: [
'<%= conf.src %>/**/*.js',
'!<%= conf.src %>/{banner,footer,d3v3-compat}.js',
'<%= conf.spec %>/**/*.js',
'Gruntfile.js',
'grunt/*.js'
]
},
options: {
configFile: '.eslintrc'
}
},
watch: {
scripts: {
files: ['<%= conf.src %>/**/*.js'],
tasks: ['docs']
},
tests: {
files: ['<%= conf.src %>/**/*.js', '<%= conf.spec %>/**/*.js'],
tasks: ['test']
},
reload: {
files: ['<%= conf.pkg.name %>.js',
'<%= conf.pkg.name %>css',
'<%= conf.web %>/js/<%= conf.pkg.name %>.js',
'<%= conf.web %>/css/<%= conf.pkg.name %>.css',
'<%= conf.pkg.name %>.min.js'],
options: {
livereload: true
}
}
},
connect: {
server: {
options: {
port: 8888,
base: '.'
}
}
},
emu: {
api: {
src: '<%= conf.pkg.name %>.js',
dest: '<%= conf.web %>/docs/api-latest.md'
}
},
toc: {
api: {
src: '<%= emu.api.dest %>',
dest: '<%= emu.api.dest %>'
}
},
copy: {
'dc-to-gh': {
files: [
{
expand: true,
flatten: true,
nonull: true,
src: [
'<%= conf.pkg.name %>.css',
'node_modules/dc/dc.css',
'node_modules/datatables/media/css/jquery.dataTables.css',
],
dest: '<%= conf.web %>/css/'
},
{
expand: true,
flatten: true,
nonull: true,
src: [
'<%= conf.pkg.name %>.js',
'<%= conf.pkg.name %>.js.map',
'<%= conf.pkg.name %>.min.js',
'<%= conf.pkg.name %>.min.js.map',
'node_modules/jquery/dist/jquery.js',
'node_modules/d3/dist/d3.js',
'node_modules/dc/dc.js',
'node_modules/datatables/media/js/jquery.dataTables.js',
'node_modules/crossfilter2/crossfilter.js',
'node_modules/whatwg-fetch/dist/fetch.umd.js'
],
dest: '<%= conf.web %>/js/'
},
{
nonull: true,
src: 'node_modules/promise-polyfill/dist/polyfill.js',
dest: '<%= conf.web %>/js/promise-polyfill.js'
},
{
expand: true,
flatten: true,
src: [
'node_modules/datatables/media/images/*'
],
dest: '<%= conf.web %>/images'
},
]
}
},
'gh-pages': {
options: {
base: '<%= conf.web %>',
message: 'Synced from from master branch.'
},
src: ['**']
},
shell: {
merge: {
command: function (pr) {
return [
'git fetch origin',
'git checkout master',
'git reset --hard origin/master',
'git fetch origin',
'git merge --no-ff origin/pr/' + pr + ' -m \'Merge pull request #' + pr + '\''
].join('&&');
},
options: {
stdout: true,
failOnError: true
}
},
amend: {
command: 'git commit -a --amend --no-edit',
options: {
stdout: true,
failOnError: true
}
},
hooks: {
command: 'cp -n scripts/pre-commit.sh .git/hooks/pre-commit' +
' || echo \'Cowardly refusing to overwrite your existing git pre-commit hook.\''
}
},
browserify: {
dev: {
src: '<%= conf.pkg.name %>.js',
dest: 'bundle.js',
options: {
browserifyOptions: {
standalone: 'dc'
}
}
}
}
});
// custom tasks
grunt.registerMultiTask('emu', 'Documentation extraction by emu.', function () {
var emu = require('emu'),
srcFile = this.files[0].src[0],
destFile = this.files[0].dest,
source = grunt.file.read(srcFile);
grunt.file.write(destFile, emu.getComments(source));
grunt.log.writeln('File \'' + destFile + '\' created.');
});
grunt.registerTask('merge', 'Merge a github pull request.', function (pr) {
grunt.log.writeln('Merge Github Pull Request #' + pr);
grunt.task.run(['shell:merge:' + pr, 'test' , 'shell:amend']);
});
grunt.registerTask('test-stock-example', 'Test a new rendering of the stock example web page against a ' +
'baseline rendering', function (option) {
require('./regression/stock-regression-test.js').testStockExample(this.async(), option === 'diff');
});
grunt.registerTask('update-stock-example', 'Update the baseline stock example web page.', function () {
require('./regression/stock-regression-test.js').updateStockExample(this.async());
});
// task aliases
grunt.registerTask('build', ['concat', 'uglify']);
grunt.registerTask('docs', ['build', 'copy', 'emu']);
grunt.registerTask('web', ['docs', 'gh-pages']);
grunt.registerTask('server', ['docs', 'connect:server', 'watch:scripts']);
grunt.registerTask('test', ['build', 'jasmine:specs', 'shell:hooks']);
grunt.registerTask('test-browserify', ['build', 'browserify', 'jasmine:browserify']);
grunt.registerTask('coverage', ['build', 'jasmine:coverage']);
grunt.registerTask('ci', ['test', 'jasmine:specs:build', 'connect:server', 'saucelabs-jasmine']);
grunt.registerTask('ci-pull', ['test', 'jasmine:specs:build', 'connect:server']);
grunt.registerTask('lint', ['build', 'eslint']);
grunt.registerTask('default', ['build']);
};
module.exports.jsFiles = [
'src/banner.js', // NOTE: keep this first
'src/core.js', // then this!
'src/datatable.js',
'src/footer.js' // NOTE: keep this last
];