@react-native-oh/react-native-harmony-cli 0.77.18 → 0.77.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assetResolver.js +74 -43
- package/dist/autolinking/Autolinking.js +179 -178
- package/dist/codegen/core/CodegenError.js +23 -3
- package/dist/codegen/core/EventUtils.js +3 -3
- package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
- package/dist/codegen/core/UberSchema.js +97 -55
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +41 -28
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
- package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
- package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
- package/dist/codegen/generators/UberGeneratorV1.js +24 -18
- package/dist/codegen/generators/UberGeneratorV2.js +36 -28
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
- package/dist/codegen/templates/BasePackageHTemplate.js +21 -120
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -54
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
- package/dist/codegen/templates/IndexTSTemplate.js +17 -37
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -119
- package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
- package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
- package/dist/commands/bundle-harmony.js +221 -118
- package/dist/commands/clean-harmony.js +63 -58
- package/dist/commands/codegen-harmony.js +175 -104
- package/dist/commands/codegen-lib-harmony.js +116 -76
- package/dist/commands/init-harmony.js +196 -151
- package/dist/commands/init.js +961 -537
- package/dist/commands/link-harmony.js +82 -35
- package/dist/commands/run-harmony.js +520 -352
- package/dist/commands/verify-package-harmony.js +117 -54
- package/dist/core/AbsolutePath.js +49 -33
- package/dist/core/CodegenConfig.js +22 -24
- package/dist/core/DescriptiveError.js +37 -18
- package/dist/core/FileSystem.js +18 -14
- package/dist/core/OHPackageJSON5.js +23 -17
- package/dist/core/PackageJSON.js +42 -26
- package/dist/core/ProjectDependenciesManager.js +92 -40
- package/dist/core/ValidationError.js +22 -2
- package/dist/core/fs.js +7 -10
- package/dist/index.js +1 -1
- package/dist/init/templates/AppScopeAppJSON5Template.js +8 -21
- package/dist/init/templates/AppScopeStringVarTemplate.js +8 -19
- package/dist/init/templates/EntryIndexTemplate.js +8 -56
- package/dist/init/templates/EntryStringVarTemplate.js +8 -27
- package/dist/init/templates/HvigorConfigJson5Template.js +8 -33
- package/dist/init/templates/MetroConfigTemplate.js +8 -38
- package/dist/init/templates/OhPackageJson5Template.js +8 -28
- package/dist/io/CliExecutor.js +98 -46
- package/dist/io/Logger.js +46 -40
- package/dist/io/RealFS.js +100 -43
- package/dist/io/TarGz.js +8 -11
- package/dist/io/__fixtures__.js +141 -79
- package/dist/io/fsUtils.js +12 -13
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
- package/dist/package-verifier/verify-package.js +133 -56
- package/dist/simulator/LaunchSimulator.js +395 -0
- package/dist/simulator/index.js +23 -0
- package/package.json +2 -11
- package/scripts/sync-hvigor.js +27 -0
- package/src/autolinking/Autolinking.ts +1 -1
- package/src/codegen/generators/UberGeneratorV1.ts +7 -2
- package/src/codegen/generators/UberGeneratorV2.ts +6 -1
- package/src/commands/codegen-harmony.ts +17 -7
- package/src/commands/run-harmony.ts +67 -41
- package/src/init/templates/harmony/entry/src/main/module.json5 +7 -0
- package/src/simulator/LaunchSimulator.ts +359 -0
- package/src/simulator/index.ts +8 -0
- package/dist/init/templates/harmony/AppScope/app.json5 +0 -10
- package/dist/init/templates/harmony/AppScope/resources/base/element/string.json +0 -8
- package/dist/init/templates/harmony/AppScope/resources/base/media/app_icon.png +0 -0
- package/dist/init/templates/harmony/build-profile.json5 +0 -36
- package/dist/init/templates/harmony/codelinter.json +0 -32
- package/dist/init/templates/harmony/entry/build-profile.json5 +0 -18
- package/dist/init/templates/harmony/entry/gitignore +0 -7
- package/dist/init/templates/harmony/entry/hvigorfile.ts +0 -13
- package/dist/init/templates/harmony/entry/oh-package.json5 +0 -9
- package/dist/init/templates/harmony/entry/src/main/cpp/CMakeLists.txt +0 -27
- package/dist/init/templates/harmony/entry/src/main/cpp/PackageProvider.cpp +0 -13
- package/dist/init/templates/harmony/entry/src/main/cpp/gitignore +0 -4
- package/dist/init/templates/harmony/entry/src/main/ets/PackageProvider.ets +0 -8
- package/dist/init/templates/harmony/entry/src/main/ets/codegen/gitignore +0 -2
- package/dist/init/templates/harmony/entry/src/main/ets/entryability/EntryAbility.ets +0 -11
- package/dist/init/templates/harmony/entry/src/main/ets/gitignore +0 -1
- package/dist/init/templates/harmony/entry/src/main/ets/pages/.gitkeep +0 -0
- package/dist/init/templates/harmony/entry/src/main/ets/workers/RNOHWorker.ets +0 -16
- package/dist/init/templates/harmony/entry/src/main/module.json5 +0 -58
- package/dist/init/templates/harmony/entry/src/main/resources/base/element/color.json +0 -8
- package/dist/init/templates/harmony/entry/src/main/resources/base/element/string.json +0 -16
- package/dist/init/templates/harmony/entry/src/main/resources/base/media/background.png +0 -0
- package/dist/init/templates/harmony/entry/src/main/resources/base/media/foreground.png +0 -0
- package/dist/init/templates/harmony/entry/src/main/resources/base/media/layered_image.json +0 -7
- package/dist/init/templates/harmony/entry/src/main/resources/base/media/startIcon.png +0 -0
- package/dist/init/templates/harmony/entry/src/main/resources/base/profile/main_pages.json +0 -5
- package/dist/init/templates/harmony/entry/src/main/resources/gitignore +0 -1
- package/dist/init/templates/harmony/entry/src/ohosTest/ets/test/List.test.ets +0 -2
- package/dist/init/templates/harmony/entry/src/ohosTest/module.json5 +0 -13
- package/dist/init/templates/harmony/gitignore +0 -16
- package/dist/init/templates/harmony/hvigor/hvigor-config.json5 +0 -22
- package/dist/init/templates/harmony/hvigorfile.ts +0 -7
|
@@ -1,44 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.TurboModuleInterfaceTS = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
{
|
|
11
|
-
* {{{line}}}
|
|
12
|
-
{{/codegenNoticeLines}}
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { Tag } from "{{{rnohImport}}}"
|
|
16
|
-
|
|
17
|
-
export namespace {{name}} {
|
|
18
|
-
export const NAME = '{{name}}' as const
|
|
19
|
-
|
|
20
|
-
{{#enums}}
|
|
21
|
-
export enum {{name}} {
|
|
22
|
-
{{#members}}
|
|
23
|
-
{{name}} = {{{value}}},
|
|
24
|
-
{{/members}}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
{{/enums}}
|
|
28
|
-
{{#aliases}}
|
|
29
|
-
export type {{name}} = {{{type}}}
|
|
30
|
-
|
|
31
|
-
{{/aliases}}
|
|
32
|
-
export interface Spec {
|
|
33
|
-
{{#methods}}
|
|
34
|
-
{{name}}({{{stringifiedArgs}}}): {{{returnType}}};
|
|
35
|
-
|
|
36
|
-
{{/methods}}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
`;
|
|
40
|
-
class TurboModuleInterfaceTS {
|
|
41
|
-
constructor(name, codegenNoticeLines, rnohImport) {
|
|
4
|
+
var mustache_1 = require("mustache");
|
|
5
|
+
var TEMPLATE = "\n/**\n{{#codegenNoticeLines}}\n * {{{line}}}\n{{/codegenNoticeLines}}\n */\n\nimport { Tag } from \"{{{rnohImport}}}\"\n\nexport namespace {{name}} {\n export const NAME = '{{name}}' as const\n\n {{#enums}}\n export enum {{name}} {\n {{#members}}\n {{name}} = {{{value}}},\n {{/members}}\n }\n\n {{/enums}}\n {{#aliases}}\n export type {{name}} = {{{type}}}\n \n {{/aliases}}\n export interface Spec {\n {{#methods}}\n {{name}}({{{stringifiedArgs}}}): {{{returnType}}};\n \n {{/methods}}\n }\n}\n";
|
|
6
|
+
var TurboModuleInterfaceTS = /** @class */ (function () {
|
|
7
|
+
function TurboModuleInterfaceTS(name, codegenNoticeLines, rnohImport) {
|
|
42
8
|
this.name = name;
|
|
43
9
|
this.codegenNoticeLines = codegenNoticeLines;
|
|
44
10
|
this.rnohImport = rnohImport;
|
|
@@ -46,30 +12,31 @@ class TurboModuleInterfaceTS {
|
|
|
46
12
|
this.aliases = [];
|
|
47
13
|
this.enumModels = [];
|
|
48
14
|
}
|
|
49
|
-
addAlias(alias) {
|
|
15
|
+
TurboModuleInterfaceTS.prototype.addAlias = function (alias) {
|
|
50
16
|
this.aliases.push(alias);
|
|
51
|
-
}
|
|
52
|
-
addEnum(enumModel) {
|
|
17
|
+
};
|
|
18
|
+
TurboModuleInterfaceTS.prototype.addEnum = function (enumModel) {
|
|
53
19
|
this.enumModels.push(enumModel);
|
|
54
|
-
}
|
|
55
|
-
addMethod(method) {
|
|
20
|
+
};
|
|
21
|
+
TurboModuleInterfaceTS.prototype.addMethod = function (method) {
|
|
56
22
|
this.methods.push(method);
|
|
57
|
-
}
|
|
58
|
-
build() {
|
|
23
|
+
};
|
|
24
|
+
TurboModuleInterfaceTS.prototype.build = function () {
|
|
59
25
|
return mustache_1.default.render(TEMPLATE.trimStart(), {
|
|
60
|
-
codegenNoticeLines: this.codegenNoticeLines.map((line)
|
|
61
|
-
line,
|
|
62
|
-
})),
|
|
26
|
+
codegenNoticeLines: this.codegenNoticeLines.map(function (line) { return ({
|
|
27
|
+
line: line,
|
|
28
|
+
}); }),
|
|
63
29
|
name: this.name,
|
|
64
30
|
aliases: this.aliases,
|
|
65
31
|
enums: this.enumModels,
|
|
66
32
|
rnohImport: this.rnohImport,
|
|
67
|
-
methods: this.methods.map((method)
|
|
33
|
+
methods: this.methods.map(function (method) { return ({
|
|
68
34
|
name: method.name,
|
|
69
35
|
stringifiedArgs: method.stringifiedArgs,
|
|
70
36
|
returnType: method.returnType,
|
|
71
|
-
})),
|
|
37
|
+
}); }),
|
|
72
38
|
});
|
|
73
|
-
}
|
|
74
|
-
|
|
39
|
+
};
|
|
40
|
+
return TurboModuleInterfaceTS;
|
|
41
|
+
}());
|
|
75
42
|
exports.TurboModuleInterfaceTS = TurboModuleInterfaceTS;
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,30 +19,63 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
19
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
20
|
});
|
|
10
21
|
};
|
|
11
|
-
var
|
|
12
|
-
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
13
57
|
};
|
|
14
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
59
|
exports.commandBundleHarmony = void 0;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
60
|
+
var node_fs_1 = require("node:fs");
|
|
61
|
+
var os_1 = require("os");
|
|
62
|
+
var fs_extra_1 = require("fs-extra");
|
|
63
|
+
var metro_1 = require("metro");
|
|
64
|
+
var Server_1 = require("metro/src/Server");
|
|
65
|
+
var path_1 = require("path");
|
|
66
|
+
var assetResolver_1 = require("../assetResolver");
|
|
67
|
+
var child_process_1 = require("child_process");
|
|
68
|
+
var io_1 = require("../io");
|
|
69
|
+
var core_1 = require("../core");
|
|
70
|
+
var node_crypto_1 = require("node:crypto");
|
|
71
|
+
var HERMESC_BIN_PATH = {
|
|
28
72
|
darwin: path_1.default.normalize('osx-bin/hermesc'),
|
|
29
73
|
linux: path_1.default.normalize('linux64-bin/hermesc'),
|
|
30
74
|
win32: path_1.default.normalize('win64-bin/hermesc.exe'),
|
|
31
75
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
76
|
+
var HERMESC_PATH_PREFIX = path_1.default.normalize('./node_modules/react-native/sdks/hermesc/');
|
|
77
|
+
var HARMONY_RESOURCE_PATH = path_1.default.normalize('./harmony/entry/src/main/resources/rawfile');
|
|
78
|
+
var ASSETS_DEFAULT_DEST_PATH = path_1.default.normalize('./harmony/entry/src/main/resources/rawfile/assets');
|
|
35
79
|
exports.commandBundleHarmony = {
|
|
36
80
|
name: 'bundle-harmony',
|
|
37
81
|
description: 'Creates JS bundle, creates a special cpp header containing the JS code, copies assets directory to the project.',
|
|
@@ -39,14 +83,14 @@ exports.commandBundleHarmony = {
|
|
|
39
83
|
{
|
|
40
84
|
name: '--dev [boolean]',
|
|
41
85
|
description: 'If false, warnings are disabled and the bundle is minified',
|
|
42
|
-
parse: (val)
|
|
86
|
+
parse: function (val) { return val !== 'false'; },
|
|
43
87
|
default: true,
|
|
44
88
|
},
|
|
45
89
|
{
|
|
46
90
|
name: '--entry-file <path>',
|
|
47
91
|
description: 'Path to the root JS file, either absolute or relative to JS root',
|
|
48
92
|
default: 'index.js',
|
|
49
|
-
parse: (val)
|
|
93
|
+
parse: function (val) { return path_1.default.normalize(val); },
|
|
50
94
|
},
|
|
51
95
|
{
|
|
52
96
|
name: '--reset-cache',
|
|
@@ -56,20 +100,20 @@ exports.commandBundleHarmony = {
|
|
|
56
100
|
{
|
|
57
101
|
name: '--config <path>',
|
|
58
102
|
description: 'Path to the Metro configuration file',
|
|
59
|
-
parse: (val)
|
|
103
|
+
parse: function (val) { return path_1.default.normalize(val); },
|
|
60
104
|
},
|
|
61
105
|
{
|
|
62
106
|
name: '--bundle-output <path>',
|
|
63
|
-
description:
|
|
64
|
-
parse: (val)
|
|
107
|
+
description: "File path where to store the resulting bundle (default: \"".concat(HARMONY_RESOURCE_PATH).concat(path_1.default.sep, "bundle.harmony.js\")"),
|
|
108
|
+
parse: function (val) { return path_1.default.normalize(val); },
|
|
65
109
|
},
|
|
66
110
|
{
|
|
67
111
|
name: '--js-engine <string>',
|
|
68
112
|
description: 'JavaScript engine used to run the bundle. Supported engines: "hermes" and "any" (default: "any"). Setting this option to "hermes" will generate a HBC bundle instead of a JS bundle.',
|
|
69
113
|
default: 'any',
|
|
70
|
-
parse: (val)
|
|
114
|
+
parse: function (val) {
|
|
71
115
|
if (val !== 'any' && val !== 'hermes') {
|
|
72
|
-
throw new Error(
|
|
116
|
+
throw new Error("Only \"any\" and \"hermes\" are supported as JavaScript engines, but \"".concat(val, "\" was provided"));
|
|
73
117
|
}
|
|
74
118
|
return val;
|
|
75
119
|
},
|
|
@@ -78,140 +122,199 @@ exports.commandBundleHarmony = {
|
|
|
78
122
|
name: '--assets-dest <path>',
|
|
79
123
|
description: 'Directory name where to store assets referenced in the bundle',
|
|
80
124
|
default: ASSETS_DEFAULT_DEST_PATH,
|
|
81
|
-
parse: (val)
|
|
125
|
+
parse: function (val) { return path_1.default.normalize(val); },
|
|
82
126
|
},
|
|
83
127
|
{
|
|
84
128
|
name: '--sourcemap-output <path>',
|
|
85
129
|
description: 'File name where to store the resulting source map, ex. /tmp/groups.map',
|
|
86
|
-
parse: (val)
|
|
130
|
+
parse: function (val) { return path_1.default.normalize(val); },
|
|
87
131
|
},
|
|
88
132
|
{
|
|
89
133
|
name: '--minify [boolean]',
|
|
90
134
|
description: 'Allows overriding whether bundle is minified',
|
|
91
|
-
parse: (val)
|
|
135
|
+
parse: function (val) { return val !== 'false'; },
|
|
92
136
|
},
|
|
93
137
|
{
|
|
94
138
|
name: '--hermesc-dir <path>',
|
|
95
139
|
description: 'Path to hermesc directory. Relevant when --js-engine set to "hermes".',
|
|
96
140
|
default: HERMESC_PATH_PREFIX,
|
|
97
|
-
parse: (val)
|
|
141
|
+
parse: function (val) { return path_1.default.normalize(val); },
|
|
98
142
|
},
|
|
99
143
|
{
|
|
100
144
|
name: '--hermesc-options <string...>',
|
|
101
145
|
description: 'Additional options to pass to hermesc when generating HBC bundle. Example: --hermesc-options O g reuse-prop-cache. Relevant when --js-engine set to "hermes".',
|
|
102
|
-
parse: (val, prev)
|
|
146
|
+
parse: function (val, prev) { return (prev ? __spreadArray(__spreadArray([], prev, true), [val], false) : [val]); },
|
|
103
147
|
},
|
|
104
148
|
],
|
|
105
|
-
func: (argv, config, args)
|
|
149
|
+
func: function (argv, config, args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
150
|
+
var logger, defaultBundleName, bundleOutput, shouldGenerateHbcBundle, assetsDest, buildOptions, metroConfig, bundle, assets, err_1;
|
|
106
151
|
var _a;
|
|
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
|
-
|
|
152
|
+
return __generator(this, function (_b) {
|
|
153
|
+
switch (_b.label) {
|
|
154
|
+
case 0:
|
|
155
|
+
logger = new io_1.Logger();
|
|
156
|
+
_b.label = 1;
|
|
157
|
+
case 1:
|
|
158
|
+
_b.trys.push([1, 12, , 13]);
|
|
159
|
+
defaultBundleName = args.jsEngine === 'hermes' ? 'hermes_bundle.hbc' : 'bundle.harmony.js';
|
|
160
|
+
bundleOutput = (_a = args.bundleOutput) !== null && _a !== void 0 ? _a : "".concat(HARMONY_RESOURCE_PATH).concat(path_1.default.sep).concat(defaultBundleName);
|
|
161
|
+
shouldGenerateHbcBundle = bundleOutput
|
|
162
|
+
.toLowerCase()
|
|
163
|
+
.endsWith('hbc');
|
|
164
|
+
return [4 /*yield*/, fs_extra_1.default.ensureDir(path_1.default.dirname(bundleOutput))];
|
|
165
|
+
case 2:
|
|
166
|
+
_b.sent();
|
|
167
|
+
assetsDest = args.assetsDest;
|
|
168
|
+
return [4 /*yield*/, fs_extra_1.default.ensureDir(assetsDest)];
|
|
169
|
+
case 3:
|
|
170
|
+
_b.sent();
|
|
171
|
+
buildOptions = {
|
|
172
|
+
entry: args.entryFile,
|
|
173
|
+
platform: 'harmony',
|
|
174
|
+
minify: args.minify !== undefined ? args.minify : !args.dev,
|
|
175
|
+
dev: args.dev,
|
|
176
|
+
sourceMap: args.sourcemapOutput,
|
|
177
|
+
sourceMapUrl: args.sourcemapOutput,
|
|
178
|
+
};
|
|
179
|
+
return [4 /*yield*/, loadMetroConfig({
|
|
180
|
+
config: args.config,
|
|
181
|
+
resetCache: args.resetCache,
|
|
182
|
+
})];
|
|
183
|
+
case 4:
|
|
184
|
+
metroConfig = _b.sent();
|
|
185
|
+
return [4 /*yield*/, createBundle(metroConfig, buildOptions)];
|
|
186
|
+
case 5:
|
|
187
|
+
bundle = _b.sent();
|
|
188
|
+
return [4 /*yield*/, retrieveAssetsData(metroConfig, buildOptions)];
|
|
189
|
+
case 6:
|
|
190
|
+
assets = _b.sent();
|
|
191
|
+
if (!shouldGenerateHbcBundle) return [3 /*break*/, 8];
|
|
192
|
+
return [4 /*yield*/, saveHbcBundle(logger, bundle.code, bundleOutput, args.hermescDir, args.hermescOptions)];
|
|
193
|
+
case 7:
|
|
194
|
+
_b.sent();
|
|
195
|
+
return [3 /*break*/, 10];
|
|
196
|
+
case 8: return [4 /*yield*/, saveJSBundle(logger, bundle, bundleOutput)];
|
|
197
|
+
case 9:
|
|
198
|
+
_b.sent();
|
|
199
|
+
_b.label = 10;
|
|
200
|
+
case 10:
|
|
201
|
+
maybeSaveSourceMap(logger, bundle, args.sourcemapOutput);
|
|
202
|
+
return [4 /*yield*/, (0, assetResolver_1.copyAssets)(logger, assets, assetsDest)];
|
|
203
|
+
case 11:
|
|
204
|
+
_b.sent();
|
|
205
|
+
return [3 /*break*/, 13];
|
|
206
|
+
case 12:
|
|
207
|
+
err_1 = _b.sent();
|
|
208
|
+
if (err_1 instanceof core_1.DescriptiveError) {
|
|
209
|
+
logger.descriptiveError(err_1);
|
|
210
|
+
return [2 /*return*/];
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
throw err_1;
|
|
214
|
+
}
|
|
215
|
+
return [3 /*break*/, 13];
|
|
216
|
+
case 13: return [2 /*return*/];
|
|
133
217
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
maybeSaveSourceMap(logger, bundle, args.sourcemapOutput);
|
|
138
|
-
yield (0, assetResolver_1.copyAssets)(logger, assets, assetsDest);
|
|
139
|
-
}
|
|
140
|
-
catch (err) {
|
|
141
|
-
if (err instanceof core_1.DescriptiveError) {
|
|
142
|
-
logger.descriptiveError(err);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
throw err;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}),
|
|
218
|
+
});
|
|
219
|
+
}); },
|
|
150
220
|
};
|
|
151
221
|
function loadMetroConfig(options) {
|
|
152
|
-
return __awaiter(this, void 0, void 0, function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
222
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
223
|
+
return __generator(this, function (_a) {
|
|
224
|
+
switch (_a.label) {
|
|
225
|
+
case 0:
|
|
226
|
+
if (!options.config) {
|
|
227
|
+
delete options.config;
|
|
228
|
+
}
|
|
229
|
+
return [4 /*yield*/, metro_1.default.loadConfig(options)];
|
|
230
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
231
|
+
}
|
|
232
|
+
});
|
|
157
233
|
});
|
|
158
234
|
}
|
|
159
235
|
function createBundle(metroConfig, buildOptions) {
|
|
160
|
-
return __awaiter(this, void 0, void 0, function
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
236
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
237
|
+
return __generator(this, function (_a) {
|
|
238
|
+
switch (_a.label) {
|
|
239
|
+
case 0: return [4 /*yield*/, metro_1.default.runBuild(metroConfig, buildOptions)];
|
|
240
|
+
case 1:
|
|
241
|
+
// casting needed as Metro.runBuild returns Promise<{code: string, map: string}>
|
|
242
|
+
// despite being typed as Promise<void>
|
|
243
|
+
return [2 /*return*/, (_a.sent())];
|
|
244
|
+
}
|
|
245
|
+
});
|
|
164
246
|
});
|
|
165
247
|
}
|
|
166
248
|
function saveHbcBundle(logger, bundleCode, bundleOutput, hermescPath, hermescOptions) {
|
|
167
|
-
return __awaiter(this, void 0, void 0, function
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
249
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
250
|
+
var resolvedHermescPath, tmpBundlePath, hbcFilePath, hermescOptionsString;
|
|
251
|
+
return __generator(this, function (_a) {
|
|
252
|
+
switch (_a.label) {
|
|
253
|
+
case 0:
|
|
254
|
+
if (process.platform !== 'darwin' &&
|
|
255
|
+
process.platform !== 'linux' &&
|
|
256
|
+
process.platform !== 'win32') {
|
|
257
|
+
throw new Error("Unsupported platform ".concat(process.platform, " (\u2299\uFE3F\u2299)"));
|
|
258
|
+
}
|
|
259
|
+
resolvedHermescPath = path_1.default.resolve(hermescPath, HERMESC_BIN_PATH[process.platform]);
|
|
260
|
+
if (!node_fs_1.default.existsSync(resolvedHermescPath)) {
|
|
261
|
+
throw new core_1.DescriptiveError({
|
|
262
|
+
whatHappened: "Couldn't find hermesc at ".concat(resolvedHermescPath),
|
|
263
|
+
whatCanUserDo: [
|
|
264
|
+
'Find hermesc dir and provide it by using --hermesc-dir argument. hermesc dir should be in react-native package.',
|
|
265
|
+
],
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
tmpBundlePath = "".concat(os_1.default.tmpdir()).concat(path_1.default.sep, "b-").concat((0, node_crypto_1.randomUUID)(), ".harmony.js");
|
|
269
|
+
return [4 /*yield*/, fs_extra_1.default.writeFile(tmpBundlePath, bundleCode)];
|
|
270
|
+
case 1:
|
|
271
|
+
_a.sent();
|
|
272
|
+
hbcFilePath = bundleOutput.endsWith('.hbc')
|
|
273
|
+
? bundleOutput
|
|
274
|
+
: path_1.default.join(path_1.default.dirname(bundleOutput), 'hermes_bundle.hbc');
|
|
275
|
+
hermescOptionsString = (hermescOptions === null || hermescOptions === void 0 ? void 0 : hermescOptions.map(function (e) { return "-".concat(e); }).join(' ')) || '';
|
|
276
|
+
(0, child_process_1.execSync)("".concat(resolvedHermescPath, " ").concat(hermescOptionsString, " --emit-binary -out ").concat(hbcFilePath, " ").concat(tmpBundlePath), {
|
|
277
|
+
stdio: 'inherit',
|
|
278
|
+
});
|
|
279
|
+
node_fs_1.default.unlinkSync(tmpBundlePath);
|
|
280
|
+
logger.info(function (s) { return "Created ".concat(hbcFilePath); });
|
|
281
|
+
return [2 /*return*/];
|
|
282
|
+
}
|
|
190
283
|
});
|
|
191
|
-
node_fs_1.default.unlinkSync(tmpBundlePath);
|
|
192
|
-
logger.info((s) => `Created ${hbcFilePath}`);
|
|
193
284
|
});
|
|
194
285
|
}
|
|
195
286
|
function saveJSBundle(logger, bundle, bundleOutput) {
|
|
196
|
-
return __awaiter(this, void 0, void 0, function
|
|
197
|
-
|
|
198
|
-
|
|
287
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
+
return __generator(this, function (_a) {
|
|
289
|
+
node_fs_1.default.writeFileSync(bundleOutput, bundle.code);
|
|
290
|
+
logger.info(function (s) { return "Created ".concat(bundleOutput); });
|
|
291
|
+
return [2 /*return*/];
|
|
292
|
+
});
|
|
199
293
|
});
|
|
200
294
|
}
|
|
201
295
|
function maybeSaveSourceMap(logger, bundle, sourceMapOutput) {
|
|
202
296
|
if (sourceMapOutput) {
|
|
203
297
|
node_fs_1.default.writeFileSync(sourceMapOutput, bundle.map);
|
|
204
|
-
logger.info((s)
|
|
298
|
+
logger.info(function (s) { return "Created ".concat(sourceMapOutput); });
|
|
205
299
|
}
|
|
206
300
|
}
|
|
207
301
|
function retrieveAssetsData(metroConfig, buildOptions) {
|
|
208
|
-
return __awaiter(this, void 0, void 0, function
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
302
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
303
|
+
var metroServer;
|
|
304
|
+
return __generator(this, function (_a) {
|
|
305
|
+
switch (_a.label) {
|
|
306
|
+
case 0:
|
|
307
|
+
metroServer = new Server_1.default(metroConfig);
|
|
308
|
+
_a.label = 1;
|
|
309
|
+
case 1:
|
|
310
|
+
_a.trys.push([1, , 3, 4]);
|
|
311
|
+
return [4 /*yield*/, metroServer.getAssets(__assign(__assign(__assign({}, Server_1.default.DEFAULT_BUNDLE_OPTIONS), buildOptions), { entryFile: buildOptions.entry, bundleType: 'todo' }))];
|
|
312
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
313
|
+
case 3:
|
|
314
|
+
metroServer.end();
|
|
315
|
+
return [7 /*endfinally*/];
|
|
316
|
+
case 4: return [2 /*return*/];
|
|
317
|
+
}
|
|
318
|
+
});
|
|
216
319
|
});
|
|
217
320
|
}
|