From 604843161f62afbc272443470d52c77dc927cf8a Mon Sep 17 00:00:00 2001 From: Kilian Panot Date: Mon, 18 Nov 2024 16:58:28 +0900 Subject: [PATCH] feat(design): allow tag override in builder --- .../helpers/style-renderer-options.ts | 8 ++++++-- .../design/builders/generate-style/schema.json | 16 ++++++++++++++++ .../design/builders/generate-style/schema.ts | 6 ++++++ 3 files changed, 28 insertions(+), 2 deletions(-) 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}; }