@react-native-oh/react-native-harmony-cli 0.0.40 → 0.0.42
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/README.md +11 -11
- package/dist/assetResolver.js +74 -77
- package/dist/autolinking/Autolinking.js +179 -179
- package/dist/autolinking/JSON5Writer.js +61 -0
- package/dist/codegen/core/CodegenError.js +3 -23
- package/dist/codegen/core/EventUtils.js +3 -3
- package/dist/codegen/core/TypeAnnotationToTS.js +24 -28
- package/dist/codegen/core/UberSchema.js +57 -96
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +28 -41
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +27 -34
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +25 -33
- package/dist/codegen/generators/CppComponentCodeGenerator.js +23 -28
- package/dist/codegen/generators/LibGlueCodeGenerator.js +26 -29
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +25 -30
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
- package/dist/codegen/generators/UberGeneratorV1.js +24 -23
- package/dist/codegen/generators/UberGeneratorV2.js +34 -35
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +50 -24
- package/dist/codegen/templates/BasePackageHTemplate.js +120 -21
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +53 -8
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +75 -27
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +162 -29
- package/dist/codegen/templates/IndexTSTemplate.js +37 -17
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +119 -24
- package/dist/codegen/templates/TurboModuleCppTemplate.js +38 -15
- package/dist/codegen/templates/TurboModuleHTemplate.js +32 -11
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +52 -19
- package/dist/commands/bundle-harmony.js +65 -138
- package/dist/commands/codegen-harmony.js +105 -165
- package/dist/commands/codegen-lib-harmony.js +76 -116
- package/dist/commands/create-metro-host-constants.js +18 -47
- package/dist/commands/init.js +537 -961
- package/dist/commands/link-harmony.js +33 -71
- package/dist/commands/pack-harmony.js +47 -108
- package/dist/commands/run-harmony.js +372 -518
- package/dist/commands/unpack-harmony.js +105 -198
- package/dist/commands/verify-package-harmony.js +54 -108
- package/dist/core/AbsolutePath.js +31 -47
- package/dist/core/CodegenConfig.js +24 -22
- package/dist/core/DescriptiveError.js +18 -37
- package/dist/core/FileSystem.js +14 -18
- package/dist/core/OHPackageJSON5.js +17 -23
- package/dist/core/PackageJSON.js +26 -42
- package/dist/core/ProjectDependenciesManager.js +40 -92
- package/dist/core/ValidationError.js +2 -22
- package/dist/core/fs.js +9 -6
- package/dist/index.js +1 -1
- package/dist/io/CliExecutor.js +46 -98
- package/dist/io/Logger.js +40 -46
- package/dist/io/RealFS.js +35 -88
- package/dist/io/TarGz.js +11 -8
- package/dist/io/__fixtures__.js +79 -141
- package/dist/io/fsUtils.js +13 -12
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +19 -47
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +13 -41
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +8 -38
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +22 -54
- package/dist/package-verifier/verify-package.js +55 -132
- package/dist/simulator/LaunchSimulator.js +224 -301
- package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
- package/jest.config.js +12 -12
- package/package.json +79 -78
- package/react-native.config.js +17 -17
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
|
@@ -7,64 +7,59 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.CppComponentCodeGenerator = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const templates_1 = require("../templates");
|
|
11
|
+
class CppComponentCodeGenerator {
|
|
12
|
+
constructor(onGetRNOHOutputPath, codegenNoticeLines) {
|
|
13
13
|
this.onGetRNOHOutputPath = onGetRNOHOutputPath;
|
|
14
14
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
15
15
|
this.glueCodeComponentsData = [];
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
getGlueCodeData() {
|
|
18
18
|
return this.glueCodeComponentsData;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var fileContentByPath = new Map();
|
|
24
|
-
for (var _i = 0, _b = uberSchema
|
|
19
|
+
}
|
|
20
|
+
generate({ libraryCppName, uberSchema, }) {
|
|
21
|
+
const fileContentByPath = new Map();
|
|
22
|
+
for (const [_filename, schema] of uberSchema
|
|
25
23
|
.getSpecSchemaByFilenameMap()
|
|
26
|
-
.entries()
|
|
27
|
-
var _c = _b[_i], _filename = _c[0], schema = _c[1];
|
|
24
|
+
.entries()) {
|
|
28
25
|
if (schema.type === 'Component') {
|
|
29
|
-
Object.entries(schema.components).map(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
shape.props.forEach(function (prop) {
|
|
26
|
+
Object.entries(schema.components).map(([componentName, shape]) => {
|
|
27
|
+
const componentJSIBinderHTemplate = new templates_1.ComponentJSIBinderHTemplate(componentName, this.codegenNoticeLines);
|
|
28
|
+
const componentInstanceSpecHTemplate = new templates_1.BaseComponentInstanceHTemplate(componentName, libraryCppName, this.codegenNoticeLines);
|
|
29
|
+
shape.props.forEach((prop) => {
|
|
34
30
|
componentJSIBinderHTemplate.addProp({
|
|
35
31
|
name: prop.name,
|
|
36
32
|
isObject: prop.typeAnnotation.type === 'ObjectTypeAnnotation',
|
|
37
33
|
});
|
|
38
34
|
});
|
|
39
|
-
shape.events.forEach(
|
|
35
|
+
shape.events.forEach((event) => {
|
|
40
36
|
componentJSIBinderHTemplate.addEvent({
|
|
41
37
|
type: event.bubblingType,
|
|
42
38
|
eventHandlerName: event.name,
|
|
43
39
|
});
|
|
44
40
|
});
|
|
45
|
-
shape.commands.forEach(
|
|
41
|
+
shape.commands.forEach((command) => {
|
|
46
42
|
componentJSIBinderHTemplate.addCommand({
|
|
47
43
|
name: command.name,
|
|
48
44
|
});
|
|
49
45
|
componentInstanceSpecHTemplate.addCommand({
|
|
50
46
|
name: command.name,
|
|
51
|
-
args: command.typeAnnotation.params.map(
|
|
47
|
+
args: command.typeAnnotation.params.map((param) => ({
|
|
52
48
|
name: param.name,
|
|
53
49
|
typeAnnotation: param.typeAnnotation,
|
|
54
|
-
})
|
|
50
|
+
})),
|
|
55
51
|
});
|
|
56
52
|
});
|
|
57
|
-
fileContentByPath.set(
|
|
58
|
-
fileContentByPath.set(
|
|
59
|
-
|
|
53
|
+
fileContentByPath.set(this.onGetRNOHOutputPath(`${componentName}JSIBinder.h`), componentJSIBinderHTemplate.build());
|
|
54
|
+
fileContentByPath.set(this.onGetRNOHOutputPath(`Base${componentName}ComponentInstance.h`), componentInstanceSpecHTemplate.build());
|
|
55
|
+
this.glueCodeComponentsData.push({
|
|
60
56
|
name: componentName,
|
|
61
|
-
libraryCppName
|
|
57
|
+
libraryCppName,
|
|
62
58
|
});
|
|
63
59
|
});
|
|
64
60
|
}
|
|
65
61
|
}
|
|
66
62
|
return fileContentByPath;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
70
65
|
exports.CppComponentCodeGenerator = CppComponentCodeGenerator;
|
|
@@ -5,45 +5,43 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.LibGlueCodeGenerator = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const case_1 = __importDefault(require("case"));
|
|
14
|
+
const BasePackageHTemplate_1 = require("../templates/BasePackageHTemplate");
|
|
15
|
+
const templates_1 = require("../templates");
|
|
13
16
|
/**
|
|
14
17
|
* NOTE: This class is coupled with the generated code structure defined in the codegen-harmony-lib.
|
|
15
18
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
class LibGlueCodeGenerator {
|
|
20
|
+
constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
|
|
18
21
|
this.cppOutputPath = cppOutputPath;
|
|
19
22
|
this.etsOutputPath = etsOutputPath;
|
|
20
23
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
21
24
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
turboModules.forEach(function (turboModule) {
|
|
25
|
+
generate({ libraryCppName, turboModules, arkTSComponents, cppComponents, }) {
|
|
26
|
+
const fileContentByPath = new Map();
|
|
27
|
+
const basePackageClassName = `Base${case_1.default.pascal(libraryCppName)}Package`;
|
|
28
|
+
const turboModules_indexTS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
|
|
29
|
+
const components_indexTS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
|
|
30
|
+
const generated_indexETS = new templates_1.IndexTSTemplate(this.codegenNoticeLines);
|
|
31
|
+
const basePackageTemplate = new BasePackageHTemplate_1.BasePackageHTemplate(basePackageClassName, this.codegenNoticeLines);
|
|
32
|
+
turboModules.forEach((turboModule) => {
|
|
31
33
|
basePackageTemplate.addTurboModule(turboModule);
|
|
32
|
-
turboModules_indexTS.addReexport({ from:
|
|
34
|
+
turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
|
|
33
35
|
});
|
|
34
|
-
arkTSComponents.forEach(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
basePackageTemplate.
|
|
38
|
-
eventNames.forEach(function (eventName) {
|
|
39
|
-
return basePackageTemplate.addArkTSEvent({ name: eventName });
|
|
40
|
-
});
|
|
36
|
+
arkTSComponents.forEach(({ componentName, eventNames }) => {
|
|
37
|
+
components_indexTS.addReexport({ from: `./${componentName}` });
|
|
38
|
+
basePackageTemplate.addComponent({ name: componentName, libraryCppName, isArkTSComponent: true });
|
|
39
|
+
eventNames.forEach((eventName) => basePackageTemplate.addArkTSEvent({ name: eventName }));
|
|
41
40
|
});
|
|
42
|
-
cppComponents.forEach(
|
|
43
|
-
|
|
44
|
-
basePackageTemplate.addComponent({ name: componentName, libraryCppName: libraryCppName, isArkTSComponent: false });
|
|
41
|
+
cppComponents.forEach(({ componentName }) => {
|
|
42
|
+
basePackageTemplate.addComponent({ name: componentName, libraryCppName, isArkTSComponent: false });
|
|
45
43
|
});
|
|
46
|
-
fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOH', 'generated',
|
|
44
|
+
fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOH', 'generated', `${basePackageClassName}.h`), basePackageTemplate.build());
|
|
47
45
|
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'), components_indexTS.build());
|
|
48
46
|
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'), turboModules_indexTS.build());
|
|
49
47
|
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('ts.ts'), new templates_1.IndexTSTemplate(this.codegenNoticeLines)
|
|
@@ -53,7 +51,6 @@ var LibGlueCodeGenerator = /** @class */ (function () {
|
|
|
53
51
|
generated_indexETS.addReexport({ from: './ts' });
|
|
54
52
|
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('index.ets'), generated_indexETS.build());
|
|
55
53
|
return fileContentByPath;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
59
56
|
exports.LibGlueCodeGenerator = LibGlueCodeGenerator;
|
|
@@ -7,55 +7,53 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.NativeModuleCodeGenerator = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const templates_1 = require("../templates");
|
|
11
|
+
const core_1 = require("../core");
|
|
12
12
|
/**
|
|
13
13
|
* Generates boilerplate code for Turbo Modules.
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
class NativeModuleCodeGenerator {
|
|
16
|
+
constructor(cppOutputPath, etsOutputPath, codegenNoticeLines, rnohImport) {
|
|
17
17
|
this.cppOutputPath = cppOutputPath;
|
|
18
18
|
this.etsOutputPath = etsOutputPath;
|
|
19
19
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
20
20
|
this.rnohImport = rnohImport;
|
|
21
21
|
this.glueCodeTurboModulesData = [];
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
getGlueCodeData() {
|
|
24
24
|
return this.glueCodeTurboModulesData;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
}
|
|
26
|
+
generate(schema) {
|
|
27
|
+
const result = new Map();
|
|
28
28
|
if (schema.type !== 'NativeModule') {
|
|
29
29
|
throw new core_1.CodegenError({
|
|
30
|
-
whatHappened:
|
|
30
|
+
whatHappened: `NativeModuleCodeGenerator can't generate code for module type: ${schema.type}`,
|
|
31
31
|
unexpected: true,
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
result.set(this.cppOutputPath.copyWithNewSegment(
|
|
38
|
-
|
|
39
|
-
Object.entries(schema.aliasMap).map(
|
|
40
|
-
var name = _a[0], typeAnnotation = _a[1];
|
|
34
|
+
const typeAnnotationToTS = new core_1.TypeAnnotationToTS();
|
|
35
|
+
const turboModuleInterfaceTS = new templates_1.TurboModuleInterfaceTS(schema.moduleName, this.codegenNoticeLines, this.rnohImport);
|
|
36
|
+
const turboModuleH = new templates_1.TurboModuleHTemplate(schema.moduleName, this.codegenNoticeLines).build();
|
|
37
|
+
result.set(this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.h`), turboModuleH);
|
|
38
|
+
const turboModuleCpp = new templates_1.TurboModuleCppTemplate(schema.moduleName, this.codegenNoticeLines);
|
|
39
|
+
Object.entries(schema.aliasMap).map(([name, typeAnnotation]) => {
|
|
41
40
|
turboModuleInterfaceTS.addAlias({
|
|
42
41
|
name: name,
|
|
43
42
|
type: typeAnnotationToTS.convert(typeAnnotation),
|
|
44
43
|
});
|
|
45
44
|
});
|
|
46
|
-
Object.entries(schema.enumMap).map(
|
|
47
|
-
var name = _a[0], enumSpec = _a[1];
|
|
45
|
+
Object.entries(schema.enumMap).map(([name, enumSpec]) => {
|
|
48
46
|
turboModuleInterfaceTS.addEnum({
|
|
49
|
-
name
|
|
50
|
-
members: enumSpec.members.map(
|
|
47
|
+
name,
|
|
48
|
+
members: enumSpec.members.map((member) => ({
|
|
51
49
|
name: member.name,
|
|
52
50
|
value: typeof member.value === 'string'
|
|
53
51
|
? (0, core_1.wrapWithQuotes)(member.value)
|
|
54
52
|
: member.value.toString(),
|
|
55
|
-
})
|
|
53
|
+
})),
|
|
56
54
|
});
|
|
57
55
|
});
|
|
58
|
-
schema.spec.properties.map(
|
|
56
|
+
schema.spec.properties.map((prop) => {
|
|
59
57
|
if (prop.typeAnnotation.type === 'FunctionTypeAnnotation') {
|
|
60
58
|
turboModuleCpp.addMethod({
|
|
61
59
|
name: prop.name,
|
|
@@ -67,18 +65,15 @@ var NativeModuleCodeGenerator = /** @class */ (function () {
|
|
|
67
65
|
name: prop.name,
|
|
68
66
|
returnType: typeAnnotationToTS.convert(prop.typeAnnotation.returnTypeAnnotation),
|
|
69
67
|
stringifiedArgs: prop.typeAnnotation.params
|
|
70
|
-
.map(
|
|
71
|
-
return "".concat(param.name, ": ").concat(typeAnnotationToTS.convert(param.typeAnnotation));
|
|
72
|
-
})
|
|
68
|
+
.map((param) => `${param.name}: ${typeAnnotationToTS.convert(param.typeAnnotation)}`)
|
|
73
69
|
.join(', '),
|
|
74
70
|
});
|
|
75
71
|
}
|
|
76
72
|
});
|
|
77
|
-
result.set(this.cppOutputPath.copyWithNewSegment(
|
|
78
|
-
result.set(this.etsOutputPath.copyWithNewSegment(
|
|
73
|
+
result.set(this.cppOutputPath.copyWithNewSegment(`${schema.moduleName}.cpp`), turboModuleCpp.build());
|
|
74
|
+
result.set(this.etsOutputPath.copyWithNewSegment(`${schema.moduleName}.ts`), turboModuleInterfaceTS.build());
|
|
79
75
|
this.glueCodeTurboModulesData.push({ name: schema.moduleName });
|
|
80
76
|
return result;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
}());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
84
79
|
exports.NativeModuleCodeGenerator = NativeModuleCodeGenerator;
|
|
@@ -5,18 +5,19 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.SharedComponentCodeGenerator = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const RNCodegen_1 = __importDefault(require("@react-native/codegen/lib/generators/RNCodegen"));
|
|
14
|
+
class SharedComponentCodeGenerator {
|
|
15
|
+
constructor(onGetSharedOutputPath) {
|
|
13
16
|
this.onGetSharedOutputPath = onGetSharedOutputPath;
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var fileContentByPath = new Map();
|
|
19
|
-
var generatorFns = [
|
|
18
|
+
generate({ libraryCppName, uberSchema, }) {
|
|
19
|
+
const fileContentByPath = new Map();
|
|
20
|
+
const generatorFns = [
|
|
20
21
|
RNCodegen_1.default.allGenerators.generatePropsH,
|
|
21
22
|
RNCodegen_1.default.allGenerators.generatePropsCpp,
|
|
22
23
|
RNCodegen_1.default.allGenerators.generateEventEmitterH,
|
|
@@ -27,14 +28,13 @@ var SharedComponentCodeGenerator = /** @class */ (function () {
|
|
|
27
28
|
RNCodegen_1.default.allGenerators.generateShadowNodeH,
|
|
28
29
|
RNCodegen_1.default.allGenerators.generateShadowNodeCpp,
|
|
29
30
|
];
|
|
30
|
-
generatorFns.forEach(
|
|
31
|
-
|
|
32
|
-
filesOutput.forEach(
|
|
33
|
-
fileContentByPath.set(
|
|
31
|
+
generatorFns.forEach((generate) => {
|
|
32
|
+
const filesOutput = generate(libraryCppName, uberSchema.getValue(), 'UNUSED_packageName', true);
|
|
33
|
+
filesOutput.forEach((fileContent, filename) => {
|
|
34
|
+
fileContentByPath.set(this.onGetSharedOutputPath(filename), fileContent);
|
|
34
35
|
});
|
|
35
36
|
});
|
|
36
37
|
return fileContentByPath;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
40
|
exports.SharedComponentCodeGenerator = SharedComponentCodeGenerator;
|
|
@@ -5,49 +5,51 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.UberGeneratorV1 = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const core_1 = require("../core");
|
|
15
|
+
const NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
|
|
16
|
+
const ArkTSComponentCodeGeneratorArkTS_1 = require("./ArkTSComponentCodeGeneratorArkTS");
|
|
14
17
|
// The name of rnoh OHOS module
|
|
15
|
-
|
|
18
|
+
const RNOH_OHOS_NAME = '@rnoh/react-native-openharmony';
|
|
16
19
|
/**
|
|
17
20
|
* Generates code for libraries built on top of RNOH's ArkTS architecture.
|
|
18
21
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
class UberGeneratorV1 {
|
|
23
|
+
constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
|
|
21
24
|
this.cppOutputPath = cppOutputPath;
|
|
22
25
|
this.etsOutputPath = etsOutputPath;
|
|
23
26
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
24
27
|
this.glueCodeData = { components: [], turboModules: [] };
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
getGlueCodeData() {
|
|
27
30
|
return this.glueCodeData;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
}
|
|
32
|
+
generate(uberSchema) {
|
|
33
|
+
const fileContentByPath = new Map();
|
|
34
|
+
const isRNOHModulePath = this.etsOutputPath.getValue().endsWith(`${RNOH_OHOS_NAME}/generated`.replace(/\//g, path_1.default.sep));
|
|
35
|
+
const componentCodeGenerator = new ArkTSComponentCodeGeneratorArkTS_1.ArkTSComponentCodeGeneratorArkTS(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('components'), this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : `${RNOH_OHOS_NAME}/ts`);
|
|
36
|
+
const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(this.cppOutputPath, this.etsOutputPath.copyWithNewSegment('turboModules'), this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : `${RNOH_OHOS_NAME}/ts`);
|
|
37
|
+
const generatorBySpecType = {
|
|
35
38
|
Component: componentCodeGenerator,
|
|
36
39
|
NativeModule: nativeModuleCodeGenerator,
|
|
37
40
|
};
|
|
38
|
-
for (
|
|
41
|
+
for (const [_fileName, specSchema] of uberSchema
|
|
39
42
|
.getSpecSchemaByFilenameMap()
|
|
40
|
-
.entries()
|
|
41
|
-
var _b = _a[_i], _fileName = _b[0], specSchema = _b[1];
|
|
43
|
+
.entries()) {
|
|
42
44
|
if (!(specSchema.type in generatorBySpecType)) {
|
|
43
45
|
throw new core_1.CodegenError({
|
|
44
|
-
whatHappened:
|
|
46
|
+
whatHappened: `Could not find a code generator for a specification of type '${specSchema.type}'`,
|
|
45
47
|
unexpected: true,
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
50
|
generatorBySpecType[specSchema.type]
|
|
49
51
|
.generate(specSchema)
|
|
50
|
-
.forEach(
|
|
52
|
+
.forEach((fileContent, filePath) => {
|
|
51
53
|
fileContentByPath.set(filePath, fileContent);
|
|
52
54
|
});
|
|
53
55
|
}
|
|
@@ -56,7 +58,6 @@ var UberGeneratorV1 = /** @class */ (function () {
|
|
|
56
58
|
turboModules: nativeModuleCodeGenerator.getGlueCodeData(),
|
|
57
59
|
};
|
|
58
60
|
return fileContentByPath;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
62
63
|
exports.UberGeneratorV1 = UberGeneratorV1;
|
|
@@ -5,81 +5,80 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.UberGeneratorV2 = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const CppComponentCodeGenerator_1 = require("./CppComponentCodeGenerator");
|
|
15
|
+
const NativeModuleCodeGenerator_1 = require("./NativeModuleCodeGenerator");
|
|
16
|
+
const SharedComponentCodeGenerator_1 = require("./SharedComponentCodeGenerator");
|
|
14
17
|
// The name of rnoh OHOS module
|
|
15
|
-
|
|
18
|
+
const RNOH_OHOS_NAME = '@rnoh/react-native-openharmony';
|
|
16
19
|
/**
|
|
17
20
|
* Generates code for libraries built on top of RNOH's C-API architecture.
|
|
18
21
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
class UberGeneratorV2 {
|
|
23
|
+
constructor(cppOutputPath, etsOutputPath, codegenNoticeLines) {
|
|
21
24
|
this.cppOutputPath = cppOutputPath;
|
|
22
25
|
this.etsOutputPath = etsOutputPath;
|
|
23
26
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
24
27
|
this.glueCodeData = new Map();
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
getGlueCodeData() {
|
|
27
30
|
return this.glueCodeData;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var libraryCppName = _a.libraryCppName, uberSchema = _a.uberSchema;
|
|
34
|
-
_this.glueCodeData.set(libraryCppName, {
|
|
31
|
+
}
|
|
32
|
+
generate(npmPackagesInfo) {
|
|
33
|
+
const fileContentByPath = new Map();
|
|
34
|
+
npmPackagesInfo.forEach(({ libraryCppName, uberSchema }) => {
|
|
35
|
+
this.glueCodeData.set(libraryCppName, {
|
|
35
36
|
components: [],
|
|
36
37
|
turboModules: [],
|
|
37
38
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const libraryGlueCodeData = this.glueCodeData.get(libraryCppName);
|
|
40
|
+
const libraryCppOutput = this.cppOutputPath.copyWithNewSegment(libraryCppName);
|
|
41
|
+
const sharedComponentCodeGenerator = new SharedComponentCodeGenerator_1.SharedComponentCodeGenerator((filename) => {
|
|
41
42
|
return libraryCppOutput.copyWithNewSegment('react', 'renderer', 'components', libraryCppName, filename);
|
|
42
43
|
});
|
|
43
|
-
|
|
44
|
+
const cppComponentCodeGenerator = new CppComponentCodeGenerator_1.CppComponentCodeGenerator((filename) => {
|
|
44
45
|
return libraryCppOutput.copyWithNewSegment('RNOH', 'generated', 'components', filename);
|
|
45
|
-
},
|
|
46
|
+
}, this.codegenNoticeLines);
|
|
46
47
|
cppComponentCodeGenerator
|
|
47
|
-
.generate({ libraryCppName
|
|
48
|
-
.forEach(
|
|
48
|
+
.generate({ libraryCppName, uberSchema })
|
|
49
|
+
.forEach((fileContent, path) => {
|
|
49
50
|
fileContentByPath.set(path, fileContent);
|
|
50
51
|
});
|
|
51
52
|
cppComponentCodeGenerator
|
|
52
53
|
.getGlueCodeData()
|
|
53
|
-
.forEach(
|
|
54
|
+
.forEach((componentGlueCodeData) => {
|
|
54
55
|
libraryGlueCodeData.components.push(componentGlueCodeData);
|
|
55
56
|
});
|
|
56
57
|
sharedComponentCodeGenerator
|
|
57
|
-
.generate({ libraryCppName
|
|
58
|
-
.forEach(
|
|
58
|
+
.generate({ libraryCppName, uberSchema })
|
|
59
|
+
.forEach((fileContent, path) => {
|
|
59
60
|
fileContentByPath.set(path, fileContent);
|
|
60
61
|
});
|
|
61
|
-
for (
|
|
62
|
+
for (const [_fileName, specSchema] of uberSchema
|
|
62
63
|
.getSpecSchemaByFilenameMap()
|
|
63
|
-
.entries()
|
|
64
|
-
var _c = _b[_i], _fileName = _c[0], specSchema = _c[1];
|
|
64
|
+
.entries()) {
|
|
65
65
|
if (specSchema.type === 'NativeModule') {
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const isRNOHModulePath = this.etsOutputPath.getValue().endsWith(`${RNOH_OHOS_NAME}/generated`.replace(/\//g, path_1.default.sep));
|
|
67
|
+
const nativeModuleCodeGenerator = new NativeModuleCodeGenerator_1.NativeModuleCodeGenerator(libraryCppOutput.copyWithNewSegment('RNOH', 'generated', 'turbo_modules'), this.etsOutputPath.copyWithNewSegment('turboModules'), this.codegenNoticeLines, isRNOHModulePath ? '../../ts' : `${RNOH_OHOS_NAME}/ts`);
|
|
68
68
|
nativeModuleCodeGenerator
|
|
69
69
|
.generate(specSchema)
|
|
70
|
-
.forEach(
|
|
70
|
+
.forEach((fileContent, filePath) => {
|
|
71
71
|
fileContentByPath.set(filePath, fileContent);
|
|
72
72
|
});
|
|
73
73
|
nativeModuleCodeGenerator
|
|
74
74
|
.getGlueCodeData()
|
|
75
|
-
.forEach(
|
|
75
|
+
.forEach((turboModuleGlueCodeData) => {
|
|
76
76
|
libraryGlueCodeData.turboModules.push(turboModuleGlueCodeData);
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
return fileContentByPath;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}());
|
|
82
|
+
}
|
|
83
|
+
}
|
|
85
84
|
exports.UberGeneratorV2 = UberGeneratorV2;
|
|
@@ -5,51 +5,77 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.BaseComponentInstanceHTemplate = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
14
|
+
const case_1 = __importDefault(require("case"));
|
|
15
|
+
const TEMPLATE = `
|
|
16
|
+
/**
|
|
17
|
+
{{#codegenNoticeLines}}
|
|
18
|
+
* {{{line}}}
|
|
19
|
+
{{/codegenNoticeLines}}
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#pragma once
|
|
23
|
+
|
|
24
|
+
#include "RNOH/CppComponentInstance.h"
|
|
25
|
+
#include <react/renderer/components/{{libraryName}}/ShadowNodes.h>
|
|
26
|
+
|
|
27
|
+
namespace rnoh {
|
|
28
|
+
class Base{{name}}ComponentInstance
|
|
29
|
+
: public CppComponentInstance<facebook::react::{{name}}ShadowNode> {
|
|
30
|
+
public:
|
|
31
|
+
using CppComponentInstance::CppComponentInstance;
|
|
32
|
+
|
|
33
|
+
void handleCommand(std::string const &commandName, folly::dynamic const &args) override {
|
|
34
|
+
{{#commands}}
|
|
35
|
+
if (commandName == "{{commandName}}") {
|
|
36
|
+
this->on{{CommandName}}Command({{argsFromDynamic}});
|
|
37
|
+
}
|
|
38
|
+
{{/commands}}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
{{#commands}}
|
|
42
|
+
virtual void on{{CommandName}}Command({{argsDeclaration}}) = 0;
|
|
43
|
+
{{/commands}}
|
|
44
|
+
};
|
|
45
|
+
} // namespace rnoh
|
|
46
|
+
`;
|
|
47
|
+
class BaseComponentInstanceHTemplate {
|
|
48
|
+
constructor(componentName, libraryName, codegenNoticeLines) {
|
|
15
49
|
this.componentName = componentName;
|
|
16
50
|
this.libraryName = libraryName;
|
|
17
51
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
18
52
|
this.commands = [];
|
|
19
53
|
}
|
|
20
|
-
|
|
54
|
+
addCommand(command) {
|
|
21
55
|
this.commands.push(command);
|
|
22
|
-
}
|
|
23
|
-
|
|
56
|
+
}
|
|
57
|
+
build() {
|
|
24
58
|
return mustache_1.default.render(TEMPLATE, {
|
|
25
|
-
codegenNoticeLines: this.codegenNoticeLines.map(
|
|
26
|
-
line
|
|
27
|
-
})
|
|
59
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
60
|
+
line,
|
|
61
|
+
})),
|
|
28
62
|
name: this.componentName,
|
|
29
63
|
libraryName: this.libraryName,
|
|
30
|
-
commands: this.commands.map(
|
|
31
|
-
var name = _a.name, args = _a.args;
|
|
64
|
+
commands: this.commands.map(({ name, args }) => {
|
|
32
65
|
return {
|
|
33
66
|
commandName: name,
|
|
34
67
|
CommandName: case_1.default.pascal(name),
|
|
35
68
|
argsDeclaration: args
|
|
36
|
-
.map(
|
|
37
|
-
var name = _a.name, typeAnnotation = _a.typeAnnotation;
|
|
38
|
-
return "".concat(cppTypeFromTypeAnnotation(typeAnnotation), " ").concat(name);
|
|
39
|
-
})
|
|
69
|
+
.map(({ name, typeAnnotation }) => `${cppTypeFromTypeAnnotation(typeAnnotation)} ${name}`)
|
|
40
70
|
.join(', '),
|
|
41
71
|
argsFromDynamic: args
|
|
42
|
-
.map(
|
|
43
|
-
var typeAnnotation = _a.typeAnnotation;
|
|
44
|
-
return "args[".concat(index, "]").concat(dynamicExtractorFromTypeAnnotation(typeAnnotation));
|
|
45
|
-
})
|
|
72
|
+
.map(({ typeAnnotation }, index) => `args[${index}]${dynamicExtractorFromTypeAnnotation(typeAnnotation)}`)
|
|
46
73
|
.join(', '),
|
|
47
74
|
};
|
|
48
75
|
}),
|
|
49
76
|
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
53
79
|
exports.BaseComponentInstanceHTemplate = BaseComponentInstanceHTemplate;
|
|
54
80
|
function cppTypeFromTypeAnnotation(typeAnnotation) {
|
|
55
81
|
switch (typeAnnotation.type) {
|