import * as fs from 'fs/promises';
import * as path from 'path';

const linkGfx = async () => {
  const target = path.resolve('../../data/gfx/packs/Classic/world/preview');
  const link = path.resolve('./src/assets/gfx')
  process.stdout.write(`Making link:\n${link} -> ${target}\n`);
  try {
    await fs.stat(link)
    process.stdout.write('Link exists. Overwriting...\n');
    await fs.unlink(link)
  } catch (e) {
    // noop
  }

  try {
    await fs.symlink(target, link, 'dir');
    process.stdout.write('Link created.\n');
  } catch (err) {
    console.log(err);
    process.stderr.write('Cannot create link.\n')
    process.exit(1);
    return;
  }
  process.exit(0);
}

void linkGfx()
