warthog
warthog copied to clipboard
Missing module imports for ManyToOne, OneToMany field types
Do you want to request a feature or report a bug?
Bug
Generating model with warthog generate
command does not add import
statement for related fields. Adding additional logic to model.ts.ejs
I was able to run it successfully. Here is my commit: https://github.com/metmirr/warthog/commit/e9b7eeb98729de510ec81a562bc252e61fdbe11f
Good call out. Your version will work with your particular cliGeneratePath
, but would break for others. To make this work with any CLI_GENERATE_PATH
, we'll need to do something similar to what's done here: https://github.com/metmirr/warthog/blob/master/src/cli/commands/generate.ts#L41
Perhaps pass a getFolderForModel
function into props
and then call it with the other model name. Something like:
function getFolderForModel(name: string) {
const names = {
className: toolbox.strings.pascalCase(name),
camelName: toolbox.strings.camelCase(name),
kebabName: toolbox.strings.kebabCase(name),
// Not proper pluralization, but good enough and easy to fix in generated code
camelNamePlural: toolbox.strings.camelCase(name) + 's'
};
// Allow folder to be passed in or pulled from config files
const cliGeneratePath =
options.folder ||
path.join(config.get('ROOT_FOLDER'), '/', config.get('CLI_GENERATE_PATH'), '/');
// TODO:DOCS
// Allow interpolation of the above names into the generate path like './src/${kebabName}'
const destFolder = supplant(cliGeneratePath, names);
I imagine you'll also need to use path.resolve
to make sure the path imports are relative.
Do you want to try to put in a PR for this?
Definitely! I need this to work properly but I can do it on weekend.