@react-native-oh/react-native-harmony-cli 0.0.24 → 0.0.26
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/.prettierrc +6 -6
- package/jest.config.js +5 -5
- package/package.json +57 -52
- package/react-native.config.js +10 -10
- package/src/assetResolver.ts +21 -44
- package/src/codegen/core/CodeGenerator.ts +9 -0
- package/src/codegen/core/CodegenError.ts +3 -3
- package/src/codegen/core/EventUtils.ts +18 -18
- package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -75
- package/src/codegen/core/TypeAnnotationToTS.ts +188 -188
- package/src/codegen/core/UberSchema.ts +142 -99
- package/src/codegen/core/index.ts +5 -5
- package/src/codegen/generators/{ComponentCodeGenerator.ts → ComponentCodeGeneratorArkTS.ts} +112 -98
- package/src/codegen/generators/ComponentCodeGeneratorCAPI.ts +114 -0
- package/src/codegen/generators/GlueCodeGenerator.ts +109 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +115 -95
- package/src/codegen/generators/UberGeneratorV1.ts +64 -0
- package/src/codegen/generators/UberGeneratorV2.ts +91 -0
- package/src/codegen/generators/index.ts +6 -3
- package/src/codegen/index.ts +2 -2
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +116 -0
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +55 -49
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +93 -85
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +210 -202
- package/src/codegen/templates/GeneratedPackageHTemplate.ts +107 -0
- package/src/codegen/templates/IndexTSTemplate.ts +53 -33
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +130 -124
- package/src/codegen/templates/TurboModuleCppTemplate.ts +54 -47
- package/src/codegen/templates/TurboModuleHTemplate.ts +35 -26
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +90 -81
- package/src/codegen/templates/index.ts +9 -8
- package/src/commands/bundle-harmony.ts +203 -202
- package/src/commands/codegen-harmony.ts +272 -143
- package/src/commands/create-metro-host-constants.ts +48 -48
- package/src/commands/index.ts +6 -5
- package/src/commands/pack-harmony.ts +121 -121
- package/src/commands/unpack-harmony.ts +231 -231
- package/src/commands/verify-package-harmony.ts +106 -0
- package/src/core/AbsolutePath.ts +50 -43
- package/src/core/CodegenConfig.ts +62 -54
- package/src/core/DescriptiveError.ts +61 -61
- package/src/core/OHPackageJSON5.ts +23 -0
- package/src/core/PackageJSON.ts +75 -63
- package/src/core/ProjectDependenciesManager.ts +77 -77
- package/src/core/ValidationError.ts +1 -1
- package/src/core/ValueObject.ts +2 -2
- package/src/core/fs.ts +31 -31
- package/src/core/index.ts +9 -8
- package/src/index.ts +20 -18
- package/src/io/Logger.ts +68 -68
- package/src/io/TarGz.ts +26 -0
- package/src/io/fsUtils.ts +24 -24
- package/src/io/index.ts +3 -2
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -0
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -0
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -0
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -0
- package/src/package-verifier/checks/index.ts +4 -0
- package/src/package-verifier/index.ts +2 -0
- package/src/package-verifier/types.ts +12 -0
- package/src/package-verifier/verify-package.ts +117 -0
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
- package/dist/assetResolver.js +0 -41
- package/dist/codegen/core/Codegen.js +0 -35
- package/dist/codegen/core/CodegenError.js +0 -7
- package/dist/codegen/core/EventUtils.js +0 -19
- package/dist/codegen/core/TypeAnnotationToTS.js +0 -132
- package/dist/codegen/core/UberSchema.js +0 -74
- package/dist/codegen/core/index.js +0 -21
- package/dist/codegen/generators/ComponentCodeGenerator.js +0 -66
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +0 -64
- package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
- package/dist/codegen/generators/index.js +0 -19
- package/dist/codegen/index.js +0 -18
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +0 -55
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +0 -78
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -181
- package/dist/codegen/templates/IndexTSTemplate.js +0 -31
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +0 -117
- package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -45
- package/dist/codegen/templates/TurboModuleHTemplate.js +0 -32
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -64
- package/dist/codegen/templates/index.js +0 -24
- package/dist/commands/bundle-harmony.js +0 -179
- package/dist/commands/codegen-harmony.js +0 -110
- package/dist/commands/create-metro-host-constants.js +0 -61
- package/dist/commands/index.js +0 -21
- package/dist/commands/pack-harmony.js +0 -100
- package/dist/commands/unpack-harmony.js +0 -184
- package/dist/core/AbsolutePath.js +0 -41
- package/dist/core/CodegenConfig.js +0 -53
- package/dist/core/DescriptiveError.js +0 -49
- package/dist/core/PackageJSON.js +0 -53
- package/dist/core/ProjectDependenciesManager.js +0 -70
- package/dist/core/ValidationError.js +0 -6
- package/dist/core/ValueObject.js +0 -2
- package/dist/core/fs.js +0 -36
- package/dist/core/index.js +0 -24
- package/dist/index.js +0 -13
- package/dist/io/Logger.js +0 -71
- package/dist/io/fsUtils.js +0 -23
- package/dist/io/index.js +0 -18
- package/src/codegen/core/Codegen.ts +0 -44
- package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ComponentUtilsTSTemplate = void 0;
|
|
7
|
-
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
-
const TEMPLATE = `
|
|
9
|
-
// This file was generated.
|
|
10
|
-
import {
|
|
11
|
-
Descriptor as ComponentDescriptor,
|
|
12
|
-
ViewBaseProps,
|
|
13
|
-
ViewRawProps,
|
|
14
|
-
ViewDescriptorWrapperBase,
|
|
15
|
-
ColorValue,
|
|
16
|
-
Color,
|
|
17
|
-
RNInstance,
|
|
18
|
-
Tag,
|
|
19
|
-
RNComponentCommandReceiver,
|
|
20
|
-
ViewPropsSelector,
|
|
21
|
-
} from '../../ts';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export namespace {{name}} {
|
|
25
|
-
export const NAME = "{{name}}" as const
|
|
26
|
-
|
|
27
|
-
export interface DirectRawProps {
|
|
28
|
-
{{#props}}
|
|
29
|
-
{{name}}{{optionalityMarker}}: {{{type}}};
|
|
30
|
-
{{/props}}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface Props extends ViewBaseProps {}
|
|
34
|
-
|
|
35
|
-
export interface State {}
|
|
36
|
-
|
|
37
|
-
export interface RawProps extends ViewRawProps, DirectRawProps {}
|
|
38
|
-
|
|
39
|
-
export class PropsSelector extends ViewPropsSelector<Props, RawProps> {
|
|
40
|
-
{{#simpleProps}}
|
|
41
|
-
get {{name}}() {
|
|
42
|
-
return this.rawProps.{{name}}{{{orDefaultValue}}};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
{{/simpleProps}}
|
|
46
|
-
|
|
47
|
-
{{#complexProps}}
|
|
48
|
-
get {{name}}() {
|
|
49
|
-
{{{implementation}}}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
{{/complexProps}}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export type Descriptor = ComponentDescriptor<
|
|
56
|
-
typeof NAME,
|
|
57
|
-
Props,
|
|
58
|
-
State,
|
|
59
|
-
RawProps
|
|
60
|
-
>;
|
|
61
|
-
|
|
62
|
-
export class DescriptorWrapper extends ViewDescriptorWrapperBase<
|
|
63
|
-
typeof NAME,
|
|
64
|
-
Props,
|
|
65
|
-
State,
|
|
66
|
-
RawProps,
|
|
67
|
-
PropsSelector
|
|
68
|
-
> {
|
|
69
|
-
protected createPropsSelector() {
|
|
70
|
-
return new PropsSelector(this.descriptor.props, this.descriptor.rawProps)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface EventPayloadByName {
|
|
75
|
-
{{#events}}
|
|
76
|
-
"{{name}}": {{{payloadTSType}}}
|
|
77
|
-
{{/events}}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export class EventEmitter {
|
|
81
|
-
constructor(private rnInstance: RNInstance, private tag: Tag) {}
|
|
82
|
-
|
|
83
|
-
emit<TEventName extends keyof EventPayloadByName>(eventName: TEventName, payload: EventPayloadByName[TEventName]) {
|
|
84
|
-
this.rnInstance.emitComponentEvent(this.tag, eventName, payload)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface CommandArgvByName {
|
|
89
|
-
{{#commands}}
|
|
90
|
-
"{{name}}": {{{argsTSType}}}
|
|
91
|
-
{{/commands}}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export class CommandReceiver {
|
|
95
|
-
private listenersByCommandName = new Map<string, Set<(...args: any[]) => void>>()
|
|
96
|
-
private cleanUp: (() => void) | undefined = undefined
|
|
97
|
-
|
|
98
|
-
constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) {
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
subscribe<TCommandName extends keyof CommandArgvByName>(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) {
|
|
102
|
-
if (!this.listenersByCommandName.has(commandName)) {
|
|
103
|
-
this.listenersByCommandName.set(commandName, new Set())
|
|
104
|
-
}
|
|
105
|
-
this.listenersByCommandName.get(commandName)!.add(listener)
|
|
106
|
-
const hasRegisteredCommandReceiver = !!this.cleanUp
|
|
107
|
-
if (!hasRegisteredCommandReceiver) {
|
|
108
|
-
this.cleanUp = this.componentCommandReceiver.registerCommandCallback(this.tag, (commandName: string, argv: any[]) => {
|
|
109
|
-
if (this.listenersByCommandName.has(commandName)) {
|
|
110
|
-
const listeners = this.listenersByCommandName.get(commandName)!
|
|
111
|
-
listeners.forEach(listener => {
|
|
112
|
-
listener(argv)
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return () => {
|
|
119
|
-
this.listenersByCommandName.get(commandName)?.delete(listener)
|
|
120
|
-
if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) {
|
|
121
|
-
this.listenersByCommandName.delete(commandName)
|
|
122
|
-
}
|
|
123
|
-
if (this.listenersByCommandName.size === 0) {
|
|
124
|
-
this.cleanUp?.()
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
`;
|
|
132
|
-
const COLOR_VALUE_GETTER_TEMPLATE = ` if (this.rawProps.{{name}}) {
|
|
133
|
-
return Color.fromColorValue(this.rawProps.{{name}})
|
|
134
|
-
} else {
|
|
135
|
-
return new Color({ r: 0, g: 0, b: 0, a: 255})
|
|
136
|
-
}`;
|
|
137
|
-
class ComponentUtilsTSTemplate {
|
|
138
|
-
constructor(name) {
|
|
139
|
-
this.name = name;
|
|
140
|
-
this.props = [];
|
|
141
|
-
this.events = [];
|
|
142
|
-
this.commands = [];
|
|
143
|
-
this.getterTemplateByTSType = new Map();
|
|
144
|
-
this.getterTemplateByTSType.set('ColorValue', COLOR_VALUE_GETTER_TEMPLATE);
|
|
145
|
-
}
|
|
146
|
-
addProp(prop) {
|
|
147
|
-
this.props.push(prop);
|
|
148
|
-
}
|
|
149
|
-
addEvent(event) {
|
|
150
|
-
this.events.push(event);
|
|
151
|
-
}
|
|
152
|
-
addCommand(command) {
|
|
153
|
-
this.commands.push(command);
|
|
154
|
-
}
|
|
155
|
-
build() {
|
|
156
|
-
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
157
|
-
name: this.name,
|
|
158
|
-
props: this.props.map((prop) => ({
|
|
159
|
-
name: prop.name,
|
|
160
|
-
type: prop.tsType,
|
|
161
|
-
optionalityMarker: prop.isOptional ? '?' : '',
|
|
162
|
-
})),
|
|
163
|
-
events: this.events,
|
|
164
|
-
commands: this.commands,
|
|
165
|
-
simpleProps: this.props
|
|
166
|
-
.filter((prop) => !this.getterTemplateByTSType.has(prop.tsType))
|
|
167
|
-
.map((prop) => ({
|
|
168
|
-
name: prop.name,
|
|
169
|
-
type: prop.tsType,
|
|
170
|
-
orDefaultValue: prop.defaultValue ? ` ?? ${prop.defaultValue}` : '',
|
|
171
|
-
})),
|
|
172
|
-
complexProps: this.props
|
|
173
|
-
.filter((prop) => this.getterTemplateByTSType.has(prop.tsType))
|
|
174
|
-
.map((prop) => ({
|
|
175
|
-
name: prop.name,
|
|
176
|
-
implementation: mustache_1.default.render(this.getterTemplateByTSType.get(prop.tsType), { name: prop.name }, {}),
|
|
177
|
-
})),
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
exports.ComponentUtilsTSTemplate = ComponentUtilsTSTemplate;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.IndexTSTemplate = void 0;
|
|
7
|
-
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
-
const TEMPLATE = `
|
|
9
|
-
// This file was generated.
|
|
10
|
-
{{#reexports}}
|
|
11
|
-
export * {{as}}from "{{{from}}}"
|
|
12
|
-
{{/reexports}}
|
|
13
|
-
`;
|
|
14
|
-
class IndexTSTemplate {
|
|
15
|
-
constructor() {
|
|
16
|
-
this.reexports = [];
|
|
17
|
-
}
|
|
18
|
-
addReexport(reexport) {
|
|
19
|
-
this.reexports.push(reexport);
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
build() {
|
|
23
|
-
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
24
|
-
reexports: this.reexports.map((reexport) => ({
|
|
25
|
-
from: reexport.from,
|
|
26
|
-
as: reexport.as ? `as ${reexport.as} ` : '',
|
|
27
|
-
})),
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.IndexTSTemplate = IndexTSTemplate;
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.RNOHGeneratedPackageHTemplate = void 0;
|
|
7
|
-
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
-
const TEMPLATE = `
|
|
9
|
-
#pragma once
|
|
10
|
-
|
|
11
|
-
// This file was generated.
|
|
12
|
-
|
|
13
|
-
#include "RNOH/Package.h"
|
|
14
|
-
#include "RNOH/ArkTSTurboModule.h"
|
|
15
|
-
{{#turboModules}}
|
|
16
|
-
#include "generated/{{name}}.h"
|
|
17
|
-
{{/turboModules}}
|
|
18
|
-
{{#components}}
|
|
19
|
-
#include "generated/{{name}}ComponentDescriptor.h"
|
|
20
|
-
{{/components}}
|
|
21
|
-
{{#components}}
|
|
22
|
-
#include "generated/{{name}}JSIBinder.h"
|
|
23
|
-
{{/components}}
|
|
24
|
-
|
|
25
|
-
namespace rnoh {
|
|
26
|
-
|
|
27
|
-
class RNOHGeneratedPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
28
|
-
public:
|
|
29
|
-
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
|
30
|
-
{{#turboModules}}
|
|
31
|
-
if (name == "{{name}}") {
|
|
32
|
-
return std::make_shared<{{name}}>(ctx, name);
|
|
33
|
-
}
|
|
34
|
-
{{/turboModules}}
|
|
35
|
-
return nullptr;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
class GeneratedEventEmitRequestHandler : public EventEmitRequestHandler {
|
|
40
|
-
public:
|
|
41
|
-
void handleEvent(Context const &ctx) override {
|
|
42
|
-
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
43
|
-
if (eventEmitter == nullptr) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
std::vector<std::string> supportedEventNames = {
|
|
48
|
-
{{#supportedEvents}}
|
|
49
|
-
"{{name}}",
|
|
50
|
-
{{/supportedEvents}}
|
|
51
|
-
};
|
|
52
|
-
if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
53
|
-
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
class RNOHGeneratedPackage : public Package {
|
|
59
|
-
public:
|
|
60
|
-
RNOHGeneratedPackage(Package::Context ctx) : Package(ctx){};
|
|
61
|
-
|
|
62
|
-
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
|
63
|
-
return std::make_unique<RNOHGeneratedPackageTurboModuleFactoryDelegate>();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
|
|
67
|
-
return {
|
|
68
|
-
{{#components}}
|
|
69
|
-
facebook::react::concreteComponentDescriptorProvider<facebook::react::{{name}}ComponentDescriptor>(),
|
|
70
|
-
{{/components}}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
ComponentJSIBinderByString createComponentJSIBinderByName() override {
|
|
75
|
-
return {
|
|
76
|
-
{{#components}}
|
|
77
|
-
{"{{name}}", std::make_shared<{{name}}JSIBinder>()},
|
|
78
|
-
{{/components}}
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
83
|
-
return {
|
|
84
|
-
std::make_shared<GeneratedEventEmitRequestHandler>(),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
} // namespace rnoh
|
|
90
|
-
`;
|
|
91
|
-
class RNOHGeneratedPackageHTemplate {
|
|
92
|
-
constructor() {
|
|
93
|
-
this.turboModules = [];
|
|
94
|
-
this.components = [];
|
|
95
|
-
this.supportedEventNames = [];
|
|
96
|
-
}
|
|
97
|
-
addTurboModule(turboModule) {
|
|
98
|
-
this.turboModules.push(turboModule);
|
|
99
|
-
}
|
|
100
|
-
addComponent(component) {
|
|
101
|
-
this.components.push(component);
|
|
102
|
-
this.supportedEventNames = [
|
|
103
|
-
...this.supportedEventNames,
|
|
104
|
-
...component.supportedEventNames,
|
|
105
|
-
];
|
|
106
|
-
}
|
|
107
|
-
build() {
|
|
108
|
-
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
109
|
-
turboModules: this.turboModules,
|
|
110
|
-
components: this.components,
|
|
111
|
-
supportedEvents: this.supportedEventNames.map((eventName) => ({
|
|
112
|
-
name: eventName,
|
|
113
|
-
})),
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.RNOHGeneratedPackageHTemplate = RNOHGeneratedPackageHTemplate;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TurboModuleCppTemplate = void 0;
|
|
7
|
-
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
-
const TEMPLATE = `
|
|
9
|
-
#include "{{className}}.h"
|
|
10
|
-
|
|
11
|
-
// This file was generated.
|
|
12
|
-
|
|
13
|
-
namespace rnoh {
|
|
14
|
-
using namespace facebook;
|
|
15
|
-
|
|
16
|
-
{{className}}::{{className}}(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) {
|
|
17
|
-
methodMap_ = {
|
|
18
|
-
{{#methods}}
|
|
19
|
-
ARK_{{asyncMarker}}METHOD_METADATA({{name}}, {{argsCount}}),
|
|
20
|
-
{{/methods}}
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
} // namespace rnoh
|
|
25
|
-
`;
|
|
26
|
-
class TurboModuleCppTemplate {
|
|
27
|
-
constructor(name) {
|
|
28
|
-
this.name = name;
|
|
29
|
-
this.methods = [];
|
|
30
|
-
}
|
|
31
|
-
addMethod(method) {
|
|
32
|
-
this.methods.push(method);
|
|
33
|
-
}
|
|
34
|
-
build() {
|
|
35
|
-
return mustache_1.default.render(TEMPLATE, {
|
|
36
|
-
className: this.name,
|
|
37
|
-
methods: this.methods.map((method) => ({
|
|
38
|
-
name: method.name,
|
|
39
|
-
argsCount: method.argsCount,
|
|
40
|
-
asyncMarker: method.isAsync ? 'ASYNC_' : undefined,
|
|
41
|
-
})),
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.TurboModuleCppTemplate = TurboModuleCppTemplate;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TurboModuleHTemplate = void 0;
|
|
7
|
-
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
-
const TEMPLATE = `
|
|
9
|
-
#pragma once
|
|
10
|
-
|
|
11
|
-
// This file was generated.
|
|
12
|
-
|
|
13
|
-
#include "RNOH/ArkTSTurboModule.h"
|
|
14
|
-
|
|
15
|
-
namespace rnoh {
|
|
16
|
-
|
|
17
|
-
class JSI_EXPORT {{className}} : public ArkTSTurboModule {
|
|
18
|
-
public:
|
|
19
|
-
{{className}}(const ArkTSTurboModule::Context ctx, const std::string name);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
} // namespace rnoh
|
|
23
|
-
`;
|
|
24
|
-
class TurboModuleHTemplate {
|
|
25
|
-
constructor(name) {
|
|
26
|
-
this.name = name;
|
|
27
|
-
}
|
|
28
|
-
build() {
|
|
29
|
-
return mustache_1.default.render(TEMPLATE, { className: this.name });
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.TurboModuleHTemplate = TurboModuleHTemplate;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TurboModuleInterfaceTS = void 0;
|
|
7
|
-
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
-
const TEMPLATE = `
|
|
9
|
-
// This file was generated.
|
|
10
|
-
import { Tag } from "../../ts"
|
|
11
|
-
|
|
12
|
-
export namespace {{name}} {
|
|
13
|
-
export const NAME = '{{name}}' as const
|
|
14
|
-
|
|
15
|
-
{{#enums}}
|
|
16
|
-
export enum {{name}} {
|
|
17
|
-
{{#members}}
|
|
18
|
-
{{name}} = {{{value}}},
|
|
19
|
-
{{/members}}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
{{/enums}}
|
|
23
|
-
{{#aliases}}
|
|
24
|
-
export type {{name}} = {{{type}}}
|
|
25
|
-
|
|
26
|
-
{{/aliases}}
|
|
27
|
-
export interface Spec {
|
|
28
|
-
{{#methods}}
|
|
29
|
-
{{name}}({{{stringifiedArgs}}}): {{{returnType}}};
|
|
30
|
-
|
|
31
|
-
{{/methods}}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
`;
|
|
35
|
-
class TurboModuleInterfaceTS {
|
|
36
|
-
constructor(name) {
|
|
37
|
-
this.name = name;
|
|
38
|
-
this.methods = [];
|
|
39
|
-
this.aliases = [];
|
|
40
|
-
this.enumModels = [];
|
|
41
|
-
}
|
|
42
|
-
addAlias(alias) {
|
|
43
|
-
this.aliases.push(alias);
|
|
44
|
-
}
|
|
45
|
-
addEnum(enumModel) {
|
|
46
|
-
this.enumModels.push(enumModel);
|
|
47
|
-
}
|
|
48
|
-
addMethod(method) {
|
|
49
|
-
this.methods.push(method);
|
|
50
|
-
}
|
|
51
|
-
build() {
|
|
52
|
-
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
53
|
-
name: this.name,
|
|
54
|
-
aliases: this.aliases,
|
|
55
|
-
enums: this.enumModels,
|
|
56
|
-
methods: this.methods.map((method) => ({
|
|
57
|
-
name: method.name,
|
|
58
|
-
stringifiedArgs: method.stringifiedArgs,
|
|
59
|
-
returnType: method.returnType,
|
|
60
|
-
})),
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.TurboModuleInterfaceTS = TurboModuleInterfaceTS;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./TurboModuleHTemplate"), exports);
|
|
18
|
-
__exportStar(require("./TurboModuleCppTemplate"), exports);
|
|
19
|
-
__exportStar(require("./RNOHGeneratedPackageHTemplate"), exports);
|
|
20
|
-
__exportStar(require("./ComponentJSIBinderHTemplate"), exports);
|
|
21
|
-
__exportStar(require("./ComponentDescriptorHTemplate"), exports);
|
|
22
|
-
__exportStar(require("./ComponentUtilsTSTemplate"), exports);
|
|
23
|
-
__exportStar(require("./IndexTSTemplate"), exports);
|
|
24
|
-
__exportStar(require("./TurboModuleSpecTSTemplate"), exports);
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.commandBundleHarmony = void 0;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
-
const metro_1 = __importDefault(require("metro"));
|
|
19
|
-
const Server_1 = __importDefault(require("metro/src/Server"));
|
|
20
|
-
const path_1 = __importDefault(require("path"));
|
|
21
|
-
const assetResolver_1 = require("../assetResolver");
|
|
22
|
-
const ARK_RESOURCE_PATH = './harmony/entry/src/main/resources/rawfile';
|
|
23
|
-
const ASSETS_DEFAULT_DEST_PATH = './harmony/entry/src/main/resources/rawfile/assets';
|
|
24
|
-
exports.commandBundleHarmony = {
|
|
25
|
-
name: 'bundle-harmony',
|
|
26
|
-
description: 'Creates JS bundle, creates a special cpp header containing the JS code, copies assets directory to the project.',
|
|
27
|
-
options: [
|
|
28
|
-
{
|
|
29
|
-
name: '--dev [boolean]',
|
|
30
|
-
description: 'If false, warnings are disabled and the bundle is minified',
|
|
31
|
-
parse: (val) => val !== 'false',
|
|
32
|
-
default: true,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: '--entry-file <path>',
|
|
36
|
-
description: 'Path to the root JS file, either absolute or relative to JS root',
|
|
37
|
-
default: 'index.js',
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: '--config <path>',
|
|
41
|
-
description: 'Path to the Metro configuration file',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: '--bundle-output <path>',
|
|
45
|
-
description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
|
|
46
|
-
default: ARK_RESOURCE_PATH + '/bundle.harmony.js',
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: '--assets-dest <path>',
|
|
50
|
-
description: 'Directory name where to store assets referenced in the bundle',
|
|
51
|
-
default: ASSETS_DEFAULT_DEST_PATH,
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: '--sourcemap-output <path>',
|
|
55
|
-
description: 'File name where to store the resulting source map, ex. /tmp/groups.map',
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
name: '--minify [boolean]',
|
|
59
|
-
description: 'Allows overriding whether bundle is minified',
|
|
60
|
-
parse: (val) => val !== 'false',
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
-
const buildOptions = {
|
|
65
|
-
entry: args.entryFile,
|
|
66
|
-
platform: 'harmony',
|
|
67
|
-
minify: args.minify !== undefined ? args.minify : !args.dev,
|
|
68
|
-
dev: args.dev,
|
|
69
|
-
sourceMap: args.sourcemapOutput,
|
|
70
|
-
sourceMapUrl: args.sourcemapOutput,
|
|
71
|
-
};
|
|
72
|
-
const metroConfig = yield loadMetroConfig(args.config);
|
|
73
|
-
const bundle = yield createBundle(metroConfig, buildOptions);
|
|
74
|
-
yield saveBundle(bundle, args.bundleOutput, args.sourcemapOutput);
|
|
75
|
-
const assets = yield retrieveAssetsData(metroConfig, buildOptions);
|
|
76
|
-
copyAssets(assets, args.assetsDest);
|
|
77
|
-
}),
|
|
78
|
-
};
|
|
79
|
-
function loadMetroConfig(configPath) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
return configPath
|
|
82
|
-
? yield metro_1.default.loadConfig({ config: configPath })
|
|
83
|
-
: yield metro_1.default.loadConfig();
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
function createBundle(metroConfig, buildOptions) {
|
|
87
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
// casting needed as Metro.runBuild returns Promise<{code: string, map: string}>
|
|
89
|
-
// despite being typed as Promise<void>
|
|
90
|
-
return (yield metro_1.default.runBuild(metroConfig, buildOptions));
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
function saveBundle(bundle, bundleOutput, sourceMapOutput) {
|
|
94
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
yield fs_extra_1.default.ensureDir(path_1.default.dirname(bundleOutput));
|
|
96
|
-
fs_1.default.writeFileSync(bundleOutput, bundle.code);
|
|
97
|
-
console.log(`[CREATED] ${bundleOutput}`);
|
|
98
|
-
if (sourceMapOutput) {
|
|
99
|
-
fs_1.default.writeFileSync(sourceMapOutput, bundle.map);
|
|
100
|
-
console.log(`[CREATED] ${sourceMapOutput}`);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
function retrieveAssetsData(metroConfig, buildOptions) {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const metroServer = new Server_1.default(metroConfig);
|
|
107
|
-
try {
|
|
108
|
-
return yield metroServer.getAssets(Object.assign(Object.assign(Object.assign({}, Server_1.default.DEFAULT_BUNDLE_OPTIONS), buildOptions), { entryFile: buildOptions.entry, bundleType: 'todo' }));
|
|
109
|
-
}
|
|
110
|
-
finally {
|
|
111
|
-
metroServer.end();
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
function copyAssets(assetsData, assetsDest) {
|
|
116
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
if (assetsDest == null) {
|
|
118
|
-
console.warn('Assets destination folder is not set, skipping...');
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
yield fs_extra_1.default.ensureDir(assetsDest);
|
|
122
|
-
const fileDestBySrc = {};
|
|
123
|
-
for (const asset of assetsData) {
|
|
124
|
-
const idx = getHighestQualityFileIdx(asset);
|
|
125
|
-
fileDestBySrc[asset.files[idx]] = path_1.default.join(assetsDest, (0, assetResolver_1.getAssetDestRelativePath)(asset));
|
|
126
|
-
}
|
|
127
|
-
return copyFiles(fileDestBySrc);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
function getHighestQualityFileIdx(assetData) {
|
|
131
|
-
let result = 0;
|
|
132
|
-
let maxScale = -1;
|
|
133
|
-
for (let idx = 0; idx < assetData.scales.length; idx++) {
|
|
134
|
-
const scale = assetData.scales[idx];
|
|
135
|
-
if (scale > maxScale) {
|
|
136
|
-
maxScale = scale;
|
|
137
|
-
result = idx;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
function copyFiles(fileDestBySrc) {
|
|
143
|
-
const fileSources = Object.keys(fileDestBySrc);
|
|
144
|
-
if (fileSources.length === 0) {
|
|
145
|
-
return Promise.resolve();
|
|
146
|
-
}
|
|
147
|
-
console.info(`Copying ${fileSources.length} asset files`);
|
|
148
|
-
return new Promise((resolve, reject) => {
|
|
149
|
-
const copyNext = (error) => {
|
|
150
|
-
if (error) {
|
|
151
|
-
reject(error);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (fileSources.length === 0) {
|
|
155
|
-
console.info('Done copying assets');
|
|
156
|
-
resolve();
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
// fileSources.length === 0 is checked in previous branch, so this is string
|
|
160
|
-
const src = fileSources.shift();
|
|
161
|
-
const dest = fileDestBySrc[src];
|
|
162
|
-
copyFile(src, dest, copyNext);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
copyNext();
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
function copyFile(src, dest, onFinished) {
|
|
169
|
-
const destDir = path_1.default.dirname(dest);
|
|
170
|
-
fs_1.default.mkdir(destDir, { recursive: true }, (err) => {
|
|
171
|
-
if (err) {
|
|
172
|
-
onFinished(err);
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
fs_1.default.createReadStream(src)
|
|
176
|
-
.pipe(fs_1.default.createWriteStream(dest))
|
|
177
|
-
.on('finish', onFinished);
|
|
178
|
-
});
|
|
179
|
-
}
|