Skip to content

Commit 497978a

Browse files
committed
Add documentation about Build Extensibility
1 parent c41620e commit 497978a

File tree

2 files changed

+161
-3
lines changed

2 files changed

+161
-3
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-tooling/master/docs/images/UI5_logo_wide.png)
22

33
# ui5-project
4-
> Modules for building a UI5 projects dependency tree, including configuration
4+
> Modules for building a UI5 projects dependency tree, including configuration
55
> Part of the [UI5 Build and Development Tooling](https://github.com/SAP/ui5-tooling)
66
77
[![Travis CI Build Status](https://travis-ci.org/SAP/ui5-project.svg?branch=master)](https://travis-ci.org/SAP/ui5-project)
@@ -10,7 +10,7 @@
1010
[![Dependency Status](https://david-dm.org/SAP/ui5-project/master.svg)](https://david-dm.org/SAP/ui5-project/master)
1111
[![devDependency Status](https://david-dm.org/SAP/ui5-project/master/dev-status.svg)](https://david-dm.org/SAP/ui5-project/master#info=devDependencies)
1212

13-
**This is an alpha release!**
13+
**This is an alpha release!**
1414
**The UI5 Build and Development Tooling described here is not intended for productive use yet. Breaking changes are to be expected.**
1515

1616
## Normalizer
@@ -65,7 +65,7 @@ The npm translator is currently the default translator and looks for dependencie
6565

6666
Can be used to supply the full dependency information of a project in a single structured file.
6767

68-
Usage example: `ui5 serve -b static:/path/to/projectDependencies.yaml`
68+
Usage example: `ui5 serve -b static:/path/to/projectDependencies.yaml`
6969
`projectDependencies.yaml` contains something like:
7070
````yaml
7171
---
@@ -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+
color: blue
221+
- name: <custom-task-name-2>
222+
afterTask: <custom-task-name-1>
223+
configuration:
224+
color: red
215225
server:
216226
settings:
217227
port: 8099
@@ -234,6 +244,13 @@ 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+
249+
- `customTasks` (optional, list): in this block you can define additional custom build tasks. Please see (here) for a detailed explanation and examples of the build extensibility. Each entry in the `customTasks` list consists of the following options:
250+
- `name` (mandatory): the name of the custom task
251+
- `afterTask` or `beforeTask` (only one, mandatory): the name of the build task after or before which your custom task will be executed.
252+
- `configuration` (optional): additional configuration for your custom build task
253+
237254
##### server (optional)
238255
- `settings` (not yet implemented)
239256
- `port`: Project default server port. Can be overwritten via CLI parameters.

docs/BuildExtensibility.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 Tooling enables it to define a custom build for your UI5 project by adding additional tasks to the [standard task list](https://github.com/SAP/ui5-builder/blob/master/README.md#tasks).
6+
7+
## Configuration
8+
9+
The additional build tasks can be defined in the project configuration within the `ui5.yaml` file.
10+
11+
### Example: Configuration of project 'my.library'
12+
13+
````yaml
14+
---
15+
# In this example configuration two custom tasks are defined: 'babel' and 'generateMarkdownFiles'.
16+
specVersion: "0.1"
17+
type: library
18+
metadata:
19+
name: my.library
20+
builder:
21+
customTasks:
22+
- name: babel
23+
beforeTask: generateComponentPreload
24+
- name: generateMarkdownFiles
25+
afterTask: uglify
26+
configuration:
27+
color: blue
28+
````
29+
30+
In the above 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 `ugilfy`.
31+
32+
### Example: Connect multiple custom tasks
33+
34+
You can also connect multiple custom task with eachother. If you do, please be aware that the order of your definitions is important. You have to make sure that the task is defined before you set 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.
54+
55+
### 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+
### lib/tasks/generateMarkdownFiles.js
69+
70+
````javascript
71+
// Task implementation
72+
const markdownGenerator = require("./markdownGenerator");
73+
74+
module.exports = function({workspace, options}) {
75+
return workspace.byGlob("**/*.txt")
76+
.then((textResources) => {
77+
return markdownGenerator({
78+
resources: textResources
79+
});
80+
})
81+
.then((markdownResources) => {
82+
return Promise.all(markdownResources.map((resource) => {
83+
return workspace.write(resource);
84+
}));
85+
});
86+
};
87+
````
88+
89+
Task extensions can be **standalone modules** which are then handled as dependencies.
90+
91+
On the other hand you can implement a task extension as **part of your project** itself. In that case, the configuration of the extension is part of your project configuration inside the `ui5.yaml` as shown below.
92+
93+
The task extension will then be automatically collected and processed during the processing of the project.
94+
95+
### Example
96+
97+
````yaml
98+
# ui5.yaml configuration for the above example
99+
100+
specVersion: "0.1"
101+
kind: project
102+
type: library
103+
metadata:
104+
name: my.library
105+
builder:
106+
customTasks:
107+
- name: generateMarkdownFiles
108+
afterTask: uglify
109+
configuration:
110+
color: blue
111+
---
112+
# Task extension as part of your project
113+
specVersion: "0.1"
114+
kind: extension
115+
type: task
116+
metadata:
117+
name: generateMarkdownFiles
118+
task:
119+
path: lib/tasks/generateMarkdownFiles.js
120+
````
121+
122+
## Task Implementation
123+
124+
A custom task implementation needs to return a function with the following signature:
125+
126+
````javascript
127+
/**
128+
* Custom task example
129+
*
130+
* @param {Object} parameters Parameters
131+
* @param {DuplexCollection} parameters.workspace DuplexCollection to read and write files
132+
* @param {AbstractReader} parameters.dependencies Reader or Collection to read dependency files
133+
* @param {Object} parameters.options Options
134+
* @param {string} parameters.options.projectName Project name
135+
* @param {string} [parameters.options.configuration] Task configuration if given in ui5.yaml
136+
* @returns {Promise<undefined>} Promise resolving with undefined once data has been written
137+
*/
138+
module.exports = function({workspace, options}) {
139+
// [...]
140+
};
141+
````

0 commit comments

Comments
 (0)