Skip to content
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

Merged
merged 3 commits into from
Jul 18, 2022

Conversation

rcompton78
Copy link
Contributor

Added pathScheme (default nx) to app,lib,test generation. Added and
e2e test and updated generated docs

This addresses issue #427

@nx-cloud
Copy link

nx-cloud bot commented Jul 11, 2022

Added pathScheme (default nx) to  app,lib,test generation.  Added and
e2e test and updated generated docs
@rcompton78 rcompton78 force-pushed the NX-427-add-path-scheme branch from 62306fa to e41753c Compare July 11, 2022 20:33
Copy link
Member

@AgentEnder AgentEnder left a 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.

packages/core/src/generators/app/schema.json Show resolved Hide resolved
packages/core/src/generators/app/schema.json Outdated Show resolved Hide resolved
packages/core/src/generators/lib/schema.json Show resolved Hide resolved
packages/core/src/generators/test/schema.json Show resolved Hide resolved
Comment on lines 64 to 67
const projectName =
options.pathScheme === 'nx'
? projectDirectory.replace(/\//g, '-')
: projectDirectory;
Copy link
Member

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:

Suggested change
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.

Copy link
Contributor Author

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.

Copy link
Member

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;
Copy link
Member

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
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@rcompton78 rcompton78 requested a review from AgentEnder July 14, 2022 16:26
@rcompton78
Copy link
Contributor Author

I am not sure if I requested review properly after my changes.

I have fixed and pushed everything.

Comment on lines +17 to +20
export interface PathParts {
suffix: string;
separator: '.' | '-';
}
Copy link
Member

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

@AgentEnder
Copy link
Member

I'm going to merge this now, but going to add a few tests before releasing it.

@AgentEnder AgentEnder changed the title feat: 🎸 Added pathScheme (NX|dotnet) feat(core): added pathScheme for project generators Jul 18, 2022
@AgentEnder AgentEnder merged commit ded5eb8 into nx-dotnet:master Jul 18, 2022
@rcompton78 rcompton78 deleted the NX-427-add-path-scheme branch July 18, 2022 19:48
github-actions bot pushed a commit that referenced this pull request Jul 29, 2022
# [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
@github-actions
Copy link
Contributor

🎉 This PR is included in version 1.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants