API Reference
This section documents the internal utility modules and classes undersrc/utils/.
MainGenerator
Module:src/utils/main/main.generator.ts
A builder-pattern class that generates the contents of a NanoForge main.ts entry point file. It is used by the
part-main schematic.
Methods
generateBaseImports(hasTypes: boolean)adds the base NanoForge imports and conditionally emits type imports.generateLibsImports(libs)generates import statements for all libraries listed in the save file.generateComponentsImports(components)generates import statements for all components.generateSystemsImports(systems)generates import statements for all systems.generateMainFunction(hasTypes, cb)wraps generated output in anexport async function main(...)block.generateApp(isServer)emitsNanoforgeFactory.createClient()orNanoforgeFactory.createServer().generateAppInit()emitsawait app.init(options);.generateAppRun()emitsawait app.run();.generateLibsInstances(libs)emitsconst <id> = new <Name>();for each library.generateLibsInit(libs)emits the matchingapp.use*()call for each library type.generateRegistry(libs)emitsconst registry = <ecsLib>.registry;.generateEntities(entities)emits entity creation and component attachment calls.generateSystems(systems)emitsregistry.addSystem(<name>);for each system.generateInitFunctionIfNeeded(needed, func)conditionally emits lifecycle hook calls.generateInitFunctionsImportsIfNeeded(needed)conditionally emits lifecycle hook imports.toString()returns the accumulated generated code.
ConfigFinder
Module:src/utils/config/config.finder.ts
Searches the virtual file tree for an existing nanoforge.config.json and returns the parsed config if found.
find(tree, path)recursively searches upward from the given path.
ConfigDeclarator
Module:src/utils/config/config.declarator.ts
Updates a configuration tree by merging server options.
declare(tree, path, server)reads the config, deep-merges server configuration when requested, and writes the result back.
Formatting Utilities
Module:src/utils/formatting.ts
toKebabCase(str)converts a string to kebab-case.toCamelCase(str)converts a string to camelCase.toPascalCase(str)converts a string to PascalCase.
Name Utilities
Module:src/utils/name.ts
resolvePackageName(path)extracts the package name from a path string and handles scoped packages.
Object Utilities
Module:src/utils/object.ts
deepMerge(...objects)recursively merges multiple objects together.isObject(item)returnstruewhen the item is a plain object.
Types and Enums
Module:src/utils/main/enums.ts
The init function enum defines the six lifecycle hook names:
src/utils/main/save.type.ts
The save types describe the metadata consumed by part-main:
Constants
Module:src/utils/main/const.ts
Maps library types to the corresponding app.use*() method name.