@react-native/codegen 0.72.1

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.
Files changed (186) hide show
  1. package/README.md +21 -0
  2. package/lib/CodegenSchema.js +11 -0
  3. package/lib/CodegenSchema.js.flow +351 -0
  4. package/lib/SchemaValidator.js +54 -0
  5. package/lib/SchemaValidator.js.flow +67 -0
  6. package/lib/cli/combine/combine-js-to-schema-cli.js +50 -0
  7. package/lib/cli/combine/combine-js-to-schema-cli.js.flow +49 -0
  8. package/lib/cli/combine/combine-js-to-schema.js +110 -0
  9. package/lib/cli/combine/combine-js-to-schema.js.flow +48 -0
  10. package/lib/cli/combine/combine-utils.js +118 -0
  11. package/lib/cli/combine/combine-utils.js.flow +85 -0
  12. package/lib/cli/generators/generate-all.js +65 -0
  13. package/lib/cli/generators/generate-all.js.flow +66 -0
  14. package/lib/cli/parser/parser-cli.js +55 -0
  15. package/lib/cli/parser/parser-cli.js.flow +18 -0
  16. package/lib/cli/parser/parser.js +35 -0
  17. package/lib/cli/parser/parser.js.flow +37 -0
  18. package/lib/cli/parser/parser.sh +15 -0
  19. package/lib/generators/RNCodegen.js +207 -0
  20. package/lib/generators/RNCodegen.js.flow +284 -0
  21. package/lib/generators/Utils.js +31 -0
  22. package/lib/generators/Utils.js.flow +33 -0
  23. package/lib/generators/__test_fixtures__/fixtures.js +79 -0
  24. package/lib/generators/__test_fixtures__/fixtures.js.flow +82 -0
  25. package/lib/generators/components/ComponentsGeneratorUtils.js +217 -0
  26. package/lib/generators/components/ComponentsGeneratorUtils.js.flow +304 -0
  27. package/lib/generators/components/CppHelpers.js +188 -0
  28. package/lib/generators/components/CppHelpers.js.flow +228 -0
  29. package/lib/generators/components/GenerateComponentDescriptorH.js +75 -0
  30. package/lib/generators/components/GenerateComponentDescriptorH.js.flow +95 -0
  31. package/lib/generators/components/GenerateComponentHObjCpp.js +327 -0
  32. package/lib/generators/components/GenerateComponentHObjCpp.js.flow +418 -0
  33. package/lib/generators/components/GenerateEventEmitterCpp.js +199 -0
  34. package/lib/generators/components/GenerateEventEmitterCpp.js.flow +273 -0
  35. package/lib/generators/components/GenerateEventEmitterH.js +224 -0
  36. package/lib/generators/components/GenerateEventEmitterH.js.flow +315 -0
  37. package/lib/generators/components/GeneratePropsCpp.js +126 -0
  38. package/lib/generators/components/GeneratePropsCpp.js.flow +161 -0
  39. package/lib/generators/components/GeneratePropsH.js +606 -0
  40. package/lib/generators/components/GeneratePropsH.js.flow +778 -0
  41. package/lib/generators/components/GeneratePropsJavaDelegate.js +287 -0
  42. package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +348 -0
  43. package/lib/generators/components/GeneratePropsJavaInterface.js +237 -0
  44. package/lib/generators/components/GeneratePropsJavaInterface.js.flow +288 -0
  45. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +157 -0
  46. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +187 -0
  47. package/lib/generators/components/GeneratePropsJavaPojo/index.js +66 -0
  48. package/lib/generators/components/GeneratePropsJavaPojo/index.js.flow +80 -0
  49. package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +273 -0
  50. package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +296 -0
  51. package/lib/generators/components/GenerateShadowNodeCpp.js +73 -0
  52. package/lib/generators/components/GenerateShadowNodeCpp.js.flow +95 -0
  53. package/lib/generators/components/GenerateShadowNodeH.js +91 -0
  54. package/lib/generators/components/GenerateShadowNodeH.js.flow +124 -0
  55. package/lib/generators/components/GenerateStateCpp.js +70 -0
  56. package/lib/generators/components/GenerateStateCpp.js.flow +92 -0
  57. package/lib/generators/components/GenerateStateH.js +93 -0
  58. package/lib/generators/components/GenerateStateH.js.flow +111 -0
  59. package/lib/generators/components/GenerateTests.js +165 -0
  60. package/lib/generators/components/GenerateTests.js.flow +219 -0
  61. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +91 -0
  62. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +107 -0
  63. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +89 -0
  64. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +105 -0
  65. package/lib/generators/components/GenerateViewConfigJs.js +410 -0
  66. package/lib/generators/components/GenerateViewConfigJs.js.flow +484 -0
  67. package/lib/generators/components/JavaHelpers.js +87 -0
  68. package/lib/generators/components/JavaHelpers.js.flow +119 -0
  69. package/lib/generators/components/__test_fixtures__/fixtures.js +1641 -0
  70. package/lib/generators/components/__test_fixtures__/fixtures.js.flow +1672 -0
  71. package/lib/generators/modules/GenerateModuleCpp.js +299 -0
  72. package/lib/generators/modules/GenerateModuleCpp.js.flow +278 -0
  73. package/lib/generators/modules/GenerateModuleH.js +373 -0
  74. package/lib/generators/modules/GenerateModuleH.js.flow +355 -0
  75. package/lib/generators/modules/GenerateModuleJavaSpec.js +571 -0
  76. package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +553 -0
  77. package/lib/generators/modules/GenerateModuleJniCpp.js +505 -0
  78. package/lib/generators/modules/GenerateModuleJniCpp.js.flow +523 -0
  79. package/lib/generators/modules/GenerateModuleJniH.js +138 -0
  80. package/lib/generators/modules/GenerateModuleJniH.js.flow +148 -0
  81. package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js +262 -0
  82. package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js.flow +208 -0
  83. package/lib/generators/modules/GenerateModuleObjCpp/Utils.js +25 -0
  84. package/lib/generators/modules/GenerateModuleObjCpp/Utils.js.flow +32 -0
  85. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +337 -0
  86. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js.flow +288 -0
  87. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +330 -0
  88. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js.flow +279 -0
  89. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js +25 -0
  90. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js.flow +35 -0
  91. package/lib/generators/modules/GenerateModuleObjCpp/index.js +185 -0
  92. package/lib/generators/modules/GenerateModuleObjCpp/index.js.flow +219 -0
  93. package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +529 -0
  94. package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +510 -0
  95. package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js +96 -0
  96. package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js.flow +121 -0
  97. package/lib/generators/modules/Utils.js +34 -0
  98. package/lib/generators/modules/Utils.js.flow +53 -0
  99. package/lib/generators/modules/__test_fixtures__/fixtures.js +1658 -0
  100. package/lib/generators/modules/__test_fixtures__/fixtures.js.flow +1669 -0
  101. package/lib/parsers/consistency/compareSnaps.js +84 -0
  102. package/lib/parsers/error-utils.js +284 -0
  103. package/lib/parsers/error-utils.js.flow +295 -0
  104. package/lib/parsers/errors.js +350 -0
  105. package/lib/parsers/errors.js.flow +439 -0
  106. package/lib/parsers/flow/components/__test_fixtures__/failures.js +583 -0
  107. package/lib/parsers/flow/components/__test_fixtures__/failures.js.flow +600 -0
  108. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +1001 -0
  109. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +1016 -0
  110. package/lib/parsers/flow/components/commands.js +104 -0
  111. package/lib/parsers/flow/components/commands.js.flow +123 -0
  112. package/lib/parsers/flow/components/componentsUtils.js +446 -0
  113. package/lib/parsers/flow/components/componentsUtils.js.flow +496 -0
  114. package/lib/parsers/flow/components/events.js +233 -0
  115. package/lib/parsers/flow/components/events.js.flow +262 -0
  116. package/lib/parsers/flow/components/extends.js +52 -0
  117. package/lib/parsers/flow/components/extends.js.flow +66 -0
  118. package/lib/parsers/flow/components/index.js +267 -0
  119. package/lib/parsers/flow/components/index.js.flow +226 -0
  120. package/lib/parsers/flow/components/options.js +72 -0
  121. package/lib/parsers/flow/components/options.js.flow +87 -0
  122. package/lib/parsers/flow/components/props.js +47 -0
  123. package/lib/parsers/flow/components/props.js.flow +60 -0
  124. package/lib/parsers/flow/components/schema.js +106 -0
  125. package/lib/parsers/flow/components/schema.js.flow +62 -0
  126. package/lib/parsers/flow/index.js +80 -0
  127. package/lib/parsers/flow/index.js.flow +85 -0
  128. package/lib/parsers/flow/modules/__test_fixtures__/failures.js +215 -0
  129. package/lib/parsers/flow/modules/__test_fixtures__/failures.js.flow +223 -0
  130. package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +724 -0
  131. package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +747 -0
  132. package/lib/parsers/flow/modules/index.js +528 -0
  133. package/lib/parsers/flow/modules/index.js.flow +420 -0
  134. package/lib/parsers/flow/parser.js +109 -0
  135. package/lib/parsers/flow/parser.js.flow +83 -0
  136. package/lib/parsers/flow/utils.js +108 -0
  137. package/lib/parsers/flow/utils.js.flow +123 -0
  138. package/lib/parsers/parser.js +11 -0
  139. package/lib/parsers/parser.js.flow +70 -0
  140. package/lib/parsers/parserMock.js +96 -0
  141. package/lib/parsers/parserMock.js.flow +68 -0
  142. package/lib/parsers/parsers-commons.js +448 -0
  143. package/lib/parsers/parsers-commons.js.flow +447 -0
  144. package/lib/parsers/parsers-primitives.js +387 -0
  145. package/lib/parsers/parsers-primitives.js.flow +383 -0
  146. package/lib/parsers/parsers-utils.js +18 -0
  147. package/lib/parsers/parsers-utils.js.flow +19 -0
  148. package/lib/parsers/schema/index.js +23 -0
  149. package/lib/parsers/schema/index.js.flow +26 -0
  150. package/lib/parsers/typescript/components/__test_fixtures__/failures.js +489 -0
  151. package/lib/parsers/typescript/components/__test_fixtures__/failures.js.flow +505 -0
  152. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +1151 -0
  153. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +1168 -0
  154. package/lib/parsers/typescript/components/commands.js +132 -0
  155. package/lib/parsers/typescript/components/commands.js.flow +151 -0
  156. package/lib/parsers/typescript/components/componentsUtils.js +471 -0
  157. package/lib/parsers/typescript/components/componentsUtils.js.flow +521 -0
  158. package/lib/parsers/typescript/components/events.js +240 -0
  159. package/lib/parsers/typescript/components/events.js.flow +262 -0
  160. package/lib/parsers/typescript/components/extends.js +88 -0
  161. package/lib/parsers/typescript/components/extends.js.flow +103 -0
  162. package/lib/parsers/typescript/components/index.js +277 -0
  163. package/lib/parsers/typescript/components/index.js.flow +239 -0
  164. package/lib/parsers/typescript/components/options.js +72 -0
  165. package/lib/parsers/typescript/components/options.js.flow +87 -0
  166. package/lib/parsers/typescript/components/props.js +39 -0
  167. package/lib/parsers/typescript/components/props.js.flow +48 -0
  168. package/lib/parsers/typescript/components/schema.js +106 -0
  169. package/lib/parsers/typescript/components/schema.js.flow +62 -0
  170. package/lib/parsers/typescript/index.js +85 -0
  171. package/lib/parsers/typescript/index.js.flow +94 -0
  172. package/lib/parsers/typescript/modules/__test_fixtures__/failures.js +160 -0
  173. package/lib/parsers/typescript/modules/__test_fixtures__/failures.js.flow +167 -0
  174. package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js +701 -0
  175. package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js.flow +727 -0
  176. package/lib/parsers/typescript/modules/index.js +543 -0
  177. package/lib/parsers/typescript/modules/index.js.flow +435 -0
  178. package/lib/parsers/typescript/parseTopLevelType.js +203 -0
  179. package/lib/parsers/typescript/parseTopLevelType.js.flow +243 -0
  180. package/lib/parsers/typescript/parser.js +105 -0
  181. package/lib/parsers/typescript/parser.js.flow +87 -0
  182. package/lib/parsers/typescript/utils.js +101 -0
  183. package/lib/parsers/typescript/utils.js.flow +115 -0
  184. package/lib/parsers/utils.js +273 -0
  185. package/lib/parsers/utils.js.flow +266 -0
  186. package/package.json +45 -0
