@react-native-oh/react-native-harmony-cli 0.0.30 → 0.0.37
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/dist/assetResolver.js +105 -10
- package/dist/autolinking/Autolinking.js +9 -11
- package/dist/codegen/core/EventUtils.js +5 -8
- package/dist/codegen/core/TypeAnnotationToTS.js +3 -3
- package/dist/codegen/core/UberSchema.js +7 -11
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +2 -1
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +3 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +3 -0
- package/dist/codegen/generators/CppComponentCodeGenerator.js +3 -0
- package/dist/codegen/generators/LibGlueCodeGenerator.js +2 -2
- package/dist/codegen/templates/BasePackageHTemplate.js +12 -1
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +15 -0
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +12 -1
- package/dist/commands/bundle-harmony.js +4 -67
- package/dist/commands/codegen-harmony.js +13 -17
- package/dist/commands/codegen-lib-harmony.js +10 -14
- package/dist/commands/create-metro-host-constants.js +1 -1
- package/dist/commands/index.js +2 -1
- package/dist/commands/init.js +703 -0
- package/dist/commands/link-harmony.js +1 -1
- package/dist/commands/pack-harmony.js +1 -1
- package/dist/commands/run-harmony.js +462 -0
- package/dist/commands/types.js +8 -0
- package/dist/commands/unpack-harmony.js +2 -4
- package/dist/commands/verify-package-harmony.js +2 -2
- package/dist/core/CodegenConfig.js +4 -6
- package/dist/core/DescriptiveError.js +8 -4
- package/dist/core/PackageJSON.js +4 -7
- package/dist/core/fs.js +4 -5
- package/dist/index.js +2 -1
- package/dist/io/CliExecutor.js +57 -24
- package/dist/io/Logger.js +72 -42
- package/dist/io/TarGz.js +1 -2
- package/dist/io/__fixtures__.js +9 -3
- package/dist/io/fsUtils.js +1 -2
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +1 -2
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +1 -2
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +1 -2
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +1 -2
- package/dist/package-verifier/verify-package.js +7 -10
- package/dist/simulator/LaunchSimulator.js +311 -0
- package/dist/simulator/index.js +23 -0
- package/package.json +13 -6
- package/src/assetResolver.ts +117 -11
- package/src/autolinking/Autolinking.ts +10 -12
- package/src/codegen/core/EventUtils.ts +4 -6
- package/src/codegen/core/UberSchema.ts +7 -11
- package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +5 -1
- package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +3 -0
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +3 -0
- package/src/codegen/generators/CppComponentCodeGenerator.ts +3 -0
- package/src/codegen/generators/LibGlueCodeGenerator.ts +2 -2
- package/src/codegen/templates/BasePackageHTemplate.ts +13 -1
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +24 -1
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +13 -1
- package/src/commands/bundle-harmony.ts +6 -81
- package/src/commands/codegen-harmony.ts +14 -19
- package/src/commands/codegen-lib-harmony.ts +11 -16
- package/src/commands/create-metro-host-constants.ts +2 -2
- package/src/commands/index.ts +2 -1
- package/src/commands/init.ts +755 -0
- package/src/commands/link-harmony.ts +2 -2
- package/src/commands/pack-harmony.ts +2 -2
- package/src/commands/run-harmony.ts +506 -0
- package/src/commands/types.ts +21 -0
- package/src/commands/unpack-harmony.ts +3 -5
- package/src/commands/verify-package-harmony.ts +3 -3
- package/src/core/CodegenConfig.ts +4 -6
- package/src/core/DescriptiveError.ts +9 -9
- package/src/core/PackageJSON.ts +5 -8
- package/src/core/fs.ts +2 -2
- package/src/index.ts +5 -3
- package/src/io/CliExecutor.ts +56 -34
- package/src/io/Logger.ts +78 -45
- package/src/io/__fixtures__.ts +15 -11
- package/src/package-verifier/verify-package.ts +5 -7
- package/src/simulator/LaunchSimulator.ts +352 -0
- package/src/simulator/index.ts +8 -0
package/dist/assetResolver.js
CHANGED
|
@@ -1,25 +1,120 @@
|
|
|
1
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.copyAssets = copyAssets;
|
|
2
16
|
/**
|
|
3
17
|
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
18
|
*
|
|
5
19
|
* This source code is licensed under the MIT license found in the
|
|
6
20
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
21
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
22
|
+
const fs_1 = __importDefault(require("fs"));
|
|
23
|
+
const path_1 = __importDefault(require("path"));
|
|
24
|
+
const ALLOWED_SCALES = [1, 2, 3, 4];
|
|
25
|
+
function filterAssetScales(scales) {
|
|
26
|
+
const result = scales.filter(scale => ALLOWED_SCALES.includes(scale));
|
|
27
|
+
if (result.length === 0 && scales.length > 0) {
|
|
28
|
+
// No matching scale found, but there are some available. Ideally we don't
|
|
29
|
+
// want to be in this situation and should throw, but for now as a fallback
|
|
30
|
+
// let's just use the closest larger image
|
|
31
|
+
const maxScale = ALLOWED_SCALES[ALLOWED_SCALES.length - 1];
|
|
32
|
+
for (const scale of scales) {
|
|
33
|
+
if (scale > maxScale) {
|
|
34
|
+
result.push(scale);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// There is no larger scales available, use the largest we have
|
|
39
|
+
if (result.length === 0) {
|
|
40
|
+
result.push(scales[scales.length - 1]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function copyAssets(logger, assetsData, assetsDest) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
if (assetsDest == null) {
|
|
48
|
+
logger.warn((s) => 'Assets destination folder is not set, skipping...');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const filesToCopy = {};
|
|
52
|
+
const addAssetToCopy = (asset) => {
|
|
53
|
+
const validScales = filterAssetScales(asset.scales);
|
|
54
|
+
asset.scales.forEach((scale, idx) => {
|
|
55
|
+
if (!validScales.includes(scale)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const src = asset.files[idx];
|
|
59
|
+
const dest = path_1.default.join(assetsDest, getAssetDestRelativePath(asset, scale));
|
|
60
|
+
filesToCopy[src] = dest;
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
assetsData.forEach(addAssetToCopy);
|
|
64
|
+
return copyFiles(logger, filesToCopy);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function getAssetDestRelativePath(asset, scale = 1) {
|
|
68
|
+
const suffix = scale === 1 ? '' : `@${scale}x`;
|
|
11
69
|
const fileName = getResourceIdentifier(asset);
|
|
12
|
-
|
|
70
|
+
// Assets can have relative paths outside of the project root.
|
|
71
|
+
// Replace `../` with `_` to make sure they don't end up outside of
|
|
72
|
+
// the expected assets directory.
|
|
73
|
+
return `${fileName + suffix}.${asset.type}`.replace(/\.\.\//g, '_');
|
|
13
74
|
}
|
|
14
|
-
exports.getAssetDestRelativePath = getAssetDestRelativePath;
|
|
15
75
|
function getResourceIdentifier(asset) {
|
|
16
76
|
const folderPath = getBasePath(asset);
|
|
17
|
-
return `${folderPath}/${asset.name}`.
|
|
77
|
+
return `${folderPath}/${asset.name}`.replace(/^assets\//, '');
|
|
18
78
|
}
|
|
19
79
|
function getBasePath(asset) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
80
|
+
const basePath = asset.httpServerLocation;
|
|
81
|
+
return basePath.startsWith('/') ? basePath.slice(1) : basePath;
|
|
82
|
+
}
|
|
83
|
+
function copyFiles(logger, fileDestBySrc) {
|
|
84
|
+
const fileSources = Object.keys(fileDestBySrc);
|
|
85
|
+
if (fileSources.length === 0) {
|
|
86
|
+
return Promise.resolve();
|
|
23
87
|
}
|
|
24
|
-
|
|
88
|
+
const assetFilesCount = fileSources.length;
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
const copyNext = (error) => {
|
|
91
|
+
if (error) {
|
|
92
|
+
reject(error);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (fileSources.length === 0) {
|
|
96
|
+
logger.info(() => `Copied ${assetFilesCount} ${assetFilesCount === 1 ? 'asset' : 'assets'}`);
|
|
97
|
+
resolve();
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// fileSources.length === 0 is checked in previous branch, so this is string
|
|
101
|
+
const src = fileSources.shift();
|
|
102
|
+
const dest = fileDestBySrc[src];
|
|
103
|
+
copyFile(src, dest, copyNext);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
copyNext();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function copyFile(src, dest, onFinished) {
|
|
110
|
+
const destDir = path_1.default.dirname(dest);
|
|
111
|
+
fs_1.default.mkdir(destDir, { recursive: true }, (err) => {
|
|
112
|
+
if (err) {
|
|
113
|
+
onFinished(err);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
fs_1.default.createReadStream(src)
|
|
117
|
+
.pipe(fs_1.default.createWriteStream(dest))
|
|
118
|
+
.on('finish', onFinished);
|
|
119
|
+
});
|
|
25
120
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
4
4
|
*
|
|
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.
|
|
@@ -95,9 +95,7 @@ class Autolinking {
|
|
|
95
95
|
config.excludedNpmPackageNames.size > 0) {
|
|
96
96
|
throw new core_1.DescriptiveError({
|
|
97
97
|
whatHappened: 'Tried to exclude and include npm packages.',
|
|
98
|
-
whatCanUserDo:
|
|
99
|
-
default: ['Include or exclude npm packages, but not both.'],
|
|
100
|
-
},
|
|
98
|
+
whatCanUserDo: ['Include or exclude npm packages, but not both.'],
|
|
101
99
|
extraData: {
|
|
102
100
|
includedNpmPackageNamesCount: config.includedNpmPackageNames.size,
|
|
103
101
|
excludedNpmPackageNamesCount: config.excludedNpmPackageNames.size,
|
|
@@ -255,21 +253,21 @@ class Autolinking {
|
|
|
255
253
|
this.fs.writeTextSync(path, content);
|
|
256
254
|
});
|
|
257
255
|
output.linkedLibraryNpmPackageNames.forEach((npmPackageName) => {
|
|
258
|
-
this.logger.
|
|
256
|
+
this.logger.debug((styles) => `[${styles.green(styles.bold('link'))}] ${npmPackageName}`);
|
|
259
257
|
});
|
|
260
258
|
output.skippedLibraryNpmPackageNames.forEach((npmPackageName) => {
|
|
261
|
-
this.logger.
|
|
259
|
+
this.logger.debug((styles) => `[${styles.yellow(styles.bold('skip'))}] ${npmPackageName}`);
|
|
262
260
|
});
|
|
263
|
-
this.logger.
|
|
261
|
+
this.logger.debug(() => '');
|
|
264
262
|
const sortedPathsRelativeToRoot = pathAndContentPairs
|
|
265
263
|
.map(([path]) => path.relativeTo(output.projectRootPath).toString())
|
|
266
264
|
.sort();
|
|
267
265
|
sortedPathsRelativeToRoot.forEach((pathStr) => {
|
|
268
|
-
this.logger.
|
|
266
|
+
this.logger.debug((styles) => styles.gray(`• ${pathStr}`));
|
|
269
267
|
});
|
|
270
|
-
this.logger.
|
|
271
|
-
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
|
|
272
|
-
this.logger.
|
|
268
|
+
this.logger.debug(() => '');
|
|
269
|
+
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`);
|
|
270
|
+
this.logger.debug(() => '');
|
|
273
271
|
}
|
|
274
272
|
}
|
|
275
273
|
exports.Autolinking = Autolinking;
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
4
4
|
*
|
|
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
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.createEventNameFromEventHandlerName =
|
|
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
15
|
whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
|
|
16
|
-
whatCanUserDo:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
],
|
|
20
|
-
},
|
|
16
|
+
whatCanUserDo: [
|
|
17
|
+
'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
|
|
18
|
+
],
|
|
21
19
|
});
|
|
22
20
|
}
|
|
23
21
|
return eventName.charAt(0).toLowerCase() + eventName.slice(1);
|
|
24
22
|
}
|
|
25
|
-
exports.createEventNameFromEventHandlerName = createEventNameFromEventHandlerName;
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.TypeAnnotationToTS = void 0;
|
|
10
|
+
exports.getStringifiedTSDefaultValueFromPropTypeAnnotation = getStringifiedTSDefaultValueFromPropTypeAnnotation;
|
|
11
|
+
exports.wrapWithQuotes = wrapWithQuotes;
|
|
10
12
|
class TypeAnnotationToTS {
|
|
11
13
|
constructor(aliasPrefix = '') {
|
|
12
14
|
this.aliasPrefix = aliasPrefix;
|
|
@@ -126,7 +128,6 @@ function getStringifiedTSDefaultValueFromPropTypeAnnotation(propTypeAnnotation)
|
|
|
126
128
|
}
|
|
127
129
|
return null;
|
|
128
130
|
}
|
|
129
|
-
exports.getStringifiedTSDefaultValueFromPropTypeAnnotation = getStringifiedTSDefaultValueFromPropTypeAnnotation;
|
|
130
131
|
function wrapWithQuotes(str) {
|
|
131
132
|
if (str.includes("'")) {
|
|
132
133
|
return `"${str}"`;
|
|
@@ -135,4 +136,3 @@ function wrapWithQuotes(str) {
|
|
|
135
136
|
return `'${str}'`;
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
|
-
exports.wrapWithQuotes = wrapWithQuotes;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
4
4
|
*
|
|
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.
|
|
@@ -41,11 +41,9 @@ class UberSchema {
|
|
|
41
41
|
if (err instanceof Error) {
|
|
42
42
|
throw new CodegenError_1.CodegenError({
|
|
43
43
|
whatHappened: "Couldn't create the schema",
|
|
44
|
-
whatCanUserDo:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
],
|
|
48
|
-
},
|
|
44
|
+
whatCanUserDo: [
|
|
45
|
+
`There's probably at least one spec file defined in your project or in a third-party package that breaks some code generation restrictions. Please check the message below. If it's ambiguous, debug the problem with divide and conquer strategy.\n\n${err.message}`,
|
|
46
|
+
],
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
49
|
throw err;
|
|
@@ -77,11 +75,9 @@ class UberSchema {
|
|
|
77
75
|
if (err instanceof Error) {
|
|
78
76
|
throw new CodegenError_1.CodegenError({
|
|
79
77
|
whatHappened: "Couldn't create the schema",
|
|
80
|
-
whatCanUserDo:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
],
|
|
84
|
-
},
|
|
78
|
+
whatCanUserDo: [
|
|
79
|
+
`There's probably at least one spec file defined in your project or in a third-party package that breaks some code generation restrictions. Please check the message below. If it's ambiguous, debug the problem with divide and conquer strategy.\n\n${err.message}`,
|
|
80
|
+
],
|
|
85
81
|
});
|
|
86
82
|
}
|
|
87
83
|
throw err;
|
|
@@ -35,6 +35,7 @@ class AppBuildTimeGlueCodeGenerator {
|
|
|
35
35
|
generatedPackageH_v1.addComponent({
|
|
36
36
|
name,
|
|
37
37
|
supportedEventNames: eventNames,
|
|
38
|
+
isArkTSComponent: true,
|
|
38
39
|
});
|
|
39
40
|
});
|
|
40
41
|
v1.turboModules.forEach((turboModule) => {
|
|
@@ -45,7 +46,7 @@ class AppBuildTimeGlueCodeGenerator {
|
|
|
45
46
|
const basePackageClassName = `Base${case_1.default.pascal(libraryName)}Package`;
|
|
46
47
|
const generatedPackageH_v2 = new BasePackageHTemplate_1.BasePackageHTemplate(basePackageClassName, this.codegenNoticeLines);
|
|
47
48
|
components.forEach((component) => {
|
|
48
|
-
generatedPackageH_v2.addComponent(component);
|
|
49
|
+
generatedPackageH_v2.addComponent(Object.assign(Object.assign({}, component), { isArkTSComponent: false }));
|
|
49
50
|
});
|
|
50
51
|
turboModules.forEach((turboModule) => {
|
|
51
52
|
turboModules_indexTS.addReexport({ from: `./${turboModule.name}` });
|
|
@@ -39,6 +39,9 @@ class CppComponentCodeGenerator {
|
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
shape.commands.forEach((command) => {
|
|
42
|
+
componentJSIBinderHTemplate.addCommand({
|
|
43
|
+
name: command.name,
|
|
44
|
+
});
|
|
42
45
|
componentInstanceSpecHTemplate.addCommand({
|
|
43
46
|
name: command.name,
|
|
44
47
|
args: command.typeAnnotation.params.map((param) => ({
|
|
@@ -35,11 +35,11 @@ class LibGlueCodeGenerator {
|
|
|
35
35
|
});
|
|
36
36
|
arkTSComponents.forEach(({ componentName, eventNames }) => {
|
|
37
37
|
components_indexTS.addReexport({ from: `./${componentName}` });
|
|
38
|
-
basePackageTemplate.addComponent({ name: componentName, libraryCppName });
|
|
38
|
+
basePackageTemplate.addComponent({ name: componentName, libraryCppName, isArkTSComponent: true });
|
|
39
39
|
eventNames.forEach((eventName) => basePackageTemplate.addArkTSEvent({ name: eventName }));
|
|
40
40
|
});
|
|
41
41
|
cppComponents.forEach(({ componentName }) => {
|
|
42
|
-
basePackageTemplate.addComponent({ name: componentName, libraryCppName });
|
|
42
|
+
basePackageTemplate.addComponent({ name: componentName, libraryCppName, isArkTSComponent: false });
|
|
43
43
|
});
|
|
44
44
|
fileContentByPath.set(this.cppOutputPath.copyWithNewSegment('RNOH', 'generated', `${basePackageClassName}.h`), basePackageTemplate.build());
|
|
45
45
|
fileContentByPath.set(this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'), components_indexTS.build());
|
|
@@ -50,16 +50,26 @@ class {{name}}EventEmitRequestHandler : public EventEmitRequestHandler {
|
|
|
50
50
|
public:
|
|
51
51
|
void handleEvent(Context const &ctx) override {
|
|
52
52
|
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
53
|
+
auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
|
|
54
|
+
|
|
53
55
|
if (eventEmitter == nullptr) {
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
std::vector<std::string> supportedComponentNames = {
|
|
60
|
+
{{#arkTSComponents}}
|
|
61
|
+
"{{name}}",
|
|
62
|
+
{{/arkTSComponents}}
|
|
63
|
+
};
|
|
64
|
+
|
|
57
65
|
std::vector<std::string> supportedEventNames = {
|
|
58
66
|
{{#arkTSEvents}}
|
|
59
67
|
"{{name}}",
|
|
60
68
|
{{/arkTSEvents}}
|
|
61
69
|
};
|
|
62
|
-
|
|
70
|
+
|
|
71
|
+
if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
|
|
72
|
+
std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
63
73
|
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
64
74
|
}
|
|
65
75
|
}
|
|
@@ -126,6 +136,7 @@ class BasePackageHTemplate {
|
|
|
126
136
|
name: this.name,
|
|
127
137
|
turboModules: this.turboModules,
|
|
128
138
|
components: this.components,
|
|
139
|
+
arkTSComponents: this.components.filter((component) => component.isArkTSComponent),
|
|
129
140
|
arkTSEvents: this.arkTSEvents,
|
|
130
141
|
libraries: Array.from(this.libraryCppNames).map((name) => ({
|
|
131
142
|
name,
|
|
@@ -32,6 +32,14 @@ class {{name}}JSIBinder : public ViewComponentJSIBinder {
|
|
|
32
32
|
return object;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
facebook::jsi::Object createCommands(facebook::jsi::Runtime &rt) override {
|
|
36
|
+
auto commands = ViewComponentJSIBinder::createCommands(rt);
|
|
37
|
+
{{#commands}}
|
|
38
|
+
commands.setProperty(rt, "{{name}}", "{{name}}");
|
|
39
|
+
{{/commands}}
|
|
40
|
+
return commands;
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
|
|
36
44
|
facebook::jsi::Object events(rt);
|
|
37
45
|
{{#bubblingEvents}}
|
|
@@ -55,11 +63,15 @@ class ComponentJSIBinderHTemplate {
|
|
|
55
63
|
this.name = name;
|
|
56
64
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
57
65
|
this.props = [];
|
|
66
|
+
this.commands = [];
|
|
58
67
|
this.events = [];
|
|
59
68
|
}
|
|
60
69
|
addProp(prop) {
|
|
61
70
|
this.props.push(prop);
|
|
62
71
|
}
|
|
72
|
+
addCommand(command) {
|
|
73
|
+
this.commands.push(command);
|
|
74
|
+
}
|
|
63
75
|
addEvent(event) {
|
|
64
76
|
this.events.push(event);
|
|
65
77
|
}
|
|
@@ -73,6 +85,9 @@ class ComponentJSIBinderHTemplate {
|
|
|
73
85
|
name: prop.name,
|
|
74
86
|
type: prop.isObject ? '"Object"' : 'true',
|
|
75
87
|
})),
|
|
88
|
+
commands: this.commands.map((command) => ({
|
|
89
|
+
name: command.name,
|
|
90
|
+
})),
|
|
76
91
|
bubblingEvents: this.events
|
|
77
92
|
.filter((event) => event.type === 'bubble')
|
|
78
93
|
.map((event) => ({
|
|
@@ -53,16 +53,26 @@ class GeneratedEventEmitRequestHandler : public EventEmitRequestHandler {
|
|
|
53
53
|
public:
|
|
54
54
|
void handleEvent(Context const &ctx) override {
|
|
55
55
|
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
56
|
+
auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
|
|
57
|
+
|
|
56
58
|
if (eventEmitter == nullptr) {
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
61
|
|
|
62
|
+
std::vector<std::string> supportedComponentNames = {
|
|
63
|
+
{{#arkTSComponents}}
|
|
64
|
+
"{{name}}",
|
|
65
|
+
{{/arkTSComponents}}
|
|
66
|
+
};
|
|
67
|
+
|
|
60
68
|
std::vector<std::string> supportedEventNames = {
|
|
61
69
|
{{#supportedEvents}}
|
|
62
70
|
"{{name}}",
|
|
63
71
|
{{/supportedEvents}}
|
|
64
72
|
};
|
|
65
|
-
|
|
73
|
+
|
|
74
|
+
if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
|
|
75
|
+
std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
66
76
|
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
67
77
|
}
|
|
68
78
|
}
|
|
@@ -121,6 +131,7 @@ class RNOHGeneratedPackageHTemplate {
|
|
|
121
131
|
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
122
132
|
turboModules: this.turboModules,
|
|
123
133
|
components: this.components,
|
|
134
|
+
arkTSComponents: this.components.filter((component) => component.isArkTSComponent),
|
|
124
135
|
supportedEvents: this.supportedEventNames.map((eventName) => ({
|
|
125
136
|
name: eventName,
|
|
126
137
|
})),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
4
4
|
*
|
|
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.
|
|
@@ -25,6 +25,7 @@ const metro_1 = __importDefault(require("metro"));
|
|
|
25
25
|
const Server_1 = __importDefault(require("metro/src/Server"));
|
|
26
26
|
const path_1 = __importDefault(require("path"));
|
|
27
27
|
const assetResolver_1 = require("../assetResolver");
|
|
28
|
+
const io_1 = require("../io");
|
|
28
29
|
const ARK_RESOURCE_PATH = './harmony/entry/src/main/resources/rawfile';
|
|
29
30
|
const ASSETS_DEFAULT_DEST_PATH = './harmony/entry/src/main/resources/rawfile/assets';
|
|
30
31
|
exports.commandBundleHarmony = {
|
|
@@ -67,6 +68,7 @@ exports.commandBundleHarmony = {
|
|
|
67
68
|
},
|
|
68
69
|
],
|
|
69
70
|
func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
const logger = new io_1.Logger();
|
|
70
72
|
const buildOptions = {
|
|
71
73
|
entry: args.entryFile,
|
|
72
74
|
platform: 'harmony',
|
|
@@ -79,7 +81,7 @@ exports.commandBundleHarmony = {
|
|
|
79
81
|
const bundle = yield createBundle(metroConfig, buildOptions);
|
|
80
82
|
yield saveBundle(bundle, args.bundleOutput, args.sourcemapOutput);
|
|
81
83
|
const assets = yield retrieveAssetsData(metroConfig, buildOptions);
|
|
82
|
-
copyAssets(assets, args.assetsDest);
|
|
84
|
+
(0, assetResolver_1.copyAssets)(logger, assets, args.assetsDest);
|
|
83
85
|
}),
|
|
84
86
|
};
|
|
85
87
|
function loadMetroConfig(configPath) {
|
|
@@ -118,68 +120,3 @@ function retrieveAssetsData(metroConfig, buildOptions) {
|
|
|
118
120
|
}
|
|
119
121
|
});
|
|
120
122
|
}
|
|
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
|
-
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
4
4
|
*
|
|
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.
|
|
@@ -119,11 +119,9 @@ function validateArgs(args) {
|
|
|
119
119
|
if (!args.rnohModulePath) {
|
|
120
120
|
throw new core_1.DescriptiveError({
|
|
121
121
|
whatHappened: "--rnoh-module-path argument wasn't provided",
|
|
122
|
-
whatCanUserDo:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
],
|
|
126
|
-
},
|
|
122
|
+
whatCanUserDo: [
|
|
123
|
+
'Please provide a path to the native React Native for Open Harmony module (rnoh) which is probably located somewhere in "<PROJECT_ROOT>/harmony" directory',
|
|
124
|
+
],
|
|
127
125
|
});
|
|
128
126
|
}
|
|
129
127
|
}
|
|
@@ -155,12 +153,10 @@ function throwErrorIfUnsupportedCodegenVersion(codegenVersion, maxSupportedCodeg
|
|
|
155
153
|
if (codegenVersion > maxSupportedCodegenVersion) {
|
|
156
154
|
throw new codegen_1.CodegenError({
|
|
157
155
|
whatHappened: `Package "${packageName}" requires codegenVersion: ${codegenVersion}, which is not supported (maxSupportedCodegenVersion=${maxSupportedCodegenVersion}).`,
|
|
158
|
-
whatCanUserDo:
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
],
|
|
163
|
-
},
|
|
156
|
+
whatCanUserDo: [
|
|
157
|
+
`Try downgrading "${packageName}".`,
|
|
158
|
+
'Update the "@react-native-oh/react-native-harmony-cli" package.',
|
|
159
|
+
],
|
|
164
160
|
});
|
|
165
161
|
}
|
|
166
162
|
}
|
|
@@ -181,7 +177,7 @@ function prepareDirectory(path, enableSafetyCheck) {
|
|
|
181
177
|
if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
|
|
182
178
|
throw new core_1.DescriptiveError({
|
|
183
179
|
whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
|
|
184
|
-
whatCanUserDo:
|
|
180
|
+
whatCanUserDo: ['Run codegen from different location'],
|
|
185
181
|
});
|
|
186
182
|
}
|
|
187
183
|
(0, core_1.maybeRemoveFilesInDirectory)(path);
|
|
@@ -190,11 +186,11 @@ function logCodegenResult(logger, fileContentByPath, projectRootPath) {
|
|
|
190
186
|
const sortedRelativePathStrings = Array.from(fileContentByPath.keys()).map((path) => node_path_1.default.relative(projectRootPath.getValue(), path.getValue()));
|
|
191
187
|
sortedRelativePathStrings.sort();
|
|
192
188
|
sortedRelativePathStrings.forEach((pathStr) => {
|
|
193
|
-
logger.
|
|
189
|
+
logger.debug((styles) => styles.gray(`• ${pathStr}`));
|
|
194
190
|
});
|
|
195
|
-
logger.
|
|
196
|
-
logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)
|
|
197
|
-
logger.
|
|
191
|
+
logger.debug(() => '');
|
|
192
|
+
logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`);
|
|
193
|
+
logger.debug(() => '');
|
|
198
194
|
}
|
|
199
195
|
function deriveCppDirectoryNameFromNpmPackageName(npmPackageName) {
|
|
200
196
|
let result = npmPackageName;
|