Skip to content

Commit 543e702

Browse files
committed
added Documentation and example regarding dependency tree modelling were added in multiple places
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent adff4f5 commit 543e702

File tree

6 files changed

+55
-26
lines changed

6 files changed

+55
-26
lines changed

HISTORY.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.
88
* Removed synthetic default imports. (via [#243])
99
The resulting _JavaScript_ did not change in functionality, but in size.
1010
Downstream users of the _TypeScript_ sources might consider this a bugfix, others a feature, others a style-change.
11+
* Added
12+
* Documentation and example regarding dependency tree modelling were added in multiple places. (via [#])
1113
* Build
1214
* No longer enable _TypeScript_ config `esModuleInterop` & `allowSyntheticDefaultImports`,
1315
which causes smaller build results and less unnecessary generated code.

README.md

+19-11
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,16 @@ See extended [examples].
100100
const cdx = require('@cyclonedx/cyclonedx-library')
101101

102102
const bom = new cdx.Models.Bom()
103-
bom.components.add(
104-
new cdx.Models.Component(
105-
cdx.Enums.ComponentType.Library,
106-
'myComponent'
107-
)
103+
bom.metadata.component = new cdx.Models.Component(
104+
cdx.Enums.ComponentType.Application,
105+
'MyProject'
108106
)
107+
const componentA = new cdx.Models.Component(
108+
cdx.Enums.ComponentType.Library,
109+
'myComponentA',
110+
)
111+
bom.components.add(componentA)
112+
bom.metadata.component.dependencies.add(componentA.bomRef)
109113
```
110114

111115
### In _WebBrowsers_
@@ -118,12 +122,16 @@ bom.components.add(
118122
const cdx = CycloneDX_library
119123
120124
let bom = new cdx.Models.Bom()
121-
bom.components.add(
122-
new cdx.Models.Component(
123-
cdx.Enums.ComponentType.Library,
124-
'myComponent'
125-
)
125+
bom.metadata.component = new cdx.Models.Component(
126+
cdx.Enums.ComponentType.Application,
127+
'MyProject'
128+
)
129+
const componentA = new cdx.Models.Component(
130+
cdx.Enums.ComponentType.Library,
131+
'myComponentA',
126132
)
133+
bom.components.add(componentA)
134+
bom.metadata.component.dependencies.add(componentA.bomRef)
127135
</script>
128136
```
129137

@@ -141,7 +149,7 @@ See the [LICENSE][license_file] file for the full license.
141149

142150
[license_file]: https://github.com/CycloneDX/cyclonedx-javascript-library/blob/main/LICENSE
143151
[contributing_file]: https://github.com/CycloneDX/cyclonedx-javascript-library/blob/main/CONTRIBUTING.md
144-
[examples]: https://github.com/CycloneDX/cyclonedx-javascript-library/tree/main/examples
152+
[examples]: https://github.com/CycloneDX/cyclonedx-javascript-library/tree/main/examples/README.md
145153

146154
[shield_gh-workflow-test]: https://img.shields.io/github/workflow/status/CycloneDX/cyclonedx-javascript-library/Node%20CI/main?logo=GitHub&logoColor=white "tests"
147155
[shield_npm-version]: https://img.shields.io/npm/v/%40cyclonedx/cyclonedx-library?logo=npm&logoColor=white "npm"

examples/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Examples
22

3+
## Usage
4+
35
* [`example.cjs`](node/example.cjs) showcases the usage in node, commonjs style.
46
* [`example.mjs`](node/example.mjs) showcases the usage in node, module style.
57
* [`web-browser.html`](web-browser.html) showcases the usage in a web-browser.
8+
9+
## Data models
10+
11+
The ["models" test data](../tests/_data/models.js) holds also examples for complete structures
12+
with all possible use cases, all nesting, and advanced complexity.

examples/node/example.cjs

+9-5
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ const cdx = require('@cyclonedx/cyclonedx-library')
2424
// full Library is available as `cdx`, now
2525

2626
const bom = new cdx.Models.Bom()
27-
bom.components.add(
28-
new cdx.Models.Component(
29-
cdx.Enums.ComponentType.Library,
30-
'myComponent'
31-
)
27+
bom.metadata.component = new cdx.Models.Component(
28+
cdx.Enums.ComponentType.Application,
29+
'MyProject'
3230
)
31+
const componentA = new cdx.Models.Component(
32+
cdx.Enums.ComponentType.Library,
33+
'myComponentA',
34+
)
35+
bom.components.add(componentA)
36+
bom.metadata.component.dependencies.add(componentA.bomRef)
3337

3438
const jsonSerializer = new cdx.Serialize.JsonSerializer(
3539
new cdx.Serialize.JSON.Normalize.Factory(

examples/node/example.mjs

+9-5
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ import * as cdx from '@cyclonedx/cyclonedx-library'
2424
// full Library is available as `cdx`, now
2525

2626
const bom = new cdx.Models.Bom()
27-
bom.components.add(
28-
new cdx.Models.Component(
29-
cdx.Enums.ComponentType.Library,
30-
'myComponent'
31-
)
27+
bom.metadata.component = new cdx.Models.Component(
28+
cdx.Enums.ComponentType.Application,
29+
'MyProject'
3230
)
31+
const componentA = new cdx.Models.Component(
32+
cdx.Enums.ComponentType.Library,
33+
'myComponentA',
34+
)
35+
bom.components.add(componentA)
36+
bom.metadata.component.dependencies.add(componentA.bomRef)
3337

3438
const jsonSerializer = new cdx.Serialize.JsonSerializer(
3539
new cdx.Serialize.JSON.Normalize.Factory(

examples/web-browser.html

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@
3232
// full Library is available as `cdx`, now
3333

3434
const bom = new cdx.Models.Bom()
35-
bom.components.add(
36-
new cdx.Models.Component(
37-
cdx.Enums.ComponentType.Library,
38-
'myComponent'
39-
)
35+
bom.metadata.component = new cdx.Models.Component(
36+
cdx.Enums.ComponentType.Application,
37+
'MyProject'
4038
)
39+
const componentA = new cdx.Models.Component(
40+
cdx.Enums.ComponentType.Library,
41+
'myComponentA',
42+
)
43+
bom.components.add(componentA)
44+
bom.metadata.component.dependencies.add(componentA.bomRef)
4145

4246
const jsonSerializer = new cdx.Serialize.JsonSerializer(
4347
new cdx.Serialize.JSON.Normalize.Factory(

0 commit comments

Comments
 (0)