flow2schema/src/index.js

28 lines
660 B
JavaScript
Raw Permalink Normal View History

2018-07-25 08:38:10 +03:00
// @flow
2017-11-16 15:17:15 +03:00
import Parser from './parser';
import Collector from './collector';
2017-12-01 22:39:03 +03:00
import type {Type} from './types';
2017-12-16 17:03:08 +03:00
import generateJsonSchema from './generators/jsonSchema';
import type {Schema} from './generators/jsonSchema';
2017-11-16 15:17:15 +03:00
// @see babel#6805.
//export {Parser, Collector};
2017-12-17 13:29:32 +03:00
function collect(path: string): {+types: Type[], +schema: Schema} {
2017-11-16 15:17:15 +03:00
const parser = new Parser;
const collector = new Collector(parser);
collector.collect(path);
2017-12-02 11:01:37 +03:00
const fund = collector.finish();
return {
2017-12-16 17:03:08 +03:00
types: Array.from(fund.takeAll()),
schema: generateJsonSchema(fund),
2017-12-02 11:01:37 +03:00
};
2017-11-16 15:17:15 +03:00
}
2017-12-17 13:29:32 +03:00
// Export in CommonJS for the users.
module.exports = collect;