UNPKG

@taiga-ui/cdk

Version:

Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance

114 lines 5.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.migrateEditor = exports.TUI_EDITOR_VERSION = void 0; /// <reference lib="es2021" /> const ng_morph_1 = require("ng-morph"); const file_globs_1 = require("../../../constants/file-globs"); const add_unique_import_1 = require("../../../utils/add-unique-import"); const get_named_import_references_1 = require("../../../utils/get-named-import-references"); const replace_identifier_1 = require("../../steps/replace-identifier"); const replace_package_name_1 = require("../../steps/replace-package-name"); exports.TUI_EDITOR_VERSION = '^4.21.0'; function migrateEditor(fileSystem, options) { const moduleSpecifier = ['@tinkoff/tui-editor', '@taiga-ui/addon-editor']; const hasEditor = moduleSpecifier.every((pkg) => !(0, ng_morph_1.getPackageJsonDependency)(fileSystem.tree, pkg)); if (hasEditor) { return; } !options['skip-logs'] && (0, ng_morph_1.infoLog)(`${ng_morph_1.SMALL_TAB_SYMBOL}${ng_morph_1.REPLACE_SYMBOL} migrating editor...`); addProprietaryProviders(fileSystem); (0, replace_identifier_1.replaceIdentifiers)(options, [ { from: { name: 'TuiEditorModule', moduleSpecifier }, to: [ { name: 'TuiEditor', moduleSpecifier: '@taiga-ui/editor' }, { name: 'TuiEditorSocket', moduleSpecifier: '@taiga-ui/editor' }, ], }, { from: { name: 'TuiEditorSocketModule', moduleSpecifier }, to: { name: 'TuiEditorSocket', moduleSpecifier: '@taiga-ui/editor' }, }, { from: { name: 'TuiToolbarModule', moduleSpecifier }, to: { name: 'TuiToolbar', moduleSpecifier: '@taiga-ui/editor' }, }, { from: { name: 'defaultEditorExtensions', moduleSpecifier }, to: { name: 'TUI_EDITOR_DEFAULT_EXTENSIONS', moduleSpecifier: '@taiga-ui/editor', }, }, { from: { name: 'TUI_EDITOR_DEFAULT_EXTENSIONS', moduleSpecifier }, to: { name: 'TUI_EDITOR_DEFAULT_EXTENSIONS', moduleSpecifier: '@taiga-ui/editor', }, }, { from: [ { name: 'defaultEditorTools', moduleSpecifier }, { name: 'TUI_EDITOR_DEFAULT_TOOLS', moduleSpecifier }, ], to: { name: 'TUI_EDITOR_DEFAULT_TOOLS', moduleSpecifier: '@taiga-ui/editor' }, }, { from: { name: 'TUI_EDITOR_DEFAULT_EDITOR_TOOLS', moduleSpecifier }, to: { name: 'TUI_EDITOR_DEFAULT_TOOLS', moduleSpecifier: '@taiga-ui/editor' }, }, { from: { name: 'TuiColorPickerModule', moduleSpecifier }, to: { name: 'TuiColorPickerModule', moduleSpecifier: '@taiga-ui/legacy' }, }, { from: { name: 'TuiInputColorModule', moduleSpecifier }, to: { name: 'TuiInputColorModule', moduleSpecifier: '@taiga-ui/legacy' }, }, ]); (0, ng_morph_1.getSourceFiles)(file_globs_1.ALL_TS_FILES).forEach((sourceFile) => sourceFile.replaceWithText(sourceFile .getFullText() .replaceAll(/import\(['"`](@tinkoff|@taiga-ui)\/(tui-editor|addon-editor)\/(.*)['"`]\)/g, "import('@taiga-ui/editor')"))); (0, ng_morph_1.saveActiveProject)(); moduleSpecifier.forEach((pkg) => (0, replace_package_name_1.replacePackageName)(pkg, { name: '@taiga-ui/editor', version: exports.TUI_EDITOR_VERSION }, fileSystem.tree)); (0, ng_morph_1.saveActiveProject)(); !options['skip-logs'] && (0, ng_morph_1.titleLog)(`${ng_morph_1.FINISH_SYMBOL} successfully migrated \n`); } exports.migrateEditor = migrateEditor; function addProprietaryProviders(fileSystem) { var _a; const proprietary = (0, ng_morph_1.getPackageJsonDependency)(fileSystem.tree, '@taiga-ui/proprietary-core') || (0, ng_morph_1.getPackageJsonDependency)(fileSystem.tree, '@taiga-ui/proprietary'); if (!proprietary) { return; } const refs = [ ...(0, get_named_import_references_1.getNamedImportReferences)('TuiEditorModule', '@tinkoff/tui-editor'), ...(0, get_named_import_references_1.getNamedImportReferences)('TuiEditorModule', '@taiga-ui/addon-editor'), ]; for (const ref of refs) { if (ref.wasForgotten()) { return; } const parent = ref.getParent(); const filePath = (_a = parent === null || parent === void 0 ? void 0 : parent.getSourceFile().getFilePath()) !== null && _a !== void 0 ? _a : ''; if (ng_morph_1.Node.isImportSpecifier(parent)) { (0, add_unique_import_1.addUniqueImport)(filePath, 'tuiEditorOptionsProvider', '@taiga-ui/editor'); (0, add_unique_import_1.addUniqueImport)(filePath, 'TUI_PROPRIETARY_EDITOR_ICONS', '@taiga-ui/proprietary'); } else if (ng_morph_1.Node.isArrayLiteralExpression(parent)) { const [componentClass] = (0, ng_morph_1.getNgComponents)(filePath); const [moduleClass] = (0, ng_morph_1.getNgModules)(filePath); const provider = 'tuiEditorOptionsProvider({icons: TUI_PROPRIETARY_EDITOR_ICONS})'; if (componentClass) { (0, ng_morph_1.addProviderToComponent)(componentClass, provider); } if (moduleClass) { (0, ng_morph_1.addProviderToNgModule)(moduleClass, provider); } } } } //# sourceMappingURL=migrate-editor.js.map