[bazel] Run nodejs inside of bazel for genrules (#1948)
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
const { ArgumentParser } = require("argparse");
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const ejs = require('ejs');
|
||||
const spec = require('./style-spec');
|
||||
const colorParser = require('csscolorparser');
|
||||
|
||||
@@ -222,10 +221,13 @@ global.defaultValue = function (property) {
|
||||
}
|
||||
};
|
||||
|
||||
const layerHpp = ejs.compile(fs.readFileSync(`include/mbgl/style/layers/layer.hpp.ejs`, 'utf8'), {strict: true});
|
||||
const layerCpp = ejs.compile(fs.readFileSync(`src/mbgl/style/layers/layer.cpp.ejs`, 'utf8'), {strict: true});
|
||||
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});
|
||||
console.log("Generating style code...");
|
||||
const root = args.root ? args.root : path.dirname(__dirname);
|
||||
|
||||
const layerHpp = readAndCompile(`include/mbgl/style/layers/layer.hpp.ejs`, root);
|
||||
const layerCpp = readAndCompile(`src/mbgl/style/layers/layer.cpp.ejs`, root);
|
||||
const propertiesHpp = readAndCompile(`src/mbgl/style/layers/layer_properties.hpp.ejs`, root);
|
||||
const propertiesCpp = readAndCompile(`src/mbgl/style/layers/layer_properties.cpp.ejs`, root);
|
||||
|
||||
const collator = new Intl.Collator("en-US");
|
||||
|
||||
@@ -273,16 +275,16 @@ const layers = Object.keys(spec.layer.type.values).map((type) => {
|
||||
for (const layer of layers) {
|
||||
const layerFileName = layer.type.replace('-', '_');
|
||||
|
||||
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer_properties.hpp`, propertiesHpp(layer), args.root);
|
||||
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer_properties.cpp`, propertiesCpp(layer), args.root);
|
||||
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer_properties.hpp`, propertiesHpp(layer), root);
|
||||
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer_properties.cpp`, propertiesCpp(layer), root);
|
||||
|
||||
// Remove our fake property for the external interace.
|
||||
if (layer.type === 'line') {
|
||||
layer.paintProperties = layer.paintProperties.filter(property => property.name !== 'line-floor-width');
|
||||
}
|
||||
|
||||
writeIfModified(`include/mbgl/style/layers/${layerFileName}_layer.hpp`, layerHpp(layer), args.root);
|
||||
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer.cpp`, layerCpp(layer), args.root);
|
||||
writeIfModified(`include/mbgl/style/layers/${layerFileName}_layer.hpp`, layerHpp(layer), root);
|
||||
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer.cpp`, layerCpp(layer), root);
|
||||
}
|
||||
|
||||
// Light
|
||||
@@ -298,7 +300,7 @@ const lightProperties = Object.keys(spec[`light`]).reduce((memo, name) => {
|
||||
// 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}), args.root);
|
||||
writeIfModified(`src/mbgl/style/light.cpp`, lightCpp({properties: lightProperties}), args.root);
|
||||
const lightHpp = readAndCompile(`include/mbgl/style/light.hpp.ejs`, root);
|
||||
const lightCpp = readAndCompile(`src/mbgl/style/light.cpp.ejs`, root);
|
||||
writeIfModified(`include/mbgl/style/light.hpp`, lightHpp({properties: lightProperties}), root);
|
||||
writeIfModified(`src/mbgl/style/light.cpp`, lightCpp({properties: lightProperties}), root);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Global functions //
|
||||
|
||||
const ejs = require('ejs');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
@@ -59,3 +60,11 @@ global.writeIfModified = function(filename, newContent, output) {
|
||||
}
|
||||
console.warn(`* Updating outdated file '${filename}'`);
|
||||
};
|
||||
|
||||
global.readAndCompile = function(filename, root) {
|
||||
if (root) {
|
||||
filename = path.resolve(path.join(root, filename));
|
||||
}
|
||||
|
||||
return ejs.compile(fs.readFileSync(filename, 'utf8'), {strict: true});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user