An open API service indexing awesome lists of open source software.

https://github.com/common-workflow-lab/cwl-ts-auto

Autogenerated TypeScript bindings for CWL
https://github.com/common-workflow-lab/cwl-ts-auto

Last synced: 4 months ago
JSON representation

Autogenerated TypeScript bindings for CWL

Awesome Lists containing this project

README

          

# cwl-ts-auto
![Actions CI](https://github.com/common-workflow-lab/cwl-ts-auto/actions/workflows/workflow.yml/badge.svg)
[![npm version](https://badge.fury.io/js/cwl-ts-auto.svg)](https://badge.fury.io/js/cwl-ts-auto)

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

## Installation & Usage
To install the latest version of cwl-ts-auto execute:

`npm install cwl-ts-auto`

### Loading Documents
Documents can be loaded by specyfying a file path or by string
```TypeScript
import * as cwlTsAuto from 'cwl-ts-auto'
import fs from 'fs'
import url from 'url'

// Load document by file
cwlTsAuto.loadDocument('./test.cwl')
.then((file) => {
if (file instanceof cwlTsAuto.CommandLineTool) {
console.log('This document is a CommandLineTool with baseCommand: ', file.baseCommand)
}
})
.catch((e) => {
if(e instanceof cwlTsAuto.ValidationException) {
console.log(e.toString())
} else {
console.log(e)
}
})

// Load document by string
let docAsString = fs.readFileSync('./test.cwl').toString()
cwlTsAuto.loadDocumentByString(docAsString, url.pathToFileURL('/your/base/uri/').toString())
.then((file) => {
if (file instanceof cwlTsAuto.CommandLineTool) {
console.log('This document is a CommandLineTool with baseCommand: ', file.baseCommand)
}
})
.catch((e) => {
if(e instanceof cwlTsAuto.ValidationException) {
console.log(e.toString())
} else {
console.log(e)
}
})

// Load document by URL
cwlTsAuto.loadDocument('https://raw.githubusercontent.com/common-workflow-lab/cwl-ts-auto/main/src/test/data/examples/valid-cat-tool.cwl')
.then((file) => {
if (file instanceof cwlTsAuto.CommandLineTool) {
console.log('This document is a CommandLineTool with baseCommand: ', file.baseCommand)
}
})
.catch((e) => {
if(e instanceof cwlTsAuto.ValidationException) {
console.log(e.toString())
} else {
console.log(e)
}
})
```

### Creating, editing and saving Documents
This example shows how to create a simple CommandLineTool with one input
```TypeScript
import * as cwlTsAuto from 'cwl-ts-auto'

let exampleCommandLineTool =
new cwlTsAuto.CommandLineTool({
class_: cwlTsAuto.CommandLineTool_class.COMMANDLINETOOL,
inputs: [],
outputs: []
})
exampleCommandLineTool.baseCommand = 'echo'

let exampleInput =
new cwlTsAuto.CommandInputParameter({
type: cwlTsAuto.PrimitiveType.STRING
})
exampleInput.default_ = 'Hello World!'
exampleCommandLineTool.inputs.push(exampleInput)

console.log(JSON.stringify(exampleCommandLineTool.save()))
```

## Documentation
The complete documentation, autogenerated by [TypeDoc](https://typedoc.org/) can be found under the following link:
https://common-workflow-lab.github.io/cwl-ts-auto/

## Limitations
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/)

## Running and debugging tests
To run tests, install npm and run `npm test`, which launches mocha as defined
in `package.json`. Additional options to mocha can be passed afer `--`. To run
a single test run `run npm test -- --grep $my_test_id`. It is occasionally
helpful to pass `--allow-uncaught` to mocha to get a better handle on failing
test assertions. To debug a test using the chrome inspector insert a
breakpoint anywhere in code called by the test. Breakpoints are using the
`debugger;` instruction. Open chrome and navigate to `chrome://inspect`, then
run `npm test -- --grep valid_cond_wf_003_1_nojs --inspect --debug-brk`, switch
back to chrome and click inspect.