@react-native-oh/react-native-harmony-cli 0.0.40 → 0.0.41
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 +43 -74
- package/dist/autolinking/Autolinking.js +178 -179
- 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 +53 -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 +78 -78
- package/react-native.config.js +17 -17
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
|
@@ -5,12 +5,112 @@
|
|
|
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.BasePackageHTemplate = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
14
|
+
const TEMPLATE = `
|
|
15
|
+
/**
|
|
16
|
+
{{#codegenNoticeLines}}
|
|
17
|
+
* {{{line}}}
|
|
18
|
+
{{/codegenNoticeLines}}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#pragma once
|
|
22
|
+
|
|
23
|
+
{{#libraries}}
|
|
24
|
+
#include <react/renderer/components/{{name}}/ComponentDescriptors.h>
|
|
25
|
+
{{/libraries}}
|
|
26
|
+
#include "RNOH/Package.h"
|
|
27
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
28
|
+
{{#turboModules}}
|
|
29
|
+
#include "RNOH/generated/turbo_modules/{{name}}.h"
|
|
30
|
+
{{/turboModules}}
|
|
31
|
+
{{#components}}
|
|
32
|
+
#include "RNOH/generated/components/{{name}}JSIBinder.h"
|
|
33
|
+
{{/components}}
|
|
34
|
+
|
|
35
|
+
namespace rnoh {
|
|
36
|
+
|
|
37
|
+
class {{name}}TurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
38
|
+
public:
|
|
39
|
+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
|
40
|
+
{{#turboModules}}
|
|
41
|
+
if (name == "{{name}}") {
|
|
42
|
+
return std::make_shared<{{name}}>(ctx, name);
|
|
43
|
+
}
|
|
44
|
+
{{/turboModules}}
|
|
45
|
+
return nullptr;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
class {{name}}EventEmitRequestHandler : public EventEmitRequestHandler {
|
|
50
|
+
public:
|
|
51
|
+
void handleEvent(Context const &ctx) override {
|
|
52
|
+
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
53
|
+
auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
|
|
54
|
+
|
|
55
|
+
if (eventEmitter == nullptr) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
std::vector<std::string> supportedComponentNames = {
|
|
60
|
+
{{#arkTSComponents}}
|
|
61
|
+
"{{name}}",
|
|
62
|
+
{{/arkTSComponents}}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
std::vector<std::string> supportedEventNames = {
|
|
66
|
+
{{#arkTSEvents}}
|
|
67
|
+
"{{name}}",
|
|
68
|
+
{{/arkTSEvents}}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
|
|
72
|
+
std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
73
|
+
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class {{name}} : public Package {
|
|
80
|
+
public:
|
|
81
|
+
{{name}}(Package::Context ctx) : Package(ctx){};
|
|
82
|
+
|
|
83
|
+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
|
84
|
+
return std::make_unique<{{name}}TurboModuleFactoryDelegate>();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
|
|
88
|
+
return {
|
|
89
|
+
{{#components}}
|
|
90
|
+
facebook::react::concreteComponentDescriptorProvider<facebook::react::{{name}}ComponentDescriptor>(),
|
|
91
|
+
{{/components}}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
ComponentJSIBinderByString createComponentJSIBinderByName() override {
|
|
96
|
+
return {
|
|
97
|
+
{{#components}}
|
|
98
|
+
{"{{name}}", std::make_shared<{{name}}JSIBinder>()},
|
|
99
|
+
{{/components}}
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
104
|
+
return {
|
|
105
|
+
std::make_shared<{{name}}EventEmitRequestHandler>(),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
} // namespace rnoh
|
|
111
|
+
`;
|
|
112
|
+
class BasePackageHTemplate {
|
|
113
|
+
constructor(name, codegenNoticeLines) {
|
|
14
114
|
this.name = name;
|
|
15
115
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
16
116
|
this.turboModules = [];
|
|
@@ -18,31 +118,30 @@ var BasePackageHTemplate = /** @class */ (function () {
|
|
|
18
118
|
this.arkTSEvents = [];
|
|
19
119
|
this.libraryCppNames = new Set();
|
|
20
120
|
}
|
|
21
|
-
|
|
121
|
+
addTurboModule(turboModule) {
|
|
22
122
|
this.turboModules.push(turboModule);
|
|
23
|
-
}
|
|
24
|
-
|
|
123
|
+
}
|
|
124
|
+
addComponent(component) {
|
|
25
125
|
this.components.push(component);
|
|
26
126
|
this.libraryCppNames.add(component.libraryCppName);
|
|
27
|
-
}
|
|
28
|
-
|
|
127
|
+
}
|
|
128
|
+
addArkTSEvent(arkTSEvent) {
|
|
29
129
|
this.arkTSEvents.push(arkTSEvent);
|
|
30
|
-
}
|
|
31
|
-
|
|
130
|
+
}
|
|
131
|
+
build() {
|
|
32
132
|
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
33
|
-
codegenNoticeLines: this.codegenNoticeLines.map(
|
|
34
|
-
line
|
|
35
|
-
})
|
|
133
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
134
|
+
line,
|
|
135
|
+
})),
|
|
36
136
|
name: this.name,
|
|
37
137
|
turboModules: this.turboModules,
|
|
38
138
|
components: this.components,
|
|
39
|
-
arkTSComponents: this.components.filter(
|
|
139
|
+
arkTSComponents: this.components.filter((component) => component.isArkTSComponent),
|
|
40
140
|
arkTSEvents: this.arkTSEvents,
|
|
41
|
-
libraries: Array.from(this.libraryCppNames).map(
|
|
42
|
-
name
|
|
43
|
-
})
|
|
141
|
+
libraries: Array.from(this.libraryCppNames).map((name) => ({
|
|
142
|
+
name,
|
|
143
|
+
})),
|
|
44
144
|
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}());
|
|
145
|
+
}
|
|
146
|
+
}
|
|
48
147
|
exports.BasePackageHTemplate = BasePackageHTemplate;
|
|
@@ -5,19 +5,64 @@
|
|
|
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.ComponentDescriptorHTemplate = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
14
|
+
const TEMPLATE = `
|
|
15
|
+
/**
|
|
16
|
+
* This code was generated by "react-native codegen-harmony"
|
|
17
|
+
*
|
|
18
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
19
|
+
* lost once the code is regenerated.
|
|
20
|
+
*
|
|
21
|
+
* @generatorVersion: 1
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#pragma once
|
|
25
|
+
|
|
26
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
27
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
28
|
+
#include <react/renderer/components/view/ViewShadowNode.h>
|
|
29
|
+
|
|
30
|
+
namespace facebook {
|
|
31
|
+
namespace react {
|
|
32
|
+
|
|
33
|
+
constexpr char {{name}}ComponentName[] = "{{name}}";
|
|
34
|
+
|
|
35
|
+
class {{name}}Props : public ViewProps {
|
|
36
|
+
public:
|
|
37
|
+
{{name}}Props() = default;
|
|
38
|
+
|
|
39
|
+
{{name}}Props(const PropsParserContext &context, const {{name}}Props &sourceProps, const RawProps &rawProps)
|
|
40
|
+
: ViewProps(context, sourceProps, rawProps) {}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
using {{name}}ShadowNode = ConcreteViewShadowNode<
|
|
44
|
+
{{name}}ComponentName,
|
|
45
|
+
{{name}}Props,
|
|
46
|
+
ViewEventEmitter>;
|
|
47
|
+
|
|
48
|
+
class {{name}}ComponentDescriptor final
|
|
49
|
+
: public ConcreteComponentDescriptor<{{name}}ShadowNode> {
|
|
50
|
+
public:
|
|
51
|
+
{{name}}ComponentDescriptor(ComponentDescriptorParameters const ¶meters)
|
|
52
|
+
: ConcreteComponentDescriptor(parameters) {}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace react
|
|
56
|
+
} // namespace facebook
|
|
57
|
+
`;
|
|
58
|
+
class ComponentDescriptorHTemplate {
|
|
59
|
+
constructor(name) {
|
|
14
60
|
this.name = name;
|
|
15
61
|
}
|
|
16
|
-
|
|
62
|
+
build() {
|
|
17
63
|
return mustache_1.default.render(TEMPLATE, {
|
|
18
64
|
name: this.name,
|
|
19
65
|
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
23
68
|
exports.ComponentDescriptorHTemplate = ComponentDescriptorHTemplate;
|
|
@@ -5,54 +5,102 @@
|
|
|
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.ComponentJSIBinderHTemplate = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
14
|
+
const TEMPLATE = `
|
|
15
|
+
/**
|
|
16
|
+
{{#codegenNoticeLines}}
|
|
17
|
+
* {{{line}}}
|
|
18
|
+
{{/codegenNoticeLines}}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#pragma once
|
|
22
|
+
#include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
|
|
23
|
+
|
|
24
|
+
namespace rnoh {
|
|
25
|
+
class {{name}}JSIBinder : public ViewComponentJSIBinder {
|
|
26
|
+
protected:
|
|
27
|
+
facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override {
|
|
28
|
+
auto object = ViewComponentJSIBinder::createNativeProps(rt);
|
|
29
|
+
{{#props}}
|
|
30
|
+
object.setProperty(rt, "{{name}}", {{{type}}});
|
|
31
|
+
{{/props}}
|
|
32
|
+
return object;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
facebook::jsi::Object createCommands(facebook::jsi::Runtime &rt) override {
|
|
36
|
+
auto commands = ViewComponentJSIBinder::createCommands(rt);
|
|
37
|
+
{{#commands}}
|
|
38
|
+
commands.setProperty(rt, "{{name}}", "{{name}}");
|
|
39
|
+
{{/commands}}
|
|
40
|
+
return commands;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
|
|
44
|
+
facebook::jsi::Object events(rt);
|
|
45
|
+
{{#bubblingEvents}}
|
|
46
|
+
events.setProperty(rt, "{{TOPname}}", createBubblingCapturedEvent(rt, "{{name}}"));
|
|
47
|
+
{{/bubblingEvents}}
|
|
48
|
+
return events;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
|
|
52
|
+
facebook::jsi::Object events(rt);
|
|
53
|
+
{{#directEvents}}
|
|
54
|
+
events.setProperty(rt, "{{TOPname}}", createDirectEvent(rt, "{{name}}"));
|
|
55
|
+
{{/directEvents}}
|
|
56
|
+
return events;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
} // namespace rnoh
|
|
60
|
+
`;
|
|
61
|
+
class ComponentJSIBinderHTemplate {
|
|
62
|
+
constructor(name, codegenNoticeLines) {
|
|
14
63
|
this.name = name;
|
|
15
64
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
16
65
|
this.props = [];
|
|
17
66
|
this.commands = [];
|
|
18
67
|
this.events = [];
|
|
19
68
|
}
|
|
20
|
-
|
|
69
|
+
addProp(prop) {
|
|
21
70
|
this.props.push(prop);
|
|
22
|
-
}
|
|
23
|
-
|
|
71
|
+
}
|
|
72
|
+
addCommand(command) {
|
|
24
73
|
this.commands.push(command);
|
|
25
|
-
}
|
|
26
|
-
|
|
74
|
+
}
|
|
75
|
+
addEvent(event) {
|
|
27
76
|
this.events.push(event);
|
|
28
|
-
}
|
|
29
|
-
|
|
77
|
+
}
|
|
78
|
+
build() {
|
|
30
79
|
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
31
|
-
codegenNoticeLines: this.codegenNoticeLines.map(
|
|
32
|
-
line
|
|
33
|
-
})
|
|
80
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
81
|
+
line,
|
|
82
|
+
})),
|
|
34
83
|
name: this.name,
|
|
35
|
-
props: this.props.map(
|
|
84
|
+
props: this.props.map((prop) => ({
|
|
36
85
|
name: prop.name,
|
|
37
86
|
type: prop.isObject ? '"Object"' : 'true',
|
|
38
|
-
})
|
|
39
|
-
commands: this.commands.map(
|
|
87
|
+
})),
|
|
88
|
+
commands: this.commands.map((command) => ({
|
|
40
89
|
name: command.name,
|
|
41
|
-
})
|
|
90
|
+
})),
|
|
42
91
|
bubblingEvents: this.events
|
|
43
|
-
.filter(
|
|
44
|
-
.map(
|
|
92
|
+
.filter((event) => event.type === 'bubble')
|
|
93
|
+
.map((event) => ({
|
|
45
94
|
TOPname: event.eventHandlerName.replace('on', 'top'),
|
|
46
95
|
name: event.eventHandlerName,
|
|
47
|
-
})
|
|
96
|
+
})),
|
|
48
97
|
directEvents: this.events
|
|
49
|
-
.filter(
|
|
50
|
-
.map(
|
|
98
|
+
.filter((event) => event.type === 'direct')
|
|
99
|
+
.map((event) => ({
|
|
51
100
|
TOPname: event.eventHandlerName.replace('on', 'top'),
|
|
52
101
|
name: event.eventHandlerName,
|
|
53
|
-
})
|
|
102
|
+
})),
|
|
54
103
|
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
}());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
58
106
|
exports.ComponentJSIBinderHTemplate = ComponentJSIBinderHTemplate;
|
|
@@ -5,13 +5,148 @@
|
|
|
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.ComponentUtilsTSTemplate = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
14
|
+
const TEMPLATE = `
|
|
15
|
+
/**
|
|
16
|
+
{{#codegenNoticeLines}}
|
|
17
|
+
* {{{line}}}
|
|
18
|
+
{{/codegenNoticeLines}}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
Descriptor as ComponentDescriptor,
|
|
23
|
+
ViewBaseProps,
|
|
24
|
+
ViewRawProps,
|
|
25
|
+
ViewDescriptorWrapperBase,
|
|
26
|
+
ColorValue,
|
|
27
|
+
Color,
|
|
28
|
+
RNInstance,
|
|
29
|
+
Tag,
|
|
30
|
+
RNComponentCommandReceiver,
|
|
31
|
+
ViewPropsSelector,
|
|
32
|
+
} from '{{{rnohImport}}}';
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export namespace {{name}} {
|
|
36
|
+
export const NAME = "{{name}}" as const
|
|
37
|
+
|
|
38
|
+
export interface DirectRawProps {
|
|
39
|
+
{{#props}}
|
|
40
|
+
{{name}}{{optionalityMarker}}: {{{type}}};
|
|
41
|
+
{{/props}}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface Props extends ViewBaseProps {}
|
|
45
|
+
|
|
46
|
+
export interface State {}
|
|
47
|
+
|
|
48
|
+
export interface RawProps extends ViewRawProps, DirectRawProps {}
|
|
49
|
+
|
|
50
|
+
export class PropsSelector extends ViewPropsSelector<Props, RawProps> {
|
|
51
|
+
{{#simpleProps}}
|
|
52
|
+
get {{name}}() {
|
|
53
|
+
return this.rawProps.{{name}}{{{orDefaultValue}}};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
{{/simpleProps}}
|
|
57
|
+
|
|
58
|
+
{{#complexProps}}
|
|
59
|
+
get {{name}}() {
|
|
60
|
+
{{{implementation}}}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
{{/complexProps}}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type Descriptor = ComponentDescriptor<
|
|
67
|
+
typeof NAME,
|
|
68
|
+
Props,
|
|
69
|
+
State,
|
|
70
|
+
RawProps
|
|
71
|
+
>;
|
|
72
|
+
|
|
73
|
+
export class DescriptorWrapper extends ViewDescriptorWrapperBase<
|
|
74
|
+
typeof NAME,
|
|
75
|
+
Props,
|
|
76
|
+
State,
|
|
77
|
+
RawProps,
|
|
78
|
+
PropsSelector
|
|
79
|
+
> {
|
|
80
|
+
protected createPropsSelector() {
|
|
81
|
+
return new PropsSelector(this.descriptor.props, this.descriptor.rawProps)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface EventPayloadByName {
|
|
86
|
+
{{#events}}
|
|
87
|
+
"{{name}}": {{{payloadTSType}}}
|
|
88
|
+
{{/events}}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class EventEmitter {
|
|
92
|
+
constructor(private rnInstance: RNInstance, private tag: Tag) {}
|
|
93
|
+
|
|
94
|
+
emit<TEventName extends keyof EventPayloadByName>(eventName: TEventName, payload: EventPayloadByName[TEventName]) {
|
|
95
|
+
this.rnInstance.emitComponentEvent(this.tag, eventName, payload)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface CommandArgvByName {
|
|
100
|
+
{{#commands}}
|
|
101
|
+
"{{name}}": {{{argsTSType}}}
|
|
102
|
+
{{/commands}}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export class CommandReceiver {
|
|
106
|
+
private listenersByCommandName = new Map<string, Set<(...args: any[]) => void>>()
|
|
107
|
+
private cleanUp: (() => void) | undefined = undefined
|
|
108
|
+
|
|
109
|
+
constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) {
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
subscribe<TCommandName extends keyof CommandArgvByName>(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) {
|
|
113
|
+
if (!this.listenersByCommandName.has(commandName)) {
|
|
114
|
+
this.listenersByCommandName.set(commandName, new Set())
|
|
115
|
+
}
|
|
116
|
+
this.listenersByCommandName.get(commandName)!.add(listener)
|
|
117
|
+
const hasRegisteredCommandReceiver = !!this.cleanUp
|
|
118
|
+
if (!hasRegisteredCommandReceiver) {
|
|
119
|
+
this.cleanUp = this.componentCommandReceiver.registerCommandCallback(this.tag, (commandName: string, argv: any[]) => {
|
|
120
|
+
if (this.listenersByCommandName.has(commandName)) {
|
|
121
|
+
const listeners = this.listenersByCommandName.get(commandName)!
|
|
122
|
+
listeners.forEach(listener => {
|
|
123
|
+
listener(argv)
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return () => {
|
|
130
|
+
this.listenersByCommandName.get(commandName)?.delete(listener)
|
|
131
|
+
if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) {
|
|
132
|
+
this.listenersByCommandName.delete(commandName)
|
|
133
|
+
}
|
|
134
|
+
if (this.listenersByCommandName.size === 0) {
|
|
135
|
+
this.cleanUp?.()
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
const COLOR_VALUE_GETTER_TEMPLATE = ` if (this.rawProps.{{name}}) {
|
|
144
|
+
return Color.fromColorValue(this.rawProps.{{name}})
|
|
145
|
+
} else {
|
|
146
|
+
return new Color({ r: 0, g: 0, b: 0, a: 255})
|
|
147
|
+
}`;
|
|
148
|
+
class ComponentUtilsTSTemplate {
|
|
149
|
+
constructor(name, codegenNoticeLines, rnohImport) {
|
|
15
150
|
this.name = name;
|
|
16
151
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
17
152
|
this.rnohImport = rnohImport;
|
|
@@ -21,45 +156,43 @@ var ComponentUtilsTSTemplate = /** @class */ (function () {
|
|
|
21
156
|
this.getterTemplateByTSType = new Map();
|
|
22
157
|
this.getterTemplateByTSType.set('ColorValue', COLOR_VALUE_GETTER_TEMPLATE);
|
|
23
158
|
}
|
|
24
|
-
|
|
159
|
+
addProp(prop) {
|
|
25
160
|
this.props.push(prop);
|
|
26
|
-
}
|
|
27
|
-
|
|
161
|
+
}
|
|
162
|
+
addEvent(event) {
|
|
28
163
|
this.events.push(event);
|
|
29
|
-
}
|
|
30
|
-
|
|
164
|
+
}
|
|
165
|
+
addCommand(command) {
|
|
31
166
|
this.commands.push(command);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
var _this = this;
|
|
167
|
+
}
|
|
168
|
+
build() {
|
|
35
169
|
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
36
|
-
codegenNoticeLines: this.codegenNoticeLines.map(
|
|
37
|
-
line
|
|
38
|
-
})
|
|
170
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
171
|
+
line,
|
|
172
|
+
})),
|
|
39
173
|
name: this.name,
|
|
40
174
|
rnohImport: this.rnohImport,
|
|
41
|
-
props: this.props.map(
|
|
175
|
+
props: this.props.map((prop) => ({
|
|
42
176
|
name: prop.name,
|
|
43
177
|
type: prop.tsType,
|
|
44
178
|
optionalityMarker: prop.isOptional ? '?' : '',
|
|
45
|
-
})
|
|
179
|
+
})),
|
|
46
180
|
events: this.events,
|
|
47
181
|
commands: this.commands,
|
|
48
182
|
simpleProps: this.props
|
|
49
|
-
.filter(
|
|
50
|
-
.map(
|
|
183
|
+
.filter((prop) => !this.getterTemplateByTSType.has(prop.tsType))
|
|
184
|
+
.map((prop) => ({
|
|
51
185
|
name: prop.name,
|
|
52
186
|
type: prop.tsType,
|
|
53
|
-
orDefaultValue: prop.defaultValue ?
|
|
54
|
-
})
|
|
187
|
+
orDefaultValue: prop.defaultValue ? ` ?? ${prop.defaultValue}` : '',
|
|
188
|
+
})),
|
|
55
189
|
complexProps: this.props
|
|
56
|
-
.filter(
|
|
57
|
-
.map(
|
|
190
|
+
.filter((prop) => this.getterTemplateByTSType.has(prop.tsType))
|
|
191
|
+
.map((prop) => ({
|
|
58
192
|
name: prop.name,
|
|
59
|
-
implementation: mustache_1.default.render(
|
|
60
|
-
})
|
|
193
|
+
implementation: mustache_1.default.render(this.getterTemplateByTSType.get(prop.tsType), { name: prop.name }, {}),
|
|
194
|
+
})),
|
|
61
195
|
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
}());
|
|
196
|
+
}
|
|
197
|
+
}
|
|
65
198
|
exports.ComponentUtilsTSTemplate = ComponentUtilsTSTemplate;
|
|
@@ -5,34 +5,54 @@
|
|
|
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.IndexTSTemplate = void 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
14
|
+
const TEMPLATE = `
|
|
15
|
+
/**
|
|
16
|
+
{{#codegenNoticeLines}}
|
|
17
|
+
* {{{line}}}
|
|
18
|
+
{{/codegenNoticeLines}}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
{{#reexports}}
|
|
22
|
+
export * {{as}}from "{{{from}}}"
|
|
23
|
+
{{/reexports}}
|
|
24
|
+
`;
|
|
25
|
+
const TEMPLATE_EMPTY = `
|
|
26
|
+
/**
|
|
27
|
+
{{#codegenNoticeLines}}
|
|
28
|
+
* {{{line}}}
|
|
29
|
+
{{/codegenNoticeLines}}
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export {}
|
|
33
|
+
`;
|
|
34
|
+
class IndexTSTemplate {
|
|
35
|
+
constructor(codegenNoticeLines) {
|
|
15
36
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
16
37
|
this.reexports = [];
|
|
17
38
|
}
|
|
18
|
-
|
|
39
|
+
addReexport(reexport) {
|
|
19
40
|
this.reexports.push(reexport);
|
|
20
41
|
return this;
|
|
21
|
-
}
|
|
22
|
-
|
|
42
|
+
}
|
|
43
|
+
build() {
|
|
23
44
|
if (this.reexports.length === 0) {
|
|
24
45
|
return mustache_1.default.render(TEMPLATE_EMPTY, {});
|
|
25
46
|
}
|
|
26
47
|
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
27
|
-
codegenNoticeLines: this.codegenNoticeLines.map(
|
|
28
|
-
line
|
|
29
|
-
})
|
|
30
|
-
reexports: this.reexports.map(
|
|
48
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
49
|
+
line,
|
|
50
|
+
})),
|
|
51
|
+
reexports: this.reexports.map((reexport) => ({
|
|
31
52
|
from: reexport.from,
|
|
32
|
-
as: reexport.as ?
|
|
33
|
-
})
|
|
53
|
+
as: reexport.as ? `as ${reexport.as} ` : '',
|
|
54
|
+
})),
|
|
34
55
|
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
}());
|
|
56
|
+
}
|
|
57
|
+
}
|
|
38
58
|
exports.IndexTSTemplate = IndexTSTemplate;
|