-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(schematics): add addon-doc migration step (#8682)
- Loading branch information
Showing
8 changed files
with
317 additions
and
146 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
73 changes: 73 additions & 0 deletions
73
projects/cdk/schematics/ng-update/v4/migrate-addon-doc/index.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,73 @@ | ||
import type {Rule, SchematicContext, Tree} from '@angular-devkit/schematics'; | ||
import {chain} from '@angular-devkit/schematics'; | ||
import {renameTypes, replaceIdentifiers} from '@taiga-ui/cdk/schematics/ng-update/steps'; | ||
import {getPackageJsonDependency, getSourceFiles, saveActiveProject} from 'ng-morph'; | ||
|
||
import {ALL_TS_FILES} from '../../../constants/file-globs'; | ||
import type {TuiSchema} from '../../../ng-add/schema'; | ||
import { | ||
FINISH_SYMBOL, | ||
infoLog, | ||
REPLACE_SYMBOL, | ||
SMALL_TAB_SYMBOL, | ||
titleLog, | ||
} from '../../../utils/colored-log'; | ||
import {removeModules} from '../../steps/remove-module'; | ||
import {getFileSystem} from '../../utils/get-file-system'; | ||
import {DOC_SYMBOLS_TO_REPLACE} from './replace-symbols'; | ||
|
||
export function migrateAddonDoc(options: TuiSchema): Rule { | ||
return chain([ | ||
(tree: Tree, _context: SchematicContext) => { | ||
const fileSystem = getFileSystem(tree); | ||
|
||
if (!getPackageJsonDependency(fileSystem.tree, '@taiga-ui/addon-doc')) { | ||
return; | ||
} | ||
|
||
!options['skip-logs'] && | ||
infoLog(`${SMALL_TAB_SYMBOL}${REPLACE_SYMBOL} replacing...`); | ||
|
||
removeModules(options, [ | ||
{ | ||
name: 'tuiGenerateRoutes', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
]); | ||
|
||
renameTypes(options, [ | ||
{ | ||
from: 'TuiDocExample', | ||
to: 'Record<string, TuiRawLoaderContent>', | ||
moduleSpecifier: ['@taiga-ui/addon-doc'], | ||
removeImport: true, | ||
newImports: [ | ||
{ | ||
name: 'TuiRawLoaderContent', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
getSourceFiles(ALL_TS_FILES).forEach((file) => | ||
file.replaceWithText( | ||
file | ||
.getFullText() | ||
.replaceAll( | ||
/RouterModule\.forChild\(tuiGenerateRoutes\(\w+\)\)/g, | ||
'RouterModule', | ||
), | ||
), | ||
); | ||
|
||
replaceIdentifiers(options, DOC_SYMBOLS_TO_REPLACE); | ||
|
||
fileSystem.commitEdits(); | ||
saveActiveProject(); | ||
|
||
!options['skip-logs'] && | ||
titleLog(`${FINISH_SYMBOL} addon-doc successfully migrated \n`); | ||
}, | ||
]); | ||
} |
138 changes: 138 additions & 0 deletions
138
projects/cdk/schematics/ng-update/v4/migrate-addon-doc/replace-symbols.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,138 @@ | ||
import type {ReplacementIdentifierMulti} from '../../interfaces/replacement-identifier'; | ||
|
||
export const DOC_SYMBOLS_TO_REPLACE: ReplacementIdentifierMulti[] = [ | ||
{ | ||
from: { | ||
name: 'DocumentationPropertyType', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
to: { | ||
name: 'TuiDocumentationPropertyType', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
}, | ||
{ | ||
from: { | ||
name: 'RawContentLoader', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
to: { | ||
name: 'TuiRawContentLoader', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
}, | ||
{ | ||
from: { | ||
name: 'TuiDocCopyModule', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
to: { | ||
name: 'TuiDocCopy', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
}, | ||
{ | ||
from: { | ||
name: 'TuiScrollIntoViewLinkModule', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
to: { | ||
name: 'TuiDocScrollIntoViewLink', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
}, | ||
{ | ||
from: { | ||
name: 'TuiTextCodeModule', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
to: { | ||
name: 'TuiDocText', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
}, | ||
{ | ||
from: { | ||
name: 'TuiDocDocumentationModule', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
to: { | ||
name: 'TuiAddonDoc', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
spreadInModule: true, | ||
}, | ||
}, | ||
{ | ||
from: { | ||
name: 'TuiDocPage', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
to: { | ||
name: 'TuiDocRoutePage', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
}, | ||
{ | ||
from: [ | ||
{ | ||
name: 'TuiDocCodeModule', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
{ | ||
name: 'TuiDocDemoModule', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
{ | ||
name: 'TuiDocMainModule', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
{ | ||
name: 'TuiDocNavigationModule', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
{ | ||
name: 'TuiDocPageModule', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
{ | ||
name: 'TuiAddonDocModule', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
], | ||
to: { | ||
name: 'TuiAddonDoc', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
spreadInModule: true, | ||
}, | ||
}, | ||
{ | ||
from: { | ||
name: 'TuiDocPage', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
to: { | ||
name: 'TuiDocRoutePage', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
}, | ||
{ | ||
from: { | ||
name: 'TuiDocPages', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
to: { | ||
name: 'TuiDocRoutePages', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
}, | ||
{ | ||
from: { | ||
name: 'TuiDeepPartial', | ||
moduleSpecifier: '@taiga-ui/cdk', | ||
}, | ||
to: { | ||
name: 'TuiDeepPartial', | ||
moduleSpecifier: '@taiga-ui/addon-doc', | ||
}, | ||
}, | ||
]; |
Oops, something went wrong.