This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Gruntfile.js
728 lines (646 loc) · 25.4 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
var fs = require('fs');
var path = require('path');
var version = require('./package.json').version;
var HTML_HEAD = fs.readFileSync('./jsduck-config/head.html').toString();
var CSS = fs.readFileSync('./jsduck-config/style.css').toString();
var babel = require('babel-core');
module.exports = function (grunt) {
var saucelabsTests = require('./sauce-gruntfile')(grunt, version);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
webcomponents: {
build: {
files: [
{
src: ['src/ui/**/*.js', '!src/ui/**/test.js', '!src/ui/**/tests/*.js']
}
],
options: {
}
}
},
custom_babel: {
dist: {
files: [
{
src: ['lib-es6/**/*.js'],
dest: 'lib-es5'
}
],
options: {
}
}
},
remove: {
build: {
fileList: ['build']
},
theme: {
fileList: ['themes/build']
},
lib: {
dirList: ['lib']
},
libes5: {
dirList: ['lib-es5']
},
libes6: {
dirList: ['lib-es6']
},
},
browserify: {
options: {
verbose: true,
separator: ';',
transform: [ ],
browserifyOptions: {
}
},
samples: {
files: [
{
dest: 'samples/build.js',
src: 'samples/index.js'
}
],
options: {
transform: [['babelify', {
presets: ['es2015']}]],
}
},
build: {
files: [
{
dest: 'build/layer-xdk.js',
src: 'lib/index-all.js'
}
]
},
core: {
files: [
{
dest: 'build/layer-xdk-core.js',
src: 'lib/index-core.js'
}
]
},
coverage: {
files: {
'test/coverage-build.js': ['lib/index-all.js']
},
options: {
transform: [[fixBrowserifyForIstanbul], ["istanbulify"]],
browserifyOptions: {
standalone: false,
debug: false
}
}
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */ ',
mangle: {
except: [
"layer",
"Client"]
},
sourceMap: false,
screwIE8: true
},
build: {
files: {
'build/layer-xdk.min.js': ['build/layer-xdk.js']
}
}
},
less: {
themes: {
files: [
{src: ['themes/src/layer-basic-blue/theme.less'], dest: 'themes/build/layer-basic-blue.css'},
//{src: ['themes/src/layer-groups/theme.less'], dest: 'themes/build/layer-groups.css'}
]
}
},
custom_copy: {
src: {
src: ['src/core/*', 'src/*.js', 'src/utils'],
dest: 'lib-es6/'
},
},
copy: {
npm: {
files: [
{src: ['**'], cwd: 'themes/build/', dest: 'npm/themes/', expand: true},
{src: ['**'], cwd: 'themes/src/', dest: 'npm/themes/src/', expand: true},
{src: ['**'], cwd: 'lib/', dest: 'npm/', expand: true},
{src: 'package.json', dest: 'npm/package.json'}
]
},
themes: {
src: ["themes/src/*/**.html", "themes/src/*/**.js"],
dest: "themes/build/",
flatten: true,
expand: true
},
// Adds support for the ignoreFiles parameter, which is needed for removing generated files from the result
fixIstanbul: {
src: "grunt-template-jasmine-istanbul_src-main-js-template.js",
dest: "node_modules/grunt-template-jasmine-istanbul/src/main/js/template.js"
}
},
move: {
lib: {
src: 'lib-es5',
dest: 'lib'
}
},
cssmin: {
build: {
files: [
{src: ['themes/build/layer-basic-blue.css'], dest: 'themes/build/layer-basic-blue.min.css'},
//{src: ['themes/build/layer-groups.css'], dest: 'themes/build/layer-groups.min.css'}
]
}
},
// Testing and Coverage tasks
jasmine: {
options: {
helpers: ['test/lib/mock-ajax.js', 'test/core/specs/responses.js'],
specs: ['test/core/specs/unit/*Spec.js', 'test/core/specs/unit/**/*Spec.js'],
summary: true
},
debug: {
src: ["build/layer-xdk-core.js"]
}
},
// Documentation
jsduck: {
build: {
src: ["lib/**/*.js"],
dest: 'docs',
options: {
'builtin-classes': false,
'warnings': ['-no_doc', '-dup_member', '-link_ambiguous', '-cat_class_missing'],
'external': ['HTMLTemplateElement', 'Websocket', 'Blob', 'KeyboardEvent', 'DocumentFragment', 'IDBVersionChangeEvent', 'IDBKeyRange', 'IDBDatabase', 'File', 'Canvas', 'CustomEvent'],
'title': 'Layer UI for Web - API Documentation',
'categories': ['jsduck-config/categories.json'],
'head-html': HTML_HEAD,
'css': [CSS],
'footer': 'Layer Web XDK v' + version
}
}
},
jsducktemplates: {
build: {
files: [
{
src: ['src/ui/components/**/*.html']
}
],
options: {
}
}
},
jsduckfixes: {
build: {
files: [
{
src: ['docs/output/*.js']
}
],
options: {
}
}
},
version: {
build: {
files: [
{
dest: 'src/version.js',
src: 'src/version.js'
}
]
},
options: {
version: "<%= pkg.version %>"
}
},
'generate-tests': {
debug: {
files: [
{
src: ['src/ui/**/test.js', 'src/ui/**/tests/**.js']
}
],
}
},
connect: {
saucelabs: {
options: {
base: "",
port: 9999
}
},
develop: {
options: {
base: "",
port: 8004
}
}
},
watch: {
js: {
files: ['package.json', 'Gruntfile.js', 'samples/index-all.js', 'src/**', '!**/test.js', '!src/ui/**/tests/**.js', '!src/version.js'],
tasks: ['debug', 'notify:watch'],
options: {
interrupt: true
}
},
themes: {
files: ['themes/src/**'],
tasks: ['theme'],
options: {
interrupt: true
}
}
},
notify: {
watch: {
options: {
title: 'Watch Build', // optional
message: 'Build Complete', //required
}
}
},
'saucelabs-jasmine': saucelabsTests.tasks.saucelabs,
});
/* Insure that browserify and babelify generated code does not get counted against our test coverage */
var through = require('through');
function fixBrowserifyForIstanbul(file) {
var generatedLines = [
"function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }",
];
var data = '';
return through(write, end);
function write (buf) {
data += buf;
}
function end () {
var lines = data.split(/\n/);
for (var i = 0; i < lines.length; i++) {
if (generatedLines.indexOf(lines[i]) !== -1) {
lines[i] = "/* istanbul ignore next */ " + lines[i];
}
}
this.queue(lines.join('\n'));
this.queue(null);
}
}
grunt.registerMultiTask('jsduckfixes', 'Fixing Docs', function() {
var options = this.options();
this.files.forEach(function(fileGroup) {
fileGroup.src.forEach(function(file, index) {
var contents = grunt.file.read(file);
var startIndex = contents.indexOf('{');
var endIndex = contents.lastIndexOf('}') + 1;
var parsedContents = JSON.parse(contents.substring(startIndex, endIndex));
if (parsedContents.members) parsedContents.members.forEach(function(element) {
element.id = element.id.replace(/:/g, '_');
});
parsedContents.html = parsedContents.html.replace(/id='([^']*):([^']*)'/g, "id='" + "$1" + "_" + "$2'");
parsedContents.html = parsedContents.html.replace(/href='([^']*):([^']*)'/g, "href='" + "$1" + "_" + "$2'");
contents = contents.substring(0, startIndex) + JSON.stringify(parsedContents) + contents.substring(endIndex);
grunt.file.write(file, contents);
});
});
});
/* Adds template info to the jsduck class definition comments */
grunt.registerMultiTask('jsducktemplates', 'Adding templates to Docs', function() {
var options = this.options();
this.files.forEach(function(fileGroup) {
fileGroup.src.forEach(function(file, index) {
var template = grunt.file.read(file);
var srcFilePath = file.replace(/src/, 'lib').replace(/\.html/, '.js');
var srcFile = grunt.file.read(srcFilePath);
var startIndex = srcFile.indexOf("@class");
if (startIndex !== -1) {
var layerIds = (template.match(/layer-id=["'](.*?)["']/gm) || []).map(function(match) {
return match.replace(/^.*["'](.*)["']/, "$1");
});
srcFile = srcFile.substring(0, startIndex) +
`### Templates\n\n * You can see the template for the latest template version at [${file.replace(/^.*\//, '')}](https://github.com/layerhq/web-xdk/blob/master/src/${srcFilePath.replace(/^.*lib/,'').replace(/\.js$/, '.html')}) \n * \n * The following layer-id attributes are expected in templates for this component: \n * \n * * ${layerIds.join('\n * * ')} \n` + srcFile.substring(startIndex);
grunt.file.write(srcFilePath, srcFile);
}
});
});
});
grunt.registerMultiTask('version', 'Assign Versions', function() {
var options = this.options();
function replace(fileGroup, version) {
fileGroup.src.forEach(function(file, index) {
var contents = grunt.file.read(file);
grunt.file.write(fileGroup.dest, 'module.exports = "' + version + '";');
});
}
// Iterate over each file set and fire away on that set
this.files.forEach(function(fileGroup) {
replace(fileGroup, options.version);
});
});
grunt.registerMultiTask('custom_copy', 'Copying files', function() {
var options = this.options();
function process(file, outputPath) {
try {
grunt.file.copy(file, outputPath);
} catch(e) {
grunt.log.writeln('Failed to process ' + file + '; ', e);
}
}
// Iterate over each file set and generate the build file specified for that set
this.files.forEach(function(fileGroup) {
fileGroup.src.forEach(function(file, index) {
// TODO: Generalize this to not only work with src
process(file, file.replace(/^src/, fileGroup.dest));
});
});
});
// Don't recall all the reasons we don't just use a Grunt Babel task, but this does give us more direct
// control over parameters, as well as progress reporting and error reporting
grunt.registerMultiTask('custom_babel', 'Babelifying all files in src/core', function() {
var options = this.options();
function convert(file, outputPath) {
try {
var output = grunt.file.read(file);
var outputFolder = path.dirname(outputPath);
if (!grunt.file.exists(outputFolder)) {
grunt.file.mkdir(outputFolder);
}
var babelResult = babel.transform(output, {
presets: ["babel-preset-es2015"],
auxiliaryCommentBefore: 'istanbul ignore next'
});
var result = babelResult.code;
var indexOfClass = result.indexOf('@class');
var indexOfClassCodeBlock = (indexOfClass !== -1) ? result.lastIndexOf('/**', indexOfClass) : -1;
if (indexOfClassCodeBlock !== -1) {
var endOfClassCodeBlock = result.indexOf('*/', indexOfClassCodeBlock);
if (endOfClassCodeBlock !== -1) {
endOfClassCodeBlock += 2;
var prefix = result.substring(0, indexOfClassCodeBlock);
var classComment = result.substring(indexOfClassCodeBlock, endOfClassCodeBlock);
classComment = classComment.replace(/\n\s*\*/g, '\n *') + '\n';
var postfix = result.substring(endOfClassCodeBlock);
result = classComment + prefix + postfix;
}
}
grunt.file.write(outputPath, result);
} catch(e) {
grunt.log.writeln('Failed to process ' + file + '; ', e);
}
}
var files = [];
// Iterate over each file set and generate the build file specified for that set
this.files.forEach(function(fileGroup) {
fileGroup.src.forEach(function(file, index) {
files.push(file);
// TODO: Generalize this to not only work with lib-es6
try {
convert(file, file.replace(/^lib-es6/, fileGroup.dest));
} catch(e) {
console.error('Failed to convert ' + file + ' to babel');
throw(e);
}
});
});
});
grunt.registerMultiTask('webcomponents', 'Building Web Components', function() {
var options = this.options();
function optimizeStrings(contents, name, commentExpr) {
var keyString = name + ': `';
var startIndex = contents.indexOf(keyString);
if (startIndex === -1) return contents;
startIndex += keyString.length;
var endIndex = contents.indexOf('`', startIndex);
if (endIndex === -1) return contents;
var stringToOptimize = contents.substring(startIndex, endIndex).replace(commentExpr, '').split(/\n/).map(line => line.trim()).filter(line => line).join('\n');
return contents.substring(0, startIndex) + stringToOptimize + contents.substring(endIndex);
}
function parseTemplates(parentFolder, className, pathToLayerUI) {
var output = '';
var templates = grunt.file.expand(parentFolder + "/*.html")
templates.forEach(function(templateFileName) {
// Stick the entire template into a function comment for easy multi-line string,
// and feed the resulting function.toString() into buildTemplate() to create and assign a template to the widget.
// TODO: maybe we should minify the HTML and CSS so it fits on a single line and doesn't need a function comment.
// Note: this would require escaping of all strings, which can get messy.
grunt.log.writeln("Writing template for " + className);
var contents = grunt.file.read(templateFileName);
contents = contents.replace(/\/\*[\s\S]*?\*\//mg, '');
var templateCount = 0;
var templates = contents.match(/^\s*<template(\s+id=['"].*?['"]\s*)?>([\s\S]*?)<\/template>/mg);
templates.forEach(function(templateString) {
templateCount++;
var templateMatches = templateString.match(/^\s*<template(\s+id=['"].*?['"]\s*)?>([\s\S]*?)<\/template>/m);
var templateContents = templateMatches[2];
var templateId = templateMatches[1] || '';
if (templateId) templateId = templateId.replace(/^.*['"](.*)['"].*$/, "$1");
if (!templateId) {
var templateName = templateFileName.replace(/\.html/, '').replace(/^.*\//, '');
if (templateName !== className) templateId = templateName;
}
// Extracting styles won't be needed once we have shadow dom. For now, this prevents 500 <layer-message> css blocks
// from getting added and all applying to all messages.
var styleMatches = templateContents.match(/<style>([\s\S]*)<\/style>/);
var style;
if (styleMatches) {
style = styleMatches[1].replace(/^\s*/gm, '');
templateContents = templateContents.replace(/<style>([\s\S]*)<\/style>\s*/, '');
}
// Strip out white space between tags
templateContents = templateContents.replace(/<!--[\s\S]*?-->/gm, '');
// Strip out HTML Comment Nodes
templateContents = templateContents.replace(/>\s+</g, '><');
// Generate the <template /> and <style> objects
output += '\n(function() {\n';
output += 'var layerUI = require(\'' + pathToLayerUI + '\');\n';
output += 'layerUI.buildAndRegisterTemplate("' + className + '", ' + JSON.stringify(templateContents.replace(/\n/g,'').trim()) + ', "' + templateId + '");\n';
output += 'layerUI.buildStyle("' + className + '", ' + JSON.stringify(style.trim()) + ', "' + templateId + '");\n';
output += '})()';
});
});
return output;
}
function createCombinedComponentFile(file, outputPathES5, outputPathES6) {
try {
// Extract the class name; TODO: class name should be same as file name.
var jsFileName = file.replace(/^.*\//, '');
var className = jsFileName.replace(/\.js$/, '');
if (jsFileName === 'test.js') return;
var output = grunt.file.read(file);
output = optimizeStrings(output, 'style', /\/\*[\s\S]*?\*\//m);
output = optimizeStrings(output, 'template', /<!--[\s\S]*?-->/m);
var outputFolderES6 = path.dirname(outputPathES6);
var outputFolderES5 = path.dirname(outputPathES5);
// Find the template file by checking for an html file of the same name as the js file in the same folder.
var parentFolder = path.dirname(file);
var pathToLayerUI = parentFolder.replace(/[/|\bsrc/ui/][^/]*/g, "/..").substring(7) + "/layer-ui"
// We have mostly migrated away from these template files
output += parseTemplates(parentFolder, className, pathToLayerUI);
//var outputES5 = output.replace(/\/\*[\s\S]*?\*\//g, '');
var outputES5 = output;
if (!grunt.file.exists(outputFolderES6)) {
grunt.file.mkdir(outputFolderES6);
}
grunt.file.write(outputPathES6, output);
if (!grunt.file.exists(outputFolderES5)) {
grunt.file.mkdir(outputFolderES5);
}
var babelResult = babel.transform(outputES5, {
presets: ['babel-preset-es2015']
});
outputES5 = babelResult.code;
// Babel sometimes moves our jsduck comments defining the class to the end of the file, causing JSDuck to quack.
// Move it back to the top so that JSDuck knows what class all the properties and methods belong to.
var indexOfClass = outputES5.indexOf('@class');
var indexOfClassCodeBlock = (indexOfClass !== -1) ? outputES5.lastIndexOf('/**', indexOfClass) : -1;
if (indexOfClassCodeBlock !== -1) {
var endOfClassCodeBlock = outputES5.indexOf('*/', indexOfClassCodeBlock);
if (endOfClassCodeBlock !== -1) {
endOfClassCodeBlock += 2;
var prefix = outputES5.substring(0, indexOfClassCodeBlock);
var classComment = outputES5.substring(indexOfClassCodeBlock, endOfClassCodeBlock);
classComment = classComment.replace(/\n\s*\*/g, '\n *') + '\n';
var postfix = outputES5.substring(endOfClassCodeBlock);
outputES5 = classComment + prefix + postfix;
}
}
grunt.file.write(outputPathES5, outputES5);
//grunt.log.writeln("Wrote " + outputPath + "; success: " + grunt.file.exists(outputPath));
} catch(e) {
grunt.log.writeln('Failed to process ' + file + '; ', e);
}
}
var files = [];
// Iterate over each file set and generate the build file specified for that set
this.files.forEach(function(fileGroup) {
fileGroup.src.forEach(function(file, index) {
files.push(file);
var outputPathES5 = file.replace(/^src/, 'lib');
var outputPathES6 = file.replace(/^src/, 'lib-es6');
createCombinedComponentFile(file, outputPathES5, outputPathES6);
});
});
});
grunt.registerMultiTask('generate-tests', 'Building SpecRunner.html', function() {
var options = this.options();
var specFiles = [
{file: 'test/SpecRunnerTemplate.html', contents: grunt.file.read('test/SpecRunnerTemplate.html'), template: true, destName: 'ui_'},
{file: 'test/SpecRunnerTemplate.html', contents: grunt.file.read('test/SpecRunnerTemplate.html'), template: false},
{file: 'test/CoverageRunner.html', contents: grunt.file.read('test/CoverageRunner.html'), template: false}
];
var startStr = "<!-- START GENERATED SPEC LIST -->";
var endStr = "<!-- END GENERATED SPEC LIST -->";
var startIndexes = specFiles.map(function(file) {
return file.contents.indexOf(startStr) + startStr.length;
});
var endIndexes = specFiles.map(function(file) {
return file.contents.indexOf(endStr);
});
var scripts = {all: []};
// Iterate over each file set and generate the build file specified for that set
this.files.forEach(function(fileGroup) {
fileGroup.src.forEach(function(file, index) {
var scriptTag = '<script src="../' + file + '" type="text/javascript"></script>';
var folderName = file.replace(/src\/ui\/?(.*?)\/.*$/, "$1");
var componentFolderName = file.replace(/src\/ui\/components\/?(.*?)\/.*$/, "$1");
// Arbitrary subdivision of the components folder which has too many tests for IE11
if (componentFolderName === 'tests') {
if (file.match(/(-list|-item)(-test)?.js/)) {
folderName += '-lists';
}
}
if (!scripts[folderName]) scripts[folderName] = [];
scripts[folderName].push(scriptTag);
scripts.all.push(scriptTag);
});
});
for (var i = 0; i < specFiles.length; i++) {
var filePath = specFiles[i].file;
var contents = specFiles[i].contents;
if (startIndexes[i] !== -1) {
if (!specFiles[i].template) {
contents = contents.substring(0, startIndexes[i]) + '\n' + scripts.all.join('\n') + '\n' + contents.substring(endIndexes[i]);
grunt.file.write(filePath, contents);
} else {
Object.keys(scripts).forEach(function(testName, index, allScripts) {
if (testName === 'all') return;
var testFile = contents.substring(0, startIndexes[i]) + '\n' + scripts[testName].join('\n') + '\n' + contents.substring(endIndexes[i]);
if (index < allScripts.length - 1) {
testFile = testFile.replace(/next_file_name_here\.html/, specFiles[i].destName + allScripts[index + 1] + '.html');
} else {
testFile = testFile.replace(/next_file_name_here\.html/, 'tests_done.html');
}
console.log("WRITE " + specFiles[i].destName + testName + '.html');
grunt.file.write(filePath.replace(/[^/]*$/, specFiles[i].destName + testName + '.html'), testFile);
});
}
}
}
});
grunt.registerTask('wait', 'Waiting for files to appear', function() {
console.log('Waiting...');
var done = this.async();
// There is an inexplicable delay between when grunt writes a file (and confirms it as written) and when it shows up in the file system.
// This has no affect on subsequent grunt tasks but can severely impact npm publish
// Note that we can't test if a file exists because grunt reports that it exists even if it hasn't yet been flushed to the file system.
setTimeout(function() {
console.log("Waiting...");
setTimeout(function() {
console.log("Waiting...");
setTimeout(function() {
done();
}, 1500);
}, 1500);
}, 1500);
});
grunt.registerTask('fix-npm-package', function() {
var contents = JSON.parse(grunt.file.read('npm/package.json'));
contents.main = 'index.js'
delete contents.scripts.prepare;
grunt.file.write('npm/package.json', JSON.stringify(contents, null, 4));
});
grunt.registerTask('refuse-to-publish', function() {
throw new Error('cd into the npm folder to complete publishing');
});
// Building
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-jsduck');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-notify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-saucelabs');
grunt.loadNpmTasks('grunt-remove');
grunt.loadNpmTasks('grunt-move');
// Testing
grunt.loadNpmTasks('grunt-contrib-jasmine');
//grunt.registerTask('phantomtest', ['debug', 'jasmine:debug']);
grunt.registerTask('coverage', ['copy:fixIstanbul', 'remove:libes6','custom_copy:src', 'remove:lib', 'remove:libes5', 'custom_babel', 'move:lib', 'browserify:coverage']);
grunt.registerTask("test", ["generate-tests", "connect:saucelabs", "saucelabs-jasmine"]);
grunt.registerTask('docs', ['debug', /*'jsducktemplates',*/ 'jsduck', 'jsduckfixes']);
// Basic Code/theme building
// We are not going to publish lib-es6 as this risks importing of files from both lib and lib-es6 by accident and getting multiple definitions of classes
grunt.registerTask('debug', ['version', 'remove:libes6', 'webcomponents', 'custom_copy:src', 'remove:libes5', 'custom_babel', 'remove:lib', 'move:lib', 'browserify:build', 'generate-tests', 'remove:libes6']);
grunt.registerTask('build', ['remove:build', 'debug', 'uglify', 'theme', 'cssmin']);
grunt.registerTask('prepublish', ['build', 'copy:npm', 'fix-npm-package', 'refuse-to-publish']);
grunt.registerTask('samples', ['debug', 'browserify:samples']);
grunt.registerTask('theme', ['remove:theme', 'less', 'copy:themes']),
grunt.registerTask('default', ['build']);
// Open a port for running tests and rebuild whenever anything interesting changes
grunt.registerTask("develop", ["debug", "connect:develop", "watch"]);
};