-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
178 lines (145 loc) · 5.08 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//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');
//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;
};
//Jasmine tests, for simple in browser verification
gulp.task('jasmine', function() {
gulp.src(['./test/jasmine.html'])
.pipe(open('<%file.path%>'));
});
//Test for browser compatibility
gulp.task('browsers', function(done) {
var opts = {
configFile: __dirname+'/karma.conf.js',
singleRun: true,
browsers: ['PhantomJS', 'Chrome', 'ChromeCanary', 'Firefox', 'FirefoxDeveloper', 'IE11', 'IE10', 'IE9'],
reporters: ['mocha', 'html'],
preprocessors: {}
};
return karma.start(opts, done);
});
//USED FOR OLD karma-html-reporter plugin; since switching to karma-html-file-reporter, this is no longer necessary
/*gulp.task('compatibility', ['karma-compatibility'], function() {
console.log('./test/browser/'+ (typeof args.open === 'string' ? args.open+'*' : '*') +'/index.html');
//return gulp.src(['./test/browser/'+ (typeof args.open === 'string' ? args.open+'*' : '*') +'/index.html'])
.pipe(forEach(function(stream, file){
var output, justOS, justBrowser, segments, newName, pathing, dirContents;
//Get path segments
console.log(file.path);
output = splitPath(file.path);
output.path.pop();
//Create the appropriate names
justOS = output.dir.match(/ \(.*\)/i);
justBrowser = output.dir.replace(/ \(.*\)/i, '');
segments = justBrowser.split('.');
newName = (segments.length < 3 ? segments.join('.') : segments[0] +'.'+ segments[1]);// + ((justOS && justOS[0]) || '');
//Move the files, and clear the old directories
console.log(newName);
if (newName && output.fileType){
pathing = output.path.join('\\');
console.log(pathing +'\\'+ newName + output.fileType);
fs.renameSync(file.path, pathing +'\\'+ newName + output.fileType);
dirCotnents = fs.readdirSync(pathing +'\\'+ output.dir);
if ( !dirContents || !dirContents.length ){
fs.rmdirSync(pathing +'\\'+ output.dir);
}
}
}))
.pipe(check(args.open, open('<%file.path%>')));
});*/
//Full Karma run-through for coverage
gulp.task('karma-coverage', function(done) {
var opts = {
configFile: __dirname+'/karma.conf.js',
singleRun: true,
browsers: args.browsers ? [args.browsers] : ['PhantomJS'],
reporters: ['mocha', 'coverage'],
};
return karma.start(opts, done);
});
//Test for basic completeness and coverage
gulp.task('coverage', ['karma-coverage'], function() {
return gulp.src(['./test/results/Phantom*']) //'+ args.browser ? args.browser : 'Phantom' +'
.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/textStack.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('#class: TextStack', '# API'))
//.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/NOTES.md', './docs/API.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/textStack.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'))
});
//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());
});