1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const akala = require("@akala/core");
|
4 | const master = require("./master-meta");
|
5 | function 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 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
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 | }
|
67 | exports.microservice = microservice;
|
68 |
|
\ | No newline at end of file |