nest-cli icon indicating copy to clipboard operation
nest-cli copied to clipboard

Add configuration option to generate files with PascalCase instead of the default naming convention

Open bbenoist opened this issue 5 years ago • 11 comments

I'm submitting a...

  • [x] Feature request

Current behavior

As of now, if I generate a new file with nest g, its is named name.type.ts (e.g. my.module.ts).

I'd like the tool to create a file named NameType.ts (e.g. MyModule.ts) so that it matches the name of the class it contains.

Expected behavior

Ideally, a fileNameCase configuration option in nest-cli.json of type "dot" | "pascal" | "camel" | "snake" | "kebab" would be nice.

Minimal reproduction of the problem with instructions

nest g mo my generates a file named my.module.ts

What is the motivation / use case for changing the behavior?

All of my company source files are named with the same name as the classes that they include. It's a common convention we see in a lot of OOP projects.

bbenoist avatar Nov 13 '19 17:11 bbenoist

Side-demand. It would be nice to also support naming test files with .test.ts instead of .spec.ts via a testFileExtension option too.

bbenoist avatar Nov 13 '19 20:11 bbenoist

Side-demand. It would be nice to also support naming test files with .test.ts instead of .spec.ts via a testFileExtension option too.

We're tracking this here https://github.com/nestjs/schematics/issues/143

kamilmysliwiec avatar Nov 14 '19 09:11 kamilmysliwiec

If a fileNameCase is introduced, should it only affect filenames, as suggested by the option name? What about directory names, if you specify that in the generate command, such as nest g controller auth-dir/users_dir/users --no-spec?

Should there also be introduced a directoryNameCase option? or should it just be a nameCase option that affect both files and directories?

Something like https://www.npmjs.com/package/change-case could help implement the solution without having to worry about correct case convertions

emilgodsk avatar Jan 12 '20 16:01 emilgodsk

this would be a very nice addition. having to switch to kabob case is a huge pain for our team

cyrdax avatar Nov 11 '20 23:11 cyrdax

Is there any news on this?

donnyroufs avatar Aug 04 '21 06:08 donnyroufs

Is there any news on this?(

oonsamyi avatar Dec 16 '21 06:12 oonsamyi

Is there any news on this? Do you need any help?

hydra13 avatar Jan 18 '22 14:01 hydra13

Contributions are more than welcome! @hydra13

kamilmysliwiec avatar Jan 18 '22 14:01 kamilmysliwiec

Hi, is this issue still on going? I need this feature (with camelcase) and want to take a look if it's still valid. @kamilmysliwiec

erie0210 avatar Mar 30 '22 08:03 erie0210

@kamilmysliwiec can you point me to the code which generates the files? I want to try implementing support for file names in PascalCase. 🙂

bennycode avatar Aug 06 '22 16:08 bennycode

@bennycode all templates lives here: https://github.com/nestjs/schematics and are chosen here: https://github.com/nestjs/nest-cli/blob/master/actions/generate.action.ts

micalevisk avatar Aug 06 '22 16:08 micalevisk

I started working on a draft PR for this feature. @kamilmysliwiec or @micalevisk I would love some feedback!

espoal avatar Jul 31 '23 21:07 espoal

Let's track this here https://github.com/nestjs/nest-cli/pull/2208

kamilmysliwiec avatar Aug 01 '23 06:08 kamilmysliwiec