forked from Yohn/PicoCSS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-dev.js
146 lines (132 loc) · 3.43 KB
/
build-dev.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const sass = require("sass");
const path = require("path");
const fs = require("fs");
const themeColors = [
//? uncomment 1 theme you'd like to build for the dev environment.
//"amber",
//"blue",
//"cyan",
//"fuchsia",
//"green",
//"grey",
//"indigo",
"indigo",
//"lime",
//"orange",
//"pink",
//"pumpkin",
//"purple",
//"red",
//"sand",
//"slate",
//"violet",
//"yellow",
//"zinc",
];
const tempScssFoldername = path.join(__dirname, "../.pico");
const cssFoldername = path.join(__dirname, "../css");
// Create a folder if it doesn't exist
const createFolderIfNotExists = (foldername) => {
if (!fs.existsSync(foldername)) {
fs.mkdirSync(foldername);
}
};
// Empty a folder
const emptyFolder = (foldername) => {
// Delete all files in the temp folder
fs.readdirSync(foldername).forEach((file) => {
fs.unlinkSync(path.join(foldername, file));
});
};
// Create the temp folder if it doesn't exist
createFolderIfNotExists(tempScssFoldername);
// Empty the temp folder
emptyFolder(tempScssFoldername);
// Loop through the theme colors
themeColors.forEach((themeColor, colorIndex) => {
// All the versions to generate
const versions = [
{
name: "pico",
content: `@use "../scss" with (
$theme-color: "${themeColor}"
);`,
},
//{
// name: "pico.classless",
// content: `@use "../scss" with (
// $theme-color: "${themeColor}",
// $enable-semantic-container: true,
// $enable-classes: false
// );`,
//},
//{
// name: "pico.fluid.classless",
// content: `@use "../scss" with (
// $theme-color: "${themeColor}",
// $enable-semantic-container: true,
// $enable-viewport: false,
// $enable-classes: false
// );`,
//},
//{
// name: "pico.conditional",
// content: `@use "../scss" with (
// $theme-color: "${themeColor}",
// $parent-selector: ".pico"
// );`,
//},
//{
// name: "pico.classless.conditional",
// content: `@use "../scss" with (
// $theme-color: "${themeColor}",
// $enable-semantic-container: true,
// $enable-classes: false,
// $parent-selector: ".pico"
// );`,
//},
//{
// name: "pico.fluid.classless.conditional",
// content: `@use "../scss" with (
// $theme-color: "${themeColor}",
// $enable-semantic-container: true,
// $enable-viewport: false,
// $enable-classes: false,
// $parent-selector: ".pico"
// );`,
//},
];
const displayAsciiProgress = ({length, index, color}) => {
const progress = Math.round((index / length) * 100);
const bar = "■".repeat(progress / 10);
const empty = "□".repeat(10 - progress / 10);
process.stdout.write(`[@picocss/pico] ✨ ${bar}${empty} ${color}\r`);
};
// Loop through the versions
versions.forEach((version) => {
displayAsciiProgress({
length: themeColors.length,
index: colorIndex,
color: themeColor.charAt(0).toUpperCase() + themeColor.slice(1),
});
// Create the file
fs.writeFileSync(
path.join(tempScssFoldername, `${version.name}.${themeColor}.scss`),
version.content,
);
// Compile the file
const result = sass.compile(
path.join(tempScssFoldername, `${version.name}.${themeColor}.scss`),
{ outputStyle: "compressed" },
);
// Write the file
fs.writeFileSync(path.join(cssFoldername, `${version.name}.${themeColor}.css`), result.css);
// Clear the console - only if running in a TTY
if (process.stdout.isTTY) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
}
});
});
// Empty the temp folder
emptyFolder(tempScssFoldername);