Skip to content

Commit 1850dab

Browse files
committed
Add documentation about Build Extensibility
1 parent 2d4d20c commit 1850dab

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ resources:
212212
configuration:
213213
paths:
214214
"src": "source"
215+
builder:
216+
customTasks:
217+
- name: custom-task-name-1
218+
beforeTask: standard-task-name
219+
configuration:
220+
configuration-key: value
221+
- name: custom-task-name-2
222+
afterTask: custom-task-name-1
223+
configuration:
224+
color: blue
215225
server:
216226
settings:
217227
port: 8099
@@ -234,6 +244,12 @@ Some general information
234244
+ For type `library` there can be a setting for mapping the virtual paths `src` and `test` to physical paths within the project
235245
- `shims`: Can be used to define, extend or override UI5 configs of dependencies. Inner structure equals the general structure. It is a key-value map where the key equals the project ID as supplied by the translator.
236246

247+
##### builder (optional)
248+
- `customTasks` (optional, list): in this block you can define additional custom build tasks. Please see [here](docs/BuildExtensibility.md) for a detailed explanation and examples of the build extensibility. Each entry in the `customTasks` list consists of the following options:
249+
- `name` (mandatory): the name of the custom task
250+
- `afterTask` or `beforeTask` (only one, mandatory): the name of the build task after or before which your custom task will be executed.
251+
- `configuration` (optional): additional configuration that will be passed to the custom build task
252+
237253
##### server (optional)
238254
- `settings` (not yet implemented)
239255
- `port`: Project default server port. Can be overwritten via CLI parameters.

docs/BuildExtensibility.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-tooling/master/docs/images/UI5_logo_wide.png)
2+
3+
# UI5 Build Extensibility
4+
5+
The UI5 Build Extensibility enables a developer to enhance the build process of any UI5 project. In addition to the [standard task list](https://github.com/SAP/ui5-builder/blob/master/README.md#tasks), custom tasks can be created.
6+
7+
## Configuration of the Custom Build Process
8+
9+
You can configure your build process with additional build task. The custom tasks can be defined in the project [configuration](https://github.com/SAP/ui5-project/blob/master/README.md#configuration) within the `ui5.yaml` file.
10+
11+
In the below example, when building the library `my.library` the `babel` task will be executed before the standard task `generateComponentPreload`. Another custom task called `generateMarkdownFiles` is then executed immediatly after the standard task `uglify`.
12+
13+
### Example: Configuration of project 'my.library'
14+
15+
````yaml
16+
---
17+
# In this example configuration two custom tasks are defined: 'babel' and 'generateMarkdownFiles'.
18+
specVersion: "0.1"
19+
type: library
20+
metadata:
21+
name: my.library
22+
builder:
23+
customTasks:
24+
- name: babel
25+
beforeTask: generateComponentPreload
26+
- name: generateMarkdownFiles
27+
afterTask: uglify
28+
configuration:
29+
color: blue
30+
````
31+
32+
### Example: Connect multiple custom tasks
33+
34+
You can also connect multiple custom task with each other. Please be aware that the order of your definitions is important. You have to make sure that the task is defined before you reference it as `beforeTask` or `afterTask`.
35+
36+
````yaml
37+
---
38+
# In this example 'myCustomTask2' gets executed after 'myCustomTask1'.
39+
specVersion: "0.1"
40+
type: library
41+
metadata:
42+
name: my.library
43+
builder:
44+
customTasks:
45+
- name: myCustomTask1
46+
beforeTask: generateComponentPreload
47+
- name: myCustomTask2
48+
afterTask: myCustomTask1
49+
````
50+
51+
## Custom Task Extension
52+
53+
A custom task extension consists of a `ui5.yaml` and a [task implementation](#task-implementation). It can be a standalone module or part of an existing UI5 project.
54+
55+
### Example: ui5.yaml
56+
57+
````yaml
58+
---
59+
specVersion: "0.1"
60+
kind: extension
61+
type: task
62+
metadata:
63+
name: generateMarkdownFiles
64+
task:
65+
path: lib/tasks/generateMarkdownFiles.js
66+
````
67+
68+
Task extensions can be **standalone modules** which are handled as dependencies.
69+
70+
On the other hand you can implement a task extension as **part of your UI5 project**. In that case, the configuration of the extension is part of your project configuration inside the `ui5.yaml` as shown below.
71+
72+
The task extension will then be automatically collected and processed during the processing of the project.
73+
74+
### Example: Custom Task Extension defined in UI5 project
75+
76+
````yaml
77+
# ui5.yaml configuration for the above example
78+
79+
specVersion: "0.1"
80+
kind: project
81+
type: library
82+
metadata:
83+
name: my.library
84+
builder:
85+
customTasks:
86+
- name: generateMarkdownFiles
87+
afterTask: uglify
88+
configuration:
89+
color: blue
90+
---
91+
# Task extension as part of your project
92+
specVersion: "0.1"
93+
kind: extension
94+
type: task
95+
metadata:
96+
name: generateMarkdownFiles
97+
task:
98+
path: lib/tasks/generateMarkdownFiles.js
99+
````
100+
101+
## Task Implementation
102+
103+
A custom task implementation needs to return a function with the following signature:
104+
105+
````javascript
106+
/**
107+
* Custom task example
108+
*
109+
* @param {Object} parameters Parameters
110+
* @param {DuplexCollection} parameters.workspace DuplexCollection to read and write files
111+
* @param {AbstractReader} parameters.dependencies Reader or Collection to read dependency files
112+
* @param {Object} parameters.options Options
113+
* @param {string} parameters.options.projectName Project name
114+
* @param {string} [parameters.options.configuration] Task configuration if given in ui5.yaml
115+
* @returns {Promise<undefined>} Promise resolving with undefined once data has been written
116+
*/
117+
module.exports = function({workspace, options}) {
118+
// [...]
119+
};
120+
````
121+
122+
The following code snippets shows an example how a task implementation could look like:
123+
124+
### Example: lib/tasks/generateMarkdownFiles.js
125+
126+
````javascript
127+
// Task implementation
128+
const markdownGenerator = require("./markdownGenerator");
129+
130+
module.exports = function({workspace, options}) {
131+
return workspace.byGlob("**/*.txt")
132+
.then((textResources) => {
133+
return markdownGenerator({
134+
resources: textResources
135+
});
136+
})
137+
.then((markdownResources) => {
138+
return Promise.all(markdownResources.map((resource) => {
139+
return workspace.write(resource);
140+
}));
141+
});
142+
};
143+
````

0 commit comments

Comments
 (0)