Yellicode
The extensible code generator
- Getting started
- Tutorial - Model driven basics
- Tutorial - Full stack Angular application
- Fundamentals
- How-to
- Modeler
- Reference
Generating multiple files
Sometimes you might want to generate multiple files from a single template. For example, you might want to generate a number of TypeScript classes where each class resides in its own file. To do so, organize your template code as follows:
import { TextWriter } from '@yellicode/core';
import { Generator } from '@yellicode/templating';
import * as elements from '@yellicode/elements';
Generator.getModel().then((model: elements.Model) => {
// Generate a file for each class in the model
model.getAllClasses().forEach((eachClass) => {
Generator.generate({ outputFile: `${eachClass.name}.ts` },
(writer: TextWriter) => {
writer.writeLine(`/* This file contains the code for class '${eachClass.name}'. */`);
}
);
});
})
So, instead of calling generateFromModel() directly, we have split our generator calls into a single getModel() call and a variable number of generate() calls.