@aj-shadow/z-abs-corelayer-server 0.0.0-aj-beta.221

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.gitattributes +26 -0
  2. package/LICENSE.txt +96 -0
  3. package/README.md +5 -0
  4. package/npm-shrinkwrap.json +13 -0
  5. package/package.json +10 -0
  6. package/project/server/_build/Server-CoreLayer-server.bld +12 -0
  7. package/project/server/_build/z-abs-corelayer-server.prj +12 -0
  8. package/project/server/communication/core-protocol/decoder.js +404 -0
  9. package/project/server/communication/core-protocol/encoder.js +503 -0
  10. package/project/server/communication/messages/messages-s-to-c/message-persistent-init-response.js +14 -0
  11. package/project/server/communication/messages/messages-s-to-c/message-persistent-publish.js +16 -0
  12. package/project/server/communication/messages/messages-s-to-c/message-ws-init.js +14 -0
  13. package/project/server/communication/messages/messages-s-to-s/service-init-request.js +17 -0
  14. package/project/server/communication/messages/messages-s-to-s/service-init-response.js +18 -0
  15. package/project/server/communication/messages/messages-s-to-s/service-offer-off.js +15 -0
  16. package/project/server/communication/messages/messages-s-to-s/service-offer-on.js +15 -0
  17. package/project/server/communication/messages/messages-s-to-s/worker-init-request.js +15 -0
  18. package/project/server/data-response.js +588 -0
  19. package/project/server/high-resolution-timestamp.js +36 -0
  20. package/project/server/log/log-config.js +107 -0
  21. package/project/server/log/log-types.js +14 -0
  22. package/project/server/log/logger-console.js +36 -0
  23. package/project/server/log/logger.js +114 -0
  24. package/project/server/node/channel-input.js +65 -0
  25. package/project/server/node/channel-output.js +39 -0
  26. package/project/server/node/clients.js +80 -0
  27. package/project/server/node/connection-address.js +24 -0
  28. package/project/server/node/connection-data-ip.js +82 -0
  29. package/project/server/node/connection-data.js +25 -0
  30. package/project/server/node/const.js +44 -0
  31. package/project/server/node/external-services.js +209 -0
  32. package/project/server/node/http-cache.js +109 -0
  33. package/project/server/node/http-proxy.js +97 -0
  34. package/project/server/node/http-request-handler.js +219 -0
  35. package/project/server/node/http-server.js +36 -0
  36. package/project/server/node/http2-server.js +67 -0
  37. package/project/server/node/https-server.js +63 -0
  38. package/project/server/node/ip-client.js +98 -0
  39. package/project/server/node/ip-server.js +63 -0
  40. package/project/server/node/ip-subscription.js +46 -0
  41. package/project/server/node/message-channel.js +98 -0
  42. package/project/server/node/node-admin.js +513 -0
  43. package/project/server/node/node-data.js +25 -0
  44. package/project/server/node/node-settings.js +352 -0
  45. package/project/server/node/node-worker.js +76 -0
  46. package/project/server/node/node.js +156 -0
  47. package/project/server/node/servers.js +168 -0
  48. package/project/server/node/ws-client.js +12 -0
  49. package/project/server/node/ws-server.js +20 -0
  50. package/project/server/node/ws-web-server.js +52 -0
  51. package/project/server/node/wss-server.js +20 -0
  52. package/project/server/node/wss-web-server.js +82 -0
  53. package/project/server/path/actor-path-build.js +29 -0
  54. package/project/server/path/actor-path-content.js +51 -0
  55. package/project/server/path/actor-path-creator.js +90 -0
  56. package/project/server/path/actor-path-data.js +487 -0
  57. package/project/server/path/actor-path-dist.js +132 -0
  58. package/project/server/path/actor-path-generated.js +202 -0
  59. package/project/server/path/actor-path-project.js +181 -0
  60. package/project/server/path/actor-path.js +57 -0
  61. package/project/server/path/paths/actor-content-paths.js +34 -0
  62. package/project/server/path/paths/actor-data-paths.js +302 -0
  63. package/project/server/path/paths/actor-generated-paths.js +99 -0
  64. package/project/server/path/paths/actor-paths.js +22 -0
  65. package/project/server/plugin-base-multi.js +484 -0
  66. package/project/server/plugin-base.js +233 -0
  67. package/project/server/plugin-component.js +92 -0
  68. package/project/server/plugin-data/client/plugin_data_ClientGet.js +18 -0
  69. package/project/server/plugin-data/dialog-file/plugin_data_DialogFileGet.js +197 -0
  70. package/project/server/plugin-data/platform/plugin_data_PlatformPing.js +19 -0
  71. package/project/server/plugin-factor-protocol.js +35 -0
  72. package/project/server/plugin-factory.js +127 -0
  73. package/project/server/plugin-lock.js +164 -0
  74. package/project/server/response-queue.js +46 -0
  75. package/project/server/responses.js +20 -0
  76. package/project/server/service/plugin-service.js +264 -0
  77. package/project/server/service/service-export.js +47 -0
  78. package/project/server/service/service-manager.js +270 -0
  79. package/project/server/service/service-requests.js +49 -0
  80. package/project/server/session-cache.js +39 -0
  81. package/project/server/session.js +23 -0
  82. package/project/server/worker/worker-channel.js +175 -0
  83. package/project/server/worker/worker-core.js +58 -0
  84. package/project/server/worker/worker-main.js +165 -0
  85. package/project/server/worker/worker-pool.js +94 -0
  86. package/project/server/worker/worker-thread.js +128 -0
  87. package/project/z-abs-corelayer-server.tree +99 -0
