Creates an instance of PgGenerator.
are parameters for several options.
are added by pg-generator
functions and not for user.
If clear option is true, this method is called. It deletes destination path. User may override this method to tailor clear operation according to generator's purposes.
Executes the default sub-generator app
from a generator. If options are provided, they are combined with current options.
this.composeWith("generator-from-npm");
this.composeWith("generator-from-npm", options);
this.composeWith(require.resolve("./local-generator"), options);
is the name or path of the generator. If it is a local path, use require.resolve
or provide an absolute path.
are the new options added on top of curent options.
Executes a sub-generator from a generator. If options are provided, they are merged with current options. Also some of the options
are changed to sensible default values for sub-generators (e.g. clear
is changed to false
), but they can be overridden by
newly provided options.
this.composeWith("generator-from-npm", "sub-generator");
this.composeWith(require.resolve("./local-generator"), "sub-generator", options);
is the name or path of the generator. If it is a local path, use require.resolve
or provide an absolute path.
is the name of the sub-generator to be executed.
are the new options added on top of curent options.
Provides generator specific extra context to templates. This data is deeply merged with context provided by user.
export default class App extends PgGenerator {
protected context(): Record<string, any> {
return { global: { addSchemaName: true } };
}
}
generator spesific extra context data.
Copy the source file to the destination. Also creates the destination directory if it does not exist.
is the source file to copy.
is the destination file to be created.
Removes file or directory (and it's contents() from destination. If destination is equal to cwd()
it throws error and aborts operation for a safety measure. Most probably cwd()
contains other files too.
is the path relative to the destination root.
Returns abosulte path for the given path relative to output directory.
is the path relative to output directory.
the absolute path.
Fetches and merges context data from pg-generator
instance, context file and options.
The context file may be a JSON5 data file (may contain comments etc.) or a JavaScript file
with a default export of object or a function. If it is a function, it is passed
pg-structure
db instance.
Merge priorities are: options.context
> context file > context()
method.
merged context data.
Formats given content. By default prettier
is used. Plase note that at this stage file is not written to disk yet.
is the path of the destination file to be created.
is the content to format.
formatted code.
Renders all templates in [rootDir]/templates
directory with the render function using related context data,
and writes generated contents to the files in output directory. If render function returns undefined
for a template/database object pair no file is not written for that pair.
Template file names may contain variables and basic filter functions to change names of generated files.
Additionally copies all files in [rootDir]/files
to the output directory.
Executed after clear operation.
Writes generated content from render to the destination file.
is the destionation path of the file to be cerated..
is the content to process.
Generates content from the template with provided path using the context.
import engine from "my-favorite-template-engine";
export default class Md extends PgGenerator {
protected async render(templatePath: string, context: Context): Promise<string> {
return engine.render(templatePath, context);
}
}
is the path of the template file to generate content.
is the data to be used for generating content.
generated content.
Returns abosulte path for the given path relative to template root.
is the path relative to template root.
the absolute path.
Writes given content to the file after creating it's directory.
is the content to write.
Generated using TypeDoc
Base abstract class for for pg-generator classes.