diff --git a/packages/@o3r/design/builders/generate-style/helpers/style-renderer-options.ts b/packages/@o3r/design/builders/generate-style/helpers/style-renderer-options.ts index ea87a10412..7ec250bd42 100644 --- a/packages/@o3r/design/builders/generate-style/helpers/style-renderer-options.ts +++ b/packages/@o3r/design/builders/generate-style/helpers/style-renderer-options.ts @@ -1,5 +1,6 @@ import type { BuilderContext } from '@angular-devkit/architect'; import { + type CssStyleContentUpdaterOptions, type CssTokenDefinitionRendererOptions, type CssTokenValueRendererOptions, type DesignTokenListTransform, @@ -14,6 +15,7 @@ import { getTokenSorterByName, getTokenSorterByRef, getTokenSorterFromRegExpList, + type SassStyleContentUpdaterOptions, type SassTokenDefinitionRendererOptions, type SassTokenValueRendererOptions, type TokenKeyRenderer, @@ -51,13 +53,15 @@ export const getStyleRendererOptions = (tokenVariableNameRenderer: TokenKeyRende /** Update of file content based on selected language */ const styleContentUpdater = ((language) => { + const updaterOptions = options.codeEditTags && + { startTag: options.codeEditTags.start, endTag: options.codeEditTags.end } as const satisfies CssStyleContentUpdaterOptions & SassStyleContentUpdaterOptions; switch (language) { case 'css': { - return getCssStyleContentUpdater(); + return getCssStyleContentUpdater(updaterOptions); } case 'scss': case 'sass': { - return getSassStyleContentUpdater(); + return getSassStyleContentUpdater(updaterOptions); } default: { throw new Error(`No available updater for "${language as string}"`); diff --git a/packages/@o3r/design/builders/generate-style/schema.json b/packages/@o3r/design/builders/generate-style/schema.json index 69c6dad114..867b04fd0f 100644 --- a/packages/@o3r/design/builders/generate-style/schema.json +++ b/packages/@o3r/design/builders/generate-style/schema.json @@ -106,6 +106,22 @@ "sortOrderPatternsFilePath": { "type": "string", "description": "Path to the JSON file exposing an ordered array of RegExps applied to the token name which will define the priority of the generated variables. (Note: not matching tokens will default to ASC order)" + }, + "codeEditTags": { + "description": "Tags to surround the generated code in the outputted file. It is used to detect the code to replace. Note: the tag should be valid in the selected language.", + "type": "object", + "properties": { + "start": { + "description": "Starting tag", + "type": "string" + }, + "end": { + "description": "Ending tag", + "type": "string" + } + }, + "additionalItems": false, + "required": ["start", "end"] } }, "additionalProperties": true, diff --git a/packages/@o3r/design/builders/generate-style/schema.ts b/packages/@o3r/design/builders/generate-style/schema.ts index add3e5ef58..eb830e56f9 100644 --- a/packages/@o3r/design/builders/generate-style/schema.ts +++ b/packages/@o3r/design/builders/generate-style/schema.ts @@ -73,4 +73,10 @@ export interface GenerateStyleSchematicsSchema extends SchematicOptionObject { * Note: not matching tokens will default to ASC order. */ sortOrderPatternsFilePath?: string; + + /** + * Tags to surround the generated code in the outputted file. + * It is used to detect the code to replace + */ + codeEditTags?: {end: string; start: string}; }