-
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.
fix(misc): fix misc issues with move generators
- Loading branch information
1 parent
836cd34
commit 5d573fc
Showing
15 changed files
with
360 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './normalize-schema'; | ||
export * from './update-module-name'; | ||
export * from './update-ng-package'; | ||
export * from './update-secondary-entry-points'; |
15 changes: 15 additions & 0 deletions
15
packages/angular/src/generators/move/lib/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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Tree } from '@nx/devkit'; | ||
import { readProjectConfiguration } from '@nx/devkit'; | ||
import type { NormalizedSchema, Schema } from '../schema'; | ||
import { getNewProjectName } from '../../utils/get-new-project-name'; | ||
|
||
export function normalizeSchema(tree: Tree, schema: Schema): NormalizedSchema { | ||
const newProjectName = getNewProjectName(schema.destination); | ||
const { root } = readProjectConfiguration(tree, schema.projectName); | ||
|
||
return { | ||
...schema, | ||
newProjectName, | ||
oldProjectRoot: root, | ||
}; | ||
} |
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
71 changes: 71 additions & 0 deletions
71
packages/angular/src/generators/move/lib/update-secondary-entry-points.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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { Tree } from '@nx/devkit'; | ||
import { | ||
joinPathFragments, | ||
normalizePath, | ||
readProjectConfiguration, | ||
visitNotIgnoredFiles, | ||
} from '@nx/devkit'; | ||
import { basename, dirname } from 'path'; | ||
import type { NormalizedSchema } from '../schema'; | ||
|
||
const libraryExecutors = [ | ||
'@angular-devkit/build-angular:ng-packagr', | ||
'@nx/angular:ng-packagr-lite', | ||
'@nx/angular:package', | ||
// TODO(v17): remove when @nrwl/* scope is removed | ||
'@nrwl/angular:ng-packagr-lite', | ||
'@nrwl/angular:package', | ||
]; | ||
|
||
export function updateSecondaryEntryPoints( | ||
tree: Tree, | ||
schema: NormalizedSchema | ||
): void { | ||
const project = readProjectConfiguration(tree, schema.newProjectName); | ||
|
||
if (project.projectType !== 'library') { | ||
return; | ||
} | ||
|
||
if ( | ||
!Object.values(project.targets ?? {}).some((target) => | ||
libraryExecutors.includes(target.executor) | ||
) | ||
) { | ||
return; | ||
} | ||
|
||
visitNotIgnoredFiles(tree, project.root, (filePath) => { | ||
if ( | ||
basename(filePath) !== 'ng-package.json' || | ||
normalizePath(filePath) === | ||
joinPathFragments(project.root, 'ng-package.json') | ||
) { | ||
return; | ||
} | ||
|
||
updateReadme( | ||
tree, | ||
dirname(filePath), | ||
schema.projectName, | ||
schema.newProjectName | ||
); | ||
}); | ||
} | ||
|
||
function updateReadme( | ||
tree: Tree, | ||
dir: string, | ||
oldProjectName: string, | ||
newProjectName: string | ||
) { | ||
const readmePath = joinPathFragments(dir, 'README.md'); | ||
if (!tree.exists(readmePath)) { | ||
return; | ||
} | ||
|
||
const findName = new RegExp(`${oldProjectName}`, 'g'); | ||
const oldContent = tree.read(readmePath, 'utf-8'); | ||
const newContent = oldContent.replace(findName, newProjectName); | ||
tree.write(readmePath, newContent); | ||
} |
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.