Skip to content

Commit

Permalink
Merge pull request #545 from mapnik/mapnik-index
Browse files Browse the repository at this point in the history
Start bundling mapnik-index command
  • Loading branch information
Dane Springmeyer committed Oct 21, 2015
2 parents 8f760d0 + e699d62 commit d2bcae4
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ matrix:
env:
global:
- JOBS: "8"
- MAPNIK_GIT: v3.0.7
- MAPNIK_GIT: v3.0.7-47-g1455c6b
- secure: F42vcZEgWgCMDvQXlmyYmWwFo86fUjlJbsvXEwyliaMfasjCNsbmeILU61aScn8daiCGD+vRUaRlmv+XxUSS2G8FaoI8ZjwgMo2guMwthAQJ1ohTvf4bZI0JqVYKnnZpzhGPv2zD0DTdt31l30qn2GZnnGrF4yFpPU1HW2HcMuE=
- secure: WRWrn3KjCaevRo2htdvn26euALTZNCDtcSlQvtH6Bc7yLdhlH5apj+qSuWqlN59f1cprFH+5aQ2zmBkVmAV2DT4IbsfszMIR6k6EetuY6VOugo/qsPW2x/MQbpFgjCbl95bYty4eUH9Bcf70Pz/S+XVewABXHWikJiLUiZBbLyE=

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
environment:
MAPNIK_GIT: 3.0.7
MAPNIK_GIT: 3.0.7-48-g9df5486
node_pre_gyp_accessKeyId:
secure: 7DrSVc5eIGtmMcki5H+iRft+Tk3MJTwDBQEUuJHWaQ4=
node_pre_gyp_secretAccessKey:
Expand Down
29 changes: 29 additions & 0 deletions bin/mapnik-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env node

'use strict';

var binary = require('node-pre-gyp'),
path = require('path'),
bindingPath = binary.find(path.resolve(__dirname, '..', 'package.json')),
program = path.join(path.dirname(bindingPath), 'mapnik-index'),
spawn = require('child_process').spawn,
fs = require('fs');

if (!fs.existsSync(program)) {
// assume it is not packaged but still on PATH
program = 'mapnik-index';
}

var proc = spawn(program, process.argv.slice(2))
.on('error', function(err) {
if (err && err.code == 'ENOENT') {
throw new Error("mapnik-index not found at " + program);
}
throw err;
})
.on('exit', function(code) {
process.exit(code);
});

proc.stdout.pipe(process.stdout);
proc.stderr.pipe(process.stderr);
2 changes: 2 additions & 0 deletions scripts/build_against_sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ MODULE_PATH=$(node-pre-gyp reveal module_path ${ARGS})
rm -rf ${MODULE_PATH}
npm install --build-from-source ${ARGS} --clang=1
npm ls
# copy mapnik-index
cp ${MAPNIK_SDK}/bin/mapnik-index ${MODULE_PATH}
# copy shapeindex
cp ${MAPNIK_SDK}/bin/shapeindex ${MODULE_PATH}
# copy lib
Expand Down
1 change: 1 addition & 0 deletions scripts/build_against_sdk_02-copy-deps-to-bindingdir.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Try{
Write-Output "to: $env:NODEMAPNIK_BINDING_DIR"

Copy-Item $env:MAPNIK_SDK\bin\shapeindex.exe $env:NODEMAPNIK_BINDING_DIR\ -ErrorAction Stop
Copy-Item $env:MAPNIK_SDK\bin\mapnik-index.exe $env:NODEMAPNIK_BINDING_DIR\ -ErrorAction Stop

$deps = Get-ChildItem -Path $env:MAPNIK_SDK\lib -Filter *.dll | % { $_.FullName }

Expand Down
44 changes: 44 additions & 0 deletions test/mapnik-index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"use strict";

var assert = require('assert');
var path = require('path');
var fs = require('fs');
var os = require('os');
var crypto = require('crypto');
var mapnikindex = path.resolve(__dirname, '..', 'bin', 'mapnik-index.js');

var file = path.join(__dirname, 'data', 'world_merc.json');

var tmpdir = path.join(os.tmpdir(), crypto.randomBytes(8).toString('hex'));
var tmpfile = path.join(tmpdir, 'world_merc.json');

var spawn = require('child_process').spawn;

function copy(done) {
fs.mkdir(tmpdir, function() {
fs.createReadStream(file).pipe(fs.createWriteStream(tmpfile)).on('close', done);
});
}

describe('bin/mapnik-index.js', function() {
before(copy);

it('should create a spatial index', function(done) {
var args = [mapnikindex, '--files', tmpfile];
spawn(process.execPath, args)
.on('error', function(err) { assert.ifError(err, 'no error'); })
.on('close', function(code) {
assert.equal(code, 0, 'exit 0');

fs.readdir(tmpdir, function(err, files) {

files = files.filter(function(filename) {
return filename === 'world_merc.json.index';
});

assert.equal(files.length, 1, 'made spatial index');
done();
});
});
});
});

0 comments on commit d2bcae4

Please sign in to comment.