@xriptjs/typegen
v0.1.1
Published
Generate TypeScript definitions from xript manifests.
Maintainers
Readme
@xriptjs/typegen
Generate TypeScript type definitions from xript manifests.
Install
npm install @xriptjs/typegenCLI
npx xript-typegen manifest.json # print to stdout
npx xript-typegen manifest.json -o types.d.ts # write to fileGenerates .d.ts files with full JSDoc, namespace support, and hook type definitions from a manifest.
API
import { generateTypes, generateTypesFromFile } from "@xriptjs/typegen";
const dts = generateTypes({
xript: "0.1",
name: "my-app",
bindings: {
greet: {
description: "Returns a greeting.",
params: [{ name: "name", type: "string" }],
returns: "string",
},
},
});
console.log(dts);
// => declare function greet(name: string): string;generateTypes(manifest, options?): string
Generates TypeScript declarations from a manifest object.
Options:
header: custom header comment (replaces the default auto-generated header)
generateTypesFromFile(path, options?): Promise<{ content: string; filePath: string }>
Reads a manifest JSON file and generates TypeScript declarations.
What it generates
declare functionfor top-level bindingsdeclare namespacefor namespace bindings (with nesting)interfacefor custom types with fieldstypealiases for enum typesdeclare namespace hookswith handler signatures and phased hook namespaces- JSDoc with
@param,@deprecated, and@remarksannotations
Documentation
xript.dev: full docs, manifest specification, and examples.
License
MIT
