-
Notifications
You must be signed in to change notification settings - Fork 219
/
gulpfile.js
168 lines (137 loc) · 4.03 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
'use strict';
const { series } = require('gulp');
var gulp = require('gulp');
var log = require('fancy-log');
var fs = require('fs');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var argv = require('minimist')(process.argv);
var templateCache = require('gulp-angular-templatecache');
var gjshint = require('gulp-jshint');
var ngAnnotate = require('gulp-ng-annotate');
var stylish = require('jshint-stylish');
var port = 3000;
var covport = 3001;
var lrport = 35729;
var openBrowser;
var bump = require('gulp-bump');
async function tpl() {
return gulp.src('src/**/*.tpl.html')
.pipe(templateCache({
module: 'mentio'
}))
.pipe(gulp.dest('src'));
};
function dist () {
return gulp.src([
'src/mentio.directive.js',
'src/mentio.service.js',
'src/templates.js'
])
.pipe(gjshint())
.pipe(gjshint.reporter(stylish))
.pipe(ngAnnotate())
.pipe(concat('mentio.js'))
.pipe(gulp.dest('dist'))
.pipe(uglify())
.pipe(concat('mentio.min.js'))
.pipe(gulp.dest('dist')).on('end', function(){ log('Done!'); });
};
async function copy() {
gulp.src(['bower_components/angular-ui-tinymce/src/tinymce.js'])
.pipe(gulp.dest('ment.io'))
};
async function site () {
var express = require('express');
var app = express();
app.use(require('connect-livereload')({
port: lrport
}));
app.use(express.static('./'));
app.listen(port, function () {
var lrServer = require('gulp-livereload')();
gulp.watch(['src/**/*.*', 'ment.io/*.*'], dist).on('change', function (file) {
log('Reload', file.path);
lrServer.changed(file.path);
});
// open the browser
require('open')('http://localhost:' + port + '/ment.io', openBrowser);
log('Example app started on port [%s]', port);
});
};
async function jshint() {
return gulp.src('src/**/*.js')
.pipe(gjshint())
.pipe(gjshint.reporter(stylish));
};
// Basic usage:
// Will patch the version
async function bump(){
gulp.src(['./package.json', './bower.json'])
.pipe(bump())
.pipe(gulp.dest('./'));
};
function testTask (params) {
var karma = require('karma');
var karmaConfig = {
configFile: __dirname + '/karma.conf.js',
action: params.isWatch ? 'watch' : 'run',
singleRun: true
};
if (params.coverageReporter) {
karmaConfig.coverageReporter = params.coverageReporter;
}
if (params.reporters) {
karmaConfig.reporters = params.reporters;
}
new karma.Server(karmaConfig).start();
}
/**
* Run the karma spec tests
*/
async function test() {
testTask({
isWatch: false
});
};
async function coveralls() {
var coveralls = require('gulp-coveralls');
gulp.src('./coverage/**/lcov.info')
.pipe(coveralls());
};
async function coverage() {
var express = require('express');
var app = express();
var coverageFile;
var karmaHtmlFile;
function getTestFile (path) {
if (fs.existsSync(path)) {
var files = fs.readdirSync(path);
if (files) {
for (var i = 0; i < files.length; i++) {
if (fs.lstatSync(path + '/' + files[i]).isDirectory()) {
return files[i];
} else {
return files[i];
}
}
}
}
}
testTask({
isWatch: gutil.env.hasOwnProperty('watch'),
reporters: ['progress', 'coverage', 'threshold']
});
setTimeout(function () {
coverageFile = getTestFile('coverage');
karmaHtmlFile = getTestFile('karma_html');
app.use(express.static('./'));
app.listen(covport, function openPage () {
if (coverageFile) {
require('open')('http://localhost:' + covport + '/coverage/' + coverageFile);
}
});
}, 3000);
};
exports.test = series(copy, tpl, dist, test);
exports.default = series(copy, tpl, dist, site);