-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathgulpfile.js
121 lines (106 loc) · 3.16 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
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
/* globals require: true */
var gulp = require('gulp')
, header = require('gulp-header')
, uglify = require('gulp-uglify')
, rename = require('gulp-rename')
, jshint = require('gulp-jshint')
, addsrc = require('gulp-add-src')
, pkg = require('./package.json')
, banner = [
'/*!'
, ' * @license'
, ' * <%= pkg.name %> <%= pkg.version %> <%= pkg.homepage %>'
, ' * Copyright 2012-<%= new Date().getFullYear() %> <%= pkg.author %>'
, ' * MIT license'
, ' */'
, ''
].join('\n');
var striphtml = (function () {
/* globals Buffer: true */
'use strict';
var PluginError = require('plugin-error')
, through = require('through2');
function removeHTML(src, patterns) {
var lines = src.split('\n')
, scriptSection = false
, commentingSection = false;
lines.forEach(function (line, i) {
var starts = (/<script/i).test(line)
, stops = (/<\/script/i).test(line)
, commentStart = (/<!--/).test(line)
, commentStop = (/-->/).test(line);
if (starts && !(starts && stops)) {
var type = line.match(/<script[^>]*type=['"]?([^\s"']*)[^>]*>/i);
scriptSection = (type === null || type[1] === 'text/javascript');
lines[i] = '';
} else if (stops) {
scriptSection = false;
}
if(!scriptSection && commentStart){
commentingSection = true;
}
if (!scriptSection || commentingSection) {
lines[i] = '';
}
if(commentStop){
commentingSection = false;
}
});
return lines.join('\n');
}
return function (options) {
return through.obj(function processContent(file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new PluginError('gulp-striphtml', 'Streaming not supported'));
return;
}
var res = removeHTML(file.contents.toString());
file.contents = new Buffer(res);
this.push(file);
cb();
});
};
})();
gulp.task('build', function() {
return gulp.src('luaparse.js')
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest('dist'))
.pipe(uglify({ output: { comments: /^!|@preserve|@license|@cc_on/i } }))
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('dist'));
});
gulp.task('lint', function() {
return gulp.src([
'examples/**/*.html'
, 'docs/!(coverage)/*.html'
])
.pipe(striphtml())
.pipe(addsrc([
'./*.{js,json}'
, './test/{,spec}/*.js'
, './{examples,benchmarks}/**/*.{js,json}'
, '{bin,scripts}/*'
, '.jshintrc'
]))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
gulp.task('version-bump', function () {
var through = require('through2');
return gulp.src('luaparse.js')
.pipe(through.obj(function processContent(file, enc, cb) {
var data = file.contents.toString();
file.contents = new Buffer(data.replace(
/(exports\.version\s*=\s*)(?:'[^']+'|"[^"]+")(;)/, function (_, s0, s1) {
return s0 + JSON.stringify(pkg.version) + s1;
}));
this.push(file);
cb();
}))
.pipe(gulp.dest('.'));
});