@teambit/builder 0.0.555 → 0.0.559
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/build.cmd.d.ts +2 -1
- package/dist/build.cmd.js +9 -3
- package/dist/build.cmd.js.map +1 -1
- package/package.json +32 -17
- package/tsconfig.json +1 -1
- package/artifact/artifact-definition.ts +0 -52
- package/artifact/artifact-extractor.ts +0 -116
- package/artifact/artifact-factory.ts +0 -119
- package/artifact/artifact-list.ts +0 -64
- package/artifact/artifact.ts +0 -81
- package/artifact/artifacts.cmd.ts +0 -68
- package/artifact/extension-artifact.ts +0 -12
- package/artifact/index.ts +0 -5
- package/build-pipe.ts +0 -167
- package/build-pipeline-order.ts +0 -197
- package/build-pipeline-result-list.ts +0 -97
- package/build-task.ts +0 -114
- package/build.cmd.ts +0 -91
- package/builder.aspect.ts +0 -5
- package/builder.graphql.ts +0 -38
- package/builder.main.runtime.ts +0 -346
- package/builder.service.tsx +0 -163
- package/exceptions/artifact-storage-error.ts +0 -7
- package/exceptions/capsule-not-found.ts +0 -7
- package/exceptions/index.ts +0 -3
- package/exceptions/invalid-task.ts +0 -7
- package/index.ts +0 -9
- package/package-tar/teambit-builder-0.0.555.tgz +0 -0
- package/pipeline/index.ts +0 -1
- package/pipeline/pipeline-results.ts +0 -1
- package/storage/default-resolver.ts +0 -13
- package/storage/index.ts +0 -2
- package/storage/s3-resolver.ts +0 -40
- package/storage/storage-resolver.ts +0 -18
- package/task-results-list.ts +0 -66
- package/tasks-queue.ts +0 -40
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
- package/types.ts +0 -39
package/build.cmd.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
-
import { Logger } from '@teambit/logger';
|
|
3
|
-
import { Workspace } from '@teambit/workspace';
|
|
4
|
-
import { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import { BuilderMain } from './builder.main.runtime';
|
|
7
|
-
|
|
8
|
-
type BuildOpts = {
|
|
9
|
-
rebuild: boolean;
|
|
10
|
-
install: boolean;
|
|
11
|
-
cachePackagesOnCapsulesRoot: boolean;
|
|
12
|
-
reuseCapsules: boolean;
|
|
13
|
-
tasks: string;
|
|
14
|
-
listTasks?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export class BuilderCmd implements Command {
|
|
18
|
-
name = 'build [pattern]';
|
|
19
|
-
description = 'run set of tasks for build';
|
|
20
|
-
alias = '';
|
|
21
|
-
group = 'development';
|
|
22
|
-
options = [
|
|
23
|
-
['', 'install', 'install core aspects in capsules'],
|
|
24
|
-
['', 'reuse-capsules', 'avoid deleting the capsules root-dir before starting the build'],
|
|
25
|
-
[
|
|
26
|
-
'',
|
|
27
|
-
'tasks <string>',
|
|
28
|
-
`build the specified task(s) only. for multiple tasks, separate by a comma and wrap with quotes.
|
|
29
|
-
specify the task-name (e.g. "TypescriptCompiler") or the task-aspect-id (e.g. teambit.compilation/compiler)`,
|
|
30
|
-
],
|
|
31
|
-
['', 'cache-packages-on-capsule-root', 'set the package-manager cache on the capsule root'],
|
|
32
|
-
[
|
|
33
|
-
'',
|
|
34
|
-
'list-tasks <string>',
|
|
35
|
-
'list tasks of an env or a component-id for each one of the pipelines: build, tag and snap',
|
|
36
|
-
],
|
|
37
|
-
] as CommandOptions;
|
|
38
|
-
|
|
39
|
-
constructor(private builder: BuilderMain, private workspace: Workspace, private logger: Logger) {}
|
|
40
|
-
|
|
41
|
-
async report(
|
|
42
|
-
[userPattern]: [string],
|
|
43
|
-
{ install = false, cachePackagesOnCapsulesRoot = false, reuseCapsules = false, tasks, listTasks }: BuildOpts
|
|
44
|
-
): Promise<string> {
|
|
45
|
-
if (!this.workspace) throw new ConsumerNotFound();
|
|
46
|
-
if (listTasks) {
|
|
47
|
-
return this.getListTasks(listTasks);
|
|
48
|
-
}
|
|
49
|
-
const longProcessLogger = this.logger.createLongProcessLogger('build');
|
|
50
|
-
const pattern = userPattern && userPattern.toString();
|
|
51
|
-
const components = pattern ? await this.workspace.byPattern(pattern) : await this.workspace.list();
|
|
52
|
-
|
|
53
|
-
const envsExecutionResults = await this.builder.build(
|
|
54
|
-
components,
|
|
55
|
-
{
|
|
56
|
-
installOptions: {
|
|
57
|
-
installTeambitBit: install,
|
|
58
|
-
},
|
|
59
|
-
linkingOptions: { linkTeambitBit: !install },
|
|
60
|
-
emptyRootDir: !reuseCapsules,
|
|
61
|
-
getExistingAsIs: reuseCapsules,
|
|
62
|
-
cachePackagesOnCapsulesRoot,
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
tasks: tasks ? tasks.split(',').map((task) => task.trim()) : [],
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
longProcessLogger.end();
|
|
69
|
-
envsExecutionResults.throwErrorsIfExist();
|
|
70
|
-
this.logger.consoleSuccess();
|
|
71
|
-
return chalk.green(`the build has been completed. total: ${envsExecutionResults.tasksQueue.length} tasks`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private async getListTasks(componentIdStr: string): Promise<string> {
|
|
75
|
-
const compId = await this.workspace.resolveComponentId(componentIdStr);
|
|
76
|
-
const component = await this.workspace.get(compId);
|
|
77
|
-
const results = this.builder.listTasks(component);
|
|
78
|
-
return `${chalk.green('Tasks List')}
|
|
79
|
-
id: ${results.id.toString()}
|
|
80
|
-
envId: ${results.envId}
|
|
81
|
-
|
|
82
|
-
${chalk.bold('Build Pipeline Tasks:')}
|
|
83
|
-
${results.buildTasks.join('\n')}
|
|
84
|
-
|
|
85
|
-
${chalk.bold('Tag Pipeline Tasks:')}
|
|
86
|
-
${results.tagTasks.join('\n')}
|
|
87
|
-
|
|
88
|
-
${chalk.bold('Snap Pipeline Tasks:')}
|
|
89
|
-
${results.snapTasks.join('\n') || '<N/A>'}`;
|
|
90
|
-
}
|
|
91
|
-
}
|
package/builder.aspect.ts
DELETED
package/builder.graphql.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Component } from '@teambit/component';
|
|
2
|
-
import gql from 'graphql-tag';
|
|
3
|
-
|
|
4
|
-
import { BuilderMain } from './builder.main.runtime';
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
-
export function builderSchema(builder: BuilderMain) {
|
|
8
|
-
return {
|
|
9
|
-
typeDefs: gql`
|
|
10
|
-
type ExtensionDescriptor {
|
|
11
|
-
# extension ID.
|
|
12
|
-
id: String
|
|
13
|
-
|
|
14
|
-
# icon of the extension.
|
|
15
|
-
icon: String
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type ExtensionArtifact {
|
|
19
|
-
# descriptor of the artifact's extension
|
|
20
|
-
extensionDescriptor: ExtensionDescriptor
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
extend type Component {
|
|
24
|
-
# list of extension artifacts.
|
|
25
|
-
getArtifacts(hash: String!): [ExtensionArtifact]
|
|
26
|
-
}
|
|
27
|
-
`,
|
|
28
|
-
resolvers: {
|
|
29
|
-
Component: {
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
31
|
-
getArtifacts: async (component: Component, { hash }: { hash: string }) => {
|
|
32
|
-
// const artifacts = await builder.getArtifacts(component.id, hash);
|
|
33
|
-
// return artifacts.map((artifact) => artifact.toObject());
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
}
|
package/builder.main.runtime.ts
DELETED
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
import { flatten } from 'lodash';
|
|
2
|
-
import { ArtifactVinyl } from '@teambit/legacy/dist/consumer/component/sources/artifact';
|
|
3
|
-
import { AspectLoaderAspect, AspectLoaderMain } from '@teambit/aspect-loader';
|
|
4
|
-
import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
|
|
5
|
-
import { Component, ComponentAspect, ComponentMap } from '@teambit/component';
|
|
6
|
-
import { EnvsAspect, EnvsMain } from '@teambit/envs';
|
|
7
|
-
import { GraphqlAspect, GraphqlMain } from '@teambit/graphql';
|
|
8
|
-
import { Slot, SlotRegistry } from '@teambit/harmony';
|
|
9
|
-
import { LoggerAspect, LoggerMain } from '@teambit/logger';
|
|
10
|
-
import { ScopeAspect, ScopeMain, OnTagResults } from '@teambit/scope';
|
|
11
|
-
import { Workspace, WorkspaceAspect } from '@teambit/workspace';
|
|
12
|
-
import { IsolateComponentsOptions, IsolatorAspect, IsolatorMain } from '@teambit/isolator';
|
|
13
|
-
import { OnTagOpts } from '@teambit/legacy/dist/scope/scope';
|
|
14
|
-
import { ArtifactObject } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';
|
|
15
|
-
import { ArtifactList } from './artifact';
|
|
16
|
-
import { ArtifactFactory } from './artifact/artifact-factory'; // it gets undefined when importing it from './artifact'
|
|
17
|
-
import { BuilderAspect } from './builder.aspect';
|
|
18
|
-
import { builderSchema } from './builder.graphql';
|
|
19
|
-
import { BuilderService, BuilderServiceOptions } from './builder.service';
|
|
20
|
-
import { BuilderCmd } from './build.cmd';
|
|
21
|
-
import { BuildTask } from './build-task';
|
|
22
|
-
import { StorageResolver } from './storage';
|
|
23
|
-
import { TaskResults } from './build-pipe';
|
|
24
|
-
import { TaskResultsList } from './task-results-list';
|
|
25
|
-
import { ArtifactStorageError } from './exceptions';
|
|
26
|
-
import { BuildPipelineResultList, AspectData, PipelineReport } from './build-pipeline-result-list';
|
|
27
|
-
import { Serializable } from './types';
|
|
28
|
-
import { ArtifactsCmd } from './artifact/artifacts.cmd';
|
|
29
|
-
|
|
30
|
-
export type TaskSlot = SlotRegistry<BuildTask[]>;
|
|
31
|
-
|
|
32
|
-
export type StorageResolverSlot = SlotRegistry<StorageResolver>;
|
|
33
|
-
|
|
34
|
-
export type BuilderData = {
|
|
35
|
-
pipeline: PipelineReport[];
|
|
36
|
-
artifacts: ArtifactObject[] | undefined;
|
|
37
|
-
aspectsData: AspectData[];
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export class BuilderMain {
|
|
41
|
-
constructor(
|
|
42
|
-
private envs: EnvsMain,
|
|
43
|
-
private workspace: Workspace,
|
|
44
|
-
private buildService: BuilderService,
|
|
45
|
-
private tagService: BuilderService,
|
|
46
|
-
private snapService: BuilderService,
|
|
47
|
-
private scope: ScopeMain,
|
|
48
|
-
private isolator: IsolatorMain,
|
|
49
|
-
private aspectLoader: AspectLoaderMain,
|
|
50
|
-
private buildTaskSlot: TaskSlot,
|
|
51
|
-
private tagTaskSlot: TaskSlot,
|
|
52
|
-
private snapTaskSlot: TaskSlot,
|
|
53
|
-
private storageResolversSlot: StorageResolverSlot
|
|
54
|
-
) {}
|
|
55
|
-
|
|
56
|
-
private async storeArtifacts(tasksResults: TaskResults[]) {
|
|
57
|
-
const artifacts = tasksResults.flatMap((t) => (t.artifacts ? [t.artifacts] : []));
|
|
58
|
-
const storeP = artifacts.map(async (artifactMap: ComponentMap<ArtifactList>) => {
|
|
59
|
-
return Promise.all(
|
|
60
|
-
artifactMap.toArray().map(async ([component, artifactList]) => {
|
|
61
|
-
try {
|
|
62
|
-
return await artifactList.store(component);
|
|
63
|
-
} catch (err: any) {
|
|
64
|
-
throw new ArtifactStorageError(err, component);
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
await Promise.all(storeP);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private pipelineResultsToBuilderData(
|
|
73
|
-
components: Component[],
|
|
74
|
-
buildPipelineResults: TaskResults[]
|
|
75
|
-
): ComponentMap<BuilderData> {
|
|
76
|
-
const buildPipelineResultList = new BuildPipelineResultList(buildPipelineResults, components);
|
|
77
|
-
return ComponentMap.as<BuilderData>(components, (component) => {
|
|
78
|
-
const aspectsData = buildPipelineResultList.getDataOfComponent(component.id);
|
|
79
|
-
const pipelineReport = buildPipelineResultList.getPipelineReportOfComponent(component.id);
|
|
80
|
-
const artifactsData = buildPipelineResultList.getArtifactsDataOfComponent(component.id);
|
|
81
|
-
return { pipeline: pipelineReport, artifacts: artifactsData, aspectsData };
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async tagListener(
|
|
86
|
-
components: Component[],
|
|
87
|
-
options: OnTagOpts = {},
|
|
88
|
-
isolateOptions: IsolateComponentsOptions = {}
|
|
89
|
-
): Promise<OnTagResults> {
|
|
90
|
-
const pipeResults: TaskResultsList[] = [];
|
|
91
|
-
const { throwOnError, forceDeploy, disableTagAndSnapPipelines, isSnap } = options;
|
|
92
|
-
const envsExecutionResults = await this.build(
|
|
93
|
-
components,
|
|
94
|
-
{ emptyRootDir: true, ...isolateOptions },
|
|
95
|
-
{ skipTests: options.skipTests }
|
|
96
|
-
);
|
|
97
|
-
if (throwOnError && !forceDeploy) envsExecutionResults.throwErrorsIfExist();
|
|
98
|
-
const allTasksResults = [...envsExecutionResults.tasksResults];
|
|
99
|
-
pipeResults.push(envsExecutionResults);
|
|
100
|
-
if (forceDeploy || (!disableTagAndSnapPipelines && !envsExecutionResults.hasErrors())) {
|
|
101
|
-
const deployEnvsExecutionResults = isSnap
|
|
102
|
-
? await this.runSnapTasks(components, isolateOptions)
|
|
103
|
-
: await this.runTagTasks(components, isolateOptions);
|
|
104
|
-
if (throwOnError) deployEnvsExecutionResults.throwErrorsIfExist();
|
|
105
|
-
allTasksResults.push(...deployEnvsExecutionResults.tasksResults);
|
|
106
|
-
pipeResults.push(deployEnvsExecutionResults);
|
|
107
|
-
}
|
|
108
|
-
await this.storeArtifacts(allTasksResults);
|
|
109
|
-
const builderDataMap = this.pipelineResultsToBuilderData(components, allTasksResults);
|
|
110
|
-
return { builderDataMap, pipeResults };
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* register a new storage resolver.
|
|
115
|
-
*/
|
|
116
|
-
registerStorageResolver(storageResolver: StorageResolver) {
|
|
117
|
-
this.storageResolversSlot.register(storageResolver);
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* get storage resolver by name. otherwise, returns default.
|
|
123
|
-
*/
|
|
124
|
-
getStorageResolver(name: string): StorageResolver | undefined {
|
|
125
|
-
return this.storageResolversSlot.values().find((storageResolver) => storageResolver.name === name);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// TODO: merge with getArtifactsVinylByExtensionAndName by getting aspect name and name as object with optional props
|
|
129
|
-
async getArtifactsVinylByExtension(component: Component, aspectName: string): Promise<ArtifactVinyl[]> {
|
|
130
|
-
const artifactsObjects = this.getArtifactsByExtension(component, aspectName);
|
|
131
|
-
const vinyls = await Promise.all(
|
|
132
|
-
(artifactsObjects || []).map((artifactObject) =>
|
|
133
|
-
artifactObject.files.getVinylsAndImportIfMissing(component.id.scope as string, this.scope.legacyScope)
|
|
134
|
-
)
|
|
135
|
-
);
|
|
136
|
-
return flatten(vinyls);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async getArtifactsVinylByExtensionAndName(
|
|
140
|
-
component: Component,
|
|
141
|
-
aspectName: string,
|
|
142
|
-
name: string
|
|
143
|
-
): Promise<ArtifactVinyl[]> {
|
|
144
|
-
const artifactsObjects = this.getArtifactsByExtensionAndName(component, aspectName, name);
|
|
145
|
-
const vinyls = await Promise.all(
|
|
146
|
-
(artifactsObjects || []).map((artifactObject) =>
|
|
147
|
-
artifactObject.files.getVinylsAndImportIfMissing(component.id.scope as string, this.scope.legacyScope)
|
|
148
|
-
)
|
|
149
|
-
);
|
|
150
|
-
return flatten(vinyls);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
getArtifactsByName(component: Component, name: string): ArtifactObject[] | undefined {
|
|
154
|
-
const artifacts = this.getArtifacts(component);
|
|
155
|
-
return artifacts?.filter((artifact) => artifact.name === name);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
getArtifactsByExtension(component: Component, aspectName: string): ArtifactObject[] | undefined {
|
|
159
|
-
const artifacts = this.getArtifacts(component);
|
|
160
|
-
return artifacts?.filter((artifact) => artifact.task.id === aspectName);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
getArtifactsByExtensionAndName(component: Component, aspectName: string, name: string): ArtifactObject[] | undefined {
|
|
164
|
-
const artifacts = this.getArtifacts(component);
|
|
165
|
-
return artifacts?.filter((artifact) => artifact.task.id === aspectName && artifact.name === name);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
getDataByAspect(component: Component, aspectName: string): Serializable | undefined {
|
|
169
|
-
const aspectsData = this.getBuilderData(component)?.aspectsData;
|
|
170
|
-
const data = aspectsData?.find((aspectData) => aspectData.aspectId === aspectName);
|
|
171
|
-
return data?.data;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
getArtifacts(component: Component): ArtifactObject[] | undefined {
|
|
175
|
-
return this.getBuilderData(component)?.artifacts;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
getBuilderData(component: Component): BuilderData | undefined {
|
|
179
|
-
return component.state.aspects.get(BuilderAspect.id)?.data as BuilderData | undefined;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* build given components for release.
|
|
184
|
-
* for each one of the envs it runs a series of tasks.
|
|
185
|
-
* in case of an error in a task, it stops the execution of that env and continue to the next
|
|
186
|
-
* env. at the end, the results contain the data and errors per env.
|
|
187
|
-
*/
|
|
188
|
-
async build(
|
|
189
|
-
components: Component[],
|
|
190
|
-
isolateOptions?: IsolateComponentsOptions,
|
|
191
|
-
builderOptions?: BuilderServiceOptions
|
|
192
|
-
): Promise<TaskResultsList> {
|
|
193
|
-
const ids = components.map((c) => c.id);
|
|
194
|
-
const network = await this.isolator.isolateComponents(ids, isolateOptions);
|
|
195
|
-
const envs = await this.envs.createEnvironment(network.graphCapsules.getAllComponents());
|
|
196
|
-
const builderServiceOptions = { seedersOnly: isolateOptions?.seedersOnly, ...(builderOptions || {}) };
|
|
197
|
-
const buildResult = await envs.runOnce(this.buildService, builderServiceOptions);
|
|
198
|
-
return buildResult;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
async runTagTasks(components: Component[], isolateOptions?: IsolateComponentsOptions): Promise<TaskResultsList> {
|
|
202
|
-
const envs = await this.envs.createEnvironment(components);
|
|
203
|
-
const buildResult = await envs.runOnce(this.tagService, { seedersOnly: isolateOptions?.seedersOnly });
|
|
204
|
-
|
|
205
|
-
return buildResult;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
async runSnapTasks(components: Component[], isolateOptions?: IsolateComponentsOptions): Promise<TaskResultsList> {
|
|
209
|
-
const envs = await this.envs.createEnvironment(components);
|
|
210
|
-
const buildResult = await envs.runOnce(this.snapService, { seedersOnly: isolateOptions?.seedersOnly });
|
|
211
|
-
|
|
212
|
-
return buildResult;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
listTasks(component: Component) {
|
|
216
|
-
const compEnv = this.envs.getEnv(component);
|
|
217
|
-
const buildTasks = this.buildService.getCurrentPipeTasks(compEnv);
|
|
218
|
-
const tagTasks = this.tagService.getCurrentPipeTasks(compEnv);
|
|
219
|
-
const snapTasks = this.snapService.getCurrentPipeTasks(compEnv);
|
|
220
|
-
return { id: component.id, envId: compEnv.id, buildTasks, tagTasks, snapTasks };
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* register a build task to apply on all component build pipelines.
|
|
225
|
-
* build happens on `bit build` and as part of `bit tag --persist`.
|
|
226
|
-
*/
|
|
227
|
-
registerBuildTasks(tasks: BuildTask[]) {
|
|
228
|
-
this.buildTaskSlot.register(tasks);
|
|
229
|
-
return this;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* @deprecated use registerTagTasks or registerSnapTasks
|
|
234
|
-
*/
|
|
235
|
-
registerDeployTasks(tasks: BuildTask[]) {
|
|
236
|
-
this.tagTaskSlot.register(tasks);
|
|
237
|
-
return this;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* tag tasks that don't get executed on `bit build`, only on `bit tag'.
|
|
242
|
-
* this pipeline is running once the build-pipeline has completed.
|
|
243
|
-
*/
|
|
244
|
-
registerTagTasks(tasks: BuildTask[]) {
|
|
245
|
-
this.tagTaskSlot.register(tasks);
|
|
246
|
-
return this;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* tag tasks that don't get executed on `bit build`, only on `bit snap'.
|
|
251
|
-
* this pipeline is running once the build-pipeline has completed.
|
|
252
|
-
*/
|
|
253
|
-
registerSnapTasks(tasks: BuildTask[]) {
|
|
254
|
-
this.snapTaskSlot.register(tasks);
|
|
255
|
-
return this;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
static slots = [
|
|
259
|
-
Slot.withType<BuildTask>(),
|
|
260
|
-
Slot.withType<StorageResolver>(),
|
|
261
|
-
Slot.withType<BuildTask>(),
|
|
262
|
-
Slot.withType<BuildTask>(),
|
|
263
|
-
];
|
|
264
|
-
|
|
265
|
-
static runtime = MainRuntime;
|
|
266
|
-
static dependencies = [
|
|
267
|
-
CLIAspect,
|
|
268
|
-
EnvsAspect,
|
|
269
|
-
WorkspaceAspect,
|
|
270
|
-
ScopeAspect,
|
|
271
|
-
IsolatorAspect,
|
|
272
|
-
LoggerAspect,
|
|
273
|
-
AspectLoaderAspect,
|
|
274
|
-
GraphqlAspect,
|
|
275
|
-
ComponentAspect,
|
|
276
|
-
];
|
|
277
|
-
|
|
278
|
-
static async provider(
|
|
279
|
-
[cli, envs, workspace, scope, isolator, loggerExt, aspectLoader, graphql]: [
|
|
280
|
-
CLIMain,
|
|
281
|
-
EnvsMain,
|
|
282
|
-
Workspace,
|
|
283
|
-
ScopeMain,
|
|
284
|
-
IsolatorMain,
|
|
285
|
-
LoggerMain,
|
|
286
|
-
AspectLoaderMain,
|
|
287
|
-
GraphqlMain
|
|
288
|
-
],
|
|
289
|
-
config,
|
|
290
|
-
[buildTaskSlot, storageResolversSlot, tagTaskSlot, snapTaskSlot]: [
|
|
291
|
-
TaskSlot,
|
|
292
|
-
StorageResolverSlot,
|
|
293
|
-
TaskSlot,
|
|
294
|
-
TaskSlot
|
|
295
|
-
]
|
|
296
|
-
) {
|
|
297
|
-
const artifactFactory = new ArtifactFactory(storageResolversSlot);
|
|
298
|
-
const logger = loggerExt.createLogger(BuilderAspect.id);
|
|
299
|
-
const buildService = new BuilderService(
|
|
300
|
-
isolator,
|
|
301
|
-
logger,
|
|
302
|
-
buildTaskSlot,
|
|
303
|
-
'getBuildPipe',
|
|
304
|
-
'build',
|
|
305
|
-
artifactFactory,
|
|
306
|
-
scope
|
|
307
|
-
);
|
|
308
|
-
envs.registerService(buildService);
|
|
309
|
-
const tagService = new BuilderService(isolator, logger, tagTaskSlot, 'getTagPipe', 'tag', artifactFactory, scope);
|
|
310
|
-
const snapService = new BuilderService(
|
|
311
|
-
isolator,
|
|
312
|
-
logger,
|
|
313
|
-
snapTaskSlot,
|
|
314
|
-
'getSnapPipe',
|
|
315
|
-
'snap',
|
|
316
|
-
artifactFactory,
|
|
317
|
-
scope
|
|
318
|
-
);
|
|
319
|
-
const builder = new BuilderMain(
|
|
320
|
-
envs,
|
|
321
|
-
workspace,
|
|
322
|
-
buildService,
|
|
323
|
-
tagService,
|
|
324
|
-
snapService,
|
|
325
|
-
scope,
|
|
326
|
-
isolator,
|
|
327
|
-
aspectLoader,
|
|
328
|
-
buildTaskSlot,
|
|
329
|
-
tagTaskSlot,
|
|
330
|
-
snapTaskSlot,
|
|
331
|
-
storageResolversSlot
|
|
332
|
-
);
|
|
333
|
-
|
|
334
|
-
graphql.register(builderSchema(builder));
|
|
335
|
-
const func = builder.tagListener.bind(builder);
|
|
336
|
-
if (scope) scope.onTag(func);
|
|
337
|
-
if (workspace && !workspace.consumer.isLegacy) {
|
|
338
|
-
const commands = [new BuilderCmd(builder, workspace, logger), new ArtifactsCmd(builder, scope)];
|
|
339
|
-
cli.unregister('build');
|
|
340
|
-
cli.register(...commands);
|
|
341
|
-
}
|
|
342
|
-
return builder;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
BuilderAspect.addRuntime(BuilderMain);
|
package/builder.service.tsx
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { EnvDefinition, EnvService, ExecutionContext } from '@teambit/envs';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { ScopeMain } from '@teambit/scope';
|
|
4
|
-
import { Text, Newline } from 'ink';
|
|
5
|
-
import { Logger } from '@teambit/logger';
|
|
6
|
-
import { IsolatorMain } from '@teambit/isolator';
|
|
7
|
-
import { Component } from '@teambit/component';
|
|
8
|
-
import { BuildPipe } from './build-pipe';
|
|
9
|
-
import { TaskResultsList } from './task-results-list';
|
|
10
|
-
import { TaskSlot } from './builder.main.runtime';
|
|
11
|
-
import { BuildContext, BuildTaskHelper } from './build-task';
|
|
12
|
-
import { ArtifactFactory } from './artifact';
|
|
13
|
-
import { calculatePipelineOrder } from './build-pipeline-order';
|
|
14
|
-
import { BuilderAspect } from './builder.aspect';
|
|
15
|
-
|
|
16
|
-
export type BuildServiceResults = {
|
|
17
|
-
id: string;
|
|
18
|
-
buildResults: TaskResultsList;
|
|
19
|
-
components: Component[];
|
|
20
|
-
errors?: [];
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type BuilderServiceOptions = { seedersOnly?: boolean; tasks?: string[]; skipTests?: boolean };
|
|
24
|
-
|
|
25
|
-
export type EnvsBuildContext = { [envId: string]: BuildContext };
|
|
26
|
-
|
|
27
|
-
const pipeNames = {
|
|
28
|
-
getBuildPipe: 'build',
|
|
29
|
-
getTagPipe: 'tag',
|
|
30
|
-
getSnapPipe: 'snap',
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
type PipeName = 'build' | 'tag' | 'snap';
|
|
34
|
-
|
|
35
|
-
export type BuilderDescriptor = Array<{ pipeName: PipeName; tasks: string[] }>;
|
|
36
|
-
|
|
37
|
-
type PipeFunctionNames = keyof typeof pipeNames;
|
|
38
|
-
export class BuilderService implements EnvService<BuildServiceResults, BuilderDescriptor> {
|
|
39
|
-
name = 'builder';
|
|
40
|
-
|
|
41
|
-
constructor(
|
|
42
|
-
/**
|
|
43
|
-
* isolator extension.
|
|
44
|
-
*/
|
|
45
|
-
private isolator: IsolatorMain,
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* logger extension.
|
|
49
|
-
*/
|
|
50
|
-
private logger: Logger,
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* task slot (e.g tasks registered by other extensions.).
|
|
54
|
-
*/
|
|
55
|
-
private taskSlot: TaskSlot,
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* a method with such name should be implemented on the env in order to run the pipe tasks.
|
|
59
|
-
*/
|
|
60
|
-
private pipeNameOnEnv: PipeFunctionNames,
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* pipe name to display on the console during the execution
|
|
64
|
-
*/
|
|
65
|
-
private displayPipeName: string,
|
|
66
|
-
private artifactFactory: ArtifactFactory,
|
|
67
|
-
private scope: ScopeMain
|
|
68
|
-
) {}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* runs all tasks for all envs
|
|
72
|
-
*/
|
|
73
|
-
async runOnce(envsExecutionContext: ExecutionContext[], options: BuilderServiceOptions): Promise<TaskResultsList> {
|
|
74
|
-
const envs = envsExecutionContext.map((executionContext) => executionContext.envDefinition);
|
|
75
|
-
const tasksQueue = calculatePipelineOrder(
|
|
76
|
-
this.taskSlot,
|
|
77
|
-
envs,
|
|
78
|
-
this.pipeNameOnEnv,
|
|
79
|
-
options.tasks,
|
|
80
|
-
options.skipTests
|
|
81
|
-
);
|
|
82
|
-
tasksQueue.validate();
|
|
83
|
-
this.logger.info(`going to run tasks in the following order:\n${tasksQueue.toString()}`);
|
|
84
|
-
const title = `running ${this.displayPipeName} pipe for ${envs.length} environments, total ${tasksQueue.length} tasks`;
|
|
85
|
-
const longProcessLogger = this.logger.createLongProcessLogger(title);
|
|
86
|
-
this.logger.consoleTitle(title);
|
|
87
|
-
const envsBuildContext: EnvsBuildContext = {};
|
|
88
|
-
await Promise.all(
|
|
89
|
-
envsExecutionContext.map(async (executionContext) => {
|
|
90
|
-
const componentIds = executionContext.components.map((component) => component.id);
|
|
91
|
-
const capsuleNetwork = await this.isolator.isolateComponents(componentIds, {
|
|
92
|
-
getExistingAsIs: true,
|
|
93
|
-
seedersOnly: options.seedersOnly,
|
|
94
|
-
});
|
|
95
|
-
this.logger.console(
|
|
96
|
-
`generated graph for env "${executionContext.id}", seeders total: ${capsuleNetwork.seedersCapsules.length}, graph total: ${capsuleNetwork.graphCapsules.length}`
|
|
97
|
-
);
|
|
98
|
-
const buildContext = Object.assign(executionContext, {
|
|
99
|
-
capsuleNetwork,
|
|
100
|
-
previousTasksResults: [],
|
|
101
|
-
});
|
|
102
|
-
envsBuildContext[executionContext.id] = buildContext;
|
|
103
|
-
})
|
|
104
|
-
);
|
|
105
|
-
const buildPipe = BuildPipe.from(tasksQueue, envsBuildContext, this.logger, this.artifactFactory);
|
|
106
|
-
const buildResults = await buildPipe.execute();
|
|
107
|
-
longProcessLogger.end();
|
|
108
|
-
buildResults.hasErrors() ? this.logger.consoleFailure() : this.logger.consoleSuccess();
|
|
109
|
-
|
|
110
|
-
return buildResults;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
render(env: EnvDefinition) {
|
|
114
|
-
const pipes = this.getDescriptor(env);
|
|
115
|
-
|
|
116
|
-
return (
|
|
117
|
-
<Text key={BuilderAspect.id}>{pipes.map(({ pipeName, tasks }) => this.renderOnePipe(pipeName, tasks))}</Text>
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
private renderOnePipe(pipeName, tasks) {
|
|
122
|
-
if (!tasks || !tasks.length) return null;
|
|
123
|
-
return (
|
|
124
|
-
<Text key={pipeName}>
|
|
125
|
-
<Text underline color="green">
|
|
126
|
-
{pipeName} pipe
|
|
127
|
-
</Text>
|
|
128
|
-
<Newline />
|
|
129
|
-
<Text color="cyan">total {tasks.length} tasks are configured to be executed in the following order</Text>
|
|
130
|
-
<Newline />
|
|
131
|
-
{tasks.map((task, index) => (
|
|
132
|
-
<Text key={index}>
|
|
133
|
-
<Text>
|
|
134
|
-
{index + 1}. {task}
|
|
135
|
-
</Text>
|
|
136
|
-
<Newline />
|
|
137
|
-
</Text>
|
|
138
|
-
))}
|
|
139
|
-
<Newline />
|
|
140
|
-
</Text>
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
getDescriptor(env: EnvDefinition) {
|
|
145
|
-
// @ts-ignore
|
|
146
|
-
const tasks = Object.keys(pipeNames).map((pipeFuncName: PipeFunctionNames) => {
|
|
147
|
-
const tasksQueue = this.getTasksNamesByPipeFunc(env, pipeFuncName);
|
|
148
|
-
return { pipeName: pipeNames[pipeFuncName], tasks: tasksQueue };
|
|
149
|
-
});
|
|
150
|
-
return tasks as BuilderDescriptor;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private getTasksNamesByPipeFunc(env: EnvDefinition, pipeFuncName: PipeFunctionNames): string[] {
|
|
154
|
-
const tasksQueue = calculatePipelineOrder(this.taskSlot, [env], pipeFuncName).map(({ task }) =>
|
|
155
|
-
BuildTaskHelper.serializeId(task)
|
|
156
|
-
);
|
|
157
|
-
return tasksQueue;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
getCurrentPipeTasks(env: EnvDefinition) {
|
|
161
|
-
return this.getTasksNamesByPipeFunc(env, this.pipeNameOnEnv);
|
|
162
|
-
}
|
|
163
|
-
}
|
package/exceptions/index.ts
DELETED
package/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { BuildPipe } from './build-pipe';
|
|
2
|
-
export { ComponentResult, TaskMetadata } from './types';
|
|
3
|
-
export { BuildContext, BuildTask, BuiltTaskResult, TaskLocation, BuildTaskHelper } from './build-task';
|
|
4
|
-
export type { BuilderMain, BuilderData } from './builder.main.runtime';
|
|
5
|
-
export type { PipelineReport } from './build-pipeline-result-list';
|
|
6
|
-
export { BuilderAspect } from './builder.aspect';
|
|
7
|
-
export { StorageResolver } from './storage';
|
|
8
|
-
export { Artifact, ArtifactList, ArtifactFactory, ArtifactDefinition } from './artifact';
|
|
9
|
-
export { TaskResultsList } from './task-results-list';
|
|
Binary file
|
package/pipeline/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { PipelineResults } from './pipeline-results';
|