Skip to content

Commit

Permalink
More theme.json variable creation
Browse files Browse the repository at this point in the history
  • Loading branch information
rsefer committed Oct 10, 2023
1 parent 3a27fe9 commit d9c5594
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,26 @@ import { promises } from 'fs';
const buildColors = async () => {
try {
let theme = JSON.parse(await promises.readFile(project.path + '/theme.json'));
let themeFileData = `// This file is automatically generated. Do not edit.\n`;
let themeFileData = `// This file is automatically generated from theme.json. Do not edit.\n`;
if (theme.settings.custom && theme.settings.custom['dirDist']) {
themeFileData += `$themeDirDist: "${theme.settings.custom['dirDist']}";\n`;
}
if (theme.styles?.typography) {
if (theme.styles.typography.fontSize) {
let fontSizeBase = theme.styles.typography.fontSize;
themeFileData += `$font-size-base: ${theme.styles.typography.fontSize}; // --wp--preset--font-size\n`;
if (theme.settings.custom && theme.settings.custom['breakpoints-rem']) {
for (var breakpoint in theme.settings.custom['breakpoints-rem']) {
themeFileData += `$screen-${breakpoint}: ${theme.settings.custom['breakpoints-rem'][breakpoint]}rem;\n`;
themeFileData += `$screen-${breakpoint}-px: ${theme.settings.custom['breakpoints-rem'][breakpoint] * fontSizeBase.replace('px', '')}px;\n`;
}
if (theme.settings.custom['breakpoint-mobile']) {
themeFileData += `$mobile-breakpoint: $screen-${theme.settings.custom['breakpoint-mobile']};\n`;
themeFileData += `$mobile-breakpoint-px: $screen-${theme.settings.custom['breakpoint-mobile']}-px;\n`;
}
}
}
}
if (theme.settings?.typography?.fontFamilies) {
for (var fontFamily of theme.settings.typography.fontFamilies) {
themeFileData += `$${fontFamily['slug']}: ${fontFamily['fontFamily']}; // --wp--preset--font-family--${fontFamily['slug']}\n`;
Expand Down

0 comments on commit d9c5594

Please sign in to comment.