@react-native-oh/react-native-harmony-cli 0.0.25 → 0.0.26

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 (116) hide show
  1. package/.prettierrc +6 -6
  2. package/jest.config.js +5 -5
  3. package/package.json +57 -56
  4. package/react-native.config.js +10 -10
  5. package/src/assetResolver.ts +21 -44
  6. package/src/codegen/core/CodeGenerator.ts +9 -0
  7. package/src/codegen/core/CodegenError.ts +3 -3
  8. package/src/codegen/core/EventUtils.ts +18 -18
  9. package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -75
  10. package/src/codegen/core/TypeAnnotationToTS.ts +188 -188
  11. package/src/codegen/core/UberSchema.ts +142 -99
  12. package/src/codegen/core/index.ts +5 -5
  13. package/src/codegen/generators/{ComponentCodeGenerator.ts → ComponentCodeGeneratorArkTS.ts} +112 -98
  14. package/src/codegen/generators/ComponentCodeGeneratorCAPI.ts +114 -0
  15. package/src/codegen/generators/GlueCodeGenerator.ts +109 -0
  16. package/src/codegen/generators/NativeModuleCodeGenerator.ts +115 -95
  17. package/src/codegen/generators/UberGeneratorV1.ts +64 -0
  18. package/src/codegen/generators/UberGeneratorV2.ts +91 -0
  19. package/src/codegen/generators/index.ts +6 -3
  20. package/src/codegen/index.ts +2 -2
  21. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +116 -0
  22. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +55 -49
  23. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +93 -85
  24. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +210 -202
  25. package/src/codegen/templates/GeneratedPackageHTemplate.ts +107 -0
  26. package/src/codegen/templates/IndexTSTemplate.ts +53 -33
  27. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +130 -124
  28. package/src/codegen/templates/TurboModuleCppTemplate.ts +54 -47
  29. package/src/codegen/templates/TurboModuleHTemplate.ts +35 -26
  30. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +90 -81
  31. package/src/codegen/templates/index.ts +9 -8
  32. package/src/commands/bundle-harmony.ts +203 -203
  33. package/src/commands/codegen-harmony.ts +272 -143
  34. package/src/commands/create-metro-host-constants.ts +48 -48
  35. package/src/commands/index.ts +6 -6
  36. package/src/commands/pack-harmony.ts +121 -121
  37. package/src/commands/unpack-harmony.ts +231 -231
  38. package/src/commands/verify-package-harmony.ts +106 -106
  39. package/src/core/AbsolutePath.ts +50 -43
  40. package/src/core/CodegenConfig.ts +62 -54
  41. package/src/core/DescriptiveError.ts +61 -61
  42. package/src/core/OHPackageJSON5.ts +23 -23
  43. package/src/core/PackageJSON.ts +75 -63
  44. package/src/core/ProjectDependenciesManager.ts +77 -77
  45. package/src/core/ValidationError.ts +1 -1
  46. package/src/core/ValueObject.ts +2 -2
  47. package/src/core/fs.ts +31 -31
  48. package/src/core/index.ts +9 -9
  49. package/src/index.ts +20 -20
  50. package/src/io/Logger.ts +68 -68
  51. package/src/io/TarGz.ts +26 -26
  52. package/src/io/fsUtils.ts +24 -24
  53. package/src/io/index.ts +3 -3
  54. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -28
  55. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -24
  56. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -18
  57. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -47
  58. package/src/package-verifier/checks/index.ts +4 -4
  59. package/src/package-verifier/index.ts +2 -2
  60. package/src/package-verifier/types.ts +12 -12
  61. package/src/package-verifier/verify-package.ts +117 -117
  62. package/tsconfig.build.json +6 -6
  63. package/tsconfig.json +2 -2
  64. package/dist/assetResolver.js +0 -41
  65. package/dist/codegen/core/Codegen.js +0 -35
  66. package/dist/codegen/core/CodegenError.js +0 -7
  67. package/dist/codegen/core/EventUtils.js +0 -19
  68. package/dist/codegen/core/TypeAnnotationToTS.js +0 -132
  69. package/dist/codegen/core/UberSchema.js +0 -74
  70. package/dist/codegen/core/index.js +0 -21
  71. package/dist/codegen/generators/ComponentCodeGenerator.js +0 -66
  72. package/dist/codegen/generators/NativeModuleCodeGenerator.js +0 -64
  73. package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
  74. package/dist/codegen/generators/index.js +0 -19
  75. package/dist/codegen/index.js +0 -18
  76. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +0 -55
  77. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +0 -78
  78. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -181
  79. package/dist/codegen/templates/IndexTSTemplate.js +0 -31
  80. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +0 -117
  81. package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -45
  82. package/dist/codegen/templates/TurboModuleHTemplate.js +0 -32
  83. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -64
  84. package/dist/codegen/templates/index.js +0 -24
  85. package/dist/commands/bundle-harmony.js +0 -179
  86. package/dist/commands/codegen-harmony.js +0 -110
  87. package/dist/commands/create-metro-host-constants.js +0 -61
  88. package/dist/commands/index.js +0 -22
  89. package/dist/commands/pack-harmony.js +0 -100
  90. package/dist/commands/unpack-harmony.js +0 -184
  91. package/dist/commands/verify-package-harmony.js +0 -127
  92. package/dist/core/AbsolutePath.js +0 -41
  93. package/dist/core/CodegenConfig.js +0 -53
  94. package/dist/core/DescriptiveError.js +0 -49
  95. package/dist/core/OHPackageJSON5.js +0 -23
  96. package/dist/core/PackageJSON.js +0 -53
  97. package/dist/core/ProjectDependenciesManager.js +0 -70
  98. package/dist/core/ValidationError.js +0 -6
  99. package/dist/core/ValueObject.js +0 -2
  100. package/dist/core/fs.js +0 -36
  101. package/dist/core/index.js +0 -25
  102. package/dist/index.js +0 -14
  103. package/dist/io/Logger.js +0 -71
  104. package/dist/io/TarGz.js +0 -28
  105. package/dist/io/fsUtils.js +0 -23
  106. package/dist/io/index.js +0 -19
  107. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +0 -38
  108. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +0 -32
  109. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +0 -26
  110. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +0 -51
  111. package/dist/package-verifier/checks/index.js +0 -20
  112. package/dist/package-verifier/index.js +0 -18
  113. package/dist/package-verifier/types.js +0 -2
  114. package/dist/package-verifier/verify-package.js +0 -100
  115. package/src/codegen/core/Codegen.ts +0 -44
  116. package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TurboModuleHTemplate = void 0;
