@teambit/ui 0.0.881 → 0.0.883
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.
- package/dist/create-root.js +2 -26
- package/dist/create-root.js.map +1 -1
- package/dist/events/index.js +0 -2
- package/dist/events/index.js.map +1 -1
- package/dist/events/ui-server-started-event.js +1 -12
- package/dist/events/ui-server-started-event.js.map +1 -1
- package/dist/exceptions/index.js +0 -6
- package/dist/exceptions/index.js.map +1 -1
- package/dist/exceptions/unknown-build-error.js +0 -3
- package/dist/exceptions/unknown-build-error.js.map +1 -1
- package/dist/exceptions/unknown-ui.js +0 -5
- package/dist/exceptions/unknown-ui.js.map +1 -1
- package/dist/index.js +0 -14
- package/dist/index.js.map +1 -1
- package/dist/ssr-middleware/index.js +0 -3
- package/dist/ssr-middleware/index.js.map +1 -1
- package/dist/ssr-middleware/ssr-middleware.js +0 -39
- package/dist/ssr-middleware/ssr-middleware.js.map +1 -1
- package/dist/start.cmd.js +8 -30
- package/dist/start.cmd.js.map +1 -1
- package/dist/ui/client-context.js +1 -27
- package/dist/ui/client-context.js.map +1 -1
- package/dist/ui-build.cmd.js +0 -13
- package/dist/ui-build.cmd.js.map +1 -1
- package/dist/ui-server.js +22 -83
- package/dist/ui-server.js.map +1 -1
- package/dist/ui.aspect.js +0 -6
- package/dist/ui.aspect.js.map +1 -1
- package/dist/ui.cli.rt.js +1 -0
- package/dist/ui.cli.rt.js.map +1 -1
- package/dist/ui.composition.js +0 -6
- package/dist/ui.composition.js.map +1 -1
- package/dist/ui.main.runtime.js +15 -150
- package/dist/ui.main.runtime.js.map +1 -1
- package/dist/ui.runtime.js +1 -0
- package/dist/ui.runtime.js.map +1 -1
- package/dist/ui.ui.runtime.js +9 -49
- package/dist/ui.ui.runtime.js.map +1 -1
- package/dist/webpack/html.js +0 -1
- package/dist/webpack/html.js.map +1 -1
- package/dist/webpack/postcss.config.js +7 -3
- package/dist/webpack/postcss.config.js.map +1 -1
- package/dist/webpack/webpack.base.config.js +45 -65
- package/dist/webpack/webpack.base.config.js.map +1 -1
- package/dist/webpack/webpack.browser.config.js +3 -31
- package/dist/webpack/webpack.browser.config.js.map +1 -1
- package/dist/webpack/webpack.dev.config.js +25 -63
- package/dist/webpack/webpack.dev.config.js.map +1 -1
- package/dist/webpack/webpack.ssr.config.js +5 -14
- package/dist/webpack/webpack.ssr.config.js.map +1 -1
- package/package-tar/teambit-ui-0.0.883.tgz +0 -0
- package/package.json +10 -10
- package/{preview-1666409808293.js → preview-1666582798766.js} +2 -2
- package/package-tar/teambit-ui-0.0.881.tgz +0 -0
package/dist/ui.main.runtime.js
CHANGED
|
@@ -1,278 +1,195 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.array.iterator.js");
|
|
6
|
-
|
|
7
5
|
require("core-js/modules/es.array.sort.js");
|
|
8
|
-
|
|
9
6
|
require("core-js/modules/es.promise.js");
|
|
10
|
-
|
|
11
7
|
Object.defineProperty(exports, "__esModule", {
|
|
12
8
|
value: true
|
|
13
9
|
});
|
|
14
10
|
exports.UiMain = void 0;
|
|
15
|
-
|
|
16
11
|
function _defineProperty2() {
|
|
17
12
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
|
-
|
|
19
13
|
_defineProperty2 = function () {
|
|
20
14
|
return data;
|
|
21
15
|
};
|
|
22
|
-
|
|
23
16
|
return data;
|
|
24
17
|
}
|
|
25
|
-
|
|
26
18
|
function _cache() {
|
|
27
19
|
const data = require("@teambit/cache");
|
|
28
|
-
|
|
29
20
|
_cache = function () {
|
|
30
21
|
return data;
|
|
31
22
|
};
|
|
32
|
-
|
|
33
23
|
return data;
|
|
34
24
|
}
|
|
35
|
-
|
|
36
25
|
function _cli() {
|
|
37
26
|
const data = require("@teambit/cli");
|
|
38
|
-
|
|
39
27
|
_cli = function () {
|
|
40
28
|
return data;
|
|
41
29
|
};
|
|
42
|
-
|
|
43
30
|
return data;
|
|
44
31
|
}
|
|
45
|
-
|
|
46
32
|
function _component() {
|
|
47
33
|
const data = require("@teambit/component");
|
|
48
|
-
|
|
49
34
|
_component = function () {
|
|
50
35
|
return data;
|
|
51
36
|
};
|
|
52
|
-
|
|
53
37
|
return data;
|
|
54
38
|
}
|
|
55
|
-
|
|
56
39
|
function _express() {
|
|
57
40
|
const data = require("@teambit/express");
|
|
58
|
-
|
|
59
41
|
_express = function () {
|
|
60
42
|
return data;
|
|
61
43
|
};
|
|
62
|
-
|
|
63
44
|
return data;
|
|
64
45
|
}
|
|
65
|
-
|
|
66
46
|
function _graphql() {
|
|
67
47
|
const data = require("@teambit/graphql");
|
|
68
|
-
|
|
69
48
|
_graphql = function () {
|
|
70
49
|
return data;
|
|
71
50
|
};
|
|
72
|
-
|
|
73
51
|
return data;
|
|
74
52
|
}
|
|
75
|
-
|
|
76
53
|
function _chalk() {
|
|
77
54
|
const data = _interopRequireDefault(require("chalk"));
|
|
78
|
-
|
|
79
55
|
_chalk = function () {
|
|
80
56
|
return data;
|
|
81
57
|
};
|
|
82
|
-
|
|
83
58
|
return data;
|
|
84
59
|
}
|
|
85
|
-
|
|
86
60
|
function _harmony() {
|
|
87
61
|
const data = require("@teambit/harmony");
|
|
88
|
-
|
|
89
62
|
_harmony = function () {
|
|
90
63
|
return data;
|
|
91
64
|
};
|
|
92
|
-
|
|
93
65
|
return data;
|
|
94
66
|
}
|
|
95
|
-
|
|
96
67
|
function _logger() {
|
|
97
68
|
const data = require("@teambit/logger");
|
|
98
|
-
|
|
99
69
|
_logger = function () {
|
|
100
70
|
return data;
|
|
101
71
|
};
|
|
102
|
-
|
|
103
72
|
return data;
|
|
104
73
|
}
|
|
105
|
-
|
|
106
74
|
function _pubsub() {
|
|
107
75
|
const data = _interopRequireDefault(require("@teambit/pubsub"));
|
|
108
|
-
|
|
109
76
|
_pubsub = function () {
|
|
110
77
|
return data;
|
|
111
78
|
};
|
|
112
|
-
|
|
113
79
|
return data;
|
|
114
80
|
}
|
|
115
|
-
|
|
116
81
|
function _utils() {
|
|
117
82
|
const data = require("@teambit/legacy/dist/utils");
|
|
118
|
-
|
|
119
83
|
_utils = function () {
|
|
120
84
|
return data;
|
|
121
85
|
};
|
|
122
|
-
|
|
123
86
|
return data;
|
|
124
87
|
}
|
|
125
|
-
|
|
126
88
|
function _pMapSeries() {
|
|
127
89
|
const data = _interopRequireDefault(require("p-map-series"));
|
|
128
|
-
|
|
129
90
|
_pMapSeries = function () {
|
|
130
91
|
return data;
|
|
131
92
|
};
|
|
132
|
-
|
|
133
93
|
return data;
|
|
134
94
|
}
|
|
135
|
-
|
|
136
95
|
function _fsExtra() {
|
|
137
96
|
const data = _interopRequireDefault(require("fs-extra"));
|
|
138
|
-
|
|
139
97
|
_fsExtra = function () {
|
|
140
98
|
return data;
|
|
141
99
|
};
|
|
142
|
-
|
|
143
100
|
return data;
|
|
144
101
|
}
|
|
145
|
-
|
|
146
102
|
function _toolboxNetwork() {
|
|
147
103
|
const data = require("@teambit/toolbox.network.get-port");
|
|
148
|
-
|
|
149
104
|
_toolboxNetwork = function () {
|
|
150
105
|
return data;
|
|
151
106
|
};
|
|
152
|
-
|
|
153
107
|
return data;
|
|
154
108
|
}
|
|
155
|
-
|
|
156
109
|
function _path() {
|
|
157
110
|
const data = require("path");
|
|
158
|
-
|
|
159
111
|
_path = function () {
|
|
160
112
|
return data;
|
|
161
113
|
};
|
|
162
|
-
|
|
163
114
|
return data;
|
|
164
115
|
}
|
|
165
|
-
|
|
166
116
|
function _util() {
|
|
167
117
|
const data = require("util");
|
|
168
|
-
|
|
169
118
|
_util = function () {
|
|
170
119
|
return data;
|
|
171
120
|
};
|
|
172
|
-
|
|
173
121
|
return data;
|
|
174
122
|
}
|
|
175
|
-
|
|
176
123
|
function _webpack() {
|
|
177
124
|
const data = _interopRequireDefault(require("webpack"));
|
|
178
|
-
|
|
179
125
|
_webpack = function () {
|
|
180
126
|
return data;
|
|
181
127
|
};
|
|
182
|
-
|
|
183
128
|
return data;
|
|
184
129
|
}
|
|
185
|
-
|
|
186
130
|
function _events() {
|
|
187
131
|
const data = require("./events");
|
|
188
|
-
|
|
189
132
|
_events = function () {
|
|
190
133
|
return data;
|
|
191
134
|
};
|
|
192
|
-
|
|
193
135
|
return data;
|
|
194
136
|
}
|
|
195
|
-
|
|
196
137
|
function _createRoot() {
|
|
197
138
|
const data = require("./create-root");
|
|
198
|
-
|
|
199
139
|
_createRoot = function () {
|
|
200
140
|
return data;
|
|
201
141
|
};
|
|
202
|
-
|
|
203
142
|
return data;
|
|
204
143
|
}
|
|
205
|
-
|
|
206
144
|
function _exceptions() {
|
|
207
145
|
const data = require("./exceptions");
|
|
208
|
-
|
|
209
146
|
_exceptions = function () {
|
|
210
147
|
return data;
|
|
211
148
|
};
|
|
212
|
-
|
|
213
149
|
return data;
|
|
214
150
|
}
|
|
215
|
-
|
|
216
151
|
function _start() {
|
|
217
152
|
const data = require("./start.cmd");
|
|
218
|
-
|
|
219
153
|
_start = function () {
|
|
220
154
|
return data;
|
|
221
155
|
};
|
|
222
|
-
|
|
223
156
|
return data;
|
|
224
157
|
}
|
|
225
|
-
|
|
226
158
|
function _uiBuild() {
|
|
227
159
|
const data = require("./ui-build.cmd");
|
|
228
|
-
|
|
229
160
|
_uiBuild = function () {
|
|
230
161
|
return data;
|
|
231
162
|
};
|
|
232
|
-
|
|
233
163
|
return data;
|
|
234
164
|
}
|
|
235
|
-
|
|
236
165
|
function _uiServer() {
|
|
237
166
|
const data = require("./ui-server");
|
|
238
|
-
|
|
239
167
|
_uiServer = function () {
|
|
240
168
|
return data;
|
|
241
169
|
};
|
|
242
|
-
|
|
243
170
|
return data;
|
|
244
171
|
}
|
|
245
|
-
|
|
246
172
|
function _ui() {
|
|
247
173
|
const data = require("./ui.aspect");
|
|
248
|
-
|
|
249
174
|
_ui = function () {
|
|
250
175
|
return data;
|
|
251
176
|
};
|
|
252
|
-
|
|
253
177
|
return data;
|
|
254
178
|
}
|
|
255
|
-
|
|
256
179
|
function _webpackBrowser() {
|
|
257
180
|
const data = _interopRequireDefault(require("./webpack/webpack.browser.config"));
|
|
258
|
-
|
|
259
181
|
_webpackBrowser = function () {
|
|
260
182
|
return data;
|
|
261
183
|
};
|
|
262
|
-
|
|
263
184
|
return data;
|
|
264
185
|
}
|
|
265
|
-
|
|
266
186
|
function _webpackSsr() {
|
|
267
187
|
const data = _interopRequireDefault(require("./webpack/webpack.ssr.config"));
|
|
268
|
-
|
|
269
188
|
_webpackSsr = function () {
|
|
270
189
|
return data;
|
|
271
190
|
};
|
|
272
|
-
|
|
273
191
|
return data;
|
|
274
192
|
}
|
|
275
|
-
|
|
276
193
|
class UiMain {
|
|
277
194
|
constructor(
|
|
278
195
|
/**
|
|
@@ -337,22 +254,17 @@ class UiMain {
|
|
|
337
254
|
return new (_events().UiServerStartedEvent)(Date.now(), targetHost, targetPort, uiRoot);
|
|
338
255
|
});
|
|
339
256
|
}
|
|
340
|
-
|
|
341
257
|
async publicDir(uiRoot) {
|
|
342
258
|
const overwriteFn = this.getOverwritePublic();
|
|
343
|
-
|
|
344
259
|
if (overwriteFn) {
|
|
345
260
|
const hasDir = await overwriteFn(uiRoot);
|
|
346
261
|
if (hasDir) return hasDir;
|
|
347
262
|
}
|
|
348
|
-
|
|
349
263
|
if (this.config.publicDir.startsWith('/')) {
|
|
350
264
|
return this.config.publicDir.substring(1);
|
|
351
265
|
}
|
|
352
|
-
|
|
353
266
|
return this.config.publicDir;
|
|
354
267
|
}
|
|
355
|
-
|
|
356
268
|
getUiByName(name) {
|
|
357
269
|
const roots = this.uiRootSlot.toArray();
|
|
358
270
|
const [, root] = roots.find(([, uiRoot]) => {
|
|
@@ -360,20 +272,19 @@ class UiMain {
|
|
|
360
272
|
}) || [];
|
|
361
273
|
return root;
|
|
362
274
|
}
|
|
275
|
+
|
|
363
276
|
/**
|
|
364
277
|
* create a build of the given UI root.
|
|
365
278
|
*/
|
|
366
|
-
|
|
367
|
-
|
|
368
279
|
async build(uiRootName) {
|
|
369
280
|
var _uiRoot$buildOptions;
|
|
370
|
-
|
|
371
281
|
// TODO: change to MultiStats from webpack once they export it in their types
|
|
372
282
|
this.logger.debug(`build, uiRootName: "${uiRootName}"`);
|
|
373
283
|
const maybeUiRoot = this.getUi(uiRootName);
|
|
374
284
|
if (!maybeUiRoot) throw new (_exceptions().UnknownUI)(uiRootName, this.possibleUis());
|
|
375
|
-
const [name, uiRoot] = maybeUiRoot;
|
|
285
|
+
const [name, uiRoot] = maybeUiRoot;
|
|
376
286
|
|
|
287
|
+
// TODO: @uri refactor all dev server related code to use the bundler extension instead.
|
|
377
288
|
const ssr = ((_uiRoot$buildOptions = uiRoot.buildOptions) === null || _uiRoot$buildOptions === void 0 ? void 0 : _uiRoot$buildOptions.ssr) || false;
|
|
378
289
|
const mainEntry = await this.generateRoot(await uiRoot.resolveAspects(_ui().UIRuntime.name), name);
|
|
379
290
|
const browserConfig = (0, _webpackBrowser().default)(uiRoot.path, [mainEntry], uiRoot.name, await this.publicDir(uiRoot));
|
|
@@ -385,30 +296,25 @@ class UiMain {
|
|
|
385
296
|
const results = await compilerRun();
|
|
386
297
|
this.logger.debug(`build, uiRootName: "${uiRootName}" completed webpack`);
|
|
387
298
|
if (!results) throw new (_exceptions().UnknownBuildError)();
|
|
388
|
-
|
|
389
299
|
if (results !== null && results !== void 0 && results.hasErrors()) {
|
|
390
300
|
this.clearConsole();
|
|
391
301
|
throw new Error(results === null || results === void 0 ? void 0 : results.toString());
|
|
392
302
|
}
|
|
393
|
-
|
|
394
303
|
return results;
|
|
395
304
|
}
|
|
396
|
-
|
|
397
305
|
registerStartPlugin(startPlugin) {
|
|
398
306
|
this.startPluginSlot.register(startPlugin);
|
|
399
307
|
return this;
|
|
400
308
|
}
|
|
401
|
-
|
|
402
309
|
async initiatePlugins(options) {
|
|
403
310
|
const plugins = this.startPluginSlot.values();
|
|
404
311
|
await (0, _pMapSeries().default)(plugins, plugin => plugin.initiate(options));
|
|
405
312
|
return plugins;
|
|
406
313
|
}
|
|
314
|
+
|
|
407
315
|
/**
|
|
408
316
|
* create a Bit UI runtime.
|
|
409
317
|
*/
|
|
410
|
-
|
|
411
|
-
|
|
412
318
|
async createRuntime({
|
|
413
319
|
uiRootName,
|
|
414
320
|
pattern,
|
|
@@ -425,7 +331,6 @@ class UiMain {
|
|
|
425
331
|
pattern
|
|
426
332
|
});
|
|
427
333
|
if (this.componentExtension.isHost(name)) this.componentExtension.setHostPriority(name);
|
|
428
|
-
|
|
429
334
|
const uiServer = _uiServer().UIServer.create({
|
|
430
335
|
express: this.express,
|
|
431
336
|
graphql: this.graphql,
|
|
@@ -435,11 +340,10 @@ class UiMain {
|
|
|
435
340
|
logger: this.logger,
|
|
436
341
|
publicDir: await this.publicDir(uiRoot),
|
|
437
342
|
startPlugins: plugins
|
|
438
|
-
});
|
|
439
|
-
|
|
343
|
+
});
|
|
440
344
|
|
|
345
|
+
// Adding signal listeners to make sure we immediately close the process on sigint / sigterm (otherwise webpack dev server closing will take time)
|
|
441
346
|
this.addSignalListener();
|
|
442
|
-
|
|
443
347
|
if (dev) {
|
|
444
348
|
await uiServer.dev({
|
|
445
349
|
portRange: port || this.config.portRange
|
|
@@ -450,11 +354,9 @@ class UiMain {
|
|
|
450
354
|
portRange: port || this.config.portRange
|
|
451
355
|
});
|
|
452
356
|
}
|
|
453
|
-
|
|
454
357
|
this.pubsub.pub(_ui().UIAspect.id, this.createUiServerStartedEvent(this.config.host, uiServer.port, uiRoot));
|
|
455
358
|
return uiServer;
|
|
456
359
|
}
|
|
457
|
-
|
|
458
360
|
addSignalListener() {
|
|
459
361
|
process.on('SIGTERM', () => {
|
|
460
362
|
process.exit();
|
|
@@ -463,16 +365,15 @@ class UiMain {
|
|
|
463
365
|
process.exit();
|
|
464
366
|
});
|
|
465
367
|
}
|
|
466
|
-
|
|
467
368
|
async getPort(port) {
|
|
468
369
|
if (port) return port;
|
|
469
370
|
return this.config.port || this.selectPort();
|
|
470
371
|
}
|
|
372
|
+
|
|
471
373
|
/**
|
|
472
374
|
* Events
|
|
473
375
|
*/
|
|
474
376
|
|
|
475
|
-
|
|
476
377
|
/**
|
|
477
378
|
* pre-start events are triggered and *completed* before the webserver started.
|
|
478
379
|
* (the promise is awaited)
|
|
@@ -480,132 +381,109 @@ class UiMain {
|
|
|
480
381
|
registerPreStart(preStartFn) {
|
|
481
382
|
this.preStartSlot.register(preStartFn);
|
|
482
383
|
}
|
|
384
|
+
|
|
483
385
|
/**
|
|
484
386
|
* bind to ui server start event.
|
|
485
387
|
*/
|
|
486
|
-
|
|
487
|
-
|
|
488
388
|
registerOnStart(onStartFn) {
|
|
489
389
|
this.onStartSlot.register(onStartFn);
|
|
490
390
|
return this;
|
|
491
391
|
}
|
|
392
|
+
|
|
492
393
|
/**
|
|
493
394
|
* overwrite the build ui function
|
|
494
395
|
*/
|
|
495
|
-
|
|
496
|
-
|
|
497
396
|
registerBuildUIOverwrite(fn) {
|
|
498
397
|
this.buildMethodOverwriteSlot.register(fn);
|
|
499
398
|
return this;
|
|
500
399
|
}
|
|
400
|
+
|
|
501
401
|
/**
|
|
502
402
|
* overwrite the build ui function
|
|
503
403
|
*/
|
|
504
|
-
|
|
505
|
-
|
|
506
404
|
registerPublicDirOverwrite(fn) {
|
|
507
405
|
this.publicDirOverwriteSlot.register(fn);
|
|
508
406
|
return this;
|
|
509
407
|
}
|
|
510
|
-
|
|
511
408
|
getOverwriteBuildFn() {
|
|
512
409
|
const buildMethodOverwrite = this.buildMethodOverwriteSlot.toArray();
|
|
513
|
-
|
|
514
410
|
if (buildMethodOverwrite[0]) {
|
|
515
411
|
const [, fn] = buildMethodOverwrite[0];
|
|
516
412
|
return fn;
|
|
517
413
|
}
|
|
518
|
-
|
|
519
414
|
return undefined;
|
|
520
415
|
}
|
|
521
|
-
|
|
522
416
|
getOverwritePublic() {
|
|
523
417
|
const overwritePublic = this.publicDirOverwriteSlot.toArray();
|
|
524
|
-
|
|
525
418
|
if (overwritePublic[0]) {
|
|
526
419
|
const [, fn] = overwritePublic[0];
|
|
527
420
|
return fn;
|
|
528
421
|
}
|
|
529
|
-
|
|
530
422
|
return undefined;
|
|
531
423
|
}
|
|
532
|
-
|
|
533
424
|
async invokePreStart(preStartOpts) {
|
|
534
425
|
const onPreStartFuncs = this.preStartSlot.values();
|
|
535
426
|
await (0, _pMapSeries().default)(onPreStartFuncs, async fn => fn(preStartOpts));
|
|
536
427
|
}
|
|
537
|
-
|
|
538
428
|
async invokeOnStart() {
|
|
539
429
|
const onStartFuncs = this.onStartSlot.values();
|
|
540
430
|
const startPlugins = await (0, _pMapSeries().default)(onStartFuncs, async fn => fn());
|
|
541
431
|
return startPlugins.filter(plugin => !!plugin);
|
|
542
432
|
}
|
|
433
|
+
|
|
543
434
|
/**
|
|
544
435
|
* register a UI slot.
|
|
545
436
|
*/
|
|
546
|
-
|
|
547
|
-
|
|
548
437
|
registerUiRoot(uiRoot) {
|
|
549
438
|
return this.uiRootSlot.register(uiRoot);
|
|
550
439
|
}
|
|
440
|
+
|
|
551
441
|
/**
|
|
552
442
|
* get a UI runtime instance.
|
|
553
443
|
*/
|
|
554
|
-
|
|
555
|
-
|
|
556
444
|
getUi(uiRootName) {
|
|
557
445
|
if (uiRootName) {
|
|
558
446
|
const root = this.uiRootSlot.get(uiRootName) || this.getUiByName(uiRootName);
|
|
559
447
|
if (!root) return undefined;
|
|
560
448
|
return [uiRootName, root];
|
|
561
449
|
}
|
|
562
|
-
|
|
563
450
|
const uis = this.uiRootSlot.toArray();
|
|
564
451
|
if (uis.length === 1) return uis[0];
|
|
565
452
|
return uis.find(([, root]) => root.priority);
|
|
566
453
|
}
|
|
567
|
-
|
|
568
454
|
isHostAvailable() {
|
|
569
455
|
return Boolean(this.componentExtension.getHost());
|
|
570
456
|
}
|
|
571
|
-
|
|
572
457
|
getUiName(uiRootName) {
|
|
573
458
|
const [, ui] = this.getUi(uiRootName) || [];
|
|
574
459
|
if (!ui) return undefined;
|
|
575
460
|
return ui.name;
|
|
576
461
|
}
|
|
577
|
-
|
|
578
462
|
possibleUis() {
|
|
579
463
|
return this.uiRootSlot.toArray().map(([id]) => id);
|
|
580
464
|
}
|
|
581
|
-
|
|
582
465
|
createLink(aspectDefs, rootExtensionName) {
|
|
583
466
|
return (0, _createRoot().createRoot)(aspectDefs, rootExtensionName);
|
|
584
467
|
}
|
|
468
|
+
|
|
585
469
|
/**
|
|
586
470
|
* generate the root file of the UI runtime.
|
|
587
471
|
*/
|
|
588
|
-
|
|
589
|
-
|
|
590
472
|
async generateRoot(aspectDefs, rootExtensionName, runtimeName = _ui().UIRuntime.name, rootAspect = _ui().UIAspect.id, config, path) {
|
|
591
473
|
const contents = await (0, _createRoot().createRoot)(aspectDefs, rootExtensionName, rootAspect, runtimeName, config || this.harmony.config.toObject());
|
|
592
474
|
const filepath = (0, _path().resolve)((0, _path().join)(path || __dirname, `${runtimeName}.root${(0, _utils().sha1)(contents)}.js`));
|
|
593
475
|
if (_fsExtra().default.existsSync(filepath)) return filepath;
|
|
594
|
-
|
|
595
476
|
_fsExtra().default.outputFileSync(filepath, contents);
|
|
596
|
-
|
|
597
477
|
return filepath;
|
|
598
478
|
}
|
|
599
|
-
|
|
600
479
|
async selectPort() {
|
|
601
480
|
const [from, to] = this.config.portRange;
|
|
602
481
|
const usedPorts = (await this.cache.get(`${from}${to}`)) || [];
|
|
603
|
-
const port = await _toolboxNetwork().Port.getPort(from, to, usedPorts);
|
|
604
|
-
|
|
482
|
+
const port = await _toolboxNetwork().Port.getPort(from, to, usedPorts);
|
|
483
|
+
// this will lock the port for 1 min to avoid race conditions
|
|
605
484
|
await this.cache.set(`${from}${to}`, usedPorts.concat(port), 5000);
|
|
606
485
|
return port;
|
|
607
486
|
}
|
|
608
|
-
|
|
609
487
|
async buildUI(name, uiRoot, rebuild) {
|
|
610
488
|
this.logger.debug(`buildUI, name ${name}`);
|
|
611
489
|
const overwrite = this.getOverwriteBuildFn();
|
|
@@ -614,7 +492,6 @@ class UiMain {
|
|
|
614
492
|
await this.buildIfNoBundle(name, uiRoot);
|
|
615
493
|
return hash;
|
|
616
494
|
}
|
|
617
|
-
|
|
618
495
|
async buildUiHash(uiRoot, runtime = 'ui') {
|
|
619
496
|
const aspects = await uiRoot.resolveAspects(runtime);
|
|
620
497
|
aspects.sort((a, b) => a.aspectPath > b.aspectPath ? 1 : -1);
|
|
@@ -623,46 +500,37 @@ class UiMain {
|
|
|
623
500
|
});
|
|
624
501
|
return (0, _utils().sha1)(hash.join(''));
|
|
625
502
|
}
|
|
626
|
-
|
|
627
503
|
async buildIfChanged(name, uiRoot, force) {
|
|
628
504
|
this.logger.debug(`buildIfChanged, name ${name}`);
|
|
629
505
|
const hash = await this.buildUiHash(uiRoot);
|
|
630
506
|
const hashed = await this.cache.get(uiRoot.path);
|
|
631
|
-
|
|
632
507
|
if (hash === hashed && !force) {
|
|
633
508
|
this.logger.debug(`buildIfChanged, name ${name}, returned from cache`);
|
|
634
509
|
return hash;
|
|
635
510
|
}
|
|
636
|
-
|
|
637
511
|
if (!hashed) {
|
|
638
512
|
this.logger.console(`Building UI assets for '${_chalk().default.cyan(uiRoot.name)}' in target directory: ${_chalk().default.cyan(await this.publicDir(uiRoot))}. The first time we build the UI it may take a few minutes.`);
|
|
639
513
|
} else {
|
|
640
514
|
this.logger.console(`Rebuilding UI assets for '${_chalk().default.cyan(uiRoot.name)} in target directory: ${_chalk().default.cyan(await this.publicDir(uiRoot))}' as ${uiRoot.configFile} has been changed.`);
|
|
641
515
|
}
|
|
642
|
-
|
|
643
516
|
await this.build(name);
|
|
644
517
|
await this.cache.set(uiRoot.path, hash);
|
|
645
518
|
return hash;
|
|
646
519
|
}
|
|
647
|
-
|
|
648
520
|
clearConsole() {
|
|
649
521
|
process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H');
|
|
650
522
|
}
|
|
651
|
-
|
|
652
523
|
async buildIfNoBundle(name, uiRoot) {
|
|
653
524
|
var _config$output;
|
|
654
|
-
|
|
655
525
|
const config = (0, _webpackBrowser().default)(uiRoot.path, [await this.generateRoot(await uiRoot.resolveAspects(_ui().UIRuntime.name), name)], uiRoot.name, await this.publicDir(uiRoot));
|
|
656
526
|
if ((_config$output = config.output) !== null && _config$output !== void 0 && _config$output.path && _fsExtra().default.pathExistsSync(config.output.path)) return;
|
|
657
527
|
const hash = await this.buildUiHash(uiRoot);
|
|
658
528
|
await this.build(name);
|
|
659
529
|
await this.cache.set(uiRoot.path, hash);
|
|
660
530
|
}
|
|
661
|
-
|
|
662
531
|
get publicUrl() {
|
|
663
532
|
return this.config.publicUrl;
|
|
664
533
|
}
|
|
665
|
-
|
|
666
534
|
static async provider([pubsub, cli, graphql, express, componentExtension, cache, loggerMain], config, [uiRootSlot, preStartSlot, onStartSlot, publicDirOverwriteSlot, buildMethodOverwriteSlot, proxyGetterSlot], harmony) {
|
|
667
535
|
// aspectExtension.registerRuntime(new RuntimeDefinition('ui', []))
|
|
668
536
|
const logger = loggerMain.createLogger(_ui().UIAspect.id);
|
|
@@ -670,9 +538,7 @@ class UiMain {
|
|
|
670
538
|
cli.register(new (_start().StartCmd)(ui, logger), new (_uiBuild().UIBuildCmd)(ui));
|
|
671
539
|
return ui;
|
|
672
540
|
}
|
|
673
|
-
|
|
674
541
|
}
|
|
675
|
-
|
|
676
542
|
exports.UiMain = UiMain;
|
|
677
543
|
(0, _defineProperty2().default)(UiMain, "defaultConfig", {
|
|
678
544
|
publicDir: 'public/bit',
|
|
@@ -682,7 +548,6 @@ exports.UiMain = UiMain;
|
|
|
682
548
|
(0, _defineProperty2().default)(UiMain, "runtime", _cli().MainRuntime);
|
|
683
549
|
(0, _defineProperty2().default)(UiMain, "dependencies", [_pubsub().default, _cli().CLIAspect, _graphql().GraphqlAspect, _express().ExpressAspect, _component().ComponentAspect, _cache().CacheAspect, _logger().LoggerAspect]);
|
|
684
550
|
(0, _defineProperty2().default)(UiMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType()]);
|
|
685
|
-
|
|
686
551
|
_ui().UIAspect.addRuntime(UiMain);
|
|
687
552
|
|
|
688
553
|
//# sourceMappingURL=ui.main.runtime.js.map
|