diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-05-02 15:25:48 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-05-02 17:44:18 +0200 |
commit | 2489afdd0db97de0664198f5ae64bd94db6b6fc7 (patch) | |
tree | a7a52194daab971f58f60ef21bd45b1a0d517f4b /scripts/generate-style-code.js | |
parent | a48152a9811a856e467eff3e396a76a059558fb1 (diff) | |
download | qtlocation-mapboxgl-2489afdd0db97de0664198f5ae64bd94db6b6fc7.tar.gz |
[build] change style code generator to sort properties alphabetically
JSON keys in our style specification don't have a defined order. This change sorts them alphabetically so that we can rely on the order remaining them same across code generation runs.
Diffstat (limited to 'scripts/generate-style-code.js')
-rwxr-xr-x | scripts/generate-style-code.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js index 0bac355071..aed676c990 100755 --- a/scripts/generate-style-code.js +++ b/scripts/generate-style-code.js @@ -197,6 +197,8 @@ const layerCpp = ejs.compile(fs.readFileSync('src/mbgl/style/layers/layer.cpp.ej const propertiesHpp = ejs.compile(fs.readFileSync('src/mbgl/style/layers/layer_properties.hpp.ejs', 'utf8'), {strict: true}); const propertiesCpp = ejs.compile(fs.readFileSync('src/mbgl/style/layers/layer_properties.cpp.ejs', 'utf8'), {strict: true}); +const collator = new Intl.Collator("en-US"); + // Add this mock property that our SDF line shader needs so that it gets added to the list of // "data driven" properties. spec.paint_line['line-floor-width'] = { @@ -214,12 +216,20 @@ const layers = Object.keys(spec.layer.type.values).map((type) => { return memo; }, []); + // JSON doesn't have a defined order. We're going to sort them alphabetically + // to get a deterministic order. + layoutProperties.sort((a, b) => collator.compare(a.name, b.name)); + const paintProperties = Object.keys(spec[`paint_${type}`]).reduce((memo, name) => { spec[`paint_${type}`][name].name = name; memo.push(spec[`paint_${type}`][name]); return memo; }, []); + // JSON doesn't have a defined order. We're going to sort them alphabetically + // to get a deterministic order. + paintProperties.sort((a, b) => collator.compare(a.name, b.name)); + return { type: type, layoutProperties: layoutProperties, @@ -254,6 +264,10 @@ const lightProperties = Object.keys(spec[`light`]).reduce((memo, name) => { return memo; }, []); +// JSON doesn't have a defined order. We're going to sort them alphabetically +// to get a deterministic order. +lightProperties.sort((a, b) => collator.compare(a.name, b.name)); + const lightHpp = ejs.compile(fs.readFileSync('include/mbgl/style/light.hpp.ejs', 'utf8'), {strict: true}); const lightCpp = ejs.compile(fs.readFileSync('src/mbgl/style/light.cpp.ejs', 'utf8'), {strict: true}); writeIfModified(`include/mbgl/style/light.hpp`, lightHpp({properties: lightProperties})); |