-
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.
feat(cdk): add schematics for migrate
@taiga-ui/addon-editor
to `@t…
…inkoff/tui-editor` (#4870) Co-authored-by: tinkoff-bot <[email protected]>
- Loading branch information
1 parent
e1ffffa
commit 5f40437
Showing
8 changed files
with
208 additions
and
11 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
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
9 changes: 6 additions & 3 deletions
9
...ics/ng-update/steps/icons/replace-text.ts → ...chematics/ng-update/utils/replace-text.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
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
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
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,51 @@ | ||
import {Rule, SchematicContext, Tree} from '@angular-devkit/schematics'; | ||
import { | ||
addPackageJsonDependency, | ||
getPackageJsonDependency, | ||
removePackageJsonDependency, | ||
saveActiveProject, | ||
} from 'ng-morph'; | ||
|
||
import {ALL_TS_FILES} from '../../constants'; | ||
import {TuiSchema} from '../../ng-add/schema'; | ||
import { | ||
FINISH_SYMBOL, | ||
infoLog, | ||
REPLACE_SYMBOL, | ||
SMALL_TAB_SYMBOL, | ||
titleLog, | ||
} from '../../utils/colored-log'; | ||
import {getFileSystem} from '../utils/get-file-system'; | ||
import {replaceText} from '../utils/replace-text'; | ||
|
||
const OLD_PACKAGE = `@taiga-ui/addon-editor`; | ||
const NEW_PACKAGE = `@tinkoff/tui-editor`; | ||
const NEW_PACKAGE_VERSION = `^1.0.1`; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export function updateToV3_36(options: TuiSchema): Rule { | ||
return (tree: Tree, _: SchematicContext) => { | ||
if (!getPackageJsonDependency(tree, OLD_PACKAGE)) { | ||
!options[`skip-logs`] && | ||
titleLog(`${FINISH_SYMBOL} No migrations required for ${OLD_PACKAGE}\n`); | ||
|
||
return; | ||
} | ||
|
||
const fileSystem = getFileSystem(tree); | ||
|
||
!options[`skip-logs`] && | ||
infoLog( | ||
`${SMALL_TAB_SYMBOL}${REPLACE_SYMBOL} replacing imports for ${OLD_PACKAGE}...`, | ||
); | ||
|
||
replaceText([{from: OLD_PACKAGE, to: NEW_PACKAGE}], ALL_TS_FILES); | ||
removePackageJsonDependency(tree, OLD_PACKAGE); | ||
addPackageJsonDependency(tree, {name: NEW_PACKAGE, version: NEW_PACKAGE_VERSION}); | ||
|
||
fileSystem.commitEdits(); | ||
saveActiveProject(); | ||
|
||
!options[`skip-logs`] && titleLog(`${FINISH_SYMBOL} successfully migrated \n`); | ||
}; | ||
} |
143 changes: 143 additions & 0 deletions
143
projects/cdk/schematics/ng-update/v3-36/tests/schematic-migrate-editor.spec.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,143 @@ | ||
/* eslint-disable rxjs/no-topromise */ | ||
import {HostTree} from '@angular-devkit/schematics'; | ||
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; | ||
import {TuiSchema} from '@taiga-ui/cdk/schematics/ng-add/schema'; | ||
import { | ||
createProject, | ||
createSourceFile, | ||
resetActiveProject, | ||
saveActiveProject, | ||
setActiveProject, | ||
} from 'ng-morph'; | ||
import {join} from 'path'; | ||
|
||
import {createAngularJson} from '../../../utils/create-angular-json'; | ||
|
||
const collectionPath = join(__dirname, `../../../migration.json`); | ||
|
||
const COMPONENT_BEFORE = `import { TUI_EDITOR_EXTENSIONS, TUI_ATTACH_FILES_LOADER } from '@taiga-ui/addon-editor'; | ||
@Component({ | ||
selector: 'test', | ||
templateUrl: './test.template.html', | ||
styleUrls: ['./index.less'], | ||
providers: [ | ||
{ | ||
provide: TUI_EDITOR_EXTENSIONS, | ||
useValue: [ | ||
import('@taiga-ui/addon-editor/extensions/starter-kit').then( | ||
({StarterKit}) => StarterKit, | ||
), | ||
import('@tiptap/extension-text-style').then(({TextStyle}) => TextStyle), | ||
import('@taiga-ui/addon-editor/extensions/link').then( | ||
({TuiLink}) => TuiLink, | ||
), | ||
import('@taiga-ui/addon-editor/extensions/jump-anchor').then( | ||
({TuiJumpAnchor}) => TuiJumpAnchor, | ||
), | ||
import('@taiga-ui/addon-editor/extensions/file-link').then( | ||
({TuiFileLink}) => TuiFileLink, | ||
), | ||
], | ||
}, | ||
{ | ||
provide: TUI_ATTACH_FILES_LOADER, | ||
deps: [FileIoService], | ||
useFactory: fileLoader, | ||
}, | ||
], | ||
}) | ||
export class TestComponent { | ||
}`; | ||
|
||
const COMPONENT_AFTER = `import { TUI_EDITOR_EXTENSIONS, TUI_ATTACH_FILES_LOADER } from '@tinkoff/tui-editor'; | ||
@Component({ | ||
selector: 'test', | ||
templateUrl: './test.template.html', | ||
styleUrls: ['./index.less'], | ||
providers: [ | ||
{ | ||
provide: TUI_EDITOR_EXTENSIONS, | ||
useValue: [ | ||
import('@tinkoff/tui-editor/extensions/starter-kit').then( | ||
({StarterKit}) => StarterKit, | ||
), | ||
import('@tiptap/extension-text-style').then(({TextStyle}) => TextStyle), | ||
import('@tinkoff/tui-editor/extensions/link').then( | ||
({TuiLink}) => TuiLink, | ||
), | ||
import('@tinkoff/tui-editor/extensions/jump-anchor').then( | ||
({TuiJumpAnchor}) => TuiJumpAnchor, | ||
), | ||
import('@tinkoff/tui-editor/extensions/file-link').then( | ||
({TuiFileLink}) => TuiFileLink, | ||
), | ||
], | ||
}, | ||
{ | ||
provide: TUI_ATTACH_FILES_LOADER, | ||
deps: [FileIoService], | ||
useFactory: fileLoader, | ||
}, | ||
], | ||
}) | ||
export class TestComponent { | ||
}`; | ||
|
||
const PACKAGE_BEFORE = `{ | ||
"dependencies": { | ||
"@angular/core": "~13.0.0", | ||
"@taiga-ui/addon-editor": "3.35.0" | ||
} | ||
}`; | ||
|
||
const PACKAGE_AFTER = `{ | ||
"dependencies": { | ||
"@angular/core": "~13.0.0", | ||
"@tinkoff/tui-editor": "^1.0.1" | ||
} | ||
}`; | ||
|
||
describe(`ng-update`, () => { | ||
let host: UnitTestTree; | ||
let runner: SchematicTestRunner; | ||
|
||
beforeEach(() => { | ||
host = new UnitTestTree(new HostTree()); | ||
runner = new SchematicTestRunner(`schematics`, collectionPath); | ||
|
||
setActiveProject(createProject(host)); | ||
|
||
createMainFiles(); | ||
|
||
saveActiveProject(); | ||
}); | ||
|
||
it(`should migrate addon-editor`, async () => { | ||
const tree = await runner | ||
.runSchematicAsync( | ||
`updateToV3_36`, | ||
{'skip-logs': process.env[`TUI_CI`] === `true`} as Partial<TuiSchema>, | ||
host, | ||
) | ||
.toPromise(); | ||
|
||
expect(tree.readContent(`test/app/test.component.ts`)).toEqual(COMPONENT_AFTER); | ||
expect(tree.readContent(`package.json`)).toEqual(PACKAGE_AFTER); | ||
}); | ||
|
||
afterEach(() => { | ||
resetActiveProject(); | ||
}); | ||
}); | ||
|
||
function createMainFiles(): void { | ||
createSourceFile(`test/app/test.component.ts`, COMPONENT_BEFORE); | ||
|
||
createSourceFile(`test/app/test.template.html`, `<tui-editor></tui-editor>`); | ||
|
||
createAngularJson(); | ||
|
||
createSourceFile(`package.json`, PACKAGE_BEFORE); | ||
} |
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