mirror of
https://github.com/picocss/pico.git
synced 2025-04-20 16:46:14 -04:00
refactor: build theme script
This commit is contained in:
parent
4eee189dab
commit
1a2fc6536c
1 changed files with 40 additions and 10 deletions
|
@ -4,7 +4,6 @@ const fs = require("fs");
|
||||||
|
|
||||||
const themeColors = [
|
const themeColors = [
|
||||||
"amber",
|
"amber",
|
||||||
// "azure",
|
|
||||||
"blue",
|
"blue",
|
||||||
"cyan",
|
"cyan",
|
||||||
"fuchsia",
|
"fuchsia",
|
||||||
|
@ -28,18 +27,29 @@ const themeColors = [
|
||||||
const tempScssFoldername = path.join(__dirname, "../.pico");
|
const tempScssFoldername = path.join(__dirname, "../.pico");
|
||||||
const cssFoldername = path.join(__dirname, "../css");
|
const cssFoldername = path.join(__dirname, "../css");
|
||||||
|
|
||||||
// Ceeate the temp folder if it doesn't exist
|
// Create a folder if it doesn't exist
|
||||||
if (!fs.existsSync(tempScssFoldername)) {
|
const createFolderIfNotExists = (foldername) => {
|
||||||
fs.mkdirSync(tempScssFoldername);
|
if (!fs.existsSync(foldername)) {
|
||||||
}
|
fs.mkdirSync(foldername);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Delete all files in the temp folder
|
// Empty a folder
|
||||||
fs.readdirSync(tempScssFoldername).forEach((file) => {
|
const emptyFolder = (foldername) => {
|
||||||
fs.unlinkSync(path.join(tempScssFoldername, file));
|
// 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
|
// Loop through the theme colors
|
||||||
themeColors.forEach((themeColor) => {
|
themeColors.forEach((themeColor, colorIndex) => {
|
||||||
// All the versions to generate
|
// All the versions to generate
|
||||||
const versions = [
|
const versions = [
|
||||||
{
|
{
|
||||||
|
@ -93,8 +103,21 @@ themeColors.forEach((themeColor) => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
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
|
// Loop through the versions
|
||||||
versions.forEach((version) => {
|
versions.forEach((version) => {
|
||||||
|
displayAsciiProgress({
|
||||||
|
length: themeColors.length,
|
||||||
|
index: colorIndex,
|
||||||
|
color: themeColor.charAt(0).toUpperCase() + themeColor.slice(1),
|
||||||
|
});
|
||||||
|
|
||||||
// Create the file
|
// Create the file
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(tempScssFoldername, `${version.name}.${themeColor}.scss`),
|
path.join(tempScssFoldername, `${version.name}.${themeColor}.scss`),
|
||||||
|
@ -109,5 +132,12 @@ themeColors.forEach((themeColor) => {
|
||||||
|
|
||||||
// Write the file
|
// Write the file
|
||||||
fs.writeFileSync(path.join(cssFoldername, `${version.name}.${themeColor}.min.css`), result.css);
|
fs.writeFileSync(path.join(cssFoldername, `${version.name}.${themeColor}.min.css`), result.css);
|
||||||
|
|
||||||
|
// Clear the console
|
||||||
|
process.stdout.clearLine();
|
||||||
|
process.stdout.cursorTo(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Empty the temp folder
|
||||||
|
emptyFolder(tempScssFoldername);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue