hotshot-mod-manager
Version:
119 lines (97 loc) • 2.91 kB
JavaScript
import inquirer from "inquirer";
import { randomUUID } from "node:crypto";
import fs from "node:fs";
import path from "node:path";
export async function othersGenTrigger() {
const { command } = await inquirer.prompt([
{
type: "list",
name: "command",
message: "Select a command:",
validate: (input) => input.trim() ? true : "Command cannot be empty.",
choices: [
"Initiate HotShot Project",
"Exit",
],
},
]);
if (command === "Initiate HotShot Project") {
await initiateHotShotProject();
}
}
export function initiateHotShotProject() {
const configPath = path.join(process.cwd(), "hotshot.config.json");
if (fs.existsSync(configPath)) {
throw new Error("hotshot.config.json already exists.");
}
// Check src directory
if (!fs.existsSync(path.join(process.cwd(), "src"))) {
fs.mkdirSync(path.join(process.cwd(), "src"));
}
fs.writeFileSync(
path.join(process.cwd(), "src", "kernel.ts"),
modManagerContents(),
);
fs.writeFileSync(
path.join(process.cwd(), "hotshot.config.json"),
configContents(),
);
}
/*
|-----------------------------------------------------------------------
| Kernel Contents
|-----------------------------------------------------------------------
*/
function modManagerContents() {
return `
/*
* |
* |--------------------------------------------------------------------
* |
* | Mod Manager - This file is used to manage all the modules
* |
* |--------------------------------------------------------------------
* |
*/
import { routerFactory } from "@a4arpon/hotshot"
/*
* |--------------------------------------------------------------------
* | Router Factory (API Routes)
* |--------------------------------------------------------------------
* |
* | Inject your routers here as shown below:
* |
* | export const applicationRoutes = routerFactory([
* | AuthRouter, UserPrefRouter, CartRouter
* | ])
*/
export const applicationRoutes = routerFactory([])
/*
* |--------------------------------------------------------------------
* | Application Workers (Bull Queues)
* |--------------------------------------------------------------------
*/
export const applicationWorkers = []
/*
|--------------------------------------------------------------------
| API Specs (OpenAPI)
|--------------------------------------------------------------------
*/
export const openApiSpecs = []
`;
}
/*
|-----------------------------------------------------------------------
| Config Contents
|-----------------------------------------------------------------------
*/
function configContents() {
const projectName = `project-${randomUUID()?.slice(0, 8)}`;
return `{
"projectName": "${projectName}",
"routerModules": [],
"cacheDrivers": [],
"useGuards": [],
"openAPISpecs": []
}`;
}