feat: add custom.css support

closes #433
This commit is contained in:
Mathias Schopmans
2024-03-14 14:21:32 +01:00
parent f94c94ffd8
commit 1a7ea3527f
8 changed files with 74 additions and 20 deletions

View File

@@ -17,7 +17,7 @@ function info(message) {
}
function warn(message) {
console.warn(`Warning: ${message}`);
console.log(`\x1b[33mWarning: ${message}\x1b[0m`);
}
function error(message) {
@@ -30,20 +30,16 @@ function bootstrap() {
warn(
"Could not find radar directory. Created a bootstrap radar directory in your current working directory. Feel free to customize it.",
);
fs.cpSync(
path.join(BUILDER_DIR, "data", "radar"),
path.join(CWD, "radar"),
{
recursive: true,
},
);
fs.cpSync(path.join(SOURCE_DIR, "data", "radar"), path.join(CWD, "radar"), {
recursive: true,
});
}
if (!fs.existsSync(path.join(CWD, "public"))) {
warn(
"Could not find public directory. Created a public radar directory in your current working directory.",
);
fs.cpSync(path.join(BUILDER_DIR, "public"), path.join(CWD, "public"), {
fs.cpSync(path.join(SOURCE_DIR, "public"), path.join(CWD, "public"), {
recursive: true,
});
}
@@ -53,7 +49,7 @@ function bootstrap() {
"Could not find a config.json. Created a bootstrap config.json in your current working directory. Customize it to your needs.",
);
fs.copyFileSync(
path.join(BUILDER_DIR, "data", "config.default.json"),
path.join(SOURCE_DIR, "data", "config.default.json"),
path.join(CWD, "config.json"),
);
}
@@ -63,10 +59,18 @@ function bootstrap() {
"Could not find a about.md. Created a bootstrap about.md in your current working directory. Customize it to your needs.",
);
fs.copyFileSync(
path.join(BUILDER_DIR, "data", "about.md"),
path.join(SOURCE_DIR, "data", "about.md"),
path.join(CWD, "about.md"),
);
}
if (!fs.existsSync(path.join(CWD, "custom.css"))) {
warn("Created a bootstrap custom.css in your current working directory.");
fs.copyFileSync(
path.join(SOURCE_DIR, "src", "styles", "custom.css"),
path.join(CWD, "custom.css"),
);
}
}
// Calculate current hash of package.json
@@ -77,7 +81,7 @@ function calculateHash(file) {
return hashSum.digest("hex");
}
const CURRENT_HASH = calculateHash(path.join(CWD, "package-lock.json"));
const CURRENT_HASH = calculateHash(path.join(CWD, "package.json"));
// Check if builder dir needs to be recreated
let RECREATE_DIR = false;
@@ -107,12 +111,13 @@ if (RECREATE_DIR) {
process.chdir(BUILDER_DIR);
info("Installing npm packages");
execSync("npm install", { stdio: "inherit" });
bootstrap();
} catch (e) {
error("Could not install npm packages");
}
}
bootstrap();
try {
if (fs.existsSync(path.join(BUILDER_DIR, "data", "radar"))) {
fs.rmSync(path.join(BUILDER_DIR, "data", "radar"), { recursive: true });
@@ -127,6 +132,10 @@ try {
path.join(CWD, "about.md"),
path.join(BUILDER_DIR, "data", "about.md"),
);
fs.copyFileSync(
path.join(CWD, "custom.css"),
path.join(BUILDER_DIR, "src", "styles", "custom.css"),
);
fs.copyFileSync(
path.join(CWD, "config.json"),
path.join(BUILDER_DIR, "data", "config.json"),