-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schematics): add migration for
@tbank/tui-editor
- Loading branch information
Showing
7 changed files
with
1,726 additions
and
1,804 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,53 @@ | ||
import {Rule, SchematicContext, Tree} from '@angular-devkit/schematics'; | ||
import {NodePackageInstallTask} from '@angular-devkit/schematics/tasks'; | ||
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 = '@tinkoff/tui-editor'; | ||
const NEW_PACKAGE = '@tbank/tui-editor'; | ||
const NEW_PACKAGE_VERSION = '^1.33.0'; | ||
|
||
export function updateToV3_83(options: TuiSchema): Rule { | ||
return (tree: Tree, context: SchematicContext): void => { | ||
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}); | ||
context.addTask(new NodePackageInstallTask()); | ||
|
||
fileSystem.commitEdits(); | ||
saveActiveProject(); | ||
|
||
!options['skip-logs'] && titleLog(`${FINISH_SYMBOL} successfully migrated \n`); | ||
}; | ||
} |
142 changes: 142 additions & 0 deletions
142
projects/cdk/schematics/ng-update/v3-83/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,142 @@ | ||
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 '@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 COMPONENT_AFTER = `import { TUI_EDITOR_EXTENSIONS, TUI_ATTACH_FILES_LOADER } from '@tbank/tui-editor'; | ||
@Component({ | ||
selector: 'test', | ||
templateUrl: './test.template.html', | ||
styleUrls: ['./index.less'], | ||
providers: [ | ||
{ | ||
provide: TUI_EDITOR_EXTENSIONS, | ||
useValue: [ | ||
import('@tbank/tui-editor/extensions/starter-kit').then( | ||
({StarterKit}) => StarterKit, | ||
), | ||
import('@tiptap/extension-text-style').then(({TextStyle}) => TextStyle), | ||
import('@tbank/tui-editor/extensions/link').then( | ||
({TuiLink}) => TuiLink, | ||
), | ||
import('@tbank/tui-editor/extensions/jump-anchor').then( | ||
({TuiJumpAnchor}) => TuiJumpAnchor, | ||
), | ||
import('@tbank/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", | ||
"@tinkoff/tui-editor": "3.35.0" | ||
} | ||
}`; | ||
|
||
const PACKAGE_AFTER = `{ | ||
"dependencies": { | ||
"@angular/core": "~13.0.0", | ||
"@tbank/tui-editor": "^1.33.0" | ||
} | ||
}`; | ||
|
||
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_83', | ||
{'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