diff options
Diffstat (limited to 'src/helpers/recipe-helpers.js')
-rw-r--r-- | src/helpers/recipe-helpers.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/helpers/recipe-helpers.js b/src/helpers/recipe-helpers.js new file mode 100644 index 000000000..257e322fb --- /dev/null +++ b/src/helpers/recipe-helpers.js | |||
@@ -0,0 +1,39 @@ | |||
1 | import path from 'path'; | ||
2 | import { remote } from 'electron'; | ||
3 | |||
4 | // import ServiceModel from '../models/Service'; | ||
5 | |||
6 | const app = remote.app; | ||
7 | |||
8 | export function getRecipeDirectory(id = '') { | ||
9 | return path.join(app.getPath('userData'), 'recipes', id); | ||
10 | } | ||
11 | |||
12 | export function getDevRecipeDirectory(id = '') { | ||
13 | return path.join(app.getPath('userData'), 'recipes', 'dev', id); | ||
14 | } | ||
15 | |||
16 | export function loadRecipeConfig(recipeId) { | ||
17 | try { | ||
18 | const configPath = `${recipeId}/package.json`; | ||
19 | // Delete module from cache | ||
20 | delete require.cache[require.resolve(configPath)]; | ||
21 | |||
22 | // eslint-disable-next-line | ||
23 | let config = require(configPath); | ||
24 | |||
25 | const moduleConfigPath = require.resolve(configPath); | ||
26 | const paths = path.parse(moduleConfigPath); | ||
27 | config.path = paths.dir; | ||
28 | |||
29 | return config; | ||
30 | } catch (e) { | ||
31 | console.error(e); | ||
32 | return null; | ||
33 | } | ||
34 | } | ||
35 | |||
36 | module.paths.unshift( | ||
37 | getDevRecipeDirectory(), | ||
38 | getRecipeDirectory(), | ||
39 | ); | ||