@react-native-oh/react-native-harmony-cli 0.0.36 → 0.0.40
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/README.md +11 -11
- package/dist/assetResolver.js +74 -43
- package/dist/autolinking/Autolinking.js +183 -179
- 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 +96 -57
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +42 -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 -109
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -53
- 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 -108
- 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 +138 -53
- package/dist/commands/codegen-harmony.js +175 -104
- package/dist/commands/codegen-lib-harmony.js +116 -76
- package/dist/commands/create-metro-host-constants.js +47 -18
- package/dist/commands/init.js +961 -537
- package/dist/commands/link-harmony.js +71 -33
- package/dist/commands/pack-harmony.js +108 -47
- package/dist/commands/run-harmony.js +520 -352
- package/dist/commands/unpack-harmony.js +198 -105
- package/dist/commands/verify-package-harmony.js +108 -54
- package/dist/core/AbsolutePath.js +47 -31
- 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 +96 -46
- package/dist/core/ValidationError.js +22 -2
- package/dist/core/fs.js +6 -9
- package/dist/index.js +1 -1
- package/dist/io/CliExecutor.js +98 -46
- package/dist/io/Logger.js +46 -40
- package/dist/io/RealFS.js +88 -35
- 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 +132 -55
- package/dist/simulator/LaunchSimulator.js +395 -0
- package/dist/simulator/index.js +23 -0
- package/jest.config.js +12 -12
- package/package.json +78 -70
- package/react-native.config.js +17 -17
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
- package/.prettierrc +0 -6
- package/src/assetResolver.ts +0 -134
- package/src/autolinking/Autolinking.test.ts +0 -483
- package/src/autolinking/Autolinking.ts +0 -382
- package/src/autolinking/index.ts +0 -8
- package/src/codegen/core/CodeGenerator.ts +0 -16
- package/src/codegen/core/CodegenError.ts +0 -10
- package/src/codegen/core/EventUtils.ts +0 -23
- package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
- package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
- package/src/codegen/core/UberSchema.ts +0 -152
- package/src/codegen/core/index.ts +0 -12
- package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -120
- package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
- package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
- package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
- package/src/codegen/generators/UberGeneratorV1.ts +0 -75
- package/src/codegen/generators/UberGeneratorV2.ts +0 -114
- package/src/codegen/generators/index.ts +0 -15
- package/src/codegen/index.ts +0 -9
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
- package/src/codegen/templates/BasePackageHTemplate.ts +0 -147
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
- package/src/codegen/templates/IndexTSTemplate.ts +0 -62
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -138
- package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
- package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
- package/src/codegen/templates/index.ts +0 -16
- package/src/commands/bundle-harmony.ts +0 -134
- package/src/commands/codegen-harmony.ts +0 -297
- package/src/commands/codegen-lib-harmony.ts +0 -389
- package/src/commands/create-metro-host-constants.ts +0 -55
- package/src/commands/index.ts +0 -16
- package/src/commands/init.ts +0 -755
- package/src/commands/link-harmony.ts +0 -102
- package/src/commands/pack-harmony.ts +0 -128
- package/src/commands/run-harmony.ts +0 -478
- package/src/commands/types.ts +0 -21
- package/src/commands/unpack-harmony.ts +0 -238
- package/src/commands/verify-package-harmony.ts +0 -113
- package/src/core/AbsolutePath.ts +0 -66
- package/src/core/CodegenConfig.ts +0 -67
- package/src/core/DescriptiveError.ts +0 -68
- package/src/core/FileSystem.ts +0 -57
- package/src/core/OHPackageJSON5.ts +0 -30
- package/src/core/PackageJSON.ts +0 -104
- package/src/core/ProjectDependenciesManager.ts +0 -103
- package/src/core/ValidationError.ts +0 -8
- package/src/core/ValueObject.ts +0 -9
- package/src/core/fs.ts +0 -38
- package/src/core/index.ts +0 -17
- package/src/index.ts +0 -33
- package/src/io/CliExecutor.ts +0 -69
- package/src/io/Logger.ts +0 -112
- package/src/io/RealFS.ts +0 -62
- package/src/io/TarGz.ts +0 -33
- package/src/io/__fixtures__.ts +0 -139
- package/src/io/fsUtils.ts +0 -44
- package/src/io/index.ts +0 -11
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
- package/src/package-verifier/checks/index.ts +0 -11
- package/src/package-verifier/index.ts +0 -9
- package/src/package-verifier/types.ts +0 -19
- package/src/package-verifier/verify-package.ts +0 -123
package/dist/commands/init.js
CHANGED
|
@@ -6,6 +6,17 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
+
var __assign = (this && this.__assign) || function () {
|
|
10
|
+
__assign = Object.assign || function(t) {
|
|
11
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
12
|
+
s = arguments[i];
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
}
|
|
16
|
+
return t;
|
|
17
|
+
};
|
|
18
|
+
return __assign.apply(this, arguments);
|
|
19
|
+
};
|
|
9
20
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
10
21
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
22
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -15,101 +26,167 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
15
26
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
16
27
|
});
|
|
17
28
|
};
|
|
18
|
-
var
|
|
19
|
-
|
|
29
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
30
|
+
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);
|
|
31
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
32
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
33
|
+
function step(op) {
|
|
34
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
35
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
36
|
+
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;
|
|
37
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
38
|
+
switch (op[0]) {
|
|
39
|
+
case 0: case 1: t = op; break;
|
|
40
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
41
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
42
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
43
|
+
default:
|
|
44
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
45
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
46
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
47
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
48
|
+
if (t[2]) _.ops.pop();
|
|
49
|
+
_.trys.pop(); continue;
|
|
50
|
+
}
|
|
51
|
+
op = body.call(thisArg, _);
|
|
52
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
53
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
57
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
58
|
+
if (ar || !(i in from)) {
|
|
59
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
60
|
+
ar[i] = from[i];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
64
|
};
|
|
21
65
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
66
|
exports.rnohInit = rnohInit;
|
|
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
|
-
|
|
67
|
+
var node_path_1 = require("node:path");
|
|
68
|
+
var node_os_1 = require("node:os");
|
|
69
|
+
var commander_1 = require("commander");
|
|
70
|
+
var inquirer_1 = require("inquirer");
|
|
71
|
+
var chalk_1 = require("chalk");
|
|
72
|
+
var fs_extra_1 = require("fs-extra");
|
|
73
|
+
var json5_1 = require("json5");
|
|
74
|
+
var cli_tools_1 = require("@react-native-community/cli-tools");
|
|
75
|
+
var CliExecutor_1 = require("../io/CliExecutor");
|
|
76
|
+
var AbsolutePath_1 = require("../core/AbsolutePath");
|
|
77
|
+
var DescriptiveError_1 = require("../core/DescriptiveError");
|
|
78
|
+
var VALID_APP_NAME_REG = /^[A-Za-z][A-Za-z0-9_]*[A-Za-z0-9]$/;
|
|
79
|
+
var DEFAULT_PACKAGE_PREFIX = 'com.example.';
|
|
80
|
+
var HARMONY_DIR = 'harmony';
|
|
81
|
+
var JSON5_EXT = '.json5';
|
|
82
|
+
var DEFAULT_ENCODING = 'utf8';
|
|
83
|
+
var MODULE_DESC = 'module_desc';
|
|
84
|
+
var ENTRY_ABILITY_DESC = 'EntryAbility_desc';
|
|
85
|
+
var ENTRY_ABILITY_LABEL = 'EntryAbility_label';
|
|
86
|
+
var REACT_NATIVE = 'react-native';
|
|
87
|
+
var NODE_MODULES = 'node_modules';
|
|
88
|
+
var STRING_TYPE = 'string';
|
|
89
|
+
var PROJECT_NAME_INDEX = 0;
|
|
90
|
+
var JSON_INDENTATION_LENGTH = 2;
|
|
91
|
+
var GIT_EXE = 'git';
|
|
92
|
+
var NODE_EXE = 'node';
|
|
93
|
+
var NPM_EXE = 'npm';
|
|
94
|
+
var APP_JSON = 'app.json';
|
|
95
|
+
var APP_JSON5 = 'app.json5';
|
|
96
|
+
var STRING_JSON = 'string.json';
|
|
97
|
+
var PACKAGE_JSON = 'package.json';
|
|
98
|
+
var TEMPLATE_CONFIG_JS = 'template.config.js';
|
|
99
|
+
var METRO_CONFIG_JS = 'metro.config.js';
|
|
100
|
+
var DEFAULT_TEMPLATE_PKG = '@react-native-oh/template';
|
|
101
|
+
var REACT_NATIVE_OH_REACT_NATIVE_HARMONY = '@react-native-oh/react-native-harmony';
|
|
102
|
+
var REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI = '@react-native-oh/react-native-harmony-cli';
|
|
59
103
|
/**
|
|
60
104
|
* Helper class for file operations (JSON and text file updates).
|
|
61
105
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
if (!(yield fs_extra_1.default.pathExists(filePath))) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
const content = yield fs_extra_1.default.readFile(filePath, DEFAULT_ENCODING);
|
|
70
|
-
const data = json5_1.default.parse(content);
|
|
71
|
-
const updatedData = updateFn(data);
|
|
72
|
-
const outputContent = filePath.endsWith(JSON5_EXT)
|
|
73
|
-
? json5_1.default.stringify(updatedData, null, JSON_INDENTATION_LENGTH)
|
|
74
|
-
: JSON.stringify(updatedData, null, JSON_INDENTATION_LENGTH);
|
|
75
|
-
yield fs_extra_1.default.writeFile(filePath, outputContent);
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
throw new DescriptiveError_1.DescriptiveError({
|
|
79
|
-
whatHappened: errorMessage,
|
|
80
|
-
whatCanUserDo: ['Please check if the file format is correct.'],
|
|
81
|
-
extraData: e,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
});
|
|
106
|
+
var FileOperationHelper = /** @class */ (function () {
|
|
107
|
+
function FileOperationHelper() {
|
|
85
108
|
}
|
|
86
|
-
|
|
87
|
-
return __awaiter(this, void 0, void 0, function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
FileOperationHelper.updateJsonFile = function (filePath, updateFn, errorMessage) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
+
var content, data, updatedData, outputContent, e_1;
|
|
112
|
+
return __generator(this, function (_a) {
|
|
113
|
+
switch (_a.label) {
|
|
114
|
+
case 0: return [4 /*yield*/, fs_extra_1.default.pathExists(filePath)];
|
|
115
|
+
case 1:
|
|
116
|
+
if (!(_a.sent())) {
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
_a.label = 2;
|
|
120
|
+
case 2:
|
|
121
|
+
_a.trys.push([2, 5, , 6]);
|
|
122
|
+
return [4 /*yield*/, fs_extra_1.default.readFile(filePath, DEFAULT_ENCODING)];
|
|
123
|
+
case 3:
|
|
124
|
+
content = _a.sent();
|
|
125
|
+
data = json5_1.default.parse(content);
|
|
126
|
+
updatedData = updateFn(data);
|
|
127
|
+
outputContent = filePath.endsWith(JSON5_EXT)
|
|
128
|
+
? json5_1.default.stringify(updatedData, null, JSON_INDENTATION_LENGTH)
|
|
129
|
+
: JSON.stringify(updatedData, null, JSON_INDENTATION_LENGTH);
|
|
130
|
+
return [4 /*yield*/, fs_extra_1.default.writeFile(filePath, outputContent)];
|
|
131
|
+
case 4:
|
|
132
|
+
_a.sent();
|
|
133
|
+
return [3 /*break*/, 6];
|
|
134
|
+
case 5:
|
|
135
|
+
e_1 = _a.sent();
|
|
136
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
137
|
+
whatHappened: errorMessage,
|
|
138
|
+
whatCanUserDo: ['Please check if the file format is correct.'],
|
|
139
|
+
extraData: e_1,
|
|
140
|
+
});
|
|
141
|
+
case 6: return [2 /*return*/];
|
|
96
142
|
}
|
|
97
|
-
}
|
|
98
|
-
catch (e) {
|
|
99
|
-
throw new DescriptiveError_1.DescriptiveError({
|
|
100
|
-
whatHappened: `Failed to update ${node_path_1.default.basename(filePath)}.`,
|
|
101
|
-
whatCanUserDo: ['Please check if the file is readable and writable.'],
|
|
102
|
-
extraData: e,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
143
|
+
});
|
|
105
144
|
});
|
|
106
|
-
}
|
|
107
|
-
|
|
145
|
+
};
|
|
146
|
+
FileOperationHelper.updateTextFile = function (filePath, placeholder, replacement) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
+
var content, e_2;
|
|
149
|
+
return __generator(this, function (_a) {
|
|
150
|
+
switch (_a.label) {
|
|
151
|
+
case 0: return [4 /*yield*/, fs_extra_1.default.pathExists(filePath)];
|
|
152
|
+
case 1:
|
|
153
|
+
if (!(_a.sent())) {
|
|
154
|
+
return [2 /*return*/];
|
|
155
|
+
}
|
|
156
|
+
_a.label = 2;
|
|
157
|
+
case 2:
|
|
158
|
+
_a.trys.push([2, 6, , 7]);
|
|
159
|
+
return [4 /*yield*/, fs_extra_1.default.readFile(filePath, DEFAULT_ENCODING)];
|
|
160
|
+
case 3:
|
|
161
|
+
content = _a.sent();
|
|
162
|
+
if (!content.includes(placeholder)) return [3 /*break*/, 5];
|
|
163
|
+
content = content.replace(new RegExp(placeholder, 'g'), replacement);
|
|
164
|
+
return [4 /*yield*/, fs_extra_1.default.writeFile(filePath, content, DEFAULT_ENCODING)];
|
|
165
|
+
case 4:
|
|
166
|
+
_a.sent();
|
|
167
|
+
_a.label = 5;
|
|
168
|
+
case 5: return [3 /*break*/, 7];
|
|
169
|
+
case 6:
|
|
170
|
+
e_2 = _a.sent();
|
|
171
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
172
|
+
whatHappened: "Failed to update ".concat(node_path_1.default.basename(filePath), "."),
|
|
173
|
+
whatCanUserDo: ['Please check if the file is readable and writable.'],
|
|
174
|
+
extraData: e_2,
|
|
175
|
+
});
|
|
176
|
+
case 7: return [2 /*return*/];
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
return FileOperationHelper;
|
|
182
|
+
}());
|
|
108
183
|
/**
|
|
109
184
|
* Helper class for validation operations.
|
|
110
185
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
186
|
+
var ValidationHelper = /** @class */ (function () {
|
|
187
|
+
function ValidationHelper() {
|
|
188
|
+
}
|
|
189
|
+
ValidationHelper.validateProjectName = function (projectName) {
|
|
113
190
|
if (!projectName.trim()) {
|
|
114
191
|
return 'Project name cannot be empty.';
|
|
115
192
|
}
|
|
@@ -117,60 +194,91 @@ class ValidationHelper {
|
|
|
117
194
|
return 'Project name must start with a letter and can only contain letters, numbers, _.';
|
|
118
195
|
}
|
|
119
196
|
return true;
|
|
120
|
-
}
|
|
121
|
-
|
|
197
|
+
};
|
|
198
|
+
ValidationHelper.validateOptions = function (options) {
|
|
122
199
|
if (options.version && options.template) {
|
|
123
200
|
throw new DescriptiveError_1.DescriptiveError({
|
|
124
201
|
whatHappened: 'Cannot specify both --version and --template.',
|
|
125
202
|
whatCanUserDo: ['Please specify only one of --version or --template.'],
|
|
126
203
|
});
|
|
127
204
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return __awaiter(this, void 0, void 0, function
|
|
131
|
-
var _a;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
205
|
+
};
|
|
206
|
+
ValidationHelper.validateReactNativeVersion = function (destDir) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
208
|
+
var packageJsonPath, packageJson, _a, _b, reactNativeVersion;
|
|
209
|
+
var _c;
|
|
210
|
+
return __generator(this, function (_d) {
|
|
211
|
+
switch (_d.label) {
|
|
212
|
+
case 0:
|
|
213
|
+
packageJsonPath = node_path_1.default.join(destDir, PACKAGE_JSON);
|
|
214
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(packageJsonPath)];
|
|
215
|
+
case 1:
|
|
216
|
+
if (!_d.sent()) return [3 /*break*/, 3];
|
|
217
|
+
_b = (_a = JSON).parse;
|
|
218
|
+
return [4 /*yield*/, fs_extra_1.default.readFile(packageJsonPath, DEFAULT_ENCODING)];
|
|
219
|
+
case 2:
|
|
220
|
+
packageJson = _b.apply(_a, [_d.sent()]);
|
|
221
|
+
reactNativeVersion = (_c = packageJson.dependencies) === null || _c === void 0 ? void 0 : _c[REACT_NATIVE];
|
|
222
|
+
if (!reactNativeVersion || !/^\^?0\.(72)|(77)\./.test(reactNativeVersion)) {
|
|
223
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
224
|
+
whatHappened: "Unsupported RN community template. Please ensure react-native version starts with \"0.77.\".",
|
|
225
|
+
whatCanUserDo: ['Please use a template with react-native version 0.77.x.'],
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return [2 /*return*/, reactNativeVersion];
|
|
229
|
+
case 3: return [2 /*return*/, "0.77"];
|
|
141
230
|
}
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
return "0.77";
|
|
231
|
+
});
|
|
145
232
|
});
|
|
146
|
-
}
|
|
147
|
-
|
|
233
|
+
};
|
|
234
|
+
return ValidationHelper;
|
|
235
|
+
}());
|
|
148
236
|
/**
|
|
149
237
|
* Main entry point for the RNOH init command.
|
|
150
238
|
* Initializes a new RNOH project with proper template and configuration.
|
|
151
239
|
*/
|
|
152
240
|
function rnohInit() {
|
|
153
|
-
return __awaiter(this, void 0, void 0, function
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
241
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
242
|
+
var program;
|
|
243
|
+
var _this = this;
|
|
244
|
+
return __generator(this, function (_a) {
|
|
245
|
+
switch (_a.label) {
|
|
246
|
+
case 0:
|
|
247
|
+
program = new commander_1.Command();
|
|
248
|
+
program
|
|
249
|
+
.command('init [projectName]')
|
|
250
|
+
.description('Initialize a new RNOH project')
|
|
251
|
+
.option('-v, --version <version>', 'Harmonized RN version')
|
|
252
|
+
.option('-t, --template <template>', 'Template npm package')
|
|
253
|
+
.action(function (projectName, options) { return __awaiter(_this, void 0, void 0, function () {
|
|
254
|
+
var err_1;
|
|
255
|
+
return __generator(this, function (_a) {
|
|
256
|
+
switch (_a.label) {
|
|
257
|
+
case 0:
|
|
258
|
+
_a.trys.push([0, 2, , 3]);
|
|
259
|
+
return [4 /*yield*/, runInit(projectName, options)];
|
|
260
|
+
case 1:
|
|
261
|
+
_a.sent();
|
|
262
|
+
return [3 /*break*/, 3];
|
|
263
|
+
case 2:
|
|
264
|
+
err_1 = _a.sent();
|
|
265
|
+
handleError(err_1);
|
|
266
|
+
process.exit(1);
|
|
267
|
+
return [3 /*break*/, 3];
|
|
268
|
+
case 3: return [2 /*return*/];
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}); });
|
|
272
|
+
return [4 /*yield*/, program.parseAsync(process.argv)];
|
|
273
|
+
case 1:
|
|
274
|
+
_a.sent();
|
|
275
|
+
return [2 /*return*/];
|
|
167
276
|
}
|
|
168
|
-
})
|
|
169
|
-
yield program.parseAsync(process.argv);
|
|
277
|
+
});
|
|
170
278
|
});
|
|
171
279
|
}
|
|
172
280
|
function showWelcomeMessage(version) {
|
|
173
|
-
|
|
281
|
+
var rnohLogoArray = [
|
|
174
282
|
' ',
|
|
175
283
|
' ____ _ ______ __ __ ',
|
|
176
284
|
' / __ \\/ | / / __ \\/ / / / ',
|
|
@@ -179,348 +287,549 @@ function showWelcomeMessage(version) {
|
|
|
179
287
|
' /_/ |_/_/ |_/\\____/_/ /_/ ',
|
|
180
288
|
' ',
|
|
181
289
|
];
|
|
182
|
-
|
|
183
|
-
?
|
|
290
|
+
var versionInfo = version && version !== 'undefined'
|
|
291
|
+
? " Welcome to RNOH ".concat(version, "!")
|
|
184
292
|
: ' Welcome to RNOH!';
|
|
185
|
-
cli_tools_1.logger.log(
|
|
293
|
+
cli_tools_1.logger.log("".concat(chalk_1.default.cyan(rnohLogoArray.join('\n')), "\n").concat(chalk_1.default.cyanBright.bold(versionInfo), "\n"));
|
|
186
294
|
}
|
|
187
295
|
function runInit(projectName, options) {
|
|
188
|
-
return __awaiter(this, void 0, void 0, function
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
296
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
297
|
+
var packageName, destDir, tempDir, error_1;
|
|
298
|
+
return __generator(this, function (_a) {
|
|
299
|
+
switch (_a.label) {
|
|
300
|
+
case 0: return [4 /*yield*/, getValidatedProjectName(projectName)];
|
|
301
|
+
case 1:
|
|
302
|
+
projectName = _a.sent();
|
|
303
|
+
ValidationHelper.validateOptions(options);
|
|
304
|
+
packageName = "".concat(DEFAULT_PACKAGE_PREFIX).concat(projectName);
|
|
305
|
+
destDir = node_path_1.default.resolve(process.cwd(), projectName);
|
|
306
|
+
return [4 /*yield*/, checkDestinationDirectory(destDir, projectName)];
|
|
307
|
+
case 2:
|
|
308
|
+
_a.sent();
|
|
309
|
+
showWelcomeMessage(options.version);
|
|
310
|
+
return [4 /*yield*/, createTempDir()];
|
|
311
|
+
case 3:
|
|
312
|
+
tempDir = _a.sent();
|
|
313
|
+
_a.label = 4;
|
|
314
|
+
case 4:
|
|
315
|
+
_a.trys.push([4, 6, 8, 10]);
|
|
316
|
+
return [4 /*yield*/, executeInitializationSteps(tempDir, destDir, projectName, packageName, options)];
|
|
317
|
+
case 5:
|
|
318
|
+
_a.sent();
|
|
319
|
+
return [3 /*break*/, 10];
|
|
320
|
+
case 6:
|
|
321
|
+
error_1 = _a.sent();
|
|
322
|
+
return [4 /*yield*/, cleanupOnError(destDir)];
|
|
323
|
+
case 7:
|
|
324
|
+
_a.sent();
|
|
325
|
+
throw error_1;
|
|
326
|
+
case 8: return [4 /*yield*/, cleanupTempDir(tempDir)];
|
|
327
|
+
case 9:
|
|
328
|
+
_a.sent();
|
|
329
|
+
return [7 /*endfinally*/];
|
|
330
|
+
case 10: return [2 /*return*/];
|
|
331
|
+
}
|
|
332
|
+
});
|
|
206
333
|
});
|
|
207
334
|
}
|
|
208
335
|
function getValidatedProjectName(projectName) {
|
|
209
|
-
return __awaiter(this, void 0, void 0, function
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
336
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
337
|
+
var name_1, validationResult;
|
|
338
|
+
return __generator(this, function (_a) {
|
|
339
|
+
switch (_a.label) {
|
|
340
|
+
case 0:
|
|
341
|
+
if (!!projectName) return [3 /*break*/, 2];
|
|
342
|
+
return [4 /*yield*/, inquirer_1.default.prompt([
|
|
343
|
+
{
|
|
344
|
+
type: 'input',
|
|
345
|
+
name: 'name',
|
|
346
|
+
message: 'Please input your project name:',
|
|
347
|
+
validate: ValidationHelper.validateProjectName,
|
|
348
|
+
},
|
|
349
|
+
])];
|
|
350
|
+
case 1:
|
|
351
|
+
name_1 = (_a.sent()).name;
|
|
352
|
+
return [2 /*return*/, name_1.trim()];
|
|
353
|
+
case 2:
|
|
354
|
+
validationResult = ValidationHelper.validateProjectName(projectName);
|
|
355
|
+
if (validationResult !== true) {
|
|
356
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
357
|
+
whatHappened: 'Invalid project name.',
|
|
358
|
+
whatCanUserDo: [validationResult],
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
return [2 /*return*/, projectName];
|
|
362
|
+
}
|
|
363
|
+
});
|
|
229
364
|
});
|
|
230
365
|
}
|
|
231
366
|
function checkDestinationDirectory(destDir, projectName) {
|
|
232
|
-
return __awaiter(this, void 0, void 0, function
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
default
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
367
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
368
|
+
var overwrite, err_2;
|
|
369
|
+
return __generator(this, function (_a) {
|
|
370
|
+
switch (_a.label) {
|
|
371
|
+
case 0: return [4 /*yield*/, fs_extra_1.default.pathExists(destDir)];
|
|
372
|
+
case 1:
|
|
373
|
+
if (!_a.sent()) return [3 /*break*/, 6];
|
|
374
|
+
return [4 /*yield*/, inquirer_1.default.prompt([
|
|
375
|
+
{
|
|
376
|
+
type: 'confirm',
|
|
377
|
+
name: 'overwrite',
|
|
378
|
+
message: "Directory '".concat(projectName, "' already exists. Do you want to overwrite it?"),
|
|
379
|
+
default: false,
|
|
380
|
+
},
|
|
381
|
+
])];
|
|
382
|
+
case 2:
|
|
383
|
+
overwrite = (_a.sent()).overwrite;
|
|
384
|
+
if (!overwrite) {
|
|
385
|
+
process.exit(0);
|
|
386
|
+
}
|
|
387
|
+
_a.label = 3;
|
|
388
|
+
case 3:
|
|
389
|
+
_a.trys.push([3, 5, , 6]);
|
|
390
|
+
return [4 /*yield*/, fs_extra_1.default.remove(destDir)];
|
|
391
|
+
case 4:
|
|
392
|
+
_a.sent();
|
|
393
|
+
return [3 /*break*/, 6];
|
|
394
|
+
case 5:
|
|
395
|
+
err_2 = _a.sent();
|
|
396
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
397
|
+
whatHappened: "Failed to remove existing directory ".concat(destDir),
|
|
398
|
+
whatCanUserDo: ['Check permissions for the directory.', 'Ensure the directory is not in use.'],
|
|
399
|
+
});
|
|
400
|
+
case 6: return [2 /*return*/];
|
|
253
401
|
}
|
|
254
|
-
}
|
|
402
|
+
});
|
|
255
403
|
});
|
|
256
404
|
}
|
|
257
405
|
function executeInitializationSteps(tempDir, destDir, projectName, packageName, options) {
|
|
258
|
-
return __awaiter(this, void 0, void 0, function
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
406
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
407
|
+
var loader, err_3, _a, templateConfig, templateRoot, isHarmonyTemplate, rnohTemplateConfig, rnohVersion, rnohCliVersion, rnVersion, err_4, updateConfig, err_5, err_6, isSuccess;
|
|
408
|
+
var _b;
|
|
409
|
+
return __generator(this, function (_c) {
|
|
410
|
+
switch (_c.label) {
|
|
411
|
+
case 0:
|
|
412
|
+
loader = (0, cli_tools_1.getLoader)();
|
|
413
|
+
loader.start("".concat(chalk_1.default.bold('Downloading template...')));
|
|
414
|
+
_c.label = 1;
|
|
415
|
+
case 1:
|
|
416
|
+
_c.trys.push([1, 3, , 4]);
|
|
417
|
+
return [4 /*yield*/, npmInitAndInstall(tempDir, options.template, options.version)];
|
|
418
|
+
case 2:
|
|
419
|
+
_c.sent();
|
|
420
|
+
loader.succeed('Template downloaded successfully!');
|
|
421
|
+
return [3 /*break*/, 4];
|
|
422
|
+
case 3:
|
|
423
|
+
err_3 = _c.sent();
|
|
424
|
+
loader.fail('Failed to download template');
|
|
425
|
+
if (err_3 instanceof DescriptiveError_1.DescriptiveError) {
|
|
426
|
+
throw err_3;
|
|
427
|
+
}
|
|
428
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
429
|
+
whatHappened: 'Template download failed',
|
|
430
|
+
whatCanUserDo: ['Check your internet connection.', 'Ensure the template package exists.'],
|
|
431
|
+
});
|
|
432
|
+
case 4:
|
|
433
|
+
loader.start("".concat(chalk_1.default.bold('Copying template...')));
|
|
434
|
+
return [4 /*yield*/, getTemplateConfigFromPkg(tempDir)];
|
|
435
|
+
case 5:
|
|
436
|
+
_a = _c.sent(), templateConfig = _a.templateConfig, templateRoot = _a.templateRoot;
|
|
437
|
+
isHarmonyTemplate = true;
|
|
438
|
+
rnohTemplateConfig = undefined;
|
|
439
|
+
rnohVersion = undefined;
|
|
440
|
+
rnohCliVersion = undefined;
|
|
441
|
+
_c.label = 6;
|
|
442
|
+
case 6:
|
|
443
|
+
_c.trys.push([6, 12, , 13]);
|
|
444
|
+
return [4 /*yield*/, copyAndReplaceTemplate(templateConfig, templateRoot, destDir)];
|
|
445
|
+
case 7:
|
|
446
|
+
_c.sent();
|
|
447
|
+
return [4 /*yield*/, ValidationHelper.validateReactNativeVersion(destDir)];
|
|
448
|
+
case 8:
|
|
449
|
+
rnVersion = _c.sent();
|
|
450
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(node_path_1.default.join(destDir, HARMONY_DIR))];
|
|
451
|
+
case 9:
|
|
452
|
+
if (!!(_c.sent())) return [3 /*break*/, 11];
|
|
453
|
+
isHarmonyTemplate = false;
|
|
454
|
+
return [4 /*yield*/, handleMissingHarmonyDir(destDir, rnVersion)];
|
|
455
|
+
case 10:
|
|
456
|
+
(_b = _c.sent(), rnohTemplateConfig = _b.rnohTemplateConfig, rnohVersion = _b.rnohVersion, rnohCliVersion = _b.rnohCliVersion);
|
|
457
|
+
_c.label = 11;
|
|
458
|
+
case 11:
|
|
459
|
+
loader.succeed('Template copied successfully!');
|
|
460
|
+
return [3 /*break*/, 13];
|
|
461
|
+
case 12:
|
|
462
|
+
err_4 = _c.sent();
|
|
463
|
+
loader.fail('Failed to copy template');
|
|
464
|
+
if (err_4 instanceof DescriptiveError_1.DescriptiveError) {
|
|
465
|
+
throw err_4;
|
|
466
|
+
}
|
|
467
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
468
|
+
whatHappened: 'Template copy failed',
|
|
469
|
+
whatCanUserDo: ['Ensure you have write permissions for the destination directory.'],
|
|
470
|
+
});
|
|
471
|
+
case 13:
|
|
472
|
+
loader.start("".concat(chalk_1.default.bold('Processing template...')));
|
|
473
|
+
_c.label = 14;
|
|
474
|
+
case 14:
|
|
475
|
+
_c.trys.push([14, 16, , 17]);
|
|
476
|
+
updateConfig = {
|
|
477
|
+
destDir: destDir,
|
|
478
|
+
templateRoot: templateRoot,
|
|
479
|
+
templateConfig: templateConfig,
|
|
480
|
+
projectName: projectName,
|
|
481
|
+
packageName: packageName,
|
|
482
|
+
isHarmonyTemplate: isHarmonyTemplate,
|
|
483
|
+
rnohVersion: rnohVersion,
|
|
484
|
+
rnohCliVersion: rnohCliVersion,
|
|
485
|
+
rnohTemplateConfig: rnohTemplateConfig,
|
|
486
|
+
};
|
|
487
|
+
return [4 /*yield*/, processTemplate(updateConfig)];
|
|
488
|
+
case 15:
|
|
489
|
+
_c.sent();
|
|
490
|
+
loader.succeed('Template processed successfully!');
|
|
491
|
+
return [3 /*break*/, 17];
|
|
492
|
+
case 16:
|
|
493
|
+
err_5 = _c.sent();
|
|
494
|
+
loader.fail('Failed to process template');
|
|
495
|
+
if (err_5 instanceof DescriptiveError_1.DescriptiveError) {
|
|
496
|
+
throw err_5;
|
|
497
|
+
}
|
|
498
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
499
|
+
whatHappened: 'Template processing failed',
|
|
500
|
+
whatCanUserDo: ['Check if the template files are corrupted.'],
|
|
501
|
+
});
|
|
502
|
+
case 17:
|
|
503
|
+
loader.start("".concat(chalk_1.default.bold('Installing dependencies...')));
|
|
504
|
+
_c.label = 18;
|
|
505
|
+
case 18:
|
|
506
|
+
_c.trys.push([18, 20, , 21]);
|
|
507
|
+
return [4 /*yield*/, runCliCommand(NPM_EXE, ['install', '--legacy-peer-deps'], destDir)];
|
|
508
|
+
case 19:
|
|
509
|
+
_c.sent();
|
|
510
|
+
loader.succeed('Dependencies installed successfully!');
|
|
511
|
+
return [3 /*break*/, 21];
|
|
512
|
+
case 20:
|
|
513
|
+
err_6 = _c.sent();
|
|
514
|
+
loader.fail('Failed to install dependencies');
|
|
515
|
+
if (err_6 instanceof DescriptiveError_1.DescriptiveError) {
|
|
516
|
+
throw err_6;
|
|
517
|
+
}
|
|
518
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
519
|
+
whatHappened: 'Dependency installation failed',
|
|
520
|
+
whatCanUserDo: ['Check your internet connection.'],
|
|
521
|
+
});
|
|
522
|
+
case 21:
|
|
523
|
+
loader.start("".concat(chalk_1.default.bold('Initializing git repository...')));
|
|
524
|
+
return [4 /*yield*/, initGitRepo(destDir)];
|
|
525
|
+
case 22:
|
|
526
|
+
isSuccess = _c.sent();
|
|
527
|
+
if (isSuccess) {
|
|
528
|
+
loader.succeed('Git repository initialized successfully!');
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
loader.fail('Failed to initialize git repository.');
|
|
532
|
+
}
|
|
533
|
+
return [2 /*return*/];
|
|
335
534
|
}
|
|
336
|
-
|
|
337
|
-
whatHappened: 'Dependency installation failed',
|
|
338
|
-
whatCanUserDo: ['Check your internet connection.'],
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
loader.start(`${chalk_1.default.bold('Initializing git repository...')}`);
|
|
342
|
-
const isSuccess = yield initGitRepo(destDir);
|
|
343
|
-
if (isSuccess) {
|
|
344
|
-
loader.succeed('Git repository initialized successfully!');
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
loader.fail('Failed to initialize git repository.');
|
|
348
|
-
}
|
|
535
|
+
});
|
|
349
536
|
});
|
|
350
537
|
}
|
|
351
538
|
function createTempDir() {
|
|
352
|
-
return __awaiter(this, void 0, void 0, function
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
539
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
540
|
+
var tempDir;
|
|
541
|
+
return __generator(this, function (_a) {
|
|
542
|
+
switch (_a.label) {
|
|
543
|
+
case 0:
|
|
544
|
+
tempDir = node_path_1.default.join(node_os_1.default.tmpdir(), "rnoh-init-".concat(Date.now(), "-").concat(Math.random().toString(36).slice(2)));
|
|
545
|
+
return [4 /*yield*/, fs_extra_1.default.ensureDir(tempDir)];
|
|
546
|
+
case 1:
|
|
547
|
+
_a.sent();
|
|
548
|
+
return [2 /*return*/, tempDir];
|
|
549
|
+
}
|
|
550
|
+
});
|
|
356
551
|
});
|
|
357
552
|
}
|
|
358
553
|
function npmInitAndInstall(tempDir, customTemplate, version) {
|
|
359
|
-
return __awaiter(this, void 0, void 0, function
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
554
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
555
|
+
var installTarget;
|
|
556
|
+
return __generator(this, function (_a) {
|
|
557
|
+
switch (_a.label) {
|
|
558
|
+
case 0: return [4 /*yield*/, runCliCommand(NPM_EXE, ['init', '-y'], tempDir)];
|
|
559
|
+
case 1:
|
|
560
|
+
_a.sent();
|
|
561
|
+
installTarget = customTemplate ? customTemplate : version ? "".concat(DEFAULT_TEMPLATE_PKG, "@").concat(version) : DEFAULT_TEMPLATE_PKG;
|
|
562
|
+
return [4 /*yield*/, runCliCommand(NPM_EXE, ['install', installTarget], tempDir)];
|
|
563
|
+
case 2:
|
|
564
|
+
_a.sent();
|
|
565
|
+
return [2 /*return*/];
|
|
566
|
+
}
|
|
567
|
+
});
|
|
363
568
|
});
|
|
364
569
|
}
|
|
365
570
|
function getTemplateConfigFromPkg(tempDir) {
|
|
366
|
-
return __awaiter(this, void 0, void 0, function
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
571
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
572
|
+
var pkgJsonPath, packageJson, _a, _b, dependencies, templateName, templateRoot, configPath, templateConfig;
|
|
573
|
+
return __generator(this, function (_c) {
|
|
574
|
+
switch (_c.label) {
|
|
575
|
+
case 0:
|
|
576
|
+
pkgJsonPath = node_path_1.default.join(tempDir, PACKAGE_JSON);
|
|
577
|
+
_b = (_a = JSON).parse;
|
|
578
|
+
return [4 /*yield*/, fs_extra_1.default.readFile(pkgJsonPath, DEFAULT_ENCODING)];
|
|
579
|
+
case 1:
|
|
580
|
+
packageJson = _b.apply(_a, [_c.sent()]);
|
|
581
|
+
dependencies = packageJson.dependencies;
|
|
582
|
+
templateName = Object.keys(dependencies)[0];
|
|
583
|
+
templateRoot = node_path_1.default.join.apply(node_path_1.default, __spreadArray([tempDir, NODE_MODULES], templateName.split('/'), false));
|
|
584
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(templateRoot)];
|
|
585
|
+
case 2:
|
|
586
|
+
if (!(_c.sent())) {
|
|
587
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
588
|
+
whatHappened: 'Cannot find installed template package.',
|
|
589
|
+
whatCanUserDo: ['Check npm install output.'],
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
configPath = node_path_1.default.join(templateRoot, TEMPLATE_CONFIG_JS);
|
|
593
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(configPath)];
|
|
594
|
+
case 3:
|
|
595
|
+
if (!(_c.sent())) {
|
|
596
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
597
|
+
whatHappened: "".concat(TEMPLATE_CONFIG_JS, " not found in template package."),
|
|
598
|
+
whatCanUserDo: ['Check the template package.'],
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
templateConfig = require(configPath);
|
|
602
|
+
validateTemplateConfig(templateConfig);
|
|
603
|
+
return [2 /*return*/, { templateConfig: templateConfig, templateRoot: templateRoot }];
|
|
604
|
+
}
|
|
605
|
+
});
|
|
388
606
|
});
|
|
389
607
|
}
|
|
390
608
|
function validateTemplateConfig(templateConfig) {
|
|
391
609
|
if (!templateConfig.placeholderName || !templateConfig.templateDir) {
|
|
392
610
|
throw new DescriptiveError_1.DescriptiveError({
|
|
393
|
-
whatHappened:
|
|
394
|
-
whatCanUserDo: [
|
|
611
|
+
whatHappened: "".concat(TEMPLATE_CONFIG_JS, " missing required fields (placeholderName, templateDir)."),
|
|
612
|
+
whatCanUserDo: ["Check ".concat(TEMPLATE_CONFIG_JS, " format.")],
|
|
395
613
|
});
|
|
396
614
|
}
|
|
397
615
|
if (typeof templateConfig.placeholderName !== STRING_TYPE || typeof templateConfig.templateDir !== STRING_TYPE) {
|
|
398
616
|
throw new DescriptiveError_1.DescriptiveError({
|
|
399
|
-
whatHappened:
|
|
400
|
-
whatCanUserDo: [
|
|
617
|
+
whatHappened: "".concat(TEMPLATE_CONFIG_JS, " fields must be strings."),
|
|
618
|
+
whatCanUserDo: ["Check ".concat(TEMPLATE_CONFIG_JS, " format.")],
|
|
401
619
|
});
|
|
402
620
|
}
|
|
403
621
|
}
|
|
404
622
|
function copyAndReplaceTemplate(templateConfig, templateRoot, destDir) {
|
|
405
|
-
return __awaiter(this, void 0, void 0, function
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
623
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
624
|
+
var srcDir;
|
|
625
|
+
return __generator(this, function (_a) {
|
|
626
|
+
switch (_a.label) {
|
|
627
|
+
case 0:
|
|
628
|
+
srcDir = node_path_1.default.join(templateRoot, templateConfig.templateDir);
|
|
629
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(srcDir)];
|
|
630
|
+
case 1:
|
|
631
|
+
if (!(_a.sent())) {
|
|
632
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
633
|
+
whatHappened: 'Template directory not found.',
|
|
634
|
+
whatCanUserDo: ["Check templateDir in ".concat(TEMPLATE_CONFIG_JS, ".")],
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
return [4 /*yield*/, fs_extra_1.default.copy(srcDir, destDir)];
|
|
638
|
+
case 2:
|
|
639
|
+
_a.sent();
|
|
640
|
+
return [2 /*return*/];
|
|
641
|
+
}
|
|
642
|
+
});
|
|
414
643
|
});
|
|
415
644
|
}
|
|
416
645
|
function updateRNConfigFiles(updateConfig) {
|
|
417
|
-
return __awaiter(this, void 0, void 0, function
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
646
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
647
|
+
var updates;
|
|
648
|
+
return __generator(this, function (_a) {
|
|
649
|
+
switch (_a.label) {
|
|
650
|
+
case 0:
|
|
651
|
+
updates = [
|
|
652
|
+
FileOperationHelper.updateJsonFile(node_path_1.default.join(updateConfig.destDir, APP_JSON), function (data) { return (__assign(__assign({}, data), { name: updateConfig.projectName, displayName: updateConfig.projectName })); }, "Failed to update ".concat(APP_JSON, ".")),
|
|
653
|
+
FileOperationHelper.updateJsonFile(node_path_1.default.join(updateConfig.destDir, PACKAGE_JSON), function (data) {
|
|
654
|
+
var _a, _b;
|
|
655
|
+
if (!updateConfig.isHarmonyTemplate) {
|
|
656
|
+
data.dependencies = __assign(__assign({}, data.dependencies), (_a = {}, _a[REACT_NATIVE_OH_REACT_NATIVE_HARMONY] = updateConfig.rnohVersion, _a));
|
|
657
|
+
data.devDependencies = __assign(__assign({}, data.devDependencies), (_b = {}, _b[REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI] = updateConfig.rnohCliVersion, _b));
|
|
658
|
+
}
|
|
659
|
+
return __assign(__assign({}, data), { name: updateConfig.packageName });
|
|
660
|
+
}, "Failed to update ".concat(PACKAGE_JSON, ".")),
|
|
661
|
+
];
|
|
662
|
+
return [4 /*yield*/, Promise.all(updates)];
|
|
663
|
+
case 1:
|
|
664
|
+
_a.sent();
|
|
665
|
+
return [2 /*return*/];
|
|
666
|
+
}
|
|
667
|
+
});
|
|
429
668
|
});
|
|
430
669
|
}
|
|
431
670
|
function renameDotFiles(destDir) {
|
|
432
|
-
return __awaiter(this, void 0, void 0, function
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
671
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
672
|
+
var dotMap, renameOperations;
|
|
673
|
+
var _this = this;
|
|
674
|
+
return __generator(this, function (_a) {
|
|
675
|
+
switch (_a.label) {
|
|
676
|
+
case 0:
|
|
677
|
+
dotMap = {
|
|
678
|
+
'_bundle': '.bundle',
|
|
679
|
+
'_eslintrc.js': '.eslintrc.js',
|
|
680
|
+
'_gitignore': '.gitignore',
|
|
681
|
+
'_prettierrc.js': '.prettierrc.js',
|
|
682
|
+
'_watchmanconfig': '.watchmanconfig',
|
|
683
|
+
'_buckconfig': '.buckconfig',
|
|
684
|
+
'_flowconfig': '.flowconfig',
|
|
685
|
+
'_gitattributes': '.gitattributes',
|
|
686
|
+
'_editorconfig': '.editorconfig',
|
|
687
|
+
'_ruby-version': '.ruby-version',
|
|
688
|
+
'_node-version': '.node-version',
|
|
689
|
+
'_xcode.env': '.xcode.env',
|
|
690
|
+
};
|
|
691
|
+
renameOperations = Object.entries(dotMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
692
|
+
var srcPath;
|
|
693
|
+
var src = _b[0], dest = _b[1];
|
|
694
|
+
return __generator(this, function (_c) {
|
|
695
|
+
switch (_c.label) {
|
|
696
|
+
case 0:
|
|
697
|
+
srcPath = node_path_1.default.join(destDir, src);
|
|
698
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(srcPath)];
|
|
699
|
+
case 1:
|
|
700
|
+
if (!_c.sent()) return [3 /*break*/, 3];
|
|
701
|
+
return [4 /*yield*/, fs_extra_1.default.move(srcPath, node_path_1.default.join(destDir, dest), { overwrite: true })];
|
|
702
|
+
case 2:
|
|
703
|
+
_c.sent();
|
|
704
|
+
_c.label = 3;
|
|
705
|
+
case 3: return [2 /*return*/];
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
}); });
|
|
709
|
+
return [4 /*yield*/, Promise.all(renameOperations)];
|
|
710
|
+
case 1:
|
|
711
|
+
_a.sent();
|
|
712
|
+
return [2 /*return*/];
|
|
451
713
|
}
|
|
452
|
-
})
|
|
453
|
-
yield Promise.all(renameOperations);
|
|
714
|
+
});
|
|
454
715
|
});
|
|
455
716
|
}
|
|
456
717
|
function runPostInitScript(scriptPath, templateRoot, cwd, isHarmonyTemplate) {
|
|
457
|
-
return __awaiter(this, void 0, void 0, function
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
718
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
719
|
+
var absScriptPath, err_7;
|
|
720
|
+
return __generator(this, function (_a) {
|
|
721
|
+
switch (_a.label) {
|
|
722
|
+
case 0:
|
|
723
|
+
absScriptPath = node_path_1.default.join(templateRoot, scriptPath);
|
|
724
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(absScriptPath)];
|
|
725
|
+
case 1:
|
|
726
|
+
if (!(_a.sent())) {
|
|
727
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
728
|
+
whatHappened: 'postInitScript not found.',
|
|
729
|
+
whatCanUserDo: ["Check postInitScript path in ".concat(TEMPLATE_CONFIG_JS, ".")],
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
if (!!isHarmonyTemplate) return [3 /*break*/, 6];
|
|
733
|
+
_a.label = 2;
|
|
734
|
+
case 2:
|
|
735
|
+
_a.trys.push([2, 4, , 5]);
|
|
736
|
+
return [4 /*yield*/, runCliCommand(NODE_EXE, [absScriptPath], cwd)];
|
|
737
|
+
case 3:
|
|
738
|
+
_a.sent();
|
|
739
|
+
return [3 /*break*/, 5];
|
|
740
|
+
case 4:
|
|
741
|
+
err_7 = _a.sent();
|
|
742
|
+
cli_tools_1.logger.error("Failed to execute postInitScript in RN community template, please execute manually.");
|
|
743
|
+
return [3 /*break*/, 5];
|
|
744
|
+
case 5: return [3 /*break*/, 8];
|
|
745
|
+
case 6: return [4 /*yield*/, runCliCommand(NODE_EXE, [absScriptPath], cwd)];
|
|
746
|
+
case 7:
|
|
747
|
+
_a.sent();
|
|
748
|
+
_a.label = 8;
|
|
749
|
+
case 8: return [2 /*return*/];
|
|
471
750
|
}
|
|
472
|
-
}
|
|
473
|
-
else {
|
|
474
|
-
yield runCliCommand(NODE_EXE, [absScriptPath], cwd);
|
|
475
|
-
}
|
|
751
|
+
});
|
|
476
752
|
});
|
|
477
753
|
}
|
|
478
754
|
function runCliCommand(cmd_1, args_1, cwd_1) {
|
|
479
|
-
return __awaiter(this, arguments, void 0, function
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
755
|
+
return __awaiter(this, arguments, void 0, function (cmd, args, cwd, silent, stdOutFunc) {
|
|
756
|
+
var cli, err_8;
|
|
757
|
+
if (silent === void 0) { silent = true; }
|
|
758
|
+
return __generator(this, function (_a) {
|
|
759
|
+
switch (_a.label) {
|
|
760
|
+
case 0:
|
|
761
|
+
cli = new CliExecutor_1.RealCliExecutor();
|
|
762
|
+
_a.label = 1;
|
|
763
|
+
case 1:
|
|
764
|
+
_a.trys.push([1, 3, , 4]);
|
|
765
|
+
return [4 /*yield*/, cli.run(cmd, {
|
|
766
|
+
args: args,
|
|
767
|
+
cwd: new AbsolutePath_1.AbsolutePath(cwd),
|
|
768
|
+
shell: true,
|
|
769
|
+
onStdout: silent ? undefined : stdOutFunc ? function (data) { return stdOutFunc(data); } : function (data) { return cli_tools_1.logger.info(data); },
|
|
770
|
+
onStderr: silent ? undefined : function (data) { return cli_tools_1.logger.error(data); },
|
|
771
|
+
})];
|
|
772
|
+
case 2:
|
|
773
|
+
_a.sent();
|
|
774
|
+
return [3 /*break*/, 4];
|
|
775
|
+
case 3:
|
|
776
|
+
err_8 = _a.sent();
|
|
777
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
778
|
+
whatHappened: "Failed to run command: ".concat(cmd, " ").concat(args.join(' ')),
|
|
779
|
+
extraData: err_8,
|
|
780
|
+
});
|
|
781
|
+
case 4: return [2 /*return*/];
|
|
782
|
+
}
|
|
783
|
+
});
|
|
496
784
|
});
|
|
497
785
|
}
|
|
498
786
|
function initGitRepo(destDir) {
|
|
499
|
-
return __awaiter(this, void 0, void 0, function
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
787
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
788
|
+
var gitDir, error_2;
|
|
789
|
+
return __generator(this, function (_a) {
|
|
790
|
+
switch (_a.label) {
|
|
791
|
+
case 0:
|
|
792
|
+
gitDir = node_path_1.default.join(destDir, '.git');
|
|
793
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(gitDir)];
|
|
794
|
+
case 1:
|
|
795
|
+
if (_a.sent()) {
|
|
796
|
+
cli_tools_1.logger.warn('Git repository already exists, skipping git init.');
|
|
797
|
+
return [2 /*return*/, false];
|
|
798
|
+
}
|
|
799
|
+
_a.label = 2;
|
|
800
|
+
case 2:
|
|
801
|
+
_a.trys.push([2, 6, , 10]);
|
|
802
|
+
return [4 /*yield*/, runCliCommand(GIT_EXE, ['init'], destDir)];
|
|
803
|
+
case 3:
|
|
804
|
+
_a.sent();
|
|
805
|
+
return [4 /*yield*/, runCliCommand(GIT_EXE, ['add', '.'], destDir)];
|
|
806
|
+
case 4:
|
|
807
|
+
_a.sent();
|
|
808
|
+
return [4 /*yield*/, runCliCommand(GIT_EXE, ['commit', '-m', "\"Initial RNOH by ".concat(REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI, "\"")], destDir)];
|
|
809
|
+
case 5:
|
|
810
|
+
_a.sent();
|
|
811
|
+
return [3 /*break*/, 10];
|
|
812
|
+
case 6:
|
|
813
|
+
error_2 = _a.sent();
|
|
814
|
+
cli_tools_1.logger.warn('Failed to initialize git repository. You can initialize it manually later.');
|
|
815
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(gitDir)];
|
|
816
|
+
case 7:
|
|
817
|
+
if (!_a.sent()) return [3 /*break*/, 9];
|
|
818
|
+
return [4 /*yield*/, fs_extra_1.default.remove(gitDir)];
|
|
819
|
+
case 8:
|
|
820
|
+
_a.sent();
|
|
821
|
+
_a.label = 9;
|
|
822
|
+
case 9: return [2 /*return*/, false];
|
|
823
|
+
case 10: return [2 /*return*/, true];
|
|
514
824
|
}
|
|
515
|
-
|
|
516
|
-
}
|
|
517
|
-
return true;
|
|
825
|
+
});
|
|
518
826
|
});
|
|
519
827
|
}
|
|
520
828
|
function handleError(err) {
|
|
521
829
|
if (err instanceof DescriptiveError_1.DescriptiveError) {
|
|
522
830
|
cli_tools_1.logger.error(chalk_1.default.red(err.getMessage()));
|
|
523
|
-
for (
|
|
831
|
+
for (var _i = 0, _a = err.getSuggestions(); _i < _a.length; _i++) {
|
|
832
|
+
var suggestion = _a[_i];
|
|
524
833
|
cli_tools_1.logger.info(chalk_1.default.yellow('Tip: ' + suggestion));
|
|
525
834
|
}
|
|
526
835
|
if (err.getDetails()) {
|
|
@@ -528,176 +837,291 @@ function handleError(err) {
|
|
|
528
837
|
}
|
|
529
838
|
}
|
|
530
839
|
else {
|
|
531
|
-
|
|
840
|
+
var message = err instanceof Error ? err.message : String(err);
|
|
532
841
|
cli_tools_1.logger.error(chalk_1.default.red('Unexpected error: ' + message));
|
|
533
842
|
}
|
|
534
843
|
}
|
|
535
844
|
function cleanupOnError(destDir) {
|
|
536
|
-
return __awaiter(this, void 0, void 0, function
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
845
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
846
|
+
return __generator(this, function (_a) {
|
|
847
|
+
switch (_a.label) {
|
|
848
|
+
case 0: return [4 /*yield*/, fs_extra_1.default.pathExists(destDir)];
|
|
849
|
+
case 1:
|
|
850
|
+
if (!_a.sent()) return [3 /*break*/, 3];
|
|
851
|
+
return [4 /*yield*/, fs_extra_1.default.remove(destDir)];
|
|
852
|
+
case 2:
|
|
853
|
+
_a.sent();
|
|
854
|
+
_a.label = 3;
|
|
855
|
+
case 3: return [2 /*return*/];
|
|
856
|
+
}
|
|
857
|
+
});
|
|
540
858
|
});
|
|
541
859
|
}
|
|
542
860
|
function cleanupTempDir(tempDir) {
|
|
543
|
-
return __awaiter(this, void 0, void 0, function
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
861
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
862
|
+
var cleanupError_1;
|
|
863
|
+
return __generator(this, function (_a) {
|
|
864
|
+
switch (_a.label) {
|
|
865
|
+
case 0:
|
|
866
|
+
_a.trys.push([0, 2, , 3]);
|
|
867
|
+
return [4 /*yield*/, fs_extra_1.default.remove(tempDir)];
|
|
868
|
+
case 1:
|
|
869
|
+
_a.sent();
|
|
870
|
+
return [3 /*break*/, 3];
|
|
871
|
+
case 2:
|
|
872
|
+
cleanupError_1 = _a.sent();
|
|
873
|
+
cli_tools_1.logger.warn('Failed to clean up temporary directory:', tempDir);
|
|
874
|
+
return [3 /*break*/, 3];
|
|
875
|
+
case 3: return [2 /*return*/];
|
|
876
|
+
}
|
|
877
|
+
});
|
|
550
878
|
});
|
|
551
879
|
}
|
|
552
880
|
function getRNOHVersion(rnVersion) {
|
|
553
|
-
return __awaiter(this, void 0, void 0, function
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
881
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
882
|
+
var versionParts, majorMinorVersion, versionInfos, versions, matchingVersions;
|
|
883
|
+
return __generator(this, function (_a) {
|
|
884
|
+
switch (_a.label) {
|
|
885
|
+
case 0:
|
|
886
|
+
versionParts = rnVersion.split('.');
|
|
887
|
+
majorMinorVersion = "".concat(versionParts[0], ".").concat(versionParts[1]);
|
|
888
|
+
versionInfos = "";
|
|
889
|
+
return [4 /*yield*/, runCliCommand(NPM_EXE, ['view', DEFAULT_TEMPLATE_PKG, 'versions', '--json'], process.cwd(), false, function (data) {
|
|
890
|
+
versionInfos += data.toString();
|
|
891
|
+
})];
|
|
892
|
+
case 1:
|
|
893
|
+
_a.sent();
|
|
894
|
+
versions = JSON.parse(versionInfos);
|
|
895
|
+
matchingVersions = versions.filter(function (v) { return v.startsWith(majorMinorVersion); });
|
|
896
|
+
if (matchingVersions.length === 0) {
|
|
897
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
898
|
+
whatHappened: "No matching versions found for ".concat(DEFAULT_TEMPLATE_PKG, " with major version ").concat(majorMinorVersion, "."),
|
|
899
|
+
whatCanUserDo: ['Please check the available versions of the template package.'],
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
return [2 /*return*/, matchingVersions.pop()];
|
|
903
|
+
}
|
|
559
904
|
});
|
|
560
|
-
const versions = JSON.parse(versionInfos);
|
|
561
|
-
const matchingVersions = versions.filter((v) => v.startsWith(majorMinorVersion));
|
|
562
|
-
if (matchingVersions.length === 0) {
|
|
563
|
-
throw new DescriptiveError_1.DescriptiveError({
|
|
564
|
-
whatHappened: `No matching versions found for ${DEFAULT_TEMPLATE_PKG} with major version ${majorMinorVersion}.`,
|
|
565
|
-
whatCanUserDo: ['Please check the available versions of the template package.'],
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
return matchingVersions.pop();
|
|
569
905
|
});
|
|
570
906
|
}
|
|
571
907
|
function handleMissingHarmonyDir(destDir, rnVersion) {
|
|
572
|
-
return __awaiter(this, void 0, void 0, function
|
|
573
|
-
var _a, _b;
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
908
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
909
|
+
var lastestVersion, defaultTempDir, defaultTemplateConfig, sourceHarmonyDir, targetHarmonyDir, sourceMetroConfigPath, targetMetroConfigPath, pkgJsonPath, pkgContent, _a, _b, rnohVersion, rnohCliVersion, androidDir, iosDir, error_3;
|
|
910
|
+
var _c, _d;
|
|
911
|
+
return __generator(this, function (_e) {
|
|
912
|
+
switch (_e.label) {
|
|
913
|
+
case 0: return [4 /*yield*/, getRNOHVersion(rnVersion)];
|
|
914
|
+
case 1:
|
|
915
|
+
lastestVersion = _e.sent();
|
|
916
|
+
return [4 /*yield*/, createTempDir()];
|
|
917
|
+
case 2:
|
|
918
|
+
defaultTempDir = _e.sent();
|
|
919
|
+
_e.label = 3;
|
|
920
|
+
case 3:
|
|
921
|
+
_e.trys.push([3, 19, 20, 22]);
|
|
922
|
+
return [4 /*yield*/, npmInitAndInstall(defaultTempDir, "".concat(DEFAULT_TEMPLATE_PKG, "@").concat(lastestVersion))];
|
|
923
|
+
case 4:
|
|
924
|
+
_e.sent();
|
|
925
|
+
return [4 /*yield*/, getTemplateConfigFromPkg(defaultTempDir)];
|
|
926
|
+
case 5:
|
|
927
|
+
defaultTemplateConfig = _e.sent();
|
|
928
|
+
sourceHarmonyDir = node_path_1.default.join(defaultTemplateConfig.templateRoot, defaultTemplateConfig.templateConfig.templateDir, HARMONY_DIR);
|
|
929
|
+
targetHarmonyDir = node_path_1.default.join(destDir, HARMONY_DIR);
|
|
930
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(sourceHarmonyDir)];
|
|
931
|
+
case 6:
|
|
932
|
+
if (!(_e.sent())) {
|
|
933
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
934
|
+
whatHappened: "Default template does not contain harmony directory at ".concat(sourceHarmonyDir),
|
|
935
|
+
whatCanUserDo: ['Please use a template that contains harmony directory.', 'Check if the default template package is correct.'],
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
return [4 /*yield*/, fs_extra_1.default.copy(sourceHarmonyDir, targetHarmonyDir)];
|
|
939
|
+
case 7:
|
|
940
|
+
_e.sent();
|
|
941
|
+
sourceMetroConfigPath = node_path_1.default.join(defaultTemplateConfig.templateRoot, defaultTemplateConfig.templateConfig.templateDir, METRO_CONFIG_JS);
|
|
942
|
+
targetMetroConfigPath = node_path_1.default.join(destDir, METRO_CONFIG_JS);
|
|
943
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(sourceMetroConfigPath)];
|
|
944
|
+
case 8:
|
|
945
|
+
if (!_e.sent()) return [3 /*break*/, 10];
|
|
946
|
+
return [4 /*yield*/, fs_extra_1.default.copyFile(sourceMetroConfigPath, targetMetroConfigPath)];
|
|
947
|
+
case 9:
|
|
948
|
+
_e.sent();
|
|
949
|
+
return [3 /*break*/, 11];
|
|
950
|
+
case 10: throw new DescriptiveError_1.DescriptiveError({
|
|
951
|
+
whatHappened: "Default template does not contain ".concat(METRO_CONFIG_JS, " at ").concat(sourceMetroConfigPath),
|
|
952
|
+
whatCanUserDo: ["Please use a template that contains ".concat(METRO_CONFIG_JS, "."), 'Check if the default template package is correct.'],
|
|
597
953
|
});
|
|
954
|
+
case 11:
|
|
955
|
+
pkgJsonPath = node_path_1.default.join(defaultTemplateConfig.templateRoot, defaultTemplateConfig.templateConfig.templateDir, PACKAGE_JSON);
|
|
956
|
+
_b = (_a = JSON).parse;
|
|
957
|
+
return [4 /*yield*/, fs_extra_1.default.readFile(pkgJsonPath, DEFAULT_ENCODING)];
|
|
958
|
+
case 12:
|
|
959
|
+
pkgContent = _b.apply(_a, [_e.sent()]);
|
|
960
|
+
rnohVersion = (_c = pkgContent.dependencies) === null || _c === void 0 ? void 0 : _c[REACT_NATIVE_OH_REACT_NATIVE_HARMONY];
|
|
961
|
+
rnohCliVersion = (_d = pkgContent.devDependencies) === null || _d === void 0 ? void 0 : _d[REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI];
|
|
962
|
+
androidDir = node_path_1.default.join(destDir, 'android');
|
|
963
|
+
iosDir = node_path_1.default.join(destDir, 'ios');
|
|
964
|
+
return [4 /*yield*/, fs_extra_1.default.pathExists(androidDir)];
|
|
965
|
+
case 13:
|
|
966
|
+
if (!_e.sent()) return [3 /*break*/, 15];
|
|
967
|
+
return [4 /*yield*/, fs_extra_1.default.remove(androidDir)];
|
|
968
|
+
case 14:
|
|
969
|
+
_e.sent();
|
|
970
|
+
_e.label = 15;
|
|
971
|
+
case 15: return [4 /*yield*/, fs_extra_1.default.pathExists(iosDir)];
|
|
972
|
+
case 16:
|
|
973
|
+
if (!_e.sent()) return [3 /*break*/, 18];
|
|
974
|
+
return [4 /*yield*/, fs_extra_1.default.remove(iosDir)];
|
|
975
|
+
case 17:
|
|
976
|
+
_e.sent();
|
|
977
|
+
_e.label = 18;
|
|
978
|
+
case 18: return [2 /*return*/, { rnohTemplateConfig: defaultTemplateConfig.templateConfig, rnohVersion: rnohVersion, rnohCliVersion: rnohCliVersion }];
|
|
979
|
+
case 19:
|
|
980
|
+
error_3 = _e.sent();
|
|
981
|
+
if (error_3 instanceof DescriptiveError_1.DescriptiveError) {
|
|
982
|
+
throw error_3;
|
|
983
|
+
}
|
|
984
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
985
|
+
whatHappened: 'Failed to handle missing harmony directory from default template.',
|
|
986
|
+
whatCanUserDo: [
|
|
987
|
+
'Check your internet connection.',
|
|
988
|
+
'Ensure you have write permissions for the destination directory.',
|
|
989
|
+
'Verify that the default template package exists and is accessible.',
|
|
990
|
+
],
|
|
991
|
+
extraData: error_3,
|
|
992
|
+
});
|
|
993
|
+
case 20: return [4 /*yield*/, cleanupTempDir(defaultTempDir)];
|
|
994
|
+
case 21:
|
|
995
|
+
_e.sent();
|
|
996
|
+
return [7 /*endfinally*/];
|
|
997
|
+
case 22: return [2 /*return*/];
|
|
598
998
|
}
|
|
599
|
-
|
|
600
|
-
const pkgContent = JSON.parse(yield fs_extra_1.default.readFile(pkgJsonPath, DEFAULT_ENCODING));
|
|
601
|
-
const rnohVersion = (_a = pkgContent.dependencies) === null || _a === void 0 ? void 0 : _a[REACT_NATIVE_OH_REACT_NATIVE_HARMONY];
|
|
602
|
-
const rnohCliVersion = (_b = pkgContent.devDependencies) === null || _b === void 0 ? void 0 : _b[REACT_NATIVE_OH_REACT_NATIVE_HARMONY_CLI];
|
|
603
|
-
const androidDir = node_path_1.default.join(destDir, 'android');
|
|
604
|
-
const iosDir = node_path_1.default.join(destDir, 'ios');
|
|
605
|
-
if (yield fs_extra_1.default.pathExists(androidDir)) {
|
|
606
|
-
yield fs_extra_1.default.remove(androidDir);
|
|
607
|
-
}
|
|
608
|
-
if (yield fs_extra_1.default.pathExists(iosDir)) {
|
|
609
|
-
yield fs_extra_1.default.remove(iosDir);
|
|
610
|
-
}
|
|
611
|
-
return { rnohTemplateConfig: defaultTemplateConfig.templateConfig, rnohVersion, rnohCliVersion };
|
|
612
|
-
}
|
|
613
|
-
catch (error) {
|
|
614
|
-
if (error instanceof DescriptiveError_1.DescriptiveError) {
|
|
615
|
-
throw error;
|
|
616
|
-
}
|
|
617
|
-
throw new DescriptiveError_1.DescriptiveError({
|
|
618
|
-
whatHappened: 'Failed to handle missing harmony directory from default template.',
|
|
619
|
-
whatCanUserDo: [
|
|
620
|
-
'Check your internet connection.',
|
|
621
|
-
'Ensure you have write permissions for the destination directory.',
|
|
622
|
-
'Verify that the default template package exists and is accessible.',
|
|
623
|
-
],
|
|
624
|
-
extraData: error,
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
finally {
|
|
628
|
-
yield cleanupTempDir(defaultTempDir);
|
|
629
|
-
}
|
|
999
|
+
});
|
|
630
1000
|
});
|
|
631
1001
|
}
|
|
632
1002
|
function updateHarmonyFiles(updateConfig) {
|
|
633
|
-
return __awaiter(this, void 0, void 0, function
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
1003
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1004
|
+
var harmonyDir, appScopeDir, entryDir, updateOperations;
|
|
1005
|
+
return __generator(this, function (_a) {
|
|
1006
|
+
switch (_a.label) {
|
|
1007
|
+
case 0:
|
|
1008
|
+
harmonyDir = node_path_1.default.join(updateConfig.destDir, HARMONY_DIR);
|
|
1009
|
+
appScopeDir = node_path_1.default.join(harmonyDir, 'AppScope');
|
|
1010
|
+
entryDir = node_path_1.default.join(harmonyDir, 'entry');
|
|
1011
|
+
updateOperations = [
|
|
1012
|
+
updateAppScopeStringJson(appScopeDir, updateConfig.projectName),
|
|
1013
|
+
updateEntryIndexEts(entryDir, updateConfig),
|
|
1014
|
+
updateAppScopeAppJson5(appScopeDir, updateConfig.packageName),
|
|
1015
|
+
updateEntryStringJson(entryDir, updateConfig.projectName),
|
|
1016
|
+
];
|
|
1017
|
+
return [4 /*yield*/, Promise.all(updateOperations)];
|
|
1018
|
+
case 1:
|
|
1019
|
+
_a.sent();
|
|
1020
|
+
return [2 /*return*/];
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
644
1023
|
});
|
|
645
1024
|
}
|
|
646
1025
|
function updateAppScopeStringJson(appScopeDir, projectName) {
|
|
647
|
-
return __awaiter(this, void 0, void 0, function
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
1026
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1027
|
+
var appScopeStringJson;
|
|
1028
|
+
return __generator(this, function (_a) {
|
|
1029
|
+
switch (_a.label) {
|
|
1030
|
+
case 0:
|
|
1031
|
+
appScopeStringJson = node_path_1.default.join(appScopeDir, 'resources', 'base', 'element', STRING_JSON);
|
|
1032
|
+
return [4 /*yield*/, FileOperationHelper.updateJsonFile(appScopeStringJson, function (data) {
|
|
1033
|
+
if (Array.isArray(data.string) && data.string.length > 0) {
|
|
1034
|
+
data.string[PROJECT_NAME_INDEX].value = projectName;
|
|
1035
|
+
}
|
|
1036
|
+
return data;
|
|
1037
|
+
}, "Failed to update AppScope ".concat(STRING_JSON, "."))];
|
|
1038
|
+
case 1:
|
|
1039
|
+
_a.sent();
|
|
1040
|
+
return [2 /*return*/];
|
|
652
1041
|
}
|
|
653
|
-
|
|
654
|
-
}, `Failed to update AppScope ${STRING_JSON}.`);
|
|
1042
|
+
});
|
|
655
1043
|
});
|
|
656
1044
|
}
|
|
657
1045
|
function updateEntryIndexEts(entryDir, updateConfig) {
|
|
658
|
-
return __awaiter(this, void 0, void 0, function
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
1046
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1047
|
+
var entryIndexEts, replacedText;
|
|
1048
|
+
return __generator(this, function (_a) {
|
|
1049
|
+
switch (_a.label) {
|
|
1050
|
+
case 0:
|
|
1051
|
+
entryIndexEts = node_path_1.default.join(entryDir, 'src', 'main', 'ets', 'pages', 'Index.ets');
|
|
1052
|
+
replacedText = updateConfig.templateConfig.placeholderName;
|
|
1053
|
+
if (!updateConfig.isHarmonyTemplate && updateConfig.rnohTemplateConfig) {
|
|
1054
|
+
replacedText = updateConfig.rnohTemplateConfig.placeholderName;
|
|
1055
|
+
}
|
|
1056
|
+
return [4 /*yield*/, FileOperationHelper.updateTextFile(entryIndexEts, replacedText, updateConfig.projectName)];
|
|
1057
|
+
case 1:
|
|
1058
|
+
_a.sent();
|
|
1059
|
+
return [2 /*return*/];
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
665
1062
|
});
|
|
666
1063
|
}
|
|
667
1064
|
function updateAppScopeAppJson5(appScopeDir, packageName) {
|
|
668
|
-
return __awaiter(this, void 0, void 0, function
|
|
669
|
-
|
|
670
|
-
|
|
1065
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1066
|
+
var appScopeAppJson5;
|
|
1067
|
+
return __generator(this, function (_a) {
|
|
1068
|
+
switch (_a.label) {
|
|
1069
|
+
case 0:
|
|
1070
|
+
appScopeAppJson5 = node_path_1.default.join(appScopeDir, APP_JSON5);
|
|
1071
|
+
return [4 /*yield*/, FileOperationHelper.updateJsonFile(appScopeAppJson5, function (data) { return (__assign(__assign({}, data), { app: __assign(__assign({}, data.app), { bundleName: packageName }) })); }, "Failed to update AppScope ".concat(APP_JSON5, "."))];
|
|
1072
|
+
case 1:
|
|
1073
|
+
_a.sent();
|
|
1074
|
+
return [2 /*return*/];
|
|
1075
|
+
}
|
|
1076
|
+
});
|
|
671
1077
|
});
|
|
672
1078
|
}
|
|
673
1079
|
function updateEntryStringJson(entryDir, projectName) {
|
|
674
|
-
return __awaiter(this, void 0, void 0, function
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
1080
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1081
|
+
var entryStringJson;
|
|
1082
|
+
return __generator(this, function (_a) {
|
|
1083
|
+
switch (_a.label) {
|
|
1084
|
+
case 0:
|
|
1085
|
+
entryStringJson = node_path_1.default.join(entryDir, 'src', 'main', 'resources', 'base', 'element', STRING_JSON);
|
|
1086
|
+
return [4 /*yield*/, FileOperationHelper.updateJsonFile(entryStringJson, function (data) {
|
|
1087
|
+
if (Array.isArray(data.string)) {
|
|
1088
|
+
data.string.forEach(function (item) {
|
|
1089
|
+
if (item.name === MODULE_DESC || item.name === ENTRY_ABILITY_DESC) {
|
|
1090
|
+
item.value = '';
|
|
1091
|
+
}
|
|
1092
|
+
if (item.name === ENTRY_ABILITY_LABEL) {
|
|
1093
|
+
item.value = projectName;
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
return data;
|
|
1098
|
+
}, "Failed to update entry ".concat(STRING_JSON, "."))];
|
|
1099
|
+
case 1:
|
|
1100
|
+
_a.sent();
|
|
1101
|
+
return [2 /*return*/];
|
|
686
1102
|
}
|
|
687
|
-
|
|
688
|
-
}, `Failed to update entry ${STRING_JSON}.`);
|
|
1103
|
+
});
|
|
689
1104
|
});
|
|
690
1105
|
}
|
|
691
1106
|
function processTemplate(updateConfig) {
|
|
692
|
-
return __awaiter(this, void 0, void 0, function
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
1107
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1108
|
+
return __generator(this, function (_a) {
|
|
1109
|
+
switch (_a.label) {
|
|
1110
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
1111
|
+
updateRNConfigFiles(updateConfig),
|
|
1112
|
+
updateHarmonyFiles(updateConfig),
|
|
1113
|
+
renameDotFiles(updateConfig.destDir),
|
|
1114
|
+
])];
|
|
1115
|
+
case 1:
|
|
1116
|
+
_a.sent();
|
|
1117
|
+
if (!updateConfig.templateConfig.postInitScript) return [3 /*break*/, 3];
|
|
1118
|
+
return [4 /*yield*/, runPostInitScript(updateConfig.templateConfig.postInitScript, updateConfig.templateRoot, updateConfig.destDir, updateConfig.isHarmonyTemplate)];
|
|
1119
|
+
case 2:
|
|
1120
|
+
_a.sent();
|
|
1121
|
+
_a.label = 3;
|
|
1122
|
+
case 3: return [2 /*return*/];
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
701
1125
|
});
|
|
702
1126
|
}
|
|
703
1127
|
rnohInit();
|