@teambit/ui 0.0.554 → 0.0.558
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/compose.d.ts +5 -0
- package/dist/open-browser.d.ts +4 -0
- package/dist/render-lifecycle.d.ts +31 -0
- package/dist/ssr/request-browser.d.ts +35 -0
- package/dist/ssr/request-server.d.ts +3 -0
- package/dist/start-plugin.d.ts +7 -0
- package/dist/start.cmd.d.ts +8 -1
- package/dist/ui-build.cmd.d.ts +8 -1
- package/dist/ui-root.d.ts +24 -0
- package/dist/ui-server.d.ts +14 -0
- package/dist/ui.main.runtime.d.ts +141 -1
- package/dist/ui.ui.runtime.d.ts +31 -1
- package/dist/webpack/html.d.ts +1 -0
- package/package.json +32 -24
- package/tsconfig.json +1 -2
- package/compose.tsx +0 -27
- package/create-root.ts +0 -94
- package/events/index.ts +0 -1
- package/events/ui-server-started-event.ts +0 -14
- package/exceptions/index.ts +0 -2
- package/exceptions/unknown-build-error.ts +0 -5
- package/exceptions/unknown-ui.ts +0 -9
- package/index.ts +0 -18
- package/open-browser.ts +0 -128
- package/package-tar/teambit-ui-0.0.554.tgz +0 -0
- package/render-lifecycle.tsx +0 -56
- package/ssr/render-middleware.ts +0 -129
- package/ssr/request-browser.ts +0 -86
- package/ssr/request-server.ts +0 -10
- package/ssr/ssr-content.ts +0 -9
- package/start-plugin.ts +0 -25
- package/start.cmd.tsx +0 -93
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
- package/ui/client-context.module.scss +0 -4
- package/ui/client-context.tsx +0 -28
- package/ui-build.cmd.tsx +0 -27
- package/ui-root.tsx +0 -59
- package/ui-root.ui.ts +0 -7
- package/ui-server.ts +0 -249
- package/ui.aspect.ts +0 -10
- package/ui.cli.rt.tsx +0 -10
- package/ui.docs.md +0 -118
- package/ui.main.runtime.ts +0 -573
- package/ui.route.ts +0 -0
- package/ui.runtime.ts +0 -21
- package/ui.ui.runtime.tsx +0 -277
- package/webpack/html.ts +0 -24
- package/webpack/postcss.config.ts +0 -22
- package/webpack/webpack.base.config.ts +0 -392
- package/webpack/webpack.browser.config.ts +0 -125
- package/webpack/webpack.dev.config.ts +0 -336
- package/webpack/webpack.ssr.config.ts +0 -38
package/ui.main.runtime.ts
DELETED
|
@@ -1,573 +0,0 @@
|
|
|
1
|
-
import type { AspectMain } from '@teambit/aspect';
|
|
2
|
-
import { ComponentType } from 'react';
|
|
3
|
-
import { AspectDefinition } from '@teambit/aspect-loader';
|
|
4
|
-
import { CacheAspect, CacheMain } from '@teambit/cache';
|
|
5
|
-
import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
|
|
6
|
-
import type { ComponentMain } from '@teambit/component';
|
|
7
|
-
import { ComponentAspect } from '@teambit/component';
|
|
8
|
-
import { ExpressAspect, ExpressMain } from '@teambit/express';
|
|
9
|
-
import type { GraphqlMain } from '@teambit/graphql';
|
|
10
|
-
import { GraphqlAspect } from '@teambit/graphql';
|
|
11
|
-
import chalk from 'chalk';
|
|
12
|
-
import { Slot, SlotRegistry, Harmony } from '@teambit/harmony';
|
|
13
|
-
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
|
|
14
|
-
import PubsubAspect, { PubsubMain } from '@teambit/pubsub';
|
|
15
|
-
import { sha1 } from '@teambit/legacy/dist/utils';
|
|
16
|
-
import fs from 'fs-extra';
|
|
17
|
-
import { Port } from '@teambit/toolbox.network.get-port';
|
|
18
|
-
import { join, resolve } from 'path';
|
|
19
|
-
import { promisify } from 'util';
|
|
20
|
-
import webpack from 'webpack';
|
|
21
|
-
import { UiServerStartedEvent } from './events';
|
|
22
|
-
import { createRoot } from './create-root';
|
|
23
|
-
import { UnknownUI, UnknownBuildError } from './exceptions';
|
|
24
|
-
import { StartCmd } from './start.cmd';
|
|
25
|
-
import { UIBuildCmd } from './ui-build.cmd';
|
|
26
|
-
import { UIRoot } from './ui-root';
|
|
27
|
-
import { UIServer } from './ui-server';
|
|
28
|
-
import { UIAspect, UIRuntime } from './ui.aspect';
|
|
29
|
-
import { OpenBrowser } from './open-browser';
|
|
30
|
-
import createWebpackConfig from './webpack/webpack.browser.config';
|
|
31
|
-
import createSsrWebpackConfig from './webpack/webpack.ssr.config';
|
|
32
|
-
import { StartPlugin, StartPluginOptions } from './start-plugin';
|
|
33
|
-
|
|
34
|
-
export type UIDeps = [PubsubMain, CLIMain, GraphqlMain, ExpressMain, ComponentMain, CacheMain, LoggerMain, AspectMain];
|
|
35
|
-
|
|
36
|
-
export type UIRootRegistry = SlotRegistry<UIRoot>;
|
|
37
|
-
|
|
38
|
-
export type PreStart = (preStartOpts: PreStartOpts) => Promise<void>;
|
|
39
|
-
|
|
40
|
-
export type PreStartOpts = { skipCompilation?: boolean };
|
|
41
|
-
|
|
42
|
-
export type OnStart = () => Promise<undefined | ComponentType<{}>>;
|
|
43
|
-
|
|
44
|
-
export type StartPluginSlot = SlotRegistry<StartPlugin>;
|
|
45
|
-
|
|
46
|
-
export type PublicDirOverwrite = (uiRoot: UIRoot) => Promise<string | undefined>;
|
|
47
|
-
|
|
48
|
-
export type BuildMethodOverwrite = (name: string, uiRoot: UIRoot, rebuild?: boolean) => Promise<string>;
|
|
49
|
-
|
|
50
|
-
export type PreStartSlot = SlotRegistry<PreStart>;
|
|
51
|
-
|
|
52
|
-
export type OnStartSlot = SlotRegistry<OnStart>;
|
|
53
|
-
|
|
54
|
-
export type PublicDirOverwriteSlot = SlotRegistry<PublicDirOverwrite>;
|
|
55
|
-
|
|
56
|
-
export type BuildMethodOverwriteSlot = SlotRegistry<BuildMethodOverwrite>;
|
|
57
|
-
|
|
58
|
-
export type UIConfig = {
|
|
59
|
-
/**
|
|
60
|
-
* port for the UI root to use.
|
|
61
|
-
*/
|
|
62
|
-
port?: number;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* port range for the UI root to use.
|
|
66
|
-
*/
|
|
67
|
-
portRange: [number, number];
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* host for the UI root
|
|
71
|
-
*/
|
|
72
|
-
host: string;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* directory in workspace to use for public assets.
|
|
76
|
-
* always relative to the workspace root directory.
|
|
77
|
-
*/
|
|
78
|
-
publicDir: string;
|
|
79
|
-
|
|
80
|
-
/** the url to display when server is listening. Note that bit does not provide proxying to this url */
|
|
81
|
-
publicUrl?: string;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export type RuntimeOptions = {
|
|
85
|
-
/**
|
|
86
|
-
* determine whether to initiate on verbose mode.
|
|
87
|
-
*/
|
|
88
|
-
verbose?: boolean;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* name of the UI root to load.
|
|
92
|
-
*/
|
|
93
|
-
uiRootName?: string;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* component selector pattern to load.
|
|
97
|
-
*/
|
|
98
|
-
pattern?: string;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* determine whether to start a dev server (defaults to false).
|
|
102
|
-
*/
|
|
103
|
-
dev?: boolean;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* port of the config.
|
|
107
|
-
*/
|
|
108
|
-
port?: number;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* determine whether to rebuild the UI before start.
|
|
112
|
-
*/
|
|
113
|
-
rebuild?: boolean;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export class UiMain {
|
|
117
|
-
constructor(
|
|
118
|
-
/**
|
|
119
|
-
* Pubsub extension.
|
|
120
|
-
*/
|
|
121
|
-
private pubsub: PubsubMain,
|
|
122
|
-
|
|
123
|
-
private config: UIConfig,
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* graphql extension.
|
|
127
|
-
*/
|
|
128
|
-
private graphql: GraphqlMain,
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* slot registry of ui roots.
|
|
132
|
-
*/
|
|
133
|
-
private uiRootSlot: UIRootRegistry,
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* express extension.
|
|
137
|
-
*/
|
|
138
|
-
private express: ExpressMain,
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* pre-start slot
|
|
142
|
-
*/
|
|
143
|
-
private preStartSlot: PreStartSlot,
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* on start slot
|
|
147
|
-
*/
|
|
148
|
-
private onStartSlot: OnStartSlot,
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Overwrite the public dir Slot
|
|
152
|
-
*/
|
|
153
|
-
private publicDirOverwriteSlot: PublicDirOverwriteSlot,
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Overwrite the build ui method
|
|
157
|
-
*/
|
|
158
|
-
private buildMethodOverwriteSlot: BuildMethodOverwriteSlot,
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* component extension.
|
|
162
|
-
*/
|
|
163
|
-
private componentExtension: ComponentMain,
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* ui logger instance.
|
|
167
|
-
*/
|
|
168
|
-
private cache: CacheMain,
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* ui logger instance.
|
|
172
|
-
*/
|
|
173
|
-
private logger: Logger,
|
|
174
|
-
|
|
175
|
-
private harmony: Harmony,
|
|
176
|
-
|
|
177
|
-
private startPluginSlot: StartPluginSlot
|
|
178
|
-
) {}
|
|
179
|
-
|
|
180
|
-
async publicDir(uiRoot: UIRoot) {
|
|
181
|
-
const overwriteFn = this.getOverwritePublic();
|
|
182
|
-
if (overwriteFn) {
|
|
183
|
-
const hasDir = await overwriteFn(uiRoot);
|
|
184
|
-
if (hasDir) return hasDir;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (this.config.publicDir.startsWith('/')) {
|
|
188
|
-
return this.config.publicDir.substring(1);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return this.config.publicDir;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
private getUiByName(name: string) {
|
|
195
|
-
const roots = this.uiRootSlot.toArray();
|
|
196
|
-
const [, root] =
|
|
197
|
-
roots.find(([, uiRoot]) => {
|
|
198
|
-
return uiRoot.name === name;
|
|
199
|
-
}) || [];
|
|
200
|
-
|
|
201
|
-
return root;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* create a build of the given UI root.
|
|
206
|
-
*/
|
|
207
|
-
async build(uiRootName?: string): Promise<webpack.MultiStats | undefined> {
|
|
208
|
-
// TODO: change to MultiStats from webpack once they export it in their types
|
|
209
|
-
this.logger.debug(`build, uiRootName: "${uiRootName}"`);
|
|
210
|
-
const maybeUiRoot = this.getUi(uiRootName);
|
|
211
|
-
|
|
212
|
-
if (!maybeUiRoot) throw new UnknownUI(uiRootName, this.possibleUis());
|
|
213
|
-
const [name, uiRoot] = maybeUiRoot;
|
|
214
|
-
|
|
215
|
-
// TODO: @uri refactor all dev server related code to use the bundler extension instead.
|
|
216
|
-
const ssr = uiRoot.buildOptions?.ssr || false;
|
|
217
|
-
const mainEntry = await this.generateRoot(await uiRoot.resolveAspects(UIRuntime.name), name);
|
|
218
|
-
|
|
219
|
-
const browserConfig = createWebpackConfig(uiRoot.path, [mainEntry], uiRoot.name, await this.publicDir(uiRoot));
|
|
220
|
-
const ssrConfig = ssr && createSsrWebpackConfig(uiRoot.path, [mainEntry], await this.publicDir(uiRoot));
|
|
221
|
-
|
|
222
|
-
const config = [browserConfig, ssrConfig].filter((x) => !!x) as webpack.Configuration[];
|
|
223
|
-
const compiler = webpack(config);
|
|
224
|
-
this.logger.debug(`build, uiRootName: "${uiRootName}" running webpack`);
|
|
225
|
-
const compilerRun = promisify(compiler.run.bind(compiler));
|
|
226
|
-
const results = await compilerRun();
|
|
227
|
-
this.logger.debug(`build, uiRootName: "${uiRootName}" completed webpack`);
|
|
228
|
-
if (!results) throw new UnknownBuildError();
|
|
229
|
-
if (results?.hasErrors()) {
|
|
230
|
-
this.clearConsole();
|
|
231
|
-
throw new Error(results?.toString());
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return results;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
registerStartPlugin(startPlugin: StartPlugin) {
|
|
238
|
-
this.startPluginSlot.register(startPlugin);
|
|
239
|
-
return this;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
private async initiatePlugins(options: StartPluginOptions) {
|
|
243
|
-
const plugins = this.startPluginSlot.values();
|
|
244
|
-
await Promise.all(plugins.map((plugin) => plugin.initiate(options)));
|
|
245
|
-
return plugins;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* create a Bit UI runtime.
|
|
250
|
-
*/
|
|
251
|
-
async createRuntime({ uiRootName, pattern, dev, port, rebuild, verbose }: RuntimeOptions) {
|
|
252
|
-
const maybeUiRoot = this.getUi(uiRootName);
|
|
253
|
-
if (!maybeUiRoot) throw new UnknownUI(uiRootName, this.possibleUis());
|
|
254
|
-
|
|
255
|
-
const [name, uiRoot] = maybeUiRoot;
|
|
256
|
-
|
|
257
|
-
const plugins = await this.initiatePlugins({
|
|
258
|
-
verbose,
|
|
259
|
-
pattern,
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
if (this.componentExtension.isHost(name)) this.componentExtension.setHostPriority(name);
|
|
263
|
-
|
|
264
|
-
const uiServer = UIServer.create({
|
|
265
|
-
express: this.express,
|
|
266
|
-
graphql: this.graphql,
|
|
267
|
-
uiRoot,
|
|
268
|
-
uiRootExtension: name,
|
|
269
|
-
ui: this,
|
|
270
|
-
logger: this.logger,
|
|
271
|
-
publicDir: await this.publicDir(uiRoot),
|
|
272
|
-
startPlugins: plugins,
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
// Adding signal listeners to make sure we immediately close the process on sigint / sigterm (otherwise webpack dev server closing will take time)
|
|
276
|
-
this.addSignalListener();
|
|
277
|
-
if (dev) {
|
|
278
|
-
await uiServer.dev({ portRange: port || this.config.portRange });
|
|
279
|
-
} else {
|
|
280
|
-
await this.buildUI(name, uiRoot, rebuild);
|
|
281
|
-
await uiServer.start({ portRange: port || this.config.portRange });
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
this.pubsub.pub(UIAspect.id, this.createUiServerStartedEvent(this.config.host, uiServer.port, uiRoot));
|
|
285
|
-
|
|
286
|
-
return uiServer;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
private addSignalListener() {
|
|
290
|
-
process.on('SIGTERM', () => {
|
|
291
|
-
process.exit();
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
process.on('SIGINT', () => {
|
|
295
|
-
process.exit();
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
async getPort(port?: number): Promise<number> {
|
|
300
|
-
if (port) return port;
|
|
301
|
-
return this.config.port || this.selectPort();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Events
|
|
306
|
-
*/
|
|
307
|
-
private createUiServerStartedEvent = (targetHost, targetPort, uiRoot) => {
|
|
308
|
-
return new UiServerStartedEvent(Date.now(), targetHost, targetPort, uiRoot);
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* pre-start events are triggered and *completed* before the webserver started.
|
|
313
|
-
* (the promise is awaited)
|
|
314
|
-
*/
|
|
315
|
-
registerPreStart(preStartFn: PreStart) {
|
|
316
|
-
this.preStartSlot.register(preStartFn);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* bind to ui server start event.
|
|
321
|
-
*/
|
|
322
|
-
registerOnStart(onStartFn: OnStart) {
|
|
323
|
-
this.onStartSlot.register(onStartFn);
|
|
324
|
-
return this;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* overwrite the build ui function
|
|
329
|
-
*/
|
|
330
|
-
registerBuildUIOverwrite(fn: BuildMethodOverwrite) {
|
|
331
|
-
this.buildMethodOverwriteSlot.register(fn);
|
|
332
|
-
return this;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* overwrite the build ui function
|
|
337
|
-
*/
|
|
338
|
-
registerPublicDirOverwrite(fn: PublicDirOverwrite) {
|
|
339
|
-
this.publicDirOverwriteSlot.register(fn);
|
|
340
|
-
return this;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
private getOverwriteBuildFn() {
|
|
344
|
-
const buildMethodOverwrite = this.buildMethodOverwriteSlot.toArray();
|
|
345
|
-
if (buildMethodOverwrite[0]) {
|
|
346
|
-
const [, fn] = buildMethodOverwrite[0];
|
|
347
|
-
return fn;
|
|
348
|
-
}
|
|
349
|
-
return undefined;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
private getOverwritePublic() {
|
|
353
|
-
const overwritePublic = this.publicDirOverwriteSlot.toArray();
|
|
354
|
-
if (overwritePublic[0]) {
|
|
355
|
-
const [, fn] = overwritePublic[0];
|
|
356
|
-
return fn;
|
|
357
|
-
}
|
|
358
|
-
return undefined;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
async invokePreStart(preStartOpts: PreStartOpts): Promise<void> {
|
|
362
|
-
const promises = this.preStartSlot.values().map((fn) => fn(preStartOpts));
|
|
363
|
-
await Promise.all(promises);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
async invokeOnStart(): Promise<ComponentType[]> {
|
|
367
|
-
const promises = this.onStartSlot.values().map((fn) => fn());
|
|
368
|
-
const startPlugins = await Promise.all(promises);
|
|
369
|
-
return startPlugins.filter((plugin) => !!plugin) as ComponentType[];
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* register a UI slot.
|
|
374
|
-
*/
|
|
375
|
-
registerUiRoot(uiRoot: UIRoot) {
|
|
376
|
-
return this.uiRootSlot.register(uiRoot);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* get a UI runtime instance.
|
|
381
|
-
*/
|
|
382
|
-
getUi(uiRootName?: string): [string, UIRoot] | undefined {
|
|
383
|
-
if (uiRootName) {
|
|
384
|
-
const root = this.uiRootSlot.get(uiRootName) || this.getUiByName(uiRootName);
|
|
385
|
-
if (!root) return undefined;
|
|
386
|
-
return [uiRootName, root];
|
|
387
|
-
}
|
|
388
|
-
const uis = this.uiRootSlot.toArray();
|
|
389
|
-
if (uis.length === 1) return uis[0];
|
|
390
|
-
return uis.find(([, root]) => root.priority);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
getUiName(uiRootName?: string): string | undefined {
|
|
394
|
-
const [, ui] = this.getUi(uiRootName) || [];
|
|
395
|
-
if (!ui) return undefined;
|
|
396
|
-
|
|
397
|
-
return ui.name;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
private possibleUis() {
|
|
401
|
-
return this.uiRootSlot.toArray().map(([id]) => id);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
createLink(aspectDefs: AspectDefinition[], rootExtensionName: string) {
|
|
405
|
-
return createRoot(aspectDefs, rootExtensionName);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* generate the root file of the UI runtime.
|
|
410
|
-
*/
|
|
411
|
-
async generateRoot(
|
|
412
|
-
aspectDefs: AspectDefinition[],
|
|
413
|
-
rootExtensionName: string,
|
|
414
|
-
runtimeName = UIRuntime.name,
|
|
415
|
-
rootAspect = UIAspect.id
|
|
416
|
-
) {
|
|
417
|
-
const contents = await createRoot(
|
|
418
|
-
aspectDefs,
|
|
419
|
-
rootExtensionName,
|
|
420
|
-
rootAspect,
|
|
421
|
-
runtimeName,
|
|
422
|
-
this.harmony.config.toObject()
|
|
423
|
-
);
|
|
424
|
-
const filepath = resolve(join(__dirname, `${runtimeName}.root${sha1(contents)}.js`));
|
|
425
|
-
if (fs.existsSync(filepath)) return filepath;
|
|
426
|
-
fs.outputFileSync(filepath, contents);
|
|
427
|
-
return filepath;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
private async selectPort() {
|
|
431
|
-
const [from, to] = this.config.portRange;
|
|
432
|
-
const usedPorts = (await this.cache.get<number[]>(`${from}${to}`)) || [];
|
|
433
|
-
const port = await Port.getPort(from, to, usedPorts);
|
|
434
|
-
// this will lock the port for 1 min to avoid race conditions
|
|
435
|
-
await this.cache.set(`${from}${to}`, usedPorts.concat(port), 5000);
|
|
436
|
-
return port;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
private async buildUI(name: string, uiRoot: UIRoot, rebuild?: boolean): Promise<string> {
|
|
440
|
-
this.logger.debug(`buildUI, name ${name}`);
|
|
441
|
-
const overwrite = this.getOverwriteBuildFn();
|
|
442
|
-
if (overwrite) return overwrite(name, uiRoot, rebuild);
|
|
443
|
-
const hash = await this.buildIfChanged(name, uiRoot, rebuild);
|
|
444
|
-
await this.buildIfNoBundle(name, uiRoot);
|
|
445
|
-
return hash;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
async buildUiHash(uiRoot: UIRoot, runtime = 'ui'): Promise<string> {
|
|
449
|
-
const aspects = await uiRoot.resolveAspects(runtime);
|
|
450
|
-
aspects.sort((a, b) => (a.aspectPath > b.aspectPath ? 1 : -1));
|
|
451
|
-
const hash = aspects.map((aspect) => {
|
|
452
|
-
return [aspect.aspectPath, aspect.runtimePath].join('');
|
|
453
|
-
});
|
|
454
|
-
return sha1(hash.join(''));
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
async buildIfChanged(name: string, uiRoot: UIRoot, force: boolean | undefined): Promise<string> {
|
|
458
|
-
this.logger.debug(`buildIfChanged, name ${name}`);
|
|
459
|
-
const hash = await this.buildUiHash(uiRoot);
|
|
460
|
-
const hashed = await this.cache.get(uiRoot.path);
|
|
461
|
-
if (hash === hashed && !force) {
|
|
462
|
-
this.logger.debug(`buildIfChanged, name ${name}, returned from cache`);
|
|
463
|
-
return hash;
|
|
464
|
-
}
|
|
465
|
-
if (!hashed) {
|
|
466
|
-
this.logger.console(
|
|
467
|
-
`Building UI assets for '${chalk.cyan(uiRoot.name)}' in target directory: ${chalk.cyan(
|
|
468
|
-
await this.publicDir(uiRoot)
|
|
469
|
-
)}. The first time we build the UI it may take a few minutes.`
|
|
470
|
-
);
|
|
471
|
-
} else {
|
|
472
|
-
this.logger.console(
|
|
473
|
-
`Rebuilding UI assets for '${chalk.cyan(uiRoot.name)} in target directory: ${chalk.cyan(
|
|
474
|
-
await this.publicDir(uiRoot)
|
|
475
|
-
)}' as ${uiRoot.configFile} has been changed.`
|
|
476
|
-
);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
await this.build(name);
|
|
480
|
-
await this.cache.set(uiRoot.path, hash);
|
|
481
|
-
return hash;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
clearConsole() {
|
|
485
|
-
process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H');
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
async buildIfNoBundle(name: string, uiRoot: UIRoot) {
|
|
489
|
-
const config = createWebpackConfig(
|
|
490
|
-
uiRoot.path,
|
|
491
|
-
[await this.generateRoot(await uiRoot.resolveAspects(UIRuntime.name), name)],
|
|
492
|
-
uiRoot.name,
|
|
493
|
-
await this.publicDir(uiRoot)
|
|
494
|
-
);
|
|
495
|
-
if (config.output?.path && fs.pathExistsSync(config.output.path)) return;
|
|
496
|
-
const hash = await this.buildUiHash(uiRoot);
|
|
497
|
-
await this.build(name);
|
|
498
|
-
await this.cache.set(uiRoot.path, hash);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
get publicUrl() {
|
|
502
|
-
return this.config.publicUrl;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
private async openBrowser(url: string) {
|
|
506
|
-
const openBrowser = new OpenBrowser(this.logger);
|
|
507
|
-
openBrowser.open(url);
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
static defaultConfig: UIConfig = {
|
|
511
|
-
publicDir: 'public/bit',
|
|
512
|
-
portRange: [3000, 3100],
|
|
513
|
-
host: 'localhost',
|
|
514
|
-
};
|
|
515
|
-
|
|
516
|
-
static runtime = MainRuntime;
|
|
517
|
-
static dependencies = [
|
|
518
|
-
PubsubAspect,
|
|
519
|
-
CLIAspect,
|
|
520
|
-
GraphqlAspect,
|
|
521
|
-
ExpressAspect,
|
|
522
|
-
ComponentAspect,
|
|
523
|
-
CacheAspect,
|
|
524
|
-
LoggerAspect,
|
|
525
|
-
];
|
|
526
|
-
|
|
527
|
-
static slots = [
|
|
528
|
-
Slot.withType<UIRoot>(),
|
|
529
|
-
Slot.withType<PreStart>(),
|
|
530
|
-
Slot.withType<OnStart>(),
|
|
531
|
-
Slot.withType<PublicDirOverwriteSlot>(),
|
|
532
|
-
Slot.withType<BuildMethodOverwriteSlot>(),
|
|
533
|
-
Slot.withType<StartPlugin>(),
|
|
534
|
-
];
|
|
535
|
-
|
|
536
|
-
static async provider(
|
|
537
|
-
[pubsub, cli, graphql, express, componentExtension, cache, loggerMain]: UIDeps,
|
|
538
|
-
config,
|
|
539
|
-
[uiRootSlot, preStartSlot, onStartSlot, publicDirOverwriteSlot, buildMethodOverwriteSlot, proxyGetterSlot]: [
|
|
540
|
-
UIRootRegistry,
|
|
541
|
-
PreStartSlot,
|
|
542
|
-
OnStartSlot,
|
|
543
|
-
PublicDirOverwriteSlot,
|
|
544
|
-
BuildMethodOverwriteSlot,
|
|
545
|
-
StartPluginSlot
|
|
546
|
-
],
|
|
547
|
-
harmony: Harmony
|
|
548
|
-
) {
|
|
549
|
-
// aspectExtension.registerRuntime(new RuntimeDefinition('ui', []))
|
|
550
|
-
const logger = loggerMain.createLogger(UIAspect.id);
|
|
551
|
-
|
|
552
|
-
const ui = new UiMain(
|
|
553
|
-
pubsub,
|
|
554
|
-
config,
|
|
555
|
-
graphql,
|
|
556
|
-
uiRootSlot,
|
|
557
|
-
express,
|
|
558
|
-
preStartSlot,
|
|
559
|
-
onStartSlot,
|
|
560
|
-
publicDirOverwriteSlot,
|
|
561
|
-
buildMethodOverwriteSlot,
|
|
562
|
-
componentExtension,
|
|
563
|
-
cache,
|
|
564
|
-
logger,
|
|
565
|
-
harmony,
|
|
566
|
-
proxyGetterSlot
|
|
567
|
-
);
|
|
568
|
-
cli.register(new StartCmd(ui, logger), new UIBuildCmd(ui));
|
|
569
|
-
return ui;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
UIAspect.addRuntime(UiMain);
|
package/ui.route.ts
DELETED
|
File without changes
|
package/ui.runtime.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// import harmony from '@teambit/harmony';
|
|
2
|
-
// import { UIRuntimeExtension } from './ui.ui';
|
|
3
|
-
// import { DocsUI } from '../docs/docs.ui';
|
|
4
|
-
// import { TesterUI } from '../tester/tester.ui';
|
|
5
|
-
// import { ChangeLogUI } from '../changelog/changelog.ui';
|
|
6
|
-
// import { ComponentUI } from '../component';
|
|
7
|
-
// import { CompositionsUI } from '../compositions/compositions.ui';
|
|
8
|
-
|
|
9
|
-
// /**
|
|
10
|
-
// * configure all core extensions
|
|
11
|
-
// * TODO: pass all other extensions from above.
|
|
12
|
-
// */
|
|
13
|
-
// harmony
|
|
14
|
-
// .run([UIRuntimeExtension, TesterUI, ChangeLogUI, CompositionsUI, DocsUI, ComponentUI])
|
|
15
|
-
// .then(() => {
|
|
16
|
-
// const uiExtension = harmony.get<UIRuntimeExtension>('UIRuntimeExtension');
|
|
17
|
-
// uiExtension.render();
|
|
18
|
-
// })
|
|
19
|
-
// .catch((err) => {
|
|
20
|
-
// throw err;
|
|
21
|
-
// });
|