Summary:
This diff adds a new `js1` script `js1 build viewconfigs` which will generate the view configs for generated components in xplat/js

Note that the view configs are not currently valid so I'm not checking them in or adding them to a test, that work will follow

Reviewed By: TheSavior

Differential Revision: D15239656

fbshipit-source-id: d15776f36a7d7684f50beafd783bccb02352afc0
This commit is contained in:
Rick Hanlon 2019-05-16 10:45:54 -07:00 коммит произвёл Facebook Github Bot
Родитель 0815f811df
Коммит c9d9f8cc2a
9 изменённых файлов: 151 добавлений и 43 удалений

Просмотреть файл

@ -11,19 +11,12 @@
'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
}
}
const RNParser = require('../src/generators/RNParser.js');
function combineSchemas(files: Array<string>): SchemaType {
return files.reduce(
(merged, filename) => {
const schema = parse(filename);
const schema = RNParser.parse(filename);
if (schema && schema.modules) {
merged.modules = {...merged.modules, ...schema.modules};
}

Просмотреть файл

@ -42,8 +42,7 @@ try {
throw new Error(`Can't parse schema to JSON. ${schemaPath}`);
}
RNCodegen.generate({
libraryName,
schema,
outputDirectory,
});
RNCodegen.generate(
{libraryName, schema, outputDirectory},
{generators: ['descriptors', 'events', 'props', 'tests', 'shadow-nodes']},
);

Просмотреть файл

@ -0,0 +1,18 @@
/**
* 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.
*
* @emails oncall+react_native
* @flow
* @format
*/
'use strict';
const generate = require('./generate-view-configs');
const [fileList] = process.argv.slice(2);
generate(fileList.split('\n'));

Просмотреть файл

@ -0,0 +1,34 @@
/**
* 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');
function generate(files: Array<string>): void {
files.forEach(filename => {
const schema = RNParser.parse(filename);
if (schema && schema.modules) {
RNCodegen.generate(
{
schema,
outputDirectory: path.dirname(filename),
libraryName: path.basename(filename).replace('Schema.js', ''),
},
{generators: ['view-configs']},
);
}
});
}
module.exports = generate;

Просмотреть файл

@ -0,0 +1,15 @@
#!/bin/bash
# set -euo pipefail
set -e
set -u
THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
FILES=$(find "$JS_DIR/" -name "*Schema.js" -print -type f)
# shellcheck source=xplat/js/env-utils/setup_env_vars.sh
source "$THIS_DIR/../../../../env-utils/setup_env_vars.sh"
exec "$FLOW_NODE_BINARY" "$THIS_DIR/generate-view-configs-cli.js" "$@" "$FILES"

Просмотреть файл

@ -198,7 +198,7 @@ function buildViewConfig(
module.exports = {
generate(libraryName: string, schema: SchemaType): FilesOutput {
const fileName = 'ViewConfigs.js';
const fileName = `${libraryName}NativeViewConfig.js`;
const imports: Set<string> = new Set();
imports.add(

Просмотреть файл

@ -37,6 +37,30 @@ type Options = $ReadOnly<{|
outputDirectory: string,
|}>;
type Generators =
| 'descriptors'
| 'events'
| 'props'
| 'tests'
| 'shadow-nodes'
| 'view-configs';
type Config = $ReadOnly<{|
generators: Array<Generators>,
|}>;
const GENERATORS = {
descriptors: [generateComponentDescriptorH.generate],
events: [generateEventEmitterCpp.generate, generateEventEmitterH.generate],
props: [generatePropsCpp.generate, generatePropsH.generate],
tests: [generateTests.generate],
'shadow-nodes': [
generateShadowNodeCpp.generate,
generateShadowNodeH.generate,
],
'view-configs': [generateViewConfigJs.generate],
};
function writeMapToFiles(map: Map<string, string>, outputDirectory: string) {
map.forEach((contents: string, fileName: string) => {
const location = path.join(outputDirectory, fileName);
@ -45,20 +69,19 @@ function writeMapToFiles(map: Map<string, string>, outputDirectory: string) {
}
module.exports = {
generate({libraryName, schema, outputDirectory}: Options) {
generate(
{libraryName, schema, outputDirectory}: Options,
{generators}: Config,
) {
schemaValidator.validate(schema);
const generatedFiles: Map<string, string> = new Map([
...generateComponentDescriptorH.generate(libraryName, schema),
...generateEventEmitterCpp.generate(libraryName, schema),
...generateEventEmitterH.generate(libraryName, schema),
...generatePropsCpp.generate(libraryName, schema),
...generatePropsH.generate(libraryName, schema),
...generateTests.generate(libraryName, schema),
...generateShadowNodeCpp.generate(libraryName, schema),
...generateShadowNodeH.generate(libraryName, schema),
...generateViewConfigJs.generate(libraryName, schema),
]);
writeMapToFiles(generatedFiles, outputDirectory);
const generatedFiles = [];
for (const name of generators) {
for (const generator of GENERATORS[name]) {
generatedFiles.push(...generator(libraryName, schema));
}
}
writeMapToFiles(new Map([...generatedFiles]), outputDirectory);
},
};

26
packages/react-native-codegen/src/generators/RNParser.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,26 @@
/**
* 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 strict-local
* @format
*/
'use strict';
import type {SchemaType} from '../CodegenSchema.js';
function parse(filename: string): ?SchemaType {
try {
// $FlowFixMe Can't require dynamic variables
return require(filename);
} catch (err) {
// Ignore
}
}
module.exports = {
parse,
};

Просмотреть файл

@ -2,7 +2,7 @@
exports[`GenerateViewConfigJs can generate fixture ARRAY_PROPS 1`] = `
Map {
"ViewConfigs.js" => "
"ARRAY_PROPSNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -43,7 +43,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture BOOLEAN_PROP 1`] = `
Map {
"ViewConfigs.js" => "
"BOOLEAN_PROPNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -78,7 +78,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture COLOR_PROP 1`] = `
Map {
"ViewConfigs.js" => "
"COLOR_PROPNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -113,7 +113,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture ENUM_PROP 1`] = `
Map {
"ViewConfigs.js" => "
"ENUM_PROPNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -148,7 +148,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture EVENT_NESTED_OBJECT_PROPS 1`] = `
Map {
"ViewConfigs.js" => "
"EVENT_NESTED_OBJECT_PROPSNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -192,7 +192,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture EVENT_PROPS 1`] = `
Map {
"ViewConfigs.js" => "
"EVENT_PROPSNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -242,7 +242,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture FLOAT_PROPS 1`] = `
Map {
"ViewConfigs.js" => "
"FLOAT_PROPSNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -282,7 +282,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture IMAGE_PROP 1`] = `
Map {
"ViewConfigs.js" => "
"IMAGE_PROPNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -317,7 +317,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture INTEGER_PROPS 1`] = `
Map {
"ViewConfigs.js" => "
"INTEGER_PROPSNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -354,7 +354,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture INTERFACE_ONLY 1`] = `
Map {
"ViewConfigs.js" => "
"INTERFACE_ONLYNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -398,7 +398,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture MULTI_NATIVE_PROP 1`] = `
Map {
"ViewConfigs.js" => "
"MULTI_NATIVE_PROPNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -436,7 +436,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture POINT_PROP 1`] = `
Map {
"ViewConfigs.js" => "
"POINT_PROPNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -471,7 +471,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture STRING_PROP 1`] = `
Map {
"ViewConfigs.js" => "
"STRING_PROPNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -506,7 +506,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture TWO_COMPONENTS_DIFFERENT_FILES 1`] = `
Map {
"ViewConfigs.js" => "
"TWO_COMPONENTS_DIFFERENT_FILESNativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@ -555,7 +555,7 @@ ReactNativeViewConfigRegistry.register(
exports[`GenerateViewConfigJs can generate fixture TWO_COMPONENTS_SAME_FILE 1`] = `
Map {
"ViewConfigs.js" => "
"TWO_COMPONENTS_SAME_FILENativeViewConfig.js" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*