7
- const mustache_1 = __importDefault(require("mustache"));
8
- const TEMPLATE = `
9
- #pragma once
10
-
11
- // This file was generated.
12
-
13
- #include "RNOH/ArkTSTurboModule.h"
14
-
15
- namespace rnoh {
16
-
17
- class JSI_EXPORT {{className}} : public ArkTSTurboModule {
18
- public:
19
- {{className}}(const ArkTSTurboModule::Context ctx, const std::string name);
20
- };
21
-
22
- } // namespace rnoh
23
- `;
24
- class TurboModuleHTemplate {
25
- constructor(name) {
26
- this.name = name;
27
- }
28
- build() {
29
- return mustache_1.default.render(TEMPLATE, { className: this.name });
30
- }
31
- }
32
- exports.TurboModuleHTemplate = TurboModuleHTemplate;
@@ -1,64 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TurboModuleInterfaceTS = void 0;
7
- const mustache_1 = __importDefault(require("mustache"));
8
- const TEMPLATE = `
9
- // This file was generated.
10
- import { Tag } from "../../ts"
11
-
12
- export namespace {{name}} {
13
- export const NAME = '{{name}}' as const
14
-
15
- {{#enums}}
16
- export enum {{name}} {
17
- {{#members}}
18
- {{name}} = {{{value}}},
19
- {{/members}}
20
- }
21
-
22
- {{/enums}}
23
- {{#aliases}}
24
- export type {{name}} = {{{type}}}
25
-
26
- {{/aliases}}
27
- export interface Spec {
28
- {{#methods}}
29
- {{name}}({{{stringifiedArgs}}}): {{{returnType}}};
30
-
31
- {{/methods}}
32
- }
33
- }
34
- `;
35
- class TurboModuleInterfaceTS {
36
- constructor(name) {
37
- this.name = name;
38
- this.methods = [];
39
- this.aliases = [];
40
- this.enumModels = [];
41
- }
42
- addAlias(alias) {
43
- this.aliases.push(alias);
44
- }
45
- addEnum(enumModel) {
46
- this.enumModels.push(enumModel);
47
- }
48
- addMethod(method) {
49
- this.methods.push(method);
50
- }
51
- build() {
52
- return mustache_1.default.render(TEMPLATE.trimStart(), {
53
- name: this.name,
54
- aliases: this.aliases,
55
- enums: this.enumModels,
56
- methods: this.methods.map((method) => ({
57
- name: method.name,
58
- stringifiedArgs: method.stringifiedArgs,
59
- returnType: method.returnType,
60
- })),
61
- });
62
- }
63
- }
64
- exports.TurboModuleInterfaceTS = TurboModuleInterfaceTS;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./TurboModuleHTemplate"), exports);
18
- __exportStar(require("./TurboModuleCppTemplate"), exports);
19
- __exportStar(require("./RNOHGeneratedPackageHTemplate"), exports);
20
- __exportStar(require("./ComponentJSIBinderHTemplate"), exports);
21
- __exportStar(require("./ComponentDescriptorHTemplate"), exports);
22
- __exportStar(require("./ComponentUtilsTSTemplate"), exports);
23
- __exportStar(require("./IndexTSTemplate"), exports);
24
- __exportStar(require("./TurboModuleSpecTSTemplate"), exports);
@@ -1,179 +0,0 @@
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.commandBundleHarmony = void 0;
16
- const fs_1 = __importDefault(require("fs"));
17
- const fs_extra_1 = __importDefault(require("fs-extra"));
18
- const metro_1 = __importDefault(require("metro"));
19
- const Server_1 = __importDefault(require("metro/src/Server"));
20
- const path_1 = __importDefault(require("path"));
21
- const assetResolver_1 = require("../assetResolver");
22
- const ARK_RESOURCE_PATH = './harmony/entry/src/main/resources/rawfile';
23
- const ASSETS_DEFAULT_DEST_PATH = './harmony/entry/src/main/resources/rawfile/assets';
24
- exports.commandBundleHarmony = {
25
- name: 'bundle-harmony',
26
- description: 'Creates JS bundle, creates a special cpp header containing the JS code, copies assets directory to the project.',
27
- options: [
28
- {
29
- name: '--dev [boolean]',
30
- description: 'If false, warnings are disabled and the bundle is minified',
31
- parse: (val) => val !== 'false',
32
- default: true,
33
- },
34
- {
35
- name: '--entry-file <path>',
36
- description: 'Path to the root JS file, either absolute or relative to JS root',
37
- default: 'index.js',
38
- },
39
- {
40
- name: '--config <path>',
41
- description: 'Path to the Metro configuration file',
42
- },
43
- {
44
- name: '--bundle-output <path>',
45
- description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
46
- default: ARK_RESOURCE_PATH + '/bundle.harmony.js',
47
- },
48
- {
49
- name: '--assets-dest <path>',
50
- description: 'Directory name where to store assets referenced in the bundle',
51
- default: ASSETS_DEFAULT_DEST_PATH,
52
- },
53
- {
54
- name: '--sourcemap-output <path>',
55
- description: 'File name where to store the resulting source map, ex. /tmp/groups.map',
56
- },
57
- {
58
- name: '--minify [boolean]',
59
- description: 'Allows overriding whether bundle is minified',
60
- parse: (val) => val !== 'false',
61
- },
62
- ],
63
- func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
64
- const buildOptions = {
65
- entry: args.entryFile,
66
- platform: 'harmony',
67
- minify: args.minify !== undefined ? args.minify : !args.dev,
68
- dev: args.dev,
69
- sourceMap: args.sourcemapOutput,
70
- sourceMapUrl: args.sourcemapOutput,
71
- };
72
- const metroConfig = yield loadMetroConfig(args.config);
73
- const bundle = yield createBundle(metroConfig, buildOptions);
74
- yield saveBundle(bundle, args.bundleOutput, args.sourcemapOutput);
75
- const assets = yield retrieveAssetsData(metroConfig, buildOptions);
76
- copyAssets(assets, args.assetsDest);
77
- }),
78
- };
79
- function loadMetroConfig(configPath) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- return configPath
82
- ? yield metro_1.default.loadConfig({ config: configPath })
83
- : yield metro_1.default.loadConfig();
84
- });
85
- }
86
- function createBundle(metroConfig, buildOptions) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- // casting needed as Metro.runBuild returns Promise<{code: string, map: string}>
89
- // despite being typed as Promise<void>
90
- return (yield metro_1.default.runBuild(metroConfig, buildOptions));
91
- });
92
- }
93
- function saveBundle(bundle, bundleOutput, sourceMapOutput) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- yield fs_extra_1.default.ensureDir(path_1.default.dirname(bundleOutput));
96
- fs_1.default.writeFileSync(bundleOutput, bundle.code);
97
- console.log(`[CREATED] ${bundleOutput}`);
98
- if (sourceMapOutput) {
99
- fs_1.default.writeFileSync(sourceMapOutput, bundle.map);
100
- console.log(`[CREATED] ${sourceMapOutput}`);
101
- }
102
- });
103
- }
104
- function retrieveAssetsData(metroConfig, buildOptions) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- const metroServer = new Server_1.default(metroConfig);
107
- try {
108
- return yield metroServer.getAssets(Object.assign(Object.assign(Object.assign({}, Server_1.default.DEFAULT_BUNDLE_OPTIONS), buildOptions), { entryFile: buildOptions.entry, bundleType: 'todo' }));
109
- }
110
- finally {
111
- metroServer.end();
112
- }
113
- });
114
- }
115
- function copyAssets(assetsData, assetsDest) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- if (assetsDest == null) {
118
- console.warn('Assets destination folder is not set, skipping...');
119
- return;
120
- }
121
- yield fs_extra_1.default.ensureDir(assetsDest);
122
- const fileDestBySrc = {};
123
- for (const asset of assetsData) {
124
- const idx = getHighestQualityFileIdx(asset);
125
- fileDestBySrc[asset.files[idx]] = path_1.default.join(assetsDest, (0, assetResolver_1.getAssetDestRelativePath)(asset));
126
- }
127
- return copyFiles(fileDestBySrc);
128
- });
129
- }
130
- function getHighestQualityFileIdx(assetData) {
131
- let result = 0;
132
- let maxScale = -1;
133
- for (let idx = 0; idx < assetData.scales.length; idx++) {
134
- const scale = assetData.scales[idx];
135
- if (scale > maxScale) {
136
- maxScale = scale;
137
- result = idx;
138
- }
139
- }
140
- return result;
141
- }
142
- function copyFiles(fileDestBySrc) {
143
- const fileSources = Object.keys(fileDestBySrc);
144
- if (fileSources.length === 0) {
145
- return Promise.resolve();
146
- }
147
- console.info(`Copying ${fileSources.length} asset files`);
148
- return new Promise((resolve, reject) => {
149
- const copyNext = (error) => {
150
- if (error) {
151
- reject(error);
152
- return;
153
- }
154
- if (fileSources.length === 0) {
155
- console.info('Done copying assets');
156
- resolve();
157
- }
158
- else {
159
- // fileSources.length === 0 is checked in previous branch, so this is string
160
- const src = fileSources.shift();
161
- const dest = fileDestBySrc[src];
162
- copyFile(src, dest, copyNext);
163
- }
164
- };
165
- copyNext();
166
- });
167
- }
168
- function copyFile(src, dest, onFinished) {
169
- const destDir = path_1.default.dirname(dest);
170
- fs_1.default.mkdir(destDir, { recursive: true }, (err) => {
171
- if (err) {
172
- onFinished(err);
173
- return;
174
- }
175
- fs_1.default.createReadStream(src)
176
- .pipe(fs_1.default.createWriteStream(dest))
177
- .on('finish', onFinished);
178
- });
179
- }
@@ -1,110 +0,0 @@
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.commandCodegenHarmony = void 0;
16
- const node_fs_1 = __importDefault(require("node:fs"));
17
- const node_path_1 = __importDefault(require("node:path"));
18
- const core_1 = require("../core");
19
- const codegen_1 = require("../codegen");
20
- const io_1 = require("../io");
21
- exports.commandCodegenHarmony = {
22
- name: 'codegen-harmony',
23
- description: 'Generates a glue layer and native utilities from Turbo Module or Fabric Components specifications',
24
- options: [
25
- {
26
- name: '--rnoh-module-path <path>',
27
- description: 'Specifies the relative path to the rnoh OHOS module',
28
- },
29
- {
30
- name: '--cpp-output-path <path>',
31
- description: 'Specifies the relative path to the output directory intended for storing generated C++ files',
32
- default: './harmony/entry/src/main/cpp/generated',
33
- },
34
- {
35
- name: '--project-root-path <path>',
36
- description: 'Relative path to package root',
37
- default: '.',
38
- },
39
- {
40
- name: '--debug [boolean]',
41
- description: 'Enables logging details',
42
- default: false,
43
- },
44
- ],
45
- func: (_argv, _config, args) => __awaiter(void 0, void 0, void 0, function* () {
46
- const logger = new io_1.Logger();
47
- try {
48
- validateArgs(args);
49
- const etsOutputPath = new core_1.AbsolutePath(args.rnohModulePath).copyWithNewSegment('generated');
50
- const cppOutputPath = new core_1.AbsolutePath(args.cppOutputPath);
51
- const projectRootPath = new core_1.AbsolutePath(args.projectRootPath);
52
- const codegen = createCodegen(cppOutputPath, etsOutputPath);
53
- const uberSchema = yield codegen_1.UberSchema.fromProjectRootPath(new core_1.AbsolutePath(args.projectRootPath));
54
- const fileContentByPath = codegen.generate(uberSchema);
55
- if (args.debug) {
56
- logger.debug((styles) => styles.gray(JSON.stringify(uberSchema.getValue(), null, 2)));
57
- }
58
- saveCodegenResult(fileContentByPath, cppOutputPath, etsOutputPath);
59
- logCodegenResult(logger, fileContentByPath, projectRootPath);
60
- }
61
- catch (err) {
62
- if (err instanceof core_1.DescriptiveError) {
63
- logger.descriptiveError(err);
64
- process.exit(1);
65
- }
66
- throw err;
67
- }
68
- }),
69
- };
70
- function validateArgs(args) {
71
- if (!args.rnohModulePath) {
72
- throw new core_1.DescriptiveError({
73
- whatHappened: "--rnoh-module-path argument wasn't provided",
74
- whatCanUserDo: {
75
- default: [
76
- 'Please provide a path to the native React Native for Open Harmony module (rnoh) which is probably located somewhere in "<PROJECT_ROOT>/harmony" directory',
77
- ],
78
- },
79
- });
80
- }
81
- }
82
- function createCodegen(cppOutputPath, etsOutputPath) {
83
- return new codegen_1.Codegen(new codegen_1.PackageCodeGenerator(cppOutputPath, etsOutputPath), {
84
- Component: new codegen_1.ComponentCodeGenerator(cppOutputPath, etsOutputPath.copyWithNewSegment('components')),
85
- NativeModule: new codegen_1.NativeModuleCodeGenerator(cppOutputPath, etsOutputPath.copyWithNewSegment('turboModules')),
86
- });
87
- }
88
- function saveCodegenResult(fileContentByPath, cppOutputPath, etsOutputPath) {
89
- prepareDirectory(cppOutputPath);
90
- prepareDirectory(etsOutputPath);
91
- prepareDirectory(etsOutputPath.copyWithNewSegment('components'));
92
- prepareDirectory(etsOutputPath.copyWithNewSegment('turboModules'));
93
- fileContentByPath.forEach((fileContent, path) => {
94
- node_fs_1.default.writeFileSync(path.getValue(), fileContent);
95
- });
96
- }
97
- function prepareDirectory(path) {
98
- (0, core_1.maybeMakeDirectories)(path);
99
- (0, core_1.maybeRemoveFilesInDirectory)(path);
100
- }
101
- function logCodegenResult(logger, fileContentByPath, projectRootPath) {
102
- const sortedRelativePathStrings = Array.from(fileContentByPath.keys()).map((path) => node_path_1.default.relative(projectRootPath.getValue(), path.getValue()));
103
- sortedRelativePathStrings.sort();
104
- sortedRelativePathStrings.forEach((pathStr) => {
105
- logger.info((styles) => styles.gray(`• ${pathStr}`));
106
- });
107
- logger.info(() => '');
108
- logger.info((styles) => `Generated ${styles.green(styles.bold(fileContentByPath.size))} file(s)`, { prefix: true });
109
- logger.info(() => '');
110
- }
@@ -1,61 +0,0 @@
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.commandCreateMetroConstantsHarmony = void 0;
16
- const node_os_1 = __importDefault(require("node:os"));
17
- const node_fs_1 = __importDefault(require("node:fs"));
18
- const node_path_1 = __importDefault(require("node:path"));
19
- exports.commandCreateMetroConstantsHarmony = {
20
- name: 'create-metro-host-constants-harmony',
21
- description: 'Creates a Typescript file that exports constant with IP of the host machine. That IP is later used to connect to the Metro server from a physical device.',
22
- options: [
23
- {
24
- name: '--output <string>',
25
- description: 'Output file',
26
- default: './harmony/entry/src/main/ets/codegen/MetroHostConstants.ts',
27
- },
28
- ],
29
- func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
30
- createMetroHostConstants(node_path_1.default.resolve(args.output));
31
- }),
32
- };
33
- function createMetroHostConstants(outputPath) {
34
- const networkInterfacesByName = node_os_1.default.networkInterfaces();
35
- const getIP = () => {
36
- var _a;
37
- for (let name of Object.keys(networkInterfacesByName)) {
38
- for (let net of (_a = networkInterfacesByName[name]) !== null && _a !== void 0 ? _a : []) {
39
- // skip over non-ipv4 and internal (i.e. 127.0.0.1) addresses
40
- if (net.family === 'IPv4' && !net.internal) {
41
- return net.address;
42
- }
43
- }
44
- }
45
- return;
46
- };
47
- const ip = getIP();
48
- const tsCode = [
49
- '// This file is autogenerated. Do not modify it manually.',
50
- '',
51
- `export const METRO_SERVER_IP = '${ip}';\n`,
52
- ];
53
- node_fs_1.default.writeFile(outputPath, tsCode.join('\n'), (err) => {
54
- if (err) {
55
- console.error(`Error writing to ${outputPath}:`, err);
56
- }
57
- else {
58
- console.log(`Created file at ${outputPath}`);
59
- }
60
- });
61
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./bundle-harmony"), exports);
18
- __exportStar(require("./pack-harmony"), exports);
19
- __exportStar(require("./unpack-harmony"), exports);
20
- __exportStar(require("./create-metro-host-constants"), exports);
21
- __exportStar(require("./codegen-harmony"), exports);
22
- __exportStar(require("./verify-package-harmony"), exports);
@@ -1,100 +0,0 @@
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.commandPackHarmony = void 0;
16
- const glob_1 = require("glob");
17
- const path_1 = __importDefault(require("path"));
18
- const tar_1 = __importDefault(require("tar"));
19
- const fs_1 = __importDefault(require("fs"));
20
- const core_1 = require("../core");
21
- const ignore_1 = __importDefault(require("ignore"));
22
- const json5_1 = __importDefault(require("json5"));
23
- exports.commandPackHarmony = {
24
- name: 'pack-harmony',
25
- description: 'Pack native code. Used for package development.',
26
- options: [
27
- {
28
- name: '--oh-module-path <string>',
29
- description: 'Path to the OH module',
30
- },
31
- {
32
- name: '--harmony-dir-path <string>',
33
- description: 'Path to the harmony dir',
34
- },
35
- {
36
- name: '--package-json-path <string>',
37
- description: 'Path to the package.json',
38
- },
39
- ],
40
- func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
41
- try {
42
- yield pack(path_1.default.resolve(args.harmonyDirPath), path_1.default.resolve(args.ohModulePath), path_1.default.resolve(args.packageJsonPath));
43
- }
44
- catch (err) {
45
- if (err instanceof core_1.ValidationError) {
46
- console.error('[ERROR]', err.message);
47
- process.exit(1);
48
- }
49
- else {
50
- throw err;
51
- }
52
- }
53
- }),
54
- };
55
- function pack(harmonyDirPath, ohModuleDirPath, packageJSONPath) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- syncVersions(packageJSONPath, path_1.default.join(ohModuleDirPath, 'oh-package.json5'));
58
- if (!fs_1.default.existsSync(harmonyDirPath)) {
59
- fs_1.default.mkdirSync(harmonyDirPath, { recursive: true });
60
- }
61
- yield createTGZFromDir(ohModuleDirPath, path_1.default.join(harmonyDirPath, `${path_1.default.parse(ohModuleDirPath).name}.tar.gz`));
62
- yield createTGZFromDir(harmonyDirPath, path_1.default.join(path_1.default.dirname(harmonyDirPath), 'harmony.tar.gz'));
63
- });
64
- }
65
- function syncVersions(packageJSONFilePath, ohPackageJSONFilePath) {
66
- const packageJSONFileContent = JSON.parse(fs_1.default.readFileSync(packageJSONFilePath, { encoding: 'utf-8' }));
67
- if (fs_1.default.existsSync(ohPackageJSONFilePath)) {
68
- const ohPackageJSONFileContent = json5_1.default.parse(fs_1.default.readFileSync(ohPackageJSONFilePath, { encoding: 'utf-8' }));
69
- ohPackageJSONFileContent['version'] = packageJSONFileContent['version'];
70
- fs_1.default.writeFileSync(ohPackageJSONFilePath, json5_1.default.stringify(ohPackageJSONFileContent, null, 2));
71
- }
72
- }
73
- function createTGZFromDir(dirPath, outputFilePath) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- const ig = getIgnoreUtil(path_1.default.join(dirPath, '.tarignore'));
76
- const filesToInclude = (0, glob_1.globSync)('**', {
77
- cwd: dirPath,
78
- nodir: true,
79
- }).filter((path) => !ig.ignores(path));
80
- yield createArchive(outputFilePath, dirPath, filesToInclude);
81
- });
82
- }
83
- function getIgnoreUtil(tarignorePath) {
84
- if (!fs_1.default.existsSync(tarignorePath)) {
85
- return (0, ignore_1.default)();
86
- }
87
- return (0, ignore_1.default)().add(fs_1.default.readFileSync(tarignorePath).toString());
88
- }
89
- function createArchive(outputFilePath, packageDirPath, filesToInclude) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- if (filesToInclude.length === 0) {
92
- throw new core_1.ValidationError('Nothing to pack');
93
- }
94
- yield tar_1.default.c({
95
- gzip: true,
96
- file: outputFilePath,
97
- cwd: packageDirPath,
98
- }, filesToInclude);
99
- });
100
- }