Emit true JSON
parent
62fd586712
commit
fd049a4d30
54
README.md
54
README.md
|
@ -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.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
const fs = require('fs');
|
||||
|
||||
const stringify = require('json-stringify-pretty-compact');
|
||||
const argv = require('optimist')
|
||||
.usage('Usage: $0 <path> ...')
|
||||
.argv;
|
||||
|
@ -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);
|
||||
|
|
71
package.json
71
package.json
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue