@teambit/application 1.0.108 → 1.0.110
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/artifacts/preview/teambit_harmony_application-preview.js +1 -0
- package/dist/{preview-1703647408454.js → preview-1703733956734.js} +2 -2
- package/package.json +21 -17
- package/app-build-context.ts +0 -55
- package/app-build-result.ts +0 -26
- package/app-context.ts +0 -97
- package/app-deploy-context.ts +0 -38
- package/app-instance.ts +0 -36
- package/app-server.ts +0 -9
- package/app-type-list.ts +0 -25
- package/app-type.plugin.ts +0 -24
- package/app.cmd.ts +0 -46
- package/app.plugin.ts +0 -17
- package/application-type.ts +0 -18
- package/application.aspect.ts +0 -5
- package/application.main.runtime.ts +0 -485
- package/application.service.ts +0 -32
- package/application.ts +0 -41
- package/apps-env-type.ts +0 -9
- package/build-application.task.ts +0 -183
- package/deploy.task.ts +0 -134
- package/deployment-provider.ts +0 -5
- package/index.ts +0 -13
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
2
|
-
import mapSeries from 'p-map-series';
|
|
3
|
-
import {
|
|
4
|
-
BuildTask,
|
|
5
|
-
BuiltTaskResult,
|
|
6
|
-
BuildContext,
|
|
7
|
-
ComponentResult,
|
|
8
|
-
ArtifactDefinition,
|
|
9
|
-
CAPSULE_ARTIFACTS_DIR,
|
|
10
|
-
} from '@teambit/builder';
|
|
11
|
-
import { compact } from 'lodash';
|
|
12
|
-
import { Capsule } from '@teambit/isolator';
|
|
13
|
-
import { Component } from '@teambit/component';
|
|
14
|
-
|
|
15
|
-
import { ApplicationAspect } from './application.aspect';
|
|
16
|
-
import { ApplicationMain } from './application.main.runtime';
|
|
17
|
-
import { AppBuildContext } from './app-build-context';
|
|
18
|
-
import { Application } from './application';
|
|
19
|
-
|
|
20
|
-
export const BUILD_TASK = 'build_application';
|
|
21
|
-
export const ARTIFACTS_DIR_NAME = 'apps';
|
|
22
|
-
|
|
23
|
-
export type OneAppResult = {
|
|
24
|
-
componentResult: ComponentResult;
|
|
25
|
-
artifacts?: ArtifactDefinition[];
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export type OneComponentResult = {
|
|
29
|
-
componentResult: ComponentResult;
|
|
30
|
-
artifacts?: ArtifactDefinition[];
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type BuildAppResult = {
|
|
34
|
-
componentResult: ComponentResult;
|
|
35
|
-
artifacts?: ArtifactDefinition[];
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type BuildDeployContexts = {
|
|
39
|
-
deployContext: { publicDir?: string; ssrPublicDir?: string };
|
|
40
|
-
name: string;
|
|
41
|
-
appType: string;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export type Options = {
|
|
45
|
-
deploy: boolean;
|
|
46
|
-
};
|
|
47
|
-
export class AppsBuildTask implements BuildTask {
|
|
48
|
-
name = BUILD_TASK;
|
|
49
|
-
aspectId = ApplicationAspect.id;
|
|
50
|
-
readonly location = 'end';
|
|
51
|
-
constructor(private application: ApplicationMain, private opt: Options = { deploy: true }) {}
|
|
52
|
-
|
|
53
|
-
async execute(context: BuildContext): Promise<BuiltTaskResult> {
|
|
54
|
-
const originalSeedersIds = context.capsuleNetwork.originalSeedersCapsules.map((c) => c.component.id.toString());
|
|
55
|
-
const { capsuleNetwork } = context;
|
|
56
|
-
const result: BuiltTaskResult = {
|
|
57
|
-
componentsResults: [],
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// const componentsResults = await mapSeries(apps, async (app): Promise<AppsResults | undefined> => {
|
|
61
|
-
await mapSeries(capsuleNetwork.originalSeedersCapsules, async (capsule) => {
|
|
62
|
-
const component = capsule.component;
|
|
63
|
-
if (originalSeedersIds && originalSeedersIds.length && !originalSeedersIds.includes(component.id.toString())) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const apps = await this.application.loadAppsFromComponent(component, capsule.path);
|
|
68
|
-
if (!apps || !apps.length) return undefined;
|
|
69
|
-
const componentsResults = await mapSeries(compact(apps), async (app) =>
|
|
70
|
-
this.runForOneApp(app, component, capsule, context)
|
|
71
|
-
);
|
|
72
|
-
const merged = this.mergeAppsResults(compact(componentsResults));
|
|
73
|
-
if (merged) {
|
|
74
|
-
result.componentsResults.push(merged.componentResult);
|
|
75
|
-
if (!result.artifacts) result.artifacts = [];
|
|
76
|
-
result.artifacts.push(...(merged.artifacts || []));
|
|
77
|
-
}
|
|
78
|
-
return undefined;
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private async runForOneApp(
|
|
85
|
-
app: Application,
|
|
86
|
-
component: Component,
|
|
87
|
-
capsule: Capsule,
|
|
88
|
-
context: BuildContext
|
|
89
|
-
): Promise<OneAppResult | undefined> {
|
|
90
|
-
if (!app.build) return undefined;
|
|
91
|
-
const artifactsDir = this.getArtifactDirectory();
|
|
92
|
-
const capsuleRootDir = context.capsuleNetwork.capsulesRootDir;
|
|
93
|
-
const appContext = await this.application.createAppBuildContext(
|
|
94
|
-
component.id,
|
|
95
|
-
app.name,
|
|
96
|
-
capsuleRootDir,
|
|
97
|
-
capsule.path
|
|
98
|
-
);
|
|
99
|
-
const appBuildContext = AppBuildContext.create({
|
|
100
|
-
appContext,
|
|
101
|
-
buildContext: context,
|
|
102
|
-
appComponent: component,
|
|
103
|
-
name: app.name,
|
|
104
|
-
capsule,
|
|
105
|
-
artifactsDir,
|
|
106
|
-
});
|
|
107
|
-
const deployContext = await app.build(appBuildContext);
|
|
108
|
-
const defaultArtifacts: ArtifactDefinition[] = this.getDefaultArtifactDef(app.applicationType || app.name);
|
|
109
|
-
const artifacts = defaultArtifacts.concat(deployContext.artifacts || []);
|
|
110
|
-
|
|
111
|
-
const getDeployContextFromMetadata = () => {
|
|
112
|
-
if (deployContext.metadata) {
|
|
113
|
-
return deployContext.metadata;
|
|
114
|
-
}
|
|
115
|
-
// if metadata is not defined, don't save deployContext blindly. in node-app for example it includes the entire
|
|
116
|
-
// Network object, with all capsules and components.
|
|
117
|
-
return {};
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
return {
|
|
121
|
-
artifacts,
|
|
122
|
-
componentResult: {
|
|
123
|
-
component: capsule.component,
|
|
124
|
-
errors: deployContext.errors,
|
|
125
|
-
warnings: deployContext.warnings,
|
|
126
|
-
metadata: { deployContext: getDeployContextFromMetadata(), name: app.name, appType: app.applicationType },
|
|
127
|
-
/**
|
|
128
|
-
* @deprecated - please use metadata instead
|
|
129
|
-
*
|
|
130
|
-
* @guysaar223
|
|
131
|
-
* @ranm8
|
|
132
|
-
* TODO: we need to think how to pass private metadata between build pipes, maybe create shared context
|
|
133
|
-
* or create new deploy context on builder
|
|
134
|
-
*/
|
|
135
|
-
// @ts-ignore
|
|
136
|
-
_metadata: { deployContext, name: app.name, appType: app.applicationType },
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private mergeAppsResults(appsResults: OneAppResult[]): OneComponentResult | undefined {
|
|
142
|
-
if (!appsResults || !appsResults.length) return undefined;
|
|
143
|
-
const merged: OneComponentResult = {
|
|
144
|
-
artifacts: [],
|
|
145
|
-
componentResult: {
|
|
146
|
-
component: appsResults[0].componentResult.component,
|
|
147
|
-
errors: [],
|
|
148
|
-
warnings: [],
|
|
149
|
-
metadata: {
|
|
150
|
-
buildDeployContexts: [],
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
appsResults.forEach((appResult) => {
|
|
155
|
-
merged.artifacts = (merged.artifacts || []).concat(appResult.artifacts || []);
|
|
156
|
-
merged.componentResult.errors = (merged.componentResult.errors || []).concat(
|
|
157
|
-
appResult.componentResult.errors || []
|
|
158
|
-
);
|
|
159
|
-
merged.componentResult.warnings = (merged.componentResult.warnings || []).concat(
|
|
160
|
-
appResult.componentResult.warnings || []
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
164
|
-
merged.componentResult.metadata!.buildDeployContexts =
|
|
165
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
166
|
-
(merged.componentResult.metadata!.buildDeployContexts || []).concat(appResult.componentResult.metadata || []);
|
|
167
|
-
});
|
|
168
|
-
return merged;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
private getArtifactDirectory() {
|
|
172
|
-
return join(CAPSULE_ARTIFACTS_DIR, ARTIFACTS_DIR_NAME);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
private getDefaultArtifactDef(nameSuffix: string): ArtifactDefinition[] {
|
|
176
|
-
return [
|
|
177
|
-
{
|
|
178
|
-
name: `app-build-${nameSuffix}`,
|
|
179
|
-
globPatterns: [`${this.getArtifactDirectory()}/**`],
|
|
180
|
-
},
|
|
181
|
-
];
|
|
182
|
-
}
|
|
183
|
-
}
|
package/deploy.task.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import mapSeries from 'p-map-series';
|
|
2
|
-
import {
|
|
3
|
-
BuilderMain,
|
|
4
|
-
BuildTask,
|
|
5
|
-
BuildContext,
|
|
6
|
-
ComponentResult,
|
|
7
|
-
TaskResults,
|
|
8
|
-
BuiltTaskResult,
|
|
9
|
-
CAPSULE_ARTIFACTS_DIR,
|
|
10
|
-
} from '@teambit/builder';
|
|
11
|
-
import { compact, join } from 'lodash';
|
|
12
|
-
import { Capsule } from '@teambit/isolator';
|
|
13
|
-
import { Component } from '@teambit/component';
|
|
14
|
-
import { ApplicationAspect } from './application.aspect';
|
|
15
|
-
import { ApplicationMain } from './application.main.runtime';
|
|
16
|
-
import { ARTIFACTS_DIR_NAME, BUILD_TASK, BuildDeployContexts } from './build-application.task';
|
|
17
|
-
import { AppDeployContext } from './app-deploy-context';
|
|
18
|
-
import { Application } from './application';
|
|
19
|
-
import { ApplicationDeployment } from './app-instance';
|
|
20
|
-
import { AppBuildContext } from './app-build-context';
|
|
21
|
-
|
|
22
|
-
export const DEPLOY_TASK = 'deploy_application';
|
|
23
|
-
|
|
24
|
-
export class DeployTask implements BuildTask {
|
|
25
|
-
name = DEPLOY_TASK;
|
|
26
|
-
aspectId = ApplicationAspect.id;
|
|
27
|
-
readonly location = 'end';
|
|
28
|
-
constructor(private application: ApplicationMain, private builder: BuilderMain) {}
|
|
29
|
-
|
|
30
|
-
async execute(context: BuildContext): Promise<BuiltTaskResult> {
|
|
31
|
-
const originalSeedersIds = context.capsuleNetwork.originalSeedersCapsules.map((c) => c.component.id.toString());
|
|
32
|
-
const { capsuleNetwork } = context;
|
|
33
|
-
|
|
34
|
-
const components = await mapSeries(capsuleNetwork.originalSeedersCapsules, async (capsule) => {
|
|
35
|
-
const component = capsule.component;
|
|
36
|
-
if (originalSeedersIds && originalSeedersIds.length && !originalSeedersIds.includes(component.id.toString())) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
const apps = await this.application.loadAppsFromComponent(component, capsule.path);
|
|
40
|
-
if (!apps || !apps.length) return undefined;
|
|
41
|
-
const appDeployments = await mapSeries(compact(apps), async (app) => this.runForOneApp(app, capsule, context));
|
|
42
|
-
const deploys = compact(appDeployments);
|
|
43
|
-
return { component, deploys };
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const _componentsResults: ComponentResult[] = compact(components).map(({ component, deploys }) => {
|
|
47
|
-
return {
|
|
48
|
-
component,
|
|
49
|
-
metadata: {
|
|
50
|
-
deployments: deploys.map((deploy) => {
|
|
51
|
-
const deployObject = deploy || {};
|
|
52
|
-
return {
|
|
53
|
-
appName: deployObject?.appName,
|
|
54
|
-
timestamp: deployObject?.timestamp,
|
|
55
|
-
url: deployObject?.url,
|
|
56
|
-
};
|
|
57
|
-
}),
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
componentsResults: _componentsResults,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private async runForOneApp(
|
|
68
|
-
app: Application,
|
|
69
|
-
capsule: Capsule,
|
|
70
|
-
context: BuildContext
|
|
71
|
-
): Promise<ApplicationDeployment | void | undefined> {
|
|
72
|
-
const aspectId = this.application.getAppAspect(app.name);
|
|
73
|
-
if (!aspectId) return undefined;
|
|
74
|
-
|
|
75
|
-
if (!capsule || !capsule?.component) return undefined;
|
|
76
|
-
|
|
77
|
-
const buildTask = this.getBuildTask(context.previousTasksResults, context.envRuntime.id);
|
|
78
|
-
|
|
79
|
-
const metadata = this.getBuildMetadata(buildTask, capsule.component);
|
|
80
|
-
if (!metadata) return undefined;
|
|
81
|
-
const buildDeployContexts = metadata.find((ctx) => ctx.name === app.name && ctx.appType === app.applicationType);
|
|
82
|
-
if (!buildDeployContexts) return undefined;
|
|
83
|
-
|
|
84
|
-
const artifacts = this.builder.getArtifacts(capsule.component);
|
|
85
|
-
const appContext = await this.application.createAppBuildContext(capsule.component.id, app.name, capsule.path);
|
|
86
|
-
const artifactsDir = this.getArtifactDirectory();
|
|
87
|
-
const appBuildContext = AppBuildContext.create({
|
|
88
|
-
appContext,
|
|
89
|
-
buildContext: context,
|
|
90
|
-
appComponent: capsule.component,
|
|
91
|
-
name: app.name,
|
|
92
|
-
capsule,
|
|
93
|
-
artifactsDir,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const appDeployContext = new AppDeployContext(
|
|
97
|
-
appBuildContext,
|
|
98
|
-
artifacts,
|
|
99
|
-
buildDeployContexts.deployContext.publicDir,
|
|
100
|
-
buildDeployContexts.deployContext.ssrPublicDir
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
if (app && typeof app.deploy === 'function') {
|
|
104
|
-
return app.deploy(appDeployContext);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return undefined;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
private getArtifactDirectory() {
|
|
111
|
-
return join(CAPSULE_ARTIFACTS_DIR, ARTIFACTS_DIR_NAME);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
private getBuildMetadata(
|
|
115
|
-
buildTask: TaskResults | undefined,
|
|
116
|
-
component: Component
|
|
117
|
-
): BuildDeployContexts[] | undefined {
|
|
118
|
-
if (!buildTask) {
|
|
119
|
-
const appData = this.builder.getDataByAspect(component, ApplicationAspect.id);
|
|
120
|
-
if (!appData) return undefined;
|
|
121
|
-
return appData.buildDeployContexts;
|
|
122
|
-
}
|
|
123
|
-
const componentResults = buildTask?.componentsResults.find((res) =>
|
|
124
|
-
res.component.id.isEqual(component.id, { ignoreVersion: true })
|
|
125
|
-
);
|
|
126
|
-
return componentResults?.metadata?.buildDeployContexts;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private getBuildTask(taskResults: TaskResults[], runtime: string) {
|
|
130
|
-
return taskResults.find(
|
|
131
|
-
({ task, env }) => task.aspectId === ApplicationAspect.id && task.name === BUILD_TASK && env.id === runtime
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
}
|
package/deployment-provider.ts
DELETED
package/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { ApplicationAspect } from './application.aspect';
|
|
2
|
-
export type { ApplicationInstance, ApplicationDeployment } from './app-instance';
|
|
3
|
-
export type { ApplicationMain, ApplicationMetadata } from './application.main.runtime';
|
|
4
|
-
export type { Application, DeployFn, BuildFn, AppResult } from './application';
|
|
5
|
-
export { AppContext } from './app-context';
|
|
6
|
-
export type { DeploymentProvider } from './deployment-provider';
|
|
7
|
-
export type { ApplicationType } from './application-type';
|
|
8
|
-
export type { AppDeployContext } from './app-deploy-context';
|
|
9
|
-
export type { AppBuildContext } from './app-build-context';
|
|
10
|
-
export type { AppBuildResult } from './app-build-result';
|
|
11
|
-
export { ARTIFACTS_DIR_NAME as APPS_ARTIFACTS_DIR_NAME } from './build-application.task';
|
|
12
|
-
export type { AppsEnv } from './apps-env-type';
|
|
13
|
-
export { AppTypeList } from './app-type-list';
|