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