@rock-js/platform-harmony 0.11.6

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 (82) hide show
  1. package/README.md +7 -0
  2. package/dist/src/index.d.ts +1 -0
  3. package/dist/src/index.js +2 -0
  4. package/dist/src/index.js.map +1 -0
  5. package/dist/src/lib/commands/build/buildHarmony.d.ts +21 -0
  6. package/dist/src/lib/commands/build/buildHarmony.js +69 -0
  7. package/dist/src/lib/commands/build/buildHarmony.js.map +1 -0
  8. package/dist/src/lib/commands/build/command.d.ts +3 -0
  9. package/dist/src/lib/commands/build/command.js +15 -0
  10. package/dist/src/lib/commands/build/command.js.map +1 -0
  11. package/dist/src/lib/commands/getValidProjectConfig.d.ts +10 -0
  12. package/dist/src/lib/commands/getValidProjectConfig.js +39 -0
  13. package/dist/src/lib/commands/getValidProjectConfig.js.map +1 -0
  14. package/dist/src/lib/commands/run/command.d.ts +3 -0
  15. package/dist/src/lib/commands/run/command.js +15 -0
  16. package/dist/src/lib/commands/run/command.js.map +1 -0
  17. package/dist/src/lib/commands/run/findOutputFile.d.ts +2 -0
  18. package/dist/src/lib/commands/run/findOutputFile.js +14 -0
  19. package/dist/src/lib/commands/run/findOutputFile.js.map +1 -0
  20. package/dist/src/lib/commands/run/hdc.d.ts +11 -0
  21. package/dist/src/lib/commands/run/hdc.js +35 -0
  22. package/dist/src/lib/commands/run/hdc.js.map +1 -0
  23. package/dist/src/lib/commands/run/listHarmonyDevices.d.ts +7 -0
  24. package/dist/src/lib/commands/run/listHarmonyDevices.js +17 -0
  25. package/dist/src/lib/commands/run/listHarmonyDevices.js.map +1 -0
  26. package/dist/src/lib/commands/run/runHarmony.d.ts +24 -0
  27. package/dist/src/lib/commands/run/runHarmony.js +148 -0
  28. package/dist/src/lib/commands/run/runHarmony.js.map +1 -0
  29. package/dist/src/lib/commands/run/tryInstallAppOnDevice.d.ts +3 -0
  30. package/dist/src/lib/commands/run/tryInstallAppOnDevice.js +42 -0
  31. package/dist/src/lib/commands/run/tryInstallAppOnDevice.js.map +1 -0
  32. package/dist/src/lib/commands/run/tryLaunchAppOnDevice.d.ts +7 -0
  33. package/dist/src/lib/commands/run/tryLaunchAppOnDevice.js +43 -0
  34. package/dist/src/lib/commands/run/tryLaunchAppOnDevice.js.map +1 -0
  35. package/dist/src/lib/commands/run/tryRunHdcReverse.d.ts +1 -0
  36. package/dist/src/lib/commands/run/tryRunHdcReverse.js +21 -0
  37. package/dist/src/lib/commands/run/tryRunHdcReverse.js.map +1 -0
  38. package/dist/src/lib/commands/runHvigor.d.ts +11 -0
  39. package/dist/src/lib/commands/runHvigor.js +56 -0
  40. package/dist/src/lib/commands/runHvigor.js.map +1 -0
  41. package/dist/src/lib/commands/toPascalCase.d.ts +1 -0
  42. package/dist/src/lib/commands/toPascalCase.js +4 -0
  43. package/dist/src/lib/commands/toPascalCase.js.map +1 -0
  44. package/dist/src/lib/paths.d.ts +2 -0
  45. package/dist/src/lib/paths.js +12 -0
  46. package/dist/src/lib/paths.js.map +1 -0
  47. package/dist/src/lib/platformHarmony.d.ts +5 -0
  48. package/dist/src/lib/platformHarmony.js +19 -0
  49. package/dist/src/lib/platformHarmony.js.map +1 -0
  50. package/package.json +42 -0
  51. package/react-native.config.ts +31 -0
  52. package/template/harmony/AppScope/app.json5 +10 -0
  53. package/template/harmony/AppScope/resources/base/element/string.json +8 -0
  54. package/template/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  55. package/template/harmony/build-profile.json5 +36 -0
  56. package/template/harmony/codelinter.json +32 -0
  57. package/template/harmony/entry/build-profile.json5 +18 -0
  58. package/template/harmony/entry/hvigorfile.ts +13 -0
  59. package/template/harmony/entry/oh-package.json5 +8 -0
  60. package/template/harmony/entry/src/main/cpp/CMakeLists.txt +27 -0
  61. package/template/harmony/entry/src/main/cpp/PackageProvider.cpp +13 -0
  62. package/template/harmony/entry/src/main/ets/PackageProvider.ets +8 -0
  63. package/template/harmony/entry/src/main/ets/entryability/EntryAbility.ets +11 -0
  64. package/template/harmony/entry/src/main/ets/pages/Index.ets +42 -0
  65. package/template/harmony/entry/src/main/ets/workers/RNOHWorker.ets +16 -0
  66. package/template/harmony/entry/src/main/module.json5 +65 -0
  67. package/template/harmony/entry/src/main/resources/base/element/color.json +8 -0
  68. package/template/harmony/entry/src/main/resources/base/element/string.json +16 -0
  69. package/template/harmony/entry/src/main/resources/base/media/background.png +0 -0
  70. package/template/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
  71. package/template/harmony/entry/src/main/resources/base/media/layered_image.json +7 -0
  72. package/template/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
  73. package/template/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  74. package/template/harmony/entry/src/ohosTest/ets/test/List.test.ets +2 -0
  75. package/template/harmony/entry/src/ohosTest/module.json5 +13 -0
  76. package/template/harmony/gitignore +19 -0
  77. package/template/harmony/hvigor/hvigor-config.json5 +23 -0
  78. package/template/harmony/hvigorfile.ts +7 -0
  79. package/template/harmony/oh-package.json5 +17 -0
  80. package/template/metro.config.js +20 -0
  81. package/template/package.json +20 -0
  82. package/template/react-native.config.js +11 -0
