forked from Maps4HTML/MapML.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
178 lines (170 loc) · 5.33 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
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// concat: {
// options: {
// separator: ';'
// },
// dist: {
// src: ['dist/mapml.js'],
// dest: 'dist/c.js'
// }
// },
cssmin: {
options: {
mergeIntoShorthands: false,
roundingPrecision: -1
},
combine: {
files: {
'dist/mapml.css': ['node_modules/leaflet/dist/leaflet.css', 'src/mapml.css']
}
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
},
dist: {
files: {
'dist/mapml.min.js': ['<%= rollup.main.dest %>']
}
}
},
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
}
},
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,
cwd: 'src',
flatten: true,
filter: 'isFile',
src: ['*.js','*.css','*.md','index.html','package.json'],
dest: 'dist/'
},
{
expand: true,
flatten: true,
filter: 'isFile',
src: ['index.html'],
dest: 'dist/'
}
],
options: {
// leaflet and proj4 need to set their global variable on the window
// object in order to use them as modules (it seems).
process: function (content, srcpath) {
var wndoh;
if (srcpath.includes('leaflet-src.js')) {
console.log('MODIFYING: ', srcpath);
wndoh = /\}\(this\, \(function \(exports\) \{ \'use strict\'\;/gi;
return content.replace(wndoh,"}(window, (function (exports) { 'use strict';");
} else if (srcpath.includes('proj4leaflet.js')) {
console.log('PATCHING: ', srcpath);
// replace:
// return new L.LatLng(point2[1], point2[0], unbounded);
// with:
// return new L.LatLng(point2[1] || 0, point2[0] || 0, unbounded);
// so that Leaflet doesn't barf on the NaN that is recently
// returned by proj4js (where it used to return 0)
unproject = /return new L\.LatLng\(point2\[1\]\, point2\[0\]\, unbounded\)\;/gi;
return content.replace(unproject, "return new L.LatLng(point2[1] || 0, point2[0] || 0, unbounded);");
} else if (srcpath.includes('proj4-src.js')) {
console.log('MODIFYING: ', srcpath);
wndoh = /\}\(this\, \(function \(\) \{ \'use strict\'\;/gi;
return content.replace(wndoh, "}(window, (function () { 'use strict';");
} else if (srcpath.includes('index.html')) {
console.log('MODIFYING: ', srcpath);
var pathToModuleRE = /dist\/web-map\.js/gi;
return content.replace(pathToModuleRE,"web-map.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/'
}
]
}
},
clean: {
dist: ['dist']
},
rollup: {
options: {
format: 'iife',
},
main: {
dest: 'dist/mapml.js',
src: 'src/mapml/index.js', // Only one source file is permitted
},
},
});
/*grunt.loadNpmTasks('grunt-html');*/
grunt.loadNpmTasks('grunt-contrib-uglify-es');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
// grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-rollup');
/* grunt.loadNpmTasks('grunt-processhtml'); */
grunt.registerTask('test', ['jshint']);
grunt.registerTask('default', ['clean:dist', 'copy', 'jshint', 'rollup', 'uglify', 'cssmin']);
grunt.registerTask('build', ['rollup']);
};