aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/recipe-helpers.js
blob: 257e322fb15cbcd64cae7c0cc2f324ac105da686 (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
35
36
37
38
39
import path from 'path';
import { remote } from 'electron';

// import ServiceModel from '../models/Service';

const app = remote.app;

export function getRecipeDirectory(id = '') {
  return path.join(app.getPath('userData'), 'recipes', id);
}

export function getDevRecipeDirectory(id = '') {
  return path.join(app.getPath('userData'), 'recipes', '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);
    const paths = path.parse(moduleConfigPath);
    config.path = paths.dir;

    return config;
  } catch (e) {
    console.error(e);
    return null;
  }
}

module.paths.unshift(
  getDevRecipeDirectory(),
  getRecipeDirectory(),
);