mirror of
https://github.com/SrIzan10/sern-cli.git
synced 2026-05-01 11:05:17 +00:00
feat: transform repetitive paths to fromCwd
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user