@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,17 +5,6 @@
|
|
|
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 __assign = (this && this.__assign) || function () {
|
|
9
|
-
__assign = Object.assign || function(t) {
|
|
10
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
11
|
-
s = arguments[i];
|
|
12
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
-
t[p] = s[p];
|
|
14
|
-
}
|
|
15
|
-
return t;
|
|
16
|
-
};
|
|
17
|
-
return __assign.apply(this, arguments);
|
|
18
|
-
};
|
|
19
8
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
9
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
10
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -25,152 +14,171 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
25
14
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
15
|
});
|
|
27
16
|
};
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
31
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
32
|
-
function step(op) {
|
|
33
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
34
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
35
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
36
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
37
|
-
switch (op[0]) {
|
|
38
|
-
case 0: case 1: t = op; break;
|
|
39
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
40
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
41
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
42
|
-
default:
|
|
43
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
44
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
45
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
46
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
47
|
-
if (t[2]) _.ops.pop();
|
|
48
|
-
_.trys.pop(); continue;
|
|
49
|
-
}
|
|
50
|
-
op = body.call(thisArg, _);
|
|
51
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
52
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
53
|
-
}
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
54
19
|
};
|
|
55
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
21
|
exports.Autolinking = void 0;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
22
|
+
const json5_1 = __importDefault(require("json5"));
|
|
23
|
+
const core_1 = require("../core");
|
|
24
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
25
|
+
const case_1 = __importDefault(require("case"));
|
|
26
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
27
|
+
const ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = `
|
|
28
|
+
/*
|
|
29
|
+
* This file was generated by RNOH autolinking.
|
|
30
|
+
* DO NOT modify it manually, your changes WILL be overwritten.
|
|
31
|
+
*/
|
|
32
|
+
import type { RNPackageContext, RNOHPackage } from '@rnoh/react-native-openharmony';
|
|
33
|
+
{{#libraries}}
|
|
34
|
+
import {{etsRNOHPackageClassName}} from '{{{ohPackageName}}}';
|
|
35
|
+
{{/libraries}}
|
|
36
|
+
|
|
37
|
+
export function createRNOHPackages(ctx: RNPackageContext): RNOHPackage[] {
|
|
38
|
+
return [
|
|
39
|
+
{{#libraries}}
|
|
40
|
+
new {{etsRNOHPackageClassName}}(ctx),
|
|
41
|
+
{{/libraries}}
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
`.trimStart();
|
|
45
|
+
const CPP_RNOH_PACKAGES_FACTORY_TEMPLATE = `
|
|
46
|
+
/*
|
|
47
|
+
* This file was generated by RNOH autolinking.
|
|
48
|
+
* DO NOT modify it manually, your changes WILL be overwritten.
|
|
49
|
+
*/
|
|
50
|
+
// clang-format off
|
|
51
|
+
#pragma once
|
|
52
|
+
#include "RNOH/Package.h"
|
|
53
|
+
{{#libraries}}
|
|
54
|
+
#include "{{cppRNOHPackageClassName}}.h"
|
|
55
|
+
{{/libraries}}
|
|
56
|
+
|
|
57
|
+
std::vector<rnoh::Package::Shared> createRNOHPackages(const rnoh::Package::Context &ctx) {
|
|
58
|
+
return {
|
|
59
|
+
{{#libraries}}
|
|
60
|
+
std::make_shared<rnoh::{{cppRNOHPackageClassName}}>(ctx),
|
|
61
|
+
{{/libraries}}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
`.trimStart();
|
|
65
|
+
const CMAKE_AUTOLINKING_TEMPLATE = `
|
|
66
|
+
# This file was generated by RNOH autolinking.
|
|
67
|
+
# DO NOT modify it manually, your changes WILL be overwritten.
|
|
68
|
+
cmake_minimum_required(VERSION 3.5)
|
|
69
|
+
|
|
70
|
+
# @actor RNOH_APP
|
|
71
|
+
function(autolink_libraries target)
|
|
72
|
+
{{#libraries}}
|
|
73
|
+
add_subdirectory("\${OH_MODULES_DIR}/{{{ohPackageName}}}/src/main/cpp" ./{{cmakeLibraryTargetName}})
|
|
74
|
+
{{/libraries}}
|
|
75
|
+
|
|
76
|
+
set(AUTOLINKED_LIBRARIES
|
|
77
|
+
{{#libraries}}
|
|
78
|
+
{{cmakeLibraryTargetName}}
|
|
79
|
+
{{/libraries}}
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
foreach(lib \${AUTOLINKED_LIBRARIES})
|
|
83
|
+
target_link_libraries(\${target} PUBLIC \${lib})
|
|
84
|
+
endforeach()
|
|
85
|
+
endfunction()
|
|
86
|
+
`.trimStart();
|
|
87
|
+
class Autolinking {
|
|
88
|
+
constructor(fs, logger) {
|
|
67
89
|
this.fs = fs;
|
|
68
90
|
this.logger = logger;
|
|
69
91
|
}
|
|
70
|
-
|
|
71
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
var harmonyProjectPath, nodeModuleHarPaths, autolinkableLibraries, projectRootPath, skippedLibraryNpmPackageNames, ohPackagePath, ohPackageContent, cppRNOHPackagesFactoryPath, cmakeAutolinkingPath;
|
|
92
|
+
prepareInput(config) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
94
|
var _a;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
harFilePaths.length !== 1) {
|
|
111
|
-
skippedLibraryNpmPackageNames.push(packageJson.name);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
var autolinkingConfig = providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
|
|
115
|
-
autolinkableLibraries.push({
|
|
116
|
-
npmPackageName: packageJson.name,
|
|
117
|
-
etsRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.etsPackageClassName,
|
|
118
|
-
cppRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cppPackageClassName,
|
|
119
|
-
cmakeLibraryTargetName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cmakeLibraryTargetName,
|
|
120
|
-
ohPackageName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.ohPackageName,
|
|
121
|
-
harFilePathRelativeToHarmony: harFilePaths[0]
|
|
122
|
-
.relativeTo(harmonyProjectPath)
|
|
123
|
-
.toString(),
|
|
124
|
-
});
|
|
125
|
-
})];
|
|
126
|
-
case 1:
|
|
127
|
-
_b.sent();
|
|
128
|
-
ohPackagePath = harmonyProjectPath.copyWithNewSegment(config.ohPackagePathRelativeToHarmony);
|
|
129
|
-
return [4 /*yield*/, this.fs.readText(ohPackagePath)];
|
|
130
|
-
case 2:
|
|
131
|
-
ohPackageContent = _b.sent();
|
|
132
|
-
cppRNOHPackagesFactoryPath = harmonyProjectPath.copyWithNewSegment(config.cppRNOHPackagesFactoryPathRelativeToHarmony);
|
|
133
|
-
cmakeAutolinkingPath = harmonyProjectPath.copyWithNewSegment(config.cmakeAutolinkPathRelativeToHarmony);
|
|
134
|
-
return [2 /*return*/, {
|
|
135
|
-
projectRootPath: projectRootPath,
|
|
136
|
-
skippedLibraryNpmPackageNames: skippedLibraryNpmPackageNames,
|
|
137
|
-
etsRNOHPackagesFactoryPath: harmonyProjectPath.copyWithNewSegment(config.etsRNOHPackagesFactoryPathRelativeToHarmony),
|
|
138
|
-
cppRNOHPackagesFactoryPath: cppRNOHPackagesFactoryPath,
|
|
139
|
-
cmakeAutolinkingPath: cmakeAutolinkingPath,
|
|
140
|
-
ohPackagePathAndContent: [ohPackagePath, ohPackageContent],
|
|
141
|
-
autolinkableLibraries: autolinkableLibraries,
|
|
142
|
-
nodeModuleHarFilePathsRelativeToHarmony: nodeModuleHarPaths.map(function (p) {
|
|
143
|
-
return p.relativeTo(harmonyProjectPath).toString();
|
|
144
|
-
}),
|
|
145
|
-
}];
|
|
95
|
+
if (config.includedNpmPackageNames.size > 0 &&
|
|
96
|
+
config.excludedNpmPackageNames.size > 0) {
|
|
97
|
+
throw new core_1.DescriptiveError({
|
|
98
|
+
whatHappened: 'Tried to exclude and include npm packages.',
|
|
99
|
+
whatCanUserDo: ['Include or exclude npm packages, but not both.'],
|
|
100
|
+
extraData: {
|
|
101
|
+
includedNpmPackageNamesCount: config.includedNpmPackageNames.size,
|
|
102
|
+
excludedNpmPackageNamesCount: config.excludedNpmPackageNames.size,
|
|
103
|
+
includedNpmPackageNames: config.includedNpmPackageNames,
|
|
104
|
+
excludedNpmPackageNames: config.excludedNpmPackageNames,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const harmonyProjectPath = (_a = config.harmonyProjectPath) !== null && _a !== void 0 ? _a : new core_1.AbsolutePath('./');
|
|
109
|
+
const nodeModuleHarPaths = [];
|
|
110
|
+
const autolinkableLibraries = [];
|
|
111
|
+
const projectRootPath = config.nodeModulesPath.copyWithNewSegment('..');
|
|
112
|
+
const skippedLibraryNpmPackageNames = [];
|
|
113
|
+
yield new core_1.ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync((dependency) => {
|
|
114
|
+
var _a;
|
|
115
|
+
const harFilePaths = dependency.getHarFilePaths();
|
|
116
|
+
if (harFilePaths.length === 0) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
nodeModuleHarPaths.push(...harFilePaths);
|
|
120
|
+
const packageJson = dependency.readPackageJSON();
|
|
121
|
+
const providedAutolinkingConfig = (_a = packageJson.harmony) === null || _a === void 0 ? void 0 : _a.autolinking;
|
|
122
|
+
if (providedAutolinkingConfig === undefined ||
|
|
123
|
+
providedAutolinkingConfig === null ||
|
|
124
|
+
(config.excludedNpmPackageNames.has(packageJson.name) &&
|
|
125
|
+
config.excludedNpmPackageNames.size > 0) ||
|
|
126
|
+
(!config.includedNpmPackageNames.has(packageJson.name) &&
|
|
127
|
+
config.includedNpmPackageNames.size > 0) ||
|
|
128
|
+
harFilePaths.length !== 1) {
|
|
129
|
+
skippedLibraryNpmPackageNames.push(packageJson.name);
|
|
130
|
+
return;
|
|
146
131
|
}
|
|
132
|
+
const autolinkingConfig = providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
|
|
133
|
+
autolinkableLibraries.push({
|
|
134
|
+
npmPackageName: packageJson.name,
|
|
135
|
+
etsRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.etsPackageClassName,
|
|
136
|
+
cppRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cppPackageClassName,
|
|
137
|
+
cmakeLibraryTargetName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cmakeLibraryTargetName,
|
|
138
|
+
ohPackageName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.ohPackageName,
|
|
139
|
+
harFilePathRelativeToHarmony: harFilePaths[0]
|
|
140
|
+
.relativeTo(harmonyProjectPath)
|
|
141
|
+
.toString(),
|
|
142
|
+
});
|
|
147
143
|
});
|
|
144
|
+
const ohPackagePath = harmonyProjectPath.copyWithNewSegment(config.ohPackagePathRelativeToHarmony);
|
|
145
|
+
const ohPackageContent = yield this.fs.readText(ohPackagePath);
|
|
146
|
+
const cppRNOHPackagesFactoryPath = harmonyProjectPath.copyWithNewSegment(config.cppRNOHPackagesFactoryPathRelativeToHarmony);
|
|
147
|
+
const cmakeAutolinkingPath = harmonyProjectPath.copyWithNewSegment(config.cmakeAutolinkPathRelativeToHarmony);
|
|
148
|
+
return {
|
|
149
|
+
projectRootPath,
|
|
150
|
+
skippedLibraryNpmPackageNames,
|
|
151
|
+
etsRNOHPackagesFactoryPath: harmonyProjectPath.copyWithNewSegment(config.etsRNOHPackagesFactoryPathRelativeToHarmony),
|
|
152
|
+
cppRNOHPackagesFactoryPath,
|
|
153
|
+
cmakeAutolinkingPath: cmakeAutolinkingPath,
|
|
154
|
+
ohPackagePathAndContent: [ohPackagePath, ohPackageContent],
|
|
155
|
+
autolinkableLibraries,
|
|
156
|
+
nodeModuleHarFilePathsRelativeToHarmony: nodeModuleHarPaths.map((p) => p.relativeTo(harmonyProjectPath).toString()),
|
|
157
|
+
};
|
|
148
158
|
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
var autolinkableLibraries = input.autolinkableLibraries.map(function (lib) {
|
|
159
|
+
}
|
|
160
|
+
evaluate(input) {
|
|
161
|
+
const autolinkableLibraries = input.autolinkableLibraries.map((lib) => {
|
|
153
162
|
var _a, _b, _c, _d;
|
|
154
|
-
return
|
|
163
|
+
return Object.assign(Object.assign({}, lib), { etsRNOHPackageClassName: (_a = lib.etsRNOHPackageClassName) !== null && _a !== void 0 ? _a : this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName), cppRNOHPackageClassName: (_b = lib.cppRNOHPackageClassName) !== null && _b !== void 0 ? _b : this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName), cmakeLibraryTargetName: (_c = lib.cmakeLibraryTargetName) !== null && _c !== void 0 ? _c : this.npmPackageNameToCMakeLibraryTargetName(lib.npmPackageName), ohPackageName: (_d = lib.ohPackageName) !== null && _d !== void 0 ? _d : this.npmPackageNameToOHPackageName(lib.npmPackageName) });
|
|
155
164
|
});
|
|
156
|
-
autolinkableLibraries.sort(
|
|
165
|
+
autolinkableLibraries.sort((a, b) => {
|
|
157
166
|
if (a.npmPackageName < b.npmPackageName)
|
|
158
167
|
return -1;
|
|
159
168
|
if (a.npmPackageName > b.npmPackageName)
|
|
160
169
|
return 1;
|
|
161
170
|
return 0;
|
|
162
171
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
Object.entries(ohPackage.dependencies).forEach(
|
|
167
|
-
var name = _a[0], dependencySpecifier = _a[1];
|
|
172
|
+
const ohPackage = json5_1.default.parse(input.ohPackagePathAndContent[1]);
|
|
173
|
+
const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map((lib) => lib.harFilePathRelativeToHarmony);
|
|
174
|
+
const unmanagedNativeDependencySpecifierByName = {};
|
|
175
|
+
Object.entries(ohPackage.dependencies).forEach(([name, dependencySpecifier]) => {
|
|
168
176
|
if (!(dependencySpecifier.includes('file:') &&
|
|
169
177
|
dependencySpecifier.includes('node_modules'))) {
|
|
170
178
|
unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
|
|
171
179
|
}
|
|
172
180
|
else {
|
|
173
|
-
|
|
181
|
+
const harFilePathRelativeToHarmony = dependencySpecifier.replace('file:', '');
|
|
174
182
|
if (!autolinkableHarFilePathsRelativeToHarmony.includes(node_path_1.default.normalize(harFilePathRelativeToHarmony)) &&
|
|
175
183
|
input.nodeModuleHarFilePathsRelativeToHarmony.includes(node_path_1.default.normalize(harFilePathRelativeToHarmony))) {
|
|
176
184
|
unmanagedNativeDependencySpecifierByName[name] =
|
|
@@ -178,15 +186,14 @@ var Autolinking = /** @class */ (function () {
|
|
|
178
186
|
}
|
|
179
187
|
}
|
|
180
188
|
});
|
|
181
|
-
|
|
182
|
-
for (
|
|
183
|
-
var library = autolinkableLibraries_1[_i];
|
|
189
|
+
const managedNativeDependencySpecifierByName = {};
|
|
190
|
+
for (const library of autolinkableLibraries) {
|
|
184
191
|
managedNativeDependencySpecifierByName[library.ohPackageName] =
|
|
185
|
-
|
|
192
|
+
`file:${library.harFilePathRelativeToHarmony}`.split(node_path_1.default.sep).join('/');
|
|
186
193
|
}
|
|
187
194
|
return {
|
|
188
195
|
skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
|
|
189
|
-
linkedLibraryNpmPackageNames: autolinkableLibraries.map(
|
|
196
|
+
linkedLibraryNpmPackageNames: autolinkableLibraries.map((lib) => lib.npmPackageName),
|
|
190
197
|
projectRootPath: input.projectRootPath,
|
|
191
198
|
cppRNOHPackagesFactoryPathAndContent: [
|
|
192
199
|
input.cppRNOHPackagesFactoryPath,
|
|
@@ -208,70 +215,62 @@ var Autolinking = /** @class */ (function () {
|
|
|
208
215
|
],
|
|
209
216
|
ohPackagePathAndContent: [
|
|
210
217
|
input.ohPackagePathAndContent[0],
|
|
211
|
-
json5_1.default.stringify(
|
|
218
|
+
json5_1.default.stringify(Object.assign(Object.assign({}, ohPackage), { dependencies: Object.assign(Object.assign({}, unmanagedNativeDependencySpecifierByName), managedNativeDependencySpecifierByName) }), { space: 2, quote: '"' }) + '\n',
|
|
212
219
|
],
|
|
213
220
|
};
|
|
214
|
-
}
|
|
215
|
-
|
|
221
|
+
}
|
|
222
|
+
npmPackageNameToRNOHPackageClassName(fullNpmPackageName) {
|
|
216
223
|
if (fullNpmPackageName.startsWith('@')) {
|
|
217
|
-
|
|
224
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
218
225
|
.replace('@', '')
|
|
219
|
-
.split('/')
|
|
226
|
+
.split('/');
|
|
220
227
|
return case_1.default.pascal(scopeName) + case_1.default.pascal(packageName) + 'Package';
|
|
221
228
|
}
|
|
222
229
|
return case_1.default.pascal(fullNpmPackageName) + 'Package';
|
|
223
|
-
}
|
|
224
|
-
|
|
230
|
+
}
|
|
231
|
+
npmPackageNameToCMakeLibraryTargetName(fullNpmPackageName) {
|
|
225
232
|
if (fullNpmPackageName.startsWith('@')) {
|
|
226
|
-
|
|
233
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
227
234
|
.replace('@', '')
|
|
228
|
-
.split('/')
|
|
235
|
+
.split('/');
|
|
229
236
|
return 'rnoh__' + case_1.default.snake(scopeName) + '__' + case_1.default.snake(packageName);
|
|
230
237
|
}
|
|
231
238
|
return 'rnoh__' + case_1.default.snake(fullNpmPackageName);
|
|
232
|
-
}
|
|
233
|
-
|
|
239
|
+
}
|
|
240
|
+
npmPackageNameToOHPackageName(fullNpmPackageName) {
|
|
234
241
|
if (fullNpmPackageName.startsWith('@')) {
|
|
235
|
-
|
|
242
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
236
243
|
.replace('@', '')
|
|
237
|
-
.split('/')
|
|
244
|
+
.split('/');
|
|
238
245
|
return '@rnoh/' + case_1.default.kebab(scopeName) + '--' + case_1.default.kebab(packageName);
|
|
239
246
|
}
|
|
240
247
|
return '@rnoh/' + case_1.default.kebab(fullNpmPackageName);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var pathAndContentPairs = [];
|
|
248
|
+
}
|
|
249
|
+
saveAndLogOutput(output) {
|
|
250
|
+
const pathAndContentPairs = [];
|
|
245
251
|
pathAndContentPairs.push(output.etsRNOHPackagesFactoryPathAndContent);
|
|
246
252
|
pathAndContentPairs.push(output.cppRNOHPackagesFactoryPathAndContent);
|
|
247
253
|
pathAndContentPairs.push(output.cmakeAutolinkingPathAndContent);
|
|
248
254
|
pathAndContentPairs.push(output.ohPackagePathAndContent);
|
|
249
|
-
pathAndContentPairs.forEach(
|
|
250
|
-
|
|
251
|
-
_this.fs.writeTextSync(path, content);
|
|
255
|
+
pathAndContentPairs.forEach(([path, content]) => {
|
|
256
|
+
this.fs.writeTextSync(path, content);
|
|
252
257
|
});
|
|
253
|
-
output.linkedLibraryNpmPackageNames.forEach(
|
|
254
|
-
|
|
258
|
+
output.linkedLibraryNpmPackageNames.forEach((npmPackageName) => {
|
|
259
|
+
this.logger.debug((styles) => `[${styles.green(styles.bold('link'))}] ${npmPackageName}`);
|
|
255
260
|
});
|
|
256
|
-
output.skippedLibraryNpmPackageNames.forEach(
|
|
257
|
-
|
|
261
|
+
output.skippedLibraryNpmPackageNames.forEach((npmPackageName) => {
|
|
262
|
+
this.logger.debug((styles) => `[${styles.yellow(styles.bold('skip'))}] ${npmPackageName}`);
|
|
258
263
|
});
|
|
259
|
-
this.logger.debug(
|
|
260
|
-
|
|
261
|
-
.map(
|
|
262
|
-
var path = _a[0];
|
|
263
|
-
return path.relativeTo(output.projectRootPath).toString();
|
|
264
|
-
})
|
|
264
|
+
this.logger.debug(() => '');
|
|
265
|
+
const sortedPathsRelativeToRoot = pathAndContentPairs
|
|
266
|
+
.map(([path]) => path.relativeTo(output.projectRootPath).toString())
|
|
265
267
|
.sort();
|
|
266
|
-
sortedPathsRelativeToRoot.forEach(
|
|
267
|
-
|
|
268
|
-
});
|
|
269
|
-
this.logger.debug(function () { return ''; });
|
|
270
|
-
this.logger.info(function (styles) {
|
|
271
|
-
return "updated ".concat(styles.green(styles.bold(sortedPathsRelativeToRoot.length)), " file(s), linked ").concat(styles.green(styles.bold(output.linkedLibraryNpmPackageNames.length)), " libraries, skipped ").concat(styles.yellow(styles.bold(output.skippedLibraryNpmPackageNames.length)), " libraries");
|
|
268
|
+
sortedPathsRelativeToRoot.forEach((pathStr) => {
|
|
269
|
+
this.logger.debug((styles) => styles.gray(`• ${pathStr}`));
|
|
272
270
|
});
|
|
273
|
-
this.logger.debug(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
271
|
+
this.logger.debug(() => '');
|
|
272
|
+
this.logger.info((styles) => `updated ${styles.green(styles.bold(sortedPathsRelativeToRoot.length))} file(s), linked ${styles.green(styles.bold(output.linkedLibraryNpmPackageNames.length))} libraries, skipped ${styles.yellow(styles.bold(output.skippedLibraryNpmPackageNames.length))} libraries`);
|
|
273
|
+
this.logger.debug(() => '');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
277
276
|
exports.Autolinking = Autolinking;
|
|
@@ -5,29 +5,9 @@
|
|
|
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 __extends = (this && this.__extends) || (function () {
|
|
9
|
-
var extendStatics = function (d, b) {
|
|
10
|
-
extendStatics = Object.setPrototypeOf ||
|
|
11
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
12
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
13
|
-
return extendStatics(d, b);
|
|
14
|
-
};
|
|
15
|
-
return function (d, b) {
|
|
16
|
-
if (typeof b !== "function" && b !== null)
|
|
17
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
18
|
-
extendStatics(d, b);
|
|
19
|
-
function __() { this.constructor = d; }
|
|
20
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
21
|
-
};
|
|
22
|
-
})();
|
|
23
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
9
|
exports.CodegenError = void 0;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function CodegenError() {
|
|
29
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
30
|
-
}
|
|
31
|
-
return CodegenError;
|
|
32
|
-
}(core_1.DescriptiveError));
|
|
10
|
+
const core_1 = require("../../core");
|
|
11
|
+
class CodegenError extends core_1.DescriptiveError {
|
|
12
|
+
}
|
|
33
13
|
exports.CodegenError = CodegenError;
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createEventNameFromEventHandlerName = createEventNameFromEventHandlerName;
|
|
10
|
-
|
|
10
|
+
const CodegenError_1 = require("./CodegenError");
|
|
11
11
|
function createEventNameFromEventHandlerName(eventHandlerName) {
|
|
12
|
-
|
|
12
|
+
const eventName = eventHandlerName.replace('on', '');
|
|
13
13
|
if (eventName.length === 0) {
|
|
14
14
|
throw new CodegenError_1.CodegenError({
|
|
15
|
-
whatHappened:
|
|
15
|
+
whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
|
|
16
16
|
whatCanUserDo: [
|
|
17
17
|
'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
|
|
18
18
|
],
|
|
@@ -9,13 +9,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.TypeAnnotationToTS = void 0;
|
|
10
10
|
exports.getStringifiedTSDefaultValueFromPropTypeAnnotation = getStringifiedTSDefaultValueFromPropTypeAnnotation;
|
|
11
11
|
exports.wrapWithQuotes = wrapWithQuotes;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (aliasPrefix === void 0) { aliasPrefix = ''; }
|
|
12
|
+
class TypeAnnotationToTS {
|
|
13
|
+
constructor(aliasPrefix = '') {
|
|
15
14
|
this.aliasPrefix = aliasPrefix;
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
var _this = this;
|
|
16
|
+
convert(typeAnnotation) {
|
|
19
17
|
if (!typeAnnotation) {
|
|
20
18
|
return 'unknown';
|
|
21
19
|
}
|
|
@@ -58,7 +56,7 @@ var TypeAnnotationToTS = /** @class */ (function () {
|
|
|
58
56
|
}
|
|
59
57
|
case 'StringEnumTypeAnnotation':
|
|
60
58
|
return typeAnnotation.options
|
|
61
|
-
.map(
|
|
59
|
+
.map((option) => {
|
|
62
60
|
if (typeof option !== 'string') {
|
|
63
61
|
return option;
|
|
64
62
|
}
|
|
@@ -68,11 +66,11 @@ var TypeAnnotationToTS = /** @class */ (function () {
|
|
|
68
66
|
case 'StringTypeAnnotation':
|
|
69
67
|
return 'string';
|
|
70
68
|
case 'FunctionTypeAnnotation':
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
.map(
|
|
69
|
+
const { params, returnTypeAnnotation } = typeAnnotation;
|
|
70
|
+
const stringifiedArgs = params
|
|
71
|
+
.map((param) => `${param.name}: ${this.convert(param.typeAnnotation)}`)
|
|
74
72
|
.join(', ');
|
|
75
|
-
return
|
|
73
|
+
return `(${stringifiedArgs}) => ${this.convert(returnTypeAnnotation)}`;
|
|
76
74
|
case 'EnumDeclaration':
|
|
77
75
|
return typeAnnotation.name;
|
|
78
76
|
case 'GenericObjectTypeAnnotation':
|
|
@@ -84,20 +82,20 @@ var TypeAnnotationToTS = /** @class */ (function () {
|
|
|
84
82
|
case 'NumberTypeAnnotation':
|
|
85
83
|
return 'number';
|
|
86
84
|
case 'NullableTypeAnnotation':
|
|
87
|
-
return
|
|
85
|
+
return `null | ${this.convert(typeAnnotation.typeAnnotation)}`;
|
|
88
86
|
case 'ObjectTypeAnnotation':
|
|
89
87
|
return this.convertObjectTypeAnnotation(typeAnnotation);
|
|
90
88
|
case 'PromiseTypeAnnotation':
|
|
91
|
-
return
|
|
89
|
+
return `Promise<${this.convert(typeAnnotation.elementType)}>`;
|
|
92
90
|
case 'VoidTypeAnnotation':
|
|
93
91
|
return 'void';
|
|
94
92
|
case 'ArrayTypeAnnotation':
|
|
95
|
-
return
|
|
93
|
+
return `${this.convert(typeAnnotation.elementType)}[]`;
|
|
96
94
|
default:
|
|
97
95
|
return 'unknown';
|
|
98
96
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
97
|
+
}
|
|
98
|
+
convertUnionMemberAnnotation(memberAnnotation) {
|
|
101
99
|
switch (memberAnnotation) {
|
|
102
100
|
case 'NumberTypeAnnotation':
|
|
103
101
|
return 'number';
|
|
@@ -106,22 +104,20 @@ var TypeAnnotationToTS = /** @class */ (function () {
|
|
|
106
104
|
case 'StringTypeAnnotation':
|
|
107
105
|
return 'string';
|
|
108
106
|
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return "".concat(prop.name).concat(maybeOptionalSymbol, ": ").concat(_this.convert(prop.typeAnnotation));
|
|
107
|
+
}
|
|
108
|
+
convertObjectTypeAnnotation(objectTypeAnnotation) {
|
|
109
|
+
const props = objectTypeAnnotation.properties
|
|
110
|
+
.map((prop) => {
|
|
111
|
+
const maybeOptionalSymbol = prop.optional ? '?' : '';
|
|
112
|
+
return `${prop.name}${maybeOptionalSymbol}: ${this.convert(prop.typeAnnotation)}`;
|
|
116
113
|
})
|
|
117
114
|
.join(', ');
|
|
118
115
|
if (props.length === 0) {
|
|
119
116
|
return '{}';
|
|
120
117
|
}
|
|
121
|
-
return
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
}());
|
|
118
|
+
return `{${props}}`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
125
121
|
exports.TypeAnnotationToTS = TypeAnnotationToTS;
|
|
126
122
|
function getStringifiedTSDefaultValueFromPropTypeAnnotation(propTypeAnnotation) {
|
|
127
123
|
if ('default' in propTypeAnnotation && propTypeAnnotation.default !== null) {
|
|
@@ -134,9 +130,9 @@ function getStringifiedTSDefaultValueFromPropTypeAnnotation(propTypeAnnotation)
|
|
|
134
130
|
}
|
|
135
131
|
function wrapWithQuotes(str) {
|
|
136
132
|
if (str.includes("'")) {
|
|
137
|
-
return "
|
|
133
|
+
return `"${str}"`;
|
|
138
134
|
}
|
|
139
135
|
else {
|
|
140
|
-
return
|
|
136
|
+
return `'${str}'`;
|
|
141
137
|
}
|
|
142
138
|
}
|