47 lines
1.8 KiB
JavaScript
47 lines
1.8 KiB
JavaScript
// About me: Bundles the extension into dist/ as the folder layout Vortex loads:
|
|
// a single CommonJS index.js plus info.json and the game artwork. `vortex-api` is
|
|
// left external because Vortex provides it to extensions at runtime.
|
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
import { dirname, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
import * as esbuild from 'esbuild';
|
|
|
|
import { encodePng, renderGameArt } from '../src/gameart.ts';
|
|
|
|
const projectRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
const distDir = resolve(projectRoot, 'dist');
|
|
const pkg = JSON.parse(readFileSync(resolve(projectRoot, 'package.json'), 'utf8'));
|
|
|
|
mkdirSync(distDir, { recursive: true });
|
|
|
|
await esbuild.build({
|
|
entryPoints: [resolve(projectRoot, 'src/index.ts')],
|
|
outfile: resolve(distDir, 'index.js'),
|
|
bundle: true,
|
|
platform: 'node',
|
|
format: 'cjs',
|
|
target: 'node18',
|
|
external: ['vortex-api'],
|
|
legalComments: 'none',
|
|
});
|
|
|
|
// The bundle is CommonJS, but this repo is an ESM package; without this marker
|
|
// node would read dist/index.js as ESM and fail on `module.exports`.
|
|
writeFileSync(resolve(distDir, 'package.json'), `${JSON.stringify({ type: 'commonjs' }, null, 2)}\n`);
|
|
|
|
const info = {
|
|
name: 'Game: Cyberpunk 2077 (Linux/Proton)',
|
|
author: 'local',
|
|
version: pkg.version,
|
|
description: pkg.description,
|
|
gameId: 'cyberpunk2077linux',
|
|
};
|
|
writeFileSync(resolve(distDir, 'info.json'), `${JSON.stringify(info, null, 2)}\n`);
|
|
|
|
// The tile artwork is generated, never copied from Vortex or Nexus, so the build
|
|
// renders it straight from source. It is deterministic, so this is reproducible.
|
|
writeFileSync(resolve(distDir, 'gameart.png'), encodePng(renderGameArt()));
|
|
|
|
console.log(`built ${resolve(distDir, 'index.js')}`);
|