From 91c525fce47ebe808356cac41d3b98a0cb801ad9 Mon Sep 17 00:00:00 2001 From: Bubbo <85169821+xbubbo@users.noreply.github.com> Date: Thu, 21 Nov 2024 05:25:55 +0000 Subject: [PATCH] Use template literals + Move port to server block in config --- config.ts | 6 ++++-- index.ts | 2 +- randomize.ts | 16 ++++++++++------ src/types/config.ts | 31 ++++++++++++++++--------------- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/config.ts b/config.ts index bb0203e..a438dac 100644 --- a/config.ts +++ b/config.ts @@ -2,7 +2,9 @@ import type { Config } from "@/types/config"; const config: Config = { // Server Configuration - port: 8080, // The port on which Interstellar runs (Default: 8080) + server: { + port: 8080, // The port on which Interstellar runs (Default: 8080) + }, // Authentication Configuration (Optional) auth: { @@ -13,7 +15,7 @@ const config: Config = { // Format: username: "password", // IMPORTANT: Replace default credentials before deployment users: { - interstellar: "password", + interstellar: "password", }, }, }; diff --git a/index.ts b/index.ts index e940ce0..98c4a09 100644 --- a/index.ts +++ b/index.ts @@ -33,7 +33,7 @@ async function Start() { } } - const port = INConfig.port || 8080; + const port = INConfig.server?.port || 8080; const app = Fastify({ serverFactory: (handler) => diff --git a/randomize.ts b/randomize.ts index 68c0544..af80973 100644 --- a/randomize.ts +++ b/randomize.ts @@ -3,7 +3,7 @@ import fs from "node:fs"; import path from "node:path"; const RenamedFiles: { [key: string]: string } = {}; -const PageRoutes: { [key: string]: string } = {}; +const PageRoutes: { [key: string]: string } = {}; export function randomizeName(filePath: string): string { const extname = path.extname(filePath); @@ -49,9 +49,13 @@ export function RandomizeNames() { fs.renameSync(oldPath, newPath); if (file.startsWith(path.join(process.cwd(), "src", "pages"))) { - const oldRoute = oldPath.replace(process.cwd() + "/src/pages", "").replace(/\\/g, "/"); - const newRoute = newPath.replace(process.cwd() + "/src/pages", "").replace(/\\/g, "/"); - PageRoutes[oldRoute] = newRoute; + const oldRoute = oldPath + .replace(`${process.cwd()}/src/pages`, "") + .replace(/\\/g, "/"); + const newRoute = newPath + .replace(`${process.cwd()}/src/pages`, "") + .replace(/\\/g, "/"); + PageRoutes[oldRoute] = newRoute; } } @@ -112,7 +116,7 @@ export function updatePageRoutes() { for (const [oldRoute, newRoute] of Object.entries(PageRoutes)) { fileContent = fileContent.replace( new RegExp(`['"]${oldRoute.replace(".astro", "")}['"]`, "g"), - `'${newRoute.replace(".astro", "")}'` + `'${newRoute.replace(".astro", "")}'`, ); } @@ -133,7 +137,7 @@ export async function Revert() { try { console.log("Reverting Changes."); execSync("git restore src/", { cwd: process.cwd(), stdio: "inherit" }); - execSync("git clean -fdx src/", { cwd: process.cwd(), stdio: "inherit" }); + execSync("git clean -fdx src/", { cwd: process.cwd(), stdio: "inherit" }); await new Promise((resolve) => setTimeout(resolve, 2000)); console.log("Revert completed."); diff --git a/src/types/config.ts b/src/types/config.ts index 586ae56..25f9faf 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -1,22 +1,23 @@ +// Configuration for the application export interface Config { + // Server configuration + server?: { + // The port to run the HTTP server on + // Default: 8080 + port?: number; + }; + + // Authentication configuration auth?: Auth; - /** - * The port to run the HTTP server on - * @default 8080 - */ - port?: number; } + +// Authentication settings export interface Auth { - /** - * Enable password protection - * @default false - */ + // Enable password protection + // Default: false challenge?: boolean; - /** - * Users and their passwords - * @example ```js - { "interstellarskidder": "superSecretPassword!!!" } - ``` - */ + + // Users and their passwords + // Example: "username": "password", users?: Record; }