#!/usr/bin/env node

'use strict';

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

    proc = spawn(shapeindex, process.argv.slice(2))
      .on('error', function(err) {
        console.error(err);
      })
      .on('exit', function(code) {
        process.exit(code);
      });

proc.stdout.pipe(process.stdout);
proc.stderr.pipe(process.stderr);

@@ -290,122 +290,373 @@
 wn,%0A
-%0A    proc = spawn(shapeindex, process.argv.slice(2))%0A      .on('error', function(err) %7B%0A        console.error(
+    fs = require('fs');%0A%0Aif (!fs.existsSync(shapeindex)) %7B%0A  // assume it is not packaged but still on PATH%0A  shapeindex = 'shapeindex';%0A%7D%0A%0Avar proc = spawn(shapeindex, process.argv.slice(2))%0A      .on('error', function(err) %7B%0A        if (err && err.code == 'ENOENT') %7B%0A          throw new Error(%22shapeindex not found at %22 + shapeindex);%0A        %7D%0A        throw 
 err
-)
 ;%0A  

support shapeindex on PATH too