Skip to content

Commit d77dbb4

Browse files
✨ support helper returning promises
1 parent 298e0b8 commit d77dbb4

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

.eslintrc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
},
1010
"rules": {
1111
"no-underscore-dangle": 0,
12-
"no-use-before-define": ["error", { "functions": false, "classes": true, "variables": true }],
13-
"max-len": 0
12+
"no-use-before-define": [
13+
"error",
14+
{ "functions": false, "classes": true, "variables": true }
15+
],
16+
"max-len": 0,
17+
"no-restricted-syntax": 0,
18+
"no-await-in-loop": 0
1419
}
1520
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "immersive",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"description": "A framework to build immersive CLIs & great developer tools.",
55
"main": "index.js",
66
"module": "src/main.js",

src/environment/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import {
2-
compose, entries, reduce, map,
3-
} from 'conductor';
1+
import { map } from 'conductor';
42

53
let environment;
64
let environments;
75
export const helpersMap = {};
86

9-
const inject = conf => compose(
10-
reduce((acc, [key, module]) => ({ ...acc, [key]: module(conf) }), {}),
11-
entries,
12-
);
7+
const inject = async (conf, helpers) => {
8+
const acc = {};
9+
for (const [helperName, getHelper] of Object.entries(helpers)) {
10+
acc[helperName] = await getHelper(conf);
11+
}
12+
return acc;
13+
};
1314

1415
export const getCurrentEnvironment = () => environment;
1516
export const loadEnvironments = (config) => {
@@ -19,9 +20,9 @@ export const loadEnvironments = (config) => {
1920
);
2021
return environments;
2122
};
22-
export const setCurrentEnvironment = (name, config) => {
23+
export const setCurrentEnvironment = async (name, config) => {
2324
environment = environments[name];
2425
if (!helpersMap[name]) {
25-
helpersMap[name] = inject(environment)(config.helpers);
26+
helpersMap[name] = await inject(environment, config.helpers);
2627
}
2728
};

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const isNotEmptyOrNil = compose(
1515
converge(or, [isNil, isEmpty]),
1616
);
1717

18-
function immersive(userConfig = {}) {
18+
async function immersive(userConfig = {}) {
1919
const {
2020
environments,
2121
defaultEnvironment,
@@ -39,7 +39,7 @@ function immersive(userConfig = {}) {
3939
});
4040
if (withEnvironment) {
4141
config.environments = loadEnvironments(config);
42-
setCurrentEnvironment(
42+
await setCurrentEnvironment(
4343
defaultEnvironment || Object.keys(environments)[0],
4444
config,
4545
);

0 commit comments

Comments
 (0)