Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(angular): normalize project name and don't default to npmScope as…
… prefix when it's not a valid html selector (#10116)
- Loading branch information
1 parent
62d0535
commit 0e21fa0
Showing
4 changed files
with
37 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,33 @@ | ||
import { names } from '@nrwl/devkit'; | ||
|
||
export function normalizeDirectory(appName: string, directoryName: string) { | ||
export function normalizeDirectory( | ||
appName: string, | ||
directoryName: string | ||
): string { | ||
return directoryName | ||
? `${names(directoryName).fileName}/${names(appName).fileName}` | ||
: names(appName).fileName; | ||
} | ||
|
||
export function normalizeProjectName(appName: string, directoryName: string) { | ||
return normalizeDirectory(appName, directoryName) | ||
.replace(new RegExp('/', 'g'), '-') | ||
.replace(/-\d+/g, ''); | ||
export function normalizeProjectName( | ||
appName: string, | ||
directoryName: string | ||
): string { | ||
return normalizeDirectory(appName, directoryName).replace(/\//g, '-'); | ||
} | ||
|
||
export function normalizePrefix( | ||
prefix: string | undefined, | ||
npmScope: string | undefined | ||
): string { | ||
if (prefix) { | ||
return prefix; | ||
} | ||
|
||
// Prefix needs to be a valid html selector, if npmScope it's not valid, we don't default | ||
// to it and let it fall through to the Angular schematic to handle it | ||
// https://github.com/angular/angular-cli/blob/1c634cd327e5a850553b258aa2d5e6a6b2c75c65/packages/schematics/angular/component/index.ts#L130 | ||
const htmlSelectorRegex = | ||
/^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*)*$/; | ||
return npmScope && htmlSelectorRegex.test(npmScope) ? npmScope : undefined; | ||
} |