@react-native-oh/react-native-harmony-cli 0.0.24 → 0.0.26-1
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/dist/assetResolver.js +1 -23
- package/dist/codegen/core/CodeGenerator.js +2 -0
- package/dist/codegen/core/UberSchema.js +35 -9
- package/dist/codegen/core/index.js +1 -1
- package/dist/codegen/generators/{ComponentCodeGenerator.js → ComponentCodeGeneratorArkTS.js} +12 -4
- package/dist/codegen/generators/ComponentCodeGeneratorCAPI.js +79 -0
- package/dist/codegen/generators/GlueCodeGenerator.js +60 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +14 -6
- package/dist/codegen/generators/UberGeneratorV1.js +49 -0
- package/dist/codegen/generators/UberGeneratorV2.js +60 -0
- package/dist/codegen/generators/index.js +5 -2
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +103 -0
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +42 -36
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +45 -36
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +135 -127
- package/dist/codegen/templates/GeneratedPackageHTemplate.js +101 -0
- package/dist/codegen/templates/IndexTSTemplate.js +23 -5
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +88 -82
- package/dist/codegen/templates/TurboModuleCppTemplate.js +26 -18
- package/dist/codegen/templates/TurboModuleHTemplate.js +27 -17
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +37 -27
- package/dist/codegen/templates/index.js +1 -0
- package/dist/commands/codegen-harmony.js +99 -14
- package/dist/commands/index.js +1 -0
- package/dist/commands/verify-package-harmony.js +127 -0
- package/dist/core/AbsolutePath.js +6 -0
- package/dist/core/CodegenConfig.js +8 -4
- package/dist/core/OHPackageJSON5.js +23 -0
- package/dist/core/PackageJSON.js +8 -3
- package/dist/core/ProjectDependenciesManager.js +2 -2
- package/dist/core/index.js +1 -0
- package/dist/index.js +1 -0
- package/dist/io/TarGz.js +28 -0
- package/dist/io/index.js +1 -0
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +38 -0
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +32 -0
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +26 -0
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +51 -0
- package/dist/package-verifier/checks/index.js +20 -0
- package/dist/package-verifier/index.js +18 -0
- package/dist/package-verifier/types.js +2 -0
- package/dist/package-verifier/verify-package.js +100 -0
- 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/codegen/core/Codegen.js +0 -35
- package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
- package/src/codegen/core/Codegen.ts +0 -44
- package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
|
@@ -5,88 +5,94 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.RNOHGeneratedPackageHTemplate = void 0;
|
|
7
7
|
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
-
const TEMPLATE = `
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
#include "
|
|
20
|
-
|
|
21
|
-
{{#
|
|
22
|
-
#include "generated/{{name}}
|
|
23
|
-
{{/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
{{
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
8
|
+
const TEMPLATE = `
|
|
9
|
+
/**
|
|
10
|
+
* This code was generated by "react-native codegen-harmony"
|
|
11
|
+
*
|
|
12
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
13
|
+
* lost once the code is regenerated.
|
|
14
|
+
*
|
|
15
|
+
* @generatorVersion: 1
|
|
16
|
+
*/
|
|
17
|
+
#pragma once
|
|
18
|
+
|
|
19
|
+
#include "RNOH/Package.h"
|
|
20
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
21
|
+
{{#turboModules}}
|
|
22
|
+
#include "generated/{{name}}.h"
|
|
23
|
+
{{/turboModules}}
|
|
24
|
+
{{#components}}
|
|
25
|
+
#include "generated/{{name}}ComponentDescriptor.h"
|
|
26
|
+
{{/components}}
|
|
27
|
+
{{#components}}
|
|
28
|
+
#include "generated/{{name}}JSIBinder.h"
|
|
29
|
+
{{/components}}
|
|
30
|
+
|
|
31
|
+
namespace rnoh {
|
|
32
|
+
|
|
33
|
+
class RNOHGeneratedPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
34
|
+
public:
|
|
35
|
+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
|
36
|
+
{{#turboModules}}
|
|
37
|
+
if (name == "{{name}}") {
|
|
38
|
+
return std::make_shared<{{name}}>(ctx, name);
|
|
39
|
+
}
|
|
40
|
+
{{/turboModules}}
|
|
41
|
+
return nullptr;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
class GeneratedEventEmitRequestHandler : 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
|
+
{{#supportedEvents}}
|
|
55
|
+
"{{name}}",
|
|
56
|
+
{{/supportedEvents}}
|
|
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
|
+
class RNOHGeneratedPackage : public Package {
|
|
65
|
+
public:
|
|
66
|
+
RNOHGeneratedPackage(Package::Context ctx) : Package(ctx){};
|
|
67
|
+
|
|
68
|
+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
|
69
|
+
return std::make_unique<RNOHGeneratedPackageTurboModuleFactoryDelegate>();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
|
|
73
|
+
return {
|
|
74
|
+
{{#components}}
|
|
75
|
+
facebook::react::concreteComponentDescriptorProvider<facebook::react::{{name}}ComponentDescriptor>(),
|
|
76
|
+
{{/components}}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
ComponentJSIBinderByString createComponentJSIBinderByName() override {
|
|
81
|
+
return {
|
|
82
|
+
{{#components}}
|
|
83
|
+
{"{{name}}", std::make_shared<{{name}}JSIBinder>()},
|
|
84
|
+
{{/components}}
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
89
|
+
return {
|
|
90
|
+
std::make_shared<GeneratedEventEmitRequestHandler>(),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
} // namespace rnoh
|
|
90
96
|
`;
|
|
91
97
|
class RNOHGeneratedPackageHTemplate {
|
|
92
98
|
constructor() {
|
|
@@ -5,27 +5,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TurboModuleCppTemplate = void 0;
|
|
7
7
|
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
-
const TEMPLATE = `
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}
|
|
8
|
+
const TEMPLATE = `
|
|
9
|
+
/**
|
|
10
|
+
* This code was generated by "react-native codegen-harmony"
|
|
11
|
+
*
|
|
12
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
13
|
+
* lost once the code is regenerated.
|
|
14
|
+
*
|
|
15
|
+
* @generatorVersion: {{generatorVersion}}
|
|
16
|
+
*/
|
|
17
|
+
#include "{{className}}.h"
|
|
18
|
+
|
|
19
|
+
namespace rnoh {
|
|
20
|
+
using namespace facebook;
|
|
21
|
+
|
|
22
|
+
{{className}}::{{className}}(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) {
|
|
23
|
+
methodMap_ = {
|
|
24
|
+
{{#methods}}
|
|
25
|
+
ARK_{{asyncMarker}}METHOD_METADATA({{name}}, {{argsCount}}),
|
|
26
|
+
{{/methods}}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
} // namespace rnoh
|
|
25
31
|
`;
|
|
26
32
|
class TurboModuleCppTemplate {
|
|
27
|
-
constructor(name) {
|
|
33
|
+
constructor(name, generatorVersion) {
|
|
28
34
|
this.name = name;
|
|
35
|
+
this.generatorVersion = generatorVersion;
|
|
29
36
|
this.methods = [];
|
|
30
37
|
}
|
|
31
38
|
addMethod(method) {
|
|
@@ -34,6 +41,7 @@ class TurboModuleCppTemplate {
|
|
|
34
41
|
build() {
|
|
35
42
|
return mustache_1.default.render(TEMPLATE, {
|
|
36
43
|
className: this.name,
|
|
44
|
+
generatorVersion: this.generatorVersion,
|
|
37
45
|
methods: this.methods.map((method) => ({
|
|
38
46
|
name: method.name,
|
|
39
47
|
argsCount: method.argsCount,
|
|
@@ -5,28 +5,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TurboModuleHTemplate = void 0;
|
|
7
7
|
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
-
const TEMPLATE = `
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
const TEMPLATE = `
|
|
9
|
+
/**
|
|
10
|
+
* This code was generated by "react-native codegen-harmony"
|
|
11
|
+
*
|
|
12
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
13
|
+
* lost once the code is regenerated.
|
|
14
|
+
*
|
|
15
|
+
* @generatorVersion: {{generatorVersion}}
|
|
16
|
+
*/
|
|
17
|
+
#pragma once
|
|
18
|
+
|
|
19
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
20
|
+
|
|
21
|
+
namespace rnoh {
|
|
22
|
+
|
|
23
|
+
class JSI_EXPORT {{className}} : public ArkTSTurboModule {
|
|
24
|
+
public:
|
|
25
|
+
{{className}}(const ArkTSTurboModule::Context ctx, const std::string name);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
} // namespace rnoh
|
|
23
29
|
`;
|
|
24
30
|
class TurboModuleHTemplate {
|
|
25
|
-
constructor(name) {
|
|
31
|
+
constructor(name, generatorVersion) {
|
|
26
32
|
this.name = name;
|
|
33
|
+
this.generatorVersion = generatorVersion;
|
|
27
34
|
}
|
|
28
35
|
build() {
|
|
29
|
-
return mustache_1.default.render(TEMPLATE, {
|
|
36
|
+
return mustache_1.default.render(TEMPLATE, {
|
|
37
|
+
className: this.name,
|
|
38
|
+
generatorVersion: this.generatorVersion,
|
|
39
|
+
});
|
|
30
40
|
}
|
|
31
41
|
}
|
|
32
42
|
exports.TurboModuleHTemplate = TurboModuleHTemplate;
|
|
@@ -5,36 +5,45 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TurboModuleInterfaceTS = void 0;
|
|
7
7
|
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
-
const TEMPLATE = `
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
{{#
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
8
|
+
const TEMPLATE = `
|
|
9
|
+
/**
|
|
10
|
+
* This code was generated by "react-native codegen-harmony"
|
|
11
|
+
*
|
|
12
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
13
|
+
* lost once the code is regenerated.
|
|
14
|
+
*
|
|
15
|
+
* @generatorVersion: {{generatorVersion}}
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { Tag } from "../../ts"
|
|
19
|
+
|
|
20
|
+
export namespace {{name}} {
|
|
21
|
+
export const NAME = '{{name}}' as const
|
|
22
|
+
|
|
23
|
+
{{#enums}}
|
|
24
|
+
export enum {{name}} {
|
|
25
|
+
{{#members}}
|
|
26
|
+
{{name}} = {{{value}}},
|
|
27
|
+
{{/members}}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
{{/enums}}
|
|
31
|
+
{{#aliases}}
|
|
32
|
+
export type {{name}} = {{{type}}}
|
|
33
|
+
|
|
34
|
+
{{/aliases}}
|
|
35
|
+
export interface Spec {
|
|
36
|
+
{{#methods}}
|
|
37
|
+
{{name}}({{{stringifiedArgs}}}): {{{returnType}}};
|
|
38
|
+
|
|
39
|
+
{{/methods}}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
34
42
|
`;
|
|
35
43
|
class TurboModuleInterfaceTS {
|
|
36
|
-
constructor(name) {
|
|
44
|
+
constructor(name, generatorVersion) {
|
|
37
45
|
this.name = name;
|
|
46
|
+
this.generatorVersion = generatorVersion;
|
|
38
47
|
this.methods = [];
|
|
39
48
|
this.aliases = [];
|
|
40
49
|
this.enumModels = [];
|
|
@@ -53,6 +62,7 @@ class TurboModuleInterfaceTS {
|
|
|
53
62
|
name: this.name,
|
|
54
63
|
aliases: this.aliases,
|
|
55
64
|
enums: this.enumModels,
|
|
65
|
+
generatorVersion: this.generatorVersion,
|
|
56
66
|
methods: this.methods.map((method) => ({
|
|
57
67
|
name: method.name,
|
|
58
68
|
stringifiedArgs: method.stringifiedArgs,
|
|
@@ -22,3 +22,4 @@ __exportStar(require("./ComponentDescriptorHTemplate"), exports);
|
|
|
22
22
|
__exportStar(require("./ComponentUtilsTSTemplate"), exports);
|
|
23
23
|
__exportStar(require("./IndexTSTemplate"), exports);
|
|
24
24
|
__exportStar(require("./TurboModuleSpecTSTemplate"), exports);
|
|
25
|
+
__exportStar(require("./BaseComponentInstanceHTemplate"), exports);
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.commandCodegenHarmony = void 0;
|
|
16
16
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
17
17
|
const node_path_1 = __importDefault(require("node:path"));
|
|
18
|
+
const case_1 = __importDefault(require("case"));
|
|
18
19
|
const core_1 = require("../core");
|
|
19
20
|
const codegen_1 = require("../codegen");
|
|
20
21
|
const io_1 = require("../io");
|
|
@@ -41,21 +42,56 @@ exports.commandCodegenHarmony = {
|
|
|
41
42
|
description: 'Enables logging details',
|
|
42
43
|
default: false,
|
|
43
44
|
},
|
|
45
|
+
{
|
|
46
|
+
name: '--no-safety-check [boolean]',
|
|
47
|
+
description: 'Skips the check that prevents file operations outside the current working directory. This command permanently deletes previously generated files. Files are generated in the path specified by cpp-output-path.',
|
|
48
|
+
},
|
|
44
49
|
],
|
|
45
50
|
func: (_argv, _config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
51
|
const logger = new io_1.Logger();
|
|
47
52
|
try {
|
|
53
|
+
const MAX_SUPPORTED_CODEGEN_VERSION = 2;
|
|
54
|
+
// prepare the input data
|
|
48
55
|
validateArgs(args);
|
|
49
56
|
const etsOutputPath = new core_1.AbsolutePath(args.rnohModulePath).copyWithNewSegment('generated');
|
|
57
|
+
const enableSafetyCheck = args.safetyCheck;
|
|
50
58
|
const cppOutputPath = new core_1.AbsolutePath(args.cppOutputPath);
|
|
51
59
|
const projectRootPath = new core_1.AbsolutePath(args.projectRootPath);
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
const uberSchemaFromArkTSLibraries = yield codegen_1.UberSchema.fromProject(projectRootPath, (codegenVersion, packageName) => {
|
|
61
|
+
throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION, packageName);
|
|
62
|
+
return codegenVersion === 1;
|
|
63
|
+
});
|
|
64
|
+
const cApiLibrariesData = yield collectLibrariesData(projectRootPath, (codegenVersion, packageName) => {
|
|
65
|
+
throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION, packageName);
|
|
66
|
+
return codegenVersion === 2;
|
|
67
|
+
});
|
|
68
|
+
// instantiate objects
|
|
69
|
+
const uberGeneratorV1 = new codegen_1.UberGeneratorV1(cppOutputPath, etsOutputPath);
|
|
70
|
+
const uberGeneratorV2 = new codegen_1.UberGeneratorV2(cppOutputPath, etsOutputPath);
|
|
71
|
+
const glueCodeGenerator = new codegen_1.GlueCodeGenerator(cppOutputPath, etsOutputPath);
|
|
72
|
+
// generate the code
|
|
73
|
+
const fileContentByPath = new Map();
|
|
74
|
+
const appendToFileContentByPath = (fileContent, path) => {
|
|
75
|
+
fileContentByPath.set(path, fileContent);
|
|
76
|
+
};
|
|
77
|
+
uberGeneratorV1
|
|
78
|
+
.generate(uberSchemaFromArkTSLibraries)
|
|
79
|
+
.forEach(appendToFileContentByPath);
|
|
80
|
+
uberGeneratorV2
|
|
81
|
+
.generate(cApiLibrariesData)
|
|
82
|
+
.forEach(appendToFileContentByPath);
|
|
83
|
+
glueCodeGenerator
|
|
84
|
+
.generate({
|
|
85
|
+
v1: uberGeneratorV1.getGlueCodeData(),
|
|
86
|
+
v2: uberGeneratorV2.getGlueCodeData(),
|
|
87
|
+
})
|
|
88
|
+
.forEach(appendToFileContentByPath);
|
|
89
|
+
// output the results
|
|
55
90
|
if (args.debug) {
|
|
91
|
+
const uberSchema = yield codegen_1.UberSchema.fromProject(projectRootPath);
|
|
56
92
|
logger.debug((styles) => styles.gray(JSON.stringify(uberSchema.getValue(), null, 2)));
|
|
57
93
|
}
|
|
58
|
-
saveCodegenResult(fileContentByPath, cppOutputPath, etsOutputPath);
|
|
94
|
+
saveCodegenResult(fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck);
|
|
59
95
|
logCodegenResult(logger, fileContentByPath, projectRootPath);
|
|
60
96
|
}
|
|
61
97
|
catch (err) {
|
|
@@ -79,23 +115,63 @@ function validateArgs(args) {
|
|
|
79
115
|
});
|
|
80
116
|
}
|
|
81
117
|
}
|
|
82
|
-
function
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
|
|
118
|
+
function collectLibrariesData(projectRootPath, onShouldAcceptCodegenConfig) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const packageJSONs = [
|
|
121
|
+
core_1.PackageJSON.fromProjectRootPath(projectRootPath, projectRootPath),
|
|
122
|
+
];
|
|
123
|
+
yield new core_1.ProjectDependenciesManager(projectRootPath).forEachAsync((dependency) => {
|
|
124
|
+
packageJSONs.push(dependency.readPackageJSON());
|
|
125
|
+
});
|
|
126
|
+
const results = [];
|
|
127
|
+
for (const packageJSON of packageJSONs) {
|
|
128
|
+
const codegenConfigs = packageJSON.getCodegenConfigs();
|
|
129
|
+
for (const codegenConfig of codegenConfigs) {
|
|
130
|
+
if (codegenConfig &&
|
|
131
|
+
onShouldAcceptCodegenConfig(codegenConfig.getVersion(), packageJSON.name)) {
|
|
132
|
+
results.push({
|
|
133
|
+
name: deriveCppDirectoryNameFromNpmPackageName(packageJSON.name),
|
|
134
|
+
uberSchema: codegen_1.UberSchema.fromCodegenConfig(codegenConfig),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return results;
|
|
86
140
|
});
|
|
87
141
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
142
|
+
function throwErrorIfUnsupportedCodegenVersion(codegenVersion, maxSupportedCodegenVersion, packageName) {
|
|
143
|
+
if (codegenVersion > maxSupportedCodegenVersion) {
|
|
144
|
+
throw new codegen_1.CodegenError({
|
|
145
|
+
whatHappened: `Package "${packageName}" requires codegenVersion: ${codegenVersion}, which is not supported (maxSupportedCodegenVersion=${maxSupportedCodegenVersion}).`,
|
|
146
|
+
whatCanUserDo: {
|
|
147
|
+
rnAppDeveloper: [
|
|
148
|
+
`Try downgrading "${packageName}".`,
|
|
149
|
+
'Update the "@rnoh/react-native-harmony-cli" package.',
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function saveCodegenResult(fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck) {
|
|
156
|
+
prepareDirectory(cppOutputPath, enableSafetyCheck);
|
|
157
|
+
prepareDirectory(etsOutputPath, enableSafetyCheck);
|
|
158
|
+
prepareDirectory(etsOutputPath.copyWithNewSegment('components'), enableSafetyCheck);
|
|
159
|
+
prepareDirectory(etsOutputPath.copyWithNewSegment('turboModules'), enableSafetyCheck);
|
|
160
|
+
fileContentByPath.forEach((_fileContent, path) => {
|
|
161
|
+
prepareDirectory(path.getDirectoryPath(), enableSafetyCheck);
|
|
162
|
+
});
|
|
93
163
|
fileContentByPath.forEach((fileContent, path) => {
|
|
94
164
|
node_fs_1.default.writeFileSync(path.getValue(), fileContent);
|
|
95
165
|
});
|
|
96
166
|
}
|
|
97
|
-
function prepareDirectory(path) {
|
|
167
|
+
function prepareDirectory(path, enableSafetyCheck) {
|
|
98
168
|
(0, core_1.maybeMakeDirectories)(path);
|
|
169
|
+
if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
|
|
170
|
+
throw new core_1.DescriptiveError({
|
|
171
|
+
whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
|
|
172
|
+
whatCanUserDo: { default: ['Run codegen from different location'] },
|
|
173
|
+
});
|
|
174
|
+
}
|
|
99
175
|
(0, core_1.maybeRemoveFilesInDirectory)(path);
|
|
100
176
|
}
|
|
101
177
|
function logCodegenResult(logger, fileContentByPath, projectRootPath) {
|
|
@@ -108,3 +184,12 @@ function logCodegenResult(logger, fileContentByPath, projectRootPath) {
|
|
|
108
184
|
logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`, { prefix: true });
|
|
109
185
|
logger.info(() => '');
|
|
110
186
|
}
|
|
187
|
+
function deriveCppDirectoryNameFromNpmPackageName(npmPackageName) {
|
|
188
|
+
let result = npmPackageName;
|
|
189
|
+
if (npmPackageName.includes('/')) {
|
|
190
|
+
result.replace('@', '');
|
|
191
|
+
result = npmPackageName.replace('/', '__');
|
|
192
|
+
}
|
|
193
|
+
result = case_1.default.snake(result);
|
|
194
|
+
return result;
|
|
195
|
+
}
|
package/dist/commands/index.js
CHANGED
|
@@ -19,3 +19,4 @@ __exportStar(require("./pack-harmony"), exports);
|
|
|
19
19
|
__exportStar(require("./unpack-harmony"), exports);
|
|
20
20
|
__exportStar(require("./create-metro-host-constants"), exports);
|
|
21
21
|
__exportStar(require("./codegen-harmony"), exports);
|
|
22
|
+
__exportStar(require("./verify-package-harmony"), exports);
|