Skip to content

Commit d707499

Browse files
authored
Include readme examples (#8)
* Export ValidationException * Add Examples to README.md
1 parent 142cd1d commit d707499

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,74 @@
11
# cwl-ts-auto
2+
![Actions CI](https://github.com/common-workflow-lab/cwl-ts-auto/actions/workflows/workflow.yml/badge.svg)
3+
[![npm version](https://badge.fury.io/js/cwl-ts-auto.svg)](https://badge.fury.io/js/cwl-ts-auto)
4+
25
This project contains TypeScript objects and utilities auto-generated by https://github.com/common-workflow-language/schema_salad for parsing documents corresponding to the https://w3id.org/cwl/cwl schema
36

4-
## Installation
7+
## Installation & Usage
58
To install the latest version of cwl-ts-auto execute:
69

710
`npm install cwl-ts-auto`
811

12+
### Loading Documents
13+
Documents can be loaded by specyfying a file path or by string
14+
```TypeScript
15+
import * as cwltsauto from 'cwl-ts-auto'
16+
import fs from 'fs'
17+
import url from 'url'
18+
19+
// Load document by file
20+
cwltsauto.loadDocument('./test.cwl')
21+
.then((file) => {
22+
if (file instanceof cwltsauto.CommandLineTool) {
23+
console.log('This document is a CommandLineTool with baseCommand: ', file.baseCommand)
24+
}
25+
})
26+
.catch((e) => {
27+
if(e instanceof cwltsauto.ValidationException) {
28+
console.log(e.toString())
29+
} else {
30+
console.log(e)
31+
}
32+
})
33+
34+
// Load document by string
35+
let docAsString = fs.readFileSync('./test.cwl').toString()
36+
cwltsauto.loadDocumentByString(docAsString, url.pathToFileURL('/your/base/uri/').toString())
37+
.then((file) => {
38+
if (file instanceof cwltsauto.CommandLineTool) {
39+
console.log('This document is a CommandLineTool with baseCommand: ', file.baseCommand)
40+
}
41+
})
42+
.catch((e) => {
43+
if(e instanceof cwltsauto.ValidationException) {
44+
console.log(e.toString())
45+
} else {
46+
console.log(e)
47+
}
48+
})
49+
```
50+
51+
### Creating, editing and saving Documents
52+
This example shows how to create a simple CommandLineTool with one input
53+
```TypeScript
54+
import * as cwltsauto from 'cwl-ts-auto'
55+
56+
let exampleCommandLineTool =
57+
new cwltsauto.CommandLineTool({
58+
class_: cwltsauto.CommandLineTool_class.COMMANDLINETOOL,
59+
inputs: [],
60+
outputs: []
61+
})
62+
exampleCommandLineTool.baseCommand = 'echo'
63+
64+
let exampleInput =
65+
new cwltsauto.CommandInputParameter({
66+
type: cwltsauto.PrimitiveType.STRING
67+
})
68+
exampleInput.default_ = 'Hello World!'
69+
exampleCommandLineTool.inputs.push(exampleInput)
70+
71+
console.log(JSON.stringify(exampleCommandLineTool.save()))
72+
```
973
## Limitations
1074
cwl-ts-auto only supports the CWL v1.2 syntax. Other documents have to be upgraded using the [cwl-upgrader](https://pypi.org/project/cwl-upgrader/)

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export {
22
loadDocument,
33
loadDocumentByString,
4+
ValidationException,
45
ToolTimeLimit_class,
56
WorkReuse_class,
67
NetworkAccessProperties,

0 commit comments

Comments
 (0)