-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pipes): prefix pipes with o3r (#1280)
## Proposed change Prefix pipes with o3r to avoid conflicts with others libraries IMO, it's not possible to provide ng-update because we cannot know easily from where the pipe is imported. ## Related issues - 🚀 Feature #1214 <!-- Please make sure to follow the contributing guidelines on https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md -->
- Loading branch information
Showing
58 changed files
with
831 additions
and
181 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
2 changes: 1 addition & 1 deletion
2
apps/showcase/src/components/showcase/dynamic-content/dynamic-content-pres.template.html
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
18 changes: 9 additions & 9 deletions
18
apps/showcase/src/components/showcase/rules-engine/rules-engine-pres.template.html
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
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,10 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/angular/angular-cli/master/packages/angular_devkit/schematics/collection-schema.json", | ||
"schematics": { | ||
"migration-v10_0": { | ||
"version": "10.0.0-alpha.0", | ||
"description": "Updates of the Otter Library to v10.0.*", | ||
"factory": "./schematics/ng-update/v10-0/index#updateV10_0" | ||
} | ||
} | ||
} |
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
77 changes: 77 additions & 0 deletions
77
packages/@o3r/components/schematics/ng-update/v10-0/index.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,77 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | ||
import * as fs from 'node:fs'; | ||
import * as path from 'node:path'; | ||
|
||
const migrationPath = path.join(__dirname, '..', '..', '..', 'migration.json'); | ||
|
||
|
||
describe('Update v10', () => { | ||
describe('Update pipes', () => { | ||
let initialTree: Tree; | ||
let runner: SchematicTestRunner; | ||
beforeEach(() => { | ||
initialTree = Tree.empty(); | ||
initialTree.create('angular.json', fs.readFileSync(path.resolve(__dirname, '..', '..', '..', 'testing', 'mocks', 'angular.mocks.json'))); | ||
initialTree.create('package.json', fs.readFileSync(path.resolve(__dirname, '..', '..', '..', 'testing', 'mocks', 'package.mocks.json'))); | ||
initialTree.create('.eslintrc.json', fs.readFileSync(path.resolve(__dirname, '..', '..', '..', 'testing', 'mocks', '__dot__eslintrc.mocks.json'))); | ||
initialTree.create('src/components/example.template.html', '{{ 120 | duration }}'); | ||
runner = new SchematicTestRunner('schematics', migrationPath); | ||
}); | ||
|
||
it('should replace the pipe with standalone component', async () => { | ||
initialTree.create('src/components/example.component.ts', ` | ||
import { Component } from '@angular/core'; | ||
import { O3rComponent } from '@o3r/core'; | ||
import { DurationPipeModule } from '@o3r/components'; | ||
@O3rComponent({ componentType: 'Component' }) | ||
@Component({ | ||
selector: 'o3r-example', | ||
standalone: true, | ||
imports: [DurationPipeModule], | ||
templateUrl: './example.template.html' | ||
}) | ||
export class ExampleComponent { | ||
} | ||
`); | ||
const tree = await runner.runSchematic('migration-v10_0', {}, initialTree); | ||
expect(tree.readText('src/components/example.component.ts')).toMatch('O3rDurationPipe'); | ||
expect(tree.readText('src/components/example.component.ts')).not.toMatch('DurationPipeModule'); | ||
expect(tree.readText('src/components/example.template.html')).toMatch('| o3rDuration'); | ||
expect(tree.readText('src/components/example.template.html')).not.toMatch('| duration'); | ||
}); | ||
|
||
it('should replace the pipe with module based component', async () => { | ||
initialTree.create('src/components/example.component.ts', ` | ||
import { Component } from '@angular/core'; | ||
import { O3rComponent } from '@o3r/core'; | ||
@O3rComponent({ componentType: 'Component' }) | ||
@Component({ | ||
selector: 'o3r-example', | ||
templateUrl: './example.template.html' | ||
}) | ||
export class ExampleComponent { | ||
} | ||
`); | ||
initialTree.create('src/components/example.module.ts', ` | ||
import { NgModule } from '@angular/core'; | ||
import { DurationPipeModule } from '@o3r/components'; | ||
import { ExampleComponent } from './example.component'; | ||
@NgModule({ | ||
imports: [DurationPipeModule], | ||
declarations: [ExampleComponent], | ||
exports: [ExampleComponent] | ||
}) | ||
export class ExampleModule {} | ||
`); | ||
const tree = await runner.runSchematic('migration-v10_0', {}, initialTree); | ||
expect(tree.readText('src/components/example.module.ts')).toMatch('O3rDurationPipe'); | ||
expect(tree.readText('src/components/example.module.ts')).not.toMatch('DurationPipeModule'); | ||
expect(tree.readText('src/components/example.template.html')).toMatch('| o3rDuration'); | ||
expect(tree.readText('src/components/example.template.html')).not.toMatch('| duration'); | ||
}); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
packages/@o3r/components/schematics/ng-update/v10-0/index.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,53 @@ | ||
/* eslint-disable camelcase, @typescript-eslint/naming-convention */ | ||
import { chain, Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; | ||
import { createSchematicWithMetricsIfInstalled, PipeReplacementInfo, updatePipes } from '@o3r/schematics'; | ||
|
||
const pipeReplacementInfo: PipeReplacementInfo = { | ||
capitalize: { | ||
new: { | ||
name: 'o3rCapitalize', | ||
import: 'O3rCapitalizePipe' | ||
}, | ||
import: 'CapitalizePipeModule' | ||
}, | ||
duration: { | ||
new: { | ||
name: 'o3rDuration', | ||
import: 'O3rDurationPipe' | ||
}, | ||
import: 'DurationPipeModule' | ||
}, | ||
keepWhiteSpace: { | ||
new: { | ||
name: 'o3rKeepWhiteSpace', | ||
import: 'O3rKeepWhiteSpacePipe' | ||
}, | ||
import: 'KeepWhiteSpacePipeModule' | ||
}, | ||
replaceWithBold: { | ||
new: { | ||
name: 'o3rReplaceWithBold', | ||
import: 'O3rReplaceWithBoldPipe' | ||
}, | ||
import: 'ReplaceWithBoldPipeModule' | ||
} | ||
}; | ||
|
||
/** | ||
* Update of Otter library V10.0 | ||
*/ | ||
function updateV10_0Fn(): Rule { | ||
return (tree: Tree, context: SchematicContext) => { | ||
|
||
const updateRules: Rule[] = [ | ||
updatePipes(pipeReplacementInfo) | ||
]; | ||
|
||
return chain(updateRules)(tree, context); | ||
}; | ||
} | ||
|
||
/** | ||
* Update of Otter library V10.0 | ||
*/ | ||
export const updateV10_0 = createSchematicWithMetricsIfInstalled(updateV10_0Fn); |
Oops, something went wrong.