forked from dainst/idai-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
222 lines (198 loc) · 7.28 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
var gulp = require('gulp');
var del = require('del');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var reload = browserSync.reload;;
var modRewrite = require('connect-modrewrite');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var minifyCss = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var ngHtml2Js = require("gulp-ng-html2js");
var minifyHtml = require("gulp-minify-html");
var Server = require('karma').Server;
var replace = require('gulp-replace');
var babel = require('gulp-babel');
var pkg = require('./package.json');
var paths = {
'build': 'dist/',
'lib': 'node_modules/',
'bootstrap': 'node_modules/bootstrap-sass/assets/',
'bower': 'bower_components/',
'geonode': 'geonode_src/'
};
// compile sass and concatenate to single css file in build dir
gulp.task('sass', function() {
return gulp.src('src/idai-components.scss')
.pipe(sass({includePaths: [paths.bootstrap + 'stylesheets/'], precision: 8}))
.pipe(concat(pkg.name + '.css'))
.pipe(gulp.dest(paths.build + '/css'))
.pipe(reload({ stream:true }));
});
// minify css files in build dir
gulp.task('minify-css', ['sass'], function() {
return gulp.src([
paths.build + '/css/*.css',
paths.bower + 'select2/dist/css/select2.css',
])
.pipe(minifyCss())
.pipe(concat(pkg.name + '.min.css'))
.pipe(gulp.dest(paths.build + '/css'));
});
// minify leaflet css files in bower dir
gulp.task('minify-leaflet-css', function() {
return gulp.src([
paths.bower + 'leaflet/dist/leaflet.css',
paths.bower + 'leaflet-fullscreen/dist/leaflet.fullscreen.css',
paths.bower + 'Leaflet.ZoomBox/L.Control.ZoomBox.css',
paths.bower + 'leaflet-measure/dist/leaflet-measure.css',
paths.bower + 'Leaflet.NavBar/src/Leaflet.NavBar.css',
paths.bower + 'Leaflet.Coordinates/src/Control.Coordinates.css',
paths.geonode + 'css/idai-leafletstyles.css'
])
.pipe(replace('img/', '../img/'))
.pipe(replace('images/', '../img/'))
.pipe(replace('fullscreen.png', '../img/fullscreen.png'))
.pipe(minifyCss())
.pipe(concat('idai-leaflet.min.css'))
.pipe(gulp.dest(paths.build + '/css'));
});
// concatenates all js files in src into a single file in build dir
gulp.task('concat-js', function() {
return gulp.src(['src/_modules-and-constants.js','src/**/*.js'])
.pipe(concat(pkg.name + '-no-tpls.js'))
.pipe(gulp.dest(paths.build + '/js'))
.pipe(reload({ stream:true }));
});
// concatenates and minifies all dependecies into a single file in build dir
gulp.task('concat-deps', function() {
return gulp.src([
paths.lib + 'angular/angular.min.js',
paths.lib + 'angular-ui-bootstrap/dist/ui-bootstrap-tpls.js',
paths.lib + 'angular-route/angular-route.min.js',
paths.lib + 'angular-animate/angular-animate.min.js'
])
.pipe(concat(pkg.name + '-deps.js'))
.pipe(uglify())
.pipe(gulp.dest(paths.build + '/js'));
});
// concatenates and minifies all leaflet dependecies into a single file
gulp.task('concat-leaflet-js', function(){
return gulp.src([
paths.bower + 'leaflet/dist/leaflet-src.js',
paths.bower + 'leaflet-fullscreen/dist/leaflet.fullscreen.js',
paths.bower + 'Leaflet.ZoomBox/L.Control.ZoomBox.js',
paths.bower + 'leaflet-measure/dist/leaflet-measure.js',
paths.bower + 'leaflet.wms/src/leaflet.wms.js',
paths.bower + 'Leaflet.NavBar/src/Leaflet.NavBar.js',
paths.bower + 'Leaflet.Coordinates/src/util/NumberFormatter.js',
paths.bower + 'Leaflet.Coordinates/src/Control.Coordinates.js',
paths.bower + 'jquery/dist/jquery.js',
paths.bower + 'col-resizable/colResizable-1.6.js',
paths.bower + 'autolink/autolink-min.js',
paths.geonode + 'js/removeEmptyCells.js',
])
.pipe(concat('idai-leaflet-components.min.js'))
.pipe(uglify())
.pipe(gulp.dest(paths.build + '/js'));
});
// concatenates and minifies all Metadata dependecies into a single file
gulp.task('concat-metadata-js', function(){
gulp.src([ paths.geonode + 'js/idai_FE-format-layer-detail.js' ])
.pipe(concat('idai_FE-format-layer-detail.min.js'))
.pipe(uglify())
.pipe(gulp.dest(paths.build + '/js'));
return gulp.src([
paths.bower + 'select2/dist/js/select2.full.js',
paths.geonode + 'js/idai_BE-new-layer-meta.js'
])
.pipe(concat('idai_BE-metadata.min.js'))
.pipe(babel({
presets: ['es2015']
}))
.pipe(uglify())
.pipe(gulp.dest(paths.build + '/js'));
});
// minifies and concatenates js files in build dir
gulp.task('minify-js', ['concat-js', 'html2js'], function() {
gulp.src([paths.build + '/js/' + pkg.name + '-no-tpls.js',
paths.build + '/' + pkg.name + '-tpls.js'])
.pipe(concat(pkg.name + '.js'))
.pipe(gulp.dest(paths.build + '/js'))
.pipe(uglify())
.pipe(concat(pkg.name + '.min.js'))
.pipe(gulp.dest(paths.build + '/js'));
// concat cart.js with session cookie
return gulp.src([
paths.lib + 'angular-cookies/angular-cookies.js',
paths.geonode + 'js/cart_session.js'
])
.pipe(concat('cart_session.min.js'))
.pipe(uglify({mangle:false}))
.pipe(gulp.dest(paths.build + '/js'));
});
// converts, minifies and concatenates html partials
// in src to a single js file in build dir
gulp.task('html2js', function() {
return gulp.src('src/**/*.html')
.pipe(minifyHtml())
.pipe(ngHtml2Js({ moduleName: 'idai.templates', stripPrefix: 'src/' }))
.pipe(concat(pkg.name + '-tpls.js'))
.pipe(gulp.dest(paths.build + '/js'));
});
gulp.task('copy-fonts', function() {
return gulp.src(paths.bootstrap + '/fonts/**/*', { base: paths.bootstrap + '/fonts' })
.pipe(gulp.dest(paths.build + '/fonts'));
});
// Copy brand images and Leaflet-lib-images
gulp.task('copy-images',['minify-leaflet-css'],function() {
gulp.src([
paths.bower + '/leaflet/dist/images/**',
paths.bower + '/leaflet-fullscreen/dist/**',
paths.bower + '/leaflet-measure/dist/images/**',
paths.bower + '/Leaflet.NavBar/src/img/**',
'img/**'
])
.pipe(gulp.dest(paths.build+'/img'));
});
gulp.task('build', [
'sass',
'minify-css',
'concat-js',
'concat-deps',
'html2js',
'minify-js',
'copy-fonts',
'concat-leaflet-js',
'minify-leaflet-css',
'copy-images',
'concat-metadata-js',
]);
// clean
gulp.task('clean', function() {
return del(paths.build + '/**/*');
});
// runs the development server and sets up browser reloading
gulp.task('server', ['sass', 'concat-js', 'html2js', 'copy-fonts'], function() {
browserSync({
server: {
baseDir: '.',
middleware: [
// rewrite for AngularJS HTML5 mode, redirect all non-file urls to index.html
modRewrite(['!\\.html|\\.js|\\.svg|\\.css|\\.png|\\.jpg|\\.gif|\\.json|\\.woff2|\\.woff|\\.ttf$ /index.html [L]']),
]
},
port: 8084
});
gulp.watch('src/**/*.scss', ['sass']);
gulp.watch('src/**/*.js', ['concat-js']);
gulp.watch('src/**/*.html', ['html2js']);
gulp.watch(['index.html',
'demo/**/*.html',
'partials/**/*.html',
'src/**/*.html',
'js/*.js'], reload);
});
gulp.task('default', function() {
runSequence('clean', 'test', 'build');
});