@react-native-oh/react-native-harmony-cli 0.0.24 → 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.
- package/.prettierrc +6 -6
- package/jest.config.js +5 -5
- package/package.json +57 -52
- package/react-native.config.js +10 -10
- package/src/assetResolver.ts +21 -44
- package/src/codegen/core/CodeGenerator.ts +9 -0
- package/src/codegen/core/CodegenError.ts +3 -3
- package/src/codegen/core/EventUtils.ts +18 -18
- package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -75
- package/src/codegen/core/TypeAnnotationToTS.ts +188 -188
- package/src/codegen/core/UberSchema.ts +142 -99
- package/src/codegen/core/index.ts +5 -5
- package/src/codegen/generators/{ComponentCodeGenerator.ts → ComponentCodeGeneratorArkTS.ts} +112 -98
- package/src/codegen/generators/ComponentCodeGeneratorCAPI.ts +114 -0
- package/src/codegen/generators/GlueCodeGenerator.ts +109 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +115 -95
- package/src/codegen/generators/UberGeneratorV1.ts +64 -0
- package/src/codegen/generators/UberGeneratorV2.ts +91 -0
- package/src/codegen/generators/index.ts +6 -3
- package/src/codegen/index.ts +2 -2
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +116 -0
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +55 -49
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +93 -85
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +210 -202
- package/src/codegen/templates/GeneratedPackageHTemplate.ts +107 -0
- package/src/codegen/templates/IndexTSTemplate.ts +53 -33
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +130 -124
- package/src/codegen/templates/TurboModuleCppTemplate.ts +54 -47
- package/src/codegen/templates/TurboModuleHTemplate.ts +35 -26
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +90 -81
- package/src/codegen/templates/index.ts +9 -8
- package/src/commands/bundle-harmony.ts +203 -202
- package/src/commands/codegen-harmony.ts +272 -143
- package/src/commands/create-metro-host-constants.ts +48 -48
- package/src/commands/index.ts +6 -5
- package/src/commands/pack-harmony.ts +121 -121
- package/src/commands/unpack-harmony.ts +231 -231
- package/src/commands/verify-package-harmony.ts +106 -0
- package/src/core/AbsolutePath.ts +50 -43
- package/src/core/CodegenConfig.ts +62 -54
- package/src/core/DescriptiveError.ts +61 -61
- package/src/core/OHPackageJSON5.ts +23 -0
- package/src/core/PackageJSON.ts +75 -63
- package/src/core/ProjectDependenciesManager.ts +77 -77
- package/src/core/ValidationError.ts +1 -1
- package/src/core/ValueObject.ts +2 -2
- package/src/core/fs.ts +31 -31
- package/src/core/index.ts +9 -8
- package/src/index.ts +20 -18
- package/src/io/Logger.ts +68 -68
- package/src/io/TarGz.ts +26 -0
- package/src/io/fsUtils.ts +24 -24
- package/src/io/index.ts +3 -2
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -0
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -0
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -0
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -0
- package/src/package-verifier/checks/index.ts +4 -0
- package/src/package-verifier/index.ts +2 -0
- package/src/package-verifier/types.ts +12 -0
- package/src/package-verifier/verify-package.ts +117 -0
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
- package/dist/assetResolver.js +0 -41
- package/dist/codegen/core/Codegen.js +0 -35
- package/dist/codegen/core/CodegenError.js +0 -7
- package/dist/codegen/core/EventUtils.js +0 -19
- package/dist/codegen/core/TypeAnnotationToTS.js +0 -132
- package/dist/codegen/core/UberSchema.js +0 -74
- package/dist/codegen/core/index.js +0 -21
- package/dist/codegen/generators/ComponentCodeGenerator.js +0 -66
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +0 -64
- package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
- package/dist/codegen/generators/index.js +0 -19
- package/dist/codegen/index.js +0 -18
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +0 -55
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +0 -78
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -181
- package/dist/codegen/templates/IndexTSTemplate.js +0 -31
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +0 -117
- package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -45
- package/dist/codegen/templates/TurboModuleHTemplate.js +0 -32
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -64
- package/dist/codegen/templates/index.js +0 -24
- package/dist/commands/bundle-harmony.js +0 -179
- package/dist/commands/codegen-harmony.js +0 -110
- package/dist/commands/create-metro-host-constants.js +0 -61
- package/dist/commands/index.js +0 -21
- package/dist/commands/pack-harmony.js +0 -100
- package/dist/commands/unpack-harmony.js +0 -184
- package/dist/core/AbsolutePath.js +0 -41
- package/dist/core/CodegenConfig.js +0 -53
- package/dist/core/DescriptiveError.js +0 -49
- package/dist/core/PackageJSON.js +0 -53
- package/dist/core/ProjectDependenciesManager.js +0 -70
- package/dist/core/ValidationError.js +0 -6
- package/dist/core/ValueObject.js +0 -2
- package/dist/core/fs.js +0 -36
- package/dist/core/index.js +0 -24
- package/dist/index.js +0 -13
- package/dist/io/Logger.js +0 -71
- package/dist/io/fsUtils.js +0 -23
- package/dist/io/index.js +0 -18
- package/src/codegen/core/Codegen.ts +0 -44
- package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import { Command } from '@react-native-community/cli-types';
|
|
2
|
-
import { globSync } from 'glob';
|
|
3
|
-
import pathUtils from 'path';
|
|
4
|
-
import tar from 'tar';
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
import { ValidationError } from '../core';
|
|
7
|
-
import ignore, { Ignore } from 'ignore';
|
|
8
|
-
import JSON5 from 'json5';
|
|
9
|
-
|
|
10
|
-
export const commandPackHarmony: Command = {
|
|
11
|
-
name: 'pack-harmony',
|
|
12
|
-
description: 'Pack native code. Used for package development.',
|
|
13
|
-
options: [
|
|
14
|
-
{
|
|
15
|
-
name: '--oh-module-path <string>',
|
|
16
|
-
description: 'Path to the OH module',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
name: '--harmony-dir-path <string>',
|
|
20
|
-
description: 'Path to the harmony dir',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
name: '--package-json-path <string>',
|
|
24
|
-
description: 'Path to the package.json',
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
func: async (argv, config, args: any) => {
|
|
28
|
-
try {
|
|
29
|
-
await pack(
|
|
30
|
-
pathUtils.resolve(args.harmonyDirPath),
|
|
31
|
-
pathUtils.resolve(args.ohModulePath),
|
|
32
|
-
pathUtils.resolve(args.packageJsonPath)
|
|
33
|
-
);
|
|
34
|
-
} catch (err) {
|
|
35
|
-
if (err instanceof ValidationError) {
|
|
36
|
-
console.error('[ERROR]', err.message);
|
|
37
|
-
process.exit(1);
|
|
38
|
-
} else {
|
|
39
|
-
throw err;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
async function pack(
|
|
46
|
-
harmonyDirPath: string,
|
|
47
|
-
ohModuleDirPath: string,
|
|
48
|
-
packageJSONPath: string
|
|
49
|
-
) {
|
|
50
|
-
syncVersions(
|
|
51
|
-
packageJSONPath,
|
|
52
|
-
pathUtils.join(ohModuleDirPath, 'oh-package.json5')
|
|
53
|
-
);
|
|
54
|
-
if (!fs.existsSync(harmonyDirPath)) {
|
|
55
|
-
fs.mkdirSync(harmonyDirPath, { recursive: true });
|
|
56
|
-
}
|
|
57
|
-
await createTGZFromDir(
|
|
58
|
-
ohModuleDirPath,
|
|
59
|
-
pathUtils.join(
|
|
60
|
-
harmonyDirPath,
|
|
61
|
-
`${pathUtils.parse(ohModuleDirPath).name}.tar.gz`
|
|
62
|
-
)
|
|
63
|
-
);
|
|
64
|
-
await createTGZFromDir(
|
|
65
|
-
harmonyDirPath,
|
|
66
|
-
pathUtils.join(pathUtils.dirname(harmonyDirPath), 'harmony.tar.gz')
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function syncVersions(
|
|
71
|
-
packageJSONFilePath: string,
|
|
72
|
-
ohPackageJSONFilePath: string
|
|
73
|
-
) {
|
|
74
|
-
const packageJSONFileContent = JSON.parse(
|
|
75
|
-
fs.readFileSync(packageJSONFilePath, { encoding: 'utf-8' })
|
|
76
|
-
);
|
|
77
|
-
if (fs.existsSync(ohPackageJSONFilePath)) {
|
|
78
|
-
const ohPackageJSONFileContent = JSON5.parse(
|
|
79
|
-
fs.readFileSync(ohPackageJSONFilePath, { encoding: 'utf-8' })
|
|
80
|
-
);
|
|
81
|
-
ohPackageJSONFileContent['version'] = packageJSONFileContent['version'];
|
|
82
|
-
fs.writeFileSync(
|
|
83
|
-
ohPackageJSONFilePath,
|
|
84
|
-
JSON5.stringify(ohPackageJSONFileContent, null, 2)
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async function createTGZFromDir(dirPath: string, outputFilePath: string) {
|
|
90
|
-
const ig = getIgnoreUtil(pathUtils.join(dirPath, '.tarignore'));
|
|
91
|
-
const filesToInclude = globSync('**', {
|
|
92
|
-
cwd: dirPath,
|
|
93
|
-
nodir: true,
|
|
94
|
-
}).filter((path) => !ig.ignores(path));
|
|
95
|
-
await createArchive(outputFilePath, dirPath, filesToInclude);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function getIgnoreUtil(tarignorePath: string): Ignore {
|
|
99
|
-
if (!fs.existsSync(tarignorePath)) {
|
|
100
|
-
return ignore();
|
|
101
|
-
}
|
|
102
|
-
return ignore().add(fs.readFileSync(tarignorePath).toString());
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function createArchive(
|
|
106
|
-
outputFilePath: string,
|
|
107
|
-
packageDirPath: string,
|
|
108
|
-
filesToInclude: string[]
|
|
109
|
-
) {
|
|
110
|
-
if (filesToInclude.length === 0) {
|
|
111
|
-
throw new ValidationError('Nothing to pack');
|
|
112
|
-
}
|
|
113
|
-
await tar.c(
|
|
114
|
-
{
|
|
115
|
-
gzip: true,
|
|
116
|
-
file: outputFilePath,
|
|
117
|
-
cwd: packageDirPath,
|
|
118
|
-
},
|
|
119
|
-
filesToInclude
|
|
120
|
-
);
|
|
121
|
-
}
|
|
1
|
+
import { Command } from '@react-native-community/cli-types';
|
|
2
|
+
import { globSync } from 'glob';
|
|
3
|
+
import pathUtils from 'path';
|
|
4
|
+
import tar from 'tar';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import { ValidationError } from '../core';
|
|
7
|
+
import ignore, { Ignore } from 'ignore';
|
|
8
|
+
import JSON5 from 'json5';
|
|
9
|
+
|
|
10
|
+
export const commandPackHarmony: Command = {
|
|
11
|
+
name: 'pack-harmony',
|
|
12
|
+
description: 'Pack native code. Used for package development.',
|
|
13
|
+
options: [
|
|
14
|
+
{
|
|
15
|
+
name: '--oh-module-path <string>',
|
|
16
|
+
description: 'Path to the OH module',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: '--harmony-dir-path <string>',
|
|
20
|
+
description: 'Path to the harmony dir',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: '--package-json-path <string>',
|
|
24
|
+
description: 'Path to the package.json',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
func: async (argv, config, args: any) => {
|
|
28
|
+
try {
|
|
29
|
+
await pack(
|
|
30
|
+
pathUtils.resolve(args.harmonyDirPath),
|
|
31
|
+
pathUtils.resolve(args.ohModulePath),
|
|
32
|
+
pathUtils.resolve(args.packageJsonPath)
|
|
33
|
+
);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
if (err instanceof ValidationError) {
|
|
36
|
+
console.error('[ERROR]', err.message);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
} else {
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
async function pack(
|
|
46
|
+
harmonyDirPath: string,
|
|
47
|
+
ohModuleDirPath: string,
|
|
48
|
+
packageJSONPath: string
|
|
49
|
+
) {
|
|
50
|
+
syncVersions(
|
|
51
|
+
packageJSONPath,
|
|
52
|
+
pathUtils.join(ohModuleDirPath, 'oh-package.json5')
|
|
53
|
+
);
|
|
54
|
+
if (!fs.existsSync(harmonyDirPath)) {
|
|
55
|
+
fs.mkdirSync(harmonyDirPath, { recursive: true });
|
|
56
|
+
}
|
|
57
|
+
await createTGZFromDir(
|
|
58
|
+
ohModuleDirPath,
|
|
59
|
+
pathUtils.join(
|
|
60
|
+
harmonyDirPath,
|
|
61
|
+
`${pathUtils.parse(ohModuleDirPath).name}.tar.gz`
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
await createTGZFromDir(
|
|
65
|
+
harmonyDirPath,
|
|
66
|
+
pathUtils.join(pathUtils.dirname(harmonyDirPath), 'harmony.tar.gz')
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function syncVersions(
|
|
71
|
+
packageJSONFilePath: string,
|
|
72
|
+
ohPackageJSONFilePath: string
|
|
73
|
+
) {
|
|
74
|
+
const packageJSONFileContent = JSON.parse(
|
|
75
|
+
fs.readFileSync(packageJSONFilePath, { encoding: 'utf-8' })
|
|
76
|
+
);
|
|
77
|
+
if (fs.existsSync(ohPackageJSONFilePath)) {
|
|
78
|
+
const ohPackageJSONFileContent = JSON5.parse(
|
|
79
|
+
fs.readFileSync(ohPackageJSONFilePath, { encoding: 'utf-8' })
|
|
80
|
+
);
|
|
81
|
+
ohPackageJSONFileContent['version'] = packageJSONFileContent['version'];
|
|
82
|
+
fs.writeFileSync(
|
|
83
|
+
ohPackageJSONFilePath,
|
|
84
|
+
JSON5.stringify(ohPackageJSONFileContent, null, 2)
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function createTGZFromDir(dirPath: string, outputFilePath: string) {
|
|
90
|
+
const ig = getIgnoreUtil(pathUtils.join(dirPath, '.tarignore'));
|
|
91
|
+
const filesToInclude = globSync('**', {
|
|
92
|
+
cwd: dirPath,
|
|
93
|
+
nodir: true,
|
|
94
|
+
}).filter((path) => !ig.ignores(path));
|
|
95
|
+
await createArchive(outputFilePath, dirPath, filesToInclude);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function getIgnoreUtil(tarignorePath: string): Ignore {
|
|
99
|
+
if (!fs.existsSync(tarignorePath)) {
|
|
100
|
+
return ignore();
|
|
101
|
+
}
|
|
102
|
+
return ignore().add(fs.readFileSync(tarignorePath).toString());
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function createArchive(
|
|
106
|
+
outputFilePath: string,
|
|
107
|
+
packageDirPath: string,
|
|
108
|
+
filesToInclude: string[]
|
|
109
|
+
) {
|
|
110
|
+
if (filesToInclude.length === 0) {
|
|
111
|
+
throw new ValidationError('Nothing to pack');
|
|
112
|
+
}
|
|
113
|
+
await tar.c(
|
|
114
|
+
{
|
|
115
|
+
gzip: true,
|
|
116
|
+
file: outputFilePath,
|
|
117
|
+
cwd: packageDirPath,
|
|
118
|
+
},
|
|
119
|
+
filesToInclude
|
|
120
|
+
);
|
|
121
|
+
}
|