@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
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @rock-js/platform-harmony
2
+
3
+ HarmonyOS Next platform integration for Rock. This package is part of the Rock ecosystem and provides HarmonyOS-specific build and development tools.
4
+
5
+ ## Documentation
6
+
7
+ For detailed documentation about Rock and its tools, visit [Rock Documentation](https://rockjs.dev)
@@ -0,0 +1 @@
1
+ export * from './lib/platformHarmony.js';
@@ -0,0 +1,2 @@
1
+ export * from './lib/platformHarmony.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { RemoteBuildCache } from '@rock-js/tools';
2
+ import { type FingerprintSources } from '@rock-js/tools';
3
+ export interface BuildFlags {
4
+ buildMode: string;
5
+ module: string;
6
+ product: string;
7
+ local?: boolean;
8
+ }
9
+ export declare function buildHarmony(harmonyConfig: {
10
+ sourceDir: string;
11
+ bundleName: string;
12
+ }, args: BuildFlags, projectRoot: string, remoteCacheProvider: null | (() => RemoteBuildCache) | undefined, fingerprintOptions: FingerprintSources): Promise<void>;
13
+ export declare const options: ({
14
+ name: string;
15
+ description: string;
16
+ default?: undefined;
17
+ } | {
18
+ name: string;
19
+ description: string;
20
+ default: string;
21
+ })[];
@@ -0,0 +1,69 @@
1
+ import { colorLink, formatArtifactName, getBinaryPath, logger, outro, relativeToCwd, } from '@rock-js/tools';
2
+ import { findOutputFile } from '../run/findOutputFile.js';
3
+ import { runHvigor } from '../runHvigor.js';
4
+ export async function buildHarmony(harmonyConfig, args, projectRoot, remoteCacheProvider, fingerprintOptions) {
5
+ const { sourceDir, bundleName } = harmonyConfig;
6
+ const artifactName = await formatArtifactName({
7
+ platform: 'harmony',
8
+ traits: [args.buildMode],
9
+ root: projectRoot,
10
+ fingerprintOptions,
11
+ });
12
+ const binaryPath = await getBinaryPath({
13
+ platformName: 'harmony',
14
+ artifactName,
15
+ localFlag: args.local,
16
+ remoteCacheProvider,
17
+ fingerprintOptions,
18
+ sourceDir,
19
+ });
20
+ if (!binaryPath) {
21
+ await runHvigor({ sourceDir, args, artifactName, bundleName });
22
+ }
23
+ if (binaryPath) {
24
+ logger.log(`Build available at: ${colorLink(relativeToCwd(binaryPath))}`);
25
+ }
26
+ else {
27
+ const signedHapPath = await findOutputFile(sourceDir, args.module, {
28
+ deviceId: undefined,
29
+ readableName: undefined,
30
+ type: 'phone',
31
+ connected: false,
32
+ });
33
+ if (signedHapPath) {
34
+ logger.log(`Signed build available at: ${colorLink(relativeToCwd(signedHapPath))}`);
35
+ }
36
+ const unsignedHapPath = await findOutputFile(sourceDir, args.module, {
37
+ deviceId: undefined,
38
+ readableName: undefined,
39
+ type: 'emulator',
40
+ connected: false,
41
+ });
42
+ if (unsignedHapPath) {
43
+ logger.log(`Unsigned build available at: ${colorLink(relativeToCwd(unsignedHapPath))}`);
44
+ }
45
+ }
46
+ outro('Success 🎉.');
47
+ }
48
+ export const options = [
49
+ {
50
+ name: '--local',
51
+ description: 'Force local build with Gradle wrapper.',
52
+ },
53
+ {
54
+ name: '--module <string>',
55
+ description: 'Name of the OH module to run.',
56
+ default: 'entry',
57
+ },
58
+ {
59
+ name: '--build-mode <string>',
60
+ description: `Specify your app's build mode, e.g. "debug" or "release".`,
61
+ default: 'debug',
62
+ },
63
+ {
64
+ name: '--product <string>',
65
+ description: 'OpenHarmony product defined in build-profile.json5.',
66
+ default: 'default',
67
+ },
68
+ ];
69
+ //# sourceMappingURL=buildHarmony.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildHarmony.js","sourceRoot":"","sources":["../../../../../src/lib/commands/build/buildHarmony.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EAET,kBAAkB,EAClB,aAAa,EACb,MAAM,EACN,KAAK,EACL,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,aAGC,EACD,IAAgB,EAChB,WAAmB,EACnB,mBAAgE,EAChE,kBAAsC;IAEtC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;IAChD,MAAM,YAAY,GAAG,MAAM,kBAAkB,CAAC;QAC5C,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC;QACxB,IAAI,EAAE,WAAW;QACjB,kBAAkB;KACnB,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC;QACrC,YAAY,EAAE,SAAS;QACvB,YAAY;QACZ,SAAS,EAAE,IAAI,CAAC,KAAK;QACr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,OAAO;KACjB;IACD;QACE,IAAI,EAAE,uBAAuB;QAC7B,WAAW,EAAE,2DAA2D;QACxE,OAAO,EAAE,OAAO;KACjB;IACD;QACE,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE,qDAAqD;QAClE,OAAO,EAAE,SAAS;KACnB;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { PluginApi } from '@rock-js/config';
2
+ import { type HarmonyProjectConfig } from '../getValidProjectConfig.js';
3
+ export declare function registerBuildCommand(api: PluginApi, pluginConfig: Partial<HarmonyProjectConfig> | undefined): void;
@@ -0,0 +1,15 @@
1
+ import { getValidProjectConfig, } from '../getValidProjectConfig.js';
2
+ import { buildHarmony, options } from './buildHarmony.js';
3
+ export function registerBuildCommand(api, pluginConfig) {
4
+ api.registerCommand({
5
+ name: 'build:harmony',
6
+ description: 'Builds your app for HarmonyOS Next platform.',
7
+ action: async (args) => {
8
+ const projectRoot = api.getProjectRoot();
9
+ const harmonyConfig = getValidProjectConfig(projectRoot, pluginConfig);
10
+ await buildHarmony(harmonyConfig, args, projectRoot, await api.getRemoteCacheProvider(), api.getFingerprintOptions());
11
+ },
12
+ options: options,
13
+ });
14
+ }
15
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../../src/lib/commands/build/command.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,GAEtB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE1D,MAAM,UAAU,oBAAoB,CAClC,GAAc,EACd,YAAuD;IAEvD,GAAG,CAAC,eAAe,CAAC;QAClB,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,8CAA8C;QAC3D,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACrB,MAAM,WAAW,GAAG,GAAG,CAAC,cAAc,EAAE,CAAC;YACzC,MAAM,aAAa,GAAG,qBAAqB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;YACvE,MAAM,YAAY,CAChB,aAAa,EACb,IAAkB,EAClB,WAAW,EACX,MAAM,GAAG,CAAC,sBAAsB,EAAE,EAClC,GAAG,CAAC,qBAAqB,EAAE,CAC5B,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,10 @@
1
+ export type HarmonyProjectConfig = {
2
+ sourceDir: string;
3
+ bundleName: string;
4
+ signingConfigs: boolean | undefined;
5
+ };
6
+ export declare function getValidProjectConfig(projectRoot: string, pluginConfig?: Partial<HarmonyProjectConfig>): {
7
+ sourceDir: string;
8
+ bundleName: string;
9
+ signingConfigs: boolean | undefined;
10
+ };
@@ -0,0 +1,39 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { logger, RockError } from '@rock-js/tools';
4
+ import json5 from 'json5';
5
+ export function getValidProjectConfig(projectRoot, pluginConfig) {
6
+ const sourceDir = pluginConfig?.sourceDir
7
+ ? path.isAbsolute(pluginConfig?.sourceDir)
8
+ ? pluginConfig?.sourceDir
9
+ : path.join(projectRoot, pluginConfig?.sourceDir)
10
+ : path.join(projectRoot, 'harmony');
11
+ if (!fs.existsSync(sourceDir)) {
12
+ throw new RockError(`Harmony project not found under ${sourceDir}.`);
13
+ }
14
+ let bundleName;
15
+ try {
16
+ bundleName = json5.parse(fs.readFileSync(path.join(sourceDir, 'AppScope', 'app.json5'), 'utf8')).app.bundleName;
17
+ }
18
+ catch (error) {
19
+ throw new RockError('Error reading app.json5 file.', {
20
+ cause: error,
21
+ });
22
+ }
23
+ let signingConfigs;
24
+ try {
25
+ const buildProfile = json5.parse(fs.readFileSync(path.join(sourceDir, 'build-profile.json5'), 'utf8'));
26
+ signingConfigs = Boolean(buildProfile.app.signingConfigs);
27
+ }
28
+ catch (error) {
29
+ logger.debug('Error reading build-profile.json5 file.', {
30
+ cause: error.message,
31
+ });
32
+ }
33
+ return {
34
+ sourceDir,
35
+ bundleName,
36
+ signingConfigs,
37
+ };
38
+ }
39
+ //# sourceMappingURL=getValidProjectConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getValidProjectConfig.js","sourceRoot":"","sources":["../../../../src/lib/commands/getValidProjectConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,MAAM,UAAU,qBAAqB,CACnC,WAAmB,EACnB,YAA4C;IAE5C,MAAM,SAAS,GAAG,YAAY,EAAE,SAAS;QACvC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,SAAS,CAAC;YACxC,CAAC,CAAC,YAAY,EAAE,SAAS;YACzB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,YAAY,EAAE,SAAS,CAAC;QACnD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAEtC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,mCAAmC,SAAS,GAAG,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,UAAkB,CAAC;IACvB,IAAI,CAAC;QACH,UAAU,GAAG,KAAK,CAAC,KAAK,CACtB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CACvE,CAAC,GAAG,CAAC,UAAU,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,SAAS,CAAC,+BAA+B,EAAE;YACnD,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IAED,IAAI,cAAc,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAC9B,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,qBAAqB,CAAC,EAAE,MAAM,CAAC,CACrE,CAAC;QACF,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,yCAAyC,EAAE;YACtD,KAAK,EAAG,KAAe,CAAC,OAAO;SAChC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,SAAS;QACT,UAAU;QACV,cAAc;KACf,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { PluginApi } from '@rock-js/config';
2
+ import { type HarmonyProjectConfig } from '../getValidProjectConfig.js';
3
+ export declare function registerRunCommand(api: PluginApi, pluginConfig: Partial<HarmonyProjectConfig> | undefined): void;
@@ -0,0 +1,15 @@
1
+ import { getValidProjectConfig, } from '../getValidProjectConfig.js';
2
+ import { runHarmony, runOptions } from './runHarmony.js';
3
+ export function registerRunCommand(api, pluginConfig) {
4
+ api.registerCommand({
5
+ name: 'run:harmony',
6
+ description: 'Builds your app and starts it on a connected HarmonyOS Next device.',
7
+ action: async (args) => {
8
+ const projectRoot = api.getProjectRoot();
9
+ const harmonyConfig = getValidProjectConfig(projectRoot, pluginConfig);
10
+ await runHarmony(harmonyConfig, args, projectRoot, await api.getRemoteCacheProvider(), api.getFingerprintOptions());
11
+ },
12
+ options: runOptions,
13
+ });
14
+ }
15
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../../src/lib/commands/run/command.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,GAEtB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEzD,MAAM,UAAU,kBAAkB,CAChC,GAAc,EACd,YAAuD;IAEvD,GAAG,CAAC,eAAe,CAAC;QAClB,IAAI,EAAE,aAAa;QACnB,WAAW,EACT,qEAAqE;QACvE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACrB,MAAM,WAAW,GAAG,GAAG,CAAC,cAAc,EAAE,CAAC;YACzC,MAAM,aAAa,GAAG,qBAAqB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;YACvE,MAAM,UAAU,CACd,aAAa,EACb,IAAa,EACb,WAAW,EACX,MAAM,GAAG,CAAC,sBAAsB,EAAE,EAClC,GAAG,CAAC,qBAAqB,EAAE,CAC5B,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,UAAU;KACpB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { DeviceData } from './listHarmonyDevices.js';
2
+ export declare function findOutputFile(sourceDir: string, module: string, device?: DeviceData): Promise<string | undefined>;
@@ -0,0 +1,14 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export async function findOutputFile(sourceDir, module, device) {
4
+ let hapName;
5
+ if (device?.type === 'emulator') {
6
+ hapName = `${module}-default-unsigned.hap`;
7
+ }
8
+ else {
9
+ hapName = `${module}-default-signed.hap`;
10
+ }
11
+ const pathToHap = path.join(sourceDir, module, 'build', 'default', 'outputs', 'default', hapName);
12
+ return fs.existsSync(pathToHap) ? pathToHap : undefined;
13
+ }
14
+ //# sourceMappingURL=findOutputFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findOutputFile.js","sourceRoot":"","sources":["../../../../../src/lib/commands/run/findOutputFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,SAAiB,EACjB,MAAc,EACd,MAAmB;IAEnB,IAAI,OAAe,CAAC;IACpB,IAAI,MAAM,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;QAChC,OAAO,GAAG,GAAG,MAAM,uBAAuB,CAAC;IAC7C,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,GAAG,MAAM,qBAAqB,CAAC;IAC3C,CAAC;IACD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CACzB,SAAS,EACT,MAAM,EACN,OAAO,EACP,SAAS,EACT,SAAS,EACT,SAAS,EACT,OAAO,CACR,CAAC;IACF,OAAO,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,11 @@
1
+ export declare function getHdcPath(): string;
2
+ /**
3
+ * Executes the commands needed to get a list of devices from ADB
4
+ */
5
+ export declare function getDevices(): Promise<{
6
+ name: string;
7
+ method: string;
8
+ state: string;
9
+ locate: string;
10
+ connectTool: string;
11
+ }[]>;
@@ -0,0 +1,35 @@
1
+ import path from 'node:path';
2
+ import { spawn } from '@rock-js/tools';
3
+ import { getDevEcoSdkPath } from '../../paths.js';
4
+ export function getHdcPath() {
5
+ return path.join(getDevEcoSdkPath(), 'default', 'openharmony', 'toolchains', 'hdc');
6
+ }
7
+ /**
8
+ * Executes the commands needed to get a list of devices from ADB
9
+ */
10
+ export async function getDevices() {
11
+ const hdcPath = getHdcPath();
12
+ try {
13
+ const { output } = await spawn(hdcPath, ['list', 'targets', '-v'], {
14
+ stdio: 'pipe',
15
+ });
16
+ const lines = output.trim().split('\n');
17
+ return (lines
18
+ .map((line) => {
19
+ const parts = line.split(/\s+/);
20
+ return {
21
+ name: parts[0],
22
+ method: parts[1], // USB
23
+ state: parts[2], // Connected, Offline
24
+ locate: parts[3], // localhost
25
+ connectTool: parts[4],
26
+ };
27
+ })
28
+ // hdc will report no devices as [Empty] sometimes
29
+ .filter((line) => line.state != undefined));
30
+ }
31
+ catch {
32
+ return [];
33
+ }
34
+ }
35
+ //# sourceMappingURL=hdc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hdc.js","sourceRoot":"","sources":["../../../../../src/lib/commands/run/hdc.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,UAAU,UAAU;IACxB,OAAO,IAAI,CAAC,IAAI,CACd,gBAAgB,EAAE,EAClB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,KAAK,CACN,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE;YACjE,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxC,OAAO,CACL,KAAK;aACF,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACZ,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAChC,OAAO;gBACL,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;gBACd,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM;gBACxB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,qBAAqB;gBACtC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,YAAY;gBAC9B,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;aACtB,CAAC;QACJ,CAAC,CAAC;YACF,kDAAkD;aACjD,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,SAAS,CAAC,CAC7C,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type DeviceData = {
2
+ deviceId: string | undefined;
3
+ readableName: string | undefined;
4
+ connected: boolean;
5
+ type: 'emulator' | 'phone';
6
+ };
7
+ export declare function listHarmonyDevices(): Promise<DeviceData[]>;
@@ -0,0 +1,17 @@
1
+ import { getDevices } from './hdc.js';
2
+ export async function listHarmonyDevices() {
3
+ const devices = await getDevices();
4
+ const allDevices = [];
5
+ for (const device of devices) {
6
+ const phoneData = {
7
+ deviceId: device.name,
8
+ // @todo get readable name
9
+ readableName: device.name,
10
+ type: 'phone',
11
+ connected: device.state === 'Connected',
12
+ };
13
+ allDevices.push(phoneData);
14
+ }
15
+ return allDevices;
16
+ }
17
+ //# sourceMappingURL=listHarmonyDevices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listHarmonyDevices.js","sourceRoot":"","sources":["../../../../../src/lib/commands/run/listHarmonyDevices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAStC,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,MAAM,OAAO,GAAG,MAAM,UAAU,EAAE,CAAC;IAEnC,MAAM,UAAU,GAAsB,EAAE,CAAC;IAEzC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,SAAS,GAAe;YAC5B,QAAQ,EAAE,MAAM,CAAC,IAAI;YACrB,0BAA0B;YAC1B,YAAY,EAAE,MAAM,CAAC,IAAI;YACzB,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,MAAM,CAAC,KAAK,KAAK,WAAW;SACxC,CAAC;QACF,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { FingerprintSources, RemoteBuildCache } from '@rock-js/tools';
2
+ import type { BuildFlags } from '../build/buildHarmony.js';
3
+ export interface Flags extends BuildFlags {
4
+ ability: string;
5
+ port: string;
6
+ device?: string;
7
+ binaryPath?: string;
8
+ }
9
+ /**
10
+ * Starts the app on a connected HarmonyOS emulator or device.
11
+ */
12
+ export declare function runHarmony(harmonyConfig: {
13
+ sourceDir: string;
14
+ bundleName: string;
15
+ }, args: Flags, projectRoot: string, remoteCacheProvider: null | (() => RemoteBuildCache) | undefined, fingerprintOptions: FingerprintSources): Promise<void>;
16
+ export declare const runOptions: ({
17
+ name: string;
18
+ description: string;
19
+ default?: undefined;
20
+ } | {
21
+ name: string;
22
+ description: string;
23
+ default: string;
24
+ })[];
@@ -0,0 +1,148 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { color, formatArtifactName, intro, isInteractive, logger, outro, promptSelect, RockError, spinner, } from '@rock-js/tools';
4
+ import { getBinaryPath } from '@rock-js/tools';
5
+ import { options } from '../build/buildHarmony.js';
6
+ import { runHvigor } from '../runHvigor.js';
7
+ import { getDevices } from './hdc.js';
8
+ import { listHarmonyDevices } from './listHarmonyDevices.js';
9
+ import { tryInstallAppOnDevice } from './tryInstallAppOnDevice.js';
10
+ import { tryLaunchAppOnDevice } from './tryLaunchAppOnDevice.js';
11
+ /**
12
+ * Starts the app on a connected HarmonyOS emulator or device.
13
+ */
14
+ export async function runHarmony(harmonyConfig, args, projectRoot, remoteCacheProvider, fingerprintOptions) {
15
+ intro('Running HarmonyOS Next app');
16
+ normalizeArgs(args, projectRoot);
17
+ const { sourceDir, bundleName } = harmonyConfig;
18
+ const devices = await listHarmonyDevices();
19
+ const device = await selectDevice(devices, args);
20
+ const artifactName = await formatArtifactName({
21
+ platform: 'harmony',
22
+ traits: [args.buildMode],
23
+ root: projectRoot,
24
+ fingerprintOptions,
25
+ });
26
+ const binaryPath = await getBinaryPath({
27
+ platformName: 'harmony',
28
+ artifactName,
29
+ binaryPathFlag: args.binaryPath,
30
+ localFlag: args.local,
31
+ remoteCacheProvider,
32
+ fingerprintOptions,
33
+ sourceDir: sourceDir,
34
+ });
35
+ if (device) {
36
+ if (device.deviceId) {
37
+ if (!binaryPath) {
38
+ await runHvigor({ sourceDir, args, artifactName, device, bundleName });
39
+ }
40
+ await runOnDevice({ device, sourceDir, args, binaryPath, bundleName });
41
+ }
42
+ }
43
+ else {
44
+ if ((await getDevices()).length === 0) {
45
+ if (isInteractive()) {
46
+ await selectAndLaunchDevice();
47
+ }
48
+ else {
49
+ logger.warn('No booted devices or emulators found. Launching first available emulator.');
50
+ // @todo add emulators
51
+ }
52
+ }
53
+ if (!binaryPath) {
54
+ await runHvigor({ sourceDir, args, artifactName, bundleName });
55
+ }
56
+ for (const device of await listHarmonyDevices()) {
57
+ if (device.connected) {
58
+ await runOnDevice({ device, sourceDir, args, binaryPath, bundleName });
59
+ }
60
+ }
61
+ }
62
+ outro('Success 🎉.');
63
+ }
64
+ async function selectAndLaunchDevice() {
65
+ const allDevices = await listHarmonyDevices();
66
+ const device = await promptForDeviceSelection(allDevices);
67
+ if (!device.connected) {
68
+ // @todo add emulators
69
+ // list devices once again when emulator is booted
70
+ const allDevices = await listHarmonyDevices();
71
+ const newDevice = allDevices.find((d) => d.readableName === device.readableName) ?? device;
72
+ return newDevice;
73
+ }
74
+ return device;
75
+ }
76
+ async function selectDevice(devices, args) {
77
+ const device = args.device ? matchingDevice(devices, args.device) : undefined;
78
+ if (!device && args.device) {
79
+ logger.warn(`No devices or emulators found matching "${args.device}". Using available one instead.`);
80
+ }
81
+ return device;
82
+ }
83
+ function matchingDevice(devices, deviceArg) {
84
+ const deviceByName = devices.find((device) => device.readableName === deviceArg);
85
+ const deviceById = devices.find((d) => d.deviceId === deviceArg);
86
+ return deviceByName || deviceById;
87
+ }
88
+ function normalizeArgs(args, projectRoot) {
89
+ if (args.binaryPath) {
90
+ args.binaryPath = path.isAbsolute(args.binaryPath)
91
+ ? args.binaryPath
92
+ : path.join(projectRoot, args.binaryPath);
93
+ if (args.binaryPath && !fs.existsSync(args.binaryPath)) {
94
+ throw new RockError(`"--binary-path" was specified, but the file was not found at "${args.binaryPath}".`);
95
+ }
96
+ }
97
+ }
98
+ async function promptForDeviceSelection(allDevices) {
99
+ if (!allDevices.length) {
100
+ throw new RockError(
101
+ // @todo add emulators
102
+ 'No devices connected. Please create connect HarmonyOS device.');
103
+ }
104
+ const selected = await promptSelect({
105
+ // @todo add emulators
106
+ message: 'Select the device you want to use',
107
+ options: allDevices.map((d) => ({
108
+ label: `${d.readableName}${d.type === 'phone' ? ' - (physical device)' : ''}${d.connected ? ' (connected)' : ''}`,
109
+ value: d,
110
+ })),
111
+ });
112
+ return selected;
113
+ }
114
+ async function runOnDevice({ device, sourceDir, args, binaryPath, bundleName, }) {
115
+ const loader = spinner();
116
+ loader.start('Installing the app');
117
+ await tryInstallAppOnDevice(device, sourceDir, args, binaryPath);
118
+ loader.message('Launching the app');
119
+ const { applicationIdWithSuffix } = await tryLaunchAppOnDevice(device, bundleName, args);
120
+ if (applicationIdWithSuffix) {
121
+ loader.stop(`Installed and launched the app on ${color.bold(device.readableName)}`);
122
+ }
123
+ else {
124
+ loader.stop(`Failed: installing and launching the app on ${color.bold(device.readableName)}`);
125
+ }
126
+ }
127
+ export const runOptions = [
128
+ ...options,
129
+ {
130
+ name: '--port <number>',
131
+ description: 'Part for packager.',
132
+ default: process.env['RCT_METRO_PORT'] || '8081',
133
+ },
134
+ {
135
+ name: '--ability <string>',
136
+ description: 'Name of the ability to start.',
137
+ default: 'EntryAbility',
138
+ },
139
+ {
140
+ name: '--device <string>',
141
+ description: 'Explicitly set the device or emulator to use by name or ID (if launched).',
142
+ },
143
+ {
144
+ name: '--binary-path <string>',
145
+ description: 'Path relative to project root where pre-built .apk binary lives.',
146
+ },
147
+ ];
148
+ //# sourceMappingURL=runHarmony.js.map
@@ -0,0 +1 @@
1
+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E,CAAC;IACzB,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACnC,MAAM,qBAAqB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IACjE,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACpC,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,oBAAoB,CAC5D,MAAM,EACN,UAAU,EACV,IAAI,CACL,CAAC;IACF,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,CACT,qCAAqC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CACvE,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,CACT,+CAA+C,KAAK,CAAC,IAAI,CACvD,MAAM,CAAC,YAAY,CACpB,EAAE,CACJ,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,GAAG,OAAO;IACV;QACE,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,oBAAoB;QACjC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,MAAM;KACjD;IACD;QACE,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE,+BAA+B;QAC5C,OAAO,EAAE,cAAc;KACxB;IACD;QACE,IAAI,EAAE,mBAAmB;QACzB,WAAW,EACT,2EAA2E;KAC9E;IACD;QACE,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EACT,kEAAkE;KACrE;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DeviceData } from './listHarmonyDevices.js';
2
+ import type { Flags } from './runHarmony.js';
3
+ export declare function tryInstallAppOnDevice(device: DeviceData, sourceDir: string, args: Flags, binaryPath: string | undefined): Promise<void>;
@@ -0,0 +1,42 @@
1
+ import path from 'node:path';
2
+ import { color, colorLink, logger, RockError, spawn, } from '@rock-js/tools';
3
+ import { findOutputFile } from './findOutputFile.js';
4
+ import { getHdcPath } from './hdc.js';
5
+ export async function tryInstallAppOnDevice(device, sourceDir, args, binaryPath) {
6
+ if (!device.deviceId) {
7
+ logger.debug(`No "deviceId" for ${device}, skipping launching the app`);
8
+ return;
9
+ }
10
+ logger.debug(`Connected to device ${color.bold(device.readableName)}`);
11
+ let pathToHap;
12
+ if (!binaryPath) {
13
+ const outputFilePath = await findOutputFile(sourceDir, args.module, device);
14
+ if (!outputFilePath) {
15
+ if (device.type === 'phone') {
16
+ throw new RockError(`There was no signed build output file for the physical device.
17
+ This usually means you're missing signing config in your ${colorLink(path.join(sourceDir, 'build-profile.json5'))} file.
18
+ Please open DevEco Studio, proceed to: ${color.bold('File > Project Structure... > Signing Configs')}
19
+ and log in to your Huawei account to fill the signing information.`);
20
+ }
21
+ else {
22
+ logger.warn("Skipping installation because there's no build output file.");
23
+ return;
24
+ }
25
+ }
26
+ pathToHap = outputFilePath;
27
+ }
28
+ else {
29
+ pathToHap = binaryPath;
30
+ }
31
+ const hdcPath = getHdcPath();
32
+ try {
33
+ await spawn(hdcPath, ['-t', device.deviceId, 'install', '-r', pathToHap]);
34
+ }
35
+ catch (error) {
36
+ const errorMessage = error.stderr || error.stdout;
37
+ if (errorMessage.includes('failed to install')) {
38
+ throw new RockError(`Installation failed. If an application with the same bundle name is already installed, try uninstalling it`, { cause: error });
39
+ }
40
+ }
41
+ }
42
+ //# sourceMappingURL=tryInstallAppOnDevice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tryInstallAppOnDevice.js","sourceRoot":"","sources":["../../../../../src/lib/commands/run/tryInstallAppOnDevice.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,KAAK,EACL,SAAS,EACT,MAAM,EACN,SAAS,EACT,KAAK,GAEN,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,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ACf,KAAyB,CAAC,MAAM,IAAK,KAAyB,CAAC,MAAM,CAAC;QACzE,IAAI,YAAY,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,SAAS,CACjB,4GAA4G,EAC5G,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { DeviceData } from './listHarmonyDevices.js';
2
+ import type { Flags } from './runHarmony.js';
3
+ export declare function tryLaunchAppOnDevice(device: DeviceData, bundleName: string, args: Flags): Promise<{
4
+ applicationIdWithSuffix?: undefined;
5
+ } | {
6
+ applicationIdWithSuffix: string;
7
+ }>;
@@ -0,0 +1,43 @@
1
+ import { logger, RockError, spawn } from '@rock-js/tools';
2
+ import { getHdcPath } from './hdc.js';
3
+ import { tryRunHdcReverse } from './tryRunHdcReverse.js';
4
+ export async function tryLaunchAppOnDevice(device, bundleName, args) {
5
+ let deviceId;
6
+ if (!device.deviceId) {
7
+ logger.debug(`No "deviceId" for ${device}, skipping launching the app`);
8
+ return {};
9
+ }
10
+ else {
11
+ deviceId = device.deviceId;
12
+ }
13
+ await tryRunHdcReverse(args.port, deviceId);
14
+ const hdcPath = getHdcPath();
15
+ try {
16
+ await spawn(hdcPath, [
17
+ '-t',
18
+ device.deviceId,
19
+ 'shell',
20
+ 'aa',
21
+ 'force-stop',
22
+ bundleName,
23
+ ]);
24
+ await spawn(hdcPath, [
25
+ '-t',
26
+ device.deviceId,
27
+ 'shell',
28
+ 'aa',
29
+ 'start',
30
+ '-a',
31
+ args.ability,
32
+ '-b',
33
+ bundleName,
34
+ ]);
35
+ }
36
+ catch (error) {
37
+ throw new RockError(`Failed to launch the app on ${device.readableName}`, {
38
+ cause: error.stderr,
39
+ });
40
+ }
41
+ return { applicationIdWithSuffix: bundleName };
42
+ }
43
+ //# sourceMappingURL=tryLaunchAppOnDevice.js.map
@@ -0,0 +1 @@
1
+ {"version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