-
Notifications
You must be signed in to change notification settings - Fork 16
/
Gruntfile.js
186 lines (182 loc) · 5.4 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
module.exports = function(grunt) {
const rollup = require('rollup');
const rollupConfig = require('./rollup.config.js');
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']
}
}
},
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,
flatten: true,
filter: 'isFile',
src: ['index.html'],
dest: 'dist/'
},
{
expand: true,
flatten: true,
filter: 'isFile',
src: ['src/pmtilesRules.js'],
dest: 'dist/'
}
],
options: {
process: function (content, srcpath) {
// see patch.diff file for comments on why patching is necessary
if (srcpath.includes('index.html')) {
console.log('MODIFYING: ', srcpath);
var pathToModuleRE = /dist\/mapml\.js/gi;
return content.replace(pathToModuleRE,"./mapml.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'
}
]
},
geoserver: {
files: [
{
expand: true,
cwd: 'dist',
src: ['*.js','*.map','*.css'],
dest: '../geoserver/src/extension/mapml/src/main/resources/viewer/widget'
}
]
},
docs: {
files: [
{
expand: true,
src: ['dist/*'],
dest: '../web-map-doc/static'
}
]
}
},
clean: {
dist: ['dist'],
tidyup: ['dist/mapmlviewer.js'],
experiments: {
options: {force: true},
src: ['../experiments/dist']
},
extension: {
options: {force: true},
src: ['../mapml-extension/src/dist']
},
geoserver: {
options: {force: true},
src: ['../geoserver/src/extension/mapml/src/main/resources/viewer/widget/*.js','../geoserver/src/extension/mapml/src/main/resources/viewer/widget/*.map','../geoserver/src/extension/mapml/src/main/resources/viewer/widget/*.css']
},
docs: {
options: {force: true},
src: ['../web-map-doc/dist']
}
},
prettier: {
options: {
// https://prettier.io/docs/en/options.html
progress: true
},
files: {
src: [
"src/**/*.js",
"test/**/*.js"
]
}
}
});
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-prettier');
// "grunt-rollup" plugin seems no longer maintained
grunt.registerTask('customRollup', 'A custom Rollup build task', async function() {
const done = this.async();
try {
// Use the configuration loaded from rollup.config.js
const bundle = await rollup.rollup(rollupConfig);
await bundle.write(rollupConfig.output);
console.log('Rollup build completed successfully.');
done();
} catch (error) {
console.error('Rollup build failed:', error);
done(false);
}
});
grunt.registerTask('format', ['prettier', 'jshint']);
grunt.registerTask('default', ['clean:dist', 'copy:main', 'copy:images', 'format', 'customRollup', 'cssmin']);
grunt.registerTask('experiments', ['clean:experiments', 'default', 'copy:experiments']);
grunt.registerTask('extension', ['clean:extension', 'default', 'copy:extension']);
grunt.registerTask('geoserver', ['clean:geoserver', 'default', 'copy:geoserver']);
grunt.registerTask('basemap', ['clean:basemap', 'default', 'copy:basemap']);
grunt.registerTask('docs', ['clean:docs', 'default', 'copy:docs']);
grunt.registerTask('sync', ['default', 'experiments', 'extension', 'docs']);
};