@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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.commandCreateMetroConstantsHarmony = void 0;
|
|
16
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
17
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
18
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
19
|
+
exports.commandCreateMetroConstantsHarmony = {
|
|
20
|
+
name: 'create-metro-host-constants-harmony',
|
|
21
|
+
description: 'Creates a Typescript file that exports constant with IP of the host machine. That IP is later used to connect to the Metro server from a physical device.',
|
|
22
|
+
options: [
|
|
23
|
+
{
|
|
24
|
+
name: '--output <string>',
|
|
25
|
+
description: 'Output file',
|
|
26
|
+
default: './harmony/entry/src/main/ets/codegen/MetroHostConstants.ts',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
createMetroHostConstants(node_path_1.default.resolve(args.output));
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
function createMetroHostConstants(outputPath) {
|
|
34
|
+
const networkInterfacesByName = node_os_1.default.networkInterfaces();
|
|
35
|
+
const getIP = () => {
|
|
36
|
+
var _a;
|
|
37
|
+
for (let name of Object.keys(networkInterfacesByName)) {
|
|
38
|
+
for (let net of (_a = networkInterfacesByName[name]) !== null && _a !== void 0 ? _a : []) {
|
|
39
|
+
// skip over non-ipv4 and internal (i.e. 127.0.0.1) addresses
|
|
40
|
+
if (net.family === 'IPv4' && !net.internal) {
|
|
41
|
+
return net.address;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
};
|
|
47
|
+
const ip = getIP();
|
|
48
|
+
const tsCode = [
|
|
49
|
+
'// This file is autogenerated. Do not modify it manually.',
|
|
50
|
+
'',
|
|
51
|
+
`export const METRO_SERVER_IP = '${ip}';\n`,
|
|
52
|
+
];
|
|
53
|
+
node_fs_1.default.writeFile(outputPath, tsCode.join('\n'), (err) => {
|
|
54
|
+
if (err) {
|
|
55
|
+
console.error(`Error writing to ${outputPath}:`, err);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
console.log(`Created file at ${outputPath}`);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
package/dist/commands/index.js
CHANGED
|
@@ -17,3 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./bundle-harmony"), exports);
|
|
18
18
|
__exportStar(require("./pack-harmony"), exports);
|
|
19
19
|
__exportStar(require("./unpack-harmony"), exports);
|
|
20
|
+
__exportStar(require("./create-metro-host-constants"), exports);
|
|
21
|
+
__exportStar(require("./codegen-harmony"), exports);
|
|
@@ -55,6 +55,9 @@ exports.commandPackHarmony = {
|
|
|
55
55
|
function pack(harmonyDirPath, ohModuleDirPath, packageJSONPath) {
|
|
56
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
57
|
syncVersions(packageJSONPath, path_1.default.join(ohModuleDirPath, 'oh-package.json5'));
|
|
58
|
+
if (!fs_1.default.existsSync(harmonyDirPath)) {
|
|
59
|
+
fs_1.default.mkdirSync(harmonyDirPath, { recursive: true });
|
|
60
|
+
}
|
|
58
61
|
yield createTGZFromDir(ohModuleDirPath, path_1.default.join(harmonyDirPath, `${path_1.default.parse(ohModuleDirPath).name}.tar.gz`));
|
|
59
62
|
yield createTGZFromDir(harmonyDirPath, path_1.default.join(path_1.default.dirname(harmonyDirPath), 'harmony.tar.gz'));
|
|
60
63
|
});
|
|
@@ -64,7 +67,7 @@ function syncVersions(packageJSONFilePath, ohPackageJSONFilePath) {
|
|
|
64
67
|
if (fs_1.default.existsSync(ohPackageJSONFilePath)) {
|
|
65
68
|
const ohPackageJSONFileContent = json5_1.default.parse(fs_1.default.readFileSync(ohPackageJSONFilePath, { encoding: 'utf-8' }));
|
|
66
69
|
ohPackageJSONFileContent['version'] = packageJSONFileContent['version'];
|
|
67
|
-
fs_1.default.writeFileSync(ohPackageJSONFilePath, json5_1.default.stringify(ohPackageJSONFileContent));
|
|
70
|
+
fs_1.default.writeFileSync(ohPackageJSONFilePath, json5_1.default.stringify(ohPackageJSONFileContent, null, 2));
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
function createTGZFromDir(dirPath, outputFilePath) {
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.commandUnpackHarmony = void 0;
|
|
16
|
+
const io_1 = require("../io");
|
|
16
17
|
const path_1 = __importDefault(require("path"));
|
|
17
18
|
const fs_1 = __importDefault(require("fs"));
|
|
18
19
|
const zlib_1 = __importDefault(require("zlib"));
|
|
@@ -21,22 +22,22 @@ const json5_1 = __importDefault(require("json5"));
|
|
|
21
22
|
const core_1 = require("../core");
|
|
22
23
|
exports.commandUnpackHarmony = {
|
|
23
24
|
name: 'unpack-harmony',
|
|
24
|
-
description: '
|
|
25
|
+
description: 'Unpacks native code.',
|
|
25
26
|
options: [
|
|
26
27
|
{
|
|
27
|
-
name: '--
|
|
28
|
-
description: '
|
|
29
|
-
default: '
|
|
28
|
+
name: '--project-root-path <path>',
|
|
29
|
+
description: 'Relative path to package root',
|
|
30
|
+
default: '.',
|
|
30
31
|
},
|
|
31
32
|
{
|
|
32
33
|
name: '--output-dir <string>',
|
|
33
34
|
description: 'Output directory to which OH modules should be unpacked to',
|
|
34
|
-
default: './harmony/
|
|
35
|
+
default: './harmony/rnoh_modules',
|
|
35
36
|
},
|
|
36
37
|
],
|
|
37
38
|
func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
39
|
try {
|
|
39
|
-
yield unpack(
|
|
40
|
+
yield unpack(new core_1.AbsolutePath(args.projectRootPath), new core_1.AbsolutePath(args.outputDir));
|
|
40
41
|
}
|
|
41
42
|
catch (err) {
|
|
42
43
|
if (err instanceof core_1.ValidationError) {
|
|
@@ -49,35 +50,82 @@ exports.commandUnpackHarmony = {
|
|
|
49
50
|
}
|
|
50
51
|
}),
|
|
51
52
|
};
|
|
52
|
-
function unpack(
|
|
53
|
+
function unpack(projectRootPath, outputDirPath) {
|
|
53
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
const logger = new io_1.Logger();
|
|
56
|
+
const projectDependenciesManager = new core_1.ProjectDependenciesManager(projectRootPath);
|
|
57
|
+
logger.info((styles) => styles.bold(`Unpacking RNOH modules`), {
|
|
58
|
+
prefix: true,
|
|
59
|
+
});
|
|
60
|
+
let unpackedArchivesCount = 0;
|
|
61
|
+
let skippedArchivesCount = 0;
|
|
62
|
+
yield projectDependenciesManager.forEachAsync((dependency) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const packageJSON = dependency.readPackageJSON();
|
|
64
|
+
const harmonyArchivePath = dependency
|
|
65
|
+
.getRootPath()
|
|
66
|
+
.copyWithNewSegment('harmony.tar.gz');
|
|
67
|
+
const pkgHarmonyDirPath = dependency
|
|
68
|
+
.getRootPath()
|
|
69
|
+
.copyWithNewSegment('harmony');
|
|
70
|
+
const harmonyTarGzPathStr = dependency
|
|
71
|
+
.getRootPath()
|
|
72
|
+
.copyWithNewSegment('harmony.tar.gz')
|
|
73
|
+
.relativeTo(projectRootPath)
|
|
74
|
+
.getValue();
|
|
75
|
+
if (packageJSON.version &&
|
|
76
|
+
shouldUnpack(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, packageJSON.version)) {
|
|
77
|
+
if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue())) {
|
|
78
|
+
/**
|
|
79
|
+
* After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
|
|
80
|
+
*/
|
|
81
|
+
logger.info((styles) => `[${styles.cyan('unpacking')}] ${styles.gray(harmonyTarGzPathStr)}`);
|
|
82
|
+
yield unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
|
|
83
|
+
unpackedArchivesCount++;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
skippedArchivesCount++;
|
|
87
|
+
logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(harmonyTarGzPathStr)}`);
|
|
88
|
+
}
|
|
89
|
+
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
65
90
|
for (const ohModuleInfo of ohModulesInfo) {
|
|
66
|
-
|
|
91
|
+
const moduleArchivePathStr = dependency
|
|
92
|
+
.getRootPath()
|
|
93
|
+
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
94
|
+
.relativeTo(projectRootPath)
|
|
95
|
+
.getValue();
|
|
96
|
+
logger.info((styles) => `[${styles.cyan('unpacking')}] ${styles.gray(moduleArchivePathStr)}`);
|
|
97
|
+
unpackedArchivesCount++;
|
|
67
98
|
yield unpackTarGz(ohModuleInfo.archivePath, ohModuleInfo.computedModulePath);
|
|
68
99
|
}
|
|
69
100
|
}
|
|
70
|
-
|
|
101
|
+
else {
|
|
102
|
+
if (fs_1.default.existsSync(harmonyArchivePath.getValue())) {
|
|
103
|
+
skippedArchivesCount++;
|
|
104
|
+
logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(harmonyTarGzPathStr)}`);
|
|
105
|
+
}
|
|
106
|
+
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
107
|
+
for (const ohModuleInfo of ohModulesInfo) {
|
|
108
|
+
const moduleArchivePathStr = dependency
|
|
109
|
+
.getRootPath()
|
|
110
|
+
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
111
|
+
.relativeTo(projectRootPath)
|
|
112
|
+
.getValue();
|
|
113
|
+
skippedArchivesCount++;
|
|
114
|
+
logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(moduleArchivePathStr)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
logger.info((styles) => `\nUnpacked: ${styles.cyan(unpackedArchivesCount)}, Skipped: ${styles.yellow(skippedArchivesCount)}`);
|
|
71
119
|
});
|
|
72
120
|
}
|
|
73
|
-
function
|
|
74
|
-
if (!fs_1.default.existsSync(harmonyArchivePath))
|
|
121
|
+
function shouldUnpack(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, nodePackageVersion) {
|
|
122
|
+
if (!fs_1.default.existsSync(harmonyArchivePath.getValue()))
|
|
75
123
|
return false;
|
|
76
|
-
if (!fs_1.default.existsSync(pkgHarmonyDirPath))
|
|
124
|
+
if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue()))
|
|
77
125
|
return true;
|
|
78
126
|
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
79
127
|
for (const ohModuleInfo of ohModulesInfo) {
|
|
80
|
-
if (!fs_1.default.existsSync(ohModuleInfo.computedModulePath) ||
|
|
128
|
+
if (!fs_1.default.existsSync(ohModuleInfo.computedModulePath.getValue()) ||
|
|
81
129
|
getOhPackageVersion(ohModuleInfo.computedModulePath) !==
|
|
82
130
|
nodePackageVersion) {
|
|
83
131
|
return true;
|
|
@@ -85,32 +133,27 @@ function shouldUnpackHarmonyArchive(harmonyArchivePath, pkgHarmonyDirPath, outpu
|
|
|
85
133
|
}
|
|
86
134
|
return false;
|
|
87
135
|
}
|
|
88
|
-
function getNodePackageVersion(nodeModulePath) {
|
|
89
|
-
const packageJSONPath = path_1.default.join(nodeModulePath, 'package.json');
|
|
90
|
-
if (!fs_1.default.existsSync(packageJSONPath))
|
|
91
|
-
return null;
|
|
92
|
-
const content = fs_1.default.readFileSync(packageJSONPath, { encoding: 'utf-8' });
|
|
93
|
-
return JSON.parse(content)['version'];
|
|
94
|
-
}
|
|
95
136
|
function getOhPackageVersion(modulePath) {
|
|
96
|
-
const ohPackagePath =
|
|
97
|
-
if (!fs_1.default.existsSync(ohPackagePath))
|
|
137
|
+
const ohPackagePath = modulePath.copyWithNewSegment('oh-package.json5');
|
|
138
|
+
if (!fs_1.default.existsSync(ohPackagePath.getValue()))
|
|
98
139
|
return null;
|
|
99
|
-
const content = fs_1.default.readFileSync(ohPackagePath, {
|
|
140
|
+
const content = fs_1.default.readFileSync(ohPackagePath.getValue(), {
|
|
141
|
+
encoding: 'utf-8',
|
|
142
|
+
});
|
|
100
143
|
return json5_1.default.parse(content)['version'];
|
|
101
144
|
}
|
|
102
145
|
function getOhModulesInfo(pkgHarmonyDirPath, outputDirPath) {
|
|
103
146
|
const results = [];
|
|
104
|
-
if (!fs_1.default.existsSync(pkgHarmonyDirPath))
|
|
147
|
+
if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue()))
|
|
105
148
|
return [];
|
|
106
|
-
const names = fs_1.default.readdirSync(pkgHarmonyDirPath);
|
|
149
|
+
const names = fs_1.default.readdirSync(pkgHarmonyDirPath.getValue());
|
|
107
150
|
for (const name of names) {
|
|
108
151
|
if (name.endsWith('.tar.gz')) {
|
|
109
|
-
const archivePath =
|
|
152
|
+
const archivePath = pkgHarmonyDirPath.copyWithNewSegment(name);
|
|
110
153
|
const computedModuleName = path_1.default
|
|
111
|
-
.parse(archivePath)
|
|
154
|
+
.parse(archivePath.getValue())
|
|
112
155
|
.name.split('.')[0];
|
|
113
|
-
const computedModulePath =
|
|
156
|
+
const computedModulePath = outputDirPath.copyWithNewSegment(computedModuleName);
|
|
114
157
|
results.push({
|
|
115
158
|
archivePath,
|
|
116
159
|
archiveFileName: name,
|
|
@@ -122,12 +165,12 @@ function getOhModulesInfo(pkgHarmonyDirPath, outputDirPath) {
|
|
|
122
165
|
return results;
|
|
123
166
|
}
|
|
124
167
|
function unpackTarGz(archivePath, outputDirPath) {
|
|
125
|
-
if (!fs_1.default.existsSync(outputDirPath)) {
|
|
126
|
-
fs_1.default.mkdirSync(outputDirPath, { recursive: true });
|
|
168
|
+
if (!fs_1.default.existsSync(outputDirPath.getValue())) {
|
|
169
|
+
fs_1.default.mkdirSync(outputDirPath.getValue(), { recursive: true });
|
|
127
170
|
}
|
|
128
|
-
const readStream = fs_1.default.createReadStream(archivePath);
|
|
171
|
+
const readStream = fs_1.default.createReadStream(archivePath.getValue());
|
|
129
172
|
const writeStream = tar_1.default.extract({
|
|
130
|
-
cwd: outputDirPath,
|
|
173
|
+
cwd: outputDirPath.getValue(),
|
|
131
174
|
});
|
|
132
175
|
readStream.pipe(zlib_1.default.createGunzip()).pipe(writeStream);
|
|
133
176
|
return new Promise((resolve, reject) => {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AbsolutePath = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
class AbsolutePath {
|
|
9
|
+
static fromSegments(...segments) {
|
|
10
|
+
return new AbsolutePath(node_path_1.default.join(...segments));
|
|
11
|
+
}
|
|
12
|
+
constructor(path) {
|
|
13
|
+
this.value = '';
|
|
14
|
+
this.value = node_path_1.default.resolve(path);
|
|
15
|
+
}
|
|
16
|
+
getValue() {
|
|
17
|
+
return this.value;
|
|
18
|
+
}
|
|
19
|
+
copyWithNewSegment(...relativePath) {
|
|
20
|
+
return new AbsolutePath(node_path_1.default.join(this.getValue(), ...relativePath));
|
|
21
|
+
}
|
|
22
|
+
getExtension() {
|
|
23
|
+
const maybeExtWithDot = node_path_1.default.extname(this.value);
|
|
24
|
+
if (maybeExtWithDot) {
|
|
25
|
+
return maybeExtWithDot.substring(1);
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
relativeTo(absolutePath) {
|
|
30
|
+
return new RelativePath(node_path_1.default.relative(absolutePath.getValue(), this.value));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.AbsolutePath = AbsolutePath;
|
|
34
|
+
class RelativePath {
|
|
35
|
+
constructor(value) {
|
|
36
|
+
this.value = value;
|
|
37
|
+
}
|
|
38
|
+
getValue() {
|
|
39
|
+
return this.value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CodegenConfig = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const io_1 = require("../io");
|
|
9
|
+
const DescriptiveError_1 = require("./DescriptiveError");
|
|
10
|
+
class CodegenConfig {
|
|
11
|
+
static fromRawCodegenConfig(rawCodegenConfig, packageRootPath, projectRootPath, packageName) {
|
|
12
|
+
var _a;
|
|
13
|
+
const SUPPORTED_SPEC_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
|
|
14
|
+
const specPaths = ((_a = rawCodegenConfig.specPaths) !== null && _a !== void 0 ? _a : []).map((rawSpecPath) => {
|
|
15
|
+
if (rawSpecPath.startsWith('~')) {
|
|
16
|
+
return projectRootPath.copyWithNewSegment(rawSpecPath.replace('~', ''));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return packageRootPath.copyWithNewSegment(rawSpecPath);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const specFilePaths = specPaths.flatMap((specPath) => {
|
|
23
|
+
if (!node_fs_1.default.existsSync(specPath.getValue())) {
|
|
24
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
25
|
+
whatHappened: `No such file or directory: ${specPath.getValue()}`,
|
|
26
|
+
whatCanUserDo: {
|
|
27
|
+
default: [
|
|
28
|
+
`Please verify in "${packageName}/package.json::harmony::codegenConfig". If you are not the maintainer of this package, please report this problem to the package maintainer.`,
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (node_fs_1.default.lstatSync(specPath.getValue()).isDirectory()) {
|
|
34
|
+
return (0, io_1.findFilePathsWithExtensions)(specPath, SUPPORTED_SPEC_EXTENSIONS);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const ext = specPath.getExtension();
|
|
38
|
+
if (ext && SUPPORTED_SPEC_EXTENSIONS.includes(ext)) {
|
|
39
|
+
return [specPath];
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return new CodegenConfig(specFilePaths);
|
|
45
|
+
}
|
|
46
|
+
constructor(specFilePaths) {
|
|
47
|
+
this.specFilePaths = specFilePaths;
|
|
48
|
+
}
|
|
49
|
+
getSpecFilePaths() {
|
|
50
|
+
return this.specFilePaths;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.CodegenConfig = CodegenConfig;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DescriptiveError = void 0;
|
|
4
|
+
class DescriptiveError extends Error {
|
|
5
|
+
constructor(data) {
|
|
6
|
+
super(data.whatHappened);
|
|
7
|
+
this.data = data;
|
|
8
|
+
}
|
|
9
|
+
isUnexpected() {
|
|
10
|
+
return 'unexpected' in this.data;
|
|
11
|
+
}
|
|
12
|
+
getMessage() {
|
|
13
|
+
return this.data.whatHappened;
|
|
14
|
+
}
|
|
15
|
+
getSuggestionsByRole() {
|
|
16
|
+
if ('whatCanUserDo' in this.data) {
|
|
17
|
+
return this.data.whatCanUserDo;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
getDetails() {
|
|
24
|
+
var _a;
|
|
25
|
+
if (!this.data.extraData) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
if (typeof this.data.extraData === 'string') {
|
|
29
|
+
return this.data.extraData.trim();
|
|
30
|
+
}
|
|
31
|
+
if (this.data.extraData instanceof Error) {
|
|
32
|
+
let lines = [
|
|
33
|
+
`${this.data.extraData.name}: ${this.data.extraData.message}`,
|
|
34
|
+
];
|
|
35
|
+
for (let stackEntry of ((_a = this.data.extraData.stack) !== null && _a !== void 0 ? _a : '').split('\n')) {
|
|
36
|
+
lines.push('');
|
|
37
|
+
lines.push(stackEntry);
|
|
38
|
+
}
|
|
39
|
+
return lines.join('\n');
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
return JSON.stringify(this.data.extraData, null, 2);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.DescriptiveError = DescriptiveError;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PackageJSON = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const CodegenConfig_1 = require("./CodegenConfig");
|
|
9
|
+
const DescriptiveError_1 = require("./DescriptiveError");
|
|
10
|
+
class PackageJSON {
|
|
11
|
+
static fromProjectRootPath(packageRootPath, projectRootPath) {
|
|
12
|
+
const packageJSONPath = packageRootPath.copyWithNewSegment('package.json');
|
|
13
|
+
if (!fs_1.default.existsSync(packageJSONPath.getValue())) {
|
|
14
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
15
|
+
whatHappened: "Couldn't find 'package.json'",
|
|
16
|
+
whatCanUserDo: {
|
|
17
|
+
default: [
|
|
18
|
+
'Check if the path to project root is correct',
|
|
19
|
+
'Try changing working directory to project root',
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
extraData: packageJSONPath.getValue(),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return new PackageJSON(JSON.parse(fs_1.default.readFileSync(packageJSONPath.getValue()).toString()), packageRootPath, projectRootPath);
|
|
26
|
+
}
|
|
27
|
+
constructor(rawPackageJSON, packageRootPath, projectRootPath) {
|
|
28
|
+
this.rawPackageJSON = rawPackageJSON;
|
|
29
|
+
this.packageRootPath = packageRootPath;
|
|
30
|
+
this.projectRootPath = projectRootPath;
|
|
31
|
+
}
|
|
32
|
+
get name() {
|
|
33
|
+
return this.rawPackageJSON.name;
|
|
34
|
+
}
|
|
35
|
+
get version() {
|
|
36
|
+
return this.rawPackageJSON.version;
|
|
37
|
+
}
|
|
38
|
+
maybeCreateCodegenConfig() {
|
|
39
|
+
var _a;
|
|
40
|
+
/**
|
|
41
|
+
* Shared codegenConfig is not used on purpose. Android, iOS and other platforms shouldn't
|
|
42
|
+
* generate code for harmony-specific packages. The shape of this codegenConfig is different
|
|
43
|
+
* that the shape of the shared config, to allow specifying which specific turbo modules or
|
|
44
|
+
* fabric components should be code generated.
|
|
45
|
+
*/
|
|
46
|
+
const rawCodegenConfig = (_a = this.rawPackageJSON.harmony) === null || _a === void 0 ? void 0 : _a.codegenConfig;
|
|
47
|
+
if (!rawCodegenConfig) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return CodegenConfig_1.CodegenConfig.fromRawCodegenConfig(rawCodegenConfig, this.packageRootPath, this.projectRootPath, this.name);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.PackageJSON = PackageJSON;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ProjectDependenciesManager = exports.ProjectDependency = void 0;
|
|
16
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
17
|
+
const PackageJSON_1 = require("./PackageJSON");
|
|
18
|
+
class ProjectDependency {
|
|
19
|
+
constructor(packageRootPath, projectRootPath) {
|
|
20
|
+
this.packageRootPath = packageRootPath;
|
|
21
|
+
this.projectRootPath = projectRootPath;
|
|
22
|
+
}
|
|
23
|
+
getRootPath() {
|
|
24
|
+
return this.packageRootPath;
|
|
25
|
+
}
|
|
26
|
+
maybeCreateCodegenConfig() {
|
|
27
|
+
return this.readPackageJSON().maybeCreateCodegenConfig();
|
|
28
|
+
}
|
|
29
|
+
readPackageJSON() {
|
|
30
|
+
return PackageJSON_1.PackageJSON.fromProjectRootPath(this.packageRootPath, this.projectRootPath);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ProjectDependency = ProjectDependency;
|
|
34
|
+
class ProjectDependenciesManager {
|
|
35
|
+
constructor(projectRootPath) {
|
|
36
|
+
this.projectRootPath = projectRootPath;
|
|
37
|
+
}
|
|
38
|
+
forEachAsync(cb) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
yield this.forEachDependencyInDirectory(cb, this.projectRootPath.copyWithNewSegment('node_modules'));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
forEachDependencyInDirectory(cb, directoryPath) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (!node_fs_1.default.existsSync(directoryPath.getValue())) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
for (let dirOrFileName of node_fs_1.default.readdirSync(directoryPath.getValue())) {
|
|
49
|
+
const potentialDependencyRootPath = directoryPath.copyWithNewSegment(dirOrFileName);
|
|
50
|
+
if (node_fs_1.default.lstatSync(potentialDependencyRootPath.getValue()).isDirectory()) {
|
|
51
|
+
if (dirOrFileName.startsWith('.')) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
else if (dirOrFileName.startsWith('@')) {
|
|
55
|
+
yield this.forEachDependencyInDirectory(cb, directoryPath.copyWithNewSegment(dirOrFileName));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (!node_fs_1.default.existsSync(potentialDependencyRootPath
|
|
59
|
+
.copyWithNewSegment('package.json')
|
|
60
|
+
.getValue())) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
yield cb(new ProjectDependency(potentialDependencyRootPath, this.projectRootPath));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ProjectDependenciesManager = ProjectDependenciesManager;
|
package/dist/core/fs.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.maybeRemoveFilesInDirectory = exports.maybeMakeDirectories = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const DescriptiveError_1 = require("./DescriptiveError");
|
|
9
|
+
function maybeMakeDirectories(path) {
|
|
10
|
+
if (!node_fs_1.default.existsSync(path.getValue())) {
|
|
11
|
+
node_fs_1.default.mkdirSync(path.getValue(), { recursive: true });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.maybeMakeDirectories = maybeMakeDirectories;
|
|
15
|
+
function maybeRemoveFilesInDirectory(path) {
|
|
16
|
+
if (!node_fs_1.default.existsSync(path.getValue())) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!node_fs_1.default.lstatSync(path.getValue()).isDirectory()) {
|
|
20
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
21
|
+
whatHappened: "Tried to remove all files from a path that doesn't point to a directory",
|
|
22
|
+
whatCanUserDo: { default: [`Verify path: ${path.getValue()}`] },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const fileOrDirNames = node_fs_1.default.readdirSync(path.getValue());
|
|
26
|
+
fileOrDirNames.forEach((fileOrDirName) => {
|
|
27
|
+
const maybeFilePath = path.copyWithNewSegment(fileOrDirName);
|
|
28
|
+
if (node_fs_1.default.statSync(maybeFilePath.getValue()).isDirectory()) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
node_fs_1.default.unlinkSync(maybeFilePath.getValue());
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.maybeRemoveFilesInDirectory = maybeRemoveFilesInDirectory;
|
package/dist/core/index.js
CHANGED
|
@@ -14,4 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./AbsolutePath"), exports);
|
|
17
18
|
__exportStar(require("./ValidationError"), exports);
|
|
19
|
+
__exportStar(require("./DescriptiveError"), exports);
|
|
20
|
+
__exportStar(require("./ValueObject"), exports);
|
|
21
|
+
__exportStar(require("./PackageJSON"), exports);
|
|
22
|
+
__exportStar(require("./ProjectDependenciesManager"), exports);
|
|
23
|
+
__exportStar(require("./CodegenConfig"), exports);
|
|
24
|
+
__exportStar(require("./fs"), exports);
|
package/dist/index.js
CHANGED
|
@@ -3,5 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.config = void 0;
|
|
4
4
|
const commands_1 = require("./commands");
|
|
5
5
|
exports.config = {
|
|
6
|
-
commands: [
|
|
6
|
+
commands: [
|
|
7
|
+
commands_1.commandBundleHarmony,
|
|
8
|
+
commands_1.commandPackHarmony,
|
|
9
|
+
commands_1.commandUnpackHarmony,
|
|
10
|
+
commands_1.commandCreateMetroConstantsHarmony,
|
|
11
|
+
commands_1.commandCodegenHarmony,
|
|
12
|
+
],
|
|
7
13
|
};
|