Skip to content

Commit

Permalink
Add conversion to w3c standard
Browse files Browse the repository at this point in the history
  • Loading branch information
Anboias committed Jan 5, 2024
1 parent 84b42da commit 583c18a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "Design tokens for the API3 organization",
"scripts": {
"build": "token-transformer --expandTypography tokens/tokens.json tokens/converted-tokens.json && style-dictionary build"
"build": "token-transformer --expandTypography tokens/tokens.json tokens/converted-tokens.json && node transformToW3C.js && style-dictionary build"
},
"devDependencies": {
"style-dictionary": "^3.9.0",
Expand Down
28 changes: 28 additions & 0 deletions transformToW3C.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require("fs");

// Read the original tokens file
fs.readFile("tokens/converted-tokens.json", "utf8", (err, data) => {
if (err) {
console.error("Error reading the file:", err);
return;
}

// As of now, only "value", "type", "category" and "extensions" are prepended with $
const convertedData = data
.replace(/"value":/g, '"$value":')
.replace(/"type":/g, '"$type":')
.replace(/"category":/g, '"$category":')
.replace(/"extensions":/g, '"$extensions":');

fs.writeFile(
"tokens/converted-tokens-w3c.json",
JSON.stringify(JSON.parse(convertedData), null, 2),
(err) => {
if (err) {
console.error("Error writing the file:", err);
return;
}
console.log("Tokens converted and saved to tokens-converted-w3c.json");
}
);
});

0 comments on commit 583c18a

Please sign in to comment.