Files
react-native/packages/react-native-codegen/buck_tests/generate-view-configs.js
T
Rick HanlonandFacebook Github Bot 3ccfbd6c39 Add test for js1 build viewconfigs
Summary:
This diff adds a new `--test` option to `js1 build viewconfigs` which will only check that the configs have not changed instead of writing the new/updated files. This will allow us to run sandcastle checks on the view configs

I also improved the output of the script to give better feedback during normal runs including an additional message and a summary of generated files

Reviewed By: TheSavior

Differential Revision: D15372843

fbshipit-source-id: 4988fc2405cc03137b540817e08d4365cb31fc34
2019-05-20 02:52:37 -07:00

69 lines
1.6 KiB
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';
const RNCodegen = require('../src/generators/RNCodegen.js');
const RNParser = require('../src/generators/RNParser.js');
const path = require('path');
type Result = $ReadOnly<{|
libraryName: string,
success: boolean,
|}>;
function generateFilesWithResults(
files: Array<string>,
test: boolean,
): Array<Result> {
return files.reduce((aggregated, filename) => {
const schema = RNParser.parse(filename);
if (schema && schema.modules) {
const libraryName = path.basename(filename).replace('Schema.js', '');
const success = RNCodegen.generate(
{
schema,
libraryName,
outputDirectory: path.dirname(filename),
},
{generators: ['view-configs'], test},
);
aggregated.push({
libraryName,
success,
});
}
return aggregated;
}, []);
}
function generate(files: Array<string>, test: boolean): void {
console.log(`${test ? 'Testing' : 'Generating'} view configs`);
const results = generateFilesWithResults(files, test);
const failed = results.filter(result => !result.success);
const totalCount = results.length;
console.log(`\n${test ? 'Tested' : 'Generated'} ${totalCount} view configs`);
if (failed.length) {
if (test === true) {
console.error(`${failed.length} configs changed`);
console.error("Please re-run 'js1 build viewconfigs'");
}
process.exit(1);
}
}
module.exports = generate;