Files
react-native/packages/react-native-codegen/buck_tests/combine-js-to-schema.js
Rick Hanlon bcd259a355 Enable Schema everywhere
Summary: Change the codegen `srcs` to match any `**/*Schema.js`

Reviewed By: TheSavior

Differential Revision: D14401232

fbshipit-source-id: 61e60b1c9ca2f33efacc5caa1903b02a93cc644e
2019-03-13 07:02:32 -07:00

37 lines
808 B
JavaScript

/**
* 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';
import type {SchemaType} from '../src/CodegenSchema.js';
function parse(filename: string): ?SchemaType {
try {
// $FlowFixMe Can't require dynamic variables
return require(filename);
} catch (err) {
// ignore
}
}
function combineSchemas(files: Array<string>): SchemaType {
return files.reduce(
(merged, filename) => {
const schema = parse(filename);
if (schema && schema.modules) {
merged.modules = {...merged.modules, ...schema.modules};
}
return merged;
},
{modules: {}},
);
}
module.exports = combineSchemas;