Skip to content

Commit

Permalink
chore(schematics): add providers for proprietary (#10156)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Jan 13, 2025
1 parent be5fef1 commit 8c80d2b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
57 changes: 56 additions & 1 deletion projects/cdk/schematics/ng-update/v4/steps/migrate-editor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/// <reference lib="es2021" />
import type {DevkitFileSystem} from 'ng-morph';
import {
addProviderToComponent,
addProviderToNgModule,
FINISH_SYMBOL,
getNgComponents,
getNgModules,
getPackageJsonDependency,
getSourceFiles,
infoLog,
Node,
REPLACE_SYMBOL,
saveActiveProject,
SMALL_TAB_SYMBOL,
Expand All @@ -13,10 +18,12 @@ import {

import {ALL_TS_FILES} from '../../../constants/file-globs';
import type {TuiSchema} from '../../../ng-add/schema';
import {addUniqueImport} from '../../../utils/add-unique-import';
import {getNamedImportReferences} from '../../../utils/get-named-import-references';
import {replaceIdentifiers} from '../../steps/replace-identifier';
import {replacePackageName} from '../../steps/replace-package-name';

export const TUI_EDITOR_VERSION = '^4.11.0';
export const TUI_EDITOR_VERSION = '^4.21.0';

export function migrateEditor(fileSystem: DevkitFileSystem, options: TuiSchema): void {
const moduleSpecifier = ['@tinkoff/tui-editor', '@taiga-ui/addon-editor'];
Expand All @@ -31,6 +38,8 @@ export function migrateEditor(fileSystem: DevkitFileSystem, options: TuiSchema):
!options['skip-logs'] &&
infoLog(`${SMALL_TAB_SYMBOL}${REPLACE_SYMBOL} migrating editor...`);

addProprietaryProviders(fileSystem);

replaceIdentifiers(options, [
{
from: {name: 'TuiEditorModule', moduleSpecifier},
Expand Down Expand Up @@ -107,3 +116,49 @@ export function migrateEditor(fileSystem: DevkitFileSystem, options: TuiSchema):

!options['skip-logs'] && titleLog(`${FINISH_SYMBOL} successfully migrated \n`);
}

function addProprietaryProviders(fileSystem: DevkitFileSystem): void {
const proprietary =
getPackageJsonDependency(fileSystem.tree, '@taiga-ui/proprietary-core') ||
getPackageJsonDependency(fileSystem.tree, '@taiga-ui/proprietary');

if (!proprietary) {
return;
}

const refs = [
...getNamedImportReferences('TuiEditorModule', '@tinkoff/tui-editor'),
...getNamedImportReferences('TuiEditorModule', '@taiga-ui/addon-editor'),
];

for (const ref of refs) {
if (ref.wasForgotten()) {
return;
}

const parent = ref.getParent();
const filePath = parent?.getSourceFile().getFilePath() ?? '';

if (Node.isImportSpecifier(parent)) {
addUniqueImport(filePath, 'tuiEditorOptionsProvider', '@taiga-ui/editor');
addUniqueImport(
filePath,
'TUI_PROPRIETARY_EDITOR_ICONS',
'@taiga-ui/proprietary',
);
} else if (Node.isArrayLiteralExpression(parent)) {
const componentClass = getNgComponents(filePath)[0];
const moduleClass = getNgModules(filePath)[0];
const provider =
'tuiEditorOptionsProvider({icons: TUI_PROPRIETARY_EDITOR_ICONS})';

if (componentClass) {
addProviderToComponent(componentClass, provider);
}

if (moduleClass) {
addProviderToNgModule(moduleClass, provider);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export class Test {
}`;

const COMPONENT_AFTER = `import { TUI_SANITIZER } from "@taiga-ui/legacy";
import { TuiEditor, TuiEditorSocket, TUI_EDITOR_DEFAULT_EXTENSIONS, TUI_EDITOR_DEFAULT_TOOLS } from "@taiga-ui/editor";
import { TUI_PROPRIETARY_EDITOR_ICONS } from "@taiga-ui/proprietary";
import { tuiEditorOptionsProvider, TuiEditor, TuiEditorSocket, TUI_EDITOR_DEFAULT_EXTENSIONS, TUI_EDITOR_DEFAULT_TOOLS } from "@taiga-ui/editor";
import { TuiRoot, TuiAlert, TuiDialog } from '@taiga-ui/core';
import {NgDompurifySanitizer} from '@taiga-ui/dompurify';
Expand All @@ -85,7 +86,8 @@ import {TuiEditorTool} from '@taiga-ui/editor';
{
provide: TUI_SANITIZER,
useClass: NgDompurifySanitizer,
}
},
tuiEditorOptionsProvider({icons: TUI_PROPRIETARY_EDITOR_ICONS})
],
})
export class Test {
Expand All @@ -99,6 +101,7 @@ const PACKAGE_JSON_BEFORE = `{
"@angular/core": "~13.0.0",
"@taiga-ui/core": "~3.35.0",
"@taiga-ui/cdk": "~3.35.0",
"@taiga-ui/proprietary-core": "~3.35.0",
"@taiga-ui/addon-editor": "~3.35.0",
"@tinkoff/ng-polymorpheus": "1.2.3",
"@tinkoff/ng-event-plugins": "4.5.6"
Expand All @@ -113,7 +116,8 @@ const PACKAGE_JSON_AFTER = `{
"@taiga-ui/editor": "${TUI_EDITOR_VERSION}",
"@taiga-ui/event-plugins": "${TUI_EVENT_PLUGINS_VERSION}",
"@taiga-ui/legacy": "${TUI_VERSION}",
"@taiga-ui/polymorpheus": "${TUI_POLYMORPHEUS_VERSION}"
"@taiga-ui/polymorpheus": "${TUI_POLYMORPHEUS_VERSION}",
"@taiga-ui/proprietary": "${TUI_VERSION}"
}
}`.trim();

Expand Down

0 comments on commit 8c80d2b

Please sign in to comment.