-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateIndexFile.ts
50 lines (43 loc) · 1.23 KB
/
generateIndexFile.ts
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
import fs from "fs";
import { globSync } from "glob";
import path from "path";
import * as url from "url";
import { WARNING_FILE_HEADER } from "./const.ts";
function genContent(path: string, files: string[]) {
fs.writeFileSync(
path,
`
/**
*
${WARNING_FILE_HEADER}
*/\n\n\n
`,
);
files.forEach((f) => {
const p = f.split("/").pop();
fs.appendFileSync(path, `@import "./${p}";\n`);
});
}
function generatIndexFile() {
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const outputPath = path.resolve(__dirname, "../../style");
const themeFolderPath = `${outputPath}/theme`;
const componentsFolderPath = `${outputPath}/components`;
const theme = globSync(`${themeFolderPath}/*.less`);
const components = globSync(`${componentsFolderPath}/*.less`);
// write theme index.less
genContent(`${themeFolderPath}/index.less`, theme);
// write components index.less
genContent(`${componentsFolderPath}/index.less`, components);
// write index.less
fs.writeFileSync(
`${outputPath}/index.less`,
`
@import "./components/index.less";
@import "./theme/index.less";
@prefix: ezreal;
@ezreal-vars-prefix: ~"--@{prefix}";
`,
);
}
export { generatIndexFile };