@react-native/codegen 0.74.0 → 0.75.0-nightly-20240221-a1171f79f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CodegenSchema.d.ts +10 -1
- package/lib/CodegenSchema.js.flow +2 -1
- package/lib/SchemaValidator.js.flow +2 -2
- package/lib/cli/combine/combine-js-to-schema-cli.js +59 -40
- package/lib/cli/combine/combine-js-to-schema-cli.js.flow +23 -39
- package/lib/cli/combine/combine-js-to-schema.js +49 -1
- package/lib/cli/combine/combine-js-to-schema.js.flow +59 -1
- package/lib/cli/combine/combine-schemas-cli.js +77 -0
- package/lib/cli/combine/combine-schemas-cli.js.flow +87 -0
- package/lib/cli/combine/combine-utils.js +3 -65
- package/lib/cli/combine/combine-utils.js.flow +7 -28
- package/lib/cli/parser/parser.js +1 -1
- package/lib/cli/parser/parser.js.flow +1 -1
- package/lib/generators/RNCodegen.d.ts +1 -0
- package/lib/generators/RNCodegen.js +58 -31
- package/lib/generators/RNCodegen.js.flow +52 -32
- package/lib/generators/TypeUtils/Cxx/index.js +17 -0
- package/lib/generators/TypeUtils/Cxx/index.js.flow +18 -0
- package/lib/generators/TypeUtils/Java/index.js +31 -0
- package/lib/generators/TypeUtils/Java/index.js.flow +27 -0
- package/lib/generators/TypeUtils/Objective-C/index.js +17 -0
- package/lib/generators/TypeUtils/Objective-C/index.js.flow +18 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js +7 -7
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +8 -10
- package/lib/generators/components/ComponentsProviderUtils.js +55 -0
- package/lib/generators/components/ComponentsProviderUtils.js.flow +60 -0
- package/lib/generators/components/CppHelpers.js +7 -0
- package/lib/generators/components/CppHelpers.js.flow +14 -0
- package/lib/generators/components/GenerateComponentDescriptorCpp.js +89 -0
- package/lib/generators/components/GenerateComponentDescriptorCpp.js.flow +101 -0
- package/lib/generators/components/GenerateComponentDescriptorH.js +28 -12
- package/lib/generators/components/GenerateComponentDescriptorH.js.flow +20 -12
- package/lib/generators/components/GenerateComponentHObjCpp.js +15 -1
- package/lib/generators/components/GenerateComponentHObjCpp.js.flow +11 -2
- package/lib/generators/components/GenerateEventEmitterCpp.js +28 -15
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +16 -17
- package/lib/generators/components/GenerateEventEmitterH.js +20 -13
- package/lib/generators/components/GenerateEventEmitterH.js.flow +13 -15
- package/lib/generators/components/GeneratePropsCpp.js +17 -8
- package/lib/generators/components/GeneratePropsCpp.js.flow +13 -9
- package/lib/generators/components/GeneratePropsH.js +23 -16
- package/lib/generators/components/GeneratePropsH.js.flow +12 -16
- package/lib/generators/components/GeneratePropsJavaDelegate.js +11 -3
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +7 -4
- package/lib/generators/components/GeneratePropsJavaInterface.js +11 -3
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +6 -3
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +6 -6
- package/lib/generators/components/GeneratePropsJavaPojo/index.js +1 -1
- package/lib/generators/components/GeneratePropsJavaPojo/index.js.flow +1 -1
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +1 -0
- package/lib/generators/components/GenerateShadowNodeCpp.js +19 -8
- package/lib/generators/components/GenerateShadowNodeCpp.js.flow +9 -8
- package/lib/generators/components/GenerateShadowNodeH.js +27 -11
- package/lib/generators/components/GenerateShadowNodeH.js.flow +11 -14
- package/lib/generators/components/GenerateStateCpp.js +19 -8
- package/lib/generators/components/GenerateStateCpp.js.flow +9 -8
- package/lib/generators/components/GenerateStateH.js +9 -5
- package/lib/generators/components/GenerateStateH.js.flow +3 -4
- package/lib/generators/components/GenerateTests.js +11 -5
- package/lib/generators/components/GenerateTests.js.flow +2 -2
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +16 -3
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +18 -3
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +18 -3
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +21 -3
- package/lib/generators/components/GenerateViewConfigJs.js +2 -2
- package/lib/generators/components/GenerateViewConfigJs.js.flow +2 -2
- package/lib/generators/components/JavaHelpers.js +8 -0
- package/lib/generators/components/JavaHelpers.js.flow +9 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +22 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +22 -0
- package/lib/generators/modules/GenerateModuleCpp.js +14 -10
- package/lib/generators/modules/GenerateModuleCpp.js.flow +9 -10
- package/lib/generators/modules/GenerateModuleH.js +198 -72
- package/lib/generators/modules/GenerateModuleH.js.flow +186 -71
- package/lib/generators/modules/GenerateModuleJavaSpec.js +50 -57
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +45 -50
- package/lib/generators/modules/GenerateModuleJniCpp.js +16 -12
- package/lib/generators/modules/GenerateModuleJniCpp.js.flow +11 -12
- package/lib/generators/modules/GenerateModuleJniH.js +12 -5
- package/lib/generators/modules/GenerateModuleJniH.js.flow +8 -6
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js +5 -5
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js.flow +11 -12
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +23 -21
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js.flow +19 -18
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +23 -21
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js.flow +19 -18
- package/lib/generators/modules/GenerateModuleObjCpp/index.js +18 -20
- package/lib/generators/modules/GenerateModuleObjCpp/index.js.flow +11 -14
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +40 -42
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +38 -44
- package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js +25 -27
- package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js.flow +26 -28
- package/lib/generators/modules/Utils.js +98 -0
- package/lib/generators/modules/Utils.js.flow +34 -2
- package/lib/generators/modules/__test_fixtures__/fixtures.js +685 -64
- package/lib/generators/modules/__test_fixtures__/fixtures.js.flow +686 -64
- package/lib/parsers/error-utils.js +17 -17
- package/lib/parsers/error-utils.js.flow +10 -10
- package/lib/parsers/errors.js +10 -0
- package/lib/parsers/errors.js.flow +15 -1
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +7 -1
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +7 -1
- package/lib/parsers/flow/components/commands.js +24 -0
- package/lib/parsers/flow/components/commands.js.flow +45 -3
- package/lib/parsers/flow/components/componentsUtils.js +5 -4
- package/lib/parsers/flow/components/componentsUtils.js.flow +4 -3
- package/lib/parsers/flow/components/events.js +7 -7
- package/lib/parsers/flow/components/events.js.flow +7 -7
- package/lib/parsers/flow/components/index.js +8 -8
- package/lib/parsers/flow/components/index.js.flow +3 -3
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +13 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +13 -0
- package/lib/parsers/flow/modules/index.js +20 -19
- package/lib/parsers/flow/modules/index.js.flow +10 -11
- package/lib/parsers/flow/parseFlowAndThrowErrors.js +105 -0
- package/lib/parsers/flow/parseFlowAndThrowErrors.js.flow +41 -0
- package/lib/parsers/flow/parser.js +24 -25
- package/lib/parsers/flow/parser.js.flow +27 -36
- package/lib/parsers/flow/utils.js.flow +1 -1
- package/lib/parsers/parser.js.flow +12 -10
- package/lib/parsers/parserMock.js +11 -12
- package/lib/parsers/parserMock.js.flow +25 -28
- package/lib/parsers/parsers-commons.js +85 -36
- package/lib/parsers/parsers-commons.js.flow +71 -37
- package/lib/parsers/parsers-primitives.js +17 -17
- package/lib/parsers/parsers-primitives.js.flow +14 -16
- package/lib/parsers/schema.js.flow +3 -3
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +8 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +8 -1
- package/lib/parsers/typescript/components/commands.js +23 -15
- package/lib/parsers/typescript/components/commands.js.flow +24 -16
- package/lib/parsers/typescript/components/componentsUtils.js +34 -20
- package/lib/parsers/typescript/components/componentsUtils.js.flow +36 -19
- package/lib/parsers/typescript/components/events.js +22 -22
- package/lib/parsers/typescript/components/events.js.flow +11 -10
- package/lib/parsers/typescript/components/extends.js.flow +1 -0
- package/lib/parsers/typescript/components/index.js +10 -10
- package/lib/parsers/typescript/components/index.js.flow +4 -4
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js +13 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js.flow +13 -0
- package/lib/parsers/typescript/modules/index.js +25 -20
- package/lib/parsers/typescript/modules/index.js.flow +16 -14
- package/lib/parsers/typescript/parser.js +25 -26
- package/lib/parsers/typescript/parser.js.flow +23 -27
- package/lib/parsers/utils.js +5 -0
- package/lib/parsers/utils.js.flow +6 -1
- package/package.json +8 -6
package/lib/CodegenSchema.d.ts
CHANGED
|
@@ -199,7 +199,16 @@ export type CommandParamTypeAnnotation =
|
|
|
199
199
|
| Int32TypeAnnotation
|
|
200
200
|
| DoubleTypeAnnotation
|
|
201
201
|
| FloatTypeAnnotation
|
|
202
|
-
| StringTypeAnnotation
|
|
202
|
+
| StringTypeAnnotation
|
|
203
|
+
| {
|
|
204
|
+
readonly type: 'ArrayTypeAnnotation';
|
|
205
|
+
readonly elementType:
|
|
206
|
+
| Int32TypeAnnotation
|
|
207
|
+
| DoubleTypeAnnotation
|
|
208
|
+
| FloatTypeAnnotation
|
|
209
|
+
| BooleanTypeAnnotation
|
|
210
|
+
| StringTypeAnnotation
|
|
211
|
+
};
|
|
203
212
|
|
|
204
213
|
export interface ReservedTypeAnnotation {
|
|
205
214
|
readonly type: 'ReservedTypeAnnotation';
|
|
@@ -213,7 +213,8 @@ export type CommandParamTypeAnnotation =
|
|
|
213
213
|
| Int32TypeAnnotation
|
|
214
214
|
| DoubleTypeAnnotation
|
|
215
215
|
| FloatTypeAnnotation
|
|
216
|
-
| StringTypeAnnotation
|
|
216
|
+
| StringTypeAnnotation
|
|
217
|
+
| ArrayTypeAnnotation;
|
|
217
218
|
|
|
218
219
|
export type ReservedTypeAnnotation = $ReadOnly<{
|
|
219
220
|
type: 'ReservedTypeAnnotation',
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
const nullthrows = require('nullthrows');
|
|
14
|
-
|
|
15
13
|
import type {SchemaType} from './CodegenSchema';
|
|
16
14
|
|
|
15
|
+
const nullthrows = require('nullthrows');
|
|
16
|
+
|
|
17
17
|
function getErrors(schema: SchemaType): $ReadOnlyArray<string> {
|
|
18
18
|
const errors = new Set<string>();
|
|
19
19
|
|
|
@@ -11,46 +11,65 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const allFiles = [];
|
|
26
|
-
fileList.forEach(file => {
|
|
27
|
-
if (fs.lstatSync(file).isDirectory()) {
|
|
28
|
-
const filePattern = path.sep === '\\' ? file.replace(/\\/g, '/') : file;
|
|
29
|
-
const dirFiles = glob
|
|
30
|
-
.sync(`${filePattern}/**/*.{js,ts,tsx}`, {
|
|
31
|
-
nodir: true,
|
|
32
|
-
// TODO: This will remove the need of slash substitution above for Windows,
|
|
33
|
-
// but it requires glob@v9+; with the package currenlty relying on
|
|
34
|
-
// glob@7.1.1; and flow-typed repo not having definitions for glob@9+.
|
|
35
|
-
// windowsPathsNoEscape: true,
|
|
36
|
-
})
|
|
37
|
-
.filter(element => filterJSFile(element, platform));
|
|
38
|
-
allFiles.push(...dirFiles);
|
|
39
|
-
} else if (filterJSFile(file)) {
|
|
40
|
-
allFiles.push(file);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
const combined = combine(allFiles);
|
|
44
|
-
|
|
45
|
-
// Warn users if there is no modules to process
|
|
46
|
-
if (Object.keys(combined.modules).length === 0) {
|
|
47
|
-
console.error(
|
|
48
|
-
'No modules to process in combine-js-to-schema-cli. If this is unexpected, please check if you set up your NativeComponent correctly. See combine-js-to-schema.js for how codegen finds modules.',
|
|
14
|
+
function _toArray(arr) {
|
|
15
|
+
return (
|
|
16
|
+
_arrayWithHoles(arr) ||
|
|
17
|
+
_iterableToArray(arr) ||
|
|
18
|
+
_unsupportedIterableToArray(arr) ||
|
|
19
|
+
_nonIterableRest()
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
function _nonIterableRest() {
|
|
23
|
+
throw new TypeError(
|
|
24
|
+
'Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',
|
|
49
25
|
);
|
|
50
26
|
}
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
27
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
28
|
+
if (!o) return;
|
|
29
|
+
if (typeof o === 'string') return _arrayLikeToArray(o, minLen);
|
|
30
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
31
|
+
if (n === 'Object' && o.constructor) n = o.constructor.name;
|
|
32
|
+
if (n === 'Map' || n === 'Set') return Array.from(o);
|
|
33
|
+
if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
34
|
+
return _arrayLikeToArray(o, minLen);
|
|
35
|
+
}
|
|
36
|
+
function _arrayLikeToArray(arr, len) {
|
|
37
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
38
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
39
|
+
return arr2;
|
|
40
|
+
}
|
|
41
|
+
function _iterableToArray(iter) {
|
|
42
|
+
if (
|
|
43
|
+
(typeof Symbol !== 'undefined' && iter[Symbol.iterator] != null) ||
|
|
44
|
+
iter['@@iterator'] != null
|
|
45
|
+
)
|
|
46
|
+
return Array.from(iter);
|
|
47
|
+
}
|
|
48
|
+
function _arrayWithHoles(arr) {
|
|
49
|
+
if (Array.isArray(arr)) return arr;
|
|
56
50
|
}
|
|
51
|
+
const _require = require('./combine-js-to-schema'),
|
|
52
|
+
combineSchemasInFileListAndWriteToFile =
|
|
53
|
+
_require.combineSchemasInFileListAndWriteToFile;
|
|
54
|
+
const yargs = require('yargs');
|
|
55
|
+
const argv = yargs
|
|
56
|
+
.option('p', {
|
|
57
|
+
alias: 'platform',
|
|
58
|
+
})
|
|
59
|
+
.option('e', {
|
|
60
|
+
alias: 'exclude',
|
|
61
|
+
})
|
|
62
|
+
.parseSync();
|
|
63
|
+
const _argv$_ = _toArray(argv._),
|
|
64
|
+
outfile = _argv$_[0],
|
|
65
|
+
fileList = _argv$_.slice(1);
|
|
66
|
+
const platform = argv.platform;
|
|
67
|
+
const exclude = argv.exclude;
|
|
68
|
+
const excludeRegExp =
|
|
69
|
+
exclude != null && exclude !== '' ? new RegExp(exclude) : null;
|
|
70
|
+
combineSchemasInFileListAndWriteToFile(
|
|
71
|
+
fileList,
|
|
72
|
+
platform != null ? platform.toLowerCase() : platform,
|
|
73
|
+
outfile,
|
|
74
|
+
excludeRegExp,
|
|
75
|
+
);
|
|
@@ -11,45 +11,29 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const {parseArgs, filterJSFile} = require('./combine-utils');
|
|
14
|
+
const {
|
|
15
|
+
combineSchemasInFileListAndWriteToFile,
|
|
16
|
+
} = require('./combine-js-to-schema');
|
|
17
|
+
const yargs = require('yargs');
|
|
19
18
|
|
|
20
|
-
const
|
|
19
|
+
const argv = yargs
|
|
20
|
+
.option('p', {
|
|
21
|
+
alias: 'platform',
|
|
22
|
+
})
|
|
23
|
+
.option('e', {
|
|
24
|
+
alias: 'exclude',
|
|
25
|
+
})
|
|
26
|
+
.parseSync();
|
|
21
27
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.sync(`${filePattern}/**/*.{js,ts,tsx}`, {
|
|
28
|
-
nodir: true,
|
|
29
|
-
// TODO: This will remove the need of slash substitution above for Windows,
|
|
30
|
-
// but it requires glob@v9+; with the package currenlty relying on
|
|
31
|
-
// glob@7.1.1; and flow-typed repo not having definitions for glob@9+.
|
|
32
|
-
// windowsPathsNoEscape: true,
|
|
33
|
-
})
|
|
34
|
-
.filter(element => filterJSFile(element, platform));
|
|
35
|
-
allFiles.push(...dirFiles);
|
|
36
|
-
} else if (filterJSFile(file)) {
|
|
37
|
-
allFiles.push(file);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
28
|
+
const [outfile, ...fileList] = argv._;
|
|
29
|
+
const platform: ?string = argv.platform;
|
|
30
|
+
const exclude: string = argv.exclude;
|
|
31
|
+
const excludeRegExp: ?RegExp =
|
|
32
|
+
exclude != null && exclude !== '' ? new RegExp(exclude) : null;
|
|
40
33
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
const formattedSchema = JSON.stringify(combined, null, 2);
|
|
50
|
-
|
|
51
|
-
if (outfile != null) {
|
|
52
|
-
fs.writeFileSync(outfile, formattedSchema);
|
|
53
|
-
} else {
|
|
54
|
-
console.log(formattedSchema);
|
|
55
|
-
}
|
|
34
|
+
combineSchemasInFileListAndWriteToFile(
|
|
35
|
+
fileList,
|
|
36
|
+
platform != null ? platform.toLowerCase() : platform,
|
|
37
|
+
outfile,
|
|
38
|
+
excludeRegExp,
|
|
39
|
+
);
|
|
@@ -76,7 +76,10 @@ const _require = require('../../parsers/flow/parser'),
|
|
|
76
76
|
FlowParser = _require.FlowParser;
|
|
77
77
|
const _require2 = require('../../parsers/typescript/parser'),
|
|
78
78
|
TypeScriptParser = _require2.TypeScriptParser;
|
|
79
|
+
const _require3 = require('./combine-utils'),
|
|
80
|
+
filterJSFile = _require3.filterJSFile;
|
|
79
81
|
const fs = require('fs');
|
|
82
|
+
const glob = require('glob');
|
|
80
83
|
const path = require('path');
|
|
81
84
|
const flowParser = new FlowParser();
|
|
82
85
|
const typescriptParser = new TypeScriptParser();
|
|
@@ -107,4 +110,49 @@ function combineSchemas(files) {
|
|
|
107
110
|
},
|
|
108
111
|
);
|
|
109
112
|
}
|
|
110
|
-
|
|
113
|
+
function expandDirectoriesIntoFiles(fileList, platform, exclude) {
|
|
114
|
+
return fileList
|
|
115
|
+
.flatMap(file => {
|
|
116
|
+
if (!fs.lstatSync(file).isDirectory()) {
|
|
117
|
+
return [file];
|
|
118
|
+
}
|
|
119
|
+
const filePattern = path.sep === '\\' ? file.replace(/\\/g, '/') : file;
|
|
120
|
+
return glob.sync(`${filePattern}/**/*.{js,ts,tsx}`, {
|
|
121
|
+
nodir: true,
|
|
122
|
+
// TODO: This will remove the need of slash substitution above for Windows,
|
|
123
|
+
// but it requires glob@v9+; with the package currenlty relying on
|
|
124
|
+
// glob@7.1.1; and flow-typed repo not having definitions for glob@9+.
|
|
125
|
+
// windowsPathsNoEscape: true,
|
|
126
|
+
});
|
|
127
|
+
})
|
|
128
|
+
.filter(element => filterJSFile(element, platform, exclude));
|
|
129
|
+
}
|
|
130
|
+
function combineSchemasInFileList(fileList, platform, exclude) {
|
|
131
|
+
const expandedFileList = expandDirectoriesIntoFiles(
|
|
132
|
+
fileList,
|
|
133
|
+
platform,
|
|
134
|
+
exclude,
|
|
135
|
+
);
|
|
136
|
+
const combined = combineSchemas(expandedFileList);
|
|
137
|
+
if (Object.keys(combined.modules).length === 0) {
|
|
138
|
+
console.error(
|
|
139
|
+
'No modules to process in combine-js-to-schema-cli. If this is unexpected, please check if you set up your NativeComponent correctly. See combine-js-to-schema.js for how codegen finds modules.',
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return combined;
|
|
143
|
+
}
|
|
144
|
+
function combineSchemasInFileListAndWriteToFile(
|
|
145
|
+
fileList,
|
|
146
|
+
platform,
|
|
147
|
+
outfile,
|
|
148
|
+
exclude,
|
|
149
|
+
) {
|
|
150
|
+
const combined = combineSchemasInFileList(fileList, platform, exclude);
|
|
151
|
+
const formattedSchema = JSON.stringify(combined, null, 2);
|
|
152
|
+
fs.writeFileSync(outfile, formattedSchema);
|
|
153
|
+
}
|
|
154
|
+
module.exports = {
|
|
155
|
+
combineSchemas,
|
|
156
|
+
combineSchemasInFileList,
|
|
157
|
+
combineSchemasInFileListAndWriteToFile,
|
|
158
|
+
};
|
|
@@ -13,7 +13,9 @@ import type {SchemaType} from '../../CodegenSchema.js';
|
|
|
13
13
|
|
|
14
14
|
const {FlowParser} = require('../../parsers/flow/parser');
|
|
15
15
|
const {TypeScriptParser} = require('../../parsers/typescript/parser');
|
|
16
|
+
const {filterJSFile} = require('./combine-utils');
|
|
16
17
|
const fs = require('fs');
|
|
18
|
+
const glob = require('glob');
|
|
17
19
|
const path = require('path');
|
|
18
20
|
|
|
19
21
|
const flowParser = new FlowParser();
|
|
@@ -46,4 +48,60 @@ function combineSchemas(files: Array<string>): SchemaType {
|
|
|
46
48
|
);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
function expandDirectoriesIntoFiles(
|
|
52
|
+
fileList: Array<string>,
|
|
53
|
+
platform: ?string,
|
|
54
|
+
exclude: ?RegExp,
|
|
55
|
+
): Array<string> {
|
|
56
|
+
return fileList
|
|
57
|
+
.flatMap(file => {
|
|
58
|
+
if (!fs.lstatSync(file).isDirectory()) {
|
|
59
|
+
return [file];
|
|
60
|
+
}
|
|
61
|
+
const filePattern = path.sep === '\\' ? file.replace(/\\/g, '/') : file;
|
|
62
|
+
return glob.sync(`${filePattern}/**/*.{js,ts,tsx}`, {
|
|
63
|
+
nodir: true,
|
|
64
|
+
// TODO: This will remove the need of slash substitution above for Windows,
|
|
65
|
+
// but it requires glob@v9+; with the package currenlty relying on
|
|
66
|
+
// glob@7.1.1; and flow-typed repo not having definitions for glob@9+.
|
|
67
|
+
// windowsPathsNoEscape: true,
|
|
68
|
+
});
|
|
69
|
+
})
|
|
70
|
+
.filter(element => filterJSFile(element, platform, exclude));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function combineSchemasInFileList(
|
|
74
|
+
fileList: Array<string>,
|
|
75
|
+
platform: ?string,
|
|
76
|
+
exclude: ?RegExp,
|
|
77
|
+
): SchemaType {
|
|
78
|
+
const expandedFileList = expandDirectoriesIntoFiles(
|
|
79
|
+
fileList,
|
|
80
|
+
platform,
|
|
81
|
+
exclude,
|
|
82
|
+
);
|
|
83
|
+
const combined = combineSchemas(expandedFileList);
|
|
84
|
+
if (Object.keys(combined.modules).length === 0) {
|
|
85
|
+
console.error(
|
|
86
|
+
'No modules to process in combine-js-to-schema-cli. If this is unexpected, please check if you set up your NativeComponent correctly. See combine-js-to-schema.js for how codegen finds modules.',
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return combined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function combineSchemasInFileListAndWriteToFile(
|
|
93
|
+
fileList: Array<string>,
|
|
94
|
+
platform: ?string,
|
|
95
|
+
outfile: string,
|
|
96
|
+
exclude: ?RegExp,
|
|
97
|
+
): void {
|
|
98
|
+
const combined = combineSchemasInFileList(fileList, platform, exclude);
|
|
99
|
+
const formattedSchema = JSON.stringify(combined, null, 2);
|
|
100
|
+
fs.writeFileSync(outfile, formattedSchema);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = {
|
|
104
|
+
combineSchemas,
|
|
105
|
+
combineSchemasInFileList,
|
|
106
|
+
combineSchemasInFileListAndWriteToFile,
|
|
107
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const assert = require('assert');
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const yargs = require('yargs');
|
|
16
|
+
const argv = yargs
|
|
17
|
+
.option('p', {
|
|
18
|
+
alias: 'platform',
|
|
19
|
+
type: 'string',
|
|
20
|
+
demandOption: true,
|
|
21
|
+
})
|
|
22
|
+
.option('o', {
|
|
23
|
+
alias: 'output',
|
|
24
|
+
})
|
|
25
|
+
.option('s', {
|
|
26
|
+
alias: 'schema-query',
|
|
27
|
+
})
|
|
28
|
+
.parseSync();
|
|
29
|
+
const platform = argv.platform.toLowerCase();
|
|
30
|
+
const output = argv.output;
|
|
31
|
+
const schemaQuery = argv.s;
|
|
32
|
+
if (!['ios', 'android'].includes(platform)) {
|
|
33
|
+
throw new Error(`Invalid platform ${platform}`);
|
|
34
|
+
}
|
|
35
|
+
if (!schemaQuery.startsWith('@')) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"The argument provided to --schema-query must be a filename that starts with '@'.",
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
const schemaQueryOutputFile = schemaQuery.replace(/^@/, '');
|
|
41
|
+
const schemaQueryOutput = fs.readFileSync(schemaQueryOutputFile, 'utf8');
|
|
42
|
+
const schemaFiles = schemaQueryOutput.split(' ');
|
|
43
|
+
const modules = {};
|
|
44
|
+
const specNameToFile = {};
|
|
45
|
+
for (const file of schemaFiles) {
|
|
46
|
+
const schema = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
47
|
+
if (schema.modules) {
|
|
48
|
+
for (const specName in schema.modules) {
|
|
49
|
+
const module = schema.modules[specName];
|
|
50
|
+
if (modules[specName]) {
|
|
51
|
+
assert.deepEqual(
|
|
52
|
+
module,
|
|
53
|
+
modules[specName],
|
|
54
|
+
`App contained two specs with the same file name '${specName}'. Schemas: ${specNameToFile[specName]}, ${file}. Please rename one of the specs.`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
if (
|
|
58
|
+
module.excludedPlatforms &&
|
|
59
|
+
module.excludedPlatforms.indexOf(platform) >= 0
|
|
60
|
+
) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
modules[specName] = module;
|
|
64
|
+
specNameToFile[specName] = file;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
fs.writeFileSync(
|
|
69
|
+
output,
|
|
70
|
+
JSON.stringify(
|
|
71
|
+
{
|
|
72
|
+
modules,
|
|
73
|
+
},
|
|
74
|
+
null,
|
|
75
|
+
2,
|
|
76
|
+
),
|
|
77
|
+
);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
ComponentSchema,
|
|
15
|
+
NativeModuleSchema,
|
|
16
|
+
SchemaType,
|
|
17
|
+
} from '../../CodegenSchema.js';
|
|
18
|
+
|
|
19
|
+
const assert = require('assert');
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
const yargs = require('yargs');
|
|
22
|
+
|
|
23
|
+
const argv = yargs
|
|
24
|
+
.option('p', {
|
|
25
|
+
alias: 'platform',
|
|
26
|
+
type: 'string',
|
|
27
|
+
demandOption: true,
|
|
28
|
+
})
|
|
29
|
+
.option('o', {
|
|
30
|
+
alias: 'output',
|
|
31
|
+
})
|
|
32
|
+
.option('s', {
|
|
33
|
+
alias: 'schema-query',
|
|
34
|
+
})
|
|
35
|
+
.parseSync();
|
|
36
|
+
|
|
37
|
+
const platform: string = argv.platform.toLowerCase();
|
|
38
|
+
const output: string = argv.output;
|
|
39
|
+
const schemaQuery: string = argv.s;
|
|
40
|
+
|
|
41
|
+
if (!['ios', 'android'].includes(platform)) {
|
|
42
|
+
throw new Error(`Invalid platform ${platform}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!schemaQuery.startsWith('@')) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
"The argument provided to --schema-query must be a filename that starts with '@'.",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const schemaQueryOutputFile = schemaQuery.replace(/^@/, '');
|
|
52
|
+
const schemaQueryOutput = fs.readFileSync(schemaQueryOutputFile, 'utf8');
|
|
53
|
+
|
|
54
|
+
const schemaFiles = schemaQueryOutput.split(' ');
|
|
55
|
+
const modules: {
|
|
56
|
+
[hasteModuleName: string]: NativeModuleSchema | ComponentSchema,
|
|
57
|
+
} = {};
|
|
58
|
+
const specNameToFile: {[hasteModuleName: string]: string} = {};
|
|
59
|
+
|
|
60
|
+
for (const file of schemaFiles) {
|
|
61
|
+
const schema: SchemaType = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
62
|
+
|
|
63
|
+
if (schema.modules) {
|
|
64
|
+
for (const specName in schema.modules) {
|
|
65
|
+
const module = schema.modules[specName];
|
|
66
|
+
if (modules[specName]) {
|
|
67
|
+
assert.deepEqual(
|
|
68
|
+
module,
|
|
69
|
+
modules[specName],
|
|
70
|
+
`App contained two specs with the same file name '${specName}'. Schemas: ${specNameToFile[specName]}, ${file}. Please rename one of the specs.`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (
|
|
75
|
+
module.excludedPlatforms &&
|
|
76
|
+
module.excludedPlatforms.indexOf(platform) >= 0
|
|
77
|
+
) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
modules[specName] = module;
|
|
82
|
+
specNameToFile[specName] = file;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fs.writeFileSync(output, JSON.stringify({modules}, null, 2));
|
|
@@ -11,66 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
function _toArray(arr) {
|
|
15
|
-
return (
|
|
16
|
-
_arrayWithHoles(arr) ||
|
|
17
|
-
_iterableToArray(arr) ||
|
|
18
|
-
_unsupportedIterableToArray(arr) ||
|
|
19
|
-
_nonIterableRest()
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
function _nonIterableRest() {
|
|
23
|
-
throw new TypeError(
|
|
24
|
-
'Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
28
|
-
if (!o) return;
|
|
29
|
-
if (typeof o === 'string') return _arrayLikeToArray(o, minLen);
|
|
30
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
31
|
-
if (n === 'Object' && o.constructor) n = o.constructor.name;
|
|
32
|
-
if (n === 'Map' || n === 'Set') return Array.from(o);
|
|
33
|
-
if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
34
|
-
return _arrayLikeToArray(o, minLen);
|
|
35
|
-
}
|
|
36
|
-
function _arrayLikeToArray(arr, len) {
|
|
37
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
38
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
39
|
-
return arr2;
|
|
40
|
-
}
|
|
41
|
-
function _iterableToArray(iter) {
|
|
42
|
-
if (
|
|
43
|
-
(typeof Symbol !== 'undefined' && iter[Symbol.iterator] != null) ||
|
|
44
|
-
iter['@@iterator'] != null
|
|
45
|
-
)
|
|
46
|
-
return Array.from(iter);
|
|
47
|
-
}
|
|
48
|
-
function _arrayWithHoles(arr) {
|
|
49
|
-
if (Array.isArray(arr)) return arr;
|
|
50
|
-
}
|
|
51
14
|
const path = require('path');
|
|
52
|
-
function parseArgs(args) {
|
|
53
|
-
if (args.length > 2 && ['-p', '--platform'].indexOf(args[2]) >= 0) {
|
|
54
|
-
const _args$slice = args.slice(4),
|
|
55
|
-
_args$slice2 = _toArray(_args$slice),
|
|
56
|
-
outfile = _args$slice2[0],
|
|
57
|
-
fileList = _args$slice2.slice(1);
|
|
58
|
-
return {
|
|
59
|
-
platform: args[3],
|
|
60
|
-
outfile,
|
|
61
|
-
fileList,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
const _args$slice3 = args.slice(2),
|
|
65
|
-
_args$slice4 = _toArray(_args$slice3),
|
|
66
|
-
outfile = _args$slice4[0],
|
|
67
|
-
fileList = _args$slice4.slice(1);
|
|
68
|
-
return {
|
|
69
|
-
platform: null,
|
|
70
|
-
outfile,
|
|
71
|
-
fileList,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
15
|
|
|
75
16
|
/**
|
|
76
17
|
* This function is used by the CLI to decide whether a JS/TS file has to be processed or not by the Codegen.
|
|
@@ -80,18 +21,16 @@ function parseArgs(args) {
|
|
|
80
21
|
* Returns: `true` if the file can be used to generate some code; `false` otherwise
|
|
81
22
|
*
|
|
82
23
|
*/
|
|
83
|
-
function filterJSFile(file, currentPlatform) {
|
|
24
|
+
function filterJSFile(file, currentPlatform, excludeRegExp) {
|
|
84
25
|
const isSpecFile = /^(Native.+|.+NativeComponent)/.test(path.basename(file));
|
|
85
26
|
const isNotNativeUIManager = !file.endsWith('NativeUIManager.js');
|
|
86
|
-
const isNotNativeSampleTurboModule = !file.endsWith(
|
|
87
|
-
'NativeSampleTurboModule.js',
|
|
88
|
-
);
|
|
89
27
|
const isNotTest = !file.includes('__tests');
|
|
28
|
+
const isNotExcluded = excludeRegExp == null || !excludeRegExp.test(file);
|
|
90
29
|
const isNotTSTypeDefinition = !file.endsWith('.d.ts');
|
|
91
30
|
const isValidCandidate =
|
|
92
31
|
isSpecFile &&
|
|
93
32
|
isNotNativeUIManager &&
|
|
94
|
-
|
|
33
|
+
isNotExcluded &&
|
|
95
34
|
isNotTest &&
|
|
96
35
|
isNotTSTypeDefinition;
|
|
97
36
|
const filenameComponents = path.basename(file).split('.');
|
|
@@ -113,6 +52,5 @@ function filterJSFile(file, currentPlatform) {
|
|
|
113
52
|
return isValidCandidate && currentPlatform === filePlatform;
|
|
114
53
|
}
|
|
115
54
|
module.exports = {
|
|
116
|
-
parseArgs,
|
|
117
55
|
filterJSFile,
|
|
118
56
|
};
|
|
@@ -13,28 +13,6 @@
|
|
|
13
13
|
|
|
14
14
|
const path = require('path');
|
|
15
15
|
|
|
16
|
-
function parseArgs(args: string[]): {
|
|
17
|
-
platform: ?string,
|
|
18
|
-
outfile: string,
|
|
19
|
-
fileList: string[],
|
|
20
|
-
} {
|
|
21
|
-
if (args.length > 2 && ['-p', '--platform'].indexOf(args[2]) >= 0) {
|
|
22
|
-
const [outfile, ...fileList] = args.slice(4);
|
|
23
|
-
return {
|
|
24
|
-
platform: args[3],
|
|
25
|
-
outfile,
|
|
26
|
-
fileList,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const [outfile, ...fileList] = args.slice(2);
|
|
31
|
-
return {
|
|
32
|
-
platform: null,
|
|
33
|
-
outfile,
|
|
34
|
-
fileList,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
16
|
/**
|
|
39
17
|
* This function is used by the CLI to decide whether a JS/TS file has to be processed or not by the Codegen.
|
|
40
18
|
* Parameters:
|
|
@@ -43,19 +21,21 @@ function parseArgs(args: string[]): {
|
|
|
43
21
|
* Returns: `true` if the file can be used to generate some code; `false` otherwise
|
|
44
22
|
*
|
|
45
23
|
*/
|
|
46
|
-
function filterJSFile(
|
|
24
|
+
function filterJSFile(
|
|
25
|
+
file: string,
|
|
26
|
+
currentPlatform: ?string,
|
|
27
|
+
excludeRegExp: ?RegExp,
|
|
28
|
+
): boolean {
|
|
47
29
|
const isSpecFile = /^(Native.+|.+NativeComponent)/.test(path.basename(file));
|
|
48
30
|
const isNotNativeUIManager = !file.endsWith('NativeUIManager.js');
|
|
49
|
-
const isNotNativeSampleTurboModule = !file.endsWith(
|
|
50
|
-
'NativeSampleTurboModule.js',
|
|
51
|
-
);
|
|
52
31
|
const isNotTest = !file.includes('__tests');
|
|
32
|
+
const isNotExcluded = excludeRegExp == null || !excludeRegExp.test(file);
|
|
53
33
|
const isNotTSTypeDefinition = !file.endsWith('.d.ts');
|
|
54
34
|
|
|
55
35
|
const isValidCandidate =
|
|
56
36
|
isSpecFile &&
|
|
57
37
|
isNotNativeUIManager &&
|
|
58
|
-
|
|
38
|
+
isNotExcluded &&
|
|
59
39
|
isNotTest &&
|
|
60
40
|
isNotTSTypeDefinition;
|
|
61
41
|
|
|
@@ -80,6 +60,5 @@ function filterJSFile(file: string, currentPlatform: ?string): boolean {
|
|
|
80
60
|
}
|
|
81
61
|
|
|
82
62
|
module.exports = {
|
|
83
|
-
parseArgs,
|
|
84
63
|
filterJSFile,
|
|
85
64
|
};
|
package/lib/cli/parser/parser.js
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
const path = require('path');
|
|
14
13
|
const _require = require('../../parsers/flow/parser'),
|
|
15
14
|
FlowParser = _require.FlowParser;
|
|
16
15
|
const _require2 = require('../../parsers/typescript/parser'),
|
|
17
16
|
TypeScriptParser = _require2.TypeScriptParser;
|
|
17
|
+
const path = require('path');
|
|
18
18
|
const flowParser = new FlowParser();
|
|
19
19
|
const typescriptParser = new TypeScriptParser();
|
|
20
20
|
function parseFiles(files) {
|