forked from algolia/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildCss.mjs
43 lines (31 loc) · 993 Bytes
/
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
import fs from 'fs';
import path from 'path';
import util from 'util';
import postcss from 'postcss';
import postCssConfig from '../postcss.config.mjs';
import { getBundleBanner } from './getBundleBanner.mjs';
const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
const mkdir = util.promisify(fs.mkdir);
const { plugins, ...cssConfig } = postCssConfig;
async function ensureDir(file) {
const directory = path.dirname(file);
if (!fs.existsSync(directory)) {
await mkdir(directory);
}
}
async function buildCss() {
const [, , input, output] = process.argv;
await ensureDir(output);
const css = await readFile(input);
const result = await postcss(plugins).process(css, {
...cssConfig,
from: input,
to: output,
});
const banner = getBundleBanner(
JSON.parse(await readFile(path.join(process.cwd(), 'package.json')))
);
await writeFile(output, [banner, result.css].join('\n'), () => true);
}
buildCss();