platform-coop-toolkit / coop-map-directory-index

The Map/Directory/Index component of the Platform Cooperative Development Kit.
https://directory.platform.coop
BSD 3-Clause "New" or "Revised" License
1 stars 3 forks source link

Identify & document a way to import configuration data into JavaScript and JSON #136

Closed erictheise closed 4 years ago

erictheise commented 4 years ago

Is your feature request related to a problem? Please describe.

Several values related to maps should vary depending on where the code is running. The Mapbox token is one example although there seems little harm in hardcoding that. Others are the sprite and glyphs urls in the Mapbox style JSON document. These should be configurable for development and production environments. For example, in production

"glyphs": "http://directory.platform.coop/static/maps/dist/styles/glyphs/{fontstack}/{range}.pbf"

should be the correct url but for my own development purposes, as I serve many glyphs across many projects, I would like to use

"glyphs": "http://localhost:8078/glyphs/{fontstack}/{range}.pbf"

and not have to worry about fiddling with these values before and after a commit.

Describe the solution you'd like

The ability to work easily and without fear of committing an invalid map style to the repo.

Describe alternatives you've considered

My first attempts at introducing a JavaScript workflow to this Django project brought in a package called envify. @greatislander queried me about it somewhere along the way and it's been removed; I kept it solely as a reminder that parsing config values would be necessary at some point. I don't even know if that package serves the purpose although the name suggested it might.

greatislander commented 4 years ago

@erictheise To clarify, these values would all end up in the transpiled JavaScript file? If so I can do a little research to see what would work best with our build system.

erictheise commented 4 years ago

@greatislander, of the values I mentioned (and I left one out), the Mapbox accessToken and style url are in maps/static/maps/js/app.js and would be transpiled. glyphs and sprite are part of the JSON-formatted Mapbox style documents, which you can see in maps/static/maps/styles/pcc/style.json on the add/pcc-map-styles branch. I have been bringing those over using

mix.copyDirectory('maps/static/maps/styles', 'maps/static/maps/dist/styles');

in webpack.mix.js but I defer to your assessment as to whether that's the optimal approach.

greatislander commented 4 years ago

Thanks @erictheise, duly noted. I'm working on the impact summary at the moment but I will make some time to look into this later and get back to you.