Sha256: e6cb9bc3a028c035e5ef9bbbdb8832768b8a36914785d6ab987336fa095e33a2
Contents?: true
Size: 1.68 KB
Versions: 6
Compression:
Stored size: 1.68 KB
Contents
import { expandGlob } from 'std/fs/mod.ts' import postcss from 'postcss' export default async (root, path) => { let tmpFile let contents const mixinFiles = [] for await (const file of expandGlob('lib/**/*.mixin.css', { root, globstar: true })) { mixinFiles.push(file.path) } // Only process mixins with PostCSS if there are any 'lib/**/*.mixin.css' files. if (mixinFiles.length > 0) { tmpFile = await Deno.makeTempFile() contents = await Deno.readTextFile(path) const result = await postcss([mixinsPlugin({ mixinFiles })]).process(contents, { from: path }) contents = result.css } return [tmpFile, contents] } const mixinsPlugin = (opts = {}) => { return { postcssPlugin: 'mixins', prepare() { const mixins = {} return { async Once(_, helpers) { for (const path of opts.mixinFiles) { const content = await Deno.readTextFile(path) const root = helpers.parse(content, { from: path }) root.walkAtRules('define-mixin', atrule => { mixins[atrule.params] = atrule }) } }, AtRule: { mixin: (rule, helpers) => { const mixin = mixins[rule.params] if (!mixin) { throw rule.error(`Undefined mixin '${rule.params}'`) } const proxy = new helpers.Root() for (let i = 0; i < mixin.nodes.length; i++) { const node = mixin.nodes[i].clone() delete node.raws.before proxy.append(node) } rule.parent.insertBefore(rule, proxy) if (rule.parent) rule.remove() } } } } } }
Version data entries
6 entries across 6 versions & 1 rubygems