@react-native-oh/react-native-harmony-cli 0.0.28 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assetResolver.js +105 -10
- package/dist/autolinking/Autolinking.js +9 -11
- package/dist/codegen/core/EventUtils.js +5 -8
- package/dist/codegen/core/TypeAnnotationToTS.js +3 -3
- package/dist/codegen/core/UberSchema.js +7 -11
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +3 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +3 -0
- package/dist/codegen/generators/CppComponentCodeGenerator.js +3 -0
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +15 -0
- package/dist/commands/bundle-harmony.js +5 -68
- package/dist/commands/codegen-harmony.js +13 -17
- package/dist/commands/codegen-lib-harmony.js +10 -14
- package/dist/commands/create-metro-host-constants.js +1 -1
- package/dist/commands/index.js +2 -1
- package/dist/commands/init.js +703 -0
- package/dist/commands/link-harmony.js +1 -1
- package/dist/commands/pack-harmony.js +1 -1
- package/dist/commands/run-harmony.js +438 -0
- package/dist/commands/types.js +8 -0
- package/dist/commands/unpack-harmony.js +2 -4
- package/dist/commands/verify-package-harmony.js +2 -2
- package/dist/core/CodegenConfig.js +4 -6
- package/dist/core/DescriptiveError.js +8 -4
- package/dist/core/PackageJSON.js +4 -7
- package/dist/core/fs.js +4 -5
- package/dist/index.js +2 -1
- package/dist/io/CliExecutor.js +57 -24
- package/dist/io/Logger.js +72 -42
- package/dist/io/TarGz.js +1 -2
- package/dist/io/__fixtures__.js +9 -3
- package/dist/io/fsUtils.js +1 -2
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +1 -2
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +1 -2
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +1 -2
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +1 -2
- package/dist/package-verifier/verify-package.js +7 -10
- package/package.json +10 -3
- package/src/assetResolver.ts +117 -11
- package/src/autolinking/Autolinking.ts +10 -12
- package/src/codegen/core/EventUtils.ts +4 -6
- package/src/codegen/core/UberSchema.ts +7 -11
- package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +3 -0
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +3 -0
- package/src/codegen/generators/CppComponentCodeGenerator.ts +3 -0
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +24 -1
- package/src/commands/bundle-harmony.ts +6 -82
- package/src/commands/codegen-harmony.ts +14 -19
- package/src/commands/codegen-lib-harmony.ts +11 -16
- package/src/commands/create-metro-host-constants.ts +2 -2
- package/src/commands/index.ts +2 -1
- package/src/commands/init.ts +755 -0
- package/src/commands/link-harmony.ts +2 -2
- package/src/commands/pack-harmony.ts +2 -2
- package/src/commands/run-harmony.ts +478 -0
- package/src/commands/types.ts +21 -0
- package/src/commands/unpack-harmony.ts +3 -5
- package/src/commands/verify-package-harmony.ts +3 -3
- package/src/core/CodegenConfig.ts +4 -6
- package/src/core/DescriptiveError.ts +9 -9
- package/src/core/PackageJSON.ts +5 -8
- package/src/core/fs.ts +2 -2
- package/src/index.ts +5 -3
- package/src/io/CliExecutor.ts +56 -34
- package/src/io/Logger.ts +78 -45
- package/src/io/__fixtures__.ts +15 -11
- package/src/package-verifier/verify-package.ts +5 -7
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
2
|
+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { Config } from '@react-native-community/cli-types';
|
|
8
|
+
import { Config, Command } from '@react-native-community/cli-types';
|
|
9
9
|
import {
|
|
10
10
|
commandBundleHarmony,
|
|
11
11
|
commandPackHarmony,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
commandVerifyPackageHarmony,
|
|
16
16
|
commandCodegenLibHarmony,
|
|
17
17
|
commandLinkHarmony,
|
|
18
|
+
commandRunHarmony,
|
|
18
19
|
} from './commands';
|
|
19
20
|
|
|
20
21
|
export const config = {
|
|
@@ -27,5 +28,6 @@ export const config = {
|
|
|
27
28
|
commandVerifyPackageHarmony,
|
|
28
29
|
commandCodegenLibHarmony,
|
|
29
30
|
commandLinkHarmony,
|
|
30
|
-
|
|
31
|
+
commandRunHarmony,
|
|
32
|
+
] as Command[],
|
|
31
33
|
} satisfies Partial<Config>;
|
package/src/io/CliExecutor.ts
CHANGED
|
@@ -1,47 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
2
|
+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { AbsolutePath } from '../core';
|
|
9
|
+
import { spawn } from 'node:child_process';
|
|
10
|
+
|
|
11
|
+
export type CliOptions = {
|
|
12
|
+
args: string[];
|
|
13
|
+
cwd?: AbsolutePath;
|
|
14
|
+
onArgsStringified?: (commandWithArgs: string) => void;
|
|
15
|
+
onStdout?: (data: string) => void;
|
|
16
|
+
onStderr?: (data: string) => void;
|
|
17
|
+
shell?: boolean;
|
|
18
|
+
};
|
|
9
19
|
|
|
10
20
|
export abstract class CliExecutor {
|
|
11
|
-
abstract run(
|
|
12
|
-
|
|
13
|
-
options?: {
|
|
14
|
-
args?: Record<string, string | number | boolean>;
|
|
15
|
-
cwd?: AbsolutePath;
|
|
16
|
-
}
|
|
17
|
-
): string;
|
|
18
|
-
|
|
19
|
-
protected stringifyCliArgs(
|
|
20
|
-
args: Record<string, string | number | boolean>
|
|
21
|
-
): string {
|
|
22
|
-
return Object.entries(args)
|
|
23
|
-
.filter(([_, value]) => {
|
|
24
|
-
if (typeof value === 'boolean') {
|
|
25
|
-
return value;
|
|
26
|
-
}
|
|
27
|
-
return value !== undefined && value !== null;
|
|
28
|
-
})
|
|
29
|
-
.map(([key, value]) => {
|
|
30
|
-
const formattedKey = toKebabCase(key);
|
|
21
|
+
abstract run(command: string, options?: CliOptions): Promise<string>;
|
|
22
|
+
}
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
export class RealCliExecutor extends CliExecutor {
|
|
25
|
+
async run(command: string, options?: CliOptions): Promise<string> {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
let commandWithArgs = command;
|
|
28
|
+
let argStrings: string[] = [];
|
|
29
|
+
if (options?.args) {
|
|
30
|
+
argStrings = options.args;
|
|
31
|
+
commandWithArgs += ' ' + argStrings.join(' ');
|
|
32
|
+
}
|
|
33
|
+
options?.onArgsStringified?.(commandWithArgs);
|
|
34
|
+
const process = spawn(command, argStrings, {
|
|
35
|
+
cwd: options?.cwd?.toString(),
|
|
36
|
+
shell: options?.shell ? true : false,
|
|
37
|
+
});
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.join(' ');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
39
|
+
let stdout = '';
|
|
40
|
+
let stderr = '';
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
process.stdout.on('data', (data) => {
|
|
43
|
+
const output = data.toString();
|
|
44
|
+
stdout += output;
|
|
45
|
+
options?.onStdout?.(output);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
process.stderr.on('data', (data) => {
|
|
49
|
+
const output = data.toString();
|
|
50
|
+
stderr += output;
|
|
51
|
+
options?.onStderr?.(output);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
process.on('error', (error) => {
|
|
55
|
+
reject(error);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
process.on('close', (code) => {
|
|
59
|
+
if (code === 0) {
|
|
60
|
+
resolve(stdout);
|
|
61
|
+
} else {
|
|
62
|
+
reject(
|
|
63
|
+
new Error(`Command failed with code ${code}\nStderr: ${stderr}`)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
47
69
|
}
|
package/src/io/Logger.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
2
|
+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
@@ -7,26 +7,57 @@
|
|
|
7
7
|
|
|
8
8
|
import chalk from 'chalk';
|
|
9
9
|
import { DescriptiveError } from '../core';
|
|
10
|
-
|
|
10
|
+
import { getLoader, logger as LOGGER } from '@react-native-community/cli-tools';
|
|
11
|
+
import process from 'node:process';
|
|
11
12
|
export class Logger {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
13
|
+
private loader = getLoader({
|
|
14
|
+
interval: process.stdout.isTTY ? undefined : 0,
|
|
15
|
+
});
|
|
16
|
+
private logger = LOGGER;
|
|
17
|
+
private isLoaderActive = false;
|
|
18
|
+
|
|
19
|
+
start(prepareMsg: (styles: typeof chalk) => string) {
|
|
20
|
+
this.loader.start(prepareMsg(chalk));
|
|
21
|
+
this.isLoaderActive = true;
|
|
22
|
+
return (options?: { persist?: boolean }) => {
|
|
23
|
+
this.isLoaderActive = false;
|
|
24
|
+
if (options?.persist) {
|
|
25
|
+
console.log({ loader: this.loader });
|
|
26
|
+
this.loader.stopAndPersist();
|
|
27
|
+
} else {
|
|
28
|
+
this.loader.stop();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
info(prepareMsg: (styles: typeof chalk) => string) {
|
|
34
|
+
const info = (msg: string) => {
|
|
35
|
+
this.isLoaderActive ? this.loader.info(msg) : this.logger.info(msg);
|
|
36
|
+
};
|
|
37
|
+
info(prepareMsg(chalk));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
succeed(prepareMsg: (styles: typeof chalk) => string) {
|
|
41
|
+
const succeed = (msg: string) =>
|
|
42
|
+
this.isLoaderActive ? this.loader.succeed(msg) : this.logger.success(msg);
|
|
43
|
+
succeed(prepareMsg(chalk));
|
|
22
44
|
}
|
|
23
|
-
|
|
45
|
+
|
|
24
46
|
warn(prepareMsg: (styles: typeof chalk) => string) {
|
|
25
|
-
|
|
47
|
+
const warn = (msg: string) =>
|
|
48
|
+
this.isLoaderActive ? this.loader.warn(msg) : this.logger.warn(msg);
|
|
49
|
+
warn(prepareMsg(chalk));
|
|
26
50
|
}
|
|
27
51
|
|
|
28
52
|
debug(prepareMsg: (styles: typeof chalk) => string) {
|
|
29
|
-
|
|
53
|
+
if (this.isLoaderActive) {
|
|
54
|
+
clearLine(process.stdout);
|
|
55
|
+
moveCursor(process.stdout, 0);
|
|
56
|
+
console.debug(prepareMsg(chalk));
|
|
57
|
+
this.loader.render();
|
|
58
|
+
} else {
|
|
59
|
+
console.debug(prepareMsg(chalk));
|
|
60
|
+
}
|
|
30
61
|
}
|
|
31
62
|
|
|
32
63
|
descriptiveError(error: DescriptiveError) {
|
|
@@ -43,37 +74,39 @@ export class Logger {
|
|
|
43
74
|
details.split('\n').forEach((line) => lines.push(line));
|
|
44
75
|
}
|
|
45
76
|
lines.push('');
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
77
|
+
lines.push(`${error.getMessage()}`);
|
|
78
|
+
const suggestions = error.getSuggestions();
|
|
79
|
+
|
|
80
|
+
if (suggestions.length > 0) {
|
|
81
|
+
lines.push('');
|
|
82
|
+
lines.push(chalk.bold(`Suggestions`));
|
|
83
|
+
suggestions.forEach((suggestion) => {
|
|
84
|
+
lines.push('• ' + suggestion);
|
|
85
|
+
});
|
|
51
86
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
lines.push(chalk.bold(`Suggestions`));
|
|
58
|
-
suggestionsByRole.default?.forEach((suggestion) => {
|
|
59
|
-
lines.push(suggestion);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
if ((suggestionsByRole.rnAppDeveloper?.length ?? 0) > 0) {
|
|
63
|
-
lines.push('');
|
|
64
|
-
lines.push(chalk.bold(`Suggestions for RN App developers`));
|
|
65
|
-
suggestionsByRole.rnAppDeveloper?.forEach((suggestion) => {
|
|
66
|
-
lines.push(suggestion);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
if (suggestionsByRole.rnPackageDeveloper?.length ?? 0) {
|
|
70
|
-
lines.push('');
|
|
71
|
-
lines.push(chalk.bold(`Suggestions for RN package developers`));
|
|
72
|
-
suggestionsByRole.rnPackageDeveloper?.forEach((suggestion) => {
|
|
73
|
-
lines.push(suggestion);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
87
|
+
|
|
88
|
+
if (this.isLoaderActive) {
|
|
89
|
+
this.loader.fail(lines.join('\n').trim());
|
|
90
|
+
} else {
|
|
91
|
+
this.logger.error(lines.join('\n').trim());
|
|
76
92
|
}
|
|
77
|
-
console.error(lines.join('\n'));
|
|
78
93
|
}
|
|
79
94
|
}
|
|
95
|
+
|
|
96
|
+
const clearLine = (stream: NodeJS.WriteStream): void => {
|
|
97
|
+
if (stream.clearLine) {
|
|
98
|
+
stream.clearLine(0);
|
|
99
|
+
} else {
|
|
100
|
+
process.stdout.write(
|
|
101
|
+
'\r' + ' '.repeat(process.stdout.columns || 80) + '\r'
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const moveCursor = (stream: NodeJS.WriteStream, x: number): void => {
|
|
107
|
+
if (stream.cursorTo) {
|
|
108
|
+
stream.cursorTo(x);
|
|
109
|
+
} else {
|
|
110
|
+
process.stdout.write('\r');
|
|
111
|
+
}
|
|
112
|
+
};
|
package/src/io/__fixtures__.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
2
|
+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { AbsolutePath, DescriptiveError, Dirent, FS } from '../core';
|
|
9
|
-
import { CliExecutor } from './CliExecutor';
|
|
9
|
+
import { CliExecutor, CliOptions } from './CliExecutor';
|
|
10
10
|
import { IFs, memfs, NestedDirectoryJSON } from 'memfs';
|
|
11
11
|
import RawMemDirent from 'memfs/lib/Dirent';
|
|
12
12
|
import { Logger } from './Logger';
|
|
@@ -15,20 +15,14 @@ import chalk from 'chalk';
|
|
|
15
15
|
export class FakeCliExecutor extends CliExecutor {
|
|
16
16
|
private commands: string[] = [];
|
|
17
17
|
|
|
18
|
-
constructor(private onRun: (command: string) => string) {
|
|
18
|
+
constructor(private onRun: (command: string) => Promise<string>) {
|
|
19
19
|
super();
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
run(
|
|
23
|
-
command: string,
|
|
24
|
-
options: {
|
|
25
|
-
args?: Record<string, string | number | boolean>;
|
|
26
|
-
cwd?: AbsolutePath;
|
|
27
|
-
} = {}
|
|
28
|
-
): string {
|
|
22
|
+
run(command: string, options: CliOptions): Promise<string> {
|
|
29
23
|
let commandWithArgs = command;
|
|
30
24
|
if (options.args) {
|
|
31
|
-
commandWithArgs += ' '
|
|
25
|
+
commandWithArgs += options.args.join(' ');
|
|
32
26
|
}
|
|
33
27
|
this.commands.push(commandWithArgs);
|
|
34
28
|
return this.onRun(commandWithArgs);
|
|
@@ -48,9 +42,19 @@ class MemFSDirent extends Dirent {
|
|
|
48
42
|
return this.rawDirent.isDirectory();
|
|
49
43
|
}
|
|
50
44
|
|
|
45
|
+
isSymbolicLink(): boolean {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
51
49
|
get name(): string {
|
|
52
50
|
return this.rawDirent.name.toString();
|
|
53
51
|
}
|
|
52
|
+
|
|
53
|
+
get path(): AbsolutePath {
|
|
54
|
+
return new AbsolutePath(this.rawDirent.path).copyWithNewSegment(
|
|
55
|
+
this.rawDirent.name.toString()
|
|
56
|
+
);
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
59
|
export class MemFS extends FS {
|
|
56
60
|
private fs: IFs;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
2
|
+
* Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
@@ -60,12 +60,10 @@ export async function* verifyRNOHPackage({
|
|
|
60
60
|
if (!harPath) {
|
|
61
61
|
throw new DescriptiveError({
|
|
62
62
|
whatHappened: 'Attempted to verify har but no har was found',
|
|
63
|
-
whatCanUserDo:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
],
|
|
68
|
-
},
|
|
63
|
+
whatCanUserDo: [
|
|
64
|
+
'Run this command without --no-harmony-code flag.',
|
|
65
|
+
'Create har files by running DevEco Studio > Build > Make Module (MODULE_NAME). The har file can be later found in MODULE_NAME/build/default/outputs/default/MODULE_NAME.har. Copy that file to the PACKAGE_ROOT/harmony directory.',
|
|
66
|
+
],
|
|
69
67
|
});
|
|
70
68
|
}
|
|
71
69
|
const tmpDirPath = new AbsolutePath(tmp.dirSync().name);
|