Created
October 13, 2021 20:15
-
-
Save webmaster128/3b46d9596e807875d1d70f7f5d12057e to your computer and use it in GitHub Desktop.
CosmWasm schema to TypeScript .d.ts
This file contains hidden or 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
#!/usr/bin/env node | |
const $RefParser = require("@apidevtools/json-schema-ref-parser"); | |
function printUsage() { | |
console.info("Usage: json-schema-ref-parser-cli FILE") | |
} | |
async function main(args) { | |
if (args.length !== 1) { | |
printUsage(); | |
return 2; | |
} | |
let normalized = await $RefParser.dereference(args[0]); | |
process.stdout.write(JSON.stringify(normalized, null, 2) + "\n"); | |
return 0 | |
} | |
main(process.argv.slice(2)).then( | |
code => process.exit(code), | |
error => { | |
console.error(error); | |
process.exit(1); | |
}, | |
); | |
This file contains hidden or 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
#!/usr/bin/env node | |
const { compileFromFile } = require("json-schema-to-typescript"); | |
function printUsage() { | |
console.info("Usage: json-schema-to-typescript-cli FILE") | |
} | |
async function main(args) { | |
if (args.length !== 1) { | |
printUsage(); | |
return 2; | |
} | |
let ts = await compileFromFile(args[0], { | |
bannerComment: "" | |
}); | |
process.stdout.write(ts); | |
return 0 | |
} | |
main(process.argv.slice(2)).then( | |
code => process.exit(code), | |
error => { | |
console.error(error); | |
process.exit(1); | |
}, | |
); | |
This file contains hidden or 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
#!/bin/bash | |
set -o errexit -o nounset -o pipefail | |
command -v shellcheck > /dev/null && shellcheck "$0" | |
NORMALIZER="$(yarn bin)/json-schema-ref-parser-cli" # local wrapper around npm package @apidevtools/json-schema-ref-parser | |
SCHEMA2DTS="$(yarn bin)/json-schema-to-typescript-cli" # local wrapper around npm package json-schema-to-typescript | |
SOURCE_DIR="$1" | |
{ | |
echo "/*" | |
echo " * This file is licensed" | |
echo " * for you under WTFPL OR 0BSD OR Unlicense OR MIT OR BSD-3-Clause." | |
echo " * Note that different terms apply for the contract's source code and schema." | |
echo " * Type generation powered by json-schema-to-typescript." | |
echo " */" | |
echo "" | |
} | |
for SCHEMA in "$SOURCE_DIR"/schema/*.json; do | |
NORMALIZED_SCHEMA=$(basename "$SCHEMA") | |
echo "Processing $SCHEMA ..." >&2 | |
"$NORMALIZER" "$SCHEMA" > "$NORMALIZED_SCHEMA" | |
( | |
"$SCHEMA2DTS" "$NORMALIZED_SCHEMA" | |
echo "" | |
) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment