Skip to content

Commit

Permalink
Merge pull request #12 from ebceu4/json_schemas
Browse files Browse the repository at this point in the history
Json schemas
  • Loading branch information
siemarell authored Nov 12, 2018
2 parents 32e4984 + 4a5da3c commit 3805d57
Show file tree
Hide file tree
Showing 33 changed files with 1,848 additions and 75 deletions.
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

0 comments on commit 3805d57

Please sign in to comment.