"use strict";

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

const libSkiaSharpName = 'libSkiaSharp.dll';
const platform = os.platform();
const arch = os.arch();

const pkgPath = __dirname.substring(0, __dirname.lastIndexOf(path.sep));
const skiaPath = path.join(pkgPath, 'native', `${platform}`, `${arch}`, libSkiaSharpName);

if (!fs.existsSync(skiaPath)) {
    const msg = `Unsupported platform: ${platform}/${arch}`;
    throw Error(msg);
}

const basePath = __dirname.substring(0, __dirname.indexOf('node_modules'));
if (basePath == '') {
    const msg = `Unexpected path: ${__dirname}`;
    throw Error(msg);
}

fs.copyFileSync(skiaPath, path.join(basePath, libSkiaSharpName));