Extract and generate Otter related data to integrate with a CMS
Extracts the component classes and types metadata from an Otter library/application, outputting them in a json file component.class.metadata.json
.
It will also generate the list of all the config interfaces defined in a library or application. The output is a json file component.config.metadata.json
containing an array of all the components configurations (app configs, pages, components).
yarn ng add @o3r/components
or
Example :npx ng add @o3r/components
First thing to do is to define your given filenames for the classes/configuration in the package.json of the library/app where you run the extractor. When running in a library it will use this configuration as the names for the metadata files. When running the extractor in an application, it will search for these filenames in each node_module (package.json file) of each library, in order to concat the metadata from the file with other libraries metadata and app metadata.
Example :// in package.json file
...
"cmsMetadata": {
...
"componentFilePath": "./component.class.metadata.json",
"configurationFilePath": "./component.config.metadata.json",
}
...
The Component Extractor is accessible via a NgCLI builder: @o3r/components:extractor
;
For an up-to-date documentation, run ng help @o3r/components:extractor
// in angular.json
"extract-components": {
"builder": "@o3r/components:extractor",
"options": {
"tsConfig": "./tsconfig.cms.json",
"libraries": [
"@your/o3r-components"
]
}
},
Note: This options will not search for the duplicate configurations in libraries.
Generates a metadata file that contains all the localized strings that are used in the application.
yarn ng add @o3r/localization
or
Example :npx ng add @o3r/localization
First thing to do is to define your given filename for the localisation in the package.json of the library/app where you run the extractor. When running in a library it will use this configuration as the default name for the metadata file. When running the extractor in an application, it will search for this filename defined in each node_module (package.json file) of each library, in order to concat the metadata from the file with other libraries metadata and app metadata.
Example :// in package.json file
...
"cmsMetadata": {
...
"localizationFilePath": "./localisation.metadata.json",
}
...
The Localization Extractor is accessible via a NgCLI builder: @o3r/localization:extractor
;
For an up-to-date documentation, run ng help @o3r/localization:extractor
// in angular.json
"extract-translations": {
"builder": "@o3r/localization:extractor",
"options": {
"tsConfig": "./tsconfig.cms.json",
"libraries": [
"@your/o3r-components"
]
}
},
Generates a metadata file that contains all the CSS Variable that are used in the application.
yarn ng add @o3r/styling
or
Example :npx ng add @o3r/styling
First thing to do is to define your given filename for the style in the package.json of the library/app where you run the extractor. When running in a library it will use this configuration as the default name for the metadata file. When running the extractor in an application, it will search for this filename defined in each node_module (package.json file) of each library, in order to concat the metadata from the file with other libraries metadata and app metadata.
Example :// in package.json file
...
"cmsMetadata": {
...
"styleFilePath": "./style.metadata.json",
}
...
The Style Extractor is accessible via a NgCLI builder: @o3r/styling:extractor
;
For an up-to-date documentation, run ng help @o3r/styling:extractor
Note: The duplicate CSS Variable will be specified as warning and overridden by the latest key received.
As for the other metadata retrieved, a bit of configuration is needed in order to extract metadata for facts and operators in rules engine scope.
yarn ng add @o3r/rules-engine
or
Example :npx ng add @o3r/rules-engine
In angular.json of the app a new build architect needs to be added. Here is an example:
Example :// angular.json
...
"extract-rules-engine": {
"builder": "@o3r/rules-engine:extractor", // otter CMS adapters builder
"options": {
"tsConfig": "./tsconfig.cms.json", // ts config file used by the builder
"libraries": [ // libraries containing facts included in the app
"@your/rules-engine-fact"
],
"factFilePatterns": [ // custom facts files
"src/facts/**/*.facts.ts"
]
}
},
Now that the new builder step is added, it has to be referenced in package.json
file, alongside other metadata extraction scripts.
// package.json
...
"scripts": {
...
"cms-adapters:rules-engine": "ng run your-o3r-app:extract-rules-engine",
"cms-adapters:metadata": "yarn cms-adapters:components && yarn cms-adapters:localizations && yarn cms-adapters:style && yarn cms-adapters:rules-engine",
}
In your json object you can add a property $schema
to validate the content of the json object.
Example:
Example :{
"$schema": "https://raw.githubusercontent.com/AmadeusITGroup/otter/main/packages/@o3r/application/schemas/functional-content.metadata.schema.json",
...
}
Version after version, it can be verified whether any breaking changes have been introduced, or if there is any metadata provided to document it.
To achieve this, simply configure the following builder in your angular.json
file as shown below.
{
// ...,
"projects": {
// ...,
"<project-name>": {
// ...,
"architect": {
"check-config-migration-metadata": {
"builder": "@o3r/components:check-config-migration-metadata",
"options": {
"migrationDataPath": "./migration-scripts/MIGRATION-*.json", // Required
"granularity": "major", // Default value is minor
"allowBreakingChanges": true, // Default value is false
"packageManager": "npm", // If not provided, it will be determined based on the repository architecture
"metadataPath": "./component.config.metadata.json" // Default value
}
},
"check-style-migration-metadata": {
"builder": "@o3r/styling:check-style-migration-metadata",
"options": {
"migrationDataPath": "./migration-scripts/MIGRATION-*.json" // Required
}
},
"check-localization-migration-metadata": {
"builder": "@o3r/localization:check-localization-migration-metadata",
"options": {
"migrationDataPath": "./migration-scripts/MIGRATION-*.json" // Required
}
}
}
}
}
}
Example of migration file:
Example :{
"$schema": "https://raw.githubusercontent.com/AmadeusITGroup/otter/main/packages/@o3r/extractors/schemas/migration.metadata.schema.json",
"version": "10.0.0",
"changes": [
{ // Move property to a new library and to a new config and rename property name
'contentType': 'CONFIG',
'before': {
'libraryName': '@old/lib',
'configName': 'OldConfig',
'propertyName': 'oldName'
},
'after': {
'libraryName': '@new/lib',
'configName': 'NewConfig',
'propertyName': 'newName'
}
},
{ // Rename configuration name for all properties
'contentType': 'CONFIG',
'before': {
'libraryName': '@o3r/lib',
'configName': 'OldConfig'
},
'after': {
'libraryName': '@o3r/lib',
'configName': 'NewConfig'
}
},
{ // Rename library name for all configurations
'contentType': 'CONFIG',
'before': {
'libraryName': '@o3r/lib2'
},
'after': {
'libraryName': '@o3r/lib3'
}
},
{ // Rename localization key
'contentType': 'LOCALIZATION',
'before': {
'key': 'old-localization.key'
},
'after': {
'key': 'new-localization.key'
}
},
{ // Rename CSS variable
'contentType': 'STYLE',
'before': {
'name': 'old-css-var-name'
},
'after': {
'name': 'new-css-var-name'
}
}
]
}
These migrations files are also useful in the CMS to automate the migration of the database associated to the metadata.
Make sure to expose them in the bundled application by adding them in the files
field of your package.json
and copy the files in the build process if needed
{
"files": [
"./migration-scripts/"
]
}
Also make sure to place them in a folder name migration-scripts
in your packaged app or to set the migrationScriptFolder
in your cms.json
.
If the libraries that you use provide migration scripts, you need to aggregate them with your own to make the metadata-checks pass.
You will need to specify in your migration script those libraries with their current version.
Example :{
"$schema": "https://raw.githubusercontent.com/AmadeusITGroup/otter/main/packages/@o3r/extractors/schemas/migration.metadata.schema.json",
"version": "10.0.0",
// List of libraries with migration scripts that your project depend on
"libraries": {
"@mylib/lib": "1.0.0"
},
"changes": [
// The changes specific to your project
]
}
Then you can automate the aggregation of migration scripts by adding the @o3r/extractors:aggregate-migration-scripts
builder in your angular.json
file as follows:
{
// ...,
"projects": {
// ...,
"<project-name>": {
// ...,
"architect": {
"aggregate-migration-scripts": {
"builder": "@o3r/extractors:aggregate-migration-scripts",
"options": {
"migrationDataPath": "./migration-scripts/src/MIGRATION-*.json",
"outputDirectory": "./migration-scripts/dist"
}
},
"check-localization-migration-metadata": {
"builder": "@o3r/localization:check-localization-migration-metadata",
"options": {
"migrationDataPath": "./migration-scripts/dist/MIGRATION-*.json"
}
}
}
}
}
}
Calling the aggregate-migration-scripts
builder will generate the full migration-scripts including the ones from the libraries.
In the previous example, you should include the output of the aggregate in the packaged application instead of the original migration scripts (./migration-scripts/dist
instead of ./mìgration-scripts/src
).
[!WARNING] The migration scripts of the libraries need be placed in the
./migration-scripts/
folder at the root the library package.