refactor: Removed the use of d.ts files to support SDK generation for public plugins

This commit is contained in:
Simeon Radivoev 2026-05-05 01:21:22 +03:00
parent 06b7e4074d
commit 2683d46b16
Signed by: simeonradivoev
GPG key ID: 7611A451D2A5D37A
114 changed files with 408 additions and 257 deletions

35
scripts/build-sdk.ts Normal file
View file

@ -0,0 +1,35 @@
import path from 'node:path';
import appPkg from '../package.json';
import sdkTsConfig from './sdk/sdk.tsconfig.json';
import sdkPackage from './sdk/package.json';
import { emptyDir } from 'fs-extra';
import { generateDtsBundle } from 'dts-bundle-generator';
async function generateApiDeclarations ()
{
const tmpConfigPath = "./scripts/sdk/sdk.tsconfig.json";
const outDir = path.join(path.dirname(tmpConfigPath), sdkTsConfig.compilerOptions.outDir);
await emptyDir(outDir);
const results = generateDtsBundle([{
filePath: './scripts/sdk/sdk.ts',
output: {
inlineDeclareGlobals: true,
sortNodes: true,
}
},], { preferredConfigPath: './scripts/sdk/sdk.tsconfig.json' });
await Bun.write('./dist-sdk/index.d.ts', results);
const pkg = {
...sdkPackage,
license: appPkg.license,
version: appPkg.version,
repository: appPkg.repository,
author: appPkg.author,
peerDependencies: appPkg.dependencies
};
await Bun.write(path.join(outDir, '..', 'package.json'), JSON.stringify(pkg, null, 3));
}
await generateApiDeclarations();

View file

@ -22,7 +22,7 @@ function spawnServer ()
stderr: 'inherit',
stdin: 'inherit',
signal: abortController.signal,
killSignal: 'SIGUSR1',
killSignal: 'SIGKILL',
ipc (message, subprocess, handle)
{
if (message === 'focus')
@ -91,7 +91,7 @@ if (!process.env.HEADLESS)
spawnBrowser()?.then(async e =>
{
if (!server) return;
server.kill("SIGUSR1");
abortController.abort();
await server.exited;
});
}

View file

@ -1,5 +1,4 @@
import audioSprite from 'audiosprite';
import { $ } from 'bun';
import path from 'node:path';
import { soundMap } from '../src/mainview/scripts/audio/audioConstants';

View file

@ -1,6 +1,5 @@
import { $ } from "bun";
const lockfile = Bun.argv[2] ?? "bun.lockb";
const output = Bun.argv[3] ?? ".config/flatpak/sources.gen.json";
const text = await $`bun ./bun.lockb --hash: 0000000000000000-0000000000000000-0000000000000000-0000000000000000`.text();

4
scripts/sdk/package.json Normal file
View file

@ -0,0 +1,4 @@
{
"name": "gameflow-sdk",
"types": "index.d.ts"
}

18
scripts/sdk/sdk.ts Normal file
View file

@ -0,0 +1,18 @@
import { SettingsType } from '@/shared/constants';
import Conf from 'conf';
import { AppEventMap } from '../../src/bun/types/types';
import EventEmitter from "node:events";
import { TaskQueue } from '@/bun/api/task-queue';
export * from '../../src/bun/types/types.schema';
export * from '../../src/bun/types/types';
export * from '../../src/bun/api/hooks/app';
export * from '../../src/shared/constants';
export * from '../../src/shared/types';
export * from '../../src/shared/utils';
export declare const config: Conf<SettingsType>;
export declare let events: EventEmitter<AppEventMap>;
export declare let taskQueue: TaskQueue;
export { };

View file

@ -0,0 +1,47 @@
{
"compilerOptions": {
"target": "ES2022",
"useDefineForClassFields": true,
"lib": [
"ES2024"
],
"module": "ESNext",
"skipLibCheck": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"emitDeclarationOnly": true,
"declaration": true,
"strict": true,
"outDir": "../../dist-sdk/sdk",
"types": [
"node"
],
"paths": {
"@/*": [
"../../src/*"
],
"~/*": [
"../../*"
],
"@shared/*": [
"../../src/shared/*"
],
"@clients/*": [
"../../src/clients/*"
],
"@schema/*": [
"../../src/bun/api/schema/*"
],
"@queries/*": [
"../../src/mainview/scripts/queries/*"
]
}
},
"include": [
"../../src/bun/api/hooks",
"../../src/bun/types",
"../../src/shared"
]
}