knowledge-graph-preview / cli /bundle-path.js
mr4's picture
Upload 136 files
fd8cdf5 verified
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import { existsSync } from 'node:fs';
/**
* Resolves the absolute path to the pre-built static bundle (dist/ directory).
*
* The compiled CLI lives at dist/cli/bundle-path.js.
* The Astro static output (index.html, _astro/, etc.) lives at dist/.
* So from this script's location, the bundle is one directory up.
*/
export function getBundlePath() {
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Navigate from dist/cli/ up to dist/
const bundlePath = resolve(__dirname, '..');
if (!existsSync(bundlePath) || !existsSync(resolve(bundlePath, 'index.html'))) {
throw new Error(`Static bundle not found at ${bundlePath}. This is a packaging error — the Astro build output (dist/) is missing.`);
}
return bundlePath;
}