1
1
mirror of https://github.com/primer/css.git synced 2024-08-17 12:10:33 +03:00

Adding build-css script for watching in dev mode

This commit is contained in:
Jon Rohan 2022-08-12 21:52:28 +00:00
parent f824882e7f
commit 8f1f95c85c
2 changed files with 33 additions and 1 deletions

View File

@ -26,7 +26,7 @@
"build:docs": "script/build-docs",
"build:docs:preview": "script/build-docs preview",
"dist": "script/dist.js",
"dist:watch": "chokidar \"src/**/*.scss\" -c \"script/dist.js\"",
"dist:watch": "chokidar \"src/**/*.scss\" -c \"script/build-css.js\"",
"stylelint": "stylelint --quiet --rd 'src/**/*.scss'",
"stylelint:fix": "yarn stylelint -- --fix",
"stylelint:remove-disables": "script/stylelint-remove-disables.js 'src/**/*.scss'",

32
script/build-css.js Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env node
import {globby} from 'globby'
import compiler from './primer-css-compiler.js'
import {dirname, join} from 'path'
import fsExtra from 'fs-extra'
const {mkdirp, readFile, writeFile} = fsExtra
const inDir = 'src'
const outDir = 'dist'
const bundleNames = {
'index.scss': 'primer'
}
const files = await globby([`${inDir}/**/index.scss`])
await mkdirp(outDir)
const inPattern = new RegExp(`^${inDir}/`)
const tasks = files.map(async from => {
const path = from.replace(inPattern, '')
const name = bundleNames[path] || dirname(path).replace(/\//g, '-')
const to = join(outDir, `${name}.css`)
const result = await compiler(await readFile(from, 'utf8'), {from, to})
await Promise.all([
writeFile(to, result.css, 'utf8'),
])
})
await Promise.all(tasks)