@@ -0,0 +1,21 @@
1
+ import { logger, RockError, spawn } from '@rock-js/tools';
2
+ import { getHdcPath } from './hdc.js';
3
+ // Runs hdc rport tcp:8081 tcp:8081 to allow loading the jsbundle from the packager
4
+ export async function tryRunHdcReverse(packagerPort, device) {
5
+ try {
6
+ const hdcPath = getHdcPath();
7
+ const hdcArgs = [
8
+ '-t',
9
+ device,
10
+ 'rport',
11
+ `tcp:${packagerPort}`,
12
+ `tcp:${packagerPort}`,
13
+ ];
14
+ logger.debug(`Connecting "${device}" to the development server`);
15
+ await spawn(hdcPath, hdcArgs);
16
+ }
17
+ catch (error) {
18
+ throw new RockError(`Failed to connect "${device}" to development server using "hdb rport"`, { cause: error.stderr });
19
+ }
20
+ }
21
+ //# sourceMappingURL=tryRunHdcReverse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tryRunHdcReverse.js","sourceRoot":"","sources":["../../../../../src/lib/commands/run/tryRunHdcReverse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,mFAAmF;AACnF,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,YAA6B,EAC7B,MAAc;IAEd,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG;YACd,IAAI;YACJ,MAAM;YACN,OAAO;YACP,OAAO,YAAY,EAAE;YACrB,OAAO,YAAY,EAAE;SACtB,CAAC;QAEF,MAAM,CAAC,KAAK,CAAC,eAAe,MAAM,6BAA6B,CAAC,CAAC;QACjE,MAAM,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,SAAS,CACjB,sBAAsB,MAAM,2CAA2C,EACvE,EAAE,KAAK,EAAG,KAAyB,CAAC,MAAM,EAAE,CAC7C,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { BuildFlags } from './build/buildHarmony.js';
2
+ import type { DeviceData } from './run/listHarmonyDevices.js';
3
+ import type { Flags } from './run/runHarmony.js';
4
+ export type RunHvigorArgs = {
5
+ sourceDir: string;
6
+ bundleName: string;
7
+ args: BuildFlags | Flags;
8
+ artifactName: string;
9
+ device?: DeviceData;
10
+ };
11
+ export declare function runHvigor({ sourceDir, bundleName, args, artifactName, device, }: RunHvigorArgs): Promise<void>;
@@ -0,0 +1,56 @@
1
+ import path from 'node:path';
2
+ import { color, logger, RockError, saveLocalBuildCache, spawn, spinner, } from '@rock-js/tools';
3
+ import { getDevEcoBuildToolsPath } from '../paths.js';
4
+ import { findOutputFile } from './run/findOutputFile.js';
5
+ async function runOhpm(sourceDir, loader) {
6
+ loader.message('Installing dependencies with ohpm');
7
+ const ohpmPath = path.join(getDevEcoBuildToolsPath(), 'ohpm', 'bin', process.platform === 'win32' ? 'ohpm.bat' : 'ohpm');
8
+ try {
9
+ await spawn(ohpmPath, ['install', '--all', '--strict_ssl', 'true'], {
10
+ cwd: sourceDir,
11
+ });
12
+ }
13
+ catch (error) {
14
+ loader.stop('Failed to install dependencies with ohpm', 1);
15
+ throw new RockError('Failed to install native dependencies with ohpm', {
16
+ cause: error.output,
17
+ });
18
+ }
19
+ }
20
+ export async function runHvigor({ sourceDir, bundleName, args, artifactName, device, }) {
21
+ logger.log(`Build Settings:
22
+ Bundle Name ${color.bold(bundleName)}
23
+ Build Mode ${color.bold(args.buildMode)}`);
24
+ const loader = spinner({ indicator: 'timer' });
25
+ const message = `Building the app`;
26
+ loader.start(message);
27
+ await runOhpm(sourceDir, loader);
28
+ const hvigorPath = path.join(getDevEcoBuildToolsPath(), 'hvigor', 'bin', 'hvigorw.js');
29
+ try {
30
+ loader.message('Building the app with Hvigor');
31
+ await spawn('node', [
32
+ hvigorPath,
33
+ `-p`,
34
+ `module=${args.module}@default`,
35
+ `-p`,
36
+ `product=${args.product}`,
37
+ `-p`,
38
+ `buildMode=${args.buildMode}`,
39
+ `-p`,
40
+ `requiredDeviceType=phone`,
41
+ `assembleHap`,
42
+ ], { cwd: sourceDir });
43
+ loader.stop(`Built the app`);
44
+ }
45
+ catch (error) {
46
+ loader.stop('Failed to build the app', 1);
47
+ throw new RockError('Failed to build the app with Hvigor', {
48
+ cause: error.output,
49
+ });
50
+ }
51
+ const outputFilePath = await findOutputFile(sourceDir, args.module, device);
52
+ if (outputFilePath) {
53
+ saveLocalBuildCache(artifactName, outputFilePath);
54
+ }
55
+ }
56
+ //# sourceMappingURL=runHvigor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runHvigor.js","sourceRoot":"","sources":["../../../../src/lib/commands/runHvigor.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,KAAK,EACL,MAAM,EACN,SAAS,EACT,mBAAmB,EACnB,KAAK,EACL,OAAO,GAER,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAYzD,KAAK,UAAU,OAAO,CAAC,SAAiB,EAAE,MAAkC;IAC1E,MAAM,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC;IAEpD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CACxB,uBAAuB,EAAE,EACzB,MAAM,EACN,KAAK,EACL,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CACnD,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE;YAClE,GAAG,EAAE,SAAS;SACf,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,IAAI,CAAC,0CAA0C,EAAE,CAAC,CAAC,CAAC;QAC3D,MAAM,IAAI,SAAS,CAAC,iDAAiD,EAAE;YACrE,KAAK,EAAG,KAAyB,CAAC,MAAM;SACzC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAC9B,SAAS,EACT,UAAU,EACV,IAAI,EACJ,YAAY,EACZ,MAAM,GACQ;IACd,MAAM,CAAC,GAAG,CAAC;gBACG,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC;gBACtB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAE5C,MAAM,MAAM,GAAG,OAAO,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,kBAAkB,CAAC;IAEnC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAEtB,MAAM,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAEjC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAC1B,uBAAuB,EAAE,EACzB,QAAQ,EACR,KAAK,EACL,YAAY,CACb,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC;QAC/C,MAAM,KAAK,CACT,MAAM,EACN;YACE,UAAU;YACV,IAAI;YACJ,UAAU,IAAI,CAAC,MAAM,UAAU;YAC/B,IAAI;YACJ,WAAW,IAAI,CAAC,OAAO,EAAE;YACzB,IAAI;YACJ,aAAa,IAAI,CAAC,SAAS,EAAE;YAC7B,IAAI;YACJ,0BAA0B;YAC1B,aAAa;SACd,EACD,EAAE,GAAG,EAAE,SAAS,EAAE,CACnB,CAAC;QACF,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC;QAE1C,MAAM,IAAI,SAAS,CAAC,qCAAqC,EAAE;YACzD,KAAK,EAAG,KAAyB,CAAC,MAAM;SACzC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5E,IAAI,cAAc,EAAE,CAAC;QACnB,mBAAmB,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IACpD,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function toPascalCase(value: string): string;
@@ -0,0 +1,4 @@
1
+ export function toPascalCase(value) {
2
+ return value !== '' ? value[0].toUpperCase() + value.slice(1) : value;
3
+ }
4
+ //# sourceMappingURL=toPascalCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toPascalCase.js","sourceRoot":"","sources":["../../../../src/lib/commands/toPascalCase.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACxE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function getDevEcoSdkPath(): string;
2
+ export declare function getDevEcoBuildToolsPath(): string;
@@ -0,0 +1,12 @@
1
+ import path from 'node:path';
2
+ export function getDevEcoSdkPath() {
3
+ const sdkRoot = process.env['DEVECO_SDK_HOME'];
4
+ if (!sdkRoot) {
5
+ throw new Error('DEVECO_SDK_HOME environment variable is not set. Please set it and run again');
6
+ }
7
+ return sdkRoot;
8
+ }
9
+ export function getDevEcoBuildToolsPath() {
10
+ return path.join(getDevEcoSdkPath(), '..', 'tools');
11
+ }
12
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../../src/lib/paths.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,UAAU,gBAAgB;IAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC/C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,OAAO,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { PlatformOutput, PluginApi } from '@rock-js/config';
2
+ import { type HarmonyProjectConfig } from './commands/getValidProjectConfig.js';
3
+ type PluginConfig = HarmonyProjectConfig;
4
+ export declare const platformHarmony: (pluginConfig?: Partial<PluginConfig>) => (api: PluginApi) => PlatformOutput;
5
+ export default platformHarmony;
@@ -0,0 +1,19 @@
1
+ import { registerBuildCommand } from './commands/build/command.js';
2
+ import { getValidProjectConfig, } from './commands/getValidProjectConfig.js';
3
+ import { registerRunCommand } from './commands/run/command.js';
4
+ export const platformHarmony = (pluginConfig) => (api) => {
5
+ registerBuildCommand(api, pluginConfig);
6
+ registerRunCommand(api, pluginConfig);
7
+ return {
8
+ name: '@rock-js/platform-harmony',
9
+ description: 'Rock plugin for HarmonyOS Next.',
10
+ autolinkingConfig: {
11
+ get project() {
12
+ const harmonyConfig = getValidProjectConfig(api.getProjectRoot(), pluginConfig);
13
+ return harmonyConfig;
14
+ },
15
+ },
16
+ };
17
+ };
18
+ export default platformHarmony;
19
+ //# sourceMappingURL=platformHarmony.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platformHarmony.js","sourceRoot":"","sources":["../../../src/lib/platformHarmony.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACL,qBAAqB,GAEtB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAI/D,MAAM,CAAC,MAAM,eAAe,GAC1B,CAAC,YAAoC,EAAE,EAAE,CACzC,CAAC,GAAc,EAAkB,EAAE;IACjC,oBAAoB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IACxC,kBAAkB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IAEtC,OAAO;QACL,IAAI,EAAE,2BAA2B;QACjC,WAAW,EAAE,iCAAiC;QAC9C,iBAAiB,EAAE;YACjB,IAAI,OAAO;gBACT,MAAM,aAAa,GAAG,qBAAqB,CACzC,GAAG,CAAC,cAAc,EAAE,EACpB,YAAY,CACb,CAAC;gBACF,OAAO,aAAa,CAAC;YACvB,CAAC;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEJ,eAAe,eAAe,CAAC"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@rock-js/platform-harmony",
3
+ "version": "0.11.6",
4
+ "type": "module",
5
+ "types": "./dist/src/index.d.ts",
6
+ "exports": {
7
+ "types": "./dist/src/index.d.ts",
8
+ "default": "./dist/src/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "template",
13
+ "react-native.config.ts"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.lib.json",
17
+ "dev": "tsc -p tsconfig.lib.json --watch",
18
+ "publish:npm": "npm publish --access public",
19
+ "publish:verdaccio": "npm publish --registry http://localhost:4873 --userconfig ../../.npmrc"
20
+ },
21
+ "dependencies": {
22
+ "@rock-js/tools": "^0.11.6",
23
+ "json5": "^2.2.3",
24
+ "tslib": "^2.3.0"
25
+ },
26
+ "devDependencies": {
27
+ "@react-native-community/cli-types": "^20.0.0",
28
+ "@rock-js/config": "^0.11.6"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/callstack/rock.git",
36
+ "directory": "packages/platform-harmony"
37
+ },
38
+ "homepage": "https://rockjs.dev",
39
+ "bugs": "https://github.com/callstack/rock/issues",
40
+ "license": "MIT",
41
+ "author": "Callstack <incubator@callstack.com>"
42
+ }
@@ -0,0 +1,31 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { getValidProjectConfig } from './dist/src/lib/commands/getValidProjectConfig.js';
4
+
5
+ /**
6
+ * Get the dependency config for the Harmony platform. It's currently very bare bones
7
+ * and only supports aliasing, but that should be enough for now to list dependencies,
8
+ * that we use as input for fingerprinting.
9
+ * @param folder - The folder to get the dependency config for.
10
+ * @returns The dependency config.
11
+ */
12
+ function getDependencyConfig(folder: string) {
13
+ const packageJsonPath = path.join(folder, 'package.json');
14
+ if (fs.existsSync(packageJsonPath)) {
15
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
16
+ if (packageJson.harmony?.alias) {
17
+ return { alias: packageJson.harmony.alias };
18
+ }
19
+ }
20
+ return null;
21
+ }
22
+
23
+ export default {
24
+ platforms: {
25
+ harmony: {
26
+ npmPackageName: '@react-native-oh/react-native-harmony',
27
+ projectConfig: getValidProjectConfig,
28
+ dependencyConfig: getDependencyConfig,
29
+ },
30
+ },
31
+ };
@@ -0,0 +1,10 @@
1
+ {
2
+ "app": {
3
+ "bundleName": "com.example.helloworld",
4
+ "vendor": "example",
5
+ "versionCode": 1000000,
6
+ "versionName": "1.0.0",
7
+ "icon": "$media:app_icon",
8
+ "label": "$string:app_name",
9
+ }
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "app_name",
5
+ "value": "HelloWorld"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ app: {
3
+ products: [
4
+ {
5
+ name: 'default',
6
+ signingConfig: 'default',
7
+ compatibleSdkVersion: '5.0.0(12)',
8
+ runtimeOS: 'HarmonyOS',
9
+ buildOption: {
10
+ nativeCompiler: 'BiSheng'
11
+ }
12
+ },
13
+ ],
14
+ buildModeSet: [
15
+ {
16
+ name: 'debug',
17
+ },
18
+ {
19
+ name: 'release',
20
+ },
21
+ ],
22
+ signingConfigs: [],
23
+ },
24
+ modules: [
25
+ {
26
+ name: 'entry',
27
+ srcPath: './entry',
28
+ targets: [
29
+ {
30
+ name: 'default',
31
+ applyToProducts: ['default'],
32
+ },
33
+ ],
34
+ },
35
+ ],
36
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "files": ["**/*.ts", "**/*.ets"],
3
+ "ignore": [
4
+ "**/ohosTest/**/*",
5
+ "**/node_modules/**/*",
6
+ "**/hvigorfile.ts",
7
+ "**/node_modules/**/*",
8
+ "**/oh_modules/**/*",
9
+ "**/build/**/*",
10
+ "**/.preview/**/*"
11
+ ],
12
+ "plugins": ["@typescript-eslint"],
13
+ "ruleSet": [],
14
+ "rules": {
15
+ "@typescript-eslint/await-thenable": "warn",
16
+ "@typescript-eslint/consistent-type-imports": "warn",
17
+ "@typescript-eslint/explicit-function-return-type": "warn",
18
+ "@typescript-eslint/explicit-module-boundary-types": "warn",
19
+ "@typescript-eslint/no-dynamic-delete": "warn",
20
+ "@typescript-eslint/no-explicit-any": "warn",
21
+ "@typescript-eslint/no-for-in-array": "warn",
22
+ "@typescript-eslint/no-this-alias": "warn",
23
+ "@typescript-eslint/no-unnecessary-type-constraint": "warn",
24
+ "@typescript-eslint/no-unsafe-argument": "warn",
25
+ "@typescript-eslint/no-unsafe-assignment": "warn",
26
+ "@typescript-eslint/no-unsafe-call": "warn",
27
+ "@typescript-eslint/no-unsafe-member-access": "warn",
28
+ "@typescript-eslint/no-unsafe-return": "warn",
29
+ "@typescript-eslint/prefer-literal-enum-member": "warn"
30
+ },
31
+ "overrides": []
32
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "apiType": 'stageMode',
3
+ "buildOption": {
4
+ "externalNativeOptions": {
5
+ "path": "./src/main/cpp/CMakeLists.txt",
6
+ "arguments": "",
7
+ },
8
+ },
9
+ "targets": [
10
+ {
11
+ "name": "default",
12
+ "runtimeOS": "HarmonyOS"
13
+ },
14
+ {
15
+ "name": "ohosTest",
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,13 @@
1
+ import { hapTasks } from '@ohos/hvigor-ohos-plugin';
2
+ import { createRNOHModulePlugin } from '@rnoh/hvigor-plugin';
3
+
4
+ export default {
5
+ system: hapTasks,
6
+ plugins: [
7
+ createRNOHModulePlugin({
8
+ codegen: {
9
+ rnohModulePath: './oh_modules/@rnoh/react-native-openharmony',
10
+ },
11
+ }),
12
+ ],
13
+ };
@@ -0,0 +1,8 @@
1
+ {
2
+ "license": "ISC",
3
+ "devDependencies": {},
4
+ "name": "entry",
5
+ "description": "",
6
+ "version": "1.0.0",
7
+ "dependencies": {}
8
+ }
@@ -0,0 +1,27 @@
1
+ cmake_minimum_required(VERSION 3.11)
2
+ project(rnapp)
3
+
4
+ set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
5
+ set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
6
+ set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp")
7
+ set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated")
8
+ set(LOG_VERBOSITY_LEVEL 1)
9
+ set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
10
+ set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
11
+ set(WITH_HITRACE_SYSTRACE ON)
12
+ set(WITH_HITRACE_REACT_MARKER ON)
13
+ set(OH_MODULES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../oh_modules") # required by 'autolink_libraries'
14
+
15
+ add_subdirectory("${RNOH_CPP_DIR}" ./rn)
16
+
17
+ include("${CMAKE_CURRENT_SOURCE_DIR}/autolinking.cmake")
18
+
19
+ file(GLOB GENERATED_CPP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/generated/*.cpp") # this line is needed by codegen v1
20
+ add_library(rnoh_app SHARED
21
+ ${GENERATED_CPP_FILES}
22
+ "./PackageProvider.cpp"
23
+ "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
24
+ )
25
+ target_link_libraries(rnoh_app PUBLIC rnoh)
26
+
27
+ autolink_libraries(rnoh_app)
@@ -0,0 +1,13 @@
1
+ #include "RNOH/PackageProvider.h"
2
+ #include "RNOHPackagesFactory.h"
3
+ #include "generated/RNOHGeneratedPackage.h"
4
+
5
+ using namespace rnoh;
6
+
7
+ std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(
8
+ Package::Context ctx) {
9
+ auto packages = createRNOHPackages(ctx); // <= autolinking
10
+ packages.push_back(std::make_shared<RNOHGeneratedPackage>(
11
+ ctx)); // generated by codegen-harmony v1 on app preBuilt stage)
12
+ return packages;
13
+ }
@@ -0,0 +1,8 @@
1
+ import type { RNPackageContext, RNOHPackage } from '@rnoh/react-native-openharmony';
2
+ import { createRNOHPackages as createRNOHPackagesAutolinking } from "./RNOHPackagesFactory"
3
+
4
+ export function getRNOHPackages(ctx: RNPackageContext): RNOHPackage[] {
5
+ return [
6
+ ...createRNOHPackagesAutolinking(ctx)
7
+ ]
8
+ }
@@ -0,0 +1,11 @@
1
+ import {RNAbility} from '@rnoh/react-native-openharmony';
2
+
3
+ export default class EntryAbility extends RNAbility {
4
+ override getPagePath() {
5
+ return 'pages/Index';
6
+ }
7
+
8
+ override getRNOHWorkerScriptUrl() {
9
+ return "entry/ets/workers/RNOHWorker.ets"
10
+ }
11
+ }
@@ -0,0 +1,42 @@
1
+ import {
2
+ AnyJSBundleProvider,
3
+ MetroJSBundleProvider,
4
+ RNApp,
5
+ RNOHErrorDialog,
6
+ ResourceJSBundleProvider,
7
+ RNOHCoreContext
8
+ } from '@rnoh/react-native-openharmony';
9
+ import { getRNOHPackages } from '../PackageProvider';
10
+
11
+ @Entry
12
+ @Component
13
+ struct Index {
14
+ @StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
15
+
16
+ build() {
17
+ Column() {
18
+ if (this.rnohCoreContext) {
19
+ if (this.rnohCoreContext?.isDebugModeEnabled) {
20
+ RNOHErrorDialog({ ctx: this.rnohCoreContext })
21
+ }
22
+ RNApp({
23
+ rnInstanceConfig: {
24
+ name: "HelloWorld",
25
+ createRNPackages: getRNOHPackages,
26
+ fontResourceByFontFamily: {},
27
+ enableDebugger: this.rnohCoreContext?.isDebugModeEnabled,
28
+ },
29
+ appKey: "HelloWorld",
30
+ jsBundleProvider: this.rnohCoreContext?.isDebugModeEnabled ?
31
+ new AnyJSBundleProvider([
32
+ new MetroJSBundleProvider(),
33
+ new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'index.jsbundle'),
34
+ ]) :
35
+ new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'index.jsbundle'),
36
+ })
37
+ }
38
+ }
39
+ .height('100%')
40
+ .width('100%')
41
+ }
42
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Importing some ets files in the following way results in runtime errors e.g.
3
+ * import { setupRNOHWorker } from "@rnoh/react-native-openharmony"
4
+ *
5
+ * It looks like this is ArkTS problem and it may be fixed in the future.
6
+ * For the time being, use direct imports.
7
+ */
8
+ import { setupRNOHWorker } from "@rnoh/react-native-openharmony/src/main/ets/setupRNOHWorker"
9
+ import { getRNOHPackages } from "../PackageProvider"
10
+
11
+ setupRNOHWorker({
12
+ createWorkerRNInstanceConfig: (_rnInstanceName) => {
13
+ return { thirdPartyPackagesFactory: getRNOHPackages }
14
+ }
15
+ })
16
+
@@ -0,0 +1,65 @@
1
+ {
2
+ "module": {
3
+ "name": "entry",
4
+ "type": "entry",
5
+ "description": "$string:module_desc",
6
+ "mainElement": "EntryAbility",
7
+ "deviceTypes": [
8
+ "default"
9
+ ],
10
+ "deliveryWithInstall": true,
11
+ "installationFree": false,
12
+ "pages": "$profile:main_pages",
13
+ // This is needed by bundleManager.canOpenLink to check if the app can open some url
14
+ "querySchemes": [
15
+ "maps",
16
+ "http",
17
+ "https",
18
+ "customDomain"
19
+ ],
20
+ "requestPermissions": [
21
+ {
22
+ "name": "ohos.permission.INTERNET"
23
+ },
24
+ {
25
+ "name": "ohos.permission.VIBRATE"
26
+ }
27
+ ],
28
+ "metadata": [
29
+ {
30
+ "name": "OPTLazyForEach",
31
+ "value": "true",
32
+ },
33
+ {
34
+ "name": "can_preview_text",
35
+ "value": "true",
36
+ },
37
+ {
38
+ "name": "halfLeading",
39
+ "value": "true",
40
+ },
41
+ ],
42
+ "abilities": [
43
+ {
44
+ "name": "EntryAbility",
45
+ "srcEntry": "./ets/entryability/EntryAbility.ets",
46
+ "description": "$string:EntryAbility_desc",
47
+ "icon": "$media:layered_image",
48
+ "label": "$string:EntryAbility_label",
49
+ "startWindowIcon": "$media:startIcon",
50
+ "startWindowBackground": "$color:start_window_background",
51
+ "visible": true,
52
+ "skills": [
53
+ {
54
+ "entities": [
55
+ "entity.system.home"
56
+ ],
57
+ "actions": [
58
+ "action.system.home"
59
+ ],
60
+ }
61
+ ]
62
+ }
63
+ ]
64
+ }
65
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "color": [
3
+ {
4
+ "name": "start_window_background",
5
+ "value": "#FFFFFF"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "module_desc",
5
+ "value": ""
6
+ },
7
+ {
8
+ "name": "EntryAbility_desc",
9
+ "value": ""
10
+ },
11
+ {
12
+ "name": "EntryAbility_label",
13
+ "value": "helloworld"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "layered-image":
3
+ {
4
+ "background" : "$media:background",
5
+ "foreground" : "$media:foreground"
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "src": [
3
+ "pages/Index"
4
+ ]
5
+ }
@@ -0,0 +1,2 @@
1
+ export default function testsuite() {
2
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "module": {
3
+ "name": "entry_test",
4
+ "type": "feature",
5
+ "deviceTypes": [
6
+ "phone",
7
+ "tablet",
8
+ "2in1"
9
+ ],
10
+ "deliveryWithInstall": true,
11
+ "installationFree": false
12
+ }
13
+ }