forked from Maps4HTML/MapML.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
224 lines (221 loc) · 6.67 KB
/
Gruntfile.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
module.exports = function(grunt) {
const Diff = require('diff');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
cssmin: {
options: {
mergeIntoShorthands: false,
roundingPrecision: -1
},
combine: {
files: {
'dist/mapml.css': ['node_modules/leaflet/dist/leaflet.css', 'node_modules/leaflet.locatecontrol/dist/L.Control.Locate.css', 'src/mapml.css']
}
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
sourceMap: {
includeSources: true
}
},
dist: {
files: {
'dist/mapml.js': ['<%= rollup.main.dest %>'],
'dist/web-map.js': ['src/web-map.js'],
'dist/mapml-viewer.js': ['src/mapml-viewer.js'],
'dist/map-caption.js': ['src/map-caption.js'],
'dist/map-feature.js': ['src/map-feature.js'],
'dist/map-extent.js': ['src/map-extent.js'],
'dist/map-input.js': ['src/map-input.js'],
'dist/map-link.js': ['src/map-link.js'],
'dist/map-area.js': ['src/map-area.js'],
'dist/layer.js': ['src/layer.js'],
'dist/leaflet.js': ['dist/leaflet-src.js',
'dist/proj4-src.js',
'dist/proj4leaflet.js',
'dist/L.Control.Locate.js']
}
}
},
jshint: {
files: ['Gruntfile.js', 'src/**/*.js','test/**/*.spec.js'],
options: {
// options here to override JSHint defaults
globals: {
console: true,
module: true,
document: true
},
// ensure that jshint keeps processing after an error
force: true,
esversion: 11,
laxbreak: true // used to fix differences with prettier
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
},
copy : {
main : {
files: [
{
expand: true,
cwd: 'node_modules/leaflet/dist/',
flatten: true,
filter: 'isFile',
src: ['leaflet-src.js'],
dest: 'dist/'
},
{
expand: true,
cwd: 'node_modules/proj4/dist/',
flatten: true,
filter: 'isFile',
src: ['proj4-src.js'],
dest: 'dist/'
},
{
expand: true,
cwd: 'node_modules/proj4leaflet/src/',
flatten: true,
filter: 'isFile',
src: ['proj4leaflet.js'],
dest: 'dist/'
},
{
expand: true,
flatten: true,
filter: 'isFile',
src: ['index.html'],
dest: 'dist/'
},
{
expand: true,
cwd: 'node_modules/leaflet.locatecontrol/src/',
flatten: true,
filter: 'isFile',
src: ['L.Control.Locate.js'],
dest: 'dist/'
}
],
options: {
process: function (content, srcpath) {
// see patch.diff file for comments on why patching is necessary
if (srcpath.includes('proj4leaflet.js')) {
console.log('PATCHING: ', srcpath);
const patch = grunt.file.read('src/proj4leaflet/patch.diff');
return Diff.applyPatch(content, patch);
} else if (srcpath.includes('proj4-src.js')) {
console.log('PATCHING: ', srcpath);
const patch = grunt.file.read('src/proj4/patch.diff');
return Diff.applyPatch(content, patch);
} else if (srcpath.includes('index.html')) {
console.log('MODIFYING: ', srcpath);
var pathToModuleRE = /dist\/mapml-viewer\.js/gi;
return content.replace(pathToModuleRE,"./mapml-viewer.js");
} else {
return content;
}
}
}
},
images: {
// if you pass images through the process function, it corrupts them,
// so you have to do this in a separate grunt 'target' ('main' being the
// default one, I believe).
files: [
{
expand: true,
cwd: 'node_modules/leaflet/dist/images/',
flatten: true,
filter: 'isFile',
src: ['*.png'],
dest: 'dist/images/'
}
]
},
experiments: {
files: [
{
expand: true,
src: ['dist/*'],
dest: '../experiments'
}
]
},
extension: {
files: [
{
expand: true,
src: ['dist/*'],
dest: '../mapml-extension/src'
}
]
},
docs: {
files: [
{
expand: true,
src: ['dist/*'],
dest: '../web-map-doc/static'
}
]
}
},
clean: {
dist: ['dist'],
tidyup: ['dist/leaflet-src.js','dist/proj4-src.js','dist/proj4leaflet.js','dist/L.Control.Locate.js'],
experiments: {
options: {force: true},
src: ['../experiments/dist']
},
extension: {
options: {force: true},
src: ['../mapml-extension/src/dist']
},
docs: {
options: {force: true},
src: ['../web-map-doc/dist']
}
},
rollup: {
options: {
format: 'iife'
},
main: {
dest: 'dist/mapml.js',
src: 'src/mapml/index.js' // Only one source file is permitted
}
},
prettier: {
options: {
// https://prettier.io/docs/en/options.html
progress: true
},
files: {
src: [
"src/**/*.js",
"test/**/*.js"
]
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-rollup');
grunt.loadNpmTasks('grunt-prettier');
grunt.registerTask('format', ['prettier', 'jshint']);
grunt.registerTask('default', ['clean:dist', 'copy:main', 'copy:images', 'format', 'rollup',
'uglify', 'cssmin','clean:tidyup']);
grunt.registerTask('experiments',['clean:experiments','default','copy:experiments']);
grunt.registerTask('extension',['clean:extension','default','copy:extension']);
grunt.registerTask('docs', ['clean:docs','default','copy:docs']);
grunt.registerTask('sync', ['default','experiments','extension','docs']);
};