-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from ebceu4/json_schemas
Json schemas
- Loading branch information
Showing
33 changed files
with
1,848 additions
and
75 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,53 @@ | ||
import { resolve } from "path"; | ||
import { writeFile} from "fs-extra"; | ||
|
||
import * as TJS from "typescript-json-schema"; | ||
|
||
const TYPES = [ | ||
'Tx', | ||
'AliasTransaction', | ||
'IssueTransaction', | ||
'TransferTransaction', | ||
'ReissueTransaction', | ||
'BurnTransaction', | ||
'LeaseTransaction', | ||
'CancelLeaseTransaction', | ||
'MassTransferTransaction', | ||
'SetScriptTransaction', | ||
'DataTransaction', | ||
] | ||
|
||
export function buildSchemas() { | ||
// optionally pass argument to schema generator | ||
const settings: TJS.PartialArgs = { | ||
required: true, | ||
include: ['transactions.ts'], | ||
excludePrivate: true, | ||
noExtraProps: true | ||
}; | ||
|
||
// optionally pass ts compiler options | ||
const compilerOptions: TJS.CompilerOptions = { | ||
strictNullChecks: true, | ||
|
||
} | ||
|
||
|
||
const program = TJS.getProgramFromFiles([resolve("src/transactions.ts")], compilerOptions); | ||
|
||
|
||
TYPES.forEach(type => { | ||
const id = `https://github.com/github/ebceu4/blob/master/src/schemas/${type}.json` | ||
const schema = TJS.generateSchema(program, type, { ...settings, id }); | ||
const filePath = `src/schemas/${type}.json` | ||
const fileContent = JSON.stringify(schema, null, 2) | ||
writeFile(filePath, fileContent, (err) => { | ||
if (err) throw err; | ||
|
||
console.log(`${type} schema has been written`); | ||
}); | ||
//console.log(schema) | ||
}) | ||
} | ||
|
||
buildSchemas() |
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
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 |
---|---|---|
@@ -1,18 +1,14 @@ | ||
module.exports = { | ||
roots: [ | ||
"<rootDir>/test" | ||
], | ||
transform: { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$", | ||
moduleFileExtensions: [ | ||
"ts", | ||
"tsx", | ||
"js", | ||
"jsx", | ||
"json", | ||
"node" | ||
], | ||
collectCoverage: true | ||
roots: [ | ||
'<rootDir>/test', | ||
], | ||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$', | ||
collectCoverage: true, | ||
globals: { | ||
'ts-jest': { | ||
diagnostics: false, | ||
}, | ||
}, | ||
preset: 'ts-jest', | ||
testMatch: null, | ||
} |
Oops, something went wrong.