1 | "use strict";
|
2 | var __importStar = (this && this.__importStar) || function (mod) {
|
3 | if (mod && mod.__esModule) return mod;
|
4 | var result = {};
|
5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
6 | result["default"] = mod;
|
7 | return result;
|
8 | };
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const akala = __importStar(require("@akala/core"));
|
11 | const master = __importStar(require("./master-meta"));
|
12 | function microservice(plugin, source, sources, config) {
|
13 | switch (source) {
|
14 | case '@akala':
|
15 | if (plugin == '@akala/server' || plugin == '@akala/client')
|
16 | return;
|
17 | break;
|
18 | }
|
19 | var moduleDefinition = require.main.require(plugin + '/package.json');
|
20 | var dependencies = [];
|
21 | if (moduleDefinition.dependencies)
|
22 | Object.keys(moduleDefinition.dependencies).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.optionalDependencies)
|
29 | Object.keys(moduleDefinition.optionalDependencies).forEach(function (dep) {
|
30 | sources.forEach(function (src) {
|
31 | if (dep.substr(0, src.length) == src)
|
32 | dependencies.push(dep + '?');
|
33 | });
|
34 | });
|
35 | if (moduleDefinition.peerDependencies)
|
36 | Object.keys(moduleDefinition.peerDependencies).forEach(function (dep) {
|
37 | sources.forEach(function (src) {
|
38 | if (dep.substr(0, src.length) == src)
|
39 | dependencies.push(dep + '?');
|
40 | });
|
41 | });
|
42 | if (config && dependencies.length) {
|
43 | var activeDependencies = [];
|
44 | dependencies.forEach(function (dep) {
|
45 | var isOptional = dep[dep.length - 1] == '?';
|
46 | if (isOptional)
|
47 | dep = dep.substring(0, dep.length - 1);
|
48 | if (config[dep] === false || (config[dep] && config[dep].disabled)) {
|
49 | if (!isOptional)
|
50 | config[plugin] = false;
|
51 | }
|
52 | else
|
53 | activeDependencies.push(dep);
|
54 | });
|
55 | dependencies = activeDependencies;
|
56 | }
|
57 | if (config && config[plugin] === false)
|
58 | return;
|
59 | var module = akala.module(plugin, ...dependencies);
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | module.activate(['$preAuthenticationRouter'], function (preAuthenticatedRouter) {
|
69 | preAuthenticatedRouter.useGet('/assets/' + plugin, master.serveStatic('node_modules/' + plugin + '/assets'));
|
70 | preAuthenticatedRouter.useGet('/' + plugin, master.serveStatic('node_modules/' + plugin + '/views'));
|
71 | });
|
72 | require(plugin);
|
73 | }
|
74 | exports.microservice = microservice;
|
75 |
|
\ | No newline at end of file |