From b00f15ab8ba6bc4ff07db0288a5c43391770daf2 Mon Sep 17 00:00:00 2001 From: Adrian Zimmer Date: Thu, 6 Jan 2022 10:36:13 +0100 Subject: [PATCH] Add load by URL example, package keywords and link to docs in RADME (#14) * Add example for loading documents by URL to README * Add keywords to package * Add link to documentation to README * Increase version number --- README.md | 46 +++++++++++++++++++++++++++++++++------------- package.json | 3 ++- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3629dac..9ab13d3 100644 --- a/README.md +++ b/README.md @@ -12,19 +12,19 @@ To install the latest version of cwl-ts-auto execute: ### Loading Documents Documents can be loaded by specyfying a file path or by string ```TypeScript -import * as cwltsauto from 'cwl-ts-auto' +import * as cwlTsAuto from 'cwl-ts-auto' import fs from 'fs' import url from 'url' // Load document by file -cwltsauto.loadDocument('./test.cwl') +cwlTsAuto.loadDocument('./test.cwl') .then((file) => { - if (file instanceof cwltsauto.CommandLineTool) { + if (file instanceof cwlTsAuto.CommandLineTool) { console.log('This document is a CommandLineTool with baseCommand: ', file.baseCommand) } }) .catch((e) => { - if(e instanceof cwltsauto.ValidationException) { + if(e instanceof cwlTsAuto.ValidationException) { console.log(e.toString()) } else { console.log(e) @@ -33,14 +33,29 @@ cwltsauto.loadDocument('./test.cwl') // Load document by string let docAsString = fs.readFileSync('./test.cwl').toString() -cwltsauto.loadDocumentByString(docAsString, url.pathToFileURL('/your/base/uri/').toString()) +cwlTsAuto.loadDocumentByString(docAsString, url.pathToFileURL('/your/base/uri/').toString()) .then((file) => { - if (file instanceof cwltsauto.CommandLineTool) { + if (file instanceof cwlTsAuto.CommandLineTool) { console.log('This document is a CommandLineTool with baseCommand: ', file.baseCommand) } }) .catch((e) => { - if(e instanceof cwltsauto.ValidationException) { + 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) @@ -51,24 +66,29 @@ cwltsauto.loadDocumentByString(docAsString, url.pathToFileURL('/your/base/uri/') ### 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' +import * as cwlTsAuto from 'cwl-ts-auto' let exampleCommandLineTool = - new cwltsauto.CommandLineTool({ - class_: cwltsauto.CommandLineTool_class.COMMANDLINETOOL, + new cwlTsAuto.CommandLineTool({ + class_: cwlTsAuto.CommandLineTool_class.COMMANDLINETOOL, inputs: [], outputs: [] }) exampleCommandLineTool.baseCommand = 'echo' let exampleInput = - new cwltsauto.CommandInputParameter({ - type: cwltsauto.PrimitiveType.STRING + 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/) \ No newline at end of file +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/) diff --git a/package.json b/package.json index 5a420b1..f1670eb 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "cwl-ts-auto", - "version": "0.1.1", + "version": "0.1.2", "description": "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.", "author": "Adrian Zimmer", "homepage": "https://www.commonwl.org/", + "keywords": ["cwl", "cwl-ts-auto", "commonwl", "common workflow language", "typescript", "models", "parsing", "serialization", "deserialization"], "license": "Apache License, Version 2.0", "repository": { "type": "git",