[TASK] Default and custom config - merge

This commit is contained in:
Xaver Maierhofer 2017-03-30 00:21:41 +02:00 committed by Xaver Maierhofer
parent 6a3986e588
commit c42758ba35
No known key found for this signature in database
GPG Key ID: 7FDCE23FD2EC9FE8
4 changed files with 31 additions and 23 deletions

20
config.default.json Normal file
View File

@ -0,0 +1,20 @@
// Gulp will remove all comments
{
"reverseGeocodingApi": "https://nominatim.openstreetmap.org/reverse",
"maxAge": 14,
"maxAgeAlert": 3,
"nodeZoom": 18,
"labelZoom": 13,
"clientZoom": 15,
"nodeInfobox": {
"contact": false,
"hardwareUsage": true
},
"supportedLocale": [
"en",
"de",
"fr",
"ru"
],
"cacheBreaker": "<!-- inject:cache-breaker -->"
}

View File

@ -25,17 +25,7 @@
],
// String or array of data provider are supported
"dataPath": "https://regensburg.freifunk.net/data/",
"reverseGeocodingApi": "https://nominatim.openstreetmap.org/reverse",
"siteName": "Freifunk Regensburg",
"maxAge": 14,
"maxAgeAlert": 3,
"nodeZoom": 18,
"labelZoom": 13,
"clientZoom": 15,
"nodeInfobox": {
"contact": false,
"hardwareUsage": true
},
"mapLayers": [
{
"name": "Freifunk Regensburg",
@ -44,7 +34,7 @@
"config": {
"maxZoom": 22,
"subdomains": "1234",
"attribution": "<a href=\'https://www.mapbox.com/about/maps/\' target=\'_blank\'>&copy; Mapbox</a> <a href=\'https://openstreetmap.org/about/\' target=\'_blank\'>&copy; OpenStreetMap</a> <a class=\'mapbox-improve-map\' href=\'https://www.mapbox.com/map-feedback/\' target=\'_blank\'>Improve this map</a>",
"attribution": "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">&copy; Mapbox</a> <a href=\"https://openstreetmap.org/about/\" target=\"_blank\">&copy; OpenStreetMap</a> <a class=\"mapbox-improve-map\" href=\"https://www.mapbox.com/map-feedback/\" target=\"_blank\">Improve this map</a>",
"start": 6
}
},
@ -55,7 +45,7 @@
"config": {
"maxZoom": 22,
"subdomains": "1234",
"attribution": "<a href=\'https://www.mapbox.com/about/maps/\' target=\'_blank\'>&copy; Mapbox</a> <a href=\'https://openstreetmap.org/about/\' target=\'_blank\'>&copy; OpenStreetMap</a> <a class=\'mapbox-improve-map\' href=\'https://www.mapbox.com/map-feedback/\' target=\'_blank\'>Improve this map</a>",
"attribution": "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">&copy; Mapbox</a> <a href=\"https://openstreetmap.org/about/\" target=\"_blank\">&copy; OpenStreetMap</a> <a class=\"mapbox-improve-map\" href=\"https://www.mapbox.com/map-feedback/\" target=\"_blank\">Improve this map</a>",
"mode": "night",
"start": 19,
"end": 7
@ -121,12 +111,5 @@
"site": "ffrgb",
"name": "Regensburg"
}
],
"supportedLocale": [
"en",
"de",
"fr",
"ru"
],
"cacheBreaker": "<!-- inject:cache-breaker -->"
]
}

View File

@ -8,7 +8,7 @@ module.exports = function () {
sass: 'scss/**/*.scss',
javascript: ['app.js', 'lib/**/*.js'],
json: 'locale/*.json',
html: ['html/index.html', 'config.json']
html: ['html/index.html', 'config.json', 'config.default.json']
},
clean: [build + '/*.map', build + '/vendor', build + '/main.css'],
autoprefixer: ['> 1% in DE'],

View File

@ -4,9 +4,14 @@ module.exports = function (gulp, plugins, config, env) {
return gulp.src(env.production() ? config.build + '/*.html' : 'html/*.html')
.pipe(plugins.inject(gulp.src(['config.json']), {
starttag: '<!-- inject:config -->',
transform: function (filePath, file) {
transform: function (filePath, customConfig) {
var defaultConfig = fs.readFileSync('config.default.json', 'utf8');
var buildConfig = Object.assign(
JSON.parse(JSON.minify(defaultConfig)),
JSON.parse(JSON.minify(customConfig.contents.toString('utf8')))
);
return '<script>var jsonData =' +
file.contents.toString('utf8')
JSON.stringify(buildConfig)
.replace('<!-- inject:cache-breaker -->',
Math.random().toString(12).substring(7)) +
';</script>'