From 78bf8dc8c941d01f33719f64f3149f5356f49537 Mon Sep 17 00:00:00 2001 From: yaswanthBonumaddi Date: Fri, 31 Jan 2025 15:00:26 +0530 Subject: [PATCH 1/2] feat: link your project now to daemon --- src/index.ts | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index f8bc9fc..d29ef9c 100755 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ import create from "./commands/create/index"; import path from "path"; // import { spawn, spawnSync } from "child_process"; import spawnSync from "cross-spawn"; - +const os = require("os"); import devOpsPluginCommands from "./commands/devops-plugin"; import pluginCommands from "./commands/plugin"; import prismaCommands from "./commands/prisma"; @@ -79,6 +79,42 @@ export const isAGodspeedProject = () => { return true; }; +const updateServicesJson = async (add = true) => { + const servicesFile = path.join(os.homedir(), ".godspeed", "services.json"); + + try { + if (!fs.existsSync(servicesFile)) return; + + const servicesData = JSON.parse(fs.readFileSync(servicesFile, "utf-8")); + const currentProject = { + serviceId: path.basename(process.cwd()), + name: path.basename(process.cwd()), + path: process.cwd(), + status: "active", + last_updated: new Date().toISOString(), + initialized: true, + }; + + if (add) { + const exists = servicesData.services.some((service: any) => service.path === process.cwd()); + if (!exists) servicesData.services.push(currentProject); + } else { + servicesData.services = servicesData.services.filter((service: any) => service.path !== process.cwd()); + } + + await fs.promises.writeFile(servicesFile, JSON.stringify(servicesData, null, 2), "utf-8"); + console.log(chalk.green("Project data updated successfully.")); + } catch (error: any) { + if (error.code === "EACCES") { + const action = add ? "link" : "unlink"; + console.error("\x1b[31mPermission denied: Cannot write to services.json\x1b[0m"); + console.error(`\x1b[33mTry running: \x1b[1msudo godspeed ${action}\x1b[0m`); + } else { + console.error("\x1b[31mAn error occurred:\x1b[0m", error); + } + } +}; + (async function main() { // console.log(chalk.bold(chalk.green("\n~~~~~~ Godspeed CLI ~~~~~~\n"))); console.log("\n"); @@ -168,6 +204,23 @@ export const isAGodspeedProject = () => { // update(options, version); // } // }); + program + .command("link") + .description("Link a local Godspeed package for development.") + .action(async () => { + if (await isAGodspeedProject()) { + updateServicesJson(true); + } + }); + +program + .command("unlink") + .description("Unlink a locally linked Godspeed package.") + .action(async() => { + if (await isAGodspeedProject()) { + updateServicesJson(false); + } + }); program .command("dev") From 7cbb6f643fbfb4fd5420608c13b2ec769dd1455f Mon Sep 17 00:00:00 2001 From: yaswanthBonumaddi Date: Fri, 31 Jan 2025 15:05:50 +0530 Subject: [PATCH 2/2] feat: link your project now to daemon --- src/index.ts | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/index.ts b/src/index.ts index d29ef9c..03407e2 100755 --- a/src/index.ts +++ b/src/index.ts @@ -204,23 +204,7 @@ const updateServicesJson = async (add = true) => { // update(options, version); // } // }); - program - .command("link") - .description("Link a local Godspeed package for development.") - .action(async () => { - if (await isAGodspeedProject()) { - updateServicesJson(true); - } - }); -program - .command("unlink") - .description("Unlink a locally linked Godspeed package.") - .action(async() => { - if (await isAGodspeedProject()) { - updateServicesJson(false); - } - }); program .command("dev") @@ -244,6 +228,24 @@ program } }); + program + .command("link") + .description("Link a local Godspeed project to the global environment for development in godspeed-daemon.") + .action(async () => { + if (await isAGodspeedProject()) { + updateServicesJson(true); + } + }); + + program + .command("unlink") + .description("Unlink a local Godspeed project from the global environment.") + .action(async() => { + if (await isAGodspeedProject()) { + updateServicesJson(false); + } + }); + program .command("gen-crud-api") .description(