-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
83 lines (69 loc) · 1.75 KB
/
gulpfile.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
var fs = require('fs'),
gulp = require('gulp'),
karma = require('gulp-karma'),
rimraf = require('gulp-rimraf'),
concat = require('gulp-concat-util'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
size = require('gulp-size'),
gutil = require('gulp-util'),
formatter = require('gulp-esformatter');
var files = {
// all files for executing tests
test: [
'tests/**/*.js'
],
// all files for client build
output: [
'lib/Wikid.js',
'lib/TokenKinds.js',
'lib/Token.js',
'lib/TokenIterator.js',
'lib/Tokenizer.js',
'lib/AST.js',
'lib/Parser.js'
]
};
// clean
gulp.task('clean', function (cb) {
rimraf('./dist', cb);
});
// test
gulp.task('test', function () {
return gulp.src(files.output.concat(files.test))
.pipe(karma({ configFile: 'karma.conf.js' }))
.on('error', gutil.log);
});
// output files
gulp.task('output', function () {
return gulp.src(files.output)
.pipe(concat('Wikid.js', { process: normalizeFiles }))
.pipe(concat.header(fs.readFileSync('./build/header')))
.pipe(concat.footer(fs.readFileSync('./build/footer')))
.pipe(formatter({ indent: { value: ' ' } }))
.pipe(size())
.pipe(gulp.dest('./dist/'))
.pipe(uglify())
.pipe(rename('Wikid.min.js'))
.pipe(size())
.pipe(gulp.dest('./dist/'))
.on('error', gutil.log);
});
gulp.task('build', [
'clean',
'output'
]);
gulp.task('default', [
'clean',
'test',
'output'
]);
/**
* Trims the files and removes 'use strict' statements.
*/
function normalizeFiles(src) {
//trim the file
src = src.trim() + '\n';
//remove duplicate 'use strict' statements
return src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, '$1');
}