-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); | ||
}); |