forked from davidagraf/doi2bib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
134 lines (112 loc) · 3.61 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
'use strict';
var gulp = require('gulp');
var debug = require('gulp-debug');
var fs = require('fs');
var protractor = require('gulp-protractor').protractor;
/*jshint camelcase: false */
var webdriverUpdate = require('gulp-protractor').webdriver_update;
/*jshint camelcase: true */
var check = require('check-dependencies');
// load plugins
var $ = require('gulp-load-plugins')();
// check if dependencies are ok
check({
checkGitUrls: true
}, function(result) {
// Print the logged errors if dependencies are not ok
if (!result.depsWereOk && result.error) {
result.error.forEach(function(message) {
console.error(message);
});
process.exit(result.status);
}
});
gulp.task('jshint', function () {
return gulp.src(['*.js', 'app/**/*.js', 'public/scripts/**/*.js', 'test/**/*.js'])
.pipe($.jshint())
.pipe($.jshint.reporter(require('jshint-stylish')));
});
gulp.task('serve', ['jison'], function () {
$.nodemon({ script: 'app/server.js'});
gulp.watch('./utils/*.jison', ['jison']);
});
gulp.task('debug', ['jison'], function () {
$.run('iron-node app/server.js').exec();
gulp.watch('./utils/*.jison', ['jison']);
});
gulp.task('distapp', function() {
return gulp.src('app/**/*.js').pipe(gulp.dest('dist/app')).pipe($.size());
});
gulp.task('distpublic', ['jshint', 'jison'], function () {
var assets = $.useref.assets({searchPath: ['public', '.tmp/public']});
var jsFilter = $.filter('**/*.js', {restore: true});
var cssFilter = $.filter('**/*.css', {restore: true});
return gulp.src('public/**/*.html')
.pipe(assets)
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore)
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore)
.pipe(assets.restore())
.pipe($.useref())
.pipe(gulp.dest('dist/public'))
.pipe($.size());
});
gulp.task('distpackage', function() {
// TODO do it the gulp way
fs.readFile('package.json', function (err, data) {
if (err) {
console.log('Error: ' + err);
return;
}
data = JSON.parse(data);
data.devDependencies = [];
if (!fs.existsSync('dist')) {
fs.mkdirSync('dist');
}
fs.writeFile('dist/package.json', JSON.stringify(data, null, 2), function(err) {
if (err) {
console.log(err);
}
});
});
});
gulp.task('distimages', function () {
return gulp.src('public/imgs/**/*')
.pipe($.cache($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('dist/public/imgs'))
.pipe($.size());
});
gulp.task('distfonts', function () {
return gulp.src('public/bower_components/**/*.{eot,svg,ttf,woff,woff2}')
.pipe($.flatten())
.pipe(gulp.dest('dist/public/fonts'))
.pipe($.size());
});
gulp.task('jison', function() {
return gulp.src('./utils/*.jison')
.pipe($.jison({moduleName: 'bibparser', moduleType: 'js'}))
.pipe(gulp.dest('./.tmp/public/scripts/lib'));
});
gulp.task('dist', ['distapp', 'distpublic', 'distpackage', 'distfonts', 'distimages']);
gulp.task('clean', function () {
return gulp.src(['.tmp', 'dist'], { read: false }).pipe($.clean());
});
gulp.task('webdriver:update', webdriverUpdate);
gulp.task('protractor', ['webdriver:update', 'serve'], function() {
return gulp.src('test/e2e/**/*.js')
.pipe(protractor({
configFile: 'test/protractor-conf.js'
}))
.on('error', function(e) {throw e;})
.on('end', function() {
process.exit(); // top process when testing is over
});
});
gulp.task('test', ['jshint', 'protractor']);