-
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.
chore(schematics): replace template line endings with platform specific
- Loading branch information
Showing
4 changed files
with
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ on: | |
pull_request: | ||
|
||
jobs: | ||
schematics: | ||
migration: | ||
runs-on: ubuntu-latest | ||
name: Run the latest migration | ||
steps: | ||
|
@@ -13,6 +13,19 @@ jobs: | |
id: info | ||
- run: npx nx run cdk:schematics --v=${{ steps.info.outputs.root-package-major-version }} | ||
|
||
unit-test: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
name: Run the unit test on ${{ matrix.os }} | ||
steps: | ||
- uses: actions/[email protected] | ||
- uses: taiga-family/ci/actions/setup/[email protected] | ||
- uses: taiga-family/ci/actions/run/[email protected] | ||
- run: npx jest projects/cdk/schematics/**/*.spec.ts --coverage=false | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true |
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
21 changes: 21 additions & 0 deletions
21
projects/cdk/schematics/ng-update/v4/steps/replace-template-line-endings.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,21 @@ | ||
/// <reference lib="es2021" /> | ||
import {EOL} from 'node:os'; | ||
|
||
import type {FileSystem} from 'ng-morph'; | ||
import {getActiveProject, getSourceFiles, saveActiveProject} from 'ng-morph'; | ||
|
||
import {ALL_FILES} from '../../../constants'; | ||
|
||
export function replaceTemplateLineEndings( | ||
fileSystem: FileSystem, | ||
pattern = ALL_FILES, | ||
): void { | ||
getActiveProject(); | ||
|
||
getSourceFiles(pattern).forEach((file) => { | ||
file.replaceWithText(file.getFullText().replaceAll(/\r?\n/g, EOL)); | ||
}); | ||
|
||
fileSystem.commitEdits(); | ||
saveActiveProject(); | ||
} |
95 changes: 95 additions & 0 deletions
95
projects/cdk/schematics/ng-update/v4/tests/replace-crlf.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,95 @@ | ||
import {type} from 'node:os'; | ||
import {join} from 'node:path'; | ||
|
||
import {HostTree} from '@angular-devkit/schematics'; | ||
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; | ||
import type {TuiSchema} from '@taiga-ui/cdk/schematics/ng-add/schema'; | ||
import { | ||
createProject, | ||
createSourceFile, | ||
resetActiveProject, | ||
saveActiveProject, | ||
setActiveProject, | ||
} from 'ng-morph'; | ||
|
||
import {createAngularJson} from '../../../utils/create-angular-json'; | ||
|
||
const collectionPath = join(__dirname, '../../../migration.json'); | ||
|
||
const COMPONENT_BEFORE = `\r\n | ||
@Component({ | ||
standalone: true, | ||
templateUrl: './test.template.html', | ||
}) | ||
export class Test {}\r\n`; | ||
|
||
const COMPONENT_AFTER = type().startsWith('Windows') | ||
? `\r\n | ||
@Component({ | ||
standalone: true, | ||
templateUrl: './test.template.html', | ||
}) | ||
export class Test {}\r\n` | ||
: `\n | ||
@Component({ | ||
standalone: true, | ||
templateUrl: './test.template.html', | ||
}) | ||
export class Test {}\n`; | ||
|
||
const TEMPLATE_BEFORE = '\r\n<p>Hello</p>\r\n'; | ||
|
||
const TEMPLATE_AFTER = type().startsWith('Windows') | ||
? '\r\n<p>Hello</p>\r\n' | ||
: '\n<p>Hello</p>\n'; | ||
|
||
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 badge in template', async () => { | ||
const tree = await runner.runSchematic( | ||
'updateToV4', | ||
{'skip-logs': process.env['TUI_CI'] === 'true'} as Partial<TuiSchema>, | ||
host, | ||
); | ||
|
||
expect(tree.readContent('test/app/test.template.html')).toEqual(TEMPLATE_AFTER); | ||
}); | ||
|
||
it('should migrate badge references in ts files', async () => { | ||
const tree = await runner.runSchematic( | ||
'updateToV4', | ||
{'skip-logs': process.env['TUI_CI'] === 'true'} as Partial<TuiSchema>, | ||
host, | ||
); | ||
|
||
expect(tree.readContent('test/app/test.component.ts')).toEqual(COMPONENT_AFTER); | ||
}); | ||
|
||
afterEach(() => { | ||
resetActiveProject(); | ||
}); | ||
}); | ||
|
||
function createMainFiles(): void { | ||
createSourceFile('test/app/test.component.ts', COMPONENT_BEFORE); | ||
createSourceFile('test/app/test.template.html', TEMPLATE_BEFORE); | ||
|
||
createAngularJson(); | ||
createSourceFile( | ||
'package.json', | ||
'{\r\n"dependencies": {\r\n"@angular/core": "~13.0.0",\r\n "@taiga-ui/addon-commerce": "~3.42.0"\r\n}\r\n}', | ||
); | ||
} |