Skip to content

Commit 884b613

Browse files
author
Olufemi Adeyemi
committed
dcache-view (build): fix and update the build system
Motivation: gulp-vulcanize is deprecated and NPM security issues. Modification: - gulpfile.js - remove vulcanise and use polymer-build to bundle the custom elements. Factorise all the file copying tasks and use array called `copyAllArray` to list the source and destination of the file to be copied. - polymer.json - added to the project because it is needed by the new dependecy called polymer-build. - package.json - modified to reflect the necessay changes. All depend- ecies are on a fixed version. - package-lock.json - this is auto-generated - pom.xml - update the version of: a. frontend-maven-plugin to 1.6 b. node to 8.0.0 c. npm to 6.5.0 Result: The build system now work. No visible changes to the end-users. Target: master Request: 1.5 Request: 1.4 Require-notes: no Require-book: no Acked-by: Albert Rossi Reviewed at https://rb.dcache.org/r/11461/
1 parent 89eab84 commit 884b613

5 files changed

Lines changed: 6766 additions & 97 deletions

File tree

gulpfile.js

Lines changed: 80 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,86 @@
1-
var gulp = require('gulp');
2-
var vulcanize = require('gulp-vulcanize');
3-
var bower = require('gulp-bower');
4-
var gutil = require('gulp-util');
1+
'use strict';
52

6-
gulp.task('bower', function() {
7-
return bower();
8-
});
9-
10-
gulp.task('copy-favicons', function() {
11-
return gulp.src([
12-
'src/favicons/*'
13-
], {
14-
base: ''
15-
})
16-
.pipe(gulp.dest('./target/favicons'));
17-
});
3+
const gulp = require('gulp');
4+
const del = require('del');
5+
const mergeStream = require('merge-stream');
6+
const polymerBuild = require('polymer-build');
187

19-
gulp.task('copy-index', function() {
20-
return gulp.src([
21-
'src/index.html'
22-
], {
23-
base: ''
24-
})
25-
.pipe(gulp.dest('./target'));
26-
});
8+
const polymerJson = require('./polymer.json');
9+
const polymerProject = new polymerBuild.PolymerProject(polymerJson);
10+
const buildDirectory = 'target';
11+
const copyAllArray = [
12+
{"source" : "./src/robots.txt", "destination": buildDirectory},
13+
{"source" : "./src/index.html", "destination": buildDirectory},
14+
{"source" : "./src/favicons/*", "destination": `${buildDirectory}/favicons`},
15+
{"source" : "./src/styles/main.css", "destination": `${buildDirectory}/styles`},
16+
{"source" : "./target/elements/src/elements/elements.html", "destination": `${buildDirectory}/elements`},
17+
{"source" : "./src/scripts/**/*", "destination": `${buildDirectory}/scripts`, "exclude": ["./src/scripts/config.js"]},
18+
{"source" : "./src/bower_components/pdfjs-dist/build/**/*", "destination": `${buildDirectory}/bower_components/pdfjs-dist/build`},
19+
{"source" : "./src/bower_components/webcomponentsjs/webcomponents-loader.js", "destination": `${buildDirectory}/bower_components/webcomponentsjs`}
20+
];
2721

