@teambit/preview 0.0.551 → 0.0.556
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/bundling-strategy.d.ts +9 -0
- package/dist/preview-definition.d.ts +9 -0
- package/dist/preview-type.d.ts +15 -0
- package/dist/preview.main.runtime.d.ts +39 -1
- package/dist/preview.preview.runtime.d.ts +28 -1
- package/dist/preview.route.d.ts +9 -1
- package/dist/preview.task.d.ts +15 -1
- package/dist/rendering-context.d.ts +3 -0
- package/dist/strategies/env-strategy.d.ts +3 -0
- package/dist/types/preview-module.d.ts +6 -0
- package/package.json +31 -25
- package/bundling-strategy.ts +0 -21
- package/events/click-inside-an-iframe.ts +0 -14
- package/events/index.ts +0 -1
- package/exceptions/bundling-strategy-not-found.ts +0 -5
- package/exceptions/index.ts +0 -3
- package/exceptions/preview-artifact-not-found.ts +0 -8
- package/exceptions/preview-not-found.ts +0 -5
- package/execution-ref.ts +0 -25
- package/generate-link.ts +0 -21
- package/index.ts +0 -8
- package/mk-temp-dir.ts +0 -7
- package/package-tar/teambit-preview-0.0.551.tgz +0 -0
- package/preview-artifact.ts +0 -12
- package/preview-context.ts +0 -5
- package/preview-definition.ts +0 -20
- package/preview-type.ts +0 -34
- package/preview.aspect.ts +0 -12
- package/preview.docs.mdx +0 -8
- package/preview.graphql.ts +0 -25
- package/preview.main.runtime.tsx +0 -346
- package/preview.preview.runtime.tsx +0 -148
- package/preview.route.ts +0 -56
- package/preview.start-plugin.tsx +0 -121
- package/preview.task.ts +0 -91
- package/rendering-context.ts +0 -12
- package/strategies/component-strategy.ts +0 -34
- package/strategies/env-strategy.ts +0 -118
- package/strategies/index.ts +0 -2
- package/tsconfig.json +0 -35
- package/types/asset.d.ts +0 -29
- package/types/preview-module.ts +0 -15
- package/types/style.d.ts +0 -42
|
@@ -3,7 +3,16 @@ import { Target, BundlerResult, BundlerContext } from '@teambit/bundler';
|
|
|
3
3
|
import { PreviewDefinition } from './preview-definition';
|
|
4
4
|
import { PreviewTask } from './preview.task';
|
|
5
5
|
export interface BundlingStrategy {
|
|
6
|
+
/**
|
|
7
|
+
* name of the bundling strategy.
|
|
8
|
+
*/
|
|
6
9
|
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* compute bundling targets for the build context.
|
|
12
|
+
*/
|
|
7
13
|
computeTargets(context: BuildContext, previewDefs: PreviewDefinition[], previewTask: PreviewTask): Promise<Target[]>;
|
|
14
|
+
/**
|
|
15
|
+
* compute the results of the bundler.
|
|
16
|
+
*/
|
|
8
17
|
computeResults(context: BundlerContext, results: BundlerResult[], previewTask: PreviewTask): Promise<BuiltTaskResult>;
|
|
9
18
|
}
|
|
@@ -2,7 +2,16 @@ import { Component, ComponentMap } from '@teambit/component';
|
|
|
2
2
|
import { ExecutionContext } from '@teambit/envs';
|
|
3
3
|
import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
|
4
4
|
export interface PreviewDefinition {
|
|
5
|
+
/**
|
|
6
|
+
* extension preview prefix
|
|
7
|
+
*/
|
|
5
8
|
prefix: string;
|
|
9
|
+
/**
|
|
10
|
+
* path of the default template to be executed.
|
|
11
|
+
*/
|
|
6
12
|
renderTemplatePath?: (context: ExecutionContext) => Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* get all files to require in the preview runtime.
|
|
15
|
+
*/
|
|
7
16
|
getModuleMap(components: Component[]): Promise<ComponentMap<AbstractVinyl[]>>;
|
|
8
17
|
}
|
package/dist/preview-type.d.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { RenderingContext } from './rendering-context';
|
|
2
2
|
import { PreviewModule } from './types/preview-module';
|
|
3
3
|
export interface PreviewType {
|
|
4
|
+
/**
|
|
5
|
+
* preview name to register.
|
|
6
|
+
*/
|
|
4
7
|
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* preview render method.
|
|
10
|
+
*/
|
|
5
11
|
render(componentId: string, linkedModules: PreviewModule<any>, includedPreviews: string[], renderingContext: RenderingContext): void;
|
|
12
|
+
/**
|
|
13
|
+
* determine if this will be the default preview to render.
|
|
14
|
+
*/
|
|
6
15
|
default?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* which other extension modules to include in the preview context.
|
|
18
|
+
*/
|
|
7
19
|
include?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* select relevant information to show in preview context
|
|
22
|
+
*/
|
|
8
23
|
selectPreviewModel?: (componentId: string, module: PreviewModule) => any;
|
|
9
24
|
}
|
|
@@ -19,7 +19,13 @@ export declare type PreviewConfig = {
|
|
|
19
19
|
};
|
|
20
20
|
export declare type BundlingStrategySlot = SlotRegistry<BundlingStrategy>;
|
|
21
21
|
export declare class PreviewMain {
|
|
22
|
+
/**
|
|
23
|
+
* harmony context.
|
|
24
|
+
*/
|
|
22
25
|
private harmony;
|
|
26
|
+
/**
|
|
27
|
+
* slot for preview definitions.
|
|
28
|
+
*/
|
|
23
29
|
private previewSlot;
|
|
24
30
|
private ui;
|
|
25
31
|
private envs;
|
|
@@ -30,12 +36,27 @@ export declare class PreviewMain {
|
|
|
30
36
|
private builder;
|
|
31
37
|
private workspace;
|
|
32
38
|
private logger;
|
|
33
|
-
constructor(
|
|
39
|
+
constructor(
|
|
40
|
+
/**
|
|
41
|
+
* harmony context.
|
|
42
|
+
*/
|
|
43
|
+
harmony: Harmony,
|
|
44
|
+
/**
|
|
45
|
+
* slot for preview definitions.
|
|
46
|
+
*/
|
|
47
|
+
previewSlot: PreviewDefinitionRegistry, ui: UiMain, envs: EnvsMain, pkg: PkgMain, aspectLoader: AspectLoaderMain, config: PreviewConfig, bundlingStrategySlot: BundlingStrategySlot, builder: BuilderMain, workspace: Workspace | undefined, logger: Logger);
|
|
34
48
|
get tempFolder(): string;
|
|
35
49
|
getPreview(component: Component): Promise<PreviewArtifact | undefined>;
|
|
36
50
|
getDefs(): PreviewDefinition[];
|
|
37
51
|
private writeHash;
|
|
38
52
|
private timestamp;
|
|
53
|
+
/**
|
|
54
|
+
* write a link to load custom modules dynamically.
|
|
55
|
+
* @param prefix write
|
|
56
|
+
* @param moduleMap map of components to module paths to require.
|
|
57
|
+
* @param defaultModule
|
|
58
|
+
* @param dirName
|
|
59
|
+
*/
|
|
39
60
|
writeLink(prefix: string, moduleMap: ComponentMap<string[]>, defaultModule: string | undefined, dirName: string): string;
|
|
40
61
|
private executionRefs;
|
|
41
62
|
private getPreviewTarget;
|
|
@@ -43,12 +64,29 @@ export declare class PreviewMain {
|
|
|
43
64
|
writePreviewRuntime(context: {
|
|
44
65
|
components: Component[];
|
|
45
66
|
}): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Filter the aspects to have only aspects that are:
|
|
69
|
+
* 1. core aspects
|
|
70
|
+
* 2. configured on the host (workspace/scope)
|
|
71
|
+
* 3. used by at least one component from the context
|
|
72
|
+
* @param aspects
|
|
73
|
+
* @param context
|
|
74
|
+
*/
|
|
46
75
|
private filterAspectsByExecutionContext;
|
|
47
76
|
private getDefaultStrategies;
|
|
48
77
|
private handleComponentChange;
|
|
49
78
|
private handleComponentRemoval;
|
|
79
|
+
/**
|
|
80
|
+
* return the configured bundling strategy.
|
|
81
|
+
*/
|
|
50
82
|
getBundlingStrategy(): BundlingStrategy;
|
|
83
|
+
/**
|
|
84
|
+
* register a new bundling strategy. default available strategies are `env` and ``
|
|
85
|
+
*/
|
|
51
86
|
registerBundlingStrategy(bundlingStrategy: BundlingStrategy): this;
|
|
87
|
+
/**
|
|
88
|
+
* register a new preview definition.
|
|
89
|
+
*/
|
|
52
90
|
registerDefinition(previewDef: PreviewDefinition): void;
|
|
53
91
|
static slots: (((registerFn: () => string) => SlotRegistry<PreviewDefinition>) | ((registerFn: () => string) => SlotRegistry<BundlingStrategy>))[];
|
|
54
92
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
@@ -8,14 +8,41 @@ export declare type RenderingContextProvider = () => {
|
|
|
8
8
|
};
|
|
9
9
|
export declare type RenderingContextSlot = SlotRegistry<RenderingContextProvider>;
|
|
10
10
|
export declare class PreviewPreview {
|
|
11
|
+
/**
|
|
12
|
+
* register to pubsub
|
|
13
|
+
*/
|
|
11
14
|
private pubsub;
|
|
15
|
+
/**
|
|
16
|
+
* preview slot.
|
|
17
|
+
*/
|
|
12
18
|
private previewSlot;
|
|
13
19
|
private renderingContextSlot;
|
|
14
|
-
constructor(
|
|
20
|
+
constructor(
|
|
21
|
+
/**
|
|
22
|
+
* register to pubsub
|
|
23
|
+
*/
|
|
24
|
+
pubsub: PubsubPreview,
|
|
25
|
+
/**
|
|
26
|
+
* preview slot.
|
|
27
|
+
*/
|
|
28
|
+
previewSlot: PreviewSlot, renderingContextSlot: RenderingContextSlot);
|
|
15
29
|
private registerClickPubSub;
|
|
30
|
+
/**
|
|
31
|
+
* render the preview.
|
|
32
|
+
*/
|
|
16
33
|
render: () => void;
|
|
34
|
+
/**
|
|
35
|
+
* register a new preview.
|
|
36
|
+
*/
|
|
17
37
|
registerPreview(preview: PreviewType): this;
|
|
38
|
+
/**
|
|
39
|
+
* get the preview rendering context.
|
|
40
|
+
*/
|
|
18
41
|
getRenderingContext(): RenderingContext;
|
|
42
|
+
/**
|
|
43
|
+
* allows aspects to add rendering contexts.
|
|
44
|
+
* render context is available through all preview definitions.
|
|
45
|
+
*/
|
|
19
46
|
registerRenderContext(renderContext: RenderingContextProvider): this;
|
|
20
47
|
getDefault(): string;
|
|
21
48
|
private getPreview;
|
package/dist/preview.route.d.ts
CHANGED
|
@@ -3,12 +3,20 @@ import { Request, Response, Route } from '@teambit/express';
|
|
|
3
3
|
import type { Logger } from '@teambit/logger';
|
|
4
4
|
import { PreviewMain } from './preview.main.runtime';
|
|
5
5
|
declare type UrlParams = {
|
|
6
|
+
/** `/preview/:previewPath(*)` */
|
|
6
7
|
previewPath?: string;
|
|
7
8
|
};
|
|
8
9
|
export declare class PreviewRoute implements Route {
|
|
10
|
+
/**
|
|
11
|
+
* preview extension.
|
|
12
|
+
*/
|
|
9
13
|
private preview;
|
|
10
14
|
private logger;
|
|
11
|
-
constructor(
|
|
15
|
+
constructor(
|
|
16
|
+
/**
|
|
17
|
+
* preview extension.
|
|
18
|
+
*/
|
|
19
|
+
preview: PreviewMain, logger: Logger);
|
|
12
20
|
route: string;
|
|
13
21
|
method: string;
|
|
14
22
|
middlewares: ((req: Request<UrlParams>, res: Response) => Promise<import("express").Response<any>>)[];
|
package/dist/preview.task.d.ts
CHANGED
|
@@ -7,9 +7,23 @@ import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
|
|
7
7
|
import { PreviewDefinition } from './preview-definition';
|
|
8
8
|
import { PreviewMain } from './preview.main.runtime';
|
|
9
9
|
export declare class PreviewTask implements BuildTask {
|
|
10
|
+
/**
|
|
11
|
+
* bundler extension.
|
|
12
|
+
*/
|
|
10
13
|
private bundler;
|
|
14
|
+
/**
|
|
15
|
+
* preview extension.
|
|
16
|
+
*/
|
|
11
17
|
private preview;
|
|
12
|
-
constructor(
|
|
18
|
+
constructor(
|
|
19
|
+
/**
|
|
20
|
+
* bundler extension.
|
|
21
|
+
*/
|
|
22
|
+
bundler: BundlerMain,
|
|
23
|
+
/**
|
|
24
|
+
* preview extension.
|
|
25
|
+
*/
|
|
26
|
+
preview: PreviewMain);
|
|
13
27
|
aspectId: string;
|
|
14
28
|
name: string;
|
|
15
29
|
location: TaskLocation;
|
|
@@ -2,6 +2,9 @@ import { RenderingContextSlot } from './preview.preview.runtime';
|
|
|
2
2
|
export declare class RenderingContext {
|
|
3
3
|
private contexts;
|
|
4
4
|
constructor(contexts: RenderingContextSlot);
|
|
5
|
+
/**
|
|
6
|
+
* obtain rendering context of a specific aspect.
|
|
7
|
+
*/
|
|
5
8
|
get(aspectId: string): {
|
|
6
9
|
[key: string]: any;
|
|
7
10
|
} | undefined;
|
|
@@ -3,6 +3,9 @@ import { BundlerResult, BundlerContext } from '@teambit/bundler';
|
|
|
3
3
|
import { BundlingStrategy } from '../bundling-strategy';
|
|
4
4
|
import { PreviewDefinition } from '../preview-definition';
|
|
5
5
|
import { PreviewMain } from '../preview.main.runtime';
|
|
6
|
+
/**
|
|
7
|
+
* bundles all components in a given env into the same bundle.
|
|
8
|
+
*/
|
|
6
9
|
export declare class EnvBundlingStrategy implements BundlingStrategy {
|
|
7
10
|
private preview;
|
|
8
11
|
name: string;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A full index of the preview data
|
|
3
|
+
*/
|
|
1
4
|
export declare type PreviewModule<T = any> = {
|
|
5
|
+
/** Dictionary mapping components to their module files. */
|
|
2
6
|
componentMap: Record<string, ModuleFile<T>[]>;
|
|
7
|
+
/** The 'main file' for this Preview type */
|
|
3
8
|
mainModule: {
|
|
4
9
|
default: (...args: any[]) => void;
|
|
5
10
|
};
|
|
6
11
|
};
|
|
12
|
+
/** single preview module, e.g. compositions file */
|
|
7
13
|
export declare type ModuleFile<T = any> = Record<string, T>;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/preview",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.556",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/preview/preview",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.preview",
|
|
8
8
|
"name": "preview",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.556"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"fs-extra": "10.0.0",
|
|
@@ -17,26 +17,26 @@
|
|
|
17
17
|
"mime": "2.5.2",
|
|
18
18
|
"@babel/runtime": "7.12.18",
|
|
19
19
|
"core-js": "^3.0.0",
|
|
20
|
-
"@teambit/builder": "0.0.
|
|
21
|
-
"@teambit/bundler": "0.0.
|
|
22
|
-
"@teambit/component": "0.0.
|
|
23
|
-
"@teambit/envs": "0.0.
|
|
24
|
-
"@teambit/toolbox.path.to-windows-compatible-path": "0.0.
|
|
25
|
-
"@teambit/aspect-loader": "0.0.
|
|
26
|
-
"@teambit/cli": "0.0.
|
|
27
|
-
"@teambit/logger": "0.0.
|
|
28
|
-
"@teambit/pkg": "0.0.
|
|
29
|
-
"@teambit/pubsub": "0.0.
|
|
30
|
-
"@teambit/ui": "0.0.
|
|
31
|
-
"@teambit/workspace": "0.0.
|
|
32
|
-
"@teambit/component-id": "0.0.
|
|
33
|
-
"@teambit/express": "0.0.
|
|
34
|
-
"@teambit/ui-foundation.ui.pages.static-error": "0.0.
|
|
35
|
-
"@teambit/compiler": "0.0.
|
|
36
|
-
"@teambit/preview.cli.preview-server-status": "0.0.
|
|
37
|
-
"@teambit/preview.cli.webpack-events-listener": "0.0.
|
|
38
|
-
"@teambit/isolator": "0.0.
|
|
39
|
-
"@teambit/bit-error": "0.0.
|
|
20
|
+
"@teambit/builder": "0.0.556",
|
|
21
|
+
"@teambit/bundler": "0.0.556",
|
|
22
|
+
"@teambit/component": "0.0.556",
|
|
23
|
+
"@teambit/envs": "0.0.556",
|
|
24
|
+
"@teambit/toolbox.path.to-windows-compatible-path": "0.0.461",
|
|
25
|
+
"@teambit/aspect-loader": "0.0.556",
|
|
26
|
+
"@teambit/cli": "0.0.387",
|
|
27
|
+
"@teambit/logger": "0.0.472",
|
|
28
|
+
"@teambit/pkg": "0.0.556",
|
|
29
|
+
"@teambit/pubsub": "0.0.556",
|
|
30
|
+
"@teambit/ui": "0.0.556",
|
|
31
|
+
"@teambit/workspace": "0.0.556",
|
|
32
|
+
"@teambit/component-id": "0.0.377",
|
|
33
|
+
"@teambit/express": "0.0.476",
|
|
34
|
+
"@teambit/ui-foundation.ui.pages.static-error": "0.0.48",
|
|
35
|
+
"@teambit/compiler": "0.0.556",
|
|
36
|
+
"@teambit/preview.cli.preview-server-status": "0.0.467",
|
|
37
|
+
"@teambit/preview.cli.webpack-events-listener": "0.0.137",
|
|
38
|
+
"@teambit/isolator": "0.0.556",
|
|
39
|
+
"@teambit/bit-error": "0.0.373"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/fs-extra": "9.0.7",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"@types/jest": "^26.0.0",
|
|
50
50
|
"@types/react-dom": "^17.0.5",
|
|
51
51
|
"@types/node": "12.20.4",
|
|
52
|
-
"@teambit/preview.aspect-docs.preview": "0.0.
|
|
52
|
+
"@teambit/preview.aspect-docs.preview": "0.0.106"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@teambit/legacy": "1.0.
|
|
55
|
+
"@teambit/legacy": "1.0.173",
|
|
56
56
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
57
57
|
"react": "^16.8.0 || ^17.0.0"
|
|
58
58
|
},
|
|
@@ -80,12 +80,18 @@
|
|
|
80
80
|
"react": "-"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
|
-
"@teambit/legacy": "1.0.
|
|
83
|
+
"@teambit/legacy": "1.0.173",
|
|
84
84
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
85
85
|
"react": "^16.8.0 || ^17.0.0"
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
},
|
|
89
|
+
"files": [
|
|
90
|
+
"dist",
|
|
91
|
+
"!dist/tsconfig.tsbuildinfo",
|
|
92
|
+
"README.md",
|
|
93
|
+
"README.mdx"
|
|
94
|
+
],
|
|
89
95
|
"private": false,
|
|
90
96
|
"engines": {
|
|
91
97
|
"node": ">=12.22.0"
|
package/bundling-strategy.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { BuildContext, BuiltTaskResult } from '@teambit/builder';
|
|
2
|
-
import { Target, BundlerResult, BundlerContext } from '@teambit/bundler';
|
|
3
|
-
import { PreviewDefinition } from './preview-definition';
|
|
4
|
-
import { PreviewTask } from './preview.task';
|
|
5
|
-
|
|
6
|
-
export interface BundlingStrategy {
|
|
7
|
-
/**
|
|
8
|
-
* name of the bundling strategy.
|
|
9
|
-
*/
|
|
10
|
-
name: string;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* compute bundling targets for the build context.
|
|
14
|
-
*/
|
|
15
|
-
computeTargets(context: BuildContext, previewDefs: PreviewDefinition[], previewTask: PreviewTask): Promise<Target[]>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* compute the results of the bundler.
|
|
19
|
-
*/
|
|
20
|
-
computeResults(context: BundlerContext, results: BundlerResult[], previewTask: PreviewTask): Promise<BuiltTaskResult>;
|
|
21
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-classes-per-file */
|
|
2
|
-
import { BitBaseEvent } from '@teambit/pubsub';
|
|
3
|
-
|
|
4
|
-
class ClickInsideAnIframeEventData {
|
|
5
|
-
constructor(private clickEvent: any) {}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class ClickInsideAnIframeEvent extends BitBaseEvent<ClickInsideAnIframeEventData> {
|
|
9
|
-
static readonly TYPE = 'click-inside-an-iframe';
|
|
10
|
-
|
|
11
|
-
constructor(readonly timestamp = Date.now(), readonly clickEvent) {
|
|
12
|
-
super(ClickInsideAnIframeEvent.TYPE, '0.0.1', timestamp, new ClickInsideAnIframeEventData(clickEvent));
|
|
13
|
-
}
|
|
14
|
-
}
|
package/events/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './click-inside-an-iframe';
|
package/exceptions/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BitError } from '@teambit/bit-error';
|
|
2
|
-
import { ComponentID } from '@teambit/component';
|
|
3
|
-
|
|
4
|
-
export class PreviewArtifactNotFound extends BitError {
|
|
5
|
-
constructor(componentId: ComponentID) {
|
|
6
|
-
super(`preview for component ${componentId.toString()} was not found`);
|
|
7
|
-
}
|
|
8
|
-
}
|
package/execution-ref.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Component, ComponentID } from '@teambit/component';
|
|
2
|
-
import type { ExecutionContext } from '@teambit/envs';
|
|
3
|
-
|
|
4
|
-
// TODO - use workspace.list() instead of this
|
|
5
|
-
export class ExecutionRef {
|
|
6
|
-
constructor(public executionCtx: ExecutionContext) {
|
|
7
|
-
this.currentComponents = executionCtx.components;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
currentComponents: Component[];
|
|
11
|
-
|
|
12
|
-
add(added: Component) {
|
|
13
|
-
this.currentComponents = this.currentComponents.concat(added);
|
|
14
|
-
}
|
|
15
|
-
remove(removed: ComponentID) {
|
|
16
|
-
this.currentComponents = this.currentComponents.filter((c) => c.id.toString() !== removed.toString());
|
|
17
|
-
}
|
|
18
|
-
update(next: Component) {
|
|
19
|
-
this.currentComponents = this.currentComponents.map((c) => (c.equals(next) ? next : c));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get(id: ComponentID) {
|
|
23
|
-
return this.currentComponents.find((x) => x.id.isEqual(id));
|
|
24
|
-
}
|
|
25
|
-
}
|
package/generate-link.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { toWindowsCompatiblePath } from '@teambit/toolbox.path.to-windows-compatible-path';
|
|
2
|
-
import type { ComponentMap } from '@teambit/component';
|
|
3
|
-
|
|
4
|
-
// :TODO refactor to building an AST and generate source code based on it.
|
|
5
|
-
export function generateLink(prefix: string, componentMap: ComponentMap<string[]>, defaultModule?: string): string {
|
|
6
|
-
return `
|
|
7
|
-
import { linkModules } from '${toWindowsCompatiblePath(require.resolve('./preview.preview.runtime'))}';
|
|
8
|
-
import harmony from '${toWindowsCompatiblePath(require.resolve('@teambit/harmony'))}';
|
|
9
|
-
${defaultModule ? `const defaultModule = require('${toWindowsCompatiblePath(defaultModule)}'` : ''});
|
|
10
|
-
linkModules('${prefix}', defaultModule, {
|
|
11
|
-
${componentMap
|
|
12
|
-
.toArray()
|
|
13
|
-
.map(([component, modulePaths]: any) => {
|
|
14
|
-
return `'${component.id.fullName}': [${modulePaths
|
|
15
|
-
.map((path) => `require('${toWindowsCompatiblePath(path)}')`)
|
|
16
|
-
.join(', ')}]`;
|
|
17
|
-
})
|
|
18
|
-
.join(',\n')}
|
|
19
|
-
});
|
|
20
|
-
`;
|
|
21
|
-
}
|
package/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { PreviewAspect as default, PreviewAspect, PreviewRuntime } from './preview.aspect';
|
|
2
|
-
|
|
3
|
-
export * from './events';
|
|
4
|
-
export type { PreviewMain } from './preview.main.runtime';
|
|
5
|
-
export type { PreviewPreview } from './preview.preview.runtime';
|
|
6
|
-
export { PreviewDefinition } from './preview-definition';
|
|
7
|
-
export type { PreviewModule, ModuleFile } from './types/preview-module';
|
|
8
|
-
export type { RenderingContext } from './rendering-context';
|
package/mk-temp-dir.ts
DELETED
|
Binary file
|
package/preview-artifact.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
|
2
|
-
import { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';
|
|
3
|
-
|
|
4
|
-
export class PreviewArtifact {
|
|
5
|
-
constructor(private artifacts: AbstractVinyl[]) {}
|
|
6
|
-
|
|
7
|
-
getFile(path: string) {
|
|
8
|
-
return this.artifacts.find((file) => {
|
|
9
|
-
return pathNormalizeToLinux(file.relative) === path;
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
}
|
package/preview-context.ts
DELETED
package/preview-definition.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Component, ComponentMap } from '@teambit/component';
|
|
2
|
-
import { ExecutionContext } from '@teambit/envs';
|
|
3
|
-
import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
|
4
|
-
|
|
5
|
-
export interface PreviewDefinition {
|
|
6
|
-
/**
|
|
7
|
-
* extension preview prefix
|
|
8
|
-
*/
|
|
9
|
-
prefix: string;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* path of the default template to be executed.
|
|
13
|
-
*/
|
|
14
|
-
renderTemplatePath?: (context: ExecutionContext) => Promise<string>;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* get all files to require in the preview runtime.
|
|
18
|
-
*/
|
|
19
|
-
getModuleMap(components: Component[]): Promise<ComponentMap<AbstractVinyl[]>>;
|
|
20
|
-
}
|
package/preview-type.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { RenderingContext } from './rendering-context';
|
|
2
|
-
import { PreviewModule } from './types/preview-module';
|
|
3
|
-
|
|
4
|
-
export interface PreviewType {
|
|
5
|
-
/**
|
|
6
|
-
* preview name to register.
|
|
7
|
-
*/
|
|
8
|
-
name: string;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* preview render method.
|
|
12
|
-
*/
|
|
13
|
-
render(
|
|
14
|
-
componentId: string,
|
|
15
|
-
linkedModules: PreviewModule<any>,
|
|
16
|
-
includedPreviews: string[],
|
|
17
|
-
renderingContext: RenderingContext
|
|
18
|
-
): void;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* determine if this will be the default preview to render.
|
|
22
|
-
*/
|
|
23
|
-
default?: boolean;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* which other extension modules to include in the preview context.
|
|
27
|
-
*/
|
|
28
|
-
include?: string[];
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* select relevant information to show in preview context
|
|
32
|
-
*/
|
|
33
|
-
selectPreviewModel?: (componentId: string, module: PreviewModule) => any;
|
|
34
|
-
}
|
package/preview.aspect.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Aspect, RuntimeDefinition } from '@teambit/harmony';
|
|
2
|
-
|
|
3
|
-
export const PreviewRuntime = new RuntimeDefinition('preview');
|
|
4
|
-
|
|
5
|
-
export const PreviewAspect = Aspect.create({
|
|
6
|
-
id: 'teambit.preview/preview',
|
|
7
|
-
dependencies: [],
|
|
8
|
-
defaultConfig: {},
|
|
9
|
-
declareRuntime: PreviewRuntime,
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
export default PreviewAspect;
|
package/preview.docs.mdx
DELETED
package/preview.graphql.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Component } from '@teambit/component';
|
|
2
|
-
import gql from 'graphql-tag';
|
|
3
|
-
|
|
4
|
-
import { PreviewMain } from './preview.main.runtime';
|
|
5
|
-
|
|
6
|
-
export function previewSchema(previewExtension: PreviewMain) {
|
|
7
|
-
return {
|
|
8
|
-
typeDefs: gql`
|
|
9
|
-
type Preview {
|
|
10
|
-
url: String!
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
extend type Component {
|
|
14
|
-
preview: Preview
|
|
15
|
-
}
|
|
16
|
-
`,
|
|
17
|
-
resolvers: {
|
|
18
|
-
Component: {
|
|
19
|
-
preview: (component: Component) => {
|
|
20
|
-
return previewExtension.getPreview(component);
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|