Manages the collection of generated content for code generation.

The GeneratedContentManager allows you to:

  • Collect generated files from multiple models.
  • Handle multiple targets (output directories) with custom overwrite settings.
  • Write the collected generated content to the filesystem.
const manager = new GeneratedContentManager(optionalListOfWorkspaceURIs);

// Generate content for multiple models
generator(manager.generatorManagerFor(model1));
generator(manager.generatorManagerFor(model2));

// Retrieve the collected content (optional)
const content = manager.getGeneratedContent();

// Write the generated content to disk
await manager.writeToDisk('./generated');
function generator(manager: GeneratorManager) {
const model = manager.getModel();
const document = manager.getDocument();
const workspaceURI = manager.getWorkspaceURI();
const localPath = manager.getDocumentLocalPath();

// Generate files
manager.createFile('src-gen/abstract_process.ts', '// Generated by Langium. Do not edit.');
manager.createFile('src/process.ts', '// Initially generated by Langium', { overwrite: false });
}

Constructors

Methods

  • Creates a new file with the given content and metadata.

    Parameters

    • targetName: undefined | string

      The target name for which the file is generated. Defaults to the default target.

    • filePath: string

      The relative path of the file to create.

    • content: string

      The content of the file.

    • overwrite: boolean

      Whether to overwrite the file if it already exists.

    • documentPath: string

      The path to the source document from which the file was generated.

    Returns void

    If a file with the same path and different content or overwrite flag has already been generated.

  • Returns the generated content for the provided target or the default target.

    Parameters

    • OptionaltargetName: string

      The target name for which to get the generated content. If not provided, the default target is used.

    Returns GeneratedContent

    A GeneratedContent map containing the generated files.

    If the specified target is not registered.

  • Writes the generated content for a target to the file system asynchronously.

    Existing files are only overwritten if the overwrite flag is set (default behavior). If the file already exists and the content is the same, the file is not overwritten, preserving the timestamp and not triggering file system file change events.

    Parameters

    • outputDir: string

      The output directory where the files will be written.

    • Optionaltarget: string

      The target name whose content should be written. If not provided, the default target is used.

    Returns Promise<void>

    If an error occurs during file or directory operations.