-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
130 lines (114 loc) · 3.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
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
var fs = require('fs');
var gulp = require('gulp');
var gutil = require('gulp-util');
var plugins = require('gulp-load-plugins')();
var packageInfo = JSON.parse(fs.readFileSync('./package.json'));
var browsers = process.env.BROWSERS || process.env.BROWSER || 'PhantomJS';
browsers = browsers ? browsers.split(' ') : undefined;
gulp.task('default', ['build', 'test']);
gulp.task('clean', function() {
return gulp.src(['./build', './test-external'], {read: false})
.pipe(plugins.clean());
});
var watching = false;
var plumber = function() {
return watching ? plugins.plumber() : gutil.noop();
};
gulp.task('lint', function() {
var jshintOptions = fs.readFileSync('./.jshintrc').toString().replace(/\/\/.*/g, '');
jshintOptions = JSON.parse(jshintOptions);
return gulp.src([
'gulpfile.js',
'./src/**/*.js',
'./test/**/*.js',
'!./src/jsondiffpatch*.js',
'!**/*_old.js'
])
.pipe(plumber())
.pipe(plugins.jshint(jshintOptions))
.pipe(plugins.jshint.reporter('jshint-stylish'))
.pipe(plugins.jshint.reporter('fail'))
.pipe(plumber());
});
var buildDependencies = ['lint'];
var bundle = function(options) {
var name = options.name || 'bundle';
var src = options.src || './src/main.js';
var minify = options.minify !== false;
gulp.task(name, ['clean'], function() {
if (fs.existsSync('./build/'+name+'.js') && (!minify || fs.existsSync('./build/'+name+'.min.js'))) {
console.log(name + ' already exists');
return;
}
var stream = gulp.src(src)
.pipe(plugins.replace('{{package-version}}', packageInfo.version))
.pipe(plugins.replace('{{package-homepage}}', packageInfo.homepage))
.pipe(plugins.browserify(options.browserifyOptions || {}))
.pipe(plugins.rename(name+'.js'))
.pipe(gulp.dest('./build'));
if (!minify) { return stream; }
return stream.pipe(plugins.uglify())
.pipe(plugins.rename(name+'.min.js'))
.pipe(gulp.dest('./build'));
});
buildDependencies.push(name);
};
bundle({
browserifyOptions: {
standalone: packageInfo.name,
exclude: '../../external/diff_match_patch_uncompressed'
}
});
bundle({
name: 'bundle-full',
browserifyOptions: {
standalone: packageInfo.name
}
});
bundle({
name: 'formatters',
src: './src/formatters/index.js',
browserifyOptions: {
standalone: packageInfo.name + '.formatters'
}
});
bundle({
name: 'test-bundle',
src: './test/test.js',
minify: false
});
gulp.task('copy-test-res', ['clean'], function() {
gulp.src('./node_modules/expect.js/index.js')
.pipe(plugins.rename('expect.js'))
.pipe(gulp.dest('./test-external'));
gulp.src('./node_modules/mocha/mocha.js')
.pipe(gulp.dest('./test-external'));
gulp.src('./node_modules/mocha/mocha.css')
.pipe(gulp.dest('./test-external'));
});
buildDependencies.push('copy-test-res');
gulp.task('build', buildDependencies, function() {
});
gulp.task('test', ['lint'], function () {
return gulp.src('./test/**.js')
.pipe(plumber())
.pipe(plugins.mocha({
grep: process.env.FILTER || undefined,
reporter: 'spec',
growl: true
}))
.pipe(plumber());
});
gulp.task('test-browser', ['build'], function() {
return gulp.src('./file-list-at-karma-conf-file')
.pipe(plugins.karma({
configFile: 'karma.conf.js',
browsers: browsers,
action: 'run'
}));
});
gulp.task('watch', ['test'], function() {
watching = true;
return gulp.watch(['external/**', 'src/**', 'test/**'], ['test'])
.on('error', gutil.log);
});