diff options
author | Vijay A <avijayr@protonmail.com> | 2021-08-15 17:15:09 +0530 |
---|---|---|
committer | Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com> | 2021-08-15 13:54:00 +0000 |
commit | bc76d19c6f5687dd18c96db249e0abe7ad79a673 (patch) | |
tree | d4e977f99be77d723ce93bb3866468d8b63ec038 /src/helpers/recipe-helpers.ts | |
parent | chore: npm upgrades (diff) | |
download | ferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.tar.gz ferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.tar.zst ferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.zip |
chore: typescript conversion of some minor utilities
Also removed 'targz' unused package from runtime.
Diffstat (limited to 'src/helpers/recipe-helpers.ts')
-rw-r--r-- | src/helpers/recipe-helpers.ts | 34 |
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 @@ | |||
1 | import { parse } from 'path'; | ||
2 | import { userDataRecipesPath } from '../environment'; | ||
3 | |||
4 | export function getRecipeDirectory(id: string = ''): string { | ||
5 | return userDataRecipesPath(id); | ||
6 | } | ||
7 | |||
8 | export function getDevRecipeDirectory(id: string = ''): string { | ||
9 | return userDataRecipesPath('dev', id); | ||
10 | } | ||
11 | |||
12 | export 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 | |||
31 | module.paths.unshift( | ||
32 | getDevRecipeDirectory(), | ||
33 | getRecipeDirectory(), | ||
34 | ); | ||