-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuildCss.mjs
51 lines (46 loc) · 1.3 KB
/
buildCss.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Copyright 2022 Adobe
All Rights Reserved.
NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it.
*/
import tailwind from "tailwindcss";
import postcss from "postcss";
import * as fs from "fs/promises";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
import tailwindConfig from "./tailwind.config.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const generateTailwindCss = async (contentRaw) => {
return (
await postcss([
tailwind({
...tailwindConfig,
content: [{ raw: contentRaw }],
}),
]).process(
`${
contentRaw ? "" : "@tailwind base;"
}@tailwind components;@tailwind utilities;`,
{
from: undefined,
}
)
).css;
};
(async () => {
const buildFile = join(__dirname, "dist", "build.css");
try {
await fs.unlink(buildFile);
} catch (err) {}
const outputStream = (await fs.open(buildFile, "a")).createWriteStream();
const files = await fs.readdir(join(__dirname, "src"));
for (const file of files) {
const fileText = (
await fs.readFile(join(__dirname, "src", file))
).toString();
outputStream.write(await generateTailwindCss(fileText));
}
})();