-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathGruntfile.js
More file actions
252 lines (226 loc) · 7.87 KB
/
Gruntfile.js
File metadata and controls
252 lines (226 loc) · 7.87 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
module.exports = function (grunt) {
var fs = require('fs');
var path = require('path');
var testDir = 'test';
var testHost = 'http://localhost:8000/';
var pkg = grunt.file.readJSON('package.json');
grunt.initConfig({
qunit: {
options: {
'--web-security': 'no',
coverage: {
disposeCollector: true,
src: ['dist/tablefilter/*.js'],
instrumentedFiles: 'report/temp/',
htmlReport: 'report/coverage',
coberturaReport: 'report/',
lcovReport: 'report/',
jsonReport: 'report',
linesThresholdPct: 80
}
},
all: {
options: {
urls: getTestFiles(testDir, testHost)
}
},
only: {
options: {
urls: []
}
}
},
connect: {
server: {
options: {
port: 8000,
base: '.'
}
}
},
copy: {
dist: {
src: [
'**',
'!**/*.styl',
'!**/extensions/**',
'!**/mixins/**'
],
cwd: 'static/style',
dest: 'dist/tablefilter/style',
expand: true
},
templates: {
src: ['**'],
cwd: 'static/templates',
dest: 'demos',
expand: true
},
assets: {
src: ['**'],
cwd: 'static/demos-assets',
dest: 'demos/assets',
expand: true
},
starter: {
src: ['demos/starter.html'],
dest: 'dist/starter.html'
}
},
'string-replace': {
demos: {
files: { 'demos/': 'demos/*.html' },
options: {
replacements: [
{
pattern: /{NAME}/ig,
replacement: pkg.name
}, {
pattern: /{VERSION}/ig,
replacement: pkg.version
}, {
pattern: /{EZEDITTABLE_LINK}/ig,
replacement: '<a href="http://edittable.free.fr/' +
'zip.php?f=ezEditTable.zip&p=1"' +
'target="_blank" title="ezEditTable is a ' +
'javascript code aimed at enhancing regular ' +
'HTML tables by adding features such as ' +
'inline editing components, advanced ' +
'selection and keyboard navigation ' +
'- Developed by ' + pkg.author.name + '">' +
'ezEditTable</a>'
}, {
pattern: /<!-- @import (.*?) -->/ig,
replacement: function (match, p1) {
return grunt.file.read('static/' + p1);
}
}
]
}
}
},
clean: ['demos/starter.html'],
watch: {
app: {
files: ['src/**/*', 'static/style/**/*'],
tasks: ['dev'],
options: {
spawn: false
}
},
templates: {
files: ['static/templates/**/*', 'static/partials/**/*'],
tasks: ['build-demos'],
options: {
spawn: false
}
}
},
// temporary shell commands while decommissioning grunt
shell: {
eslint: {
command: 'npm run lint'
},
esdoc: {
command: 'npm run esdoc'
},
build: {
command: 'npm run build'
},
dev: {
command: 'npm run dev'
},
test: {
command: 'npm run build:test'
},
'build-css': {
command: 'npm run build:css'
}
}
});
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-string-replace');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-qunit-istanbul');
grunt.registerTask('eslint', ['shell:eslint']);
grunt.registerTask('esdoc', ['shell:esdoc']);
grunt.registerTask('default', ['test', 'build', 'build-demos']);
// Dev dev/build/watch cycle
grunt.registerTask('dev',
['eslint', 'shell:dev', 'copy:dist', 'shell:build-css', 'watch:app']);
// Production build
grunt.registerTask('build',
['eslint', 'shell:build', 'copy:dist', 'shell:build-css']);
// Build demos
grunt.registerTask('dev-demos', ['build-demos', 'watch:templates']);
grunt.registerTask('build-demos', ['copy:templates', 'copy:assets',
'string-replace:demos', 'copy:starter', 'clean']);
// Build tests
grunt.registerTask('build-test',
['eslint', 'shell:test', 'copy:dist', 'shell:build-css']);
// Tests with coverage
grunt.registerTask('test', ['build-test', 'connect', 'qunit:all']);
// Build all for deployment from travis
grunt.registerTask('build-all', 'Prepare for deployment', [
'build', 'build-demos', 'esdoc'
]);
// Custom task running QUnit tests for specified files.
// Usage example: grunt test-only:test.html,test-help.html
grunt.registerTask('test-only',
'A task that runs only specified tests.',
function (tests) {
if (!tests) {
return;
}
tests = tests.split(',');
var res = [];
tests.forEach(function (itm) {
var filePath = path.resolve(testDir, itm);
var parts = filePath.split(path.sep);
res.push(buildTestUrl(testHost, testDir, parts));
});
grunt.task.run('connect');
grunt.config('qunit.only.options.urls', res);
grunt.task.run('qunit:only');
}
);
function isTestFile(pth) {
var allowedExts = ['.html', '.htm'];
for (var i = 0, len = allowedExts.length; i < len; i++) {
var ext = allowedExts[i];
if (pth.indexOf(ext) !== -1) {
return true;
}
}
return false;
}
function buildTestUrl(host, testDir, parts) {
var idx = parts.indexOf(testDir);
var fileIdx = parts.length;
var relParts = parts.slice(idx, fileIdx);
return host.concat(relParts.join('/'));
}
// Returns the list of test files from the test folder for qunit task
function getTestFiles(testDir, host) {
var getFiles = function (dir, host) {
var res = [];
var items = fs.readdirSync(dir);
items.forEach(function (itm) {
var fileOrDir = path.resolve(dir, itm);
if (isTestFile(fileOrDir)) {
var parts = fileOrDir.split(path.sep);
res.push(buildTestUrl(host, testDir, parts));
} else {
if (fs.lstatSync(fileOrDir).isDirectory()) {
res = res.concat(getFiles(fileOrDir, host));
}
}
});
return res;
};
return getFiles(testDir, host);
}
};