aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/recipe-helpers.js
blob: 7e4bfa85ab6a1fb2b078eed850c498ccb43a5f5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { parse } from 'path';
import { userDataRecipesPath } from '../environment';

export function getRecipeDirectory(id = '') {
  return userDataRecipesPath(id);
}

export function getDevRecipeDirectory(id = '') {
  return userDataRecipesPath('dev', id);
}

export function loadRecipeConfig(recipeId) {
  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(),
);