-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
135 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
import fs from 'node:fs'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import fs from "node:fs"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
|
||
// Get the current directory of the script | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
// Read the JSON file | ||
const jsonFile = path.join(__dirname, 'tokens.json'); | ||
const jsonFile = path.join(__dirname, "tokens.json"); | ||
const rawData = fs.readFileSync(jsonFile); | ||
const jsonData = JSON.parse(rawData); | ||
|
||
// Define the base output directory | ||
const baseDir = path.join(__dirname, 'tokens'); | ||
const baseDir = path.join(__dirname, "tokens"); | ||
|
||
// Define keys to exclude | ||
const excludeKeys = ['$themes']; | ||
const excludeKeys = ["$themes"]; | ||
|
||
// Function to write data to file | ||
const writeFile = (filePath, data) => { | ||
const dir = path.dirname(filePath); | ||
fs.mkdirSync(dir, { recursive: true }); | ||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2)); | ||
const dir = path.dirname(filePath); | ||
fs.mkdirSync(dir, { recursive: true }); | ||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2)); | ||
}; | ||
|
||
Object.keys(jsonData).forEach(key => { | ||
// Skip keys that are in the exclude list | ||
if (excludeKeys.includes(key)) { | ||
return; | ||
} | ||
Object.keys(jsonData).forEach((key) => { | ||
// Skip keys that are in the exclude list | ||
if (excludeKeys.includes(key)) { | ||
return; | ||
} | ||
|
||
// Split the key into parts | ||
let keyParts = key.split('/'); | ||
// Split the key into parts | ||
let keyParts = key.split("/"); | ||
|
||
// Remove the first part if there are multiple parts | ||
if (keyParts.length > 1) { | ||
keyParts.shift(); | ||
} | ||
// Remove the first part if there are multiple parts | ||
if (keyParts.length > 1) { | ||
keyParts.shift(); | ||
} | ||
|
||
// Replace spaces in each part with hyphens | ||
keyParts = keyParts.map(part => part.replace(/\s+/g, '-')); | ||
// Replace spaces in each part with hyphens | ||
keyParts = keyParts.map((part) => part.replace(/\s+/g, "-")); | ||
|
||
// Join the remaining parts with '-' and convert to lowercase | ||
const cleanKey = keyParts.join('-').toLowerCase(); | ||
// Join the remaining parts with '-' and convert to lowercase | ||
const cleanKey = keyParts.join("-").toLowerCase(); | ||
|
||
const filePath = path.join(baseDir, `${cleanKey}.json`); | ||
const filePath = path.join(baseDir, `${cleanKey}.json`); | ||
|
||
writeFile(filePath, jsonData[key]); | ||
writeFile(filePath, jsonData[key]); | ||
}); | ||
|
||
console.log('JSON files have been created in the tokens directory.'); | ||
console.log("JSON files have been created in the tokens directory."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
// filters only tokens originating from semantic sets (not core, not excluded) and also check themeable or not | ||
export const semanticFilter = | ||
(excluded, themeable = false) => | ||
(token) => { | ||
const tokenThemable = Boolean(token.attributes.themeable); | ||
return ( | ||
themeable === tokenThemable && | ||
["core", ...excluded].every( | ||
(cat) => !token.filePath.endsWith(`${cat}.json`) | ||
) | ||
); | ||
}; | ||
(excluded, themeable = false) => | ||
(token) => { | ||
const tokenThemable = Boolean(token.attributes.themeable); | ||
return ( | ||
themeable === tokenThemable && | ||
["core", ...excluded].every( | ||
(cat) => !token.filePath.endsWith(`${cat}.json`), | ||
) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import { semanticFilter } from "./filters.js"; | ||
|
||
const commonFileOptions = { | ||
format: "css/variables", | ||
options: { | ||
selector: ":host", | ||
}, | ||
format: "css/variables", | ||
options: { | ||
selector: ":host", | ||
}, | ||
}; | ||
|
||
export const generateSemanticFiles = (excluded, theme) => { | ||
const filesArr = []; | ||
// theme-specific outputs | ||
filesArr.push({ | ||
...commonFileOptions, | ||
filter: semanticFilter(excluded, true), | ||
destination: `product/${theme.toLowerCase().replace(' ', '-')}.css`, | ||
}); | ||
const filesArr = []; | ||
// theme-specific outputs | ||
filesArr.push({ | ||
...commonFileOptions, | ||
filter: semanticFilter(excluded, true), | ||
destination: `product/${theme.toLowerCase().replace(" ", "-")}.css`, | ||
}); | ||
|
||
// not theme-specific outputs | ||
filesArr.push({ | ||
...commonFileOptions, | ||
filter: semanticFilter(excluded, false), | ||
destination: `semantic.css`, | ||
}); | ||
// not theme-specific outputs | ||
filesArr.push({ | ||
...commonFileOptions, | ||
filter: semanticFilter(excluded, false), | ||
destination: `semantic.css`, | ||
}); | ||
|
||
return filesArr; | ||
}; | ||
return filesArr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters