Skip to content

Commit

Permalink
chore(schematics): add addon-doc migration step (#8682)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Aug 26, 2024
1 parent f28acd1 commit a666b53
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 146 deletions.
11 changes: 8 additions & 3 deletions projects/cdk/schematics/migration.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
"schematics": {
"migrateCssVarsV4": {
"description": "Migrate Taiga UI css variables",
"version": "4.0.0-rc.1",
"version": "4.0.0",
"factory": "./ng-update/v4/migrate-css-vars/index#migrateCssVars"
},
"migrateIconsV4": {
"description": "Migrate Taiga UI icons to a new format",
"version": "4.0.0-rc.1",
"version": "4.0.0",
"factory": "./ng-update/v4/migrate-icons/index#migrateIcons"
},
"migrateAddonDocV4": {
"description": "Migrate Taiga UI addon doc",
"version": "4.0.0",
"factory": "./ng-update/v4/migrate-addon-doc/index#migrateAddonDoc"
},
"updateToV4": {
"description": "Updates Taiga UI packages to v4",
"version": "4.0.0-rc.1",
"version": "4.0.0",
"factory": "./ng-update/v4/index#updateToV4"
}
}
Expand Down
73 changes: 73 additions & 0 deletions projects/cdk/schematics/ng-update/v4/migrate-addon-doc/index.ts
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`);
},
]);
}
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',
},
},
];
Loading

0 comments on commit a666b53

Please sign in to comment.