-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathstyle-dictionary.config.js
More file actions
166 lines (160 loc) · 4.9 KB
/
style-dictionary.config.js
File metadata and controls
166 lines (160 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*!
* Copyright 2024 Adobe. All rights reserved.
*
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import { dirname, join, sep } from "path";
import StyleDictionary from "style-dictionary";
import {
AttributeSetsTransform,
CSSOpenTypeTransform,
CSSSetsFormatter,
DataJsonFormatter,
NameKebabTransfom,
} from "./utilities/index.js";
StyleDictionary.registerTransform(CSSOpenTypeTransform);
StyleDictionary.registerTransform(NameKebabTransfom);
StyleDictionary.registerTransform(AttributeSetsTransform);
StyleDictionary.registerFormat(CSSSetsFormatter);
StyleDictionary.registerFormat(DataJsonFormatter);
/**
* @note This references the package.json because we want the root folder and
* not a nested folder which might be returned if the `main` property
* in the package.json is present.
*/
const tokensPath = import.meta.resolve("@adobe/spectrum-tokens/package.json")?.replace(/file:\/\//, "");
const tokensDir = dirname(tokensPath);
export default {
source: [join(tokensDir, "src", "*.json")],
hooks: {
transforms: {
[AttributeSetsTransform.name]: AttributeSetsTransform,
[NameKebabTransfom.name]: NameKebabTransfom,
[CSSOpenTypeTransform.name]: CSSOpenTypeTransform,
},
},
platforms: {
css: {
buildPath: join("dist", "css") + sep,
transforms: [
AttributeSetsTransform.name,
NameKebabTransfom.name,
CSSOpenTypeTransform.name,
],
prefix: "spectrum",
files: [
{
format: "css/sets",
options: { showFileHeader: false, outputReferences: true },
destination: "global-vars.css",
filter: (token) => {
const tokenSets = token.path.filter((_, idx, array) => array[idx - 1] == "sets");
if (tokenSets.includes("wireframe")) return false;
if (tokenSets.length === 0) return true;
return false;
},
},
{
format: "css/sets",
options: {
showFileHeader: false,
outputReferences: true,
selector: ".spectrum--medium",
sets: ["desktop"],
},
destination: "medium-vars.css",
filter: (token) => {
const tokenSets = token.path.filter((_, idx, array) => array[idx - 1] == "sets");
if (tokenSets.includes("wireframe")) return false;
if (!tokenSets.includes("desktop")) return false;
if (tokenSets.length === 1) return true;
return false;
},
},
{
format: "css/sets",
options: {
showFileHeader: false,
outputReferences: true,
selector: ".spectrum--large",
sets: ["mobile"],
},
destination: "large-vars.css",
filter: (token) => {
// Fetch the sets for this token
const tokenSets = token.path.filter((_, idx, array) => array[idx - 1] == "sets");
if (tokenSets.includes("wireframe")) return false;
if (!tokenSets.includes("mobile")) return false;
if (tokenSets.length === 1) return true;
return false;
},
},
{
format: "css/sets",
options: {
showFileHeader: false,
outputReferences: true,
selector: ".spectrum--light",
sets: ["light"],
},
destination: "light-vars.css",
filter: (token) => {
const tokenSets = token.path.filter((_, idx, array) => array[idx - 1] == "sets");
if (tokenSets.includes("wireframe")) return false;
if (!tokenSets.includes("light")) return false;
if (tokenSets.length === 1) return true;
return false;
},
},
{
format: "css/sets",
options: {
showFileHeader: false,
outputReferences: true,
selector: ".spectrum--dark",
sets: ["dark"],
},
destination: "dark-vars.css",
filter: (token) => {
const tokenSets = token.path.filter((_, idx, array) => array[idx - 1] == "sets");
if (tokenSets.includes("wireframe")) return false;
if (!tokenSets.includes("dark")) return false;
if (tokenSets.length === 1) return true;
return false;
},
},
],
},
JSON: {
buildPath: join("dist", "json") + sep,
transforms: [
AttributeSetsTransform.name,
NameKebabTransfom.name,
CSSOpenTypeTransform.name,
],
prefix: "spectrum",
files: [
{
format: "json/sets",
destination: "tokens.json",
filter: (token) => {
const tokenSets = token.path.filter((_, idx, array) => array[idx - 1] == "sets");
if (tokenSets.includes("wireframe")) return false;
return true;
},
options: {
showFileHeader: false,
outputReferences: true,
},
},
],
},
},
};