diff --git a/README.md b/README.md index 0bd6a71d2..4f6ec90d2 100644 --- a/README.md +++ b/README.md @@ -366,6 +366,12 @@ If you are using VSCode, you can use the [Auto Attach feature](https://code.visu npm run debug -- convert simple.gdoc simple.ipynb ``` +A simple script to convert JATS to JSON: + +```bash +cat simple-jats.xml | npm run convert-jats --silent > simple.json +``` + ## Testing ### Running tests locally diff --git a/package.json b/package.json index f9eae839e..e31deab37 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "check:deps-used": "dependency-check --missing .", "check:deps-unused": "dependency-check --unused --no-dev --ignore-module @stencila/schema --ignore-module @stencila/thema .", "start": "ts-node --files src", + "convert-jats": "ts-node ./src/convertJats.ts", "debug": "node --require ./ts-node-register.js --inspect=9229 src --debug=1", "$comment": "The build script builds everything required to publish a release, including binaries and docs", "build": "npm run build:codemeta && npm run build:dist && npm run build:docs", diff --git a/src/convertJats.ts b/src/convertJats.ts new file mode 100644 index 000000000..fe76ad6c8 --- /dev/null +++ b/src/convertJats.ts @@ -0,0 +1,22 @@ +#!/usr/bin/env node + +import { convert } from './index' + +// Convert JATS from stdin and return JSON to console.log +convert('-', undefined, { + from: 'jats', + to: 'json', + encodeOptions: { + isBundle: false, + }, + decodeOptions: { + shouldReshape: false, + }, +}) + .then((conversion) => conversion ?? '{}') + .then((conversion) => conversion.replaceAll(`${process.cwd()}/`, '')) + .then((conversion) => console.log(conversion)) + .catch((error) => { + console.error('Error during conversion:', error) + process.exit(1) + })