refactor: added type generation from schema for sdk with comments
This commit is contained in:
parent
2683d46b16
commit
04e332d91e
7 changed files with 65 additions and 20 deletions
|
|
@ -4,6 +4,11 @@ import sdkTsConfig from './sdk/sdk.tsconfig.json';
|
|||
import sdkPackage from './sdk/package.json';
|
||||
import { emptyDir } from 'fs-extra';
|
||||
import { generateDtsBundle } from 'dts-bundle-generator';
|
||||
import { zodToTs, createAuxiliaryTypeStore, printNode } from 'zod-to-ts';
|
||||
|
||||
import * as types from './sdk/sdk';
|
||||
|
||||
const zodTypeRegex = /z\.infer<typeof? ([\w\d]+)>/gm;
|
||||
|
||||
async function generateApiDeclarations ()
|
||||
{
|
||||
|
|
@ -19,7 +24,29 @@ async function generateApiDeclarations ()
|
|||
}
|
||||
},], { preferredConfigPath: './scripts/sdk/sdk.tsconfig.json' });
|
||||
|
||||
await Bun.write('./dist-sdk/index.d.ts', results);
|
||||
const auxiliaryTypeStore = createAuxiliaryTypeStore();
|
||||
|
||||
await Bun.write('./dist-sdk/index.d.ts', results.map(r =>
|
||||
{
|
||||
const result = r;
|
||||
return result.replaceAll(zodTypeRegex, (e, name) =>
|
||||
{
|
||||
const schema = types[name as keyof typeof types];
|
||||
if (schema)
|
||||
{
|
||||
try
|
||||
{
|
||||
const { node } = zodToTs(schema as any, { auxiliaryTypeStore, unrepresentable: 'any' });
|
||||
return printNode(node);
|
||||
} catch (error)
|
||||
{
|
||||
console.error(error);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return e;
|
||||
});
|
||||
}));
|
||||
|
||||
const pkg = {
|
||||
...sdkPackage,
|
||||
|
|
@ -29,7 +56,7 @@ async function generateApiDeclarations ()
|
|||
author: appPkg.author,
|
||||
peerDependencies: appPkg.dependencies
|
||||
};
|
||||
await Bun.write(path.join(outDir, '..', 'package.json'), JSON.stringify(pkg, null, 3));
|
||||
await Bun.write(path.join(outDir, 'package.json'), JSON.stringify(pkg, null, 3));
|
||||
}
|
||||
|
||||
await generateApiDeclarations();
|
||||
14
scripts/sdk/README.md
Normal file
14
scripts/sdk/README.md
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Gameflow Deck SDK
|
||||
|
||||
This is the type definitions for Gameflow Deck plugins.
|
||||
|
||||
## Developing a plugin
|
||||
|
||||
The plugin must have a default export class of type `PluginType`. It exposes the context and all the hooks to be tapped.
|
||||
Gameflow uses the [Tapable Hooks](https://github.com/webpack/tapable).
|
||||
|
||||
The package must expose a main script gameflow will import and validate. It must implement the type fields on `PluginDescriptionType`.
|
||||
|
||||
## Publishing
|
||||
|
||||
For the plugin to show up in the UI for download. It must be published to NPM with the `gameflow-plugin` keyword. Gameflow uses bun to install plugins as packages from npmjs.
|
||||
|
|
@ -1,4 +1,9 @@
|
|||
{
|
||||
"name": "gameflow-sdk",
|
||||
"types": "index.d.ts"
|
||||
"types": "index.d.ts",
|
||||
"description": "plugin SDK for the Gameflow Deck Launcher",
|
||||
"keywords": [
|
||||
"gameflow",
|
||||
"sdk"
|
||||
]
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
"emitDeclarationOnly": true,
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
"outDir": "../../dist-sdk/sdk",
|
||||
"outDir": "../../dist-sdk",
|
||||
"types": [
|
||||
"node"
|
||||
],
|
||||
|
|
@ -38,10 +38,5 @@
|
|||
"../../src/mainview/scripts/queries/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"../../src/bun/api/hooks",
|
||||
"../../src/bun/types",
|
||||
"../../src/shared"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue