-
Notifications
You must be signed in to change notification settings - Fork 0
feat: name casing #2
base: master
Are you sure you want to change the base?
Conversation
@@ -1,3 +1,48 @@ | |||
import { CaseToCase } from 'case-to-case' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is the best package to do this
|
||
export class SchematicOption { | ||
constructor(private name: string, private value: boolean | string) {} | ||
constructor(private name: string, private value: boolean | string, private caseType: CaseType) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to pass CaseType
to the constructor of SchematicOption
, so that I can pass the flag to the schematics package and I can format each field accordingly.
This approach adds more noise than I would like, so I'm open to a better solution if anyone can find it
const excludedInputNames = ['schematic', 'spec', 'flat', 'specFileSuffix']; | ||
const options: SchematicOption[] = []; | ||
inputs.forEach((input) => { | ||
if (!excludedInputNames.includes(input.name) && input.value !== undefined) { | ||
options.push(new SchematicOption(input.name, input.value)); | ||
options.push(new SchematicOption(input.name, input.value, caseType)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would introduce a key-value options here since it has 3 arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean adding something like SchmaticOption('naming', 'camelCase')
?
That's the first thing I tried but I couldn't make it work because when we launch the command nest generate controller emails --naming=camelCase
we have two schematic options:
SchmaticOption('name', 'emails')
SchmaticOption('suffix', 'controller')
We need to apply the camelCase
transform to both, hence why I used a 3 way option.
If I misunderstood you please let me know, or maybe you can see something I'm not seeing.
One option could be to open a draft PR and ask the nestjs
authors for advice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposal: nameCase becomes an extensible object (additionalParameters = { caseNaming: hello
})
@@ -48,6 +48,10 @@ export class GenerateCommand extends AbstractCommand { | |||
'-c, --collection [collectionName]', | |||
'Schematics collection to use.', | |||
) | |||
.option( | |||
'--case [case]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--naming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--caseNaming
--fileCaseNaming
--directoryCaseNaming
--variableCaseNaming
Summary
This is the second of a multi PR effort aiming at supporting custom name casing conventions, as detailed here.
@nestjs/schematics
to accept acaseType
option when generating a controller.--case
option to the CLI so that it can be correctly passed to the schematic generator.controllers
For now I decided to support only controllers, to reduce the changes size and make reviewing easier. If the approach will be approved I will make sure to extend it to other objects and to add more tests.
How to run
Run:
Then clone this branch, and do:
Copy the
dist
folder in the previous reponest-cli/node_modules/@nestjs/schematics/dist/
Then run
node bin/nest.js g co keb-pap --case camel
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently
@nestjs/cli
useskebap-case
, as mentioned in this issue.Issue Number: 462
What is the new behavior?
The goal is to add a
--case
option to the CLI so that generated files will follow the desired name casing convention.Does this PR introduce a breaking change?