aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/recipe-helpers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers/recipe-helpers.ts')
-rw-r--r--src/helpers/recipe-helpers.ts34
1 files changed, 34 insertions, 0 deletions
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 @@
1import { parse } from 'path';
2import { userDataRecipesPath } from '../environment';
3
4export function getRecipeDirectory(id: string = ''): string {
5 return userDataRecipesPath(id);
6}
7
8export function getDevRecipeDirectory(id: string = ''): string {
9 return userDataRecipesPath('dev', id);
10}
11
12export function loadRecipeConfig(recipeId: string) {
13 try {
14 const configPath = `${recipeId}/package.json`;
15 // Delete module from cache
16 delete require.cache[require.resolve(configPath)];
17
18 // eslint-disable-next-line
19 let config = require(configPath);
20
21 const moduleConfigPath = require.resolve(configPath);
22 config.path = parse(moduleConfigPath).dir;
23
24 return config;
25 } catch (e) {
26 console.error(e);
27 return null;
28 }
29}
30
31module.paths.unshift(
32 getDevRecipeDirectory(),
33 getRecipeDirectory(),
34);