This repository has been archived by the owner on Jul 9, 2022. It is now read-only.
forked from jeff-collins/ment.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
168 lines (138 loc) · 4.21 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
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var fs = require('fs');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
//var wrap = require('gulp-wrap');
var templateCache = require('gulp-angular-templatecache');
var gjshint = require('gulp-jshint');
var ngAnnotate = require('gulp-ng-annotate');
var stylish = require('jshint-stylish');
var port = gutil.env.port || 3000;
var covport = gutil.env.covport || 3001;
var lrport = gutil.env.lrport || 35729;
var openBrowser = gutil.env.browser;
var bump = require('gulp-bump');
/*
* Default task is to start the site
*/
gulp.task('default', ['site']);
gulp.task('site', ['copy', 'dist'], function () {
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) {
console.log('Reload', file.path);
lrServer.changed(file.path);
});
// open the browser
require('open')('http://localhost:' + port + '/ment.io', openBrowser);
console.log('Example app started on port [%s]', port);
});
});
gulp.task('dist', ['tpl'], function () {
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'));
});
gulp.task('jshint', function () {
return gulp.src('src/**/*.js')
.pipe(gjshint())
.pipe(gjshint.reporter(stylish));
});
gulp.task('tpl', function () {
return gulp.src('src/**/*.tpl.html')
.pipe(templateCache({
module: 'mentio'
}))
.pipe(gulp.dest('src'));
});
gulp.task('copy', function() {
gulp.src(['bower_components/angular-ui-tinymce/src/tinymce.js'])
.pipe(gulp.dest('ment.io'))
});
// Basic usage:
// Will patch the version
gulp.task('bump', function(){
gulp.src(['./package.json', './bower.json'])
.pipe(bump())
.pipe(gulp.dest('./'));
});
function testTask (params) {
var karma = require('gulp-karma');
var karmaConfig = {
configFile: './karma.conf.js',
action: params.isWatch ? 'watch' : 'run'
};
if (params.coverageReporter) {
karmaConfig.coverageReporter = params.coverageReporter;
}
if (params.reporters) {
karmaConfig.reporters = params.reporters;
}
return gulp.src('DO_NOT_MATCH') //use the files in the karma.conf.js
.pipe(karma(karmaConfig));
}
/**
* Run the karma spec tests
*/
gulp.task('test', ['copy', 'dist'], function () {
testTask({
isWatch: gutil.env.hasOwnProperty('watch')
});
});
gulp.task('coveralls', function () {
var coveralls = require('gulp-coveralls');
gulp.src('./coverage/**/lcov.info')
.pipe(coveralls());
});
gulp.task('coverage', function () {
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);
});