-
Notifications
You must be signed in to change notification settings - Fork 22
/
gulpfile.js
237 lines (202 loc) · 6.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
Copyright 2018 Iguazio Systems Ltd.
Licensed under the Apache License, Version 2.0 (the "License") with
an addition restriction as set forth herein. You may not use this
file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
In addition, you may not use the software for any purposes that are
illegal under applicable law, and the grant of the foregoing license
under the Apache 2.0 license is conditioned upon your compliance with
such restriction.
*/
//
// ******* Configuration and loading third party components *******
//
/* eslint-disable */
/**
* Load required components
*/
var babel = require('gulp-babel');
var config = require('./build.config');
var cache = require('gulp-file-transform-cache');
var gulp = require('gulp');
var concat = require('gulp-concat');
var eslint = require('gulp-eslint');
var argv = require('yargs').argv;
var minifyHtml = require('gulp-htmlmin');
var ngHtml2Js = require('gulp-ng-html2js');
var merge2 = require('merge2');
var imagemin = require('gulp-imagemin');
var del = require('del');
var vinylPaths = require('vinyl-paths');
var exec = require('child_process').exec;
var buildVersion = null;
var path = require('path');
/**
* Set up configuration
*/
var state = {
isForTesting: false
};
/**
* Set build for testing
*/
function setTesting(next) {
state.isForTesting = true;
next();
}
//
// ******* Tasks *******
//
gulp.task('build', build);
gulp.task('test-unit', testUnit);
//
// ******* Functions *******
//
/**
* Clean build directory
*/
function clean() {
return gulp.src([config.build_dir, config.cache_file], {allowEmpty: true})
.pipe(vinylPaths(del));
}
/**
* Build app.css (include all project less files)
*/
function appLess() {
var distFolder = config.assets_dir + '/less';
var task = gulp
.src(config.app_files.less_files, {allowEmpty: true})
.pipe(concat(config.output_files.app.less))
.pipe(gulp.dest(distFolder));
return task;
}
/**
* Build app.js (include all project js files and templates)
*/
function appJs() {
var distFolder = config.assets_dir + '/js';
var sourceFiles = config.app_files.js;
if (state.isForTesting) {
sourceFiles = config.test_files.unit.js_for_tests;
}
var js = gulp.src(sourceFiles, {allowEmpty: true})
.pipe(cache({
path: config.cache_file,
transformStreams: [
babel()
]
}));
var templates = gulp.src(config.app_files.templates, {allowEmpty: true})
.pipe(minifyHtml({
removeComments: true,
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
conservativeCollapse: true
}))
.pipe(ngHtml2Js({
moduleName: config.app_files.templates_module_name
}));
var task = merge2(js, templates)
.pipe(concat(config.output_files.app.js))
.pipe(gulp.dest(distFolder));
return task;
}
/**
* Copy all fonts to the build directory
*/
function fonts() {
var distFolder = config.assets_dir + '/fonts';
return gulp.src(config.source_dir + '/igz_controls/fonts/**/*', {allowEmpty: true})
.pipe(gulp.dest(distFolder));
}
/**
* Optimize all images and copy them to the build directory
*/
function images() {
var distFolder = config.assets_dir + '/images';
return gulp.src(config.source_dir + '/igz_controls/images/**/*', {allowEmpty: true})
.pipe(imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(distFolder));
}
/**
* Lint source code
*/
function lint() {
return gulp.src(config.app_files.js, {allowEmpty: true})
.pipe(eslint())
.pipe(eslint.format('compact'))
.pipe(eslint.failAfterError());
}
function i18n() {
var distFolder = config.assets_dir + '/i18n';
return gulp.src(config.app_files.i18n, {allowEmpty: true})
.pipe(gulp.dest(distFolder));
}
function injectVersion(done) {
exec('git describe --tags --abbrev=40', function (err, stdout) {
buildVersion = stdout;
});
done();
}
/**
* Run unit tests (Karma)
* Task for development environment only
*/
function testUnitRun(done) {
var karmaServer = require('karma').Server;
var files = config.test_files.unit.vendor.map(function (vendorPath) {
return __dirname + '/' + vendorPath;
})
.concat(__dirname + '/' + config.test_files.unit.modules)
.concat([__dirname + '/' + config.assets_dir + '/js/' + config.output_files.app.js])
.concat(__dirname + '/' + ((argv.spec !== undefined) ? 'src/**/' + argv.spec : config.test_files.unit.tests));
new karmaServer({
configFile: __dirname + '/' + config.test_files.unit.karma_config,
files: files,
action: 'run'
}, done).start();
}
/**
* Build vendor.less (include all vendor less files)
*/
function vendorLess() {
var distFolder = config.assets_dir + '/less';
return gulp.src(config.vendor_files.less, {allowEmpty: true})
.pipe(concat(config.output_files.vendor.less))
.pipe(gulp.dest(distFolder));
}
/**
* Build vendor.js (include all vendor js files)
*/
function vendorJs() {
var distFolder = config.assets_dir + '/js';
return gulp.src(config.vendor_files.js, {allowEmpty: true})
.pipe(concat(config.output_files.vendor.js))
.pipe(gulp.dest(distFolder));
}
/**
* Task for unit test running
* Task for development environment only
*/
function testUnit(next) {
gulp.series(setTesting, build, testUnitRun)(next);
}
//
// ******* Task chains *******
//
/**
* Base build task
*/
function build(next) {
gulp.series(lint, clean, injectVersion, vendorLess, vendorJs, gulp.parallel(appLess, appJs, fonts, images, i18n))(next);
}