stonyx 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/modules.js +10 -2
package/package.json
CHANGED
package/src/modules.js
CHANGED
|
@@ -6,8 +6,10 @@ import { readFile } from '@stonyx/utils/file';
|
|
|
6
6
|
|
|
7
7
|
export default async (config, rootPath) => {
|
|
8
8
|
const modules = [];
|
|
9
|
+
const initPromises = [];
|
|
9
10
|
const rootPackage = await readFile(`${rootPath}/package.json`, { json: true });
|
|
10
11
|
const { devDependencies:dependencies } = rootPackage;
|
|
12
|
+
config.rootPath = rootPath;
|
|
11
13
|
|
|
12
14
|
for (const moduleName of Object.keys(dependencies)) {
|
|
13
15
|
if (!moduleName.startsWith('@stonyx/')) continue; // All official stonyx modules should be start with "@stonyx/"
|
|
@@ -37,11 +39,17 @@ export default async (config, rootPath) => {
|
|
|
37
39
|
|
|
38
40
|
const { main: entryPoint } = modulePackage;
|
|
39
41
|
const { default: moduleClass } = await import(`${rootPath}/node_modules/${moduleName}/${entryPoint}`);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
const moduleInstance = new moduleClass();
|
|
43
|
+
|
|
44
|
+
modules.push(moduleInstance);
|
|
45
|
+
if (moduleInstance.init) initPromises.push(moduleInstance.init());
|
|
46
|
+
|
|
42
47
|
} catch (error) {
|
|
43
48
|
console.error(error);
|
|
44
49
|
throw new Error(`Stonyx modules with async loading must have a config/environment.js file with default configurations.`);
|
|
45
50
|
}
|
|
46
51
|
}
|
|
52
|
+
|
|
53
|
+
// Wait until all modules are initialized
|
|
54
|
+
await Promise.all(initPromises);
|
|
47
55
|
}
|