Add js1 build viewconfigs
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:
Родитель
0815f811df
Коммит
c9d9f8cc2a
|
@ -11,19 +11,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
import type {SchemaType} from '../src/CodegenSchema.js';
|
import type {SchemaType} from '../src/CodegenSchema.js';
|
||||||
|
|
||||||
function parse(filename: string): ?SchemaType {
|
const RNParser = require('../src/generators/RNParser.js');
|
||||||
try {
|
|
||||||
// $FlowFixMe Can't require dynamic variables
|
|
||||||
return require(filename);
|
|
||||||
} catch (err) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function combineSchemas(files: Array<string>): SchemaType {
|
function combineSchemas(files: Array<string>): SchemaType {
|
||||||
return files.reduce(
|
return files.reduce(
|
||||||
(merged, filename) => {
|
(merged, filename) => {
|
||||||
const schema = parse(filename);
|
const schema = RNParser.parse(filename);
|
||||||
if (schema && schema.modules) {
|
if (schema && schema.modules) {
|
||||||
merged.modules = {...merged.modules, ...schema.modules};
|
merged.modules = {...merged.modules, ...schema.modules};
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,7 @@ try {
|
||||||
throw new Error(`Can't parse schema to JSON. ${schemaPath}`);
|
throw new Error(`Can't parse schema to JSON. ${schemaPath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
RNCodegen.generate({
|
RNCodegen.generate(
|
||||||
libraryName,
|
{libraryName, schema, outputDirectory},
|
||||||
schema,
|
{generators: ['descriptors', 'events', 'props', 'tests', 'shadow-nodes']},
|
||||||
outputDirectory,
|
);
|
||||||
});
|
|
||||||
|
|
|
@ -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 = {
|
module.exports = {
|
||||||
generate(libraryName: string, schema: SchemaType): FilesOutput {
|
generate(libraryName: string, schema: SchemaType): FilesOutput {
|
||||||
const fileName = 'ViewConfigs.js';
|
const fileName = `${libraryName}NativeViewConfig.js`;
|
||||||
const imports: Set<string> = new Set();
|
const imports: Set<string> = new Set();
|
||||||
|
|
||||||
imports.add(
|
imports.add(
|
||||||
|
|
|
@ -37,6 +37,30 @@ type Options = $ReadOnly<{|
|
||||||
outputDirectory: string,
|
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) {
|
function writeMapToFiles(map: Map<string, string>, outputDirectory: string) {
|
||||||
map.forEach((contents: string, fileName: string) => {
|
map.forEach((contents: string, fileName: string) => {
|
||||||
const location = path.join(outputDirectory, fileName);
|
const location = path.join(outputDirectory, fileName);
|
||||||
|
@ -45,20 +69,19 @@ function writeMapToFiles(map: Map<string, string>, outputDirectory: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generate({libraryName, schema, outputDirectory}: Options) {
|
generate(
|
||||||
|
{libraryName, schema, outputDirectory}: Options,
|
||||||
|
{generators}: Config,
|
||||||
|
) {
|
||||||
schemaValidator.validate(schema);
|
schemaValidator.validate(schema);
|
||||||
|
|
||||||
const generatedFiles: Map<string, string> = new Map([
|
const generatedFiles = [];
|
||||||
...generateComponentDescriptorH.generate(libraryName, schema),
|
for (const name of generators) {
|
||||||
...generateEventEmitterCpp.generate(libraryName, schema),
|
for (const generator of GENERATORS[name]) {
|
||||||
...generateEventEmitterH.generate(libraryName, schema),
|
generatedFiles.push(...generator(libraryName, schema));
|
||||||
...generatePropsCpp.generate(libraryName, schema),
|
}
|
||||||
...generatePropsH.generate(libraryName, schema),
|
}
|
||||||
...generateTests.generate(libraryName, schema),
|
|
||||||
...generateShadowNodeCpp.generate(libraryName, schema),
|
writeMapToFiles(new Map([...generatedFiles]), outputDirectory);
|
||||||
...generateShadowNodeH.generate(libraryName, schema),
|
|
||||||
...generateViewConfigJs.generate(libraryName, schema),
|
|
||||||
]);
|
|
||||||
writeMapToFiles(generatedFiles, outputDirectory);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -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`] = `
|
exports[`GenerateViewConfigJs can generate fixture ARRAY_PROPS 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"ARRAY_PROPSNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -43,7 +43,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture BOOLEAN_PROP 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture BOOLEAN_PROP 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"BOOLEAN_PROPNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -78,7 +78,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture COLOR_PROP 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture COLOR_PROP 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"COLOR_PROPNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -113,7 +113,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture ENUM_PROP 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture ENUM_PROP 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"ENUM_PROPNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -148,7 +148,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture EVENT_NESTED_OBJECT_PROPS 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture EVENT_NESTED_OBJECT_PROPS 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"EVENT_NESTED_OBJECT_PROPSNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -192,7 +192,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture EVENT_PROPS 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture EVENT_PROPS 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"EVENT_PROPSNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -242,7 +242,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture FLOAT_PROPS 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture FLOAT_PROPS 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"FLOAT_PROPSNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -282,7 +282,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture IMAGE_PROP 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture IMAGE_PROP 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"IMAGE_PROPNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -317,7 +317,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture INTEGER_PROPS 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture INTEGER_PROPS 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"INTEGER_PROPSNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -354,7 +354,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture INTERFACE_ONLY 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture INTERFACE_ONLY 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"INTERFACE_ONLYNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -398,7 +398,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture MULTI_NATIVE_PROP 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture MULTI_NATIVE_PROP 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"MULTI_NATIVE_PROPNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -436,7 +436,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture POINT_PROP 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture POINT_PROP 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"POINT_PROPNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -471,7 +471,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture STRING_PROP 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture STRING_PROP 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"STRING_PROPNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -506,7 +506,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture TWO_COMPONENTS_DIFFERENT_FILES 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture TWO_COMPONENTS_DIFFERENT_FILES 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"TWO_COMPONENTS_DIFFERENT_FILESNativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
@ -555,7 +555,7 @@ ReactNativeViewConfigRegistry.register(
|
||||||
|
|
||||||
exports[`GenerateViewConfigJs can generate fixture TWO_COMPONENTS_SAME_FILE 1`] = `
|
exports[`GenerateViewConfigJs can generate fixture TWO_COMPONENTS_SAME_FILE 1`] = `
|
||||||
Map {
|
Map {
|
||||||
"ViewConfigs.js" => "
|
"TWO_COMPONENTS_SAME_FILENativeViewConfig.js" => "
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
|
|
Загрузка…
Ссылка в новой задаче