-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nx-plugin): use helper to determine project name and root in pro…
…ject generators (#18739)
- Loading branch information
1 parent
1b0439b
commit 016c89f
Showing
16 changed files
with
210 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 19 additions & 25 deletions
44
packages/plugin/src/generators/create-package/utils/normalize-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,36 @@ | ||
import { | ||
extractLayoutDirectory, | ||
getWorkspaceLayout, | ||
joinPathFragments, | ||
names, | ||
Tree, | ||
} from '@nx/devkit'; | ||
import { Tree } from '@nx/devkit'; | ||
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; | ||
import { CreatePackageSchema } from '../schema'; | ||
|
||
export interface NormalizedSchema extends CreatePackageSchema { | ||
bundler: 'swc' | 'tsc'; | ||
libsDir: string; | ||
projectName: string; | ||
projectRoot: string; | ||
projectDirectory: string; | ||
} | ||
|
||
export function normalizeSchema( | ||
export async function normalizeSchema( | ||
host: Tree, | ||
schema: CreatePackageSchema | ||
): NormalizedSchema { | ||
const { layoutDirectory, projectDirectory } = extractLayoutDirectory( | ||
schema.directory | ||
); | ||
const { libsDir: defaultLibsDir } = getWorkspaceLayout(host); | ||
const libsDir = layoutDirectory ?? defaultLibsDir; | ||
const name = names(schema.name).fileName; | ||
const fullProjectDirectory = projectDirectory | ||
? `${names(projectDirectory).fileName}/${name}` | ||
: name; | ||
const projectName = fullProjectDirectory.replace(new RegExp('/', 'g'), '-'); | ||
const projectRoot = joinPathFragments(libsDir, fullProjectDirectory); | ||
): Promise<NormalizedSchema> { | ||
const { | ||
projectName, | ||
names: projectNames, | ||
projectRoot, | ||
projectNameAndRootFormat, | ||
} = await determineProjectNameAndRootOptions(host, { | ||
name: schema.name, | ||
projectType: 'library', | ||
directory: schema.directory, | ||
projectNameAndRootFormat: schema.projectNameAndRootFormat, | ||
callingGenerator: '@nx/plugin:create-package', | ||
}); | ||
schema.projectNameAndRootFormat = projectNameAndRootFormat; | ||
|
||
return { | ||
...schema, | ||
bundler: schema.compiler ?? 'tsc', | ||
libsDir, | ||
projectName, | ||
projectRoot, | ||
name, | ||
projectDirectory: fullProjectDirectory, | ||
name: projectNames.projectSimpleName, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
016c89f
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.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-dev-nrwl.vercel.app
nx-five.vercel.app