From bc76d19c6f5687dd18c96db249e0abe7ad79a673 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Sun, 15 Aug 2021 17:15:09 +0530 Subject: chore: typescript conversion of some minor utilities Also removed 'targz' unused package from runtime. --- src/helpers/recipe-helpers.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/helpers/recipe-helpers.ts (limited to 'src/helpers/recipe-helpers.ts') diff --git a/src/helpers/recipe-helpers.ts b/src/helpers/recipe-helpers.ts new file mode 100644 index 000000000..965429210 --- /dev/null +++ b/src/helpers/recipe-helpers.ts @@ -0,0 +1,34 @@ +import { parse } from 'path'; +import { userDataRecipesPath } from '../environment'; + +export function getRecipeDirectory(id: string = ''): string { + return userDataRecipesPath(id); +} + +export function getDevRecipeDirectory(id: string = ''): string { + return userDataRecipesPath('dev', id); +} + +export function loadRecipeConfig(recipeId: string) { + try { + const configPath = `${recipeId}/package.json`; + // Delete module from cache + delete require.cache[require.resolve(configPath)]; + + // eslint-disable-next-line + let config = require(configPath); + + const moduleConfigPath = require.resolve(configPath); + config.path = parse(moduleConfigPath).dir; + + return config; + } catch (e) { + console.error(e); + return null; + } +} + +module.paths.unshift( + getDevRecipeDirectory(), + getRecipeDirectory(), +); -- cgit v1.2.3-54-g00ecf