@react-native-oh/react-native-harmony-cli 0.0.26 → 0.0.28
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 +12 -0
- package/dist/assetResolver.js +25 -0
- package/dist/autolinking/Autolinking.js +275 -0
- package/dist/autolinking/index.js +23 -0
- package/dist/codegen/core/CodeGenerator.js +8 -0
- package/dist/codegen/core/CodegenError.js +13 -0
- package/dist/codegen/core/EventUtils.js +25 -0
- package/dist/codegen/core/TypeAnnotationToTS.js +138 -0
- package/dist/codegen/core/UberSchema.js +109 -0
- package/dist/codegen/core/index.js +27 -0
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +67 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +82 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +80 -0
- package/dist/codegen/generators/CppComponentCodeGenerator.js +62 -0
- package/dist/codegen/generators/LibGlueCodeGenerator.js +56 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +79 -0
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +40 -0
- package/dist/codegen/generators/UberGeneratorV1.js +56 -0
- package/dist/codegen/generators/UberGeneratorV2.js +77 -0
- package/dist/codegen/generators/index.js +30 -0
- package/dist/codegen/index.js +24 -0
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +111 -0
- package/dist/codegen/templates/BasePackageHTemplate.js +136 -0
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +68 -0
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +91 -0
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +198 -0
- package/dist/codegen/templates/IndexTSTemplate.js +58 -0
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +130 -0
- package/dist/codegen/templates/TurboModuleCppTemplate.js +59 -0
- package/dist/codegen/templates/TurboModuleHTemplate.js +48 -0
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +81 -0
- package/dist/codegen/templates/index.js +31 -0
- package/dist/commands/bundle-harmony.js +185 -0
- package/dist/commands/codegen-harmony.js +207 -0
- package/dist/commands/codegen-lib-harmony.js +259 -0
- package/dist/commands/create-metro-host-constants.js +67 -0
- package/dist/commands/index.js +30 -0
- package/dist/commands/link-harmony.js +97 -0
- package/dist/commands/pack-harmony.js +106 -0
- package/dist/commands/unpack-harmony.js +191 -0
- package/dist/commands/verify-package-harmony.js +128 -0
- package/dist/core/AbsolutePath.js +59 -0
- package/dist/core/CodegenConfig.js +63 -0
- package/dist/core/DescriptiveError.js +55 -0
- package/dist/core/FileSystem.js +33 -0
- package/dist/core/OHPackageJSON5.js +29 -0
- package/dist/core/PackageJSON.js +66 -0
- package/dist/core/ProjectDependenciesManager.js +83 -0
- package/dist/core/ValidationError.js +12 -0
- package/dist/core/ValueObject.js +8 -0
- package/dist/core/fs.js +42 -0
- package/dist/core/index.js +32 -0
- package/dist/index.js +22 -0
- package/dist/io/CliExecutor.js +35 -0
- package/dist/io/Logger.js +80 -0
- package/dist/io/RealFS.js +68 -0
- package/dist/io/TarGz.js +34 -0
- package/dist/io/__fixtures__.js +127 -0
- package/dist/io/fsUtils.js +37 -0
- package/dist/io/index.js +26 -0
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +44 -0
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +38 -0
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +32 -0
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +57 -0
- package/dist/package-verifier/checks/index.js +26 -0
- package/dist/package-verifier/index.js +24 -0
- package/dist/package-verifier/types.js +8 -0
- package/dist/package-verifier/verify-package.js +107 -0
- package/jest.config.js +7 -0
- package/package.json +8 -2
- package/react-native.config.js +7 -0
- package/src/assetResolver.ts +7 -0
- package/src/autolinking/Autolinking.test.ts +483 -0
- package/src/autolinking/Autolinking.ts +384 -0
- package/src/autolinking/index.ts +8 -0
- package/src/codegen/core/CodeGenerator.ts +7 -0
- package/src/codegen/core/CodegenError.ts +7 -0
- package/src/codegen/core/EventUtils.ts +7 -0
- package/src/codegen/core/TypeAnnotationToTS.test.ts +7 -0
- package/src/codegen/core/TypeAnnotationToTS.ts +7 -0
- package/src/codegen/core/UberSchema.ts +15 -1
- package/src/codegen/core/index.ts +7 -0
- package/src/codegen/generators/{GlueCodeGenerator.ts → AppBuildTimeGlueCodeGenerator.ts} +20 -9
- package/src/codegen/generators/{ComponentCodeGeneratorArkTS.ts → ArkTSComponentCodeGeneratorArkTS.ts} +18 -5
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +119 -0
- package/src/codegen/generators/{ComponentCodeGeneratorCAPI.ts → CppComponentCodeGenerator.ts} +21 -43
- package/src/codegen/generators/LibGlueCodeGenerator.ts +98 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +14 -5
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +57 -0
- package/src/codegen/generators/UberGeneratorV1.ts +19 -8
- package/src/codegen/generators/UberGeneratorV2.ts +39 -16
- package/src/codegen/generators/index.ts +12 -3
- package/src/codegen/index.ts +7 -0
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +19 -7
- package/src/codegen/templates/{GeneratedPackageHTemplate.ts → BasePackageHTemplate.ts} +52 -12
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +9 -1
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +15 -10
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +20 -8
- package/src/codegen/templates/IndexTSTemplate.ts +18 -9
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +8 -0
- package/src/codegen/templates/TurboModuleCppTemplate.ts +16 -9
- package/src/codegen/templates/TurboModuleHTemplate.ts +16 -9
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +20 -9
- package/src/codegen/templates/index.ts +7 -0
- package/src/commands/bundle-harmony.ts +8 -1
- package/src/commands/codegen-harmony.ts +43 -13
- package/src/commands/codegen-lib-harmony.ts +394 -0
- package/src/commands/create-metro-host-constants.ts +7 -0
- package/src/commands/index.ts +9 -0
- package/src/commands/link-harmony.ts +102 -0
- package/src/commands/pack-harmony.ts +7 -0
- package/src/commands/unpack-harmony.ts +12 -3
- package/src/commands/verify-package-harmony.ts +7 -0
- package/src/core/AbsolutePath.ts +16 -0
- package/src/core/CodegenConfig.ts +7 -0
- package/src/core/DescriptiveError.ts +7 -0
- package/src/core/FileSystem.ts +57 -0
- package/src/core/OHPackageJSON5.ts +7 -0
- package/src/core/PackageJSON.ts +40 -8
- package/src/core/ProjectDependenciesManager.ts +40 -14
- package/src/core/ValidationError.ts +7 -0
- package/src/core/ValueObject.ts +7 -0
- package/src/core/fs.ts +7 -0
- package/src/core/index.ts +8 -0
- package/src/index.ts +11 -0
- package/src/io/CliExecutor.ts +47 -0
- package/src/io/Logger.ts +11 -0
- package/src/io/RealFS.ts +62 -0
- package/src/io/TarGz.ts +7 -0
- package/src/io/__fixtures__.ts +135 -0
- package/src/io/fsUtils.ts +26 -6
- package/src/io/index.ts +8 -0
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +7 -0
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +7 -0
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +7 -0
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +7 -0
- package/src/package-verifier/checks/index.ts +7 -0
- package/src/package-verifier/index.ts +7 -0
- package/src/package-verifier/types.ts +7 -0
- package/src/package-verifier/verify-package.ts +9 -1
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import mustache from 'mustache';
|
|
2
9
|
|
|
3
10
|
const TEMPLATE = `
|
|
4
11
|
/**
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
* lost once the code is regenerated.
|
|
9
|
-
*
|
|
10
|
-
* @generatorVersion: 2
|
|
12
|
+
{{#codegenNoticeLines}}
|
|
13
|
+
* {{{line}}}
|
|
14
|
+
{{/codegenNoticeLines}}
|
|
11
15
|
*/
|
|
16
|
+
|
|
12
17
|
#pragma once
|
|
13
18
|
|
|
14
19
|
{{#libraries}}
|
|
@@ -37,6 +42,26 @@ class {{name}}TurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
|
37
42
|
};
|
|
38
43
|
};
|
|
39
44
|
|
|
45
|
+
class {{name}}EventEmitRequestHandler : public EventEmitRequestHandler {
|
|
46
|
+
public:
|
|
47
|
+
void handleEvent(Context const &ctx) override {
|
|
48
|
+
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
49
|
+
if (eventEmitter == nullptr) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
std::vector<std::string> supportedEventNames = {
|
|
54
|
+
{{#arkTSEvents}}
|
|
55
|
+
"{{name}}",
|
|
56
|
+
{{/arkTSEvents}}
|
|
57
|
+
};
|
|
58
|
+
if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
59
|
+
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
|
|
40
65
|
class {{name}} : public Package {
|
|
41
66
|
public:
|
|
42
67
|
{{name}}(Package::Context ctx) : Package(ctx){};
|
|
@@ -62,7 +87,9 @@ class {{name}} : public Package {
|
|
|
62
87
|
};
|
|
63
88
|
|
|
64
89
|
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
65
|
-
return {
|
|
90
|
+
return {
|
|
91
|
+
std::make_shared<{{name}}EventEmitRequestHandler>(),
|
|
92
|
+
};
|
|
66
93
|
}
|
|
67
94
|
};
|
|
68
95
|
|
|
@@ -75,15 +102,20 @@ type GeneratedPackageTurboModule = {
|
|
|
75
102
|
|
|
76
103
|
type GeneratedPackageComponent = {
|
|
77
104
|
name: string;
|
|
78
|
-
|
|
105
|
+
libraryCppName: string;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
type ArkTSEvent = {
|
|
109
|
+
name: string;
|
|
79
110
|
};
|
|
80
111
|
|
|
81
112
|
export class BasePackageHTemplate {
|
|
82
113
|
private turboModules: GeneratedPackageTurboModule[] = [];
|
|
83
114
|
private components: GeneratedPackageComponent[] = [];
|
|
84
|
-
private
|
|
115
|
+
private arkTSEvents: ArkTSEvent[] = [];
|
|
116
|
+
private libraryCppNames = new Set<string>();
|
|
85
117
|
|
|
86
|
-
constructor(private name: string) {}
|
|
118
|
+
constructor(private name: string, private codegenNoticeLines: string[]) {}
|
|
87
119
|
|
|
88
120
|
addTurboModule(turboModule: GeneratedPackageTurboModule) {
|
|
89
121
|
this.turboModules.push(turboModule);
|
|
@@ -91,15 +123,23 @@ export class BasePackageHTemplate {
|
|
|
91
123
|
|
|
92
124
|
addComponent(component: GeneratedPackageComponent) {
|
|
93
125
|
this.components.push(component);
|
|
94
|
-
this.
|
|
126
|
+
this.libraryCppNames.add(component.libraryCppName);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
addArkTSEvent(arkTSEvent: ArkTSEvent) {
|
|
130
|
+
this.arkTSEvents.push(arkTSEvent);
|
|
95
131
|
}
|
|
96
132
|
|
|
97
133
|
build(): string {
|
|
98
134
|
return mustache.render(TEMPLATE.trimStart(), {
|
|
135
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
136
|
+
line,
|
|
137
|
+
})),
|
|
99
138
|
name: this.name,
|
|
100
139
|
turboModules: this.turboModules,
|
|
101
140
|
components: this.components,
|
|
102
|
-
|
|
141
|
+
arkTSEvents: this.arkTSEvents,
|
|
142
|
+
libraries: Array.from(this.libraryCppNames).map((name) => ({
|
|
103
143
|
name,
|
|
104
144
|
})),
|
|
105
145
|
});
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import mustache from 'mustache';
|
|
2
9
|
|
|
3
10
|
const TEMPLATE = `
|
|
@@ -9,6 +16,7 @@ const TEMPLATE = `
|
|
|
9
16
|
*
|
|
10
17
|
* @generatorVersion: 1
|
|
11
18
|
*/
|
|
19
|
+
|
|
12
20
|
#pragma once
|
|
13
21
|
|
|
14
22
|
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
@@ -18,7 +26,7 @@ const TEMPLATE = `
|
|
|
18
26
|
namespace facebook {
|
|
19
27
|
namespace react {
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
constexpr char {{name}}ComponentName[] = "{{name}}";
|
|
22
30
|
|
|
23
31
|
class {{name}}Props : public ViewProps {
|
|
24
32
|
public:
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import mustache from 'mustache';
|
|
2
9
|
|
|
3
10
|
const TEMPLATE = `
|
|
4
|
-
#pragma once
|
|
5
|
-
|
|
6
11
|
/**
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
* lost once the code is regenerated.
|
|
11
|
-
*
|
|
12
|
-
* @generatorVersion: {{generatorVersion}}
|
|
12
|
+
{{#codegenNoticeLines}}
|
|
13
|
+
* {{{line}}}
|
|
14
|
+
{{/codegenNoticeLines}}
|
|
13
15
|
*/
|
|
14
16
|
|
|
17
|
+
#pragma once
|
|
15
18
|
#include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
|
|
16
19
|
|
|
17
20
|
namespace rnoh {
|
|
@@ -58,7 +61,7 @@ export class ComponentJSIBinderHTemplate {
|
|
|
58
61
|
private props: ComponentJSIBinderHProp[] = [];
|
|
59
62
|
private events: ComponentJSIBinderHEvent[] = [];
|
|
60
63
|
|
|
61
|
-
constructor(private name: string, private
|
|
64
|
+
constructor(private name: string, private codegenNoticeLines: string[]) {}
|
|
62
65
|
|
|
63
66
|
addProp(prop: ComponentJSIBinderHProp) {
|
|
64
67
|
this.props.push(prop);
|
|
@@ -70,8 +73,10 @@ export class ComponentJSIBinderHTemplate {
|
|
|
70
73
|
|
|
71
74
|
build(): string {
|
|
72
75
|
return mustache.render(TEMPLATE.trimStart(), {
|
|
76
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
77
|
+
line,
|
|
78
|
+
})),
|
|
73
79
|
name: this.name,
|
|
74
|
-
generatorVersion: this.generatorVersion,
|
|
75
80
|
props: this.props.map((prop) => ({
|
|
76
81
|
name: prop.name,
|
|
77
82
|
type: prop.isObject ? '"Object"' : 'true',
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import mustache from 'mustache';
|
|
2
9
|
|
|
3
10
|
const TEMPLATE = `
|
|
4
11
|
/**
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
* lost once the code is regenerated.
|
|
9
|
-
*
|
|
10
|
-
* @generatorVersion: 1
|
|
12
|
+
{{#codegenNoticeLines}}
|
|
13
|
+
* {{{line}}}
|
|
14
|
+
{{/codegenNoticeLines}}
|
|
11
15
|
*/
|
|
12
16
|
|
|
13
17
|
import {
|
|
@@ -21,7 +25,7 @@ import {
|
|
|
21
25
|
Tag,
|
|
22
26
|
RNComponentCommandReceiver,
|
|
23
27
|
ViewPropsSelector,
|
|
24
|
-
} from '
|
|
28
|
+
} from '{{{rnohImport}}}';
|
|
25
29
|
|
|
26
30
|
|
|
27
31
|
export namespace {{name}} {
|
|
@@ -162,7 +166,11 @@ export class ComponentUtilsTSTemplate {
|
|
|
162
166
|
private commands: Command[] = [];
|
|
163
167
|
private getterTemplateByTSType = new Map<string, string>();
|
|
164
168
|
|
|
165
|
-
constructor(
|
|
169
|
+
constructor(
|
|
170
|
+
private name: string,
|
|
171
|
+
private codegenNoticeLines: string[],
|
|
172
|
+
private rnohImport: string
|
|
173
|
+
) {
|
|
166
174
|
this.getterTemplateByTSType.set('ColorValue', COLOR_VALUE_GETTER_TEMPLATE);
|
|
167
175
|
}
|
|
168
176
|
|
|
@@ -180,7 +188,11 @@ export class ComponentUtilsTSTemplate {
|
|
|
180
188
|
|
|
181
189
|
build(): string {
|
|
182
190
|
return mustache.render(TEMPLATE.trimStart(), {
|
|
191
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
192
|
+
line,
|
|
193
|
+
})),
|
|
183
194
|
name: this.name,
|
|
195
|
+
rnohImport: this.rnohImport,
|
|
184
196
|
props: this.props.map((prop) => ({
|
|
185
197
|
name: prop.name,
|
|
186
198
|
type: prop.tsType,
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import mustache from 'mustache';
|
|
2
9
|
|
|
3
10
|
const TEMPLATE = `
|
|
4
11
|
/**
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
* lost once the code is regenerated.
|
|
12
|
+
{{#codegenNoticeLines}}
|
|
13
|
+
* {{{line}}}
|
|
14
|
+
{{/codegenNoticeLines}}
|
|
9
15
|
*/
|
|
16
|
+
|
|
10
17
|
{{#reexports}}
|
|
11
18
|
export * {{as}}from "{{{from}}}"
|
|
12
19
|
{{/reexports}}
|
|
@@ -14,10 +21,9 @@ export * {{as}}from "{{{from}}}"
|
|
|
14
21
|
|
|
15
22
|
const TEMPLATE_EMPTY = `
|
|
16
23
|
/**
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
* lost once the code is regenerated.
|
|
24
|
+
{{#codegenNoticeLines}}
|
|
25
|
+
* {{{line}}}
|
|
26
|
+
{{/codegenNoticeLines}}
|
|
21
27
|
*/
|
|
22
28
|
|
|
23
29
|
export {}
|
|
@@ -31,7 +37,7 @@ type Reexport = {
|
|
|
31
37
|
export class IndexTSTemplate {
|
|
32
38
|
private reexports: Reexport[] = [];
|
|
33
39
|
|
|
34
|
-
constructor() {}
|
|
40
|
+
constructor(private codegenNoticeLines: string[]) {}
|
|
35
41
|
|
|
36
42
|
addReexport(reexport: Reexport) {
|
|
37
43
|
this.reexports.push(reexport);
|
|
@@ -44,6 +50,9 @@ export class IndexTSTemplate {
|
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
return mustache.render(TEMPLATE.trimStart(), {
|
|
53
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
54
|
+
line,
|
|
55
|
+
})),
|
|
47
56
|
reexports: this.reexports.map((reexport) => ({
|
|
48
57
|
from: reexport.from,
|
|
49
58
|
as: reexport.as ? `as ${reexport.as} ` : '',
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import mustache from 'mustache';
|
|
2
9
|
|
|
3
10
|
const TEMPLATE = `
|
|
@@ -9,6 +16,7 @@ const TEMPLATE = `
|
|
|
9
16
|
*
|
|
10
17
|
* @generatorVersion: 1
|
|
11
18
|
*/
|
|
19
|
+
|
|
12
20
|
#pragma once
|
|
13
21
|
|
|
14
22
|
#include "RNOH/Package.h"
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import mustache from 'mustache';
|
|
2
9
|
|
|
3
10
|
const TEMPLATE = `
|
|
4
11
|
/**
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
* lost once the code is regenerated.
|
|
9
|
-
*
|
|
10
|
-
* @generatorVersion: {{generatorVersion}}
|
|
12
|
+
{{#codegenNoticeLines}}
|
|
13
|
+
* {{{line}}}
|
|
14
|
+
{{/codegenNoticeLines}}
|
|
11
15
|
*/
|
|
16
|
+
|
|
12
17
|
#include "{{className}}.h"
|
|
13
18
|
|
|
14
19
|
namespace rnoh {
|
|
@@ -34,16 +39,18 @@ export type TurboModuleCppTemplateMethod = {
|
|
|
34
39
|
export class TurboModuleCppTemplate {
|
|
35
40
|
private methods: TurboModuleCppTemplateMethod[] = [];
|
|
36
41
|
|
|
37
|
-
constructor(private name: string, private
|
|
42
|
+
constructor(private name: string, private codegenNoticeLines: string[]) {}
|
|
38
43
|
|
|
39
44
|
addMethod(method: TurboModuleCppTemplateMethod) {
|
|
40
45
|
this.methods.push(method);
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
build(): string {
|
|
44
|
-
return mustache.render(TEMPLATE, {
|
|
49
|
+
return mustache.render(TEMPLATE.trimStart(), {
|
|
50
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
51
|
+
line,
|
|
52
|
+
})),
|
|
45
53
|
className: this.name,
|
|
46
|
-
generatorVersion: this.generatorVersion,
|
|
47
54
|
methods: this.methods.map((method) => ({
|
|
48
55
|
name: method.name,
|
|
49
56
|
argsCount: method.argsCount,
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import mustache from 'mustache';
|
|
2
9
|
|
|
3
10
|
const TEMPLATE = `
|
|
4
11
|
/**
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
* lost once the code is regenerated.
|
|
9
|
-
*
|
|
10
|
-
* @generatorVersion: {{generatorVersion}}
|
|
12
|
+
{{#codegenNoticeLines}}
|
|
13
|
+
* {{{line}}}
|
|
14
|
+
{{/codegenNoticeLines}}
|
|
11
15
|
*/
|
|
16
|
+
|
|
12
17
|
#pragma once
|
|
13
18
|
|
|
14
19
|
#include "RNOH/ArkTSTurboModule.h"
|
|
@@ -24,12 +29,14 @@ class JSI_EXPORT {{className}} : public ArkTSTurboModule {
|
|
|
24
29
|
`;
|
|
25
30
|
|
|
26
31
|
export class TurboModuleHTemplate {
|
|
27
|
-
constructor(private name: string, private
|
|
32
|
+
constructor(private name: string, private codegenNoticeLines: string[]) {}
|
|
28
33
|
|
|
29
34
|
build(): string {
|
|
30
|
-
return mustache.render(TEMPLATE, {
|
|
35
|
+
return mustache.render(TEMPLATE.trimStart(), {
|
|
31
36
|
className: this.name,
|
|
32
|
-
|
|
37
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
38
|
+
line,
|
|
39
|
+
})),
|
|
33
40
|
});
|
|
34
41
|
}
|
|
35
42
|
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import mustache from 'mustache';
|
|
2
9
|
|
|
3
10
|
const TEMPLATE = `
|
|
4
11
|
/**
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
* lost once the code is regenerated.
|
|
9
|
-
*
|
|
10
|
-
* @generatorVersion: {{generatorVersion}}
|
|
12
|
+
{{#codegenNoticeLines}}
|
|
13
|
+
* {{{line}}}
|
|
14
|
+
{{/codegenNoticeLines}}
|
|
11
15
|
*/
|
|
12
16
|
|
|
13
|
-
import { Tag } from "
|
|
17
|
+
import { Tag } from "{{{rnohImport}}}"
|
|
14
18
|
|
|
15
19
|
export namespace {{name}} {
|
|
16
20
|
export const NAME = '{{name}}' as const
|
|
@@ -60,7 +64,11 @@ export class TurboModuleInterfaceTS {
|
|
|
60
64
|
private aliases: Alias[] = [];
|
|
61
65
|
private enumModels: EnumModel[] = [];
|
|
62
66
|
|
|
63
|
-
constructor(
|
|
67
|
+
constructor(
|
|
68
|
+
private name: string,
|
|
69
|
+
private codegenNoticeLines: string[],
|
|
70
|
+
private rnohImport: string
|
|
71
|
+
) {}
|
|
64
72
|
|
|
65
73
|
addAlias(alias: Alias) {
|
|
66
74
|
this.aliases.push(alias);
|
|
@@ -76,10 +84,13 @@ export class TurboModuleInterfaceTS {
|
|
|
76
84
|
|
|
77
85
|
build(): string {
|
|
78
86
|
return mustache.render(TEMPLATE.trimStart(), {
|
|
87
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
88
|
+
line,
|
|
89
|
+
})),
|
|
79
90
|
name: this.name,
|
|
80
91
|
aliases: this.aliases,
|
|
81
92
|
enums: this.enumModels,
|
|
82
|
-
|
|
93
|
+
rnohImport: this.rnohImport,
|
|
83
94
|
methods: this.methods.map((method) => ({
|
|
84
95
|
name: method.name,
|
|
85
96
|
stringifiedArgs: method.stringifiedArgs,
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
export * from './TurboModuleHTemplate';
|
|
2
9
|
export * from './TurboModuleCppTemplate';
|
|
3
10
|
export * from './RNOHGeneratedPackageHTemplate';
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import { Command } from '@react-native-community/cli-types';
|
|
2
9
|
import fs from 'fs';
|
|
3
10
|
import fse from 'fs-extra';
|
|
@@ -188,7 +195,7 @@ function copyFiles(fileDestBySrc: Record<Path, Path>) {
|
|
|
188
195
|
function copyFile(
|
|
189
196
|
src: string,
|
|
190
197
|
dest: string,
|
|
191
|
-
onFinished: (error
|
|
198
|
+
onFinished: (error?: Error) => void
|
|
192
199
|
): void {
|
|
193
200
|
const destDir = pathUtils.dirname(dest);
|
|
194
201
|
fs.mkdir(destDir, { recursive: true }, (err?) => {
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
2
8
|
import pathUtils from 'node:path';
|
|
3
9
|
import Case from 'case';
|
|
4
10
|
import { Command } from '@react-native-community/cli-types';
|
|
5
11
|
import {
|
|
6
12
|
AbsolutePath,
|
|
7
13
|
DescriptiveError,
|
|
14
|
+
FS,
|
|
8
15
|
PackageJSON,
|
|
9
16
|
ProjectDependenciesManager,
|
|
10
17
|
maybeMakeDirectories,
|
|
@@ -15,15 +22,15 @@ import {
|
|
|
15
22
|
LibraryData,
|
|
16
23
|
UberGeneratorV1,
|
|
17
24
|
UberGeneratorV2,
|
|
18
|
-
|
|
25
|
+
AppBuildTimeGlueCodeGenerator,
|
|
19
26
|
CodegenError,
|
|
20
27
|
} from '../codegen';
|
|
21
|
-
import { Logger } from '../io';
|
|
28
|
+
import { Logger, RealFS } from '../io';
|
|
22
29
|
|
|
23
30
|
export const commandCodegenHarmony: Command = {
|
|
24
31
|
name: 'codegen-harmony',
|
|
25
32
|
description:
|
|
26
|
-
'Generates
|
|
33
|
+
'Generates boilerplate, types, and utilities from Turbo Module and Fabric Component specifications. This command is meant to be executed during the application build process.',
|
|
27
34
|
options: [
|
|
28
35
|
{
|
|
29
36
|
name: '--rnoh-module-path <path>',
|
|
@@ -53,6 +60,7 @@ export const commandCodegenHarmony: Command = {
|
|
|
53
60
|
],
|
|
54
61
|
func: async (_argv, _config, args: any) => {
|
|
55
62
|
const logger = new Logger();
|
|
63
|
+
const fs = new RealFS();
|
|
56
64
|
try {
|
|
57
65
|
const MAX_SUPPORTED_CODEGEN_VERSION = 2;
|
|
58
66
|
// prepare the input data
|
|
@@ -64,6 +72,7 @@ export const commandCodegenHarmony: Command = {
|
|
|
64
72
|
const cppOutputPath = new AbsolutePath(args.cppOutputPath);
|
|
65
73
|
const projectRootPath = new AbsolutePath(args.projectRootPath);
|
|
66
74
|
const uberSchemaFromArkTSLibraries = await UberSchema.fromProject(
|
|
75
|
+
fs,
|
|
67
76
|
projectRootPath,
|
|
68
77
|
(codegenVersion, packageName) => {
|
|
69
78
|
throwErrorIfUnsupportedCodegenVersion(
|
|
@@ -75,6 +84,7 @@ export const commandCodegenHarmony: Command = {
|
|
|
75
84
|
}
|
|
76
85
|
);
|
|
77
86
|
const cApiLibrariesData = await collectLibrariesData(
|
|
87
|
+
fs,
|
|
78
88
|
projectRootPath,
|
|
79
89
|
(codegenVersion, packageName) => {
|
|
80
90
|
throwErrorIfUnsupportedCodegenVersion(
|
|
@@ -87,11 +97,26 @@ export const commandCodegenHarmony: Command = {
|
|
|
87
97
|
);
|
|
88
98
|
|
|
89
99
|
// instantiate objects
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
100
|
+
const codegenNoticeLines = [
|
|
101
|
+
'This code was generated by "react-native codegen-harmony"',
|
|
102
|
+
'',
|
|
103
|
+
'Do not edit this file as changes may cause incorrect behavior and will be',
|
|
104
|
+
'lost once the code is regenerated.',
|
|
105
|
+
];
|
|
106
|
+
const uberGeneratorV1 = new UberGeneratorV1(
|
|
107
|
+
cppOutputPath,
|
|
108
|
+
etsOutputPath,
|
|
109
|
+
[...codegenNoticeLines, '', '@generatorVersion: 1']
|
|
110
|
+
);
|
|
111
|
+
const uberGeneratorV2 = new UberGeneratorV2(
|
|
93
112
|
cppOutputPath,
|
|
94
|
-
etsOutputPath
|
|
113
|
+
etsOutputPath,
|
|
114
|
+
[...codegenNoticeLines, '', '@generatorVersion: 2']
|
|
115
|
+
);
|
|
116
|
+
const glueCodeGenerator = new AppBuildTimeGlueCodeGenerator(
|
|
117
|
+
cppOutputPath,
|
|
118
|
+
etsOutputPath,
|
|
119
|
+
codegenNoticeLines
|
|
95
120
|
);
|
|
96
121
|
|
|
97
122
|
// generate the code
|
|
@@ -117,12 +142,13 @@ export const commandCodegenHarmony: Command = {
|
|
|
117
142
|
|
|
118
143
|
// output the results
|
|
119
144
|
if (args.debug) {
|
|
120
|
-
const uberSchema = await UberSchema.fromProject(projectRootPath);
|
|
145
|
+
const uberSchema = await UberSchema.fromProject(fs, projectRootPath);
|
|
121
146
|
logger.debug((styles) =>
|
|
122
147
|
styles.gray(JSON.stringify(uberSchema.getValue(), null, 2))
|
|
123
148
|
);
|
|
124
149
|
}
|
|
125
150
|
saveCodegenResult(
|
|
151
|
+
fs,
|
|
126
152
|
fileContentByPath,
|
|
127
153
|
cppOutputPath,
|
|
128
154
|
etsOutputPath,
|
|
@@ -153,13 +179,14 @@ function validateArgs(args: any) {
|
|
|
153
179
|
}
|
|
154
180
|
|
|
155
181
|
async function collectLibrariesData(
|
|
182
|
+
fs: FS,
|
|
156
183
|
projectRootPath: AbsolutePath,
|
|
157
184
|
onShouldAcceptCodegenConfig: (version: number, packageName: string) => boolean
|
|
158
185
|
): Promise<LibraryData[]> {
|
|
159
186
|
const packageJSONs: PackageJSON[] = [
|
|
160
|
-
PackageJSON.fromProjectRootPath(projectRootPath, projectRootPath),
|
|
187
|
+
PackageJSON.fromProjectRootPath(fs, projectRootPath, projectRootPath),
|
|
161
188
|
];
|
|
162
|
-
await new ProjectDependenciesManager(projectRootPath).forEachAsync(
|
|
189
|
+
await new ProjectDependenciesManager(fs, projectRootPath).forEachAsync(
|
|
163
190
|
(dependency) => {
|
|
164
191
|
packageJSONs.push(dependency.readPackageJSON());
|
|
165
192
|
}
|
|
@@ -176,7 +203,9 @@ async function collectLibrariesData(
|
|
|
176
203
|
)
|
|
177
204
|
) {
|
|
178
205
|
results.push({
|
|
179
|
-
|
|
206
|
+
libraryCppName: deriveCppDirectoryNameFromNpmPackageName(
|
|
207
|
+
packageJSON.name
|
|
208
|
+
),
|
|
180
209
|
uberSchema: UberSchema.fromCodegenConfig(codegenConfig),
|
|
181
210
|
});
|
|
182
211
|
}
|
|
@@ -204,6 +233,7 @@ function throwErrorIfUnsupportedCodegenVersion(
|
|
|
204
233
|
}
|
|
205
234
|
|
|
206
235
|
function saveCodegenResult(
|
|
236
|
+
fs: FS,
|
|
207
237
|
fileContentByPath: Map<AbsolutePath, string>,
|
|
208
238
|
cppOutputPath: AbsolutePath,
|
|
209
239
|
etsOutputPath: AbsolutePath,
|
|
@@ -223,7 +253,7 @@ function saveCodegenResult(
|
|
|
223
253
|
prepareDirectory(path.getDirectoryPath(), enableSafetyCheck);
|
|
224
254
|
});
|
|
225
255
|
fileContentByPath.forEach((fileContent, path) => {
|
|
226
|
-
fs.
|
|
256
|
+
fs.writeTextSync(path, fileContent);
|
|
227
257
|
});
|
|
228
258
|
}
|
|
229
259
|
|