-
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
1 parent
a243b63
commit 0d1dc24
Showing
2 changed files
with
36 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable no-console */ | ||
import fs from 'node:fs'; | ||
import { colors, fonts, spacing } from './index.js'; | ||
|
||
function toCSSVariables(obj: object, prefix = ''): string { | ||
let cssVars = ''; | ||
|
||
// Utilise Object.entries pour itérer uniquement sur les propriétés propres de l'objet | ||
Object.entries(obj).forEach(([key, value]) => { | ||
if (typeof value === 'object' && !Array.isArray(value)) { | ||
// Appel récursif pour les objets imbriqués | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
cssVars += toCSSVariables(value, `${prefix}-${key}`); | ||
} else { | ||
// Formate le nom de la variable CSS | ||
const cssVarName = `${prefix}-${key}`.replaceAll('_', '-').toLowerCase(); | ||
cssVars += ` --${cssVarName}: ${Array.isArray(value) ? value.join(',') : value};\n`; | ||
} | ||
}); | ||
|
||
return cssVars; | ||
} | ||
|
||
function generateCSSFile(variables: object, dist: string) { | ||
const cssVariables = `:root {\n${toCSSVariables(variables, '')}}\n`; | ||
|
||
fs.writeFile(dist, cssVariables, (err) => { | ||
if (err != null) throw err; | ||
console.log(`Le fichier CSS a été généré avec succès : ${dist}`); | ||
}); | ||
} | ||
|
||
generateCSSFile(colors, 'dist/colors.css'); | ||
generateCSSFile(fonts, 'dist/fonts.css'); | ||
generateCSSFile(spacing, 'dist/spacing.css'); |