-
Notifications
You must be signed in to change notification settings - Fork 14
/
gulpfile.js
189 lines (167 loc) · 6.06 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
179
180
181
182
183
184
185
186
187
188
189
(function () {
'use strict';
////
//// Usage: node ./node_modules/.bin/gulp <TARGET>
//// Current top targets:
//// - bundle: create the distribution files in production mode
//// - dev-bundle: create the distribution files in development mode
//// - tests: run the unit tests
////
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var rename = require("gulp-rename");
var mocha = require('gulp-mocha'); // Keep in mind that this is just a thin wrapper around Mocha and your issue is most likely with Mocha
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify-es').default;
var cssnano = require('gulp-cssnano');
var concat = require('gulp-concat');
var replace = require('gulp-replace');
var eslint = require('gulp-eslint');
// var jshint = require('gulp-jshint');
var fileinclude = require('gulp-file-include');
// bundling config
var config = {
eslint: {
source: ['./js/*.js']
},
// jshint: {
// source: ['./js/*.js']
// },
tests: {
source: ['./tests/mocha/*.test.js']
},
dist: './dist/', // output folder is a string, not an array
js: {
source: './js/phenogrid.js',
target: 'phenogrid-bundle.js'
},
css: {
source: [
'./node_modules/normalize.css/normalize.css',
'./node_modules/font-awesome/css/font-awesome.css',
'./node_modules/jquery-ui/themes/base/core.css',
'./node_modules/jquery-ui/themes/base/accordion.css',
'./node_modules/jquery-ui/themes/base/autocomplete.css',
'./node_modules/jquery-ui/themes/base/button.css',
'./node_modules/jquery-ui/themes/base/checkboxradio.css',
'./node_modules/jquery-ui/themes/base/controlgroup.css',
'./node_modules/jquery-ui/themes/base/datepicker.css',
'./node_modules/jquery-ui/themes/base/dialog.css',
'./node_modules/jquery-ui/themes/base/draggable.css',
'./node_modules/jquery-ui/themes/base/menu.css',
'./node_modules/jquery-ui/themes/base/progressbar.css',
'./node_modules/jquery-ui/themes/base/resizable.css',
'./node_modules/jquery-ui/themes/base/selectable.css',
'./node_modules/jquery-ui/themes/base/selectmenu.css',
'./node_modules/jquery-ui/themes/base/sortable.css',
'./node_modules/jquery-ui/themes/base/slider.css',
'./node_modules/jquery-ui/themes/base/spinner.css',
'./node_modules/jquery-ui/themes/base/tabs.css',
'./node_modules/jquery-ui/themes/base/tooltip.css',
'./node_modules/jquery-ui/themes/base/theme.css',
'./css/phenogrid.css'
],
replace: {
search: '../fonts/', // change fonts path in font-awesome.css
replace: 'fonts/'
},
target: 'phenogrid-bundle.css'
},
images: {
source: './node_modules/jquery-ui/themes/base/images/*',
target: 'images/'
},
fonts: {
source: './node_modules/font-awesome/fonts/*',
target: 'fonts/'
}
};
// // JSHint
// gulp.task("lint", function() {
// return gulp.src(config.jshint.source)
// .pipe(jshint())
// .pipe(jshint.reporter("jshint-stylish"));
// //.pipe(jshint.reporter("fail"));
// });
// ESLint
gulp.task("lint", function() {
return gulp.src(config.eslint.source)
.pipe(eslint());
});
// Bundle JS together with browserify
gulp.task('js-bundle', function(cb) {
var bundleStream = browserify(config.js.source).bundle();
bundleStream
.pipe(source(config.js.source))
.pipe(streamify(uglify())) // Minify JS
.pipe(rename(config.js.target))
.pipe(gulp.dest(config.dist))
.on('end', cb);
});
// No minify for dev bundle
gulp.task('js-dev-bundle', function(cb) {
var bundleStream = browserify(config.js.source).bundle();
bundleStream
.pipe(source(config.js.source))
.pipe(rename(config.js.target))
.pipe(gulp.dest(config.dist))
.on('end', cb);
});
// Bundle CSS together with gulp concat
gulp.task('css-bundle', function(cb) {
return gulp.src(config.css.source)
.pipe(concat(config.css.target))
.pipe(replace(config.css.replace.search, config.css.replace.replace)) // change fonts path in font-awesome.css
.pipe(cssnano()) //Minify CSS
.pipe(gulp.dest(config.dist));
});
// No minify for dev bundle
gulp.task('css-dev-bundle', function(cb) {
return gulp.src(config.css.source)
.pipe(concat(config.css.target))
.pipe(replace(config.css.replace.search, config.css.replace.replace)) // change fonts path in font-awesome.css
.pipe(gulp.dest(config.dist));
});
// Get rid of anything that is transient.
gulp.task('clean', function(cb) {
cb(null);
});
// Copy font-awesome fonts used in font-awesome.css
// since we've already replaced '../fonts/' with 'fonts/' in the bundled CSS file,
// we can put the fonts folder inside dist/ now
gulp.task('copy-font-awesome-fonts', function(cb) {
return gulp.src(config.fonts.source)
.pipe(gulp.dest(config.dist + config.fonts.target));
});
// Copy jquery-ui images used in jquery-ui.css
gulp.task('copy-jquery-ui-images', function(cb) {
return gulp.src(config.images.source)
.pipe(gulp.dest(config.dist + config.images.target));
});
// Testing with mocha/chai
gulp.task('test', function() {
return gulp.src(config.tests.source, {read: false}).pipe(mocha({
reporter: 'spec' // or 'nyan'
}));
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', function() {
console.log("Please specify the task name!");
});
// The default task is to build the different distributions.
gulp.task('bundle', gulp.series(
'js-bundle',
'css-bundle',
'copy-font-awesome-fonts',
'copy-jquery-ui-images'
));
// an alternate task that won't uglify. useful for debugging
gulp.task('dev-bundle', gulp.series(
'lint',
'js-dev-bundle',
'css-dev-bundle',
'copy-font-awesome-fonts',
'copy-jquery-ui-images'
));
}());