Skip to content

Commit

Permalink
enable use of custom config with temp dir and copying
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hpfast committed Apr 16, 2018
1 parent 5655f04 commit 5f32cd4
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ npm-debug.log
lerna-debug.log
.vscode
.nyc_output
packages/config/.tmp
4 changes: 2 additions & 2 deletions packages/lib/configParser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import config from '../config/config.js';
import config from '../config/.tmp/config.js';

const CONFIG = {};

Expand Down Expand Up @@ -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 };
export { CONFIG };
97 changes: 97 additions & 0 deletions packages/nlmaps/test/testconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
export default {
"version": 0.1,
"basemaps": {
"defaults": {
"crs": "EPSG:3857",
"attr": "Kaartgegevens &copy; <a href='https://www.kadaster.nl'>Kadaster</a> | <a href='https://www.verbeterdekaart.nl'>Verbeter de kaart</a>",
"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]
}
}
16 changes: 15 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 => {
Expand Down
6 changes: 6 additions & 0 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 5f32cd4

Please sign in to comment.