2019-01-15 15:28:43 -08:00
|
|
|
/**
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
* @flow
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
2019-02-11 14:50:44 -08:00
|
|
|
import type {SchemaType} from '../src/CodegenSchema.js';
|
2019-01-15 15:28:43 -08:00
|
|
|
|
2019-02-11 14:50:44 -08:00
|
|
|
function parse(filename: string): SchemaType {
|
|
|
|
try {
|
|
|
|
// $FlowFixMe Can't require dynamic variables
|
|
|
|
return require(filename);
|
|
|
|
} catch (err) {
|
|
|
|
throw new Error(`Can't require file at ${filename} ${err}`);
|
|
|
|
}
|
2019-01-15 15:28:43 -08:00
|
|
|
}
|
|
|
|
|
2019-02-11 14:50:44 -08:00
|
|
|
function combineSchemas(files: Array<string>): SchemaType {
|
|
|
|
return files.reduce(
|
|
|
|
(merged, filename) => {
|
|
|
|
const schema = parse(filename);
|
|
|
|
merged.modules = {...merged.modules, ...schema.modules};
|
|
|
|
return merged;
|
|
|
|
},
|
|
|
|
{modules: {}},
|
|
|
|
);
|
2019-01-15 15:28:43 -08:00
|
|
|
}
|
|
|
|
|
2019-02-11 14:50:44 -08:00
|
|
|
module.exports = combineSchemas;
|