2026-04-07 11:37:05 +08:00
|
|
|
import { defineConfig } from 'tsup';
|
|
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
import {csvLoader} from 'inline-schema/csv-loader/esbuild';
|
2026-04-07 16:09:47 +08:00
|
|
|
import type { Plugin } from 'esbuild';
|
2026-04-07 11:37:05 +08:00
|
|
|
|
|
|
|
|
const srcDir = fileURLToPath(new URL('./src', import.meta.url));
|
|
|
|
|
const samplesDir = fileURLToPath(new URL('./src/samples', import.meta.url));
|
|
|
|
|
|
|
|
|
|
// Auto-discover samples entry points
|
|
|
|
|
function getSamplesEntries(): Record<string, string> {
|
|
|
|
|
const entries: Record<string, string> = {};
|
|
|
|
|
if (!fs.existsSync(samplesDir)) return entries;
|
|
|
|
|
|
|
|
|
|
for (const item of fs.readdirSync(samplesDir)) {
|
|
|
|
|
const fullPath = path.join(samplesDir, item);
|
|
|
|
|
if (fs.statSync(fullPath).isDirectory()) {
|
|
|
|
|
// Directory sample (e.g. boop) - look for index.ts
|
|
|
|
|
const indexPath = path.join(fullPath, 'index.ts');
|
|
|
|
|
if (fs.existsSync(indexPath)) {
|
|
|
|
|
entries[item] = indexPath;
|
|
|
|
|
}
|
|
|
|
|
} else if (item.endsWith('.ts')) {
|
|
|
|
|
// Single file sample (e.g. tic-tac-toe.ts)
|
|
|
|
|
entries[item.replace('.ts', '')] = fullPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return entries;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const samplesEntries = getSamplesEntries();
|
|
|
|
|
|
2026-04-07 16:09:47 +08:00
|
|
|
/**
|
|
|
|
|
* Plugin to rewrite @/core/* and @/utils/* imports to use 'boardgame-core'
|
|
|
|
|
*/
|
|
|
|
|
function rewriteBoardgameImports(): Plugin {
|
|
|
|
|
return {
|
|
|
|
|
name: 'rewrite-boardgame-imports',
|
|
|
|
|
setup(build) {
|
|
|
|
|
build.onResolve({ filter: /^@\/(core|utils)\// }, args => {
|
|
|
|
|
// Mark these as external and rewrite to 'boardgame-core'
|
|
|
|
|
return {
|
|
|
|
|
path: 'boardgame-core',
|
|
|
|
|
external: true,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Also handle @/index imports
|
|
|
|
|
build.onResolve({ filter: /^@\/index$/ }, args => {
|
|
|
|
|
return {
|
|
|
|
|
path: 'boardgame-core',
|
|
|
|
|
external: true,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 11:37:05 +08:00
|
|
|
export default defineConfig({
|
|
|
|
|
entry: samplesEntries,
|
|
|
|
|
format: ['esm'],
|
|
|
|
|
dts: true,
|
|
|
|
|
clean: true,
|
|
|
|
|
sourcemap: true,
|
|
|
|
|
outDir: 'dist/samples',
|
|
|
|
|
external: ['@preact/signals-core', 'mutative', 'inline-schema', 'boardgame-core'],
|
2026-04-07 16:09:47 +08:00
|
|
|
esbuildPlugins: [csvLoader(), rewriteBoardgameImports()],
|
2026-04-07 11:37:05 +08:00
|
|
|
});
|