@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,70 +0,0 @@
|
|
|
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/ValueObject.js
DELETED
package/dist/core/fs.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./AbsolutePath"), exports);
|
|
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
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.config = void 0;
|
|
4
|
-
const commands_1 = require("./commands");
|
|
5
|
-
exports.config = {
|
|
6
|
-
commands: [
|
|
7
|
-
commands_1.commandBundleHarmony,
|
|
8
|
-
commands_1.commandPackHarmony,
|
|
9
|
-
commands_1.commandUnpackHarmony,
|
|
10
|
-
commands_1.commandCreateMetroConstantsHarmony,
|
|
11
|
-
commands_1.commandCodegenHarmony,
|
|
12
|
-
],
|
|
13
|
-
};
|
package/dist/io/Logger.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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.Logger = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
class Logger {
|
|
9
|
-
info(prepareMsg, options) {
|
|
10
|
-
const prefix = (options === null || options === void 0 ? void 0 : options.prefix) ? `[${chalk_1.default.bold(chalk_1.default.cyan('INFO'))}]` : '';
|
|
11
|
-
if (prefix) {
|
|
12
|
-
console.info(prefix, prepareMsg(chalk_1.default));
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
console.info(prepareMsg(chalk_1.default));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
debug(prepareMsg) {
|
|
19
|
-
console.debug(prepareMsg(chalk_1.default));
|
|
20
|
-
}
|
|
21
|
-
descriptiveError(error) {
|
|
22
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
23
|
-
const lines = [];
|
|
24
|
-
if (error.isUnexpected() && error.stack) {
|
|
25
|
-
lines.push('');
|
|
26
|
-
lines.push(chalk_1.default.bold('Stack'));
|
|
27
|
-
error.stack.split('\n').forEach((line) => lines.push(chalk_1.default.gray(line)));
|
|
28
|
-
}
|
|
29
|
-
const details = error.getDetails();
|
|
30
|
-
if (details) {
|
|
31
|
-
lines.push('');
|
|
32
|
-
lines.push(chalk_1.default.bold('Details'));
|
|
33
|
-
details.split('\n').forEach((line) => lines.push(line));
|
|
34
|
-
}
|
|
35
|
-
lines.push('');
|
|
36
|
-
let prefix = '';
|
|
37
|
-
if (error.isUnexpected()) {
|
|
38
|
-
prefix = '[' + chalk_1.default.red(chalk_1.default.bold('UNEXPECTED_ERROR')) + ']';
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
prefix = '[' + chalk_1.default.red(chalk_1.default.bold('ERROR')) + ']';
|
|
42
|
-
}
|
|
43
|
-
lines.push(`${prefix} ${error.getMessage()}`);
|
|
44
|
-
const suggestionsByRole = error.getSuggestionsByRole();
|
|
45
|
-
if (suggestionsByRole) {
|
|
46
|
-
if (((_b = (_a = suggestionsByRole.default) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) {
|
|
47
|
-
lines.push('');
|
|
48
|
-
lines.push(chalk_1.default.bold(`Suggestions`));
|
|
49
|
-
(_c = suggestionsByRole.default) === null || _c === void 0 ? void 0 : _c.forEach((suggestion) => {
|
|
50
|
-
lines.push(suggestion);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (((_e = (_d = suggestionsByRole.rnAppDeveloper) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) > 0) {
|
|
54
|
-
lines.push('');
|
|
55
|
-
lines.push(chalk_1.default.bold(`Suggestions for RN App developers`));
|
|
56
|
-
(_f = suggestionsByRole.rnAppDeveloper) === null || _f === void 0 ? void 0 : _f.forEach((suggestion) => {
|
|
57
|
-
lines.push(suggestion);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if ((_h = (_g = suggestionsByRole.rnPackageDeveloper) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0) {
|
|
61
|
-
lines.push('');
|
|
62
|
-
lines.push(chalk_1.default.bold(`Suggestions for RN package developers`));
|
|
63
|
-
(_j = suggestionsByRole.rnPackageDeveloper) === null || _j === void 0 ? void 0 : _j.forEach((suggestion) => {
|
|
64
|
-
lines.push(suggestion);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
console.error(lines.join('\n'));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.Logger = Logger;
|
package/dist/io/fsUtils.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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.findFilePathsWithExtensions = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
-
function findFilePathsWithExtensions(dirPath, fileExtensions) {
|
|
10
|
-
let results = [];
|
|
11
|
-
const files = node_fs_1.default.readdirSync(dirPath.getValue(), { withFileTypes: true });
|
|
12
|
-
for (const file of files) {
|
|
13
|
-
const path = dirPath.copyWithNewSegment(file.name);
|
|
14
|
-
if (file.isDirectory()) {
|
|
15
|
-
results = results.concat(findFilePathsWithExtensions(path, fileExtensions));
|
|
16
|
-
}
|
|
17
|
-
else if (fileExtensions.includes(node_path_1.default.extname(file.name).substring(1))) {
|
|
18
|
-
results.push(path);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return results;
|
|
22
|
-
}
|
|
23
|
-
exports.findFilePathsWithExtensions = findFilePathsWithExtensions;
|
package/dist/io/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Logger"), exports);
|
|
18
|
-
__exportStar(require("./fsUtils"), exports);
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { AbsolutePath } from '../../core';
|
|
2
|
-
import { CodegenError } from './CodegenError';
|
|
3
|
-
import { SpecSchema, SpecSchemaType, UberSchema } from './UberSchema';
|
|
4
|
-
|
|
5
|
-
export interface CodeGenerator<T> {
|
|
6
|
-
generate(data: T): Map<AbsolutePath, string>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface SpecCodeGenerator extends CodeGenerator<SpecSchema> {}
|
|
10
|
-
|
|
11
|
-
export class Codegen {
|
|
12
|
-
constructor(
|
|
13
|
-
private packageCodeGenerator: CodeGenerator<UberSchema>,
|
|
14
|
-
private codeGeneratorBySpecSchemaType: Record<
|
|
15
|
-
SpecSchemaType,
|
|
16
|
-
SpecCodeGenerator
|
|
17
|
-
>
|
|
18
|
-
) {}
|
|
19
|
-
|
|
20
|
-
generate(uberSchema: UberSchema): Map<AbsolutePath, string> {
|
|
21
|
-
const result = new Map<AbsolutePath, string>();
|
|
22
|
-
for (const [_fileName, specSchema] of uberSchema
|
|
23
|
-
.getSpecSchemaByFilenameMap()
|
|
24
|
-
.entries()) {
|
|
25
|
-
if (!(specSchema.type in this.codeGeneratorBySpecSchemaType)) {
|
|
26
|
-
throw new CodegenError({
|
|
27
|
-
whatHappened: `Could not find a code generator for a specification of type '${specSchema.type}'`,
|
|
28
|
-
unexpected: true,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
this.codeGeneratorBySpecSchemaType[specSchema.type]
|
|
32
|
-
.generate(specSchema)
|
|
33
|
-
.forEach((fileContent, filePath) => {
|
|
34
|
-
result.set(filePath, fileContent);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
this.packageCodeGenerator
|
|
38
|
-
.generate(uberSchema)
|
|
39
|
-
.forEach((fileContent, filePath) => {
|
|
40
|
-
result.set(filePath, fileContent);
|
|
41
|
-
});
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { AbsolutePath } from '../../core';
|
|
2
|
-
import {
|
|
3
|
-
CodeGenerator,
|
|
4
|
-
UberSchema,
|
|
5
|
-
createEventNameFromEventHandlerName,
|
|
6
|
-
} from '../core';
|
|
7
|
-
import { IndexTSTemplate, RNOHGeneratedPackageHTemplate } from '../templates';
|
|
8
|
-
|
|
9
|
-
export class PackageCodeGenerator implements CodeGenerator<UberSchema> {
|
|
10
|
-
constructor(
|
|
11
|
-
private cppOutputPath: AbsolutePath,
|
|
12
|
-
private etsOutputPath: AbsolutePath
|
|
13
|
-
) {}
|
|
14
|
-
|
|
15
|
-
generate(uberSchema: UberSchema): Map<AbsolutePath, string> {
|
|
16
|
-
const result = new Map<AbsolutePath, string>();
|
|
17
|
-
const generatedPackageH = new RNOHGeneratedPackageHTemplate();
|
|
18
|
-
const components_indexTS = new IndexTSTemplate();
|
|
19
|
-
const turboModules_indexTS = new IndexTSTemplate();
|
|
20
|
-
const generated_indexETS = new IndexTSTemplate();
|
|
21
|
-
generated_indexETS.addReexport({ from: './ts' });
|
|
22
|
-
|
|
23
|
-
uberSchema
|
|
24
|
-
.findAllSpecSchemasByType('NativeModule')
|
|
25
|
-
.forEach((nativeModuleSchema) => {
|
|
26
|
-
generatedPackageH.addTurboModule({
|
|
27
|
-
name: nativeModuleSchema.moduleName,
|
|
28
|
-
});
|
|
29
|
-
turboModules_indexTS.addReexport({
|
|
30
|
-
from: `./${nativeModuleSchema.moduleName}`,
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
uberSchema
|
|
34
|
-
.findAllSpecSchemasByType('Component')
|
|
35
|
-
.forEach((componentSchema) => {
|
|
36
|
-
Object.entries(componentSchema.components).forEach(
|
|
37
|
-
([name, componentShape]) => {
|
|
38
|
-
components_indexTS.addReexport({ from: `./${name}` });
|
|
39
|
-
generatedPackageH.addComponent({
|
|
40
|
-
name: name,
|
|
41
|
-
supportedEventNames: componentShape.events.map((e) => {
|
|
42
|
-
return createEventNameFromEventHandlerName(e.name);
|
|
43
|
-
}),
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
result.set(
|
|
49
|
-
this.cppOutputPath.copyWithNewSegment('RNOHGeneratedPackage.h'),
|
|
50
|
-
generatedPackageH.build()
|
|
51
|
-
);
|
|
52
|
-
result.set(
|
|
53
|
-
this.etsOutputPath.copyWithNewSegment('ts.ts'),
|
|
54
|
-
new IndexTSTemplate()
|
|
55
|
-
.addReexport({ from: './components/ts', as: 'RNC' })
|
|
56
|
-
.addReexport({ from: './turboModules/ts', as: 'TM' })
|
|
57
|
-
.build()
|
|
58
|
-
);
|
|
59
|
-
result.set(
|
|
60
|
-
this.etsOutputPath.copyWithNewSegment('components', 'ts.ts'),
|
|
61
|
-
components_indexTS.build()
|
|
62
|
-
);
|
|
63
|
-
result.set(
|
|
64
|
-
this.etsOutputPath.copyWithNewSegment('turboModules', 'ts.ts'),
|
|
65
|
-
turboModules_indexTS.build()
|
|
66
|
-
);
|
|
67
|
-
result.set(
|
|
68
|
-
this.etsOutputPath.copyWithNewSegment('index.ets'),
|
|
69
|
-
generated_indexETS.build()
|
|
70
|
-
);
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
}
|