Skip to content

common-workflow-lab/cwl-ts-auto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cwl-ts-auto

Actions CI npm version

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

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

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 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

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.