Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json schemas #12

Merged
merged 3 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ typings/

# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
dist
build
build/tmp
.idea
sandbox.spec.ts
53 changes: 53 additions & 0 deletions build/schemas.ts
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()
4 changes: 2 additions & 2 deletions build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const rimraf = require('rimraf')
export const p = (...path: string[]) => resolve(__dirname, ...path)

export const remove = (path: string): Promise<void> =>
new Promise((resolve, reject) => rimraf(path, (err) => err ? reject(err) : resolve()))
new Promise((resolve, reject) => rimraf(path, (err:any) => err ? reject(err) : resolve()))

export const copy = (src: string, dst: string): Promise<void> =>
new Promise((resolve, reject) => ncp(src, dst, (err) => err ? reject(err) : resolve()))
new Promise((resolve, reject) => ncp(src, dst, (err:any) => err ? reject(err) : resolve()))

export const exists = (path: string): Promise<boolean> =>
new Promise((resolve, _) => ex(path, (exists) => resolve(exists)))
Expand Down
4 changes: 2 additions & 2 deletions build/verions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { run } from "./utils";
async function keepVersions(versionsToKeep: string[]) {
const response = await run('npm view waves-transactions')
const versionInfo = eval("(" + response + ")")
const versionsToRemove = versionInfo.versions.filter(x => !versionsToKeep.includes(x))
await Promise.all(versionsToRemove.map(v => run('npm unpublish waves-transactions@' + v).then(_ => console.log(v + ' removed')).catch(_ => { })))
const versionsToRemove = versionInfo.versions.filter((x:any) => !versionsToKeep.includes(x))
await Promise.all(versionsToRemove.map((v:any) => run('npm unpublish waves-transactions@' + v).then(_ => console.log(v + ' removed')).catch(_ => { })))
console.log('done')
}

Expand Down
28 changes: 12 additions & 16 deletions jest.config.js
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,
}
Loading