-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: single CSS file for theme (#2204)
fixes #2202 Converted the CSS file for a single to include all css generated instead of just imports for the individual files.
- Loading branch information
Showing
19 changed files
with
7,683 additions
and
53 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@digdir/designsystemet-theme': patch | ||
'@digdir/designsystemet': patch | ||
--- | ||
|
||
refactor: single CSS file for theme |
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
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,44 @@ | ||
import path from 'node:path'; | ||
import chalk from 'chalk'; | ||
import glob from 'fast-glob'; | ||
import fs from 'fs-extra'; | ||
import * as R from 'ramda'; | ||
|
||
const sortLightmodeFirst = R.sortWith<string>([R.descend(R.includes('light')), R.descend(R.includes('secondary'))]); | ||
|
||
const header = `@charset "UTF-8"; | ||
@layer ds.reset, ds.theme, ds.base, ds.utilities, ds.components; | ||
\n`; | ||
|
||
const sortAndConcat = R.pipe( | ||
sortLightmodeFirst, | ||
R.map((file): string => { | ||
try { | ||
const content = fs.readFileSync(file, 'utf-8').toString(); | ||
return content; | ||
} catch (e) { | ||
console.error(`Error reading file: ${file}`); | ||
return ''; | ||
} | ||
}), | ||
R.join('\n'), | ||
); | ||
|
||
type EntryFile = (options: { | ||
outPath: string; | ||
buildPath: string; | ||
theme: string; | ||
}) => Promise<undefined>; | ||
|
||
/** | ||
* Creates a CSS entry file that imports base CSS files for a theme | ||
*/ | ||
export const makeEntryFile: EntryFile = async ({ outPath, buildPath, theme }) => { | ||
const writePath = `${outPath}/${theme}.css`; | ||
|
||
const files = await glob(`**/*`, { cwd: buildPath }); | ||
const content = header + sortAndConcat(files.map((file) => `${buildPath}/${file}`)); | ||
|
||
await fs.writeFile(writePath, content); | ||
}; |
Oops, something went wrong.