@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
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RNOHGeneratedPackageHTemplate = void 0;
|
|
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 "RNOH/Package.h"
|
|
27
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
28
|
+
{{#turboModules}}
|
|
29
|
+
#include "generated/{{name}}.h"
|
|
30
|
+
{{/turboModules}}
|
|
31
|
+
{{#components}}
|
|
32
|
+
#include "generated/{{name}}ComponentDescriptor.h"
|
|
33
|
+
{{/components}}
|
|
34
|
+
{{#components}}
|
|
35
|
+
#include "generated/{{name}}JSIBinder.h"
|
|
36
|
+
{{/components}}
|
|
37
|
+
|
|
38
|
+
namespace rnoh {
|
|
39
|
+
|
|
40
|
+
class RNOHGeneratedPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
41
|
+
public:
|
|
42
|
+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
|
43
|
+
{{#turboModules}}
|
|
44
|
+
if (name == "{{name}}") {
|
|
45
|
+
return std::make_shared<{{name}}>(ctx, name);
|
|
46
|
+
}
|
|
47
|
+
{{/turboModules}}
|
|
48
|
+
return nullptr;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
class GeneratedEventEmitRequestHandler : public EventEmitRequestHandler {
|
|
53
|
+
public:
|
|
54
|
+
void handleEvent(Context const &ctx) override {
|
|
55
|
+
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
56
|
+
if (eventEmitter == nullptr) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
std::vector<std::string> supportedEventNames = {
|
|
61
|
+
{{#supportedEvents}}
|
|
62
|
+
"{{name}}",
|
|
63
|
+
{{/supportedEvents}}
|
|
64
|
+
};
|
|
65
|
+
if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
66
|
+
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
class RNOHGeneratedPackage : public Package {
|
|
72
|
+
public:
|
|
73
|
+
RNOHGeneratedPackage(Package::Context ctx) : Package(ctx){};
|
|
74
|
+
|
|
75
|
+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
|
76
|
+
return std::make_unique<RNOHGeneratedPackageTurboModuleFactoryDelegate>();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
|
|
80
|
+
return {
|
|
81
|
+
{{#components}}
|
|
82
|
+
facebook::react::concreteComponentDescriptorProvider<facebook::react::{{name}}ComponentDescriptor>(),
|
|
83
|
+
{{/components}}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
ComponentJSIBinderByString createComponentJSIBinderByName() override {
|
|
88
|
+
return {
|
|
89
|
+
{{#components}}
|
|
90
|
+
{"{{name}}", std::make_shared<{{name}}JSIBinder>()},
|
|
91
|
+
{{/components}}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
96
|
+
return {
|
|
97
|
+
std::make_shared<GeneratedEventEmitRequestHandler>(),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
} // namespace rnoh
|
|
103
|
+
`;
|
|
104
|
+
class RNOHGeneratedPackageHTemplate {
|
|
105
|
+
constructor() {
|
|
106
|
+
this.turboModules = [];
|
|
107
|
+
this.components = [];
|
|
108
|
+
this.supportedEventNames = [];
|
|
109
|
+
}
|
|
110
|
+
addTurboModule(turboModule) {
|
|
111
|
+
this.turboModules.push(turboModule);
|
|
112
|
+
}
|
|
113
|
+
addComponent(component) {
|
|
114
|
+
this.components.push(component);
|
|
115
|
+
this.supportedEventNames = [
|
|
116
|
+
...this.supportedEventNames,
|
|
117
|
+
...component.supportedEventNames,
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
build() {
|
|
121
|
+
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
122
|
+
turboModules: this.turboModules,
|
|
123
|
+
components: this.components,
|
|
124
|
+
supportedEvents: this.supportedEventNames.map((eventName) => ({
|
|
125
|
+
name: eventName,
|
|
126
|
+
})),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.RNOHGeneratedPackageHTemplate = RNOHGeneratedPackageHTemplate;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TurboModuleCppTemplate = void 0;
|
|
13
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
14
|
+
const TEMPLATE = `
|
|
15
|
+
/**
|
|
16
|
+
{{#codegenNoticeLines}}
|
|
17
|
+
* {{{line}}}
|
|
18
|
+
{{/codegenNoticeLines}}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#include "{{className}}.h"
|
|
22
|
+
|
|
23
|
+
namespace rnoh {
|
|
24
|
+
using namespace facebook;
|
|
25
|
+
|
|
26
|
+
{{className}}::{{className}}(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) {
|
|
27
|
+
methodMap_ = {
|
|
28
|
+
{{#methods}}
|
|
29
|
+
ARK_{{asyncMarker}}METHOD_METADATA({{name}}, {{argsCount}}),
|
|
30
|
+
{{/methods}}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
} // namespace rnoh
|
|
35
|
+
`;
|
|
36
|
+
class TurboModuleCppTemplate {
|
|
37
|
+
constructor(name, codegenNoticeLines) {
|
|
38
|
+
this.name = name;
|
|
39
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
40
|
+
this.methods = [];
|
|
41
|
+
}
|
|
42
|
+
addMethod(method) {
|
|
43
|
+
this.methods.push(method);
|
|
44
|
+
}
|
|
45
|
+
build() {
|
|
46
|
+
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
47
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
48
|
+
line,
|
|
49
|
+
})),
|
|
50
|
+
className: this.name,
|
|
51
|
+
methods: this.methods.map((method) => ({
|
|
52
|
+
name: method.name,
|
|
53
|
+
argsCount: method.argsCount,
|
|
54
|
+
asyncMarker: method.isAsync ? 'ASYNC_' : undefined,
|
|
55
|
+
})),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.TurboModuleCppTemplate = TurboModuleCppTemplate;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TurboModuleHTemplate = void 0;
|
|
13
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
14
|
+
const TEMPLATE = `
|
|
15
|
+
/**
|
|
16
|
+
{{#codegenNoticeLines}}
|
|
17
|
+
* {{{line}}}
|
|
18
|
+
{{/codegenNoticeLines}}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#pragma once
|
|
22
|
+
|
|
23
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
24
|
+
|
|
25
|
+
namespace rnoh {
|
|
26
|
+
|
|
27
|
+
class JSI_EXPORT {{className}} : public ArkTSTurboModule {
|
|
28
|
+
public:
|
|
29
|
+
{{className}}(const ArkTSTurboModule::Context ctx, const std::string name);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
} // namespace rnoh
|
|
33
|
+
`;
|
|
34
|
+
class TurboModuleHTemplate {
|
|
35
|
+
constructor(name, codegenNoticeLines) {
|
|
36
|
+
this.name = name;
|
|
37
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
38
|
+
}
|
|
39
|
+
build() {
|
|
40
|
+
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
41
|
+
className: this.name,
|
|
42
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
43
|
+
line,
|
|
44
|
+
})),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.TurboModuleHTemplate = TurboModuleHTemplate;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TurboModuleInterfaceTS = void 0;
|
|
13
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
14
|
+
const TEMPLATE = `
|
|
15
|
+
/**
|
|
16
|
+
{{#codegenNoticeLines}}
|
|
17
|
+
* {{{line}}}
|
|
18
|
+
{{/codegenNoticeLines}}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { Tag } from "{{{rnohImport}}}"
|
|
22
|
+
|
|
23
|
+
export namespace {{name}} {
|
|
24
|
+
export const NAME = '{{name}}' as const
|
|
25
|
+
|
|
26
|
+
{{#enums}}
|
|
27
|
+
export enum {{name}} {
|
|
28
|
+
{{#members}}
|
|
29
|
+
{{name}} = {{{value}}},
|
|
30
|
+
{{/members}}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
{{/enums}}
|
|
34
|
+
{{#aliases}}
|
|
35
|
+
export type {{name}} = {{{type}}}
|
|
36
|
+
|
|
37
|
+
{{/aliases}}
|
|
38
|
+
export interface Spec {
|
|
39
|
+
{{#methods}}
|
|
40
|
+
{{name}}({{{stringifiedArgs}}}): {{{returnType}}};
|
|
41
|
+
|
|
42
|
+
{{/methods}}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
class TurboModuleInterfaceTS {
|
|
47
|
+
constructor(name, codegenNoticeLines, rnohImport) {
|
|
48
|
+
this.name = name;
|
|
49
|
+
this.codegenNoticeLines = codegenNoticeLines;
|
|
50
|
+
this.rnohImport = rnohImport;
|
|
51
|
+
this.methods = [];
|
|
52
|
+
this.aliases = [];
|
|
53
|
+
this.enumModels = [];
|
|
54
|
+
}
|
|
55
|
+
addAlias(alias) {
|
|
56
|
+
this.aliases.push(alias);
|
|
57
|
+
}
|
|
58
|
+
addEnum(enumModel) {
|
|
59
|
+
this.enumModels.push(enumModel);
|
|
60
|
+
}
|
|
61
|
+
addMethod(method) {
|
|
62
|
+
this.methods.push(method);
|
|
63
|
+
}
|
|
64
|
+
build() {
|
|
65
|
+
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
66
|
+
codegenNoticeLines: this.codegenNoticeLines.map((line) => ({
|
|
67
|
+
line,
|
|
68
|
+
})),
|
|
69
|
+
name: this.name,
|
|
70
|
+
aliases: this.aliases,
|
|
71
|
+
enums: this.enumModels,
|
|
72
|
+
rnohImport: this.rnohImport,
|
|
73
|
+
methods: this.methods.map((method) => ({
|
|
74
|
+
name: method.name,
|
|
75
|
+
stringifiedArgs: method.stringifiedArgs,
|
|
76
|
+
returnType: method.returnType,
|
|
77
|
+
})),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.TurboModuleInterfaceTS = TurboModuleInterfaceTS;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./TurboModuleHTemplate"), exports);
|
|
24
|
+
__exportStar(require("./TurboModuleCppTemplate"), exports);
|
|
25
|
+
__exportStar(require("./RNOHGeneratedPackageHTemplate"), exports);
|
|
26
|
+
__exportStar(require("./ComponentJSIBinderHTemplate"), exports);
|
|
27
|
+
__exportStar(require("./ComponentDescriptorHTemplate"), exports);
|
|
28
|
+
__exportStar(require("./ComponentUtilsTSTemplate"), exports);
|
|
29
|
+
__exportStar(require("./IndexTSTemplate"), exports);
|
|
30
|
+
__exportStar(require("./TurboModuleSpecTSTemplate"), exports);
|
|
31
|
+
__exportStar(require("./BaseComponentInstanceHTemplate"), exports);
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.commandBundleHarmony = void 0;
|
|
22
|
+
const fs_1 = __importDefault(require("fs"));
|
|
23
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
24
|
+
const metro_1 = __importDefault(require("metro"));
|
|
25
|
+
const Server_1 = __importDefault(require("metro/src/Server"));
|
|
26
|
+
const path_1 = __importDefault(require("path"));
|
|
27
|
+
const assetResolver_1 = require("../assetResolver");
|
|
28
|
+
const ARK_RESOURCE_PATH = './harmony/entry/src/main/resources/rawfile';
|
|
29
|
+
const ASSETS_DEFAULT_DEST_PATH = './harmony/entry/src/main/resources/rawfile/assets';
|
|
30
|
+
exports.commandBundleHarmony = {
|
|
31
|
+
name: 'bundle-harmony',
|
|
32
|
+
description: 'Creates JS bundle, creates a special cpp header containing the JS code, copies assets directory to the project.',
|
|
33
|
+
options: [
|
|
34
|
+
{
|
|
35
|
+
name: '--dev [boolean]',
|
|
36
|
+
description: 'If false, warnings are disabled and the bundle is minified',
|
|
37
|
+
parse: (val) => val !== 'false',
|
|
38
|
+
default: true,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: '--entry-file <path>',
|
|
42
|
+
description: 'Path to the root JS file, either absolute or relative to JS root',
|
|
43
|
+
default: 'index.js',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: '--config <path>',
|
|
47
|
+
description: 'Path to the Metro configuration file',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: '--bundle-output <path>',
|
|
51
|
+
description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
|
|
52
|
+
default: ARK_RESOURCE_PATH + '/bundle.harmony.js',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: '--assets-dest <path>',
|
|
56
|
+
description: 'Directory name where to store assets referenced in the bundle',
|
|
57
|
+
default: ASSETS_DEFAULT_DEST_PATH,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: '--sourcemap-output <path>',
|
|
61
|
+
description: 'File name where to store the resulting source map, ex. /tmp/groups.map',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: '--minify [boolean]',
|
|
65
|
+
description: 'Allows overriding whether bundle is minified',
|
|
66
|
+
parse: (val) => val !== 'false',
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
const buildOptions = {
|
|
71
|
+
entry: args.entryFile,
|
|
72
|
+
platform: 'harmony',
|
|
73
|
+
minify: args.minify !== undefined ? args.minify : !args.dev,
|
|
74
|
+
dev: args.dev,
|
|
75
|
+
sourceMap: args.sourcemapOutput,
|
|
76
|
+
sourceMapUrl: args.sourcemapOutput,
|
|
77
|
+
};
|
|
78
|
+
const metroConfig = yield loadMetroConfig(args.config);
|
|
79
|
+
const bundle = yield createBundle(metroConfig, buildOptions);
|
|
80
|
+
yield saveBundle(bundle, args.bundleOutput, args.sourcemapOutput);
|
|
81
|
+
const assets = yield retrieveAssetsData(metroConfig, buildOptions);
|
|
82
|
+
copyAssets(assets, args.assetsDest);
|
|
83
|
+
}),
|
|
84
|
+
};
|
|
85
|
+
function loadMetroConfig(configPath) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
return configPath
|
|
88
|
+
? yield metro_1.default.loadConfig({ config: configPath })
|
|
89
|
+
: yield metro_1.default.loadConfig();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function createBundle(metroConfig, buildOptions) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
// casting needed as Metro.runBuild returns Promise<{code: string, map: string}>
|
|
95
|
+
// despite being typed as Promise<void>
|
|
96
|
+
return (yield metro_1.default.runBuild(metroConfig, buildOptions));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function saveBundle(bundle, bundleOutput, sourceMapOutput) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
yield fs_extra_1.default.ensureDir(path_1.default.dirname(bundleOutput));
|
|
102
|
+
fs_1.default.writeFileSync(bundleOutput, bundle.code);
|
|
103
|
+
console.log(`[CREATED] ${bundleOutput}`);
|
|
104
|
+
if (sourceMapOutput) {
|
|
105
|
+
fs_1.default.writeFileSync(sourceMapOutput, bundle.map);
|
|
106
|
+
console.log(`[CREATED] ${sourceMapOutput}`);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function retrieveAssetsData(metroConfig, buildOptions) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const metroServer = new Server_1.default(metroConfig);
|
|
113
|
+
try {
|
|
114
|
+
return yield metroServer.getAssets(Object.assign(Object.assign(Object.assign({}, Server_1.default.DEFAULT_BUNDLE_OPTIONS), buildOptions), { entryFile: buildOptions.entry, bundleType: 'todo' }));
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
metroServer.end();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function copyAssets(assetsData, assetsDest) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
if (assetsDest == null) {
|
|
124
|
+
console.warn('Assets destination folder is not set, skipping...');
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
yield fs_extra_1.default.ensureDir(assetsDest);
|
|
128
|
+
const fileDestBySrc = {};
|
|
129
|
+
for (const asset of assetsData) {
|
|
130
|
+
const idx = getHighestQualityFileIdx(asset);
|
|
131
|
+
fileDestBySrc[asset.files[idx]] = path_1.default.join(assetsDest, (0, assetResolver_1.getAssetDestRelativePath)(asset));
|
|
132
|
+
}
|
|
133
|
+
return copyFiles(fileDestBySrc);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function getHighestQualityFileIdx(assetData) {
|
|
137
|
+
let result = 0;
|
|
138
|
+
let maxScale = -1;
|
|
139
|
+
for (let idx = 0; idx < assetData.scales.length; idx++) {
|
|
140
|
+
const scale = assetData.scales[idx];
|
|
141
|
+
if (scale > maxScale) {
|
|
142
|
+
maxScale = scale;
|
|
143
|
+
result = idx;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
function copyFiles(fileDestBySrc) {
|
|
149
|
+
const fileSources = Object.keys(fileDestBySrc);
|
|
150
|
+
if (fileSources.length === 0) {
|
|
151
|
+
return Promise.resolve();
|
|
152
|
+
}
|
|
153
|
+
console.info(`Copying ${fileSources.length} asset files`);
|
|
154
|
+
return new Promise((resolve, reject) => {
|
|
155
|
+
const copyNext = (error) => {
|
|
156
|
+
if (error) {
|
|
157
|
+
reject(error);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (fileSources.length === 0) {
|
|
161
|
+
console.info('Done copying assets');
|
|
162
|
+
resolve();
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
// fileSources.length === 0 is checked in previous branch, so this is string
|
|
166
|
+
const src = fileSources.shift();
|
|
167
|
+
const dest = fileDestBySrc[src];
|
|
168
|
+
copyFile(src, dest, copyNext);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
copyNext();
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function copyFile(src, dest, onFinished) {
|
|
175
|
+
const destDir = path_1.default.dirname(dest);
|
|
176
|
+
fs_1.default.mkdir(destDir, { recursive: true }, (err) => {
|
|
177
|
+
if (err) {
|
|
178
|
+
onFinished(err);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
fs_1.default.createReadStream(src)
|
|
182
|
+
.pipe(fs_1.default.createWriteStream(dest))
|
|
183
|
+
.on('finish', onFinished);
|
|
184
|
+
});
|
|
185
|
+
}
|