@react-native-oh/react-native-harmony-cli 0.0.15 → 0.0.23
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/dist/assetResolver.js +23 -5
- package/dist/codegen/core/Codegen.js +35 -0
- package/dist/codegen/core/CodegenError.js +7 -0
- package/dist/codegen/core/EventUtils.js +19 -0
- package/dist/codegen/core/TypeAnnotationToTS.js +132 -0
- package/dist/codegen/core/UberSchema.js +74 -0
- package/dist/codegen/core/index.js +21 -0
- package/dist/codegen/generators/ComponentCodeGenerator.js +66 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +64 -0
- package/dist/codegen/generators/PackageCodeGenerator.js +52 -0
- package/dist/codegen/generators/index.js +19 -0
- package/dist/codegen/index.js +18 -0
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +55 -0
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +78 -0
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +181 -0
- package/dist/codegen/templates/IndexTSTemplate.js +31 -0
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +117 -0
- package/dist/codegen/templates/TurboModuleCppTemplate.js +45 -0
- package/dist/codegen/templates/TurboModuleHTemplate.js +32 -0
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +64 -0
- package/dist/codegen/templates/index.js +24 -0
- package/dist/commands/codegen-harmony.js +110 -0
- package/dist/commands/create-metro-host-constants.js +61 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/pack-harmony.js +4 -1
- package/dist/commands/unpack-harmony.js +86 -43
- package/dist/core/AbsolutePath.js +41 -0
- package/dist/core/CodegenConfig.js +53 -0
- package/dist/core/DescriptiveError.js +49 -0
- package/dist/core/PackageJSON.js +53 -0
- package/dist/core/ProjectDependenciesManager.js +70 -0
- package/dist/core/ValueObject.js +2 -0
- package/dist/core/fs.js +36 -0
- package/dist/core/index.js +7 -0
- package/dist/index.js +7 -1
- package/dist/io/Logger.js +71 -0
- package/dist/io/fsUtils.js +23 -0
- package/dist/io/index.js +18 -0
- package/jest.config.js +5 -5
- package/package.json +52 -47
- package/react-native.config.js +10 -10
- package/src/assetResolver.ts +44 -25
- package/src/codegen/core/Codegen.ts +44 -0
- package/src/codegen/core/CodegenError.ts +3 -0
- package/src/codegen/core/EventUtils.ts +18 -0
- package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -0
- package/src/codegen/core/TypeAnnotationToTS.ts +188 -0
- package/src/codegen/core/UberSchema.ts +99 -0
- package/src/codegen/core/index.ts +5 -0
- package/src/codegen/generators/ComponentCodeGenerator.ts +98 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +95 -0
- package/src/codegen/generators/PackageCodeGenerator.ts +73 -0
- package/src/codegen/generators/index.ts +3 -0
- package/src/codegen/index.ts +2 -0
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +49 -0
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +85 -0
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +202 -0
- package/src/codegen/templates/IndexTSTemplate.ts +33 -0
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +124 -0
- package/src/codegen/templates/TurboModuleCppTemplate.ts +47 -0
- package/src/codegen/templates/TurboModuleHTemplate.ts +26 -0
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +81 -0
- package/src/codegen/templates/index.ts +8 -0
- package/src/commands/bundle-harmony.ts +202 -202
- package/src/commands/codegen-harmony.ts +143 -0
- package/src/commands/create-metro-host-constants.ts +48 -0
- package/src/commands/index.ts +5 -3
- package/src/commands/pack-harmony.ts +121 -118
- package/src/commands/unpack-harmony.ts +231 -156
- package/src/core/AbsolutePath.ts +43 -0
- package/src/core/CodegenConfig.ts +54 -0
- package/src/core/DescriptiveError.ts +61 -0
- package/src/core/PackageJSON.ts +63 -0
- package/src/core/ProjectDependenciesManager.ts +77 -0
- package/src/core/ValidationError.ts +1 -1
- package/src/core/ValueObject.ts +2 -0
- package/src/core/fs.ts +31 -0
- package/src/core/index.ts +8 -1
- package/src/index.ts +18 -10
- package/src/io/Logger.ts +68 -0
- package/src/io/fsUtils.ts +24 -0
- package/src/io/index.ts +2 -0
- package/tsconfig.build.json +6 -5
- package/tsconfig.json +2 -2
|
@@ -1,118 +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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
ohPackageJSONFileContent
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
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,156 +1,231 @@
|
|
|
1
|
-
import { Command } from '@react-native-community/cli-types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
name: '--
|
|
21
|
-
description: '
|
|
22
|
-
default: '
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
1
|
+
import { Command } from '@react-native-community/cli-types';
|
|
2
|
+
import { Logger } from '../io';
|
|
3
|
+
|
|
4
|
+
import pathUtils from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import zlib from 'zlib';
|
|
7
|
+
import tar from 'tar';
|
|
8
|
+
import JSON5 from 'json5';
|
|
9
|
+
import {
|
|
10
|
+
ValidationError,
|
|
11
|
+
AbsolutePath,
|
|
12
|
+
ProjectDependenciesManager,
|
|
13
|
+
} from '../core';
|
|
14
|
+
|
|
15
|
+
export const commandUnpackHarmony: Command = {
|
|
16
|
+
name: 'unpack-harmony',
|
|
17
|
+
description: 'Unpacks native code.',
|
|
18
|
+
options: [
|
|
19
|
+
{
|
|
20
|
+
name: '--project-root-path <path>',
|
|
21
|
+
description: 'Relative path to package root',
|
|
22
|
+
default: '.',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: '--output-dir <string>',
|
|
26
|
+
description: 'Output directory to which OH modules should be unpacked to',
|
|
27
|
+
default: './harmony/rnoh_modules',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
func: async (argv, config, args: any) => {
|
|
31
|
+
try {
|
|
32
|
+
await unpack(
|
|
33
|
+
new AbsolutePath(args.projectRootPath),
|
|
34
|
+
new AbsolutePath(args.outputDir)
|
|
35
|
+
);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
if (err instanceof ValidationError) {
|
|
38
|
+
console.error('[ERROR]', err.message);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
} else {
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
async function unpack(
|
|
48
|
+
projectRootPath: AbsolutePath,
|
|
49
|
+
outputDirPath: AbsolutePath
|
|
50
|
+
) {
|
|
51
|
+
const logger = new Logger();
|
|
52
|
+
const projectDependenciesManager = new ProjectDependenciesManager(
|
|
53
|
+
projectRootPath
|
|
54
|
+
);
|
|
55
|
+
logger.info((styles) => styles.bold(`Unpacking RNOH modules`), {
|
|
56
|
+
prefix: true,
|
|
57
|
+
});
|
|
58
|
+
let unpackedArchivesCount = 0;
|
|
59
|
+
let skippedArchivesCount = 0;
|
|
60
|
+
await projectDependenciesManager.forEachAsync(async (dependency) => {
|
|
61
|
+
const packageJSON = dependency.readPackageJSON();
|
|
62
|
+
const harmonyArchivePath = dependency
|
|
63
|
+
.getRootPath()
|
|
64
|
+
.copyWithNewSegment('harmony.tar.gz');
|
|
65
|
+
const pkgHarmonyDirPath = dependency
|
|
66
|
+
.getRootPath()
|
|
67
|
+
.copyWithNewSegment('harmony');
|
|
68
|
+
const harmonyTarGzPathStr = dependency
|
|
69
|
+
.getRootPath()
|
|
70
|
+
.copyWithNewSegment('harmony.tar.gz')
|
|
71
|
+
.relativeTo(projectRootPath)
|
|
72
|
+
.getValue();
|
|
73
|
+
if (
|
|
74
|
+
packageJSON.version &&
|
|
75
|
+
shouldUnpack(
|
|
76
|
+
harmonyArchivePath,
|
|
77
|
+
pkgHarmonyDirPath,
|
|
78
|
+
outputDirPath,
|
|
79
|
+
packageJSON.version
|
|
80
|
+
)
|
|
81
|
+
) {
|
|
82
|
+
if (!fs.existsSync(pkgHarmonyDirPath.getValue())) {
|
|
83
|
+
/**
|
|
84
|
+
* After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
|
|
85
|
+
*/
|
|
86
|
+
logger.info(
|
|
87
|
+
(styles) =>
|
|
88
|
+
`[${styles.cyan('unpacking')}] ${styles.gray(harmonyTarGzPathStr)}`
|
|
89
|
+
);
|
|
90
|
+
await unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
|
|
91
|
+
unpackedArchivesCount++;
|
|
92
|
+
} else {
|
|
93
|
+
skippedArchivesCount++;
|
|
94
|
+
logger.info(
|
|
95
|
+
(styles) =>
|
|
96
|
+
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
97
|
+
harmonyTarGzPathStr
|
|
98
|
+
)}`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
102
|
+
for (const ohModuleInfo of ohModulesInfo) {
|
|
103
|
+
const moduleArchivePathStr = dependency
|
|
104
|
+
.getRootPath()
|
|
105
|
+
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
106
|
+
.relativeTo(projectRootPath)
|
|
107
|
+
.getValue();
|
|
108
|
+
logger.info(
|
|
109
|
+
(styles) =>
|
|
110
|
+
`[${styles.cyan('unpacking')}] ${styles.gray(moduleArchivePathStr)}`
|
|
111
|
+
);
|
|
112
|
+
unpackedArchivesCount++;
|
|
113
|
+
await unpackTarGz(
|
|
114
|
+
ohModuleInfo.archivePath,
|
|
115
|
+
ohModuleInfo.computedModulePath
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
if (fs.existsSync(harmonyArchivePath.getValue())) {
|
|
120
|
+
skippedArchivesCount++;
|
|
121
|
+
logger.info(
|
|
122
|
+
(styles) =>
|
|
123
|
+
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
124
|
+
harmonyTarGzPathStr
|
|
125
|
+
)}`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
129
|
+
for (const ohModuleInfo of ohModulesInfo) {
|
|
130
|
+
const moduleArchivePathStr = dependency
|
|
131
|
+
.getRootPath()
|
|
132
|
+
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
133
|
+
.relativeTo(projectRootPath)
|
|
134
|
+
.getValue();
|
|
135
|
+
skippedArchivesCount++;
|
|
136
|
+
logger.info(
|
|
137
|
+
(styles) =>
|
|
138
|
+
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
139
|
+
moduleArchivePathStr
|
|
140
|
+
)}`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
logger.info(
|
|
146
|
+
(styles) =>
|
|
147
|
+
`\nUnpacked: ${styles.cyan(
|
|
148
|
+
unpackedArchivesCount
|
|
149
|
+
)}, Skipped: ${styles.yellow(skippedArchivesCount)}`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function shouldUnpack(
|
|
154
|
+
harmonyArchivePath: AbsolutePath,
|
|
155
|
+
pkgHarmonyDirPath: AbsolutePath,
|
|
156
|
+
outputDirPath: AbsolutePath,
|
|
157
|
+
nodePackageVersion: string
|
|
158
|
+
) {
|
|
159
|
+
if (!fs.existsSync(harmonyArchivePath.getValue())) return false;
|
|
160
|
+
if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return true;
|
|
161
|
+
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
162
|
+
for (const ohModuleInfo of ohModulesInfo) {
|
|
163
|
+
if (
|
|
164
|
+
!fs.existsSync(ohModuleInfo.computedModulePath.getValue()) ||
|
|
165
|
+
getOhPackageVersion(ohModuleInfo.computedModulePath) !==
|
|
166
|
+
nodePackageVersion
|
|
167
|
+
) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function getOhPackageVersion(modulePath: AbsolutePath) {
|
|
175
|
+
const ohPackagePath = modulePath.copyWithNewSegment('oh-package.json5');
|
|
176
|
+
if (!fs.existsSync(ohPackagePath.getValue())) return null;
|
|
177
|
+
const content = fs.readFileSync(ohPackagePath.getValue(), {
|
|
178
|
+
encoding: 'utf-8',
|
|
179
|
+
});
|
|
180
|
+
return JSON5.parse(content)['version'];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function getOhModulesInfo(
|
|
184
|
+
pkgHarmonyDirPath: AbsolutePath,
|
|
185
|
+
outputDirPath: AbsolutePath
|
|
186
|
+
) {
|
|
187
|
+
const results: {
|
|
188
|
+
archivePath: AbsolutePath;
|
|
189
|
+
archiveFileName: string;
|
|
190
|
+
computedModulePath: AbsolutePath;
|
|
191
|
+
computedModuleName: string;
|
|
192
|
+
}[] = [];
|
|
193
|
+
if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return [];
|
|
194
|
+
const names = fs.readdirSync(pkgHarmonyDirPath.getValue());
|
|
195
|
+
for (const name of names) {
|
|
196
|
+
if (name.endsWith('.tar.gz')) {
|
|
197
|
+
const archivePath = pkgHarmonyDirPath.copyWithNewSegment(name);
|
|
198
|
+
const computedModuleName = pathUtils
|
|
199
|
+
.parse(archivePath.getValue())
|
|
200
|
+
.name.split('.')[0];
|
|
201
|
+
const computedModulePath =
|
|
202
|
+
outputDirPath.copyWithNewSegment(computedModuleName);
|
|
203
|
+
results.push({
|
|
204
|
+
archivePath,
|
|
205
|
+
archiveFileName: name,
|
|
206
|
+
computedModulePath,
|
|
207
|
+
computedModuleName,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return results;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function unpackTarGz(archivePath: AbsolutePath, outputDirPath: AbsolutePath) {
|
|
215
|
+
if (!fs.existsSync(outputDirPath.getValue())) {
|
|
216
|
+
fs.mkdirSync(outputDirPath.getValue(), { recursive: true });
|
|
217
|
+
}
|
|
218
|
+
const readStream = fs.createReadStream(archivePath.getValue());
|
|
219
|
+
const writeStream = tar.extract({
|
|
220
|
+
cwd: outputDirPath.getValue(),
|
|
221
|
+
});
|
|
222
|
+
readStream.pipe(zlib.createGunzip()).pipe(writeStream);
|
|
223
|
+
return new Promise((resolve, reject) => {
|
|
224
|
+
writeStream.on('finish', () => {
|
|
225
|
+
resolve(undefined);
|
|
226
|
+
});
|
|
227
|
+
writeStream.on('error', (err) => {
|
|
228
|
+
reject(err);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|