This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
151 lines (138 loc) · 4.33 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
var gulp = require('gulp'),
pump = require('pump'),
exec = require('child_process').exec,
autoprefixer = require('autoprefixer'),
browserify = require('browserify'),
buffer = require('vinyl-buffer'),
concat = require('gulp-concat'),
csso = require('postcss-csso'),
del = require('del'),
postcss = require('gulp-postcss'),
replace = require('gulp-replace'),
source = require('vinyl-source-stream'),
sourcemaps = require('gulp-sourcemaps'),
sync = require('browser-sync').create(),
uglify = require('gulp-uglify'),
saveLicense = require('uglify-save-license'),
util = require('gulp-util');
var production = util.env.production;
// Start a Web server
gulp.task('default', ['build'], function () {
sync.init({
ui: false,
notify: false,
server: { baseDir: 'build' },
});
gulp.watch('*.html', ['html']);
gulp.watch('src/*', ['scripts']);
gulp.watch('styles/*', ['styles']);
gulp.watch(['*.json', 'queries/**/*.sparql'], ['queries']);
});
// Remove all generated files
gulp.task('clean', function () {
return del(['build', 'deps/*-browser*.js*']);
});
// Create build/*
gulp.task('build', ['html', 'queries', 'scripts', 'styles']);
// Create build/index.html with images
gulp.task('html', function (done) {
pump([
gulp.src(['*.html', 'images/*.*', 'favicon.ico'], { base: './' }),
gulp.dest('build'),
sync.stream(),
], done);
});
// Create build/queries.json
gulp.task('queries', function (done) {
exec('./queries-to-json', function (error) {
if (error)
return done(error);
pump([
gulp.src('queries.json'),
gulp.dest('build'),
sync.stream(),
], done);
});
});
// Create build/scripts/*
gulp.task('scripts', ['scripts:ui', 'scripts:worker']);
// Create build/scripts/ldf-client-ui-packaged.js with source map
gulp.task('scripts:ui', ['deps:n3'], function (done) {
pump([
gulp.src([
'deps/jquery-2.1.0.js',
'deps/chosen-1.1.0.js',
'deps/fast-scroller.js',
'deps/n3-browser.js',
'src/ldf-client-ui.js',
'src/ldf-client-url-state.js',
], { base: './' }),
sourcemaps.init({ loadMaps: true }),
concat('ldf-client-ui.min.js'),
production ? uglify({ output: { comments: saveLicense } }) : util.noop(),
sourcemaps.write('./', { sourceRoot: '../' }),
gulp.dest('build/scripts'),
sync.stream(),
], done);
});
// Create build/scripts/ldf-client-worker.js with source map
gulp.task('scripts:worker', ['deps:ldf-client'], function (done) {
pump([
gulp.src([
'deps/ldf-client-browser.js',
'src/ldf-client-worker.js',
], { base: './' }),
sourcemaps.init({ loadMaps: true }),
concat('ldf-client-worker.min.js'),
// Correct lodash from window (browser) to self (Web Worker)
replace(/var root =.*;/, 'var root = self;'),
production ? uglify({ output: { comments: saveLicense } }) : util.noop(),
sourcemaps.write('./', { sourceRoot: '../' }),
gulp.dest('build/scripts'),
sync.stream(),
], done);
});
// Create deps/ldf-client-browser.js with source map
gulp.task('deps:ldf-client', function (done) {
browerifyDependency('ldf', 'ldf-client', { exclude: ['stream'] }, done);
});
// Create deps/n3-browser.js with source map
gulp.task('deps:n3', function (done) {
browerifyDependency('N3', 'n3', { exclude: [
// The UI only uses the writer
'util', 'stream',
'n3/lib/N3Lexer.js', 'n3/lib/N3Parser.js',
'n3/lib/N3Store.js', 'n3/lib/N3Util.js',
] }, done);
});
// Browserifies the module and save it as a dependency
function browerifyDependency(name, entry, options, done) {
// Browserify the module
var module = browserify({ debug: true, standalone: name }, { base: './' });
module.add('node_modules/' + entry);
options.exclude.forEach(function (excluded) {
module.exclude(excluded);
module.exclude('/node_modules/' + excluded);
});
// Save as a dependency with a source map
pump([
module.bundle(),
source(entry + '-browser.js'),
buffer(),
sourcemaps.init({ loadMaps: true }),
sourcemaps.write('./', { sourceRoot: '../' + entry }),
gulp.dest('deps'),
], done);
}
// Create build/styles/*.css with source map
gulp.task('styles', function (done) {
pump([
gulp.src('styles/*.css'),
postcss([
autoprefixer,
csso,
]),
gulp.dest('build/styles'),
sync.stream(),
], done);
});