cwl-ts-auto
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

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

Package Sidebar

Install

npm i cwl-ts-auto

Weekly Downloads

9

Version

0.1.3

License

Apache License, Version 2.0

Unpacked Size

1.7 MB

Total Files

603

Last publish

Collaborators

  • zimmera