Code generation
ts
import { createHub, routeStore } from "@duplojs/http";
import { createHttpServer } from "@duplojs/http/node";
import { codeGeneratorPlugin } from "@duplojs/http/codeGenerator";
const hub = createHub({ environment: "DEV" })
.register(routeStore.getAll())
.plug(codeGeneratorPlugin({
outputFile: "types.d.ts",
generateDataParser: { outputFolder: "dataParsers" },
}));
await createHttpServer(
hub,
{
host: "localhost",
port: 1506,
},
);To generate typings for all your routes, use the codeGeneratorPlugin function from @duplojs/http/codeGenerator in the Hub, then start with the environment variable set to DEV or BUILD.
- The
outputFileparameter defines the file where route typings will be written. - The
generateDataParser.outputFolderparameter defines the folder where identified data parsers will be generated. - The
generateDataParser.disabledFromRouteparameter disables data parser generation from routes. - The
generateDataParser.dataParsersparameter lets you provide a list of data parsers to generate. In that case, only identified data parsers will be generated.
WARNING
You must have an HTTP server implementation, because the plugin hooks into beforeStartServer, which only runs through interface functions such as createHttpServer. Run with the Hub configured in BUILD mode to avoid starting the HTTP server.
