@ama-styling/style-dictionary 13.0.0-next.17 → 13.0.0-next.18
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
CHANGED
@@ -159,7 +159,7 @@ To enhance and facilitate the configuration of the `StyleDictionary` instance, t
|
|
159
159
|
|
160
160
|
The `getTargetFiles` function is used to parameterize the generated file based on Design Token (following the same logic as `$extensions`):
|
161
161
|
|
162
|
-
```
|
162
|
+
```javascript
|
163
163
|
// Example to generate the `color-primary-**` variables in `my-color-primary.css`
|
164
164
|
|
165
165
|
import { getTargetFiles } from '@ama-styling/style-dictionary';
|
@@ -190,6 +190,22 @@ register(sd); // Register all Otter modules
|
|
190
190
|
> The `format` option will be applied to all the files provided to the `getTargetFiles` function (including `defaultFile`).
|
191
191
|
> `defaultFile` defines the default file where variables not matching any rule will be generated.
|
192
192
|
|
193
|
+
The helper function `getTargetFiles` is registering the filter into `StyleDictionary` with a unique ID.\
|
194
|
+
This IDs can be retrieved as follows:
|
195
|
+
|
196
|
+
```javascript
|
197
|
+
import { getTargetFiles } from '@ama-styling/style-dictionary';
|
198
|
+
|
199
|
+
const sd = new StyleDictionary();
|
200
|
+
const files = getTargetFiles({ rules, { styleDictionary: sd } });
|
201
|
+
|
202
|
+
/**
|
203
|
+
* Filter IDs registered in {@link sd} Style Dictionary instance
|
204
|
+
* @type {string[]}
|
205
|
+
**/
|
206
|
+
const filterIds = files.map(({ filter }) => filter);
|
207
|
+
```
|
208
|
+
|
193
209
|
## Advanced
|
194
210
|
|
195
211
|
### Basic Node Configuration Example
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ama-styling/style-dictionary",
|
3
|
-
"version": "13.0.0-next.
|
3
|
+
"version": "13.0.0-next.18",
|
4
4
|
"type": "module",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -41,15 +41,15 @@
|
|
41
41
|
"dependencies": {
|
42
42
|
"@angular-devkit/architect": "~0.2000.0",
|
43
43
|
"@angular-devkit/schematics": "~20.0.0",
|
44
|
-
"@o3r/schematics": "^13.0.0-next.
|
44
|
+
"@o3r/schematics": "^13.0.0-next.18",
|
45
45
|
"@schematics/angular": "~20.0.0",
|
46
46
|
"tslib": "^2.6.2"
|
47
47
|
},
|
48
48
|
"peerDependencies": {
|
49
|
-
"@o3r/core": "^13.0.0-next.
|
50
|
-
"@o3r/schematics": "^13.0.0-next.
|
51
|
-
"@o3r/telemetry": "^13.0.0-next.
|
52
|
-
"style-dictionary": "^
|
49
|
+
"@o3r/core": "^13.0.0-next.18",
|
50
|
+
"@o3r/schematics": "^13.0.0-next.18",
|
51
|
+
"@o3r/telemetry": "^13.0.0-next.18",
|
52
|
+
"style-dictionary": "^5.0.0",
|
53
53
|
"type-fest": "^4.30.1"
|
54
54
|
},
|
55
55
|
"peerDependenciesMeta": {
|
@@ -82,11 +82,11 @@
|
|
82
82
|
"@nx/eslint-plugin": "~21.3.11",
|
83
83
|
"@nx/jest": "~21.3.11",
|
84
84
|
"@nx/js": "~21.3.11",
|
85
|
-
"@o3r/build-helpers": "^13.0.0-next.
|
86
|
-
"@o3r/core": "^13.0.0-next.
|
87
|
-
"@o3r/eslint-plugin": "^13.0.0-next.
|
88
|
-
"@o3r/telemetry": "^13.0.0-next.
|
89
|
-
"@o3r/test-helpers": "^13.0.0-next.
|
85
|
+
"@o3r/build-helpers": "^13.0.0-next.18",
|
86
|
+
"@o3r/core": "^13.0.0-next.18",
|
87
|
+
"@o3r/eslint-plugin": "^13.0.0-next.18",
|
88
|
+
"@o3r/telemetry": "^13.0.0-next.18",
|
89
|
+
"@o3r/test-helpers": "^13.0.0-next.18",
|
90
90
|
"@schematics/angular": "~20.0.0",
|
91
91
|
"@stylistic/eslint-plugin": "~3.1.0",
|
92
92
|
"@types/jest": "~29.5.2",
|
@@ -115,7 +115,7 @@
|
|
115
115
|
"jsonc-eslint-parser": "~2.4.0",
|
116
116
|
"nx": "~21.3.11",
|
117
117
|
"pid-from-port": "^1.1.3",
|
118
|
-
"style-dictionary": "~
|
118
|
+
"style-dictionary": "~5.0.0",
|
119
119
|
"ts-jest": "~29.3.0",
|
120
120
|
"ts-node": "~10.9.2",
|
121
121
|
"type-fest": "^4.30.1",
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import StyleDictionary from 'style-dictionary';
|
1
2
|
import type { File, FormatFn } from 'style-dictionary/types';
|
2
3
|
/** Options to get file filters */
|
3
4
|
interface TargetFileOptions {
|
@@ -7,6 +8,8 @@ interface TargetFileOptions {
|
|
7
8
|
rootPath?: string;
|
8
9
|
/** Default file if not matching any rule */
|
9
10
|
defaultFile?: string;
|
11
|
+
/** styleDictionary instance */
|
12
|
+
styleDictionary?: StyleDictionary;
|
10
13
|
}
|
11
14
|
/** Mapping of the Design Tokens to a given file */
|
12
15
|
export interface FileRuleNode {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"target-file.filter.d.mts","sourceRoot":"","sources":["../../../src/filters/target-file.filter.mts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"target-file.filter.d.mts","sourceRoot":"","sources":["../../../src/filters/target-file.filter.mts"],"names":[],"mappings":"AAOA,OAAO,eAEN,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,IAAI,EACJ,QAAQ,EACT,MAAM,wBAAwB,CAAC;AAQhC,kCAAkC;AAClC,UAAU,iBAAiB;IACzB,mCAAmC;IACnC,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC3B,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+BAA+B;IAC/B,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAC3B,oDAAoD;IACpD,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC;CACvC;AAgBD;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,YAAY,EAAE,UAAU,iBAAiB,KAAG,IAAI,EAwCzF,CAAC"}
|
@@ -1,4 +1,7 @@
|
|
1
|
+
import { randomUUID, } from 'node:crypto';
|
1
2
|
import { normalize, resolve, } from 'node:path';
|
3
|
+
import StyleDictionary from 'style-dictionary';
|
4
|
+
import { OTTER_NAME_PREFIX, } from '../constants.mjs';
|
2
5
|
import { deflatten, } from '../helpers/config-deflatten.helpers.mjs';
|
3
6
|
const getPathMap = (rule, path = [], map = new Map()) => {
|
4
7
|
return Object.entries(rule)
|
@@ -18,27 +21,33 @@ const getPathMap = (rule, path = [], map = new Map()) => {
|
|
18
21
|
* @param options
|
19
22
|
*/
|
20
23
|
export const getTargetFiles = (fileRules, options) => {
|
24
|
+
const styleDictionary = options?.styleDictionary || StyleDictionary;
|
21
25
|
const flatterRules = deflatten(fileRules);
|
22
26
|
const fileMap = getPathMap(flatterRules);
|
23
27
|
const fileMapEntries = [...fileMap.entries()];
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
28
|
+
const files = fileMapEntries
|
29
|
+
.map(([filePath, nodes]) => {
|
30
|
+
const filter = (token) => nodes.some((path) => path.every((item, idx) => token.path[idx] === item));
|
31
|
+
const name = `${OTTER_NAME_PREFIX}/filter/${randomUUID()}`;
|
32
|
+
styleDictionary.registerFilter({ name, filter });
|
33
|
+
return {
|
34
|
+
destination: options?.rootPath ? resolve(options.rootPath, filePath) : filePath,
|
35
|
+
format: options?.format,
|
36
|
+
filter: name
|
37
|
+
};
|
38
|
+
});
|
39
|
+
if (options?.defaultFile) {
|
40
|
+
const filter = (token) => !fileMapEntries
|
41
|
+
.filter(([filePath]) => normalize(filePath) !== normalize(options.defaultFile))
|
42
|
+
.some(([, nodes]) => nodes.some((path) => path.every((item, idx) => token.path[idx] === item)));
|
43
|
+
const name = `${OTTER_NAME_PREFIX}/filter/${randomUUID()}`;
|
44
|
+
styleDictionary.registerFilter({ name, filter });
|
45
|
+
files.push({
|
46
|
+
destination: options.rootPath ? resolve(options.rootPath, options.defaultFile) : options.defaultFile,
|
47
|
+
format: options?.format,
|
48
|
+
filter: name
|
49
|
+
});
|
50
|
+
}
|
51
|
+
return files;
|
43
52
|
};
|
44
53
|
//# sourceMappingURL=target-file.filter.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"target-file.filter.mjs","sourceRoot":"","sources":["../../../src/filters/target-file.filter.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,OAAO,GACR,MAAM,WAAW,CAAC;
|
1
|
+
{"version":3,"file":"target-file.filter.mjs","sourceRoot":"","sources":["../../../src/filters/target-file.filter.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,SAAS,EACT,OAAO,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,eAEN,MAAM,kBAAkB,CAAC;AAK1B,OAAO,EACL,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,SAAS,GACV,MAAM,yCAAyC,CAAC;AAoBjD,MAAM,UAAU,GAAG,CAAC,IAAkB,EAAE,OAAiB,EAAE,EAAE,MAA+B,IAAI,GAAG,EAAE,EAA2B,EAAE;IAChI,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;SACxB,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,aAAa,CAAC;SAC1C,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE;QAC7B,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,CA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