-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): added pathScheme for project generators #464
feat(core): added pathScheme for project generators #464
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit a1c2f67. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 9 targets
Sent with 💌 from NxCloud. |
Added pathScheme (default nx) to app,lib,test generation. Added and e2e test and updated generated docs
62306fa
to
e41753c
Compare
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.
This looks good! Thanks for the contribution 🎉. I left a few comments, once they are fixed we can get it merged.
const projectName = | ||
options.pathScheme === 'nx' | ||
? projectDirectory.replace(/\//g, '-') | ||
: projectDirectory; |
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.
This should probably be something like:
const projectName = | |
options.pathScheme === 'nx' | |
? projectDirectory.replace(/\//g, '-') | |
: projectDirectory; | |
const projectName = | |
options.pathScheme === 'nx' | |
? projectDirectory.replace(/\//g, '-') | |
: `${names(options.directory).className}.${className}`; |
I don't really like the way the code looks / readability at this point, but that's more of a comment on the overall state of this normalization method... If you can clean up this little section some it would be appreciated.
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.
We should decide what we want the project name to be in workspace.json because if I am not mistaked, the projectName is what is used to add the project to NX.
So I see a couple of cases that could be NX pathScheme and dotnet.
1- nx g @nx-dotnet/core:library SomeCompany.Foobar --directory=somefolder ...
2- nx g @nx-dotnet/core:library SomeCompany.Foobar ...
In other words, with and without directory
NX Scheme with directory: somefolder-some-company.foobar, -
NX Scheme without directory: some-company.foobar,
And I would assume the following for dotnet scheme
Dotnet Scheme with directory: Somefolder.SomeCompany.Foobar
Dotnet Scheme without directory: SomeCompany.Foobar
What is the reason for adding the directory to the front of the name? Just to namespace it?
Feel free to message me directory to discuss. I am not sure if I was clear here. I want to get clarity on all cases before I rip this methods apart and try make it cleaner. That includes making the changes for projectName.
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.
Yeah, adding the directory is mainly to namespace it, but also to maintain consistency w/ the other Nx generators. The csproj name matches the generated project name, and w/ the nx first party generators when you specify --directory, it is prepended to the project name.
const testRoot = schema.projectRoot + '-' + suffix; | ||
const testProjectName = schema.projectName + '-' + suffix; | ||
const separator = schema.pathScheme === 'nx' ? '-' : '.'; | ||
const testRoot = schema.projectRoot + separator + suffix; |
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.
This will be kinda ugly too, but we should default to Test
rather than test
for the suffix when using dotnet path scheme.
Perhaps:
const suffix = schema.testProjectNameSuffix || (pathScheme === 'nx' ? 'test' : 'Test');
I don't really like having the ||
and a ternary here though, that's a lot of complexity represented by the single line. A decent amount of stuff changes based on that too, so it may be easier if we changed to something like:
let suffix: string;
let separator: string;
if (schema.pathScheme === 'nx') {
separator = '-'
suffix = schema.testProjectNameSuffix || 'test'
} else {
separator = '.'
suffix = schema.testProjectNameSuffix || 'Test'
}
I'm not really a fan of that either though... It'd look better if abstracted into a method.
// ....
const { suffix, separator } = getPathPartsFromSchema(schema)
// ...
function getPathPartsFromSchema(schema) {
if (schema.pathScheme === 'nx') {
return {
separator: '-'
suffix: schema.testProjectNameSuffix || 'test'
}
} else {
return {
separator: '.'
suffix: schema.testProjectNameSuffix || 'Test'
}
}
}
Cleaned up normalizeOptions, fixed schemas with proper alias, refactored generate test
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
I am not sure if I requested review properly after my changes. I have fixed and pushed everything. |
export interface PathParts { | ||
suffix: string; | ||
separator: '.' | '-'; | ||
} |
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.
This doesn't need to be exported
I'm going to merge this now, but going to add a few tests before releasing it. |
# [1.13.0](v1.12.0...v1.13.0) (2022-07-29) ### Bug Fixes * **core:** skip-swagger-lib should be true while experimental ([92cd2d8](92cd2d8)) ### Features * **core:** added pathScheme for project generators ([#464](#464)) ([ded5eb8](ded5eb8)) * **core:** generate typescript models from swagger/openapi project ([#447](#447)) ([cd56d1c](cd56d1c)) Jul 29, 2022, 2:17 PM
🎉 This PR is included in version 1.13.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Added pathScheme (default nx) to app,lib,test generation. Added and
e2e test and updated generated docs
This addresses issue #427