From 5f32cd469d7239881b26e5c4db0f31820edb1669 Mon Sep 17 00:00:00 2001 From: Hans Fast Date: Mon, 16 Apr 2018 12:01:35 +0200 Subject: [PATCH] enable use of custom config with temp dir and copying in order to build nlmaps with a custom config, we create a temp directory and copy either the default there or the one specified with -c to build script. configParser requires this path. --- .gitignore | 1 + packages/lib/configParser.js | 4 +- packages/nlmaps/test/testconfig.js | 97 ++++++++++++++++++++++++++++++ scripts/build.js | 16 ++++- scripts/helpers.js | 6 ++ 5 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 packages/nlmaps/test/testconfig.js diff --git a/.gitignore b/.gitignore index df642434..113a82b9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ npm-debug.log lerna-debug.log .vscode .nyc_output +packages/config/.tmp diff --git a/packages/lib/configParser.js b/packages/lib/configParser.js index a7100702..94ccdf25 100644 --- a/packages/lib/configParser.js +++ b/packages/lib/configParser.js @@ -1,4 +1,4 @@ -import config from '../config/config.js'; +import config from '../config/.tmp/config.js'; const CONFIG = {}; @@ -87,4 +87,4 @@ parseMap(config.map); parseBase(config.basemaps); if(config.wms!==undefined)parseWMS(config.wms); if(config.geocoder!==undefined)parseGeocoder(config.geocoder); -export { CONFIG }; \ No newline at end of file +export { CONFIG }; diff --git a/packages/nlmaps/test/testconfig.js b/packages/nlmaps/test/testconfig.js new file mode 100644 index 00000000..ac13c8d6 --- /dev/null +++ b/packages/nlmaps/test/testconfig.js @@ -0,0 +1,97 @@ +export default { + "version": 0.1, + "basemaps": { + "defaults": { + "crs": "EPSG:3857", + "attr": "Kaartgegevens © Kadaster | Verbeter de kaart", + "minZoom": 6, + "maxZoom": 19, + "type": "wmts", + "format": "jpeg", + "url": "https://geodata.nationaalgeoregister.nl/tiles/service" + }, + "layers": [ + { + "name": "standaard", + "urlname": "brtachtergrondkaart" + }, + { + "name": "grijs", + "urlname": "brtachtergrondkaartgrijs" + }, + { + "name": "pastel", + "urlname": "brtachtergrondkaartpastel" + },{ + "name": "luchtfoto", + "urlname": "2016_ortho25", + "url": "https://geodata.nationaalgeoregister.nl/luchtfoto/rgb", + "format": "jpeg" + } + ] + }, + "wms": { + "defaults": { + "url": "https://geodata.nationaalgeoregister.nl/{workSpaceName}/wms?", + "version": "1.1.1", + "transparent": true, + "format": "image/png", + "minZoom": 0, + "maxZoom": 24 + }, + "layers": [ + { + "name": "foobar", + "workSpaceName": "bash", + "layerName": "peachy" + }, + { + "name": "gebouwen", + "workSpaceName": "bag", + "layerName": "pand" + }, + { + "name": "percelen", + "workSpaceName": "bkadastralekaartv3ag", + "layerName": "kadastralekaart" + }, + { + "name": "drone-no-fly-zones", + "workSpaceName": "dronenoflyzones", + "layerName": "luchtvaartgebieden,landingsite" + }, + { + "name": "hoogte", + "workSpaceName": "ahn2", + "layerName": "ahn2_05m_int", + "styleName": "ahn2:ahn2_05m_detail" + }, + { + "name": "gemeenten", + "workSpaceName": "bestuurlijkegrenzen", + "layerName": "gemeenten", + "styleName": "bestuurlijkegrenzen:bestuurlijkegrenzen_gemeentegrenzen" + }, + { + "name": "provincies", + "workSpaceName": "bestuurlijkegrenzen", + "layerName": "provincies", + "styleName": "bestuurlijkegrenzen:bestuurlijkegrenzen_provinciegrenzen" + } + ] + }, + "geocoder": { + "suggestUrl": "https://geodata.nationaalgeoregister.nl/locatieserver/v3/suggest?", + "lookupUrl": "https://geodata.nationaalgeoregister.nl/locatieserver/v3/lookup?" + }, + "map": { + "style": 'standaard', + "center": { + "latitude": 52.093249, + "longitude": 5.111994 + }, + "zoom": 8, + "attribution": true, + "extent": [-180,-90,180,90] + } +} diff --git a/scripts/build.js b/scripts/build.js index d54283d2..9718412f 100755 --- a/scripts/build.js +++ b/scripts/build.js @@ -13,8 +13,8 @@ if (helpers.args.watch) { rollup_args.unshift('--watch') } +//create output directories for static assets if they don't exist yet tasks.forEach(task => { - //create output directories for static assets if they don't exist yet const assetsdirpath = 'packages/' + helpers.packagePath(task) + '/build/assets'; if (!shell.test('-e', assetsdirpath)) { shell.mkdir('-p', assetsdirpath); @@ -28,6 +28,20 @@ tasks.forEach(task => { }) function main() { + //create temporary directory and copy config there. + //this is a workaround to be able to build nlmaps with a custom config. + const TEMPCONFDIR = 'packages/config/.tmp' + const DEFAULTCONFIGFILE = 'packages/config/config.js'; + if (!shell.test('-e', TEMPCONFDIR)) { + shell.mkdir(TEMPCONFDIR); + } + if (helpers.args.config !== null) { + console.log('using custom config file ' + helpers.args.config); + shell.cp(helpers.args.config, TEMPCONFDIR + '/config.js' ); + } else { + console.log('using default config file ' + DEFAULTCONFIGFILE); + shell.cp(DEFAULTCONFIGFILE, TEMPCONFDIR + '/config.js'); + } //run each package's rollup command from the package's directory //and capture/log output tasks.forEach(task => { diff --git a/scripts/helpers.js b/scripts/helpers.js index e95708bc..5fcecab1 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -30,6 +30,12 @@ parser.addArgument( help: 'report coverage for unit tests' } ); +parser.addArgument( + [ '-c', '--config' ], + { + help: 'specify a custom config file to build nlmaps with' + } +); const args = parser.parseArgs();