Compare commits
2 Commits
6352977791
...
a84aa2426b
| Author | SHA1 | Date |
|---|---|---|
|
|
a84aa2426b | |
|
|
83658c9898 |
|
|
@ -0,0 +1 @@
|
||||||
|
!node_modules
|
||||||
|
|
@ -9,10 +9,15 @@
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./dist/index.js"
|
"import": "./dist/index.js"
|
||||||
|
},
|
||||||
|
"./samples/*": {
|
||||||
|
"types": "./dist/samples/*.d.ts",
|
||||||
|
"import": "./dist/samples/*.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsup",
|
"build": "tsup",
|
||||||
|
"build:samples": "tsup --config tsup.samples.config.ts",
|
||||||
"prepare": "npm run build",
|
"prepare": "npm run build",
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
"test:run": "vitest run",
|
"test:run": "vitest run",
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ export interface IGameContext<TState extends Record<string, unknown> = {} > {
|
||||||
run<T>(input: string): Promise<CommandResult<T>>;
|
run<T>(input: string): Promise<CommandResult<T>>;
|
||||||
runParsed<T>(command: Command): Promise<CommandResult<T>>;
|
runParsed<T>(command: Command): Promise<CommandResult<T>>;
|
||||||
prompt: <TResult,TArgs extends any[]=any[]>(def: PromptDef<TArgs>, validator: PromptValidator<TResult,TArgs>, currentPlayer?: string | null) => Promise<TResult>;
|
prompt: <TResult,TArgs extends any[]=any[]>(def: PromptDef<TArgs>, validator: PromptValidator<TResult,TArgs>, currentPlayer?: string | null) => Promise<TResult>;
|
||||||
addInterruption(promise: Promise<void>): void;
|
|
||||||
|
|
||||||
// test only
|
// test only
|
||||||
_state: MutableSignal<TState>;
|
_state: MutableSignal<TState>;
|
||||||
|
|
@ -50,9 +49,6 @@ export function createGameContext<TState extends Record<string, unknown> = {} >(
|
||||||
prompt(def, validator, currentPlayer) {
|
prompt(def, validator, currentPlayer) {
|
||||||
return commands.prompt(def.schema, validator, currentPlayer);
|
return commands.prompt(def.schema, validator, currentPlayer);
|
||||||
},
|
},
|
||||||
addInterruption(promise) {
|
|
||||||
state.addInterruption(promise);
|
|
||||||
},
|
|
||||||
|
|
||||||
_state: state,
|
_state: state,
|
||||||
_commands: commands,
|
_commands: commands,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
import {
|
import {Part} from "boardgame-core";
|
||||||
createGameCommandRegistry, Part, createRegion,
|
import {createRegion} from "boardgame-core";
|
||||||
IGameContext
|
import {createGameCommandRegistry, createPromptDef, IGameContext} from "boardgame-core";
|
||||||
} from '@/index';
|
|
||||||
import {createPromptDef} from "@/core/game";
|
|
||||||
|
|
||||||
const BOARD_SIZE = 3;
|
const BOARD_SIZE = 3;
|
||||||
const MAX_TURNS = BOARD_SIZE * BOARD_SIZE;
|
const MAX_TURNS = BOARD_SIZE * BOARD_SIZE;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
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';
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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'],
|
||||||
|
esbuildPlugins: [csvLoader()],
|
||||||
|
esbuildOptions(options) {
|
||||||
|
options.alias = {
|
||||||
|
'@': srcDir,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue