forked from nemerosa/ontrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
328 lines (276 loc) · 10 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
var gulp = require('gulp');
var less = require('gulp-less');
var minifyCss = require('gulp-minify-css');
var concat = require('gulp-concat');
var liveReload = require('gulp-livereload');
var inject = require('gulp-inject');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var series = require('stream-series');
var templateCache = require('gulp-angular-templatecache');
var ngAnnotate = require('gulp-ng-annotate');
var ngFilesort = require('gulp-angular-filesort');
var debug = require('gulp-debug');
var minimist = require('minimist');
var del = require('del');
var babel = require("gulp-babel");
var sourcemaps = require('gulp-sourcemaps');
// Arguments
var knownOptions = {
string: 'version',
default: {version: 'snapshot'}
};
var options = minimist(process.argv.slice(2), knownOptions);
// Paths
var web = 'src';
var webPath = './' + web;
var assetResources = webPath + '/assets/**';
var extensionAssetResources = [webPath + '/extension/**/*.png'];
var graphiqlJsResources = webPath + '/graphiql/*.js';
var graphiqlCssResources = webPath + '/graphiql/*.css';
var graphiqlIndexResource = webPath + '/graphiql.html';
var lessResources = webPath + '/less/*.less';
var jsResources = webPath + '/app/**/*.js';
var templateResources = webPath + '/app/**/*.html';
var indexResource = webPath + '/index.html';
var vendor = './vendor';
var build = 'build/web';
var buildPath = build + '/dev';
var buildTemplates = buildPath + '/templates';
var buildConvertedJs = buildPath + '/converted';
var buildAngular = buildPath + '/angular';
var buildCss = buildPath + '/css';
var outputPath = build + '/prod';
var output = './' + outputPath;
var outputCss = './' + outputPath + '/css';
var outputJs = './' + outputPath + '/js';
var outputFonts = './' + outputPath + '/fonts';
var outputAssets = './' + outputPath + '/assets';
var outputExtensionAssets = './' + outputPath + '/extension/';
var outputGraphiql = './' + outputPath + '/graphiql/';
// Vendor resources
var vendorJsResources = [
'jquery/dist/jquery.js',
'jquery-ui/jquery-ui.js',
'angular/angular.js',
'angular-ui-router/release/angular-ui-router.js',
'angular-ui-sortable/sortable.js',
'angular-multi-select/angular-multi-select.js',
'angular-taglist/js/angular-taglist-directive.js',
'angular-sanitize/angular-sanitize.js',
'angular-bootstrap/ui-bootstrap-tpls.js',
'moment/min/moment.min.js',
'oclazyload/dist/ocLazyLoad.min.js',
'unibabel/index.js'
].map(function (rel) {
return vendor + '/' + rel;
});
var vendorCssResources = [
'angular-multi-select/angular-multi-select.css',
'angular-taglist/css/angular-taglist-directive.css'
].map(function (rel) {
return vendor + '/' + rel;
});
var graphiqlVendorJsResources = [
'fetch/fetch.js',
'react/react.min.js',
'react/react-dom.min.js'
].map(function (rel) {
return vendor + '/' + rel;
});
// Cleaning
gulp.task('clean', function () {
return del([build]);
});
// Javascript handling
gulp.task('lint', function () {
return gulp.src(jsResources)
.pipe(debug({title: 'lint:'}))
.pipe(jshint({esversion: 6}))
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
.pipe(liveReload());
});
gulp.task('templates', function () {
return gulp.src(templateResources)
.pipe(debug({title: 'templates:'}))
.pipe(templateCache({module: 'ontrack', root: 'app/'}))
.pipe(gulp.dest(buildTemplates))
.pipe(liveReload());
});
/**
* Converted files
*/
gulp.task('js:conversion', ['lint'], function () {
return gulp.src(jsResources)
.pipe(debug({title: 'js:conversion:input'}))
.pipe(babel())
.pipe(gulp.dest(buildConvertedJs))
.pipe(debug({title: 'js:conversion:output'}));
});
/**
* Sorted and annotated Angular files
*/
gulp.task('js:angular', ['lint', 'js:conversion', 'templates'], function () {
return gulp.src([buildTemplates + '/*.js', buildConvertedJs + '/**/*.js'])
.pipe(debug({title: 'js:angular:input'}))
.pipe(ngAnnotate())
.pipe(ngFilesort())
.pipe(sourcemaps.init())
.pipe(concat('ci-angular.js'))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(buildAngular))
.pipe(debug({title: 'js:angular:output'}));
});
gulp.task('js:concat', ['js:angular'], function () {
var jsSource = vendorJsResources;
jsSource.push(buildAngular + '/*.js');
return gulp.src(jsSource)
.pipe(debug({title: 'js:concat:input'}))
.pipe(concat('ci-' + options.version + '.js'))
.pipe(uglify())
.pipe(gulp.dest(outputJs))
.pipe(debug({title: 'js:concat:output'}))
;
});
// Translating Less into Minified CSS
gulp.task('less', function () {
return gulp.src(lessResources)
.pipe(debug({title: 'less:input:'}))
.pipe(less())
.pipe(debug({title: 'less:output:'}))
.pipe(concat('ci-' + options.version + '.css'))
.pipe(gulp.dest(buildCss))
.pipe(liveReload());
});
// Concatenation of all CSS files, including the one generated from less
gulp.task('css:concat', function () {
return series(
gulp.src(lessResources)
.pipe(debug({title: 'less:input:'}))
.pipe(less())
.pipe(debug({title: 'less:output:'})),
gulp.src(vendorCssResources)
)
.pipe(debug({title: 'css:concat:input'}))
.pipe(minifyCss())
.pipe(concat('ci-' + options.version + '.css'))
.pipe(debug({title: 'css:concat:output'}))
.pipe(gulp.dest(outputCss));
});
// Fonts
gulp.task('fonts', function () {
return gulp
.src([
vendor + '/font-awesome/fonts/*.*',
vendor + '/bootstrap/fonts/*.*'
])
.pipe(debug({title: 'fonts:input'}))
.pipe(gulp.dest(outputFonts));
});
// Copy of assets
gulp.task('assets', function () {
return gulp
.src(assetResources)
.pipe(debug({title: 'assets:input'}))
.pipe(gulp.dest(outputAssets));
});
gulp.task('extensionAssets', function () {
return gulp
.src(extensionAssetResources)
.pipe(debug({title: 'assets:input:extensions'}))
.pipe(gulp.dest(outputExtensionAssets));
});
// Injection in index.html
gulp.task('index:dev', ['less', 'fonts', 'js:conversion', 'templates'], function () {
var cssSources = gulp.src([buildCss + '/*.css'], {read: false});
var vendorJsSources = gulp.src(vendorJsResources, {read: false});
var vendorCssSources = gulp.src(vendorCssResources, {read: false});
var appSources = gulp.src([buildTemplates + '/*.js', buildConvertedJs + '/**/*.js']).pipe(ngFilesort());
return gulp.src(indexResource)
.pipe(debug({title: 'index:dev:input'}))
.pipe(inject(
series(
cssSources,
vendorJsSources,
vendorCssSources,
appSources
),
{relative: false, ignorePath: [outputPath, web, buildPath], addRootSlash: false}))
.pipe(gulp.dest(buildPath))
.pipe(debug({title: 'index:dev:output'}))
.pipe(liveReload());
});
gulp.task('index:prod', ['css:concat', 'assets', 'fonts', 'templates', 'js:concat'], function () {
var cssSources = gulp.src([outputCss + '/*.css'], {read: false});
var jsSources = gulp.src(outputJs + '/*.js', {read: false});
return gulp.src(indexResource)
.pipe(debug({title: 'index:prod:input'}))
.pipe(inject(
series(
cssSources,
jsSources
),
{relative: false, ignorePath: [outputPath, web, buildPath], addRootSlash: false}))
.pipe(gulp.dest(output))
.pipe(debug({title: 'index:prod:output'}));
});
// Injection in graphiql.html
gulp.task('graphiql:dev', [], function () {
var cssSources = gulp.src([graphiqlCssResources], {read: false});
var jsSources = graphiqlVendorJsResources;
jsSources.push(graphiqlJsResources);
return gulp.src(graphiqlIndexResource)
.pipe(debug({title: 'graphiql:dev:input'}))
.pipe(inject(
series(
cssSources,
gulp.src(jsSources, {read: false})
),
{relative: false, ignorePath: [outputPath, web, buildPath], addRootSlash: false}))
.pipe(gulp.dest(buildPath))
.pipe(debug({title: 'graphiql:dev:output'}))
.pipe(liveReload());
});
gulp.task('graphiql:prod:css', [], function () {
return gulp
.src(graphiqlCssResources)
.pipe(debug({title: 'graphiql:prod:css:input'}))
.pipe(concat('ci-graphiql-' + options.version + '.css'))
.pipe(gulp.dest(outputGraphiql));
});
gulp.task('graphiql:prod:js', [], function () {
var jsSources = graphiqlVendorJsResources;
jsSources.push(graphiqlJsResources);
return gulp.src(jsSources)
.pipe(debug({title: 'graphiql:prod:js:input'}))
.pipe(concat('ci-graphiql-' + options.version + '.js'))
.pipe(gulp.dest(outputGraphiql))
.pipe(debug({title: 'graphiql:prod:js:output'}))
;
});
gulp.task('graphiql:prod:index', ['graphiql:prod:css', 'graphiql:prod:js'], function () {
var cssSources = gulp.src([outputGraphiql + '/*.css'], {read: false});
var jsSources = gulp.src([outputGraphiql + '/*.js'], {read: false});
return gulp.src(graphiqlIndexResource)
.pipe(debug({title: 'graphiql:prod:input'}))
.pipe(inject(
series(
cssSources,
jsSources
),
{relative: false, ignorePath: [outputPath, web, buildPath], addRootSlash: false}))
.pipe(gulp.dest(output))
.pipe(debug({title: 'graphiql:prod:output'}));
});
// Default build
gulp.task('dev', ['index:dev', 'graphiql:dev', 'fonts']);
gulp.task('default', ['index:prod', 'graphiql:prod:index', 'assets', 'extensionAssets', 'fonts']);
// Watch setup
gulp.task('watch', function () {
liveReload.listen();
gulp.watch(lessResources, ['less']);
gulp.watch(indexResource, ['index:dev']);
gulp.watch(jsResources, ['index:dev']);
gulp.watch(templateResources, ['templates']);
});