-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Refactor styles and themes build pipeline (#1390)
Cherry-picked from #1374
- Loading branch information
1 parent
794ee5f
commit c5d25a7
Showing
4 changed files
with
116 additions
and
94 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,65 +1,3 @@ | ||
import { mkdirSync as makeDir } from 'node:fs'; | ||
import { writeFile } from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { globby } from 'globby'; | ||
import * as sass from 'sass-embedded'; | ||
import report from './report.mjs'; | ||
import { compileSass, fromTemplate } from './sass.mjs'; | ||
import { buildComponents, buildThemes } from './sass.mjs'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const DEST_DIR = path.join.bind(null, path.resolve(__dirname, '../dist')); | ||
|
||
export async function buildThemes() { | ||
const compiler = await sass.initAsyncCompiler(); | ||
const paths = await globby('src/styles/themes/{light,dark}/*.scss'); | ||
|
||
for (const sassFile of paths) { | ||
const css = await compileSass(sassFile, compiler); | ||
|
||
const outputFile = DEST_DIR( | ||
sassFile.replace(/\.scss$/, '.css').replace('src/styles/', '') | ||
); | ||
makeDir(path.dirname(outputFile), { recursive: true }); | ||
await writeFile(outputFile, css, 'utf-8'); | ||
} | ||
|
||
await compiler.dispose(); | ||
} | ||
|
||
(async () => { | ||
const compiler = await sass.initAsyncCompiler(); | ||
const start = performance.now(); | ||
|
||
const paths = await globby([ | ||
'src/components/**/*.base.scss', | ||
'src/components/**/*.common.scss', | ||
'src/components/**/*.shared.scss', | ||
'src/components/**/*.material.scss', | ||
'src/components/**/*.bootstrap.scss', | ||
'src/components/**/*.indigo.scss', | ||
'src/components/**/*.fluent.scss', | ||
]); | ||
|
||
try { | ||
await Promise.all( | ||
paths.map(async (path) => { | ||
writeFile( | ||
path.replace(/\.scss$/, '.css.ts'), | ||
fromTemplate(await compileSass(path, compiler)), | ||
'utf8' | ||
); | ||
}) | ||
); | ||
} catch (err) { | ||
await compiler.dispose(); | ||
report.error(err); | ||
process.exit(1); | ||
} | ||
|
||
await compiler.dispose(); | ||
|
||
report.success( | ||
`Styles generated in ${((performance.now() - start) / 1000).toFixed(2)}s` | ||
); | ||
})(); | ||
await Promise.all([buildThemes(), buildComponents()]); |
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