From 3ec56f951c5238b65245e935e3b3cc405b289fd9 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 1 May 2024 17:25:16 -0500 Subject: [PATCH] consolidate --- src/commands/plugins.ts | 2 +- src/utilities/getConfig.ts | 18 +++++++++++++++++- src/utilities/getLang.ts | 18 ------------------ 3 files changed, 18 insertions(+), 20 deletions(-) delete mode 100644 src/utilities/getLang.ts diff --git a/src/commands/plugins.ts b/src/commands/plugins.ts index 0dbfdbd..4bc526b 100644 --- a/src/commands/plugins.ts +++ b/src/commands/plugins.ts @@ -5,7 +5,7 @@ import { fetch } from 'undici'; import { pluginsQ } from '../prompts/plugin.js'; import { fromCwd } from '../utilities/fromCwd.js'; import esbuild from 'esbuild'; -import { getLang } from '../utilities/getLang.js'; +import { getLang } from '../utilities/getConfig.js'; import { resolve } from 'path'; import { require } from '../utilities/require.js'; interface PluginData { diff --git a/src/utilities/getConfig.ts b/src/utilities/getConfig.ts index d6a1817..68ddfbf 100644 --- a/src/utilities/getConfig.ts +++ b/src/utilities/getConfig.ts @@ -1,6 +1,22 @@ -import { readFile } from 'node:fs/promises'; import { findUp } from 'find-up'; +import { readFile } from 'node:fs/promises'; import assert from 'node:assert'; +/** + * It finds the sern.config.json file, reads it, and returns the language property + * @returns The language of the project. + */ +export async function getLang(): Promise<'typescript' | 'javascript'> { + const sernLocation = await findUp('sern.config.json'); + + if (!sernLocation) throw new Error("Can't find sern.config.json"); + + const output = JSON.parse(await readFile(sernLocation, 'utf8')); + + if (!output) throw new Error("Can't read your sern.config.json."); + + return output.language; +} + export async function getConfig(): Promise { const sernLocation = await findUp('sern.config.json'); assert(sernLocation, "Can't find sern.config.json"); diff --git a/src/utilities/getLang.ts b/src/utilities/getLang.ts deleted file mode 100644 index de9263d..0000000 --- a/src/utilities/getLang.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { findUp } from 'find-up'; -import { readFile } from 'node:fs/promises'; - -/** - * It finds the sern.config.json file, reads it, and returns the language property - * @returns The language of the project. - */ -export async function getLang(): Promise<'typescript' | 'javascript'> { - const sernLocation = await findUp('sern.config.json'); - - if (!sernLocation) throw new Error("Can't find sern.config.json"); - - const output = JSON.parse(await readFile(sernLocation, 'utf8')); - - if (!output) throw new Error("Can't read your sern.config.json."); - - return output.language; -}