@@ -0,0 +1,168 @@
1
+
2
+ 'use strict';
3
+
4
+ const Const = require('./const');
5
+ const HttpCache = require('./http-cache');
6
+ const HttpServer = require('./http-server');
7
+ const HttpsServer = require('./https-server');
8
+ const Http2Server = require('./http2-server');
9
+ const WsServer = require('./ws-server');
10
+ const WssServer = require('./wss-server');
11
+ const WsWebServer = require('./ws-web-server');
12
+ const TcpServer = tryRequire('z-abs-corelayer-bs/server/node/tcp-server');
13
+ const TlsServer = tryRequire('z-abs-corelayer-bs/server/node/tls-server');
14
+ const IpProxy = tryRequire('z-abs-corelayer-bs/server/node/ip-proxy');
15
+ const HttpProxy = tryRequire('z-abs-corelayer-bs/server/node/http-proxy');
16
+ const HttpProxyServer = tryRequire('z-abs-corelayer-bs/server/node/http-proxy-server');
17
+ const HttpsProxyServer = tryRequire('z-abs-corelayer-bs/server/node/https-proxy-server');
18
+ const Http2ProxyServer = tryRequire('z-abs-corelayer-bs/server/node/http2-proxy-server');
19
+
20
+
21
+ class Servers {
22
+ constructor(nodeName, nodeId, nodeSettings, defaultSite, dataResponse) {
23
+ this.nodeName = nodeName;
24
+ this.nodeId = nodeId;
25
+ this.nodeSettings = nodeSettings;
26
+ this.defaultSite = defaultSite;
27
+ this.dataResponse = dataResponse;
28
+ this.proxyServerDatas = [];
29
+ this.httpCache = new HttpCache();
30
+ this.servers = new Map();
31
+ }
32
+
33
+ create() {
34
+ if(0 === this.nodeSettings.wsWebServers.length && 0 === this.nodeSettings.httpServers.length && 0 === this.nodeSettings.httpsServers.length && 0 === this.nodeSettings.http2Servers.length && 0 === this.nodeSettings.tcpServers.length && 0 === this.nodeSettings.tlsServers.length && 0 === this.nodeSettings.wsServers.length && 0 === this.nodeSettings.wssServers.length && 0 === this.nodeSettings.ipProxyServers.length) {
35
+ return;
36
+ }
37
+ if(0 !== this.nodeSettings.httpServers.length) {
38
+ this.nodeSettings.httpServers.forEach((httpServerData) => {
39
+ const httpServer = new HttpServer(httpServerData, this.nodeName, this.nodeId, this.httpCache, this.dataResponse, this.defaultSite);
40
+ this.servers.set(httpServerData.name, httpServer);
41
+ });
42
+ }
43
+ if(0 !== this.nodeSettings.httpsServers.length) {
44
+ this.nodeSettings.httpsServers.forEach((httpsServerData) => {
45
+ const httpsServer = new HttpsServer(httpsServerData, this.nodeName, this.nodeId, this.httpCache, this.dataResponse, this.localServices, this.defaultSite);
46
+ this.servers.set(httpsServerData.name, httpsServer);
47
+ });
48
+ }
49
+ if(0 !== this.nodeSettings.http2Servers.length) {
50
+ this.nodeSettings.http2Servers.forEach((http2ServerData) => {
51
+ const httpsServer = new Http2Server(http2ServerData, this.nodeName, this.nodeId, this.httpCache, this.dataResponse, this.localServices, this.defaultSite);
52
+ this.servers.set(http2ServerData.name, httpsServer);
53
+ });
54
+ }
55
+ if(TcpServer && 0 !== this.nodeSettings.tcpServers.length) {
56
+ this.nodeSettings.tcpServers.forEach((tcpServerData) => {
57
+ this._createIpServer(Const.TRANSPORT_TCP, this.dataResponse, tcpServerData);
58
+ });
59
+ }
60
+ if(TlsServer && 0 !== this.nodeSettings.tlsServers.length) {
61
+ this.nodeSettings.tlsServers.forEach((tlsServerData) => {
62
+ this._createIpServer(Const.TRANSPORT_TLS, this.dataResponse, tlsServerData);
63
+ });
64
+ }
65
+ if(0 !== this.nodeSettings.wsServers.length) {
66
+ this.nodeSettings.wsServers.forEach((wsServerData) => {
67
+ this._createIpServer(Const.TRANSPORT_WS, this.dataResponse, wsServerData);
68
+ });
69
+ }
70
+ if(0 !== this.nodeSettings.wssServers.length) {
71
+ this.nodeSettings.wssServers.forEach((wssServerData) => {
72
+ this._createIpServer(Const.TRANSPORT_WSS, this.dataResponse, wssServerData);
73
+ });
74
+ }
75
+ if(IpProxy && 0 !== this.nodeSettings.ipProxyServers.length) {
76
+ this.nodeSettings.ipProxyServers.forEach((proxyServerData) => {
77
+ const ipProxy = new IpProxy(this.nodeName, this.nodeId);
78
+ this._createIpServer(proxyServerData.frontend.type, ipProxy.ipProxyFrontend, proxyServerData.frontend.settings);
79
+ this._createIpServer(proxyServerData.backend.type, ipProxy.ipProxyBackend, proxyServerData.backend.settings);
80
+ });
81
+ }
82
+ if(HttpProxy && 0 !== this.nodeSettings.httpProxyServers.length) {
83
+ this.nodeSettings.httpProxyServers.forEach((proxyServerData) => {
84
+ const httpProxy = new HttpProxy(this.nodeName, this.nodeId, proxyServerData.backends);
85
+ this._createHttpProxyServer(proxyServerData.frontend.type, httpProxy, proxyServerData.frontend.settings);
86
+ });
87
+ }
88
+ if(0 !== this.nodeSettings.wsWebServers.length) {
89
+ this.nodeSettings.wsWebServers.forEach((wsWebServerData) => {
90
+ const wsWebServer = new WsWebServer(wsWebServerData, this.nodeName, this.nodeId, this.dataResponse);
91
+ this.servers.set(wsWebServerData.name, wsWebServer);
92
+ });
93
+ }
94
+ }
95
+
96
+ start(cb) {
97
+ let pendings = this.servers.size;
98
+ if(0 === pendings) {
99
+ process.nextTick(cb);
100
+ return;
101
+ }
102
+ this.servers.forEach((server) => {
103
+ server.start(server.serverData, () => {
104
+ if(0 === --pendings) {
105
+ cb();
106
+ }
107
+ });
108
+ });
109
+ }
110
+
111
+ subscribeOnConnectionEvents(guid, eventType, name, cb) {
112
+ const server = this.servers.get(name);
113
+ if(server) {
114
+ server.ipServer.dataResponse.ipSubscription.subscribeOnConnectionEvents(guid, eventType, name, cb);
115
+ }
116
+ }
117
+
118
+ unsubscribeOnConnectionEvents(guid, eventType, name) {
119
+ const server = this.servers.get(name);
120
+ if(server) {
121
+ server.ipServer.dataResponse.ipSubscription.unsubscribeOnConnectionEvents(guid, eventType, name);
122
+ }
123
+ }
124
+
125
+ _createIpServer(type, channel, serverData) {
126
+ let server = null;
127
+ if(Const.TRANSPORT_TCP === type) {
128
+ server = new TcpServer(serverData.name, serverData, this.nodeName, this.nodeId, channel);
129
+ }
130
+ else if(Const.TRANSPORT_TLS === type) {
131
+ server = new TlsServer(serverData.name, serverData, this.nodeName, this.nodeId, channel);
132
+ }
133
+ else if(Const.TRANSPORT_WS === type) {
134
+ server = new WsServer(serverData.name, serverData, this.nodeName, this.nodeId, channel);
135
+ }
136
+ else if(Const.TRANSPORT_WSS === type) {
137
+ server = new WssServer(serverData.name, serverData, this.nodeName, this.nodeId, channel);
138
+ }
139
+ if(server) {
140
+ this.servers.set(serverData.name, server);
141
+ }
142
+ else {
143
+ console.log('ERROR');
144
+ }
145
+ }
146
+
147
+ _createHttpProxyServer(type, httpProxy, serverData) {
148
+ let server = null;
149
+ if(Const.TRANSPORT_HTTP === type) {
150
+ server = new HttpProxyServer(serverData.name, serverData, httpProxy);
151
+ }
152
+ else if(Const.TRANSPORT_HTTPS === type) {
153
+ server = new HttpsProxyServer(serverData.name, serverData, httpProxy);
154
+ }
155
+ else if(Const.TRANSPORT_HTTP2 === type) {
156
+ server = new Http2ProxyServer(serverData.name, serverData, httpProxy);
157
+ }
158
+ if(server) {
159
+ this.servers.set(serverData.name, server);
160
+ }
161
+ else {
162
+ console.log('ERROR');
163
+ }
164
+ }
165
+ }
166
+
167
+
168
+ module.exports = Servers;
@@ -0,0 +1,12 @@
1
+
2
+ 'use strict';
3
+
4
+
5
+ class WsClient {
6
+ constructor() {
7
+
8
+ }
9
+ }
10
+
11
+
12
+ module.exports = WsClient;
@@ -0,0 +1,20 @@
1
+
2
+ 'use strict';
3
+
4
+ const Const = require('./const');
5
+ const ConnectionAddress = require('./connection-address');
6
+ const IpServer = require('./ip-server');
7
+ const PluginFactoryProtocol = require('../plugin-factor-protocol');
8
+
9
+
10
+ class WsServer {
11
+ constructor(name, serverData, nodeName, nodeId, dataResponse) {
12
+ this.transport = Const.TRANSPORT_WS;
13
+ this.name = name;
14
+ this.serverData = serverData;
15
+ this.ipServer = new IpServer(this, nodeName, nodeId, dataResponse, serverData.protocols);
16
+ }
17
+ }
18
+
19
+
20
+ module.exports = WsServer;
@@ -0,0 +1,52 @@
1
+
2
+ 'use strict';
3
+
4
+ const Const = require('./const');
5
+ const DataResponse = require('../data-response');
6
+ const PluginFactoryProtocol = require('../plugin-factor-protocol');
7
+ const WebSocketServer = require('ws').Server;
8
+
9
+
10
+ class WsWebServer {
11
+ constructor(serverData, nodeName, nodeId, dataResponse) {
12
+ this.serverData = serverData;
13
+ this.nodeName = nodeName;
14
+ this.nodeId = nodeId;
15
+ this.dataResponse = dataResponse;
16
+ this.protocols = serverData.protocols;
17
+ this.pluginFactoryProtocol = new PluginFactoryProtocol();
18
+ }
19
+
20
+ start(wsData, cb) {
21
+ this.pluginFactoryProtocol.load(this.protocols, () => {
22
+ wsData.server = new WebSocketServer({
23
+ perMessageDeflate: false,
24
+ host: wsData.host,
25
+ port: wsData.port
26
+ }, () => {
27
+ ddb.writelnTime(ddb.cyan('Server: '), `${this.nodeName}-${wsData.name}`, ddb.green(' started at'), ` http://${wsData.host}:${wsData.port}`);
28
+ cb();
29
+ });
30
+ wsData.server.on('connection', (ws) => {
31
+ ws.on('message', (msgIn) => {
32
+ this.dataResponse.onMessage(msgIn, connectionData);
33
+ });
34
+ ws.on('close', () => {
35
+ this.dataResponse.onConnectionClose(Const.CONNECTION_TYPE_SERVER_WEB, connectionData);
36
+ });
37
+ const connectionData = this.dataResponse.onConnectionConnected(Const.CONNECTION_TYPE_SERVER_WEB, (buffer) => {
38
+ ws.send(buffer);
39
+ });
40
+ this.pluginFactoryProtocol.register(connectionData.channelInput, connectionData.channelOutput);
41
+ });
42
+ wsData.server.on('error', (err) => {
43
+ const date = new Date();
44
+ ddb.writelnTimeError(err, ddb.red('Server:'), ` '${this.nodeName}-${wsData.name}'`, ddb.red(' did not start at'), ` http://${wsData.host}:${wsData.port}` + ddb.red('. Error: '), err.message);
45
+ cb(err);
46
+ });
47
+ });
48
+ }
49
+ }
50
+
51
+
52
+ module.exports = WsWebServer;
@@ -0,0 +1,20 @@
1
+
2
+ 'use strict';
3
+
4
+ const Const = require('./const');
5
+ const ConnectionAddress = require('./connection-address');
6
+ const IpServer = require('./ip-server');
7
+ const PluginFactoryProtocol = require('../plugin-factor-protocol');
8
+
9
+
10
+ class WssServer {
11
+ constructor(name, serverData, nodeName, nodeId, dataResponse) {
12
+ this.transport = Const.TRANSPORT_WSS;
13
+ this.name = name;
14
+ this.serverData = serverData;
15
+ this.ipServer = new IpServer(this, nodeName, nodeId, dataResponse, serverData.protocols);
16
+ }
17
+ }
18
+
19
+
20
+ module.exports = WssServer;
@@ -0,0 +1,82 @@
1
+
2
+ 'use strict';
3
+
4
+ const Const = require('./const');
5
+ const DataResponse = require('../data-response');
6
+ const PluginFactoryProtocol = require('../plugin-factor-protocol');
7
+ const WebSocketServer = require('ws').Server;
8
+ const Https = require ('https');
9
+
10
+
11
+ class WssWebServer {
12
+ constructor(serverData, nodeName, nodeId, dataResponse) {
13
+ this.serverData = serverData;
14
+ this.nodeName = nodeName;
15
+ this.nodeId = nodeId;
16
+ this.dataResponse = dataResponse;
17
+ this.protocols = serverData.protocols;
18
+ this.pluginFactoryProtocol = new PluginFactoryProtocol();
19
+ }
20
+
21
+ start(wssData, cb) {
22
+ this.pluginFactoryProtocol.load(this.protocols, () => {
23
+ const options = this._readKeys(wssData);
24
+ if(options) {
25
+ const httpsServer = https.createServer(options);
26
+ server.listen(wssData.port, wssData.host);
27
+ wssData.server = new WebSocketServer({
28
+ perMessageDeflate: false,
29
+ server: httpsServer
30
+ }, () => {
31
+ ddb.writelnTime(ddb.cyan('Server: '), `${this.nodeName}-${wssData.name}`, ddb.green(' started at'), ` https://${wssData.host}:${wssData.port}`);
32
+ cb();
33
+ });
34
+ wssData.server.on('connection', (ws) => {
35
+ ws.on('message', (msgIn) => {
36
+ this.dataResponse.onMessage(msgIn, connectionData);
37
+ });
38
+ ws.on('close', () => {
39
+ this.dataResponse.onConnectionClose(Const.CONNECTION_TYPE_SERVER_WEB, connectionData);
40
+ });
41
+ const connectionData = this.dataResponse.onConnectionConnected(Const.CONNECTION_TYPE_SERVER_WEB, (buffer) => {
42
+ ws.send(buffer);
43
+ });
44
+ this.pluginFactoryProtocol.register(connectionData.channelInput, connectionData.channelOutput);
45
+ });
46
+ wssData.server.on('error', (err) => {
47
+ const date = new Date();
48
+ ddb.writelnTimeError(err, ddb.red('Server:'), ` '${this.nodeName}-${wssData.name}'`, ddb.red(' did not start at'), ` https://${wssData.host}:${wssData.port}` + ddb.red('. Error: '), err.message);
49
+ cb(err);
50
+ });
51
+ });
52
+ }
53
+ else {
54
+ const err = new Error('-----');
55
+ ddb.writelnTimeError(err, ddb.red('Server:'), ` '${this.nodeName}-${wssData.name}'`, ddb.red(' did not start at'), ` https://${wssData.host}:${wssData.port}` + ddb.red('. No SSL keys.'));
56
+ cb(err);
57
+ }
58
+ }
59
+
60
+ _readKeys(wssData) {
61
+ if(wssData.keyFile && wssData.certFile) {
62
+ try {
63
+ const keyFile = Fs.readFileSync(wssData.keyFile);
64
+ const certFile = Fs.readFileSync(wssData.certFile);
65
+ return {
66
+ key: keyFile,
67
+ cert: certFile
68
+ };
69
+ }
70
+ catch(err) {
71
+ ddb.writelnTimeError(ddb.red(`Could not get cert and key file, error:`), err);
72
+ return null;
73
+ }
74
+ }
75
+ else {
76
+ return null;
77
+ }
78
+ }
79
+ }
80
+
81
+
82
+ module.exports = WssWebServer;
@@ -0,0 +1,29 @@
1
+
2
+ 'use strict';
3
+
4
+ const ActorPath = require('./actor-path');
5
+ const Path = require('path');
6
+
7
+
8
+ class ActorPathBuild {
9
+ constructor() {
10
+ this.actorBuildPath = ActorPath.setPath(ActorPath.getActorPath(), `${Path.sep}build`);
11
+ }
12
+
13
+ getActorBuildPath() {
14
+ return this.actorBuildPath;
15
+ }
16
+
17
+ getCodeFile(file, projectType) {
18
+ if(!projectType) {
19
+ const fileName = file.substring('./project/'.length);
20
+ return Path.normalize(`${this.getActorBuildPath()}${Path.sep}AppLayer${Path.sep}${fileName.replace(new RegExp('[/\\\\]', 'g'), Path.sep)}`);
21
+ }
22
+ else {
23
+ return Path.normalize(`${this.getActorBuildPath()}${Path.sep}${file.replace(new RegExp('[/\\\\]', 'g'), Path.sep)}`);
24
+ }
25
+ }
26
+ }
27
+
28
+
29
+ module.exports = new ActorPathBuild();
@@ -0,0 +1,51 @@
1
+
2
+ 'use strict';
3
+
4
+ const ActorPath = require('./actor-path');
5
+ const Path = require('path');
6
+
7
+
8
+ class ActorPathContent {
9
+ constructor() {
10
+ if(ActorPath.releaseStepDelivery) {
11
+ this.contentFolder = ActorPath.setPath(ActorPath.getActorPath(), `..${Path.sep}..${Path.sep}..${Path.sep}Content`);
12
+ this.contentGlobalFolder = ActorPath.setPath(ActorPath.getActorPath(), `${Path.sep}node_modules${Path.sep}${ActorPath.organization}${Path.sep}actorjs-content-global`);
13
+ }
14
+ else if(ActorPath.releaseStepCandidate) {
15
+ this.contentFolder = ActorPath.setPath(ActorPath.getActorPath(), `..${Path.sep}Content`);
16
+ this.contentGlobalFolder = ActorPath.setPath(ActorPath.getActorPath(), `${Path.sep}node_modules${Path.sep}actorjs-content-global`);
17
+ }
18
+ else {
19
+ this.contentFolder = ActorPath.setPath(ActorPath.getActorPath(), `..${Path.sep}Content`);
20
+ this.contentGlobalFolder = ActorPath.setPath(this.contentFolder, `${Path.sep}actorjs-content-global`);
21
+ }
22
+
23
+ // *** LOCAL
24
+
25
+ this.contentLocalFolder = ActorPath.setPath(this.contentFolder, `${Path.sep}actorjs-content-local`);
26
+ this.contentLocalReadMeFile = ActorPath.setPath(this.contentLocalFolder, `${Path.sep}README.md`);
27
+ }
28
+
29
+ getContentFolder() {
30
+ return this.contentFolder;
31
+ }
32
+
33
+ getContentLocalFolder() {
34
+ return this.contentLocalFolder;
35
+ }
36
+
37
+ getContentGlobalFolder() {
38
+ return this.contentGlobalFolder;
39
+ }
40
+
41
+ getContentFile(repoPath, path) {
42
+ return Path.normalize(`${repoPath}${Path.sep}${path}`);
43
+ }
44
+
45
+ getReadMeFile() {
46
+ return this.contentLocalReadMeFile;
47
+ }
48
+ }
49
+
50
+
51
+ module.exports = new ActorPathContent();
@@ -0,0 +1,90 @@
1
+
2
+ 'use strict';
3
+
4
+ const Fs = require('fs');
5
+
6
+
7
+ class ActorPathCreator {
8
+ constructor(folderPaths, filePaths) {
9
+ this.folderPaths = folderPaths;
10
+ this.filePaths = filePaths;
11
+ this.indexFolder = this.folderPaths.length;
12
+ this.indexFile = this.filePaths.length;
13
+ }
14
+
15
+ verifyOrCreate(done) {
16
+ if(0 !== this.indexFolder) {
17
+ this.verifyOrCreateFolders((errorsFolder) => {
18
+ if(0 !== errorsFolder.length) {
19
+ done(errorsFolder);
20
+ }
21
+ else {
22
+ if(0 !== this.indexFile) {
23
+ this.verifyOrCreateFiles((errorsFile) => {
24
+ done(0 !== errorsFile.length ? errorsFile : undefined);
25
+ });
26
+ }
27
+ else {
28
+ process.nextTick(done);
29
+ }
30
+ }
31
+ });
32
+ }
33
+ else {
34
+ process.nextTick(done);
35
+ }
36
+ }
37
+
38
+ verifyOrCreateFolders(done) {
39
+ let pendings = 0;
40
+ const errors = [];
41
+ this.folderPaths.forEach((folder) => {
42
+ ++pendings;
43
+ Fs.access(folder, Fs.constants.R_OK | Fs.constants.W_OK, (err) => {
44
+ if(err) {
45
+ Fs.mkdir(folder, { recursive: true }, (e) => {
46
+ if(e) {
47
+ errors.push(e);
48
+ }
49
+ if(0 === --pendings) {
50
+ done(errors);
51
+ }
52
+ });
53
+ }
54
+ else {
55
+ if(0 === --pendings) {
56
+ done(errors);
57
+ }
58
+ }
59
+ });
60
+ });
61
+ }
62
+
63
+ verifyOrCreateFiles(done) {
64
+ let pendings = 0;
65
+ const errors = [];
66
+ this.filePaths.forEach((file) => {
67
+ ++pendings;
68
+ Fs.access(file.path, Fs.constants.R_OK | Fs.constants.W_OK, (err) => {
69
+ if(err) {
70
+ Fs.writeFile(file.path, file.default ? JSON.stringify(file.default, null, 2) : file.text, (e) => {
71
+ if(e) {
72
+ errors.push(e);
73
+ }
74
+ if(0 === --pendings) {
75
+ done(errors);
76
+ }
77
+ });
78
+ }
79
+ else {
80
+ if(0 === --pendings) {
81
+ done(errors);
82
+ }
83
+ }
84
+ });
85
+ });
86
+ }
87
+ }
88
+
89
+
90
+ module.exports = ActorPathCreator;