28-
gulp.task('copy-robots', function() {
29-
return gulp.src([
30-
'src/robots.txt'
31-
], {
32-
base: ''
22+
function waitFor(stream) {
23+
return new Promise((resolve, reject) => {
24+
stream.on('end', resolve);
25+
stream.on('error', reject);
26+
});
27+
}
28+
function copy(source, destination, exclude) {
29+
let arr;
30+
if (exclude && exclude !== "") {
31+
const len = exclude.length;
32+
for (let i=0; i<len; i++) {
33+
exclude[i] = `!${exclude[i]}`;
34+
}
35+
arr = [source, ...exclude]
36+
} else {
37+
arr = [source];
38+
}
39+
return gulp.src(arr, {base: ''})
40+
.pipe(gulp.dest(`${destination}`));
41+
}
42+
function build() {
43+
return new Promise((resolve, reject) => {
44+
let sourcesStreamSplitter = new polymerBuild.HtmlSplitter();
45+
let dependenciesStreamSplitter = new polymerBuild.HtmlSplitter();
46+
console.log(`Deleting ${buildDirectory} directory...`);
47+
del([buildDirectory])
48+
.then(() => {
49+
let sourcesStream = polymerProject.sources()
50+
.pipe(sourcesStreamSplitter.split())
51+
.pipe(sourcesStreamSplitter.rejoin());
52+
let dependenciesStream = polymerProject.dependencies()
53+
.pipe(dependenciesStreamSplitter.split())
54+
.pipe(dependenciesStreamSplitter.rejoin());
55+
let buildStream = mergeStream(sourcesStream, dependenciesStream)
56+
.once('data', () => {
57+
console.log('Analyzing build dependencies...');
58+
});
59+
buildStream = buildStream.pipe(polymerProject.bundler());
60+
buildStream = buildStream.pipe(gulp.dest(`${buildDirectory}/elements`));
61+
return waitFor(buildStream);
62+
})
63+
.then(() => {
64+
console.log('Bundling complete!');
65+
resolve();
66+
});
3367
})
34-
.pipe(gulp.dest('./target'));
68+
}
69+
gulp.task('copy-all', function (done) {
70+
console.log('Start copying files...');
71+
const len = copyAllArray.length;
72+
for (let i = 0; i < len; i++) {
73+
console.log(`copying ${copyAllArray[i].source} to ${copyAllArray[i].destination}`);
74+
copy(copyAllArray[i].source, copyAllArray[i].destination,
75+
copyAllArray[i].exclude ? copyAllArray[i].exclude: "")
76+
}
77+
console.log('Files copying completed!');
78+
done();
3579
});
36-
37-
gulp.task('copy-webcomponents', function() {
38-
return gulp.src([
39-
'./src/bower_components/webcomponentsjs/*'
40-
], {
41-
base: ''
42-
})
43-
.pipe(gulp.dest('./target/bower_components/webcomponentsjs'));
44-
});
45-
46-
gulp.task('copy-css', function() {
47-
return gulp.src([
48-
'src/styles/main.css'
49-
], {
50-
base: ''
51-
})
52-
.pipe(gulp.dest('./target/styles'));
80+
gulp.task('build', build);
81+
gulp.task('delete', function (done) {
82+
console.log(`Deleting ./target/elements/src directory...`);
83+
del(['./target/elements/src']);
84+
done();
5385
});
54-
55-
gulp.task('copy-scripts', function() {
56-
return gulp.src([
57-
'src/scripts/**/*',
58-
'!src/scripts/config.js'
59-
], {
60-
base: ''
61-
})
62-
.pipe(gulp.dest('./target/scripts'));
63-
});
64-
65-
gulp.task('copy-pdfjs', function() {
66-
return gulp.src([
67-
'./src/bower_components/pdfjs-dist/build/**/*'
68-
], {
69-
base: ''
70-
})
71-
.pipe(gulp.dest('./target/bower_components/pdfjs-dist/build'));
72-
});
73-
74-
gulp.task('vulcanize', function() {
75-
return gulp.src('src/elements/elements.html')
76-
.pipe(vulcanize({
77-
stripComments: true,
78-
inlineScripts: true,
79-
inlineCss: true
80-
}))
81-
.on('error', gutil.log)
82-
.pipe(gulp.dest('./target/elements'));
83-
});
84-
85-
gulp.task('build', ['copy-favicons', 'copy-index', 'copy-robots', 'copy-css', 'copy-scripts']);
86-
87-
gulp.task('default', ['bower', 'build'], function () {
88-
gulp.start('vulcanize','copy-webcomponents', 'copy-pdfjs');
89-
});
86+
gulp.task('default', gulp.series('build', 'copy-all', 'delete'));

0 commit comments

Comments
 (0)