'use strict';

/**
 * Post-install script for authdb-client.
 *
 * Checks whether a prebuilt .node binary exists for the current ABI version.
 * If not, prints instructions for building from source.
 */

const fs   = require('fs');
const path = require('path');

const abiVersion = process.versions.modules;
const prebuildPath = path.join(__dirname, 'prebuilds',
                               `authdb-nds.abi-${abiVersion}.node`);

if (fs.existsSync(prebuildPath)) {
    console.log(`[authdb-client] Prebuilt binary found for ABI ${abiVersion}.`);
    process.exit(0);
}

console.warn(
    `[authdb-client] WARNING: No prebuilt binary for Node.js ABI ${abiVersion} ` +
    `(${process.platform} ${process.arch}).\n` +
    `  To build from source, clone the full repository and run:\n` +
    `    mkdir build && cd build\n` +
    `    cmake .. && make\n` +
    `  Then copy the .node files into bindings/prebuilds/\n`
);
