@react-native-oh/react-native-harmony-cli 0.0.30 → 0.0.36

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.
Files changed (66) hide show
  1. package/dist/assetResolver.js +105 -10
  2. package/dist/autolinking/Autolinking.js +9 -11
  3. package/dist/codegen/core/EventUtils.js +5 -8
  4. package/dist/codegen/core/TypeAnnotationToTS.js +3 -3
  5. package/dist/codegen/core/UberSchema.js +7 -11
  6. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +3 -0
  7. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +3 -0
  8. package/dist/codegen/generators/CppComponentCodeGenerator.js +3 -0
  9. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +15 -0
  10. package/dist/commands/bundle-harmony.js +4 -67
  11. package/dist/commands/codegen-harmony.js +13 -17
  12. package/dist/commands/codegen-lib-harmony.js +10 -14
  13. package/dist/commands/create-metro-host-constants.js +1 -1
  14. package/dist/commands/index.js +2 -1
  15. package/dist/commands/init.js +703 -0
  16. package/dist/commands/link-harmony.js +1 -1
  17. package/dist/commands/pack-harmony.js +1 -1
  18. package/dist/commands/run-harmony.js +438 -0
  19. package/dist/commands/types.js +8 -0
  20. package/dist/commands/unpack-harmony.js +2 -4
  21. package/dist/commands/verify-package-harmony.js +2 -2
  22. package/dist/core/CodegenConfig.js +4 -6
  23. package/dist/core/DescriptiveError.js +8 -4
  24. package/dist/core/PackageJSON.js +4 -7
  25. package/dist/core/fs.js +4 -5
  26. package/dist/index.js +2 -1
  27. package/dist/io/CliExecutor.js +57 -24
  28. package/dist/io/Logger.js +72 -42
  29. package/dist/io/TarGz.js +1 -2
  30. package/dist/io/__fixtures__.js +9 -3
  31. package/dist/io/fsUtils.js +1 -2
  32. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +1 -2
  33. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +1 -2
  34. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +1 -2
  35. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +1 -2
  36. package/dist/package-verifier/verify-package.js +7 -10
  37. package/package.json +10 -3
  38. package/src/assetResolver.ts +117 -11
  39. package/src/autolinking/Autolinking.ts +10 -12
  40. package/src/codegen/core/EventUtils.ts +4 -6
  41. package/src/codegen/core/UberSchema.ts +7 -11
  42. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +3 -0
  43. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +3 -0
  44. package/src/codegen/generators/CppComponentCodeGenerator.ts +3 -0
  45. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +24 -1
  46. package/src/commands/bundle-harmony.ts +6 -81
  47. package/src/commands/codegen-harmony.ts +14 -19
  48. package/src/commands/codegen-lib-harmony.ts +11 -16
  49. package/src/commands/create-metro-host-constants.ts +2 -2
  50. package/src/commands/index.ts +2 -1
  51. package/src/commands/init.ts +755 -0
  52. package/src/commands/link-harmony.ts +2 -2
  53. package/src/commands/pack-harmony.ts +2 -2
  54. package/src/commands/run-harmony.ts +478 -0
  55. package/src/commands/types.ts +21 -0
  56. package/src/commands/unpack-harmony.ts +3 -5
  57. package/src/commands/verify-package-harmony.ts +3 -3
  58. package/src/core/CodegenConfig.ts +4 -6
  59. package/src/core/DescriptiveError.ts +9 -9
  60. package/src/core/PackageJSON.ts +5 -8
  61. package/src/core/fs.ts +2 -2
  62. package/src/index.ts +5 -3
  63. package/src/io/CliExecutor.ts +56 -34
  64. package/src/io/Logger.ts +78 -45
  65. package/src/io/__fixtures__.ts +15 -11
  66. package/src/package-verifier/verify-package.ts +5 -7
@@ -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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getAssetDestRelativePath = void 0;
10
- function getAssetDestRelativePath(asset) {
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
- return `${fileName}.${asset.type}`;
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}`.slice('assets/'.length);
77
+ return `${folderPath}/${asset.name}`.replace(/^assets\//, '');
18
78
  }
19
79
  function getBasePath(asset) {
20
- let basePath = asset.httpServerLocation;
21
- if (basePath[0] === '/') {
22
- basePath = basePath.substr(1);
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
- return basePath;
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.info((styles) => `[${styles.green(styles.bold('link'))}] ${npmPackageName}`);
256
+ this.logger.debug((styles) => `[${styles.green(styles.bold('link'))}] ${npmPackageName}`);
259
257
  });
260
258
  output.skippedLibraryNpmPackageNames.forEach((npmPackageName) => {
261
- this.logger.warn((styles) => `[${styles.yellow(styles.bold('skip'))}] ${npmPackageName}`);
259
+ this.logger.debug((styles) => `[${styles.yellow(styles.bold('skip'))}] ${npmPackageName}`);
262
260
  });
263
- this.logger.info(() => '');
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.info((styles) => styles.gray(`• ${pathStr}`));
266
+ this.logger.debug((styles) => styles.gray(`• ${pathStr}`));
269
267
  });
270
- this.logger.info(() => '');
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`, { prefix: true });
272
- this.logger.info(() => '');
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 = void 0;
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
- default: [
18
- 'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
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.wrapWithQuotes = exports.getStringifiedTSDefaultValueFromPropTypeAnnotation = exports.TypeAnnotationToTS = void 0;
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
- default: [
46
- `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}`,
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
- default: [
82
- `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}`,
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;
@@ -46,6 +46,9 @@ class ArkTSComponentCodeGeneratorArkTS {
46
46
  });
47
47
  });
