-
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
8 changed files
with
101 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
"@kevintyj/color": minor | ||
--- | ||
|
||
Generate CSS variable files | ||
Generate CSS exports |
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,5 @@ | ||
--- | ||
"@kevintyj/color": minor | ||
--- | ||
|
||
Generate SCSS exports |
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,5 @@ | ||
--- | ||
"@kevintyj/color": patch | ||
--- | ||
|
||
Add BaseColors (white/black) to colorset |
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,6 +1,7 @@ | ||
# dist | ||
/dist | ||
/css | ||
/scss | ||
|
||
# dependencies | ||
/node_modules | ||
|
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
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,83 @@ | ||
/// <reference path="../types/color.d.ts" /> | ||
import * as fs from 'node:fs'; | ||
import * as lightColors from '../src/light'; | ||
import * as darkColors from '../src/dark'; | ||
import { BaseBackground, BaseColors } from '../src'; | ||
import { camelToKebabCase, writeFile } from './utils'; | ||
|
||
const OUT_DIR = './scss'; | ||
const colorVariableBuilder = (colorScale: ColorScale<HexColor>, colorName: string) => { | ||
const variableEntries: string[] = []; | ||
|
||
const colorScaleName = camelToKebabCase(colorName); | ||
|
||
Object.entries(colorScale) | ||
.forEach(([colorScaleID, colorScaleValue]) => { | ||
variableEntries.push( | ||
`$${colorScaleName}-${colorScaleID}: ${colorScaleValue};`, | ||
); | ||
}); | ||
|
||
return variableEntries; | ||
}; | ||
const CSSVarBuilder = (colorType: 'light' | 'dark') => { | ||
const colorScale = colorType === 'light' | ||
? lightColors | ||
: darkColors; | ||
|
||
Object.entries(colorScale).forEach(([colorName, colorScale]) => { | ||
const cssVariableEntries: string[] = colorVariableBuilder(colorScale, colorName); | ||
const comment = `// ${colorName.toUpperCase()} Color Variables`; | ||
const cssVariableString = `${comment}\n${cssVariableEntries.join('\n')}\n`; | ||
writeFile(OUT_DIR, `_${colorName}.scss`, cssVariableString); | ||
}); | ||
}; | ||
|
||
const baseColorCSSBuilder = () => { | ||
const baseColorEntries: string[] = []; | ||
|
||
Object.entries(BaseColors).forEach(([colorName, colorValue]) => { | ||
baseColorEntries.push(`$${camelToKebabCase(colorName)}: ${colorValue};`); | ||
}); | ||
|
||
const COMMENT = `// BASE Color Variables`; | ||
|
||
const baseColorString = `${COMMENT} \n${baseColorEntries.join('\n')}\n`; | ||
const baseLightBackground = `$background: ${BaseBackground.light};\n`; | ||
const baseDarkBackground = `$background-dark: ${BaseBackground.dark};\n`; | ||
|
||
writeFile(OUT_DIR, 'base.scss', `${baseColorString}\n${baseLightBackground}\n${baseDarkBackground}`); | ||
}; | ||
|
||
const rootCSSBuilder = (colorType: 'light' | 'dark') => { | ||
const colorScale = colorType === 'light' ? lightColors : darkColors; | ||
const cssImports: string[] = []; | ||
Object.keys(colorScale).forEach((colorName) => { | ||
cssImports.push(`@import './${colorName}';`); | ||
}); | ||
writeFile(OUT_DIR, `${colorType}.scss`, cssImports.join('\n')); | ||
}; | ||
|
||
const run = () => { | ||
fs.mkdir(OUT_DIR, (err) => { | ||
if (err) { | ||
if (err.code !== 'EEXIST') | ||
console.error(err); | ||
} | ||
}); | ||
CSSVarBuilder('light'); | ||
CSSVarBuilder('dark'); | ||
rootCSSBuilder('light'); | ||
rootCSSBuilder('dark'); | ||
baseColorCSSBuilder(); | ||
writeFile( | ||
OUT_DIR, | ||
'colors.scss', | ||
`/* @kevintyj/color/scss */ | ||
@import "./light"; | ||
@import "./dark"; | ||
@import "./base";`, | ||
); | ||
}; | ||
|
||
run(); |
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