Skip to content

Commit

Permalink
Introduce a simple script to convert from JATS to json (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlisgo authored Oct 17, 2024
1 parent c328349 commit df787bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 22 additions & 0 deletions src/convertJats.ts
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit df787bf

Please sign in to comment.