@o3r/design 11.4.0-prerelease.4 → 11.4.0-prerelease.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -25
- package/builders/generate-css/schema.d.ts +2 -2
- package/builders/generate-css/schema.d.ts.map +1 -1
- package/builders/generate-css/schema.json +4 -4
- package/builders/generate-style/helpers/metadata-renderer-options.d.ts +5 -0
- package/builders/generate-style/helpers/metadata-renderer-options.d.ts.map +1 -0
- package/builders/generate-style/helpers/metadata-renderer-options.js +20 -0
- package/builders/generate-style/helpers/style-renderer-options.d.ts +5 -0
- package/builders/generate-style/helpers/style-renderer-options.d.ts.map +1 -0
- package/builders/generate-style/helpers/style-renderer-options.js +125 -0
- package/builders/generate-style/helpers/token-template.d.ts +9 -0
- package/builders/generate-style/helpers/token-template.d.ts.map +1 -0
- package/builders/generate-style/helpers/token-template.js +30 -0
- package/builders/generate-style/index.d.ts +8 -0
- package/builders/generate-style/index.d.ts.map +1 -0
- package/builders/generate-style/index.js +129 -0
- package/builders/generate-style/schema.d.ts +54 -0
- package/builders/generate-style/schema.d.ts.map +1 -0
- package/builders/generate-style/schema.js +3 -0
- package/builders/generate-style/schema.json +111 -0
- package/builders.json +6 -0
- package/cli/build-design-token.cli.cjs +12 -1
- package/cli/build-design-token.cli.cjs.map +1 -1
- package/cli/generate-css-from-design-token.cli.cjs +12 -1
- package/cli/generate-css-from-design-token.cli.cjs.map +1 -1
- package/migration.json +5 -0
- package/package.json +14 -14
- package/schematics/ng-add/register-generate-css/register-task.d.ts.map +1 -1
- package/schematics/ng-add/register-generate-css/register-task.js +1 -0
- package/schematics/ng-update/index.d.ts +6 -0
- package/schematics/ng-update/index.d.ts.map +1 -0
- package/schematics/ng-update/index.js +24 -0
- package/schematics/ng-update/v11.3/builder-migration.d.ts +3 -0
- package/schematics/ng-update/v11.3/builder-migration.d.ts.map +1 -0
- package/schematics/ng-update/v11.3/builder-migration.js +47 -0
- package/src/core/design-token/design-token-specification.interface.d.ts +4 -0
- package/src/core/design-token/design-token-specification.interface.d.ts.map +1 -1
- package/src/core/design-token/design-token-specification.interface.js.map +1 -1
- package/src/core/design-token/parsers/design-token-parser.interface.d.ts +14 -5
- package/src/core/design-token/parsers/design-token-parser.interface.d.ts.map +1 -1
- package/src/core/design-token/parsers/design-token.parser.d.ts.map +1 -1
- package/src/core/design-token/parsers/design-token.parser.js +15 -3
- package/src/core/design-token/parsers/design-token.parser.js.map +1 -1
- package/src/core/design-token/renderers/css/design-token-definition.renderers.js +2 -2
- package/src/core/design-token/renderers/css/design-token-definition.renderers.js.map +1 -1
- package/src/core/design-token/renderers/css/design-token-updater.renderers.d.ts +5 -0
- package/src/core/design-token/renderers/css/design-token-updater.renderers.d.ts.map +1 -1
- package/src/core/design-token/renderers/css/design-token-updater.renderers.js +2 -1
- package/src/core/design-token/renderers/css/design-token-updater.renderers.js.map +1 -1
- package/src/core/design-token/renderers/css/design-token-value.renderers.d.ts +3 -3
- package/src/core/design-token/renderers/css/design-token-value.renderers.d.ts.map +1 -1
- package/src/core/design-token/renderers/css/design-token-value.renderers.js +7 -4
- package/src/core/design-token/renderers/css/design-token-value.renderers.js.map +1 -1
- package/src/core/design-token/renderers/design-token-style.renderer.d.ts +15 -2
- package/src/core/design-token/renderers/design-token-style.renderer.d.ts.map +1 -1
- package/src/core/design-token/renderers/design-token-style.renderer.js +78 -10
- package/src/core/design-token/renderers/design-token-style.renderer.js.map +1 -1
- package/src/core/design-token/renderers/design-token.renderer.interface.d.ts +11 -2
- package/src/core/design-token/renderers/design-token.renderer.interface.d.ts.map +1 -1
- package/src/core/design-token/renderers/sass/design-token-definition.renderers.d.ts +6 -1
- package/src/core/design-token/renderers/sass/design-token-definition.renderers.d.ts.map +1 -1
- package/src/core/design-token/renderers/sass/design-token-definition.renderers.js +12 -3
- package/src/core/design-token/renderers/sass/design-token-definition.renderers.js.map +1 -1
- package/src/core/design-token/renderers/sass/design-token-updater.renderers.d.ts +11 -0
- package/src/core/design-token/renderers/sass/design-token-updater.renderers.d.ts.map +1 -0
- package/src/core/design-token/renderers/sass/design-token-updater.renderers.js +13 -0
- package/src/core/design-token/renderers/sass/design-token-updater.renderers.js.map +1 -0
- package/src/core/design-token/renderers/sass/design-token-value.renderers.d.ts +34 -0
- package/src/core/design-token/renderers/sass/design-token-value.renderers.d.ts.map +1 -0
- package/src/core/design-token/renderers/sass/design-token-value.renderers.js +47 -0
- package/src/core/design-token/renderers/sass/design-token-value.renderers.js.map +1 -0
- package/src/core/design-token/renderers/sass/index.d.ts +2 -0
- package/src/core/design-token/renderers/sass/index.d.ts.map +1 -1
- package/src/core/design-token/renderers/sass/index.js +2 -0
- package/src/core/design-token/renderers/sass/index.js.map +1 -1
package/README.md
CHANGED
|
@@ -33,25 +33,30 @@ Otter Design module provides a set of code generators based on [Angular schemati
|
|
|
33
33
|
|
|
34
34
|
Otter Design module provides a set of builders based on [Angular builders](https://angular.io/guide/cli-builder).
|
|
35
35
|
|
|
36
|
-
### generate-
|
|
36
|
+
### generate-style
|
|
37
37
|
|
|
38
|
-
The `generate-
|
|
38
|
+
The `generate-style` builder can generate CSS and CMS Metadata based on given Design Token Json files.
|
|
39
39
|
The following configurations are available:
|
|
40
40
|
|
|
41
|
-
| Options | Default Value
|
|
42
|
-
| --------------------------- |
|
|
43
|
-
| **
|
|
44
|
-
| **
|
|
45
|
-
| **
|
|
46
|
-
| **
|
|
47
|
-
| **
|
|
48
|
-
| **
|
|
49
|
-
| **
|
|
50
|
-
| **
|
|
51
|
-
| **
|
|
52
|
-
| **
|
|
53
|
-
| **
|
|
54
|
-
| **
|
|
41
|
+
| Options | Default Value | Description |
|
|
42
|
+
| --------------------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
43
|
+
| **language** | `'css'` *Required* | Default styling language to generate to the given Design Token. *(`css`, `scss` and `sass` are available)* |
|
|
44
|
+
| **designTokenFilePatterns** | `[]` *Required* | Path patterns to the Design Token JSON files. <br /> Files in dependencies are supported and resolved with Node Resolver. |
|
|
45
|
+
| **variableType** | *null* | Type of the variables to generate for a Design Token. |
|
|
46
|
+
| **output** | *null* | Output file where the CSS will be generated. <br /> The path specified in `o3rTargetFile` will be ignored if this option is specified |
|
|
47
|
+
| **defaultStyleFile** | `'src/theme.scss'` | File path to generate the variable if not determined by the specifications |
|
|
48
|
+
| **metadataOutput** | *null* | Path to generate the metadata for the CMS. <br /> The metadata will be generated only if the file path is specified. |
|
|
49
|
+
| **metadataIgnorePrivate** | false | Ignore private variables in the metadata generation. |
|
|
50
|
+
| **rootPath** | *null* | Root path of files where the CSS will be generated. |
|
|
51
|
+
| **failOnDuplicate** | false | Determine if the process should stop in case of Token duplication. |
|
|
52
|
+
| **templateFile** | *null* | Path to a template file (or a list of template files) to apply as default configuration to a Design Token extension. |
|
|
53
|
+
| **prefix** | *null* | Prefix to append to generated variables. |
|
|
54
|
+
| **prefixPrivate** | *null* | Prefix to append to generated private variables. |
|
|
55
|
+
| **renderPrivateVariableTo** | *null* | Generate the private variable in the given language (if not specified, in case of CSS, the variable will be ignored in the generated style). |
|
|
56
|
+
| **watch** | false | Enable watch mode. |
|
|
57
|
+
|
|
58
|
+
> [!NOTE]
|
|
59
|
+
> The document of the deprecated builder `generate-css` is available on [this page](https://github.com/AmadeusITGroup/otter/blob/main/docs/design/DEPRECATE_GENERATE_CSS.md).
|
|
55
60
|
|
|
56
61
|
### generate-jsonschema
|
|
57
62
|
|
|
@@ -92,15 +97,16 @@ It comes with the following options:
|
|
|
92
97
|
|
|
93
98
|
To enhance the features of default Design Token standard and provide additional information to renderers, the [$extensions](https://tr.designtokens.org/format/#extensions) properties has been enhanced by Otter Tooling with the following options:
|
|
94
99
|
|
|
95
|
-
| Extension property
|
|
96
|
-
|
|
|
97
|
-
| **o3rTargetFile**
|
|
98
|
-
| **o3rPrivate**
|
|
99
|
-
| **o3rImportant**
|
|
100
|
-
| **o3rScope**
|
|
101
|
-
| **o3rMetadata**
|
|
102
|
-
| **o3rUnit**
|
|
103
|
-
| **o3rRatio**
|
|
100
|
+
| Extension property | Supporting Renderers | Description |
|
|
101
|
+
| --------------------- | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
102
|
+
| **o3rTargetFile** | `css`, `sass` | Information regarding the path to the file where the token will be generated |
|
|
103
|
+
| **o3rPrivate** | `css`, `sass`, `json-schema`, `metadata`, `design-token` | Determine if the token is flagged as private |
|
|
104
|
+
| **o3rImportant** | `css` | Determine if the token should be flagged as important when generated |
|
|
105
|
+
| **o3rScope** | `css`, `sass` | Scope to apply to the generated variable |
|
|
106
|
+
| **o3rMetadata** | `css`, `sass`, `json-schema`, `metadata`, `design-token` | Additional information to provide to the metadata if generated |
|
|
107
|
+
| **o3rUnit** | `css`, `sass`, `metadata`, `design-token` | Convert a numeric value from the specified unit to the new unit. It will add a unit to the token with type "number" for which the unit is not specified.<br />In case of a complex type (such as shadow, transition, etc...), the unit will be applied to all numeric types in it. |
|
|
108
|
+
| **o3rRatio** | `css`, `sass`, `metadata`, `design-token` | Ratio to apply to previous value. The ratio will only be applied to a token of type "number" or to the first numbers determined in "string" types.<br />In case of a complex type (such as shadow, transition, etc...), the ratio will be applied to all numeric types in it. |
|
|
109
|
+
| **o3rExpectOverride** | `css`, `sass` | Indicate that the token is expected to be overridden by external rules. |
|
|
104
110
|
|
|
105
111
|
> [!NOTE]
|
|
106
112
|
> In case of implementation of custom renderer, additional properties dedicated to this renderer can be added following Design Token Extensions [guidelines](https://tr.designtokens.org/format/#extensions).
|
|
@@ -28,7 +28,7 @@ export interface GenerateCssSchematicsSchema extends SchematicOptionObject {
|
|
|
28
28
|
failOnDuplicate?: boolean;
|
|
29
29
|
/** Prefix to happen to generated variables */
|
|
30
30
|
prefix?: string;
|
|
31
|
-
/** Generate the
|
|
31
|
+
/** Generate the private variable to the given language */
|
|
32
32
|
renderPrivateVariableTo?: 'sass';
|
|
33
33
|
/** Prefix to happen to generated private variables */
|
|
34
34
|
prefixPrivate?: string;
|
|
@@ -36,7 +36,7 @@ export interface GenerateCssSchematicsSchema extends SchematicOptionObject {
|
|
|
36
36
|
failOnMissingReference?: boolean;
|
|
37
37
|
/** Type of the variables to generate for a Design Token */
|
|
38
38
|
variableType?: 'css' | 'sass';
|
|
39
|
-
/** Path to a template file to apply as default configuration to a Design Token extension */
|
|
39
|
+
/** Path to a template file (or a list of template files) to apply as default configuration to a Design Token extension */
|
|
40
40
|
templateFile?: string | string[];
|
|
41
41
|
}
|
|
42
42
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../builders/generate-css/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,2BAA4B,SAAQ,qBAAqB;IACxE,mDAAmD;IACnD,uBAAuB,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE3C;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gFAAgF;IAChF,gBAAgB,EAAE,MAAM,CAAC;IAEzB,wBAAwB;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,wEAAwE;IACxE,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,0DAA0D;IAC1D,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC,sDAAsD;IACtD,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,2FAA2F;IAC3F,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC,2DAA2D;IAC3D,YAAY,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAE9B,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../builders/generate-css/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,2BAA4B,SAAQ,qBAAqB;IACxE,mDAAmD;IACnD,uBAAuB,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE3C;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gFAAgF;IAChF,gBAAgB,EAAE,MAAM,CAAC;IAEzB,wBAAwB;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,wEAAwE;IACxE,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,0DAA0D;IAC1D,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC,sDAAsD;IACtD,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,2FAA2F;IAC3F,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC,2DAA2D;IAC3D,YAAY,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAE9B,0HAA0H;IAC1H,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAClC"}
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"output": {
|
|
31
31
|
"type": "string",
|
|
32
|
-
"description": "Path to generate the
|
|
32
|
+
"description": "Path to generate the Metadata for CMS. The Metadata will be generated only if the file path is specified"
|
|
33
33
|
},
|
|
34
34
|
"defaultStyleFile": {
|
|
35
35
|
"type": "string",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"metadataIgnorePrivate": {
|
|
44
44
|
"type": "boolean",
|
|
45
45
|
"default": false,
|
|
46
|
-
"description": "Ignore the private variable in the
|
|
46
|
+
"description": "Ignore the private variable in the Metadata generation."
|
|
47
47
|
},
|
|
48
48
|
"rootPath": {
|
|
49
49
|
"type": "string",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"description": "Determine if the process should stop in case of Token duplication"
|
|
61
61
|
},
|
|
62
62
|
"templateFile": {
|
|
63
|
-
"description": "Path to a template file(
|
|
63
|
+
"description": "Path to a template file (or a list of template files) to apply as default configuration to a Design Token extension. In case of multiple files, the JSON will be deeply merged in the order defined by the list.",
|
|
64
64
|
"oneOf": [
|
|
65
65
|
{
|
|
66
66
|
"type": "string"
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"enum": [
|
|
87
87
|
"sass"
|
|
88
88
|
],
|
|
89
|
-
"description": "Generate the
|
|
89
|
+
"description": "Generate the private variable to the given language (the variable is not generated if not specified)"
|
|
90
90
|
},
|
|
91
91
|
"failOnMissingReference": {
|
|
92
92
|
"type": "boolean",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BuilderContext } from '@angular-devkit/architect';
|
|
2
|
+
import { type DesignTokenRendererOptions, type TokenKeyRenderer } from '../../../src/public_api';
|
|
3
|
+
import type { GenerateStyleSchematicsSchema } from '../schema';
|
|
4
|
+
export declare const getMetadataRenderDesignTokenOptions: (tokenVariableNameRenderer: TokenKeyRenderer | undefined, options: GenerateStyleSchematicsSchema, context: BuilderContext) => DesignTokenRendererOptions;
|
|
5
|
+
//# sourceMappingURL=metadata-renderer-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-renderer-options.d.ts","sourceRoot":"","sources":["../../../../builders/generate-style/helpers/metadata-renderer-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EACL,KAAK,0BAA0B,EAG/B,KAAK,gBAAgB,EACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAG/D,eAAO,MAAM,mCAAmC,8BACnB,gBAAgB,GAAG,SAAS,WAC9C,6BAA6B,WAC7B,cAAc,KAAG,0BAc3B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMetadataRenderDesignTokenOptions = void 0;
|
|
4
|
+
const public_api_1 = require("../../../src/public_api");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const getMetadataRenderDesignTokenOptions = (tokenVariableNameRenderer, options, context) => {
|
|
7
|
+
/** Builder logger */
|
|
8
|
+
const logger = context.logger;
|
|
9
|
+
return {
|
|
10
|
+
determineFileToUpdate: () => (0, node_path_1.resolve)(context.workspaceRoot, options.metadataOutput || 'style.metadata.json'),
|
|
11
|
+
styleContentUpdater: (0, public_api_1.getMetadataStyleContentUpdater)(),
|
|
12
|
+
tokenDefinitionRenderer: (0, public_api_1.getMetadataTokenDefinitionRenderer)({
|
|
13
|
+
tokenVariableNameRenderer,
|
|
14
|
+
ignorePrivateVariable: options.metadataIgnorePrivate
|
|
15
|
+
}),
|
|
16
|
+
logger
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
exports.getMetadataRenderDesignTokenOptions = getMetadataRenderDesignTokenOptions;
|
|
20
|
+
//# sourceMappingURL=metadata-renderer-options.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BuilderContext } from '@angular-devkit/architect';
|
|
2
|
+
import { type DesignTokenRendererOptions, type TokenKeyRenderer } from '../../../src/public_api';
|
|
3
|
+
import type { GenerateStyleSchematicsSchema } from '../schema';
|
|
4
|
+
export declare const getStyleRendererOptions: (tokenVariableNameRenderer: TokenKeyRenderer | undefined, options: GenerateStyleSchematicsSchema, context: BuilderContext) => DesignTokenRendererOptions;
|
|
5
|
+
//# sourceMappingURL=style-renderer-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-renderer-options.d.ts","sourceRoot":"","sources":["../../../../builders/generate-style/helpers/style-renderer-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAGL,KAAK,0BAA0B,EAY/B,KAAK,gBAAgB,EAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAI/D,eAAO,MAAM,uBAAuB,8BAA+B,gBAAgB,GAAG,SAAS,WAAY,6BAA6B,WAAW,cAAc,KAAG,0BA8HnK,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStyleRendererOptions = void 0;
|
|
4
|
+
const public_api_1 = require("../../../src/public_api");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const promises_1 = require("node:fs/promises");
|
|
7
|
+
const getStyleRendererOptions = (tokenVariableNameRenderer, options, context) => {
|
|
8
|
+
/**
|
|
9
|
+
* Function to determine files to update based on the Design Token
|
|
10
|
+
* @param token
|
|
11
|
+
*/
|
|
12
|
+
const determineFileToUpdate = options.output ? () => (0, node_path_1.resolve)(context.workspaceRoot, options.output) :
|
|
13
|
+
(token) => {
|
|
14
|
+
if (token.extensions.o3rTargetFile) {
|
|
15
|
+
return token.context?.basePath && !options.rootPath
|
|
16
|
+
? (0, node_path_1.resolve)(token.context.basePath, token.extensions.o3rTargetFile)
|
|
17
|
+
: (0, node_path_1.resolve)(context.workspaceRoot, options.rootPath || '', token.extensions.o3rTargetFile);
|
|
18
|
+
}
|
|
19
|
+
return (0, node_path_1.resolve)(context.workspaceRoot, options.defaultStyleFile);
|
|
20
|
+
};
|
|
21
|
+
/** Builder logger */
|
|
22
|
+
const logger = context.logger;
|
|
23
|
+
/**
|
|
24
|
+
* File writer with logging when writing file
|
|
25
|
+
* @param file
|
|
26
|
+
* @param {...any} args
|
|
27
|
+
*/
|
|
28
|
+
const writeFileWithLogger = async (file, ...args) => {
|
|
29
|
+
const res = await (0, promises_1.writeFile)(file, ...args);
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
31
|
+
logger.info(`Updated ${file.toString()} with Design Token content.`);
|
|
32
|
+
return res;
|
|
33
|
+
};
|
|
34
|
+
/** Render for the private variables if specified */
|
|
35
|
+
const privateDefinitionRenderer = options.renderPrivateVariableTo === 'sass' ? (0, public_api_1.getSassTokenDefinitionRenderer)({
|
|
36
|
+
tokenVariableNameRenderer: (v) => (options?.prefixPrivate || '') + (0, public_api_1.tokenVariableNameSassRenderer)(v),
|
|
37
|
+
logger
|
|
38
|
+
}) : undefined;
|
|
39
|
+
/** Update of file content based on selected language */
|
|
40
|
+
const styleContentUpdater = ((language) => {
|
|
41
|
+
switch (language) {
|
|
42
|
+
case 'css': {
|
|
43
|
+
return (0, public_api_1.getCssStyleContentUpdater)();
|
|
44
|
+
}
|
|
45
|
+
case 'scss':
|
|
46
|
+
case 'sass': {
|
|
47
|
+
return (0, public_api_1.getSassStyleContentUpdater)();
|
|
48
|
+
}
|
|
49
|
+
default: {
|
|
50
|
+
throw new Error(`No available updater for "${language}"`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
})(options.language);
|
|
54
|
+
/** Style token value renderer based on selected language */
|
|
55
|
+
const tokenValueRenderer = ((language) => {
|
|
56
|
+
const tokenValueRendererOptions = {
|
|
57
|
+
tokenVariableNameRenderer,
|
|
58
|
+
logger,
|
|
59
|
+
unregisteredReferenceRenderer: options.failOnMissingReference ? (refName) => { throw new Error(`The Design Token ${refName} is not registered`); } : undefined
|
|
60
|
+
};
|
|
61
|
+
switch (language) {
|
|
62
|
+
case 'css': {
|
|
63
|
+
return (0, public_api_1.getCssTokenValueRenderer)(tokenValueRendererOptions);
|
|
64
|
+
}
|
|
65
|
+
case 'scss':
|
|
66
|
+
case 'sass': {
|
|
67
|
+
return (0, public_api_1.getSassTokenValueRenderer)(tokenValueRendererOptions);
|
|
68
|
+
}
|
|
69
|
+
default: {
|
|
70
|
+
throw new Error(`No available value renderer for "${language}"`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
})(options.variableReferenceType || options.language);
|
|
74
|
+
/** Style token variable set renderer based on selected language */
|
|
75
|
+
const tokenDefinitionRenderer = ((language) => {
|
|
76
|
+
const tokenDefinitionRendererOptions = {
|
|
77
|
+
privateDefinitionRenderer,
|
|
78
|
+
tokenVariableNameRenderer,
|
|
79
|
+
tokenValueRenderer,
|
|
80
|
+
logger
|
|
81
|
+
};
|
|
82
|
+
switch (language) {
|
|
83
|
+
case 'css': {
|
|
84
|
+
const variableReferenceType = options.variableReferenceType || options.language;
|
|
85
|
+
return (0, public_api_1.getCssTokenDefinitionRenderer)({
|
|
86
|
+
...tokenDefinitionRendererOptions,
|
|
87
|
+
tokenValueRenderer: ['sass', 'scss'].includes(variableReferenceType)
|
|
88
|
+
? (...arg) => `#{${tokenValueRenderer(...arg)}}`
|
|
89
|
+
: tokenValueRenderer
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
case 'scss':
|
|
93
|
+
case 'sass': {
|
|
94
|
+
return (0, public_api_1.getSassTokenDefinitionRenderer)(tokenDefinitionRendererOptions);
|
|
95
|
+
}
|
|
96
|
+
default: {
|
|
97
|
+
throw new Error(`No available value renderer for "${language}"`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
})(options.variableType || options.language);
|
|
101
|
+
/** Sorting strategy of variables based on selected language */
|
|
102
|
+
const tokenListTransforms = ((language) => {
|
|
103
|
+
switch (language) {
|
|
104
|
+
case 'scss':
|
|
105
|
+
case 'sass': {
|
|
106
|
+
return [public_api_1.getTokenSorterByName, public_api_1.getTokenSorterByRef];
|
|
107
|
+
}
|
|
108
|
+
case 'css':
|
|
109
|
+
default: {
|
|
110
|
+
return [public_api_1.getTokenSorterByName];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
})(options.variableType || options.language);
|
|
114
|
+
/** Option to be used by the style renderer */
|
|
115
|
+
return {
|
|
116
|
+
tokenListTransforms,
|
|
117
|
+
writeFile: writeFileWithLogger,
|
|
118
|
+
styleContentUpdater,
|
|
119
|
+
determineFileToUpdate,
|
|
120
|
+
tokenDefinitionRenderer,
|
|
121
|
+
logger
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
exports.getStyleRendererOptions = getStyleRendererOptions;
|
|
125
|
+
//# sourceMappingURL=style-renderer-options.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type DesignTokenGroupTemplate } from '../../../src/public_api';
|
|
2
|
+
import type { BuilderContext } from '@angular-devkit/architect';
|
|
3
|
+
/**
|
|
4
|
+
* Generate template object
|
|
5
|
+
* @param templateFilePaths list of template files
|
|
6
|
+
* @param context builder context
|
|
7
|
+
*/
|
|
8
|
+
export declare const generateTemplate: (templateFilePaths: string[], context: BuilderContext) => Promise<DesignTokenGroupTemplate>;
|
|
9
|
+
//# sourceMappingURL=token-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-template.d.ts","sourceRoot":"","sources":["../../../../builders/generate-style/helpers/token-template.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAE9B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,sBAA6B,MAAM,EAAE,WAAW,cAAc,KAAG,OAAO,CAAC,wBAAwB,CAgB7H,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateTemplate = void 0;
|
|
4
|
+
const promises_1 = require("node:fs/promises");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const public_api_1 = require("../../../src/public_api");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
/**
|
|
9
|
+
* Generate template object
|
|
10
|
+
* @param templateFilePaths list of template files
|
|
11
|
+
* @param context builder context
|
|
12
|
+
*/
|
|
13
|
+
const generateTemplate = async (templateFilePaths, context) => {
|
|
14
|
+
const templateFiles = await Promise.all(templateFilePaths
|
|
15
|
+
.map(async (templateFile) => {
|
|
16
|
+
let templateFilePath = (0, node_path_1.resolve)(context.workspaceRoot, templateFile);
|
|
17
|
+
if (!(0, node_fs_1.existsSync)(templateFilePath)) {
|
|
18
|
+
try {
|
|
19
|
+
templateFilePath = require.resolve(templateFile);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
context.logger.error(`Cannot resolve the template file at '${templateFile}', it will be ignored.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return JSON.parse(await (0, promises_1.readFile)(templateFilePath, { encoding: 'utf8' }));
|
|
26
|
+
}));
|
|
27
|
+
return templateFiles.reduce((acc, cur) => (0, public_api_1.mergeDesignTokenTemplates)(acc, cur), {});
|
|
28
|
+
};
|
|
29
|
+
exports.generateTemplate = generateTemplate;
|
|
30
|
+
//# sourceMappingURL=token-template.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GenerateStyleSchematicsSchema } from './schema';
|
|
2
|
+
/**
|
|
3
|
+
* Generate CSS from Design Token files
|
|
4
|
+
* @param options
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: import("@angular-devkit/architect/src/internal").Builder<GenerateStyleSchematicsSchema & import("@angular-devkit/core").JsonObject>;
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../builders/generate-style/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AA6B9D;;;GAGG;;AACH,wBA+GI"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const architect_1 = require("@angular-devkit/architect");
|
|
4
|
+
const public_api_1 = require("../../src/public_api");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const globby_1 = require("globby");
|
|
7
|
+
const node_os_1 = require("node:os");
|
|
8
|
+
const token_template_1 = require("./helpers/token-template");
|
|
9
|
+
const style_renderer_options_1 = require("./helpers/style-renderer-options");
|
|
10
|
+
const metadata_renderer_options_1 = require("./helpers/metadata-renderer-options");
|
|
11
|
+
const createBuilderWithMetricsIfInstalled = (builderFn) => async (opts, ctx) => {
|
|
12
|
+
let wrapper = (fn) => fn;
|
|
13
|
+
try {
|
|
14
|
+
const { createBuilderWithMetrics } = await Promise.resolve().then(() => require('@o3r/telemetry'));
|
|
15
|
+
wrapper = createBuilderWithMetrics;
|
|
16
|
+
}
|
|
17
|
+
catch { }
|
|
18
|
+
return wrapper(builderFn)(opts, ctx);
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Generate CSS from Design Token files
|
|
22
|
+
* @param options
|
|
23
|
+
*/
|
|
24
|
+
exports.default = (0, architect_1.createBuilder)(createBuilderWithMetricsIfInstalled(async (options, context) => {
|
|
25
|
+
/** List of template files */
|
|
26
|
+
const templateFilePaths = options.templateFile
|
|
27
|
+
&& (typeof options.templateFile === 'string' ? [options.templateFile] : options.templateFile)
|
|
28
|
+
|| undefined;
|
|
29
|
+
/** Template object */
|
|
30
|
+
const template = templateFilePaths && await (0, token_template_1.generateTemplate)(templateFilePaths, context);
|
|
31
|
+
/** List of input Design Token file patterns */
|
|
32
|
+
const designTokenFilePatterns = Array.isArray(options.designTokenFilePatterns) ? options.designTokenFilePatterns : [options.designTokenFilePatterns];
|
|
33
|
+
/**
|
|
34
|
+
* Render the variable name if the option `prefix` is defined
|
|
35
|
+
* @param variable
|
|
36
|
+
*/
|
|
37
|
+
const tokenVariableNameRenderer = options.prefix ? (variable) => options.prefix + variable.getKey() : undefined;
|
|
38
|
+
/** Option to be used by the style renderer */
|
|
39
|
+
const renderStyleDesignTokenOptions = (0, style_renderer_options_1.getStyleRendererOptions)(tokenVariableNameRenderer, options, context);
|
|
40
|
+
/** Option to be used by the metadata renderer */
|
|
41
|
+
const renderMetadataDesignTokenOptions = (0, metadata_renderer_options_1.getMetadataRenderDesignTokenOptions)(tokenVariableNameRenderer, options, context);
|
|
42
|
+
/**
|
|
43
|
+
* Runner for a single renderer
|
|
44
|
+
* @param renderDesignTokenOptions
|
|
45
|
+
*/
|
|
46
|
+
const execute = async (renderDesignTokenOptions) => {
|
|
47
|
+
const files = (0, globby_1.sync)(designTokenFilePatterns, { cwd: context.workspaceRoot, absolute: true });
|
|
48
|
+
const inDependencies = designTokenFilePatterns
|
|
49
|
+
.filter((pathName) => !pathName.startsWith('.') && !pathName.startsWith('*') && !pathName.startsWith('/'))
|
|
50
|
+
.map((pathName) => {
|
|
51
|
+
try {
|
|
52
|
+
return require.resolve(pathName);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
.filter((pathName) => !!pathName);
|
|
59
|
+
files.push(...inDependencies);
|
|
60
|
+
try {
|
|
61
|
+
const duplicatedToken = [];
|
|
62
|
+
const tokens = (await Promise.all(files.map(async (file) => ({ file, parsed: await (0, public_api_1.parseDesignTokenFile)(file, { specificationContext: { template } }) }))))
|
|
63
|
+
.reduce((acc, { file, parsed }) => {
|
|
64
|
+
parsed.forEach((variable, key) => {
|
|
65
|
+
if (acc.has(key)) {
|
|
66
|
+
context.logger[options.failOnDuplicate ? 'error' : 'warn'](`A duplication of the variable ${key} is found in ${file}`);
|
|
67
|
+
duplicatedToken.push(variable);
|
|
68
|
+
}
|
|
69
|
+
acc.set(key, variable);
|
|
70
|
+
});
|
|
71
|
+
return acc;
|
|
72
|
+
}, new Map());
|
|
73
|
+
if (options.failOnDuplicate && duplicatedToken.length > 0) {
|
|
74
|
+
throw new Error(`Found ${duplicatedToken.length} duplicated Design Token keys`);
|
|
75
|
+
}
|
|
76
|
+
await (0, public_api_1.renderDesignTokens)(tokens, renderDesignTokenOptions);
|
|
77
|
+
return { success: true };
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
return { success: false, error: String(err) };
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/** Runner for all the renderers based on options */
|
|
84
|
+
const executeMultiRenderer = async () => {
|
|
85
|
+
return (await Promise.allSettled([
|
|
86
|
+
execute(renderStyleDesignTokenOptions),
|
|
87
|
+
...(options.metadataOutput ? [execute(renderMetadataDesignTokenOptions)] : [])
|
|
88
|
+
])).reduce((acc, res) => {
|
|
89
|
+
if (res.status === 'fulfilled') {
|
|
90
|
+
acc.success &&= res.value.success;
|
|
91
|
+
if (res.value.error) {
|
|
92
|
+
acc.error ||= '';
|
|
93
|
+
acc.error += node_os_1.EOL + res.value.error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
acc.success = false;
|
|
98
|
+
if (res.reason) {
|
|
99
|
+
acc.error ||= '';
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
101
|
+
acc.error += node_os_1.EOL + res.reason;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return acc;
|
|
105
|
+
}, { success: true });
|
|
106
|
+
};
|
|
107
|
+
if (!options.watch) {
|
|
108
|
+
return await executeMultiRenderer();
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
try {
|
|
112
|
+
await Promise.resolve().then(() => require('chokidar')).then((chokidar) => chokidar.watch([
|
|
113
|
+
...designTokenFilePatterns.map((p) => (0, node_path_1.resolve)(context.workspaceRoot, p)),
|
|
114
|
+
...(templateFilePaths || [])
|
|
115
|
+
]))
|
|
116
|
+
.then((watcher) => watcher.on('all', async () => {
|
|
117
|
+
const res = await executeMultiRenderer();
|
|
118
|
+
if (res.error) {
|
|
119
|
+
context.logger.error(res.error);
|
|
120
|
+
}
|
|
121
|
+
}));
|
|
122
|
+
return { success: true };
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
return { success: false, error: String(err) };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}));
|
|
129
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { SchematicOptionObject } from '@o3r/schematics';
|
|
2
|
+
/** Available style languages */
|
|
3
|
+
export type AvailableLanguage = 'css' | 'sass' | 'scss';
|
|
4
|
+
export interface GenerateStyleSchematicsSchema extends SchematicOptionObject {
|
|
5
|
+
/**
|
|
6
|
+
* Language defined to generate the styling
|
|
7
|
+
* Note: This will drive the default behavior of {@link variableType} and {@link variableReferenceType}
|
|
8
|
+
*/
|
|
9
|
+
language: AvailableLanguage;
|
|
10
|
+
/** Type of the variables to generate for a Design Token */
|
|
11
|
+
variableType?: AvailableLanguage;
|
|
12
|
+
/** Type of the variables to generate for a Design Token reference */
|
|
13
|
+
variableReferenceType?: AvailableLanguage;
|
|
14
|
+
/** Path patterns to the Design Token JSON files */
|
|
15
|
+
designTokenFilePatterns: string | string[];
|
|
16
|
+
/**
|
|
17
|
+
* Path to generate the metadata for CMS
|
|
18
|
+
* The Metadata will be generated only if the file path is specified
|
|
19
|
+
*/
|
|
20
|
+
metadataOutput?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Ignore private variables in the metadata generation
|
|
23
|
+
*/
|
|
24
|
+
metadataIgnorePrivate?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Output file where to generate the CSS
|
|
27
|
+
*
|
|
28
|
+
* If specified, all the generated CSS variables will be generated in the given file.
|
|
29
|
+
* Otherwise, the output file will be determined based on the variable parameters
|
|
30
|
+
*/
|
|
31
|
+
output?: string;
|
|
32
|
+
/** File path to generate the variable if not determined by the specification */
|
|
33
|
+
defaultStyleFile: string;
|
|
34
|
+
/** Enable Watch mode */
|
|
35
|
+
watch?: boolean;
|
|
36
|
+
/** Root path of the files where the CSS will be generated */
|
|
37
|
+
rootPath?: string;
|
|
38
|
+
/** Determine if the process should stop in case of Design Token duplication */
|
|
39
|
+
failOnDuplicate?: boolean;
|
|
40
|
+
/** Prefix to append to generated variables */
|
|
41
|
+
prefix?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Generate the private variable in the given language
|
|
44
|
+
* Note: if not provided, the private variable will not be rendered in the CSS language.
|
|
45
|
+
*/
|
|
46
|
+
renderPrivateVariableTo?: Exclude<AvailableLanguage, 'css'>;
|
|
47
|
+
/** Prefix to append to generated private variables */
|
|
48
|
+
prefixPrivate?: string;
|
|
49
|
+
/** Determine if the builder should fail if a missing Design Token reference is detected */
|
|
50
|
+
failOnMissingReference?: boolean;
|
|
51
|
+
/** Path to a template file to apply as default configuration to a Design Token extension */
|
|
52
|
+
templateFile?: string | string[];
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../builders/generate-style/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,gCAAgC;AAChC,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAExD,MAAM,WAAW,6BAA8B,SAAQ,qBAAqB;IAC1E;;;OAGG;IACH,QAAQ,EAAE,iBAAiB,CAAC;IAE5B,2DAA2D;IAC3D,YAAY,CAAC,EAAE,iBAAiB,CAAC;IAEjC,qEAAqE;IACrE,qBAAqB,CAAC,EAAE,iBAAiB,CAAC;IAE1C,mDAAmD;IACnD,uBAAuB,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE3C;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gFAAgF;IAChF,gBAAgB,EAAE,MAAM,CAAC;IAEzB,wBAAwB;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,+EAA+E;IAC/E,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;IAE5D,sDAAsD;IACtD,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,2FAA2F;IAC3F,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC,4FAA4F;IAC5F,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAClC"}
|