-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
156 lines (124 loc) · 3.99 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
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
//Include gulp, and launch the task loader
var gulp = require('gulp');
var fs = require('fs-extra');
//Manage CLI flags
var args = require('yargs').argv;
//Get all the other modules necessary to build this out
var bump = require('gulp-bump');
var concat = require('gulp-concat');
var debug = require('gulp-debug');
var check = require('gulp-if');
var coveralls = require('gulp-coveralls');
var doc = require('gulp-jsdoc-to-markdown');
var forEach = require('gulp-foreach');
var karma = require('karma').server;
var open = require('gulp-open');
var regrep = require('gulp-regex-replace');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var uglify = require('gulp-uglify');
var util = require('gulp-util');
//Rename result folders
var splitPath = function(path){
var output = {};
//Get path segments
output.path = path.split('\\');
output.dir = output.path[output.path.length - 2];
output.fileName = output.path[output.path.length - 1];
output.fileType = output.fileName.lastIndexOf('.') > -1 ? output.fileName.substring(output.fileName.lastIndexOf('.')) : '';
output.path.pop();
return output;
};
//Generic unit testing options
var unitOpts = {
configFile: __dirname+'/test/config/karma.conf.js',
reporters: ['mocha', 'html']
};
//Jasmine tests, for simple in browser verification
gulp.task('jasmine', function() {
gulp.src(['./test/jasmine.html'])
.pipe(open('<%file.path%>'));
});
//Basic unit testing
gulp.task('unit-chrome', function(done) {
unitOpts.browsers = ['Chrome'];
unitOpts.htmlReporter = {
outputFile: 'test/results/spec/chrome.html'
};
return karma.start(unitOpts, done);
});
//Unit for browser compatibility
gulp.task('unit-browsers', function(done) {
unitOpts.browsers = ['Chrome', 'ChromeCanary', 'Firefox', 'FirefoxDeveloper', 'IE11', 'IE10', 'IE9'];
unitOpts.htmlReporter = {
outputFile: 'test/results/spec/compatibility.html'
};
return karma.start(unitOpts, done);
});
//Full Karma run-through for coverage
gulp.task('karma-coverage', function(done) {
var opts = {
configFile: __dirname+'/test/config/karma.coverage.js',
browsers: args.browsers ? [args.browsers] : ['Chrome'],
};
return karma.start(opts, done);
});
//Test for basic completeness and coverage
gulp.task('coverage', ['karma-coverage'], function() {
return gulp.src(['./test/results/coverage/Chrome*']) //'+ args.browser ? args.browser : 'Chrome' +'
.pipe(forEach(function(stream, file){
fs.copySync(file.path, splitPath(file.path).path.join('\\'));
fs.removeSync(file.path);
}))
});
//Make the markdown version of the API
gulp.task('api', function() {
return gulp.src(['./src/**/*.js'])
.pipe(doc())
.pipe(rename(function(path){
path.basename = "API";
path.extname = ".md";
}))
//.pipe(replace('##', '\n* * *\n###')) //Using v0.6.x of jsdoc-to-markdown plugin, this is no longer necessary
.pipe(replace('####', '\n* * *\n####'))
.pipe(replace(/^[\s\S]*?(?:###class: )/, '##API\n###')) //https://regex101.com/r/hO4fW4/2
.pipe(gulp.dest('./docs'))
});
//Make the readme file
gulp.task('docs', ['api'], function() {
return gulp.src(['./docs/INTRO.md', './docs/EXAMPLES.md', './docs/API.md', './docs/ENDNOTES.md', 'LICENSE.md'])
.pipe(concat('README.md'))
.pipe(gulp.dest('./'))
});
//Copy the original file to the dist folder
gulp.task('copy', ['docs'], function() {
return gulp.src(['./src/backbone-hashMate.js'])
.pipe(uglify({
output: {
beautify: true
},
compress: false,
mangle: false
}))
.pipe(gulp.dest('./dist'))
});
//Build this sucker!
gulp.task('build', ['copy'], function() {
return gulp.src(['./src/**/*.js'])
.pipe(uglify())
.pipe(rename(function(path){
path.basename += '.min';
}))
.pipe(gulp.dest('./dist'))
});
//Build, and bump the version
gulp.task('bump', ['build'], function() {
return gulp.src(['./package.json', './bower.json'])
.pipe(bump({type: args.vers || 'patch'}))
.pipe(gulp.dest('./'));
});
//Submit to coveralls
gulp.task('coveralls', function() {
gulp.src('./test/**/lcov.info')
.pipe(coveralls());
});