This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
59 lines (52 loc) · 1.71 KB
/
index.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
const debug = require('debug');
const join = require('path').join;
const getNativeModules = require('./lib/getNativeModules');
const getAppModules = require('./lib/getAppModules');
const getDependencyModules = require('./lib/getDependencyModules');
const createDepsProxy = require('./lib/createDepsProxy');
const isFunction = require('lodash/isFunction');
const d = debug('breadboard:setup');
const e = debug('breadboard:error');
module.exports = (options) => {
const containerRoot = options.containerRoot;
const blacklist = options.blacklist || [];
const substitutes = options.substitutes || {};
const substituteKeys = Object.keys(substitutes);
const entry = options.entry;
const initialState = options.initialState;
if (!entry) {
throw new Error('Expected application entry point to be specified');
}
d('Starting bootstrap');
return Promise
.all([
getNativeModules(substituteKeys),
getDependencyModules(join(__dirname, '..', '..'), blacklist, substituteKeys),
getAppModules(join(__dirname, '..', '..', containerRoot), substituteKeys)
])
.then((moduleGroups) => {
const depsProxy = createDepsProxy(moduleGroups, {
substitutes: substitutes
});
let entryPointReturn;
if (isFunction(entry)) {
entryPointReturn = entry(depsProxy);
}
else {
entryPointReturn = depsProxy[entry](initialState);
}
return Promise
.resolve(entryPointReturn)
.then((entryPointResolveValue) => {
return {
deps: depsProxy,
entryResolveValue: entryPointResolveValue
};
});
})
.catch((err) => {
e(err);
return Promise.reject(err);
});
};