Skip to content

Commit

Permalink
Emit true JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
loyd committed Nov 6, 2017
1 parent 62fd586 commit fd049a4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 66 deletions.
54 changes: 27 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,40 @@

## Example

Input:
Input (`example.js`):
```javascript
$ ./bin/flow2avro -
interface Foo {
foo: string,
// $avro long
bar: number,
opt: ?number,
baz: 'one' | 'two',
mix: 'one' | 'two' | number,
}
interface Foo {
foo: string,
// $avro long
bar: number,
opt: ?number,
baz: 'one' | 'two',
mix: 'one' | 'two' | number,
}
```

Output:
```javascript
[{
type: 'record',
name: 'Foo',
namespace: 'example',
fields: [
{ name: 'foo', type: 'string' },
{ name: 'bar', type: 'long' },
{ name: 'opt', type: [ 'null', 'double' ] },
{ name: 'baz', type: { type: 'enum', symbols: [ 'one', 'two' ] } },
{ name: 'mix', type: [
'double',
{ type: 'enum', symbols: [ 'one', 'two' ] },
] },
Output (`$ ./bin/flow2avro example.js`):
```json
[
{
"type": "record",
"fields": [
{"name": "foo", "type": "string"},
{"name": "bar", "type": "double"},
{"name": "opt", "type": ["null", "double"]},
{"name": "baz", "type": {"type": "enum", "symbols": ["one", "two"]}},
{
"name": "mix",
"type": ["double", {"type": "enum", "symbols": ["one", "two"]}]
}
],
}]
"name": "Foo",
"namespace": "example"
}
]
```

## TODO

* Generics.
* Errors and warnings.
* Support commonjs modules.
Expand Down
6 changes: 2 additions & 4 deletions bin/flow2avro
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const fs = require('fs');

const stringify = require('json-stringify-pretty-compact');
const argv = require('optimist')
.usage('Usage: $0 <path> ...')
.argv;
Expand All @@ -20,10 +21,7 @@ function run(path) {
try {
const {schemas} = collect(path);

console.dir(schemas, {
colors: true,
depth: Infinity,
});
console.log(stringify(schemas));
} catch (ex) {
console.error(ex.message);
console.error(ex.stack);
Expand Down
71 changes: 36 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
{
"name": "flow2avro",
"version": "0.1.0",
"description": "Generate avro schemas for flowtype definitions",
"author": "Paul Loyd <pavelko95@gmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/loyd/flow2avro.git"
},
"bugs": {
"url": "https://github.com/loyd/flow2avro/issues"
},
"keywords": [
"flow",
"flowtype",
"avro",
"avsc"
],
"main": "lib/index.js",
"bin": {
"babylon": "./bin/babylon.js"
},
"dependencies": {
"babylon": "^6.18.0",
"optimist": "^0.6.1",
"resolve": "^1.5.0"
},
"devDependencies": {
"jasmine": "^2.8.0",
"mocha": "^4.0.1",
"nyc": "^11.3.0"
},
"scripts": {
"test": "nyc mocha tests/do"
}
"name": "flow2avro",
"version": "0.2.0",
"description": "Generate avro schemas for flowtype definitions",
"author": "Paul Loyd <pavelko95@gmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/loyd/flow2avro.git"
},
"bugs": {
"url": "https://github.com/loyd/flow2avro/issues"
},
"keywords": [
"flow",
"flowtype",
"avro",
"avsc"
],
"main": "lib/index.js",
"bin": {
"babylon": "./bin/babylon.js"
},
"dependencies": {
"babylon": "^6.18.0",
"json-stringify-pretty-compact": "^1.0.4",
"optimist": "^0.6.1",
"resolve": "^1.5.0"
},
"devDependencies": {
"jasmine": "^2.8.0",
"mocha": "^4.0.1",
"nyc": "^11.3.0"
},
"scripts": {
"test": "nyc mocha tests/do"
}
}

0 comments on commit fd049a4

Please sign in to comment.