48
48
  shape.commands.forEach((command) => {
49
+ componentJSIBinderHTemplate.addCommand({
50
+ name: command.name,
51
+ });
49
52
  componentUtilsTSTemplate.addCommand({
50
53
  name: command.name,
51
54
  argsTSType: '[' +
@@ -44,6 +44,9 @@ class ArkTSComponentCodeGeneratorCAPI {
44
44
  });
45
45
  });
46
46
  shape.commands.forEach((command) => {
47
+ componentJSIBinderHTemplate.addCommand({
48
+ name: command.name,
49
+ });
47
50
  componentUtilsTSTemplate.addCommand({
48
51
  name: command.name,
49
52
  argsTSType: '[' +
@@ -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) => ({
@@ -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) => ({
@@ -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
- default: [
124
- 'Please provide a path to the native React Native for Open Harmony module (rnoh) which is probably located somewhere in "<PROJECT_ROOT>/harmony" directory',
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
- rnAppDeveloper: [
160
- `Try downgrading "${packageName}".`,
161
- 'Update the "@rnoh/react-native-harmony-cli" package.',
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: { default: ['Run codegen from different location'] },
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.info((styles) => styles.gray(`• ${pathStr}`));
189
+ logger.debug((styles) => styles.gray(`• ${pathStr}`));
194
190
  });
195
- logger.info(() => '');
196
- logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`, { prefix: true });
197
- logger.info(() => '');
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;
@@ -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.
@@ -107,19 +107,19 @@ function validateRawArgs(rawArgs) {
107
107
  if (!rawArgs.npmPackageName) {
108
108
  throw new core_1.DescriptiveError({
109
109
  whatHappened: '--npm-package-name is required',
110
- whatCanUserDo: { default: ['Please specify --npm-package-name'] },
110
+ whatCanUserDo: ['Please specify --npm-package-name'],
111
111
  });
112
112
  }
113
113
  if (!rawArgs.cppOutputPath) {
114
114
  throw new core_1.DescriptiveError({
115
115
  whatHappened: '--cpp-output-path is required',
116
- whatCanUserDo: { default: ['Please specify --cpp-output-path'] },
116
+ whatCanUserDo: ['Please specify --cpp-output-path'],
117
117
  });
118
118
  }
119
119
  if (!rawArgs.etsOutputPath) {
120
120
  throw new core_1.DescriptiveError({
121
121
  whatHappened: '--ets-output-path is required',
122
- whatCanUserDo: { default: ['Please specify --ets-output-path'] },
122
+ whatCanUserDo: ['Please specify --ets-output-path'],
123
123
  });
124
124
  }
125
125
  return {
@@ -138,9 +138,7 @@ function specPathsToSpecFilePaths(specPaths) {
138
138
  if (!node_fs_1.default.existsSync(specPath.getValue())) {
139
139
  throw new core_1.DescriptiveError({
140
140
  whatHappened: `No such file or directory: ${specPath.getValue()}`,
141
- whatCanUserDo: {
142
- default: [`Are you sure provided specPath exists?`],
143
- },
141
+ whatCanUserDo: [`Are you sure provided specPath exists?`],
144
142
  });
145
143
  }
146
144
  if (node_fs_1.default.lstatSync(specPath.getValue()).isDirectory()) {
@@ -237,12 +235,10 @@ function prepareDirectory(path, enableSafetyCheck) {
237
235
  if (enableSafetyCheck && !path.getValue().startsWith(process.cwd())) {
238
236
  throw new core_1.DescriptiveError({
239
237
  whatHappened: `Tried to remove files in ${path.getValue()}\nand that path is outside current working directory`,
240
- whatCanUserDo: {
241
- default: [
242
- 'Run this command with --no-safety-check flag',
243
- 'Run codegen from different location',
244
- ],
245
- },
238
+ whatCanUserDo: [
239
+ 'Run this command with --no-safety-check flag',
240
+ 'Run codegen from different location',
241
+ ],
246
242
  });
247
243
  }
248
244
  (0, core_1.maybeRemoveFilesInDirectory)(path);
@@ -254,6 +250,6 @@ function logCodegenResult(logger, fileContentByPath, rootPath) {
254
250
  logger.info((styles) => styles.gray(`• ${pathStr}`));
255
251
  });
256
252
  logger.info(() => '');
257
- logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`, { prefix: true });
253
+ logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`);
258
254
  logger.info(() => '');
259
255
  }
@@ -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.
@@ -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.
@@ -28,3 +28,4 @@ __exportStar(require("./codegen-harmony"), exports);
28
28
  __exportStar(require("./verify-package-harmony"), exports);
29
29
  __exportStar(require("./codegen-lib-harmony"), exports);
30
30
  __exportStar(require("./link-harmony"), exports);
31
+ __exportStar(require("./run-harmony"), exports);