Skip to content

Commit

Permalink
chore(schematics): add providers for proprietary
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Jan 13, 2025
1 parent 32e78bf commit 955b0e4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
54 changes: 54 additions & 0 deletions projects/cdk/schematics/ng-update/v4/steps/migrate-editor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/// <reference lib="es2021" />
import {addUniqueImport, getNamedImportReferences} from '@taiga-ui/cdk/schematics';
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 @@ -31,6 +37,8 @@ export function migrateEditor(fileSystem: DevkitFileSystem, options: TuiSchema):
!options['skip-logs'] &&

Check warning on line 37 in projects/cdk/schematics/ng-update/v4/steps/migrate-editor.ts

View check run for this annotation

codefactor.io / CodeFactor

projects/cdk/schematics/ng-update/v4/steps/migrate-editor.ts#L37

Expected an assignment or function call and instead saw an expression. (@typescript-eslint/no-unused-expressions)
infoLog(`${SMALL_TAB_SYMBOL}${REPLACE_SYMBOL} migrating editor...`);

addProprietaryProviders(fileSystem);

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

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

Check warning on line 116 in projects/cdk/schematics/ng-update/v4/steps/migrate-editor.ts

View check run for this annotation

codefactor.io / CodeFactor

projects/cdk/schematics/ng-update/v4/steps/migrate-editor.ts#L116

Expected an assignment or function call and instead saw an expression. (@typescript-eslint/no-unused-expressions)
}

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 955b0e4

Please sign in to comment.