@@ -0,0 +1,110 @@
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
+ function ownKeys(object, enumerableOnly) {
14
+ var keys = Object.keys(object);
15
+ if (Object.getOwnPropertySymbols) {
16
+ var symbols = Object.getOwnPropertySymbols(object);
17
+ enumerableOnly &&
18
+ (symbols = symbols.filter(function (sym) {
19
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
20
+ })),
21
+ keys.push.apply(keys, symbols);
22
+ }
23
+ return keys;
24
+ }
25
+ function _objectSpread(target) {
26
+ for (var i = 1; i < arguments.length; i++) {
27
+ var source = null != arguments[i] ? arguments[i] : {};
28
+ i % 2
29
+ ? ownKeys(Object(source), !0).forEach(function (key) {
30
+ _defineProperty(target, key, source[key]);
31
+ })
32
+ : Object.getOwnPropertyDescriptors
33
+ ? Object.defineProperties(
34
+ target,
35
+ Object.getOwnPropertyDescriptors(source),
36
+ )
37
+ : ownKeys(Object(source)).forEach(function (key) {
38
+ Object.defineProperty(
39
+ target,
40
+ key,
41
+ Object.getOwnPropertyDescriptor(source, key),
42
+ );
43
+ });
44
+ }
45
+ return target;
46
+ }
47
+ function _defineProperty(obj, key, value) {
48
+ key = _toPropertyKey(key);
49
+ if (key in obj) {
50
+ Object.defineProperty(obj, key, {
51
+ value: value,
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ });
56
+ } else {
57
+ obj[key] = value;
58
+ }
59
+ return obj;
60
+ }
61
+ function _toPropertyKey(arg) {
62
+ var key = _toPrimitive(arg, 'string');
63
+ return typeof key === 'symbol' ? key : String(key);
64
+ }
65
+ function _toPrimitive(input, hint) {
66
+ if (typeof input !== 'object' || input === null) return input;
67
+ var prim = input[Symbol.toPrimitive];
68
+ if (prim !== undefined) {
69
+ var res = prim.call(input, hint || 'default');
70
+ if (typeof res !== 'object') return res;
71
+ throw new TypeError('@@toPrimitive must return a primitive value.');
72
+ }
73
+ return (hint === 'string' ? String : Number)(input);
74
+ }
75
+ const _require = require('../../parsers/utils'),
76
+ parseFile = _require.parseFile;
77
+ const FlowParser = require('../../parsers/flow');
78
+ const TypeScriptParser = require('../../parsers/typescript');
79
+ const fs = require('fs');
80
+ const path = require('path');
81
+ function combineSchemas(files) {
82
+ return files.reduce(
83
+ (merged, filename) => {
84
+ const contents = fs.readFileSync(filename, 'utf8');
85
+ if (
86
+ contents &&
87
+ (/export\s+default\s+\(?codegenNativeComponent</.test(contents) ||
88
+ /extends TurboModule/.test(contents))
89
+ ) {
90
+ const isTypeScript =
91
+ path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
92
+ const schema = parseFile(
93
+ filename,
94
+ isTypeScript ? TypeScriptParser.buildSchema : FlowParser.buildSchema,
95
+ );
96
+ if (schema && schema.modules) {
97
+ merged.modules = _objectSpread(
98
+ _objectSpread({}, merged.modules),
99
+ schema.modules,
100
+ );
101
+ }
102
+ }
103
+ return merged;
104
+ },
105
+ {
106
+ modules: {},
107
+ },
108
+ );
109
+ }
110
+ module.exports = combineSchemas;
@@ -0,0 +1,48 @@
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
+ import type {SchemaType} from '../../CodegenSchema.js';
13
+
14
+ const {parseFile} = require('../../parsers/utils');
15
+ const FlowParser = require('../../parsers/flow');
16
+ const TypeScriptParser = require('../../parsers/typescript');
17
+ const fs = require('fs');
18
+ const path = require('path');
19
+
20
+ function combineSchemas(files: Array<string>): SchemaType {
21
+ return files.reduce(
22
+ (merged, filename) => {
23
+ const contents = fs.readFileSync(filename, 'utf8');
24
+
25
+ if (
26
+ contents &&
27
+ (/export\s+default\s+\(?codegenNativeComponent</.test(contents) ||
28
+ /extends TurboModule/.test(contents))
29
+ ) {
30
+ const isTypeScript =
31
+ path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
32
+
33
+ const schema = parseFile(
34
+ filename,
35
+ isTypeScript ? TypeScriptParser.buildSchema : FlowParser.buildSchema,
36
+ );
37
+
38
+ if (schema && schema.modules) {
39
+ merged.modules = {...merged.modules, ...schema.modules};
40
+ }
41
+ }
42
+ return merged;
43
+ },
44
+ {modules: {}},
45
+ );
46
+ }
47
+
48
+ module.exports = combineSchemas;
@@ -0,0 +1,118 @@
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
+ * @oncall react_native
10
+ */
11
+
12
+ 'use strict';
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
+ 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
+
75
+ /**
76
+ * This function is used by the CLI to decide whether a JS/TS file has to be processed or not by the Codegen.
77
+ * Parameters:
78
+ * - file: the path to the file
79
+ * - currentPlatform: the current platform for which we are creating the specs
80
+ * Returns: `true` if the file can be used to generate some code; `false` otherwise
81
+ *
82
+ */
83
+ function filterJSFile(file, currentPlatform) {
84
+ const isSpecFile = /^(Native.+|.+NativeComponent)/.test(path.basename(file));
85
+ const isNotNativeUIManager = !file.endsWith('NativeUIManager.js');
86
+ const isNotNativeSampleTurboModule = !file.endsWith(
87
+ 'NativeSampleTurboModule.js',
88
+ );
89
+ const isNotTest = !file.includes('__tests');
90
+ const isNotTSTypeDefinition = !file.endsWith('.d.ts');
91
+ const isValidCandidate =
92
+ isSpecFile &&
93
+ isNotNativeUIManager &&
94
+ isNotNativeSampleTurboModule &&
95
+ isNotTest &&
96
+ isNotTSTypeDefinition;
97
+ const filenameComponents = path.basename(file).split('.');
98
+ const isPlatformAgnostic = filenameComponents.length === 2;
99
+ if (currentPlatform == null) {
100
+ // need to accept only files that are platform agnostic
101
+ return isValidCandidate && isPlatformAgnostic;
102
+ }
103
+
104
+ // If a platform is passed, accept both platform agnostic specs...
105
+ if (isPlatformAgnostic) {
106
+ return isValidCandidate;
107
+ }
108
+
109
+ // ...and specs that share the same platform as the one passed.
110
+ // specfiles must follow the pattern: <filename>[.<platform>].(js|ts|tsx)
111
+ const filePlatform =
112
+ filenameComponents.length > 2 ? filenameComponents[1] : 'unknown';
113
+ return isValidCandidate && currentPlatform === filePlatform;
114
+ }
115
+ module.exports = {
116
+ parseArgs,
117
+ filterJSFile,
118
+ };
@@ -0,0 +1,85 @@
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
+ * @oncall react_native
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ const path = require('path');
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
+ /**
39
+ * This function is used by the CLI to decide whether a JS/TS file has to be processed or not by the Codegen.
40
+ * Parameters:
41
+ * - file: the path to the file
42
+ * - currentPlatform: the current platform for which we are creating the specs
43
+ * Returns: `true` if the file can be used to generate some code; `false` otherwise
44
+ *
45
+ */
46
+ function filterJSFile(file: string, currentPlatform: ?string): boolean {
47
+ const isSpecFile = /^(Native.+|.+NativeComponent)/.test(path.basename(file));
48
+ const isNotNativeUIManager = !file.endsWith('NativeUIManager.js');
49
+ const isNotNativeSampleTurboModule = !file.endsWith(
50
+ 'NativeSampleTurboModule.js',
51
+ );
52
+ const isNotTest = !file.includes('__tests');
53
+ const isNotTSTypeDefinition = !file.endsWith('.d.ts');
54
+
55
+ const isValidCandidate =
56
+ isSpecFile &&
57
+ isNotNativeUIManager &&
58
+ isNotNativeSampleTurboModule &&
59
+ isNotTest &&
60
+ isNotTSTypeDefinition;
61
+
62
+ const filenameComponents = path.basename(file).split('.');
63
+ const isPlatformAgnostic = filenameComponents.length === 2;
64
+
65
+ if (currentPlatform == null) {
66
+ // need to accept only files that are platform agnostic
67
+ return isValidCandidate && isPlatformAgnostic;
68
+ }
69
+
70
+ // If a platform is passed, accept both platform agnostic specs...
71
+ if (isPlatformAgnostic) {
72
+ return isValidCandidate;
73
+ }
74
+
75
+ // ...and specs that share the same platform as the one passed.
76
+ // specfiles must follow the pattern: <filename>[.<platform>].(js|ts|tsx)
77
+ const filePlatform =
78
+ filenameComponents.length > 2 ? filenameComponents[1] : 'unknown';
79
+ return isValidCandidate && currentPlatform === filePlatform;
80
+ }
81
+
82
+ module.exports = {
83
+ parseArgs,
84
+ filterJSFile,
85
+ };
@@ -0,0 +1,65 @@
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
+ /**
12
+ * This generates all possible outputs by executing all available generators.
13
+ */
14
+
15
+ 'use strict';
16
+
17
+ const RNCodegen = require('../../generators/RNCodegen.js');
18
+ const fs = require('fs');
19
+ const mkdirp = require('mkdirp');
20
+ const args = process.argv.slice(2);
21
+ if (args.length < 3) {
22
+ throw new Error(
23
+ `Expected to receive path to schema, library name, output directory and module spec name. Received ${args.join(
24
+ ', ',
25
+ )}`,
26
+ );
27
+ }
28
+ const schemaPath = args[0];
29
+ const libraryName = args[1];
30
+ const outputDirectory = args[2];
31
+ const packageName = args[3];
32
+ const assumeNonnull = args[4] === 'true' || args[4] === 'True';
33
+ const schemaText = fs.readFileSync(schemaPath, 'utf-8');
34
+ if (schemaText == null) {
35
+ throw new Error(`Can't find schema at ${schemaPath}`);
36
+ }
37
+ mkdirp.sync(outputDirectory);
38
+ let schema;
39
+ try {
40
+ schema = JSON.parse(schemaText);
41
+ } catch (err) {
42
+ throw new Error(`Can't parse schema to JSON. ${schemaPath}`);
43
+ }
44
+ RNCodegen.generate(
45
+ {
46
+ libraryName,
47
+ schema,
48
+ outputDirectory,
49
+ packageName,
50
+ assumeNonnull,
51
+ },
52
+ {
53
+ generators: [
54
+ 'descriptors',
55
+ 'events',
56
+ 'props',
57
+ 'states',
58
+ 'tests',
59
+ 'shadow-nodes',
60
+ 'modulesAndroid',
61
+ 'modulesCxx',
62
+ 'modulesIOS',
63
+ ],
64
+ },
65
+ );
@@ -0,0 +1,66 @@
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
8
+ * @format
9
+ */
10
+
11
+ /**
12
+ * This generates all possible outputs by executing all available generators.
13
+ */
14
+
15
+ 'use strict';
16
+
17
+ const RNCodegen = require('../../generators/RNCodegen.js');
18
+ const fs = require('fs');
19
+ const mkdirp = require('mkdirp');
20
+
21
+ const args = process.argv.slice(2);
22
+ if (args.length < 3) {
23
+ throw new Error(
24
+ `Expected to receive path to schema, library name, output directory and module spec name. Received ${args.join(
25
+ ', ',
26
+ )}`,
27
+ );
28
+ }
29
+
30
+ const schemaPath = args[0];
31
+ const libraryName = args[1];
32
+ const outputDirectory = args[2];
33
+ const packageName = args[3];
34
+ const assumeNonnull = args[4] === 'true' || args[4] === 'True';
35
+
36
+ const schemaText = fs.readFileSync(schemaPath, 'utf-8');
37
+
38
+ if (schemaText == null) {
39
+ throw new Error(`Can't find schema at ${schemaPath}`);
40
+ }
41
+
42
+ mkdirp.sync(outputDirectory);
43
+
44
+ let schema;
45
+ try {
46
+ schema = JSON.parse(schemaText);
47
+ } catch (err) {
48
+ throw new Error(`Can't parse schema to JSON. ${schemaPath}`);
49
+ }
50
+
51
+ RNCodegen.generate(
52
+ {libraryName, schema, outputDirectory, packageName, assumeNonnull},
53
+ {
54
+ generators: [
55
+ 'descriptors',
56
+ 'events',
57
+ 'props',
58
+ 'states',
59
+ 'tests',
60
+ 'shadow-nodes',
61
+ 'modulesAndroid',
62
+ 'modulesCxx',
63
+ 'modulesIOS',
64
+ ],
65
+ },
66
+ );
@@ -0,0 +1,55 @@
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
+ * @oncall react_native
10
+ */
11
+
12
+ 'use strict';
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
+ const parseFiles = require('./parser.js');
52
+ const _process$argv$slice = process.argv.slice(2),
53
+ _process$argv$slice2 = _toArray(_process$argv$slice),
54
+ fileList = _process$argv$slice2.slice(0);
55
+ parseFiles(fileList);
@@ -0,0 +1,18 @@
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
+ * @oncall react_native
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ const parseFiles = require('./parser.js');
15
+
16
+ const [...fileList] = process.argv.slice(2);
17
+
18
+ parseFiles(fileList);
@@ -0,0 +1,35 @@
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 path = require('path');
14
+ const _require = require('../../parsers/utils'),
15
+ parseFile = _require.parseFile;
16
+ const FlowParser = require('../../parsers/flow');
17
+ const TypeScriptParser = require('../../parsers/typescript');
18
+ function parseFiles(files) {
19
+ files.forEach(filename => {
20
+ const isTypeScript =
21
+ path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
22
+ console.log(
23
+ filename,
24
+ JSON.stringify(
25
+ parseFile(
26
+ filename,
27
+ isTypeScript ? TypeScriptParser.buildSchema : FlowParser.buildSchema,
28
+ ),
29
+ null,
30
+ 2,
31
+ ),
32
+ );
33
+ });
34
+ }
35
+ module.exports = parseFiles;
@@ -0,0 +1,37 @@
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
+ const path = require('path');
14
+ const {parseFile} = require('../../parsers/utils');
15
+ const FlowParser = require('../../parsers/flow');
16
+ const TypeScriptParser = require('../../parsers/typescript');
17
+
18
+ function parseFiles(files: Array<string>) {
19
+ files.forEach(filename => {
20
+ const isTypeScript =
21
+ path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
22
+
23
+ console.log(
24
+ filename,
25
+ JSON.stringify(
26
+ parseFile(
27
+ filename,
28
+ isTypeScript ? TypeScriptParser.buildSchema : FlowParser.buildSchema,
29
+ ),
30
+ null,
31
+ 2,
32
+ ),
33
+ );
34
+ });
35
+ }
36
+
37
+ module.exports = parseFiles;
@@ -0,0 +1,15 @@
1
+ #!/bin/bash
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
+ set -e
8
+ set -u
9
+
10
+ THIS_DIR=$(cd -P "$(dirname "$(realpath "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
11
+
12
+ # shellcheck source=xplat/js/env-utils/setup_env_vars.sh
13
+ source "$THIS_DIR/../../../../../../env-utils/setup_env_vars.sh"
14
+
15
+ exec "$FLOW_NODE_BINARY" "$THIS_DIR/parser.js" "$@"