@o3r/design 11.1.0-prerelease.51 → 11.1.0-prerelease.52
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 +15 -0
- package/builders/generate-css/index.js +2 -2
- package/builders/generate-css/schema.json +3 -3
- package/builders/generate-jsonschema/index.d.ts +8 -0
- package/builders/generate-jsonschema/index.d.ts.map +1 -0
- package/builders/generate-jsonschema/index.js +76 -0
- package/builders/generate-jsonschema/schema.d.ts +22 -0
- package/builders/generate-jsonschema/schema.d.ts.map +1 -0
- package/builders/generate-jsonschema/schema.js +3 -0
- package/builders/generate-jsonschema/schema.json +45 -0
- package/builders.json +5 -0
- package/package.json +10 -10
- package/src/core/design-token/renderers/index.d.ts +3 -2
- package/src/core/design-token/renderers/index.d.ts.map +1 -1
- package/src/core/design-token/renderers/index.js +3 -2
- package/src/core/design-token/renderers/index.js.map +1 -1
- package/src/core/design-token/renderers/json-schema/design-token-definition.renderers.d.ts +13 -0
- package/src/core/design-token/renderers/json-schema/design-token-definition.renderers.d.ts.map +1 -0
- package/src/core/design-token/renderers/json-schema/design-token-definition.renderers.js +39 -0
- package/src/core/design-token/renderers/json-schema/design-token-definition.renderers.js.map +1 -0
- package/src/core/design-token/renderers/json-schema/design-token-updater.renderers.d.ts +14 -0
- package/src/core/design-token/renderers/json-schema/design-token-updater.renderers.d.ts.map +1 -0
- package/src/core/design-token/renderers/json-schema/design-token-updater.renderers.js +20 -0
- package/src/core/design-token/renderers/json-schema/design-token-updater.renderers.js.map +1 -0
- package/src/core/design-token/renderers/json-schema/design-token-value.renderers.d.ts +20 -0
- package/src/core/design-token/renderers/json-schema/design-token-value.renderers.d.ts.map +1 -0
- package/src/core/design-token/renderers/json-schema/design-token-value.renderers.js +39 -0
- package/src/core/design-token/renderers/json-schema/design-token-value.renderers.js.map +1 -0
- package/src/core/design-token/renderers/json-schema/index.d.ts +4 -0
- package/src/core/design-token/renderers/json-schema/index.d.ts.map +1 -0
- package/src/core/design-token/renderers/json-schema/index.js +7 -0
- package/src/core/design-token/renderers/json-schema/index.js.map +1 -0
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ The following configurations are available:
|
|
|
41
41
|
| Options | Default Value | Description |
|
|
42
42
|
| --------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
43
43
|
| **designTokenFilePatterns** | [] *Require* | Path patterns to the Design Token JSON files. <br /> Files in dependencies are supported and resolved with Node Resolver. |
|
|
44
|
+
| **variableType** | `'css'` | Type of the variables to generate for a Design Token. |
|
|
44
45
|
| **output** | *null* | Output file where the CSS will be generated. <br /> The path specified in `o3rTargetFile` will be ignore if this option is specified |
|
|
45
46
|
| **defaultStyleFile** | src/theme.scss | File path to generate the variable if not determined by the specifications |
|
|
46
47
|
| **metadataOutput** | *null* | Path to generate the metadata for the CMS. <br /> The metadata will be generated only if the file path is specified. |
|
|
@@ -49,6 +50,20 @@ The following configurations are available:
|
|
|
49
50
|
| **prefix** | *null* | Prefix to append to generated variables. |
|
|
50
51
|
| **watch** | false | Enable Watch mode. |
|
|
51
52
|
|
|
53
|
+
### generate-jsonschema
|
|
54
|
+
|
|
55
|
+
The `generate-jsonschema` builder can generate a [JSON Schema](https://json-schema.org/) validating and providing auto-completion to a third party Design Token file implementing a theme for the current Design system.
|
|
56
|
+
The following configurations are available:
|
|
57
|
+
|
|
58
|
+
| Options | Default Value | Description |
|
|
59
|
+
| --------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
60
|
+
| **designTokenFilePatterns** | [] *Require* | Path patterns to the Design Token JSON files. <br /> Files in dependencies are supported and resolved with Node Resolver. |
|
|
61
|
+
| **output** | *null* | Output file where the CSS will be generated. <br /> The path specified in `o3rTargetFile` will be ignored if this option is specified |
|
|
62
|
+
| **failOnDuplicate** | false | Determine if the process should stop in case of Token duplication. |
|
|
63
|
+
| **schemaId** | *null* | ID used in the generated JSON Schema. |
|
|
64
|
+
| **schemaDescription** | *null* | Description of the generated JSON Schema. |
|
|
65
|
+
| **watch** | false | Enable Watch mode. |
|
|
66
|
+
|
|
52
67
|
## Technical documentation
|
|
53
68
|
|
|
54
69
|
Documentation providing explanations on the use and customization of the `Design Token` parser and renderers is available in the [technical documentation](https://github.com/AmadeusITGroup/otter/blob/main/docs/design/TECHNICAL_DOCUMENTATION.md).
|
|
@@ -87,7 +87,7 @@ exports.default = (0, architect_1.createBuilder)(async (options, context) => {
|
|
|
87
87
|
return { success: true };
|
|
88
88
|
}
|
|
89
89
|
catch (err) {
|
|
90
|
-
return { success: false, error:
|
|
90
|
+
return { success: false, error: String(err) };
|
|
91
91
|
}
|
|
92
92
|
};
|
|
93
93
|
const executeMultiRenderer = async () => {
|
|
@@ -128,7 +128,7 @@ exports.default = (0, architect_1.createBuilder)(async (options, context) => {
|
|
|
128
128
|
return { success: true };
|
|
129
129
|
}
|
|
130
130
|
catch (err) {
|
|
131
|
-
return { success: false, error:
|
|
131
|
+
return { success: false, error: String(err) };
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
-
"$id": "
|
|
4
|
-
"title": "
|
|
5
|
-
"description": "
|
|
3
|
+
"$id": "generateCssSchematicsSchema",
|
|
4
|
+
"title": "Generate the style from Design Token",
|
|
5
|
+
"description": "Generate the style from Design Token",
|
|
6
6
|
"properties": {
|
|
7
7
|
"variableType": {
|
|
8
8
|
"type": "string",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GenerateJsonSchemaSchematicsSchema } from './schema';
|
|
2
|
+
/**
|
|
3
|
+
* Generate Json Schema from Design Token files
|
|
4
|
+
* @param options
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: import("@angular-devkit/architect/src/internal").Builder<GenerateJsonSchemaSchematicsSchema & 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-jsonschema/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAC;AAYnE;;;GAGG;;AACH,wBAkEG"}
|
|
@@ -0,0 +1,76 @@
|
|
|
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 = require("globby");
|
|
7
|
+
/**
|
|
8
|
+
* Generate Json Schema from Design Token files
|
|
9
|
+
* @param options
|
|
10
|
+
*/
|
|
11
|
+
exports.default = (0, architect_1.createBuilder)(async (options, context) => {
|
|
12
|
+
const designTokenFilePatterns = Array.isArray(options.designTokenFilePatterns) ? options.designTokenFilePatterns : [options.designTokenFilePatterns];
|
|
13
|
+
const execute = async () => {
|
|
14
|
+
const files = (await globby(designTokenFilePatterns, { cwd: context.workspaceRoot, absolute: true }));
|
|
15
|
+
const inDependencies = designTokenFilePatterns
|
|
16
|
+
.filter((pathName) => !pathName.startsWith('.') && !pathName.startsWith('*') && !pathName.startsWith('/'))
|
|
17
|
+
.map((pathName) => {
|
|
18
|
+
try {
|
|
19
|
+
return require.resolve(pathName);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
.filter((pathName) => !!pathName);
|
|
26
|
+
files.push(...inDependencies);
|
|
27
|
+
try {
|
|
28
|
+
const duplicatedToken = [];
|
|
29
|
+
const tokens = (await Promise.all(files.map(async (file) => ({ file, parsed: await (0, public_api_1.parseDesignTokenFile)(file) }))))
|
|
30
|
+
.reduce((acc, { file, parsed }) => {
|
|
31
|
+
parsed.forEach((variable, key) => {
|
|
32
|
+
if (acc.has(key)) {
|
|
33
|
+
context.logger[options.failOnDuplicate ? 'error' : 'warn'](`A duplication of the variable ${key} is found in ${file}`);
|
|
34
|
+
duplicatedToken.push(variable);
|
|
35
|
+
}
|
|
36
|
+
acc.set(key, variable);
|
|
37
|
+
});
|
|
38
|
+
return acc;
|
|
39
|
+
}, new Map());
|
|
40
|
+
if (options.failOnDuplicate && duplicatedToken.length > 0) {
|
|
41
|
+
throw new Error(`Found ${duplicatedToken.length} duplicated Design Token keys`);
|
|
42
|
+
}
|
|
43
|
+
await (0, public_api_1.renderDesignTokens)(tokens, {
|
|
44
|
+
determineFileToUpdate: () => (0, node_path_1.resolve)(context.workspaceRoot, options.output),
|
|
45
|
+
tokenDefinitionRenderer: (0, public_api_1.getJsonSchemaTokenDefinitionRenderer)(),
|
|
46
|
+
styleContentUpdater: (0, public_api_1.getJsonSchemaStyleContentUpdater)({
|
|
47
|
+
id: options.schemaId,
|
|
48
|
+
description: options.schemaDescription
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
return { success: true };
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
return { success: false, error: String(err) };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
if (!options.watch) {
|
|
58
|
+
return await execute();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
try {
|
|
62
|
+
await Promise.resolve().then(() => require('chokidar')).then((chokidar) => chokidar.watch(designTokenFilePatterns.map((p) => (0, node_path_1.resolve)(context.workspaceRoot, p))))
|
|
63
|
+
.then((watcher) => watcher.on('all', async () => {
|
|
64
|
+
const res = await execute();
|
|
65
|
+
if (res.error) {
|
|
66
|
+
context.logger.error(res.error);
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
return { success: true };
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
return { success: false, error: String(err) };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SchematicOptionObject } from '@o3r/schematics';
|
|
2
|
+
export interface GenerateJsonSchemaSchematicsSchema extends SchematicOptionObject {
|
|
3
|
+
/** Path patterns to the Design Token JSON files */
|
|
4
|
+
designTokenFilePatterns: string | string[];
|
|
5
|
+
/** Path to the outputted Json schema file. */
|
|
6
|
+
output: string;
|
|
7
|
+
/** File path to generate the variable if not determined by the specification */
|
|
8
|
+
defaultStyleFile: string;
|
|
9
|
+
/** Enable Watch mode */
|
|
10
|
+
watch?: boolean;
|
|
11
|
+
/** Root path of files where the CSS will be generated */
|
|
12
|
+
rootPath?: string;
|
|
13
|
+
/** Determine if the process should stop in case of Token duplication */
|
|
14
|
+
failOnDuplicate?: boolean;
|
|
15
|
+
/** Determine if the builder should fail if a missing Design Token reference is detected */
|
|
16
|
+
failOnMissingReference?: boolean;
|
|
17
|
+
/** ID used in the generated JSON Schema */
|
|
18
|
+
schemaId?: string;
|
|
19
|
+
/** Description of the generated JSON Schema */
|
|
20
|
+
schemaDescription?: string;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../builders/generate-jsonschema/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,kCAAmC,SAAQ,qBAAqB;IAC/E,mDAAmD;IACnD,uBAAuB,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE3C,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IAEf,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,2FAA2F;IAC3F,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,+CAA+C;IAC/C,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
+
"$id": "generateJsonSchematicsSchema",
|
|
4
|
+
"title": "Generate the JSON Schema from Design Token",
|
|
5
|
+
"description": "Generate the JSON Schema from Design Token",
|
|
6
|
+
"properties": {
|
|
7
|
+
"designTokenFilePatterns": {
|
|
8
|
+
"description": "Path patterns to the Design Token JSON files (it supports Node dependency paths).",
|
|
9
|
+
"type": [
|
|
10
|
+
"array",
|
|
11
|
+
"string"
|
|
12
|
+
],
|
|
13
|
+
"items": {
|
|
14
|
+
"type": "string"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"output": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"description": "Path to the outputted Json schema file.",
|
|
20
|
+
"default": "design-token.schema.json"
|
|
21
|
+
},
|
|
22
|
+
"watch": {
|
|
23
|
+
"type": "boolean",
|
|
24
|
+
"default": false,
|
|
25
|
+
"description": "Enable Watch mode"
|
|
26
|
+
},
|
|
27
|
+
"failOnDuplicate": {
|
|
28
|
+
"type": "boolean",
|
|
29
|
+
"default": false,
|
|
30
|
+
"description": "Determine if the process should stop in case of Token duplication"
|
|
31
|
+
},
|
|
32
|
+
"schemaId": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"description": "ID used in the generated JSON Schema"
|
|
35
|
+
},
|
|
36
|
+
"schemaDescription": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"description": "Description of the generated JSON Schema"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"additionalProperties": true,
|
|
42
|
+
"required": [
|
|
43
|
+
"designTokenFilePatterns"
|
|
44
|
+
]
|
|
45
|
+
}
|
package/builders.json
CHANGED
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
"implementation": "./builders/generate-css/",
|
|
6
6
|
"schema": "./builders/generate-css/schema.json",
|
|
7
7
|
"description": "Generate CSS from Design Token files"
|
|
8
|
+
},
|
|
9
|
+
"generate-jsonschema": {
|
|
10
|
+
"implementation": "./builders/generate-jsonschema/",
|
|
11
|
+
"schema": "./builders/generate-jsonschema/schema.json",
|
|
12
|
+
"description": "Generate JSON Schema from Design Token files"
|
|
8
13
|
}
|
|
9
14
|
}
|
|
10
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o3r/design",
|
|
3
|
-
"version": "11.1.0-prerelease.
|
|
3
|
+
"version": "11.1.0-prerelease.52",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"tslib": "^2.6.2"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@o3r/core": "^11.1.0-prerelease.
|
|
56
|
-
"@o3r/schematics": "^11.1.0-prerelease.
|
|
57
|
-
"@o3r/styling": "^11.1.0-prerelease.
|
|
55
|
+
"@o3r/core": "^11.1.0-prerelease.52",
|
|
56
|
+
"@o3r/schematics": "^11.1.0-prerelease.52",
|
|
57
|
+
"@o3r/styling": "^11.1.0-prerelease.52",
|
|
58
58
|
"chokidar": "^3.5.2",
|
|
59
59
|
"globby": "^11.1.0",
|
|
60
60
|
"sass": "~1.77.0"
|
|
@@ -100,12 +100,12 @@
|
|
|
100
100
|
"@nx/eslint-plugin": "~19.5.0",
|
|
101
101
|
"@nx/jest": "~19.5.0",
|
|
102
102
|
"@nx/js": "~19.5.0",
|
|
103
|
-
"@o3r/build-helpers": "^11.1.0-prerelease.
|
|
104
|
-
"@o3r/core": "^11.1.0-prerelease.
|
|
105
|
-
"@o3r/eslint-plugin": "^11.1.0-prerelease.
|
|
106
|
-
"@o3r/schematics": "^11.1.0-prerelease.
|
|
107
|
-
"@o3r/styling": "^11.1.0-prerelease.
|
|
108
|
-
"@o3r/test-helpers": "^11.1.0-prerelease.
|
|
103
|
+
"@o3r/build-helpers": "^11.1.0-prerelease.52",
|
|
104
|
+
"@o3r/core": "^11.1.0-prerelease.52",
|
|
105
|
+
"@o3r/eslint-plugin": "^11.1.0-prerelease.52",
|
|
106
|
+
"@o3r/schematics": "^11.1.0-prerelease.52",
|
|
107
|
+
"@o3r/styling": "^11.1.0-prerelease.52",
|
|
108
|
+
"@o3r/test-helpers": "^11.1.0-prerelease.52",
|
|
109
109
|
"@schematics/angular": "~18.1.0",
|
|
110
110
|
"@stylistic/eslint-plugin-ts": "~2.4.0",
|
|
111
111
|
"@types/jest": "~29.5.2",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export * from './css/index';
|
|
1
2
|
export * from './design-token-style.renderer';
|
|
2
|
-
export * from './design-token.renderer.interface';
|
|
3
3
|
export * from './design-token-style.renderer';
|
|
4
|
+
export * from './design-token.renderer.interface';
|
|
5
|
+
export * from './json-schema/index';
|
|
4
6
|
export * from './metadata/index';
|
|
5
|
-
export * from './css/index';
|
|
6
7
|
export * from './sass/index';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/design-token/renderers/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/design-token/renderers/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./css/index"), exports);
|
|
4
5
|
tslib_1.__exportStar(require("./design-token-style.renderer"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./design-token.renderer.interface"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./design-token-style.renderer"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./design-token.renderer.interface"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./json-schema/index"), exports);
|
|
7
9
|
tslib_1.__exportStar(require("./metadata/index"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./css/index"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./sass/index"), exports);
|
|
10
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/design-token/renderers/index.ts"],"names":[],"mappings":";;;AAAA,wEAA8C;AAC9C,4EAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/design-token/renderers/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,wEAA8C;AAC9C,wEAA8C;AAC9C,4EAAkD;AAClD,8DAAoC;AACpC,2DAAiC;AACjC,uDAA6B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TokenValueRenderer } from '../../parsers/design-token-parser.interface';
|
|
2
|
+
import type { TokenDefinitionRenderer } from '../design-token.renderer.interface';
|
|
3
|
+
/** Options for {@link getJsonSchemaTokenDefinitionRenderer} */
|
|
4
|
+
export interface JsonSchemaTokenDefinitionRendererOptions {
|
|
5
|
+
/** Custom Design Token value renderer */
|
|
6
|
+
tokenValueRenderer?: TokenValueRenderer;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Retrieve the Design Token Variable renderer for Json Schema
|
|
10
|
+
* @param options
|
|
11
|
+
*/
|
|
12
|
+
export declare const getJsonSchemaTokenDefinitionRenderer: (options?: JsonSchemaTokenDefinitionRendererOptions) => TokenDefinitionRenderer;
|
|
13
|
+
//# sourceMappingURL=design-token-definition.renderers.d.ts.map
|
package/src/core/design-token/renderers/json-schema/design-token-definition.renderers.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design-token-definition.renderers.d.ts","sourceRoot":"","sources":["../../../../../../src/core/design-token/renderers/json-schema/design-token-definition.renderers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgC,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACpH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAGlF,+DAA+D;AAC/D,MAAM,WAAW,wCAAwC;IACvD,yCAAyC;IACzC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED;;;GAGG;AACH,eAAO,MAAM,oCAAoC,aAAc,wCAAwC,KAAG,uBA+BzG,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getJsonSchemaTokenDefinitionRenderer = void 0;
|
|
4
|
+
const design_token_value_renderers_1 = require("./design-token-value.renderers");
|
|
5
|
+
/**
|
|
6
|
+
* Retrieve the Design Token Variable renderer for Json Schema
|
|
7
|
+
* @param options
|
|
8
|
+
*/
|
|
9
|
+
const getJsonSchemaTokenDefinitionRenderer = (options) => {
|
|
10
|
+
const tokenValueRenderer = options?.tokenValueRenderer || (0, design_token_value_renderers_1.getJsonSchemaTokenValueRenderer)();
|
|
11
|
+
const generateNode = (currentVariable, variableValue, ancestors) => {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
[ancestors.map(({ name }) => name).join('.') + (ancestors.length ? '.' : '') + currentVariable.tokenReferenceName.split('.').at(-1)]: JSON.parse(variableValue)
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
...ancestors.length ? [{
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
[ancestors[0].name]: {
|
|
23
|
+
anyOf: generateNode(currentVariable, variableValue, ancestors.slice(1))
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}] : []
|
|
27
|
+
];
|
|
28
|
+
};
|
|
29
|
+
const renderer = (variable, variableSet) => {
|
|
30
|
+
const variableValue = tokenValueRenderer(variable, variableSet);
|
|
31
|
+
const res = {
|
|
32
|
+
anyOf: generateNode(variable, variableValue, variable.ancestors)
|
|
33
|
+
};
|
|
34
|
+
return JSON.stringify(res);
|
|
35
|
+
};
|
|
36
|
+
return renderer;
|
|
37
|
+
};
|
|
38
|
+
exports.getJsonSchemaTokenDefinitionRenderer = getJsonSchemaTokenDefinitionRenderer;
|
|
39
|
+
//# sourceMappingURL=design-token-definition.renderers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design-token-definition.renderers.js","sourceRoot":"","sources":["../../../../../../src/core/design-token/renderers/json-schema/design-token-definition.renderers.ts"],"names":[],"mappings":";;;AAEA,iFAAiF;AAQjF;;;GAGG;AACI,MAAM,oCAAoC,GAAG,CAAC,OAAkD,EAA2B,EAAE;IAClI,MAAM,kBAAkB,GAAG,OAAO,EAAE,kBAAkB,IAAI,IAAA,8DAA+B,GAAE,CAAC;IAE5F,MAAM,YAAY,GAAG,CAAC,eAA6C,EAAE,aAAqB,EAAE,SAA2C,EAAkD,EAAE;QACzL,OAAO;YACL;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,eAAe,CAAC,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;iBAC9J;aACF;YACD,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;oBACrB,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE;4BACnB,KAAK,EAAE,YAAY,CAAC,eAAe,EAAE,aAAa,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;yBACxE;qBACF;iBACF,CAAC,CAAC,CAAC,CAAC,EAAE;SACR,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,CAAC,QAAsC,EAAE,WAAsD,EAAE,EAAE;QAClH,MAAM,aAAa,GAAG,kBAAkB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAEhE,MAAM,GAAG,GAAG;YACV,KAAK,EAAE,YAAY,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,CAAC,SAAS,CAAC;SACjE,CAAC;QACF,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AA/BW,QAAA,oCAAoC,wCA+B/C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DesignContentFileUpdater } from '../design-token.renderer.interface';
|
|
2
|
+
/** Options for {@link getJsonSchemaStyleContentUpdater} */
|
|
3
|
+
export interface JsonSchemaStyleContentUpdaterOptions {
|
|
4
|
+
/** Description to the JSON Schema generated */
|
|
5
|
+
description?: string;
|
|
6
|
+
/** ID of the JSON Schema generated */
|
|
7
|
+
id?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Retrieve a Content Updater function for Metadata generator
|
|
11
|
+
* @param options
|
|
12
|
+
*/
|
|
13
|
+
export declare const getJsonSchemaStyleContentUpdater: (options?: JsonSchemaStyleContentUpdaterOptions) => DesignContentFileUpdater;
|
|
14
|
+
//# sourceMappingURL=design-token-updater.renderers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design-token-updater.renderers.d.ts","sourceRoot":"","sources":["../../../../../../src/core/design-token/renderers/json-schema/design-token-updater.renderers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAEnF,2DAA2D;AAC3D,MAAM,WAAW,oCAAoC;IACnD,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,aAAc,oCAAoC,KAAG,wBAUjG,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getJsonSchemaStyleContentUpdater = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Retrieve a Content Updater function for Metadata generator
|
|
6
|
+
* @param options
|
|
7
|
+
*/
|
|
8
|
+
const getJsonSchemaStyleContentUpdater = (options) => {
|
|
9
|
+
return (variables) => {
|
|
10
|
+
return JSON.stringify({
|
|
11
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
12
|
+
description: options?.description,
|
|
13
|
+
$id: options?.id,
|
|
14
|
+
additionalItems: true,
|
|
15
|
+
...JSON.parse(`{"allOf": [${variables.join(',')}]}`)
|
|
16
|
+
}, null, 2);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
exports.getJsonSchemaStyleContentUpdater = getJsonSchemaStyleContentUpdater;
|
|
20
|
+
//# sourceMappingURL=design-token-updater.renderers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design-token-updater.renderers.js","sourceRoot":"","sources":["../../../../../../src/core/design-token/renderers/json-schema/design-token-updater.renderers.ts"],"names":[],"mappings":";;;AAUA;;;GAGG;AACI,MAAM,gCAAgC,GAAG,CAAC,OAA8C,EAA4B,EAAE;IAC3H,OAAO,CAAC,SAAmB,EAAE,EAAE;QAC7B,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,OAAO,EAAE,yCAAyC;YAClD,WAAW,EAAE,OAAO,EAAE,WAAW;YACjC,GAAG,EAAE,OAAO,EAAE,EAAE;YAChB,eAAe,EAAE,IAAI;YACrB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;SACrD,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACd,CAAC,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,gCAAgC,oCAU3C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TokenValueRenderer } from '../../parsers/design-token-parser.interface';
|
|
2
|
+
/** Options for {@link getJsonSchemaTokenValueRenderer} */
|
|
3
|
+
export interface JsonSchemaTokenValueRendererOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Generate reference URL to the JSON Schema definition
|
|
6
|
+
* @default {@link getJsonSchemaTokenReferenceUrl}
|
|
7
|
+
*/
|
|
8
|
+
referenceUrlRenderer?: (tokenType?: string) => string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Default renderer for the reference URL to the JSON Schema defining the Token Type
|
|
12
|
+
* @param tokenType Type of the Token to refer to
|
|
13
|
+
*/
|
|
14
|
+
export declare const getJsonSchemaTokenReferenceUrl: (tokenType?: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieve the Design Token value renderer
|
|
17
|
+
* @param options
|
|
18
|
+
*/
|
|
19
|
+
export declare const getJsonSchemaTokenValueRenderer: (options?: JsonSchemaTokenValueRendererOptions) => TokenValueRenderer;
|
|
20
|
+
//# sourceMappingURL=design-token-value.renderers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design-token-value.renderers.d.ts","sourceRoot":"","sources":["../../../../../../src/core/design-token/renderers/json-schema/design-token-value.renderers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgC,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AAEpH,0DAA0D;AAC1D,MAAM,WAAW,mCAAmC;IAClD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;CACvD;AAED;;;GAGG;AACH,eAAO,MAAM,8BAA8B,0BAA6B,MAGvE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,+BAA+B,aAAc,mCAAmC,KAAG,kBAqB/F,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getJsonSchemaTokenValueRenderer = exports.getJsonSchemaTokenReferenceUrl = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Default renderer for the reference URL to the JSON Schema defining the Token Type
|
|
6
|
+
* @param tokenType Type of the Token to refer to
|
|
7
|
+
*/
|
|
8
|
+
const getJsonSchemaTokenReferenceUrl = (tokenType = 'implicit') => {
|
|
9
|
+
const capitalTokenType = tokenType.charAt(0).toUpperCase() + tokenType.slice(1);
|
|
10
|
+
return `https://raw.githubusercontent.com/AmadeusITGroup/otter/main/packages/%40o3r/design/schemas/design-token.schema.json#/definitions/tokenType${capitalTokenType}`;
|
|
11
|
+
};
|
|
12
|
+
exports.getJsonSchemaTokenReferenceUrl = getJsonSchemaTokenReferenceUrl;
|
|
13
|
+
/**
|
|
14
|
+
* Retrieve the Design Token value renderer
|
|
15
|
+
* @param options
|
|
16
|
+
*/
|
|
17
|
+
const getJsonSchemaTokenValueRenderer = (options) => {
|
|
18
|
+
const referenceUrl = options?.referenceUrlRenderer || exports.getJsonSchemaTokenReferenceUrl;
|
|
19
|
+
const renderer = (variable, variableSet) => {
|
|
20
|
+
const cssType = variable.getType(variableSet);
|
|
21
|
+
const variableValue = {
|
|
22
|
+
description: variable.description,
|
|
23
|
+
default: variable.node.$value
|
|
24
|
+
};
|
|
25
|
+
if (!cssType) {
|
|
26
|
+
variableValue.$ref = referenceUrl();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
variableValue.oneOf = [
|
|
30
|
+
{ $ref: referenceUrl() },
|
|
31
|
+
{ $ref: referenceUrl(cssType) }
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
return JSON.stringify(variableValue);
|
|
35
|
+
};
|
|
36
|
+
return renderer;
|
|
37
|
+
};
|
|
38
|
+
exports.getJsonSchemaTokenValueRenderer = getJsonSchemaTokenValueRenderer;
|
|
39
|
+
//# sourceMappingURL=design-token-value.renderers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design-token-value.renderers.js","sourceRoot":"","sources":["../../../../../../src/core/design-token/renderers/json-schema/design-token-value.renderers.ts"],"names":[],"mappings":";;;AAWA;;;GAGG;AACI,MAAM,8BAA8B,GAAG,CAAC,SAAS,GAAG,UAAU,EAAU,EAAE;IAC/E,MAAM,gBAAgB,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChF,OAAO,6IAA6I,gBAAgB,EAAE,CAAC;AACzK,CAAC,CAAC;AAHW,QAAA,8BAA8B,kCAGzC;AAEF;;;GAGG;AACI,MAAM,+BAA+B,GAAG,CAAC,OAA6C,EAAsB,EAAE;IACnH,MAAM,YAAY,GAAG,OAAO,EAAE,oBAAoB,IAAI,sCAA8B,CAAC;IAErF,MAAM,QAAQ,GAAG,CAAC,QAAsC,EAAE,WAAsD,EAAE,EAAE;QAClH,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC9C,MAAM,aAAa,GAAQ;YACzB,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;SAC9B,CAAC;QACF,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,aAAa,CAAC,IAAI,GAAG,YAAY,EAAE,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,aAAa,CAAC,KAAK,GAAG;gBACpB,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE;gBACxB,EAAE,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE;aAChC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACvC,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AArBW,QAAA,+BAA+B,mCAqB1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/core/design-token/renderers/json-schema/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./design-token-definition.renderers"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./design-token-value.renderers"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./design-token-updater.renderers"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/core/design-token/renderers/json-schema/index.ts"],"names":[],"mappings":";;;AAAA,8EAAoD;AACpD,yEAA+C;AAC/C,2EAAiD"}
|