Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Itay/update getting started #252

Draft
wants to merge 184 commits into
base: harmony
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
184 commits
Select commit Hold shift + click to select a range
46b75ec
add files and directories
giteden Jul 16, 2021
77cbf92
create new sidebar
giteden Jul 17, 2021
1284d0b
add content. add zoom to Image component.
giteden Jul 18, 2021
3bcb14f
add content
giteden Jul 19, 2021
d7465cd
add content
giteden Jul 20, 2021
1ca4294
add content.
giteden Jul 20, 2021
7b1f34c
add content
giteden Jul 20, 2021
efb3a7a
add content
giteden Jul 25, 2021
0223a52
add content.
giteden Jul 25, 2021
5534a26
add content.
giteden Jul 26, 2021
e297322
changes
ranm8 Jul 29, 2021
1c63fdb
Merge branch 'new-home-bit' of github.com:teambit/docs into new-home-bit
ranm8 Jul 30, 2021
ced0dea
pair programming with Ran
debs-obrien Jul 30, 2021
c55dd5b
more changes
ranm8 Aug 1, 2021
088bd49
minor improvements
debs-obrien Aug 1, 2021
ec26b33
for itay
ranm8 Aug 2, 2021
b1741ab
Merge branch 'many-changes' of github.com:teambit/docs into many-changes
ranm8 Aug 2, 2021
d64ad7c
mfes
itaymendel Aug 2, 2021
285bc38
changes
ranm8 Aug 2, 2021
492cd75
image
ranm8 Aug 2, 2021
464c4fb
quick start improvements
debs-obrien Aug 3, 2021
9b67c9f
skeleton done
itaymendel Aug 3, 2021
626f2e8
Merge branch 'many-changes' of github.com:teambit/docs into many-changes
itaymendel Aug 3, 2021
787c0f0
add install bit and create workspace
debs-obrien Aug 4, 2021
8bf0d24
adding in-practice
itaymendel Aug 4, 2021
e34c039
Merge branch 'many-changes' of github.com:teambit/docs into many-changes
itaymendel Aug 4, 2021
11757bf
changes
ranm8 Aug 4, 2021
97e1a2c
changes
ranm8 Aug 4, 2021
f555417
fixed
ranm8 Aug 4, 2021
2ea6052
minor additon to create components
debs-obrien Aug 4, 2021
71f0e6c
add tester overview and ws testing
giteden Aug 4, 2021
c27b973
Merge branch 'many-changes' of github.com:teambit/docs into many-changes
giteden Aug 4, 2021
d6fc757
Merge branch 'many-changes' of https://github.com/teambit/docs into m…
debs-obrien Aug 5, 2021
eff8051
Update create-components.mdx
debs-obrien Aug 5, 2021
b25b9b1
add linter overview and other fixes
giteden Aug 5, 2021
577697e
build time composition
itaymendel Aug 5, 2021
a338786
fix bash comments
itaymendel Aug 5, 2021
ac9997d
update getting started
debs-obrien Aug 6, 2021
faab040
getting started improvements
debs-obrien Aug 6, 2021
ed2fd91
update dependencies
debs-obrien Aug 6, 2021
dead0b8
improvements
debs-obrien Aug 6, 2021
bc05805
improvements
debs-obrien Aug 7, 2021
65cafd1
minor improvements
debs-obrien Aug 7, 2021
480d4e2
fix styling message
debs-obrien Aug 7, 2021
1cc73b5
add note on install to other app
debs-obrien Aug 7, 2021
361b77c
intro refactored, started runtime
itaymendel Aug 7, 2021
a119006
minor fixes
debs-obrien Aug 7, 2021
00cc303
add formatting overview
giteden Aug 7, 2021
e50e7e2
Merge branch 'many-changes' of github.com:teambit/docs into many-changes
giteden Aug 7, 2021
9c2e10f
update workspace/overview
giteden Aug 7, 2021
4b756d2
restore former ws/overview
giteden Aug 8, 2021
1bdb157
benefits... done?
itaymendel Aug 8, 2021
e528216
fix title
itaymendel Aug 8, 2021
908aef3
massive updates
itaymendel Aug 8, 2021
937dfef
ci/cd copied over plus minor additions
debs-obrien Aug 9, 2021
e0dd0f5
minor improvements
debs-obrien Aug 9, 2021
654f6f4
multi-frameworks
itaymendel Aug 9, 2021
31548d3
minor improvements
debs-obrien Aug 9, 2021
4b43994
Merge branch 'many-changes' of https://github.com/teambit/docs into m…
debs-obrien Aug 9, 2021
e3e9494
data fetching
itaymendel Aug 9, 2021
31b675c
styling
itaymendel Aug 9, 2021
91d5384
fix indentation
itaymendel Aug 9, 2021
2cc732c
Angularify the docs
debs-obrien Aug 9, 2021
c3ab2cc
npmrc
itaymendel Aug 9, 2021
fce31f0
updates
itaymendel Aug 9, 2021
dd0661a
fixes and improfements
debs-obrien Aug 9, 2021
903a1e3
minor fixes
debs-obrien Aug 9, 2021
75be4fb
small changes
giteden Aug 9, 2021
c2bfe32
minor fixes
debs-obrien Aug 10, 2021
6a43835
ready to demo mfe
itaymendel Aug 10, 2021
1490157
missing pics
itaymendel Aug 10, 2021
5bc038e
add overview section to get started
debs-obrien Aug 10, 2021
3f64e91
add content
giteden Aug 10, 2021
ea1fdc0
remove overview
debs-obrien Aug 11, 2021
001efeb
Update build-pipelines.md
giteden Aug 12, 2021
ba25cb6
fixes
ranm8 Aug 12, 2021
c761db5
Merge branch 'many-changes' of github.com:teambit/docs into many-changes
ranm8 Aug 12, 2021
5d2584c
Update sidebars.js
debs-obrien Aug 12, 2021
c45406b
slight changes
ranm8 Aug 12, 2021
885bb30
Merge branch 'many-changes' of github.com:teambit/docs into many-changes
ranm8 Aug 12, 2021
e5c05f5
getting started collapsed
debs-obrien Aug 12, 2021
d3ff59a
Merge branch 'many-changes' of github.com:teambit/docs into many-changes
ranm8 Aug 12, 2021
29c2fcd
Update sidebars.js
debs-obrien Aug 12, 2021
c58b988
Merge branch 'many-changes' of github.com:teambit/docs into many-changes
ranm8 Aug 12, 2021
7533b41
add collapsed to compose components section
debs-obrien Aug 12, 2021
db684c0
globally change collapsable
debs-obrien Aug 12, 2021
ba7e7e0
set collapsable to false
debs-obrien Aug 12, 2021
b77a8ec
remove all collapsed from sidebar
debs-obrien Aug 12, 2021
bed1ec5
more collapses
debs-obrien Aug 12, 2021
c5d5205
Merge branch 'many-changes' of github.com:teambit/docs into many-changes
ranm8 Aug 12, 2021
bb3d0d6
part done
ranm8 Aug 12, 2021
8396d20
getting started and deep dive not collapsible
debs-obrien Aug 12, 2021
d392653
progress
ranm8 Aug 13, 2021
b6544d2
improvements
ranm8 Aug 15, 2021
684521d
monorepo section
ranm8 Aug 15, 2021
f0f58c2
few more changes
ranm8 Aug 15, 2021
e9c74fd
changes
ranm8 Aug 16, 2021
a1e4167
monorepo section
ranm8 Aug 16, 2021
29f27be
improvements in monorepos and structure
ranm8 Aug 16, 2021
8fd67d9
commit all
ranm8 Aug 22, 2021
d1a241c
committing all changes
ranm8 Aug 23, 2021
05b6648
fix broken links and typos. add content.
giteden Aug 24, 2021
3f65d07
some changes
giteden Aug 24, 2021
e71fa33
content
ranm8 Aug 25, 2021
a9acb2a
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
ranm8 Aug 25, 2021
8df9ecf
redo component id
giteden Aug 25, 2021
79125e1
Update component-id.md
giteden Aug 25, 2021
197f182
Update component-link.md
giteden Aug 26, 2021
1856075
improve welcome page
debs-obrien Sep 1, 2021
f057663
fix docs menu
debs-obrien Sep 1, 2021
dce965d
quick start links done
debs-obrien Sep 1, 2021
2436f24
create components and more
debs-obrien Sep 1, 2021
f47ff01
using dependencies
debs-obrien Sep 1, 2021
80bb433
dependency overview
debs-obrien Sep 1, 2021
ee17b37
create components
debs-obrien Sep 1, 2021
c2692c7
generator improvements
debs-obrien Sep 1, 2021
3537d27
Update why-bit.md
debs-obrien Sep 2, 2021
66783c3
understanding bit
debs-obrien Sep 2, 2021
0ae53bc
more link fixes and todos added
debs-obrien Sep 2, 2021
077a32f
updtate workspace
debs-obrien Sep 3, 2021
bf208e3
update components
debs-obrien Sep 3, 2021
17f0523
dependencies updated
debs-obrien Sep 3, 2021
3d84c9d
envs updated
debs-obrien Sep 3, 2021
671eea7
fixes
ranm8 Sep 3, 2021
8196d5a
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
ranm8 Sep 3, 2021
4cc8fa7
update scope
debs-obrien Sep 3, 2021
f66341e
CICD updated
debs-obrien Sep 3, 2021
cb9dabc
builder updated
debs-obrien Sep 3, 2021
b0b34b3
apps updated
debs-obrien Sep 3, 2021
8d0b293
docs updated
debs-obrien Sep 3, 2021
ac89526
geneator and compositions updated
debs-obrien Sep 3, 2021
37797f4
tester updated
debs-obrien Sep 3, 2021
fa2737d
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
ranm8 Sep 3, 2021
71f4b13
compiler updated
debs-obrien Sep 3, 2021
44e1f0f
linter updated
debs-obrien Sep 3, 2021
ece1a56
config and formatting updated
debs-obrien Sep 3, 2021
3b82653
build done
debs-obrien Sep 3, 2021
aa79b6b
extending bit and reference updated
debs-obrien Sep 3, 2021
ccda133
final updates
debs-obrien Sep 3, 2021
350db1f
remove archived and fix links
debs-obrien Sep 3, 2021
5037fc4
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
ranm8 Sep 4, 2021
693daf3
component config
ranm8 Sep 5, 2021
6945dc9
changes
ranm8 Sep 5, 2021
8313540
add component id diagram
giteden Sep 5, 2021
406cc37
id and changes
ranm8 Sep 5, 2021
1087eca
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
ranm8 Sep 5, 2021
d926d9c
add comp config snapshot
giteden Sep 5, 2021
d2ef431
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
ranm8 Sep 5, 2021
a7d5359
packages
ranm8 Sep 5, 2021
f225db4
updates
ranm8 Sep 5, 2021
d3ab2ba
with itay
ranm8 Sep 5, 2021
9b30e61
updates
ranm8 Sep 6, 2021
645a26f
changes
ranm8 Sep 6, 2021
da78370
chnages
ranm8 Sep 6, 2021
40ebdc1
small changes
giteden Sep 7, 2021
5ae2907
ci done
itaymendel Sep 8, 2021
dc82cc1
changes to react env
giteden Sep 8, 2021
365d5e0
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
giteden Sep 8, 2021
f63b073
add package-name.
giteden Sep 8, 2021
378c46b
remove ci from install doc
itaymendel Sep 9, 2021
7ecf4e0
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
itaymendel Sep 9, 2021
6e9c92a
changes
giteden Sep 9, 2021
d4915da
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
giteden Sep 9, 2021
cf1b924
add artifacts example to packing
giteden Sep 11, 2021
acffec7
add implement compiler docs
GiladShoham Sep 12, 2021
507ec56
delete old file
GiladShoham Sep 12, 2021
64c821e
add multi compiler docs
GiladShoham Sep 12, 2021
54acad0
add multi compiler example
GiladShoham Sep 12, 2021
e77963e
small changes
giteden Sep 12, 2021
430c27f
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
giteden Sep 12, 2021
10533f6
added context
ranm8 Sep 13, 2021
56acd5c
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
ranm8 Sep 13, 2021
6ebc40e
update generator and add video
debs-obrien Sep 13, 2021
c610164
add changes to implement a compiler
giteden Sep 13, 2021
02d516c
Merge branch 'new-docs' of github.com:teambit/docs into new-docs
giteden Sep 13, 2021
4457adc
implement tester
GiladShoham Sep 13, 2021
441da42
start implelemt linter
GiladShoham Sep 14, 2021
eb9ddc5
general env is done
itaymendel Sep 15, 2021
f05a88b
for review
itaymendel Sep 15, 2021
4fc0487
fix intro
itaymendel Sep 15, 2021
8357c56
added hidden files
itaymendel Sep 15, 2021
9e41fc5
fix typos
itaymendel Sep 15, 2021
a80fb66
loosing brakets
itaymendel Sep 15, 2021
201e820
edits after conversation
itaymendel Sep 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions docs/apps/___create-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: create-app
title: Create an App
---

...
10 changes: 10 additions & 0 deletions docs/apps/___overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
id: overview
title: Overview
---

...

## What is an app component?

..
6 changes: 6 additions & 0 deletions docs/apps/___recomposing-apps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: recomposing-apps
title: Recomposing Apps
---

..
6 changes: 6 additions & 0 deletions docs/apps/deploy-app/___aws.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: aws
title: AWS
---

...
6 changes: 6 additions & 0 deletions docs/apps/deploy-app/___netlify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: netlify
title: Netlify
---

..
6 changes: 6 additions & 0 deletions docs/apps/deploy-app/___vercel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: vercel
title: Vercel
---

...
2 changes: 1 addition & 1 deletion docs/aspects/builder/builder.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: builder
title: Builder
title: Build Pipelines
slug: /aspects/builder
description: build components on isolated directories
---
Expand Down
Empty file.
9 changes: 4 additions & 5 deletions docs/aspects/dependency-resolver/dependency-resolver.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description: Simplifies the dependency management of components in a Bit workspa

Check out the [Dependency Resolver Aspect](https://bit.dev/teambit/dependencies/dependency-resolver) on Bit.dev


The [Dependency Resolver](https://bit.dev/teambit/dependencies/dependency-resolver) configures and installs dependencies for components in a Bit workspace. It auto-generates the dependency graph for components to spare us the tedious work of manually configuring it ourselves.
It does so by integrating the dependency policies set by various Bit extensions (primarily the workspace) with the components' parsed and analyzed `import`/`require` statements.
In addition to that, the Dependency Resolver offers an efficient API to manually modify the generated graph using policies that can be applied on groups of components.
Expand Down Expand Up @@ -256,9 +255,9 @@ Set the `devFilePatterns` property to add your own list of file extensions to be

#### peer dependencies

Setting a package as a peer dependency ensures the package manager installs only a single version of that package. If that is not possible, i.e. if there is no single agreed upon version for all components in the workspace, then an error will be thrown.
Setting a package as a peer dependency ensures the package manager installs only a single version of that package. If that is not possible, i.e. if there is no single "agreed upon" version for all components in the workspace, then an error will be thrown.

This can be crucial when different components communicate with each other using shared objects that are instantiated by an installed package (the dependency). If different versions of the same package create different object instances then the means of communication is broken. There is no single object to address, no single source of truth. This can turn out to be critical when working with modules that are used as plugins of another module (for example, Babel), or when working with components that are coordinated in runtime using a shared library (for example, React).
This can be crucial when different components communicate with each other using shared objects that are instantiated by an installed package (the dependency). If different versions of the same package create different object instances then the "means of communication" is broken. There is no single object to address, no single source of truth. This can turn out to be critical when working with modules that are used as "plugins" of another module (for example, Babel), or when working with components that are coordinated in runtime using a shared library (for example, React).

To set a package as a peer dependency, place it under the `peerDependencies` entry, like so:

Expand Down Expand Up @@ -349,8 +348,8 @@ Read about setting a proxy in NPM's global configuration [here](https://docs.npm
> If that token cannot be found in the `.npmrc` file, Bit will look for it in your global Bit configurations (use the `bit config` command to output your `user.token` property).
>
> <br />
> If your npm is configured to use a registry other than npmjs's, then the Dependency Resolver will use that configured registry,
> instead.
> If your npm is configured to use a registry other than npmjs's, then the Dependency
> Resolver will use that configured registry, instead.

> The 'install' process includes importing components and linking them to the `node_modules` directory.

Expand Down
1 change: 1 addition & 0 deletions docs/aspects/mdx/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as Mdx } from './mdx.mdx';

6 changes: 6 additions & 0 deletions docs/builder/___build-on-ci.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: build-on-ci
title: Build on CI
---

...
6 changes: 6 additions & 0 deletions docs/builder/___component-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: component-build
title: Component Build
---

...
279 changes: 279 additions & 0 deletions docs/builder/build-pipeline-customization.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
---
id: build-pipeline-customization
title: Build Pipeline Customization
---

The `BuildTask` interface is a good start to understand how to implement a new build-task.
When writing a build task, the `Network` object is passed and it includes the seeders capsules, as well as the entire graph including the dependencies.
Keep in mind that the entire graph may contain components from other envs.

Some tasks, such as, compiling in typescript and bundling with Webpack, need the entire graph.
Others, such as, Babel, need only the seeders. However, normally, the bundling is running after the compilation and it expects to have the dependencies compiled, so you might need the entire graph regardless.

## Adding Tasks to a pipeline

There are two ways of adding tasks to the build pipeline.

1. `getBuildPipe()` method of the env. (or `getTagPipe()` and `getSnapPipe()`)
2. registering to the slot via `builder.registerBuildTask()`. (or `registerTagTask()` and `registerSnapTask()`)

in the option #1, it's possible to determine the order. e.g. `getBuildPipe() { return [taskA, taskB, taskC]; }`
in the option #2, the register happens once the extension is loaded, so there is no way to put
one task before/after another task as of now.

## Sequencing the build tasks

The Build Pipeline takes into consideration the following factors when deciding the order of which to execute each task:

- **Location**: A task can be executed either at the start or end of the build pipeline. This can be explicitly configured by the task itself.
- **Dependencies**: A task can depend on other tasks. That means, the dependencies must be completed successfully for all envs before this task starts. The dependencies are applicable inside a location and not across locations. This is configured by the task itself.
- **An environment's list of build tasks**: This is the array of tasks as it is defined by an environment

## Executing the pipelines

Commands that trigger the build pipeline:

- `bit build` - runs the build pipeline on your local machine, for the entire workspace. The output data will not persist. - That is most often used for testing and debugging the build process.
- `bit tag` - runs the tag pipeline in addition to the build pipeline, before creating a new component release version. The output data will persist.
- `bit snap` - runs the snap pipeline in addition to the build pipeline. The output data will persist.

Build pipelines are determined by the environments in use. That means, in order to override the default pipeline, we need to create a new environment extension or modify an existing one.

The example task below, shown being used by a customized environment, prints out the component name of every component handled by it. In addition to that, the task returns the component name as custom metadata to be logged and/or stored in the component tagged version. [See a demo project here](https://github.com/teambit/harmony-build-examples).

> Information returned by a build task will only persist if the build-pipeline was triggered by the 'hard-tag' command (`bit tag <component-id>`).

```ts title="print-cmp-name-task.ts"
import { BuildTask, BuildContext, BuiltTaskResult, ComponentResult } from '@teambit/builder';

// A task is an implementation of 'BuildTask' provided by the 'builder' aspect
export class PrintCmpNameTask implements BuildTask {
// The constructor leaves these properties up to the hands of the environment using this task
constructor(readonly aspectId: string, readonly name: string) {}

// This is where the task logic is placed. It will be executed by the build pipeline
async execute(context: BuildContext): Promise<BuiltTaskResult> {
const componentsResults: ComponentResult[] = [];

// Go through every isolated component instance
context.capsuleNetwork.seedersCapsules.forEach((capsule) => {
console.log(`The current component name is: ${capsule.component.id.name}`);

componentsResults.push({
component: capsule.component,
metadata: { customProp: capsule.component.id.name },
});
});
return {
// An array of component objects, enriched with additional data produced by the task
componentsResults,
};
}
}
```

```ts title="customized-react.extension.ts"
import { EnvsMain, EnvsAspect } from '@teambit/envs';
import { ReactAspect, ReactMain } from '@teambit/react';

// Import the task
import { PrintCmpNameTask } from './print-cmp-name-task';

export class CustomReact {
constructor(private react: ReactMain) {}

static dependencies: any = [EnvsAspect, ReactAspect];

static async provider([envs, react]: [EnvsMain, ReactMain]) {
// Get the environment's default build pipeline
const reactPipe = react.env.getBuildPipe();

// Add the custom task to the end of the build tasks sequence.
// Provide the task with the component ID of the extension using it.
// Provide the ask with a name.
const tasks = [...reactPipe, new PrintCompTask('extensions/custom-react', 'PrintCmpNameTask')];

// Create a new environment by merging these configurations with the env's default ones
const customReactEnv = react.compose([react.overrideBuildPipe(tasks)]);

// register the extension as an environment
envs.registerEnv(customReactEnv);
return new CustomReact(react);
}
}
```

## Positioning a build task in the pipeline

A build task is positioned in the build pipeline sequence either by overriding the entire _customizable_ pipeline or, by registering it to a location in the pipeline using the designated builder slot.

### Override the build pipeline sequence

This methodology leaves the task completely agnostic as to its position in the build pipeline. Instead, the task position is determined by the environment using the `getBuildPipe` Environment Handler.

The example above shows the React environment `overrideBuildPipe` method being used to override its default pipeline. This method uses the `getBuildPipe()` Environment Handler, internally.

### Append to the start or end of the pipeline, in relation to other tasks

This methodology places the task at the start or end of the build pipeline sequence, and lists all other tasks needed to run successfully before it is executed.

Example:

```ts title="print-cmp-name-task.ts"
import { BuildTask, BuildContext, BuiltTaskResult, ComponentResult } from '@teambit/builder';

export class PrintCmpNameTask implements BuildTask {
constructor(readonly aspectId: string, readonly name: string) {}

// Place the task at the end of the build pipeline
readonly location = 'end';

// Run this task only after the '@teambit/preview' task is completed successfully
readonly dependencies = ['@teambit/preview'];

async execute(context: BuildContext): Promise<BuiltTaskResult> {
const componentsResults: ComponentResult[] = [];
context.capsuleNetwork.seedersCapsules.forEach((capsule) => {
console.log(`The current component name is: ${capsule.component.id.name}`);

componentsResults.push({
component: capsule.component,
metadata: { customProp: capsule.component.id.name },
});
});
return {
componentsResults,
};
}
}
```

```ts title="customized-react.extension.ts"
import { EnvsMain, EnvsAspect } from '@teambit/envs';
import { ReactAspect, ReactMain } from '@teambit/react';
import { BuilderMain } from '@teambit/builder';

// Import the task (in reality, it should be an independent component)
import { PrintCmpNameTask } from './print-cmp-name-task';

export class CustomReact {
constructor(private react: ReactMain) {}

static dependencies: any = [EnvsAspect, ReactAspect];

// Inject the builder
static async provider([envs, react, builder]: [EnvsMain, ReactMain, BuilderMain]) {
// Register this task using the registration slot, made available by the 'builder'.
// Here, the environment has no say in the positioning of the task
builder.registerBuildTasks([new ExampleTask('extensions/custom-react', 'PrintCmpNameTask')]);

const customReactEnv = react.compose([]);

envs.registerEnv(customReactEnv);
return new CustomReact(react);
}
}
```

## A build task anatomy

- **aspectId** <br />
`aspectId: string`<br />
The component ID of the environment using this task.

- **name** <br />
`name: string` <br />
A name for this task. Only alphanumerical characters are allowed. PascalCase should be used as a convention.

- **location** <br />
`location?: 'start' | 'end'` <br />
The section of the build-pipeline to which to append this task.

- **dependencies** <br />
`dependencies?: string[]` <br />
An list of tasks that must be completed before this task gets executed. <br />
For example `dependencies = ['@teambit/preview']`.

- **execute** <br />
`execute(context: BuildContext): Promise<BuiltTaskResult>` <br />
The execute method is where all the task logic is placed.

- **context** (argument) <br />
`context: BuildContext` <br />
The context of the build pipeline. Use this object (provided by the build pipeline) to get information regarding all components handled by the build pipeline. <br /><br />
For example, `context.capsuleNetwork.seedersCapsules` are models representing isolated instances of components handled by the build pipeline. These isolated instances are independent projects, generated in your local filesystem (by the build pipeline).

- **return** <br />
`Promise<BuiltTaskResult>` <br />
A `context` method returns an object with data regarding the build task process, additional data regarding the components handled by the task and, if available, data regarding the different artifacts generated by this task.<br />
The returned object has the following attributes:

- **componentsResults** <br />
`componentsResults: ComponentResult[]`
An array of objects, each containing an instance of an object handled the task and additional information regarding the process and the component itself.
- **component** <br />
`component: Component` <br />
An instance of the component handled by the task (see the above task example).

- **metadata** <br />
`metadata?: { [key: string]: Serializable }` <br />
Component metadata generated during the build task.

- **errors** <br />
`errors?: Array<Error | string>` <br />
Build task errors. A task returning errors will abort the build pipeline and log the returned errors.

- **warnings** <br />
`warnings?: string[]` <br />
warnings generated throughout the build task.

- **startTime** <br />
`startTime?: number` <br />
A timestamp (in milliseconds) of when the task started

- **endTime** <br />
`endTime?: number` <br />
A timestamp (in milliseconds) of when the task ended
- **artifacts** <br />
`artifacts?: ArtifactDefinition[]` <br />
An array of artifact definitions to generate after a successful build
- **name** <br />
`name: string` <br />
The name of the artifact. <br />
For example, a project might utilize two different artifacts for the same typescript compiler, one that generates ES5 files and another for ES6. This prop helps to distinguish between the two.
- **generatedBy** <br />
`generatedBy?: string;` <br />
Id of the component that generated this artifact.

- **description** <br />
`description?: string` <br />
A description of the artifact. <br />

- **globPatterns** <br />
`globPatterns: string[]` <br />
Glob patterns of files to include upon artifact creation. Minimatch is used to match the patterns. <br />
For example, `['*.ts', '!foo.ts']` matches all ts files but ignores `foo.ts`.

- **rootDir** <br />
`rootDir?: string` <br />
Defines the root directory of the artifacts in the capsule file system. The rootDir must be unique for every artifact, otherwise data might be overridden.

- **dirPrefix** <br />
`dirPrefix?: string` <br />
Adds a directory prefix for all artifact files.

- **context** <br />
`context?: 'component' | 'env'` <br />
Determine the context of the artifact. The default artifact context is `component`. `env` is useful when the same file is generated for all components, for example, a "preview" task may create the same webpack file for all components of that env.

- **storageResolver** <br />
`storageResolver?: string` <br />
Used to replace the location of the stored artifacts. The default resolver persists artifacts on scope (that's not recommended for large files).

- **preBuild** (advanced) <br />
`preBuild?(context: BuildContext): Promise<void>` <br />
Runs before the build pipeline has started. This method should only be used when preparations are needed to be done on all environments before the build starts.

- **postBuild** (advanced) <br />
`postBuild?(context: BuildContext, tasksResults: TaskResultsList): Promise<void>` <br />
Runs after the dependencies were completed for all environments.
Loading