diff --git a/src/commands/plugins.js b/src/commands/plugins.js index b8abd6a..d5de5e6 100644 --- a/src/commands/plugins.js +++ b/src/commands/plugins.js @@ -3,6 +3,7 @@ import prompts from 'prompts'; import { fetch } from 'undici'; import fs from 'fs'; import { greenBright } from 'colorette'; +import { fromCwd } from '../utilities/fromCwd.js'; const { prompt } = prompts; /** @@ -37,7 +38,7 @@ async function download(url) { if (!data) throw new Error('Download failed! Kindly contact developers'); - const dir = `${process.cwd()}/src/plugins`; + const dir = `${fromCwd('/src/plugins')}`; const filedir = `${process.cwd()}/src/plugins/${url.split('/').pop()}`; if (!fs.existsSync(dir)) { diff --git a/src/utilities/edits.js b/src/utilities/edits.js index ba98feb..cf1efc3 100644 --- a/src/utilities/edits.js +++ b/src/utilities/edits.js @@ -1,5 +1,6 @@ import { readFile, rename, writeFile } from 'node:fs/promises'; import { findUp } from 'find-up'; +import { fromCwd } from './fromCwd.js'; /** * It takes a string, finds the package.json file in the directory of the string, and changes the name @@ -9,7 +10,7 @@ import { findUp } from 'find-up'; */ export async function editMain(name) { const pjLocation = await findUp('package.json', { - cwd: process.cwd() + '/' + name, + cwd: fromCwd('/' + name), }); const output = JSON.parse(await readFile(pjLocation, 'utf8')); @@ -36,7 +37,7 @@ export async function editDirs( lang = 'typescript' ) { const path = await findUp('src', { - cwd: process.cwd() + '/' + name, + cwd: fromCwd(name), type: 'directory', }); @@ -46,12 +47,12 @@ export async function editDirs( await rename(path, newMainDir); const cmdsPath = await findUp('commands', { - cwd: process.cwd() + '/' + name + '/' + srcName, + cwd: fromCwd(name, srcName), type: 'directory', }); const index = await findUp(`index.${ext}`, { - cwd: process.cwd() + '/' + name + '/' + srcName, + cwd: fromCwd(name, srcName), }); const newCmdsPath = cmdsPath?.replace('commands', cmds_dirName); diff --git a/src/utilities/fromCwd.js b/src/utilities/fromCwd.js index 4a3feb7..0669e0e 100644 --- a/src/utilities/fromCwd.js +++ b/src/utilities/fromCwd.js @@ -1,10 +1,8 @@ import path from 'path'; - /** - * @param {any[]} dir + * @param {string[]} dir */ export function fromCwd(...dir) { - return path.join(process.cwd(), ...dir) + return path.join(...[process.cwd(), ...dir]); } -