use glob module to get the icu_data directory

This commit is contained in:
Eneko Lakasta 2018-01-10 15:15:43 +01:00
parent d292a922f6
commit 9c556964e5
2 changed files with 2 additions and 29 deletions

30
app.js
View File

@ -21,40 +21,12 @@ if (!semver.satisfies(nodejsVersion, '>=6.9.0')) {
// This function should be called before the require('yargs'). // This function should be called before the require('yargs').
function setICUEnvVariable() { function setICUEnvVariable() {
if (process.env.ICU_DATA === undefined) { if (process.env.ICU_DATA === undefined) {
// There are 3 ways to set the env variable. Option 1 doesn't work. Option 2 is the best alternative.
// 1
// The best approach to generate the path where the ICU DATA is stored is by calling binary.find()
// Sadly, it fails. It generates the correct path, but mapnik raises "could not create BreakIterator: U_MISSING_RESOURCE_ERROR"
const binary = require('node-pre-gyp');
let binding_path = binary.find(path.resolve(path.join(__dirname, 'node_modules/mapnik/package.json')));
binding_path = path.dirname(binding_path);
// If we hardcode de path, it works. the call to binary.find seems to be the problem here.
// var binding_path = __dirname + '/node_modules/mapnik/lib/binding/node-v48-linux-x64/';
process.env.ICU_DATA1 = path.join(binding_path, 'share/mapnik/icu/');
console.log('process.env.ICU_DATA1: ', process.env.ICU_DATA1);
// 2
// Alternative to 1 using glob module.
const glob = require('glob'); const glob = require('glob');
let directory = glob.sync(__dirname + '/node_modules/mapnik/lib/binding/*/share/mapnik/icu/'); let directory = glob.sync(__dirname + '/node_modules/mapnik/lib/binding/*/share/mapnik/icu/');
if (directory && directory.length > 0) { if (directory && directory.length > 0) {
process.env.ICU_DATA2 = directory[0]; process.env.ICU_DATA = directory[0];
} }
console.log('process.env.ICU_DATA2: ', process.env.ICU_DATA2);
// 3
// hardcoded. not multiplatform (just works in some linuxes)
process.env.ICU_DATA3 = __dirname + '/node_modules/mapnik/lib/binding/node-v48-linux-x64/share/mapnik/icu/';
console.log('process.env.ICU_DATA3: ', process.env.ICU_DATA3);
console.log(process.env.ICU_DATA1 === process.env.ICU_DATA2);
console.log(process.env.ICU_DATA2 === process.env.ICU_DATA3);
process.env.ICU_DATA = process.env.ICU_DATA3;
console.log(process.env.ICU_DATA)
} }
} }
setICUEnvVariable(); setICUEnvVariable();

View File

@ -33,6 +33,7 @@
"dot": "~1.0.2", "dot": "~1.0.2",
"express": "~4.16.0", "express": "~4.16.0",
"fastly-purge": "~1.0.1", "fastly-purge": "~1.0.1",
"glob": "^7.1.2",
"log4js": "cartodb/log4js-node#cdb", "log4js": "cartodb/log4js-node#cdb",
"lru-cache": "2.6.5", "lru-cache": "2.6.5",
"lzma": "~2.3.2", "lzma": "~2.3.2",