1 | import * as pac from './package';
|
2 | import * as akala from '@akala/core';
|
3 | import { HttpRouter } from './router';
|
4 | import * as debug from 'debug';
|
5 | import * as master from './master-meta'
|
6 |
|
7 | export function microservice(
|
8 | plugin: string,
|
9 | source: string,
|
10 | sources: string[],
|
11 | config: {},
|
12 | )
|
13 | {
|
14 |
|
15 | switch (source)
|
16 | {
|
17 | case '@akala':
|
18 | if (plugin == '@akala/server' || plugin == '@akala/client')
|
19 | return;
|
20 | break;
|
21 | }
|
22 |
|
23 | var moduleDefinition: pac.CoreProperties = require.main.require(plugin + '/package.json');
|
24 | var dependencies: string[] = [];
|
25 | if (moduleDefinition.dependencies)
|
26 | Object.keys(moduleDefinition.dependencies).forEach(function (dep)
|
27 | {
|
28 | sources.forEach(function (src)
|
29 | {
|
30 | if (dep.substr(0, src.length) == src)
|
31 | dependencies.push(dep);
|
32 | })
|
33 | });
|
34 | if (moduleDefinition.optionalDependencies)
|
35 | Object.keys(moduleDefinition.optionalDependencies).forEach(function (dep)
|
36 | {
|
37 | sources.forEach(function (src)
|
38 | {
|
39 | if (dep.substr(0, src.length) == src)
|
40 | dependencies.push(dep + '?');
|
41 | })
|
42 | });
|
43 | if (moduleDefinition.peerDependencies)
|
44 | Object.keys(moduleDefinition.peerDependencies).forEach(function (dep)
|
45 | {
|
46 | sources.forEach(function (src)
|
47 | {
|
48 | if (dep.substr(0, src.length) == src)
|
49 | dependencies.push(dep + '?');
|
50 | })
|
51 | });
|
52 |
|
53 | if (config && dependencies.length)
|
54 | {
|
55 | var activeDependencies = [];
|
56 | dependencies.forEach(function (dep)
|
57 | {
|
58 | var isOptional = dep[dep.length - 1] == '?';
|
59 | if (isOptional)
|
60 | dep = dep.substring(0, dep.length - 1);
|
61 | if (config[dep] === false || (config[dep] && config[dep].disabled))
|
62 | {
|
63 | if (!isOptional)
|
64 | config[plugin] = false;
|
65 | }
|
66 | else
|
67 | activeDependencies.push(dep);
|
68 | });
|
69 | dependencies = activeDependencies;
|
70 | }
|
71 |
|
72 | if (config && config[plugin] === false)
|
73 | return;
|
74 |
|
75 |
|
76 | var module = akala.module(
|
77 | plugin,
|
78 | ...dependencies
|
79 | );
|
80 | // module.register('$config', akala.chain(function (keys: string[])
|
81 | // {
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | module.init(['$preAuthenticationRouter'], function (preAuthenticatedRouter: HttpRouter)
|
90 | {
|
91 | preAuthenticatedRouter.useGet('/assets/' + plugin, master.serveStatic('node_modules/' + plugin + '/assets'));
|
92 |
|
93 | preAuthenticatedRouter.useGet('/' + plugin, master.serveStatic('node_modules/' + plugin + '/views') as any);
|
94 |
|
95 | });
|
96 |
|
97 | require(plugin);
|
98 | } |
\ | No newline at end of file |