The factory function initializes your generator and returns a watch handler:
ts
import type { GeneratorFactory } from "@kosmojs/devlib";
import type { Options } from "./index";
export const factory: GeneratorFactory<Options> = async (
pluginOptions,
generatorOptions
) => {
const { appRoot, sourceFolder, formatters } = pluginOptions;
// Perform initialization
// Set up paths, prepare templates, etc.
return {
async watchHandler(entries, event) {
// Process route entries and generate files
},
};
};The factory receives two arguments:
pluginOptions (PluginOptionsResolved) - Options passed to the dev plugin, shared across all generators:
baseurl- Base URL for this source folderapiurl- API URL prefixappRoot- Absolute path to project rootsourceFolder- Name of the source folder being processedoutDir- Build output directoryformatters- Array of code formatters to applyrefineTypeName- Name used for type refinements (default: "TRefine")watcher- File watcher configuration
generatorOptions - Your generator's specific options (second generic parameter). Can be undefined if your generator doesn't accept options.