-
Notifications
You must be signed in to change notification settings - Fork 471
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 experimental migration (#7399)
- Loading branch information
Showing
6 changed files
with
186 additions
and
1 deletion.
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
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
38 changes: 38 additions & 0 deletions
38
projects/cdk/schematics/ng-update/v3-78/constants/icons.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,38 @@ | ||
export const ICONS: Array<{from: string; to: string}> = [ | ||
{ | ||
from: 'tuiIconTdsTinkoffShieldLogoInverseEnLogoSiteheader', | ||
to: 'tuiIconTdsTBankEngInverseLogoSiteheader', | ||
}, | ||
{ | ||
from: 'tuiIconTdsTinkoffBusinessShieldLogoLogoSiteheader', | ||
to: 'tuiIconTdsTBankBusinessLogoSiteheader', | ||
}, | ||
{ | ||
from: 'tuiIconTdsTinkoffBusinessShieldLogoInverseLogoSiteheader', | ||
to: 'tuiIconTdsTBankBusinessInverseLogoSiteheader', | ||
}, | ||
{ | ||
from: 'tuiIconTdsTinkoffEngLogo', | ||
to: 'tuiIconTdsTBankTextEngLogo', | ||
}, | ||
{ | ||
from: 'tuiIconTdsTinkoffRuLogo', | ||
to: 'tuiIconTdsTBankTextLogo', | ||
}, | ||
{ | ||
from: 'tuiIconTdsTinkoffShieldLogoInverseEnLogoSiteheader', | ||
to: 'tuiIconTdsTBankEngInverseLogoSiteheader', | ||
}, | ||
{ | ||
from: 'tuiIconTdsTinkoffShieldLogoEnLogoSiteheader', | ||
to: 'tuiIconTdsTBankEngLogoSiteheader', | ||
}, | ||
{ | ||
from: 'tuiIconTdsTinkoffShieldLogoLogoSiteheader', | ||
to: 'tuiIconTdsTBankLogoSiteheader', | ||
}, | ||
{ | ||
from: 'tuiIconTdsTinkoffShieldLogoInverseLogoSiteheader', | ||
to: 'tuiIconTdsTBankInverseLogoSiteheader', | ||
}, | ||
].sort((prev, next) => next.from.length - prev.from.length); |
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,45 @@ | ||
import {Rule, SchematicContext, Tree} from '@angular-devkit/schematics'; | ||
import {getPackageJsonDependency, saveActiveProject} from 'ng-morph'; | ||
|
||
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'; | ||
import {ICONS} from './constants/icons'; | ||
|
||
function hasProprietaryIcons(tree: Tree): boolean { | ||
return !!getPackageJsonDependency(tree, '@taiga-ui/proprietary-icons'); | ||
} | ||
|
||
export function updateToV3_78(options: TuiSchema): Rule { | ||
return (tree: Tree, _: SchematicContext) => { | ||
if (!hasProprietaryIcons(tree)) { | ||
!options['skip-logs'] && | ||
titleLog(`${FINISH_SYMBOL} No migrations required\n`); | ||
|
||
return; | ||
} | ||
|
||
const fileSystem = getFileSystem(tree); | ||
|
||
if (options.experimental) { | ||
!options['skip-logs'] && | ||
infoLog( | ||
`${SMALL_TAB_SYMBOL}${REPLACE_SYMBOL} replacing deprecated logos...`, | ||
); | ||
replaceText(ICONS); | ||
} | ||
|
||
fileSystem.commitEdits(); | ||
saveActiveProject(); | ||
|
||
!options['skip-logs'] && | ||
titleLog(`${FINISH_SYMBOL} Icons successfully migrated \n`); | ||
}; | ||
} |
88 changes: 88 additions & 0 deletions
88
projects/cdk/schematics/ng-update/v3-78/tests/schematic-migrate-logos-icons.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,88 @@ | ||
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 = ` | ||
@Component({templateUrl: './test.template.html'}) | ||
export class TestComponent { | ||
icon1 = tuiIconTdsTinkoffShieldLogoInverseEnLogoSiteheader; | ||
icon2 = tuiIconTdsTinkoffBusinessShieldLogoLogoSiteheader; | ||
icon3 = tuiIconTdsTinkoffBusinessShieldLogoInverseLogoSiteheader; | ||
icon4 = tuiIconTdsTinkoffEngLogo; | ||
icon5 = tuiIconTdsTinkoffRuLogo; | ||
icon6 = tuiIconTdsTinkoffShieldLogoInverseEnLogoSiteheader; | ||
icon7 = tuiIconTdsTinkoffShieldLogoEnLogoSiteheader; | ||
icon8 = tuiIconTdsTinkoffShieldLogoLogoSiteheader; | ||
icon9 = tuiIconTdsTinkoffShieldLogoInverseLogoSiteheader; | ||
}`; | ||
|
||
const COMPONENT_AFTER = ` | ||
@Component({templateUrl: './test.template.html'}) | ||
export class TestComponent { | ||
icon1 = tuiIconTdsTBankEngInverseLogoSiteheader; | ||
icon2 = tuiIconTdsTBankBusinessLogoSiteheader; | ||
icon3 = tuiIconTdsTBankBusinessInverseLogoSiteheader; | ||
icon4 = tuiIconTdsTBankTextEngLogo; | ||
icon5 = tuiIconTdsTBankTextLogo; | ||
icon6 = tuiIconTdsTBankEngInverseLogoSiteheader; | ||
icon7 = tuiIconTdsTBankEngLogoSiteheader; | ||
icon8 = tuiIconTdsTBankLogoSiteheader; | ||
icon9 = tuiIconTdsTBankInverseLogoSiteheader; | ||
}`; | ||
|
||
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 old deprecated logos', async () => { | ||
const tree = await runner | ||
.runSchematicAsync( | ||
'updateToV3_78', | ||
{ | ||
experimental: true, | ||
'skip-logs': process.env['TUI_CI'] === 'true', | ||
} as Partial<TuiSchema>, | ||
host, | ||
) | ||
.toPromise(); | ||
|
||
expect(tree.readContent('test/app/test.component.ts')).toEqual(COMPONENT_AFTER); | ||
}); | ||
|
||
afterEach(() => { | ||
resetActiveProject(); | ||
}); | ||
}); | ||
|
||
function createMainFiles(): void { | ||
createSourceFile('test/app/test.component.ts', COMPONENT_BEFORE); | ||
|
||
createAngularJson(); | ||
createSourceFile( | ||
'package.json', | ||
'{"dependencies": {"@angular/core": "~13.0.0", "@taiga-ui/proprietary-icons": "~3.78.0"}}', | ||
); | ||
} |