fix: fix.env.example
This commit is contained in:
@ -1,52 +1,52 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const PRESERVED_KEYS = [
|
||||
"APP_NAME",
|
||||
"APP_ENV",
|
||||
"PORT",
|
||||
"API_KEY",
|
||||
"ALLOWED_ORIGINS",
|
||||
"REDIS_HOST",
|
||||
"REDIS_PORT",
|
||||
];
|
||||
|
||||
try {
|
||||
const envPath = path.join(process.cwd(), ".env");
|
||||
const envExamplePath = path.join(process.cwd(), ".env.example");
|
||||
|
||||
if (!fs.existsSync(envPath)) {
|
||||
console.error(`.env file not found at ${envPath}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const envContent = fs.readFileSync(envPath, "utf-8");
|
||||
|
||||
const lines = envContent.split("\n");
|
||||
const processedLines = lines.map((line) => {
|
||||
const trimmedLine = line.trim();
|
||||
|
||||
if (trimmedLine.startsWith("#") || trimmedLine === "") {
|
||||
return line;
|
||||
}
|
||||
|
||||
const delimeterIndex = line.indexOf("=");
|
||||
if (delimeterIndex === -1) {
|
||||
return line;
|
||||
}
|
||||
|
||||
const key = line.substring(0, delimeterIndex).trim();
|
||||
const value = line.substring(delimeterIndex + 1).trim();
|
||||
|
||||
if (PRESERVED_KEYS.includes(key)) {
|
||||
return `${key}=${value}`;
|
||||
}
|
||||
return `${key}=`;
|
||||
});
|
||||
|
||||
fs.writeFileSync(envExamplePath, processedLines.join("\n"));
|
||||
console.log("File .env.example berhasil diperbarui!");
|
||||
} catch (error) {
|
||||
console.error("Error while creating .env.example:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const PRESERVED_KEYS = [
|
||||
"APP_NAME",
|
||||
"APP_ENV",
|
||||
"PORT",
|
||||
"API_KEY",
|
||||
"ALLOWED_ORIGINS",
|
||||
"REDIS_HOST",
|
||||
"REDIS_PORT",
|
||||
];
|
||||
|
||||
try {
|
||||
const envPath = path.join(process.cwd(), ".env");
|
||||
const envExamplePath = path.join(process.cwd(), ".env.example");
|
||||
|
||||
if (!fs.existsSync(envPath)) {
|
||||
console.error(`.env file not found at ${envPath}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const envContent = fs.readFileSync(envPath, "utf-8");
|
||||
|
||||
const lines = envContent.split("\n");
|
||||
const processedLines = lines.map((line) => {
|
||||
const trimmedLine = line.trim();
|
||||
|
||||
if (trimmedLine.startsWith("#") || trimmedLine === "") {
|
||||
return line;
|
||||
}
|
||||
|
||||
const delimeterIndex = line.indexOf("=");
|
||||
if (delimeterIndex === -1) {
|
||||
return line;
|
||||
}
|
||||
|
||||
const key = line.substring(0, delimeterIndex).trim();
|
||||
const value = line.substring(delimeterIndex + 1).trim();
|
||||
|
||||
if (PRESERVED_KEYS.includes(key)) {
|
||||
return `${key}=${value}`;
|
||||
}
|
||||
return `${key}=`;
|
||||
});
|
||||
|
||||
fs.writeFileSync(envExamplePath, processedLines.join("\n"));
|
||||
console.log("File .env.example berhasil diperbarui!");
|
||||
} catch (error) {
|
||||
console.error("Error while creating .env.example:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@ -1,51 +1,51 @@
|
||||
/**
|
||||
* Dynamically aggregates Elysia sub-routes from modular directories into a central registry.
|
||||
*
|
||||
* @behavior
|
||||
* 1. Scans `./src/modules` for valid Elysia modules
|
||||
* 2. Generates imports and `.use()` calls for each module
|
||||
* 3. Writes composed routes to `./src/routes.ts`
|
||||
*
|
||||
* @requirements
|
||||
* - Module directories must contain an export named `[folderName]Module`
|
||||
* (e.g., `userModule` for `/user` folder)
|
||||
* - Modules must export an Elysia instance
|
||||
*
|
||||
* @outputfile ./src/routes.ts
|
||||
* @examplegenerated
|
||||
* ```ts
|
||||
* import Elysia from "elysia";
|
||||
* import { userModule } from './modules/user';
|
||||
* import { authModule } from './modules/auth';
|
||||
*
|
||||
* const routes = new Elysia()
|
||||
* .use(userModule)
|
||||
* .use(authModule);
|
||||
*
|
||||
* export { routes };
|
||||
* ```
|
||||
*/
|
||||
import { writeFileSync, readdirSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
const modulesPath = "./src/modules";
|
||||
const importLines: string[] = [];
|
||||
const useLines: string[] = [];
|
||||
|
||||
for (const folder of readdirSync(modulesPath, { withFileTypes: true })) {
|
||||
if (folder.isDirectory()) {
|
||||
const varName = `${folder.name}Module`;
|
||||
importLines.push(`import {${varName}} from './modules/${folder.name}';`);
|
||||
useLines.push(`.use(${varName})`);
|
||||
}
|
||||
}
|
||||
|
||||
const content = `
|
||||
import Elysia from "elysia";
|
||||
${importLines.join("\n")}
|
||||
const routes = new Elysia()
|
||||
${useLines.join("\n")};
|
||||
export { routes };
|
||||
`;
|
||||
|
||||
writeFileSync(join(modulesPath, "../routes.ts"), content);
|
||||
/**
|
||||
* Dynamically aggregates Elysia sub-routes from modular directories into a central registry.
|
||||
*
|
||||
* @behavior
|
||||
* 1. Scans `./src/modules` for valid Elysia modules
|
||||
* 2. Generates imports and `.use()` calls for each module
|
||||
* 3. Writes composed routes to `./src/routes.ts`
|
||||
*
|
||||
* @requirements
|
||||
* - Module directories must contain an export named `[folderName]Module`
|
||||
* (e.g., `userModule` for `/user` folder)
|
||||
* - Modules must export an Elysia instance
|
||||
*
|
||||
* @outputfile ./src/routes.ts
|
||||
* @examplegenerated
|
||||
* ```ts
|
||||
* import Elysia from "elysia";
|
||||
* import { userModule } from './modules/user';
|
||||
* import { authModule } from './modules/auth';
|
||||
*
|
||||
* const routes = new Elysia()
|
||||
* .use(userModule)
|
||||
* .use(authModule);
|
||||
*
|
||||
* export { routes };
|
||||
* ```
|
||||
*/
|
||||
import { writeFileSync, readdirSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
const modulesPath = "./src/modules";
|
||||
const importLines: string[] = [];
|
||||
const useLines: string[] = [];
|
||||
|
||||
for (const folder of readdirSync(modulesPath, { withFileTypes: true })) {
|
||||
if (folder.isDirectory()) {
|
||||
const varName = `${folder.name}Module`;
|
||||
importLines.push(`import {${varName}} from './modules/${folder.name}';`);
|
||||
useLines.push(`.use(${varName})`);
|
||||
}
|
||||
}
|
||||
|
||||
const content = `
|
||||
import Elysia from "elysia";
|
||||
${importLines.join("\n")}
|
||||
const routes = new Elysia()
|
||||
${useLines.join("\n")};
|
||||
export { routes };
|
||||
`;
|
||||
|
||||
writeFileSync(join(modulesPath, "../routes.ts"), content);
|
||||
|
||||
Reference in New Issue
Block a user