Skip to content

Commit

Permalink
feat(design): allow tag override in builder
Browse files Browse the repository at this point in the history
  • Loading branch information
kpanot committed Nov 18, 2024
1 parent e73502b commit 6048431
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BuilderContext } from '@angular-devkit/architect';
import {
type CssStyleContentUpdaterOptions,
type CssTokenDefinitionRendererOptions,
type CssTokenValueRendererOptions,
type DesignTokenListTransform,
Expand All @@ -14,6 +15,7 @@ import {
getTokenSorterByName,
getTokenSorterByRef,
getTokenSorterFromRegExpList,
type SassStyleContentUpdaterOptions,
type SassTokenDefinitionRendererOptions,
type SassTokenValueRendererOptions,
type TokenKeyRenderer,
Expand Down Expand Up @@ -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}"`);
Expand Down
16 changes: 16 additions & 0 deletions packages/@o3r/design/builders/generate-style/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions packages/@o3r/design/builders/generate-style/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}

0 comments on commit 6048431

Please sign in to comment.