@dsai-io/tools 1.2.5 → 1.3.1
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 +4 -0
- package/dist/cli/index.cjs +268 -101
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +268 -101
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +136 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +136 -86
- package/dist/index.js.map +1 -1
- package/dist/tokens/index.cjs +104 -69
- package/dist/tokens/index.cjs.map +1 -1
- package/dist/tokens/index.d.cts +6 -0
- package/dist/tokens/index.d.ts +6 -0
- package/dist/tokens/index.js +104 -67
- package/dist/tokens/index.js.map +1 -1
- package/package.json +112 -112
package/dist/tokens/index.d.cts
CHANGED
|
@@ -223,6 +223,8 @@ interface BuildOptions {
|
|
|
223
223
|
outputDir?: string;
|
|
224
224
|
/** Output formats to generate (default: ['css', 'scss', 'json']) */
|
|
225
225
|
formats?: Array<'css' | 'scss' | 'js' | 'ts' | 'json' | 'android' | 'ios'>;
|
|
226
|
+
/** CSS custom property prefix (default: '--dsai-') */
|
|
227
|
+
prefix?: string;
|
|
226
228
|
/** Per-format output directories */
|
|
227
229
|
outputDirs?: Partial<Record<string, string>>;
|
|
228
230
|
/** Per-format output file names */
|
|
@@ -1372,6 +1374,8 @@ declare function autoDetectThemes(sourceDir: string, pattern?: string, selectorP
|
|
|
1372
1374
|
interface ThemeBuildConfig {
|
|
1373
1375
|
/** Output formats to generate */
|
|
1374
1376
|
formats: OutputFormat[];
|
|
1377
|
+
/** CSS custom property prefix (e.g., '--dsai-') */
|
|
1378
|
+
prefix?: string;
|
|
1375
1379
|
/** Theme definitions (used by buildAllThemes to lookup theme metadata) */
|
|
1376
1380
|
themes?: {
|
|
1377
1381
|
definitions?: Record<string, ThemeDefinition | ResolvedThemeDefinition>;
|
|
@@ -1421,6 +1425,8 @@ interface ThemeStyleDictionaryConfig {
|
|
|
1421
1425
|
source: string[];
|
|
1422
1426
|
/** Platform configurations */
|
|
1423
1427
|
platforms: Record<string, StyleDictionaryPlatformConfig>;
|
|
1428
|
+
/** Preprocessors to apply before building */
|
|
1429
|
+
preprocessors?: string[];
|
|
1424
1430
|
/** Whether tokens use DTCG format ($value, $type, etc.) */
|
|
1425
1431
|
usesDtcg?: boolean;
|
|
1426
1432
|
/** Logging configuration */
|
package/dist/tokens/index.d.ts
CHANGED
|
@@ -223,6 +223,8 @@ interface BuildOptions {
|
|
|
223
223
|
outputDir?: string;
|
|
224
224
|
/** Output formats to generate (default: ['css', 'scss', 'json']) */
|
|
225
225
|
formats?: Array<'css' | 'scss' | 'js' | 'ts' | 'json' | 'android' | 'ios'>;
|
|
226
|
+
/** CSS custom property prefix (default: '--dsai-') */
|
|
227
|
+
prefix?: string;
|
|
226
228
|
/** Per-format output directories */
|
|
227
229
|
outputDirs?: Partial<Record<string, string>>;
|
|
228
230
|
/** Per-format output file names */
|
|
@@ -1372,6 +1374,8 @@ declare function autoDetectThemes(sourceDir: string, pattern?: string, selectorP
|
|
|
1372
1374
|
interface ThemeBuildConfig {
|
|
1373
1375
|
/** Output formats to generate */
|
|
1374
1376
|
formats: OutputFormat[];
|
|
1377
|
+
/** CSS custom property prefix (e.g., '--dsai-') */
|
|
1378
|
+
prefix?: string;
|
|
1375
1379
|
/** Theme definitions (used by buildAllThemes to lookup theme metadata) */
|
|
1376
1380
|
themes?: {
|
|
1377
1381
|
definitions?: Record<string, ThemeDefinition | ResolvedThemeDefinition>;
|
|
@@ -1421,6 +1425,8 @@ interface ThemeStyleDictionaryConfig {
|
|
|
1421
1425
|
source: string[];
|
|
1422
1426
|
/** Platform configurations */
|
|
1423
1427
|
platforms: Record<string, StyleDictionaryPlatformConfig>;
|
|
1428
|
+
/** Preprocessors to apply before building */
|
|
1429
|
+
preprocessors?: string[];
|
|
1424
1430
|
/** Whether tokens use DTCG format ($value, $type, etc.) */
|
|
1425
1431
|
usesDtcg?: boolean;
|
|
1426
1432
|
/** Logging configuration */
|
package/dist/tokens/index.js
CHANGED
|
@@ -1154,6 +1154,85 @@ var init_groups = __esm({
|
|
|
1154
1154
|
}
|
|
1155
1155
|
});
|
|
1156
1156
|
|
|
1157
|
+
// src/tokens/style-dictionary/preprocessors/fix-references.ts
|
|
1158
|
+
function fixValue(value, mappings) {
|
|
1159
|
+
if (typeof value !== "string" || !value.startsWith("{")) {
|
|
1160
|
+
return value;
|
|
1161
|
+
}
|
|
1162
|
+
let result = value;
|
|
1163
|
+
for (const mapping of mappings) {
|
|
1164
|
+
result = result.split(mapping[0]).join(mapping[1]);
|
|
1165
|
+
}
|
|
1166
|
+
return result;
|
|
1167
|
+
}
|
|
1168
|
+
function processTokens(obj, mappings) {
|
|
1169
|
+
for (const key of Object.keys(obj)) {
|
|
1170
|
+
const value = obj[key];
|
|
1171
|
+
if (value && typeof value === "object") {
|
|
1172
|
+
const typedValue = value;
|
|
1173
|
+
if ("$value" in typedValue) {
|
|
1174
|
+
typedValue["$value"] = fixValue(typedValue["$value"], mappings);
|
|
1175
|
+
} else if ("value" in typedValue) {
|
|
1176
|
+
typedValue["value"] = fixValue(typedValue["value"], mappings);
|
|
1177
|
+
} else {
|
|
1178
|
+
processTokens(typedValue, mappings);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
function createFixReferencesPreprocessor(mappings) {
|
|
1184
|
+
return {
|
|
1185
|
+
name: "fix-references-custom",
|
|
1186
|
+
preprocessor: (dictionary) => {
|
|
1187
|
+
processTokens(dictionary, mappings);
|
|
1188
|
+
return dictionary;
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
var DEFAULT_PATH_MAPPINGS, fixReferences;
|
|
1193
|
+
var init_fix_references = __esm({
|
|
1194
|
+
"src/tokens/style-dictionary/preprocessors/fix-references.ts"() {
|
|
1195
|
+
DEFAULT_PATH_MAPPINGS = [
|
|
1196
|
+
["{colors.brand.", "{color."],
|
|
1197
|
+
["{colors.neutral.", "{neutral."],
|
|
1198
|
+
["{borders.width.", "{border.width."]
|
|
1199
|
+
];
|
|
1200
|
+
fixReferences = {
|
|
1201
|
+
name: "fix-references",
|
|
1202
|
+
preprocessor: (dictionary) => {
|
|
1203
|
+
processTokens(dictionary, DEFAULT_PATH_MAPPINGS);
|
|
1204
|
+
return dictionary;
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
|
|
1210
|
+
// src/tokens/style-dictionary/preprocessors/index.ts
|
|
1211
|
+
var preprocessors_exports = {};
|
|
1212
|
+
__export(preprocessors_exports, {
|
|
1213
|
+
builtInPreprocessors: () => builtInPreprocessors,
|
|
1214
|
+
createFixReferencesPreprocessor: () => createFixReferencesPreprocessor,
|
|
1215
|
+
fixReferences: () => fixReferences,
|
|
1216
|
+
registerPreprocessors: () => registerPreprocessors
|
|
1217
|
+
});
|
|
1218
|
+
function registerPreprocessors(sd, customPreprocessors = []) {
|
|
1219
|
+
const allPreprocessors = [...builtInPreprocessors, ...customPreprocessors];
|
|
1220
|
+
for (const preprocessor of allPreprocessors) {
|
|
1221
|
+
sd.registerPreprocessor({
|
|
1222
|
+
name: preprocessor.name,
|
|
1223
|
+
preprocessor: preprocessor.preprocessor
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
var builtInPreprocessors;
|
|
1228
|
+
var init_preprocessors = __esm({
|
|
1229
|
+
"src/tokens/style-dictionary/preprocessors/index.ts"() {
|
|
1230
|
+
init_fix_references();
|
|
1231
|
+
init_fix_references();
|
|
1232
|
+
builtInPreprocessors = [fixReferences];
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1157
1236
|
// src/tokens/diff.ts
|
|
1158
1237
|
var diff_exports = {};
|
|
1159
1238
|
__export(diff_exports, {
|
|
@@ -4674,7 +4753,7 @@ var FORMAT_MAPPING = /* @__PURE__ */ new Map([
|
|
|
4674
4753
|
["ios", { default: "ios/macros", themed: "ios/macros" }]
|
|
4675
4754
|
]);
|
|
4676
4755
|
var TRANSFORM_GROUPS = /* @__PURE__ */ new Map([
|
|
4677
|
-
["css", "css"],
|
|
4756
|
+
["css", "custom/css"],
|
|
4678
4757
|
["scss", "scss"],
|
|
4679
4758
|
["js", "js-custom"],
|
|
4680
4759
|
// Use custom transform group for valid JS identifiers
|
|
@@ -4691,7 +4770,13 @@ function generateThemeBuildConfig(options) {
|
|
|
4691
4770
|
const platformsMap = /* @__PURE__ */ new Map();
|
|
4692
4771
|
const enabledFormats = config.formats;
|
|
4693
4772
|
for (const format of enabledFormats) {
|
|
4694
|
-
const platformConfig = generatePlatformConfig(
|
|
4773
|
+
const platformConfig = generatePlatformConfig(
|
|
4774
|
+
format,
|
|
4775
|
+
themeDefinition,
|
|
4776
|
+
outputDir,
|
|
4777
|
+
isDefault,
|
|
4778
|
+
config.prefix
|
|
4779
|
+
);
|
|
4695
4780
|
if (platformConfig) {
|
|
4696
4781
|
platformsMap.set(format, platformConfig);
|
|
4697
4782
|
}
|
|
@@ -4700,6 +4785,7 @@ function generateThemeBuildConfig(options) {
|
|
|
4700
4785
|
return {
|
|
4701
4786
|
source: files,
|
|
4702
4787
|
platforms,
|
|
4788
|
+
preprocessors: ["fix-references"],
|
|
4703
4789
|
// Enable DTCG format support (tokens with $value, $type, etc.)
|
|
4704
4790
|
usesDtcg: true,
|
|
4705
4791
|
// Configure logging to not throw on broken references (they'll be logged but build continues)
|
|
@@ -4712,7 +4798,7 @@ function generateThemeBuildConfig(options) {
|
|
|
4712
4798
|
}
|
|
4713
4799
|
};
|
|
4714
4800
|
}
|
|
4715
|
-
function generatePlatformConfig(format, themeDefinition, outputDir, isDefault) {
|
|
4801
|
+
function generatePlatformConfig(format, themeDefinition, outputDir, isDefault, prefix) {
|
|
4716
4802
|
const formatConfig = FORMAT_MAPPING.get(format);
|
|
4717
4803
|
if (!formatConfig) {
|
|
4718
4804
|
console.warn(`Unknown format: ${format}`);
|
|
@@ -4727,8 +4813,15 @@ function generatePlatformConfig(format, themeDefinition, outputDir, isDefault) {
|
|
|
4727
4813
|
destination: outputFile,
|
|
4728
4814
|
format: sdFormat
|
|
4729
4815
|
};
|
|
4816
|
+
if (prefix && (format === "css" || format === "scss")) {
|
|
4817
|
+
fileConfig.options = {
|
|
4818
|
+
...fileConfig.options,
|
|
4819
|
+
prefix
|
|
4820
|
+
};
|
|
4821
|
+
}
|
|
4730
4822
|
if (format === "css" && !isDefault) {
|
|
4731
4823
|
fileConfig.options = {
|
|
4824
|
+
...fileConfig.options,
|
|
4732
4825
|
selector: themeDefinition.selector
|
|
4733
4826
|
};
|
|
4734
4827
|
}
|
|
@@ -4841,6 +4934,8 @@ async function runStyleDictionaryBuild(sdConfig, options) {
|
|
|
4841
4934
|
registerCustomTransforms(StyleDictionary);
|
|
4842
4935
|
const { registerTransformGroups: registerTransformGroups2 } = await Promise.resolve().then(() => (init_groups(), groups_exports));
|
|
4843
4936
|
registerTransformGroups2(StyleDictionary);
|
|
4937
|
+
const { registerPreprocessors: registerPreprocessors2 } = await Promise.resolve().then(() => (init_preprocessors(), preprocessors_exports));
|
|
4938
|
+
registerPreprocessors2(StyleDictionary);
|
|
4844
4939
|
if (options.verbose) {
|
|
4845
4940
|
console.warn(` \u{1F527} Style Dictionary platforms:`);
|
|
4846
4941
|
for (const [platform, config] of Object.entries(sdConfig.platforms)) {
|
|
@@ -5294,7 +5389,7 @@ var STEP_DISPLAY_NAMES = /* @__PURE__ */ new Map([
|
|
|
5294
5389
|
["sass-utilities-minified", "Compile DSAi Utilities (minified)"],
|
|
5295
5390
|
["bundle", "Bundle with tsup"]
|
|
5296
5391
|
]);
|
|
5297
|
-
function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensDir, paths, sdConfigFile, strict, snapshotService, themesConfig, outputDir, formats = ["css", "scss", "json"], cssOutputDir, postprocessConfig) {
|
|
5392
|
+
function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensDir, paths, sdConfigFile, strict, snapshotService, themesConfig, outputDir, formats = ["css", "scss", "json"], cssOutputDir, postprocessConfig, prefix) {
|
|
5298
5393
|
const displayName = STEP_DISPLAY_NAMES.get(stepName) ?? `Unknown: ${stepName}`;
|
|
5299
5394
|
switch (stepName) {
|
|
5300
5395
|
case "validate":
|
|
@@ -5499,6 +5594,7 @@ function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensD
|
|
|
5499
5594
|
const result = await buildAllThemes({
|
|
5500
5595
|
config: {
|
|
5501
5596
|
formats,
|
|
5597
|
+
prefix,
|
|
5502
5598
|
themes: {
|
|
5503
5599
|
definitions: themeDefinitions
|
|
5504
5600
|
}
|
|
@@ -5614,7 +5710,8 @@ function createBuildSteps(tokensDir, _toolsDir, options, pipeline) {
|
|
|
5614
5710
|
options.outputDir,
|
|
5615
5711
|
formats,
|
|
5616
5712
|
options.cssOutputDir,
|
|
5617
|
-
options.postprocessConfig
|
|
5713
|
+
options.postprocessConfig,
|
|
5714
|
+
options.prefix
|
|
5618
5715
|
);
|
|
5619
5716
|
if (stepName === "validate" && skipValidate) {
|
|
5620
5717
|
step.skip = true;
|
|
@@ -6889,68 +6986,7 @@ function getSDTokenType(token) {
|
|
|
6889
6986
|
// src/tokens/style-dictionary/config.ts
|
|
6890
6987
|
init_formats();
|
|
6891
6988
|
init_groups();
|
|
6892
|
-
|
|
6893
|
-
// src/tokens/style-dictionary/preprocessors/fix-references.ts
|
|
6894
|
-
var DEFAULT_PATH_MAPPINGS = [
|
|
6895
|
-
["{colors.brand.", "{color."],
|
|
6896
|
-
["{colors.neutral.", "{neutral."],
|
|
6897
|
-
["{borders.width.", "{border.width."]
|
|
6898
|
-
];
|
|
6899
|
-
function fixValue(value, mappings) {
|
|
6900
|
-
if (typeof value !== "string" || !value.startsWith("{")) {
|
|
6901
|
-
return value;
|
|
6902
|
-
}
|
|
6903
|
-
let result = value;
|
|
6904
|
-
for (const mapping of mappings) {
|
|
6905
|
-
result = result.split(mapping[0]).join(mapping[1]);
|
|
6906
|
-
}
|
|
6907
|
-
return result;
|
|
6908
|
-
}
|
|
6909
|
-
function processTokens(obj, mappings) {
|
|
6910
|
-
for (const key of Object.keys(obj)) {
|
|
6911
|
-
const value = obj[key];
|
|
6912
|
-
if (value && typeof value === "object") {
|
|
6913
|
-
const typedValue = value;
|
|
6914
|
-
if ("$value" in typedValue) {
|
|
6915
|
-
typedValue["$value"] = fixValue(typedValue["$value"], mappings);
|
|
6916
|
-
} else if ("value" in typedValue) {
|
|
6917
|
-
typedValue["value"] = fixValue(typedValue["value"], mappings);
|
|
6918
|
-
} else {
|
|
6919
|
-
processTokens(typedValue, mappings);
|
|
6920
|
-
}
|
|
6921
|
-
}
|
|
6922
|
-
}
|
|
6923
|
-
}
|
|
6924
|
-
var fixReferences = {
|
|
6925
|
-
name: "fix-references",
|
|
6926
|
-
preprocessor: (dictionary) => {
|
|
6927
|
-
processTokens(dictionary, DEFAULT_PATH_MAPPINGS);
|
|
6928
|
-
return dictionary;
|
|
6929
|
-
}
|
|
6930
|
-
};
|
|
6931
|
-
function createFixReferencesPreprocessor(mappings) {
|
|
6932
|
-
return {
|
|
6933
|
-
name: "fix-references-custom",
|
|
6934
|
-
preprocessor: (dictionary) => {
|
|
6935
|
-
processTokens(dictionary, mappings);
|
|
6936
|
-
return dictionary;
|
|
6937
|
-
}
|
|
6938
|
-
};
|
|
6939
|
-
}
|
|
6940
|
-
|
|
6941
|
-
// src/tokens/style-dictionary/preprocessors/index.ts
|
|
6942
|
-
var builtInPreprocessors = [fixReferences];
|
|
6943
|
-
function registerPreprocessors(sd, customPreprocessors = []) {
|
|
6944
|
-
const allPreprocessors = [...builtInPreprocessors, ...customPreprocessors];
|
|
6945
|
-
for (const preprocessor of allPreprocessors) {
|
|
6946
|
-
sd.registerPreprocessor({
|
|
6947
|
-
name: preprocessor.name,
|
|
6948
|
-
preprocessor: preprocessor.preprocessor
|
|
6949
|
-
});
|
|
6950
|
-
}
|
|
6951
|
-
}
|
|
6952
|
-
|
|
6953
|
-
// src/tokens/style-dictionary/config.ts
|
|
6989
|
+
init_preprocessors();
|
|
6954
6990
|
init_transforms();
|
|
6955
6991
|
var DEFAULT_SOURCE_PATTERNS = [
|
|
6956
6992
|
"collections/color/*.json",
|
|
@@ -7105,6 +7141,7 @@ function setupStyleDictionary(sd, dsaiConfig, options = {}) {
|
|
|
7105
7141
|
// src/tokens/style-dictionary/index.ts
|
|
7106
7142
|
init_transforms();
|
|
7107
7143
|
init_formats();
|
|
7144
|
+
init_preprocessors();
|
|
7108
7145
|
init_groups();
|
|
7109
7146
|
|
|
7110
7147
|
// src/tokens/framework-mappers/index.ts
|