Skip to content

Commit

Permalink
refactor: Remove non-alt version
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This package no longer require `ts-morph` and does not take inn file argument. Please consult our README.md for more information
  • Loading branch information
runeh authored and simenandre committed Mar 25, 2021
1 parent c76338d commit 1625b96
Show file tree
Hide file tree
Showing 9 changed files with 684 additions and 909 deletions.
64 changes: 47 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ conversion package (e.g. JSON Schema to Runtypes).
We are thankful for all help with adding new functionality, fixing issues, or
improve the package. Feel free to open issues and pull requests ❤️

It's based on [ts-morph][ts-morph] 🎉

## Documentation

Apart from this README, you can find details and examples of using the SDK in
Expand All @@ -28,23 +26,55 @@ the following places:
## Example

```typescript
import { Project } from 'ts-morph';
import { generateRuntype } from 'generate-runtypes';

const project = new Project();
const file = project.createSourceFile('./my-file.ts');

generateRuntype(file, {
name: 'Post',
fields: [
{ name: 'title', type: 'String' },
{ name: 'body', type: 'String' },
{ name: 'author', type: 'String' },
{ name: 'comments', type: 'Array', subType: 'Comment' },
],
import { generateRuntypes } from 'generate-runtypes';

const sourceCode = generateRuntypes(
{
name: 'Comment',
type: {
kind: 'record',
fields: [
{ name: 'author', type: { kind: 'string' } },
{ name: 'body', type: { kind: 'string' } },
{ name: 'timestamp', type: { kind: 'number' } },
],
},
},
{
name: 'Post',
export: true,
type: {
kind: 'record',
fields: [
{ name: 'title', type: { kind: 'string' } },
{ name: 'body', type: { kind: 'string' } },
{ name: 'author', type: { kind: 'string' } },
{
name: 'comments',
type: { kind: 'array', type: { kind: 'named', name: 'Comment' } },
},
],
},
},
);
```

The generated code looks like this after formatting:

```typescript
const Comment = rt.Record({
author: rt.String,
body: rt.String,
timestamp: rt.Number,
});

export const Post = rt.Record({
title: rt.String,
body: rt.String,
author: rt.String,
comments: rt.Array(Comment),
});
```

[runtypes]: https://github.com/pelotom/runtypes
[ts-morph]: https://github.com/dsherret/ts-morph
[docs]: ./docs
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"@types/faker": "^5.1.7",
"@types/jest": "~26.0.21",
"@types/node": "~14.14.35",
"typedoc": "^0.20.1",
"typedoc": "^0.20.34",
"typedoc-plugin-markdown": "^3.0.8",
"@typescript-eslint/eslint-plugin": "~4.18.0",
"@typescript-eslint/eslint-plugin": "~4.19.0",
"@typescript-eslint/parser": "~4.19.0",
"eslint": "~7.22.0",
"eslint-config-prettier": "~8.1.0",
Expand All @@ -41,7 +41,6 @@
},
"dependencies": {
"runtypes": "^5.0.2",
"ts-morph": "^10.0.1",
"typescript": "~4.1.3"
}
}
Loading

0 comments on commit 1625b96

Please sign in to comment.