|
1 | 1 | # cwl-ts-auto |
| 2 | + |
| 3 | +[](https://badge.fury.io/js/cwl-ts-auto) |
| 4 | + |
2 | 5 | 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 |
3 | 6 |
|
4 | | -## Installation |
| 7 | +## Installation & Usage |
5 | 8 | To install the latest version of cwl-ts-auto execute: |
6 | 9 |
|
7 | 10 | `npm install cwl-ts-auto` |
8 | 11 |
|
| 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 | +``` |
9 | 73 | ## Limitations |
10 | 74 | 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/) |
0 commit comments