UNPKG

2.82 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const akala = require("@akala/core");
4const master = require("./master-meta");
5function microservice(plugin, source, sources, config) {
6 switch (source) {
7 case '@akala':
8 if (plugin == '@akala/server' || plugin == '@akala/client')
9 return;
10 break;
11 }
12 var moduleDefinition = require.main.require(plugin + '/package.json');
13 var dependencies = [];
14 if (moduleDefinition.dependencies)
15 Object.keys(moduleDefinition.dependencies).forEach(function (dep) {
16 sources.forEach(function (src) {
17 if (dep.substr(0, src.length) == src)
18 dependencies.push(dep);
19 });
20 });
21 if (moduleDefinition.optionalDependencies)
22 Object.keys(moduleDefinition.optionalDependencies).forEach(function (dep) {
23 sources.forEach(function (src) {
24 if (dep.substr(0, src.length) == src)
25 dependencies.push(dep + '?');
26 });
27 });
28 if (moduleDefinition.peerDependencies)
29 Object.keys(moduleDefinition.peerDependencies).forEach(function (dep) {
30 sources.forEach(function (src) {
31 if (dep.substr(0, src.length) == src)
32 dependencies.push(dep + '?');
33 });
34 });
35 if (config && dependencies.length) {
36 var activeDependencies = [];
37 dependencies.forEach(function (dep) {
38 var isOptional = dep[dep.length - 1] == '?';
39 if (isOptional)
40 dep = dep.substring(0, dep.length - 1);
41 if (config[dep] === false || (config[dep] && config[dep].disabled)) {
42 if (!isOptional)
43 config[plugin] = false;
44 }
45 else
46 activeDependencies.push(dep);
47 });
48 dependencies = activeDependencies;
49 }
50 if (config && config[plugin] === false)
51 return;
52 var module = akala.module(plugin, ...dependencies);
53 // module.register('$config', akala.chain(function (keys: string[])
54 // {
55 // akala.resolve('$config.' + plugin + '.' + keys.join('.'));
56 // }, function (keys, key: string)
57 // {
58 // keys.push(key);
59 // return keys;
60 // }));
61 module.init(['$preAuthenticationRouter'], function (preAuthenticatedRouter) {
62 preAuthenticatedRouter.useGet('/assets/' + plugin, master.serveStatic('node_modules/' + plugin + '/assets'));
63 preAuthenticatedRouter.useGet('/' + plugin, master.serveStatic('node_modules/' + plugin + '/views'));
64 });
65 require(plugin);
66}
67exports.microservice = microservice;
68//# sourceMappingURL=microservice.js.map
\No newline at end of file