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:
parent
f824882e7f
commit
8f1f95c85c
@ -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
32
script/build-css.js
Executable 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)
|
Loading…
Reference in New Issue
Block a user