-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
auspice convert
to allow cli v1 -> v2 JSON conversion
- Loading branch information
1 parent
010893c
commit eef0f25
Showing
4 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint no-console: off */ | ||
const fs = require("fs"); | ||
const convertFromV1 = require("./server/convertJsonSchemas").convertFromV1; | ||
const utils = require("./utils"); | ||
|
||
|
||
const addParser = (parser) => { | ||
const description = `Convert dataset files to the most up-to-date schema`; | ||
|
||
const subparser = parser.addParser('convert', {addHelp: true, description}); | ||
subparser.addArgument('--meta-json', {action: "store", help: "v1 schema metadata json"}); | ||
subparser.addArgument('--tree-json', {action: "store", help: "v1 schema tree json"}); | ||
subparser.addArgument('--output', {action: "store", help: "File to write output to"}); | ||
}; | ||
|
||
|
||
/** | ||
* this utility function will increase in scope over time | ||
* but currently it only converts v1 meta + tree jsons -> v2 | ||
*/ | ||
const run = (args) => { | ||
if (!(args.meta_json && args.tree_json)) { | ||
utils.error("Meta + Tree (v1) JSONs are required"); | ||
} | ||
const meta = JSON.parse(fs.readFileSync(args.meta_json, 'utf8')); | ||
const tree = JSON.parse(fs.readFileSync(args.tree_json, 'utf8')); | ||
const v2 = convertFromV1({tree, meta}); | ||
fs.writeFileSync(args.output, JSON.stringify(v2, null, 2)); | ||
}; | ||
|
||
module.exports = { | ||
addParser, | ||
run | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters