#!/usr/bin/env node

/**
 * Syncs the version from ../VERSION to package.json
 * Run this before publishing to npm
 */

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

const versionFile = path.join(__dirname, '..', '..', 'VERSION');
const packageFile = path.join(__dirname, '..', 'package.json');

const version = fs.readFileSync(versionFile, 'utf8').trim();
const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf8'));

pkg.version = version;

fs.writeFileSync(packageFile, JSON.stringify(pkg, null, 2) + '\n');

console.log(`Updated package.json version to ${version}`);
