@oniroproject/core 0.6.0 → 0.6.2
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 +25 -0
- package/dist/index.cjs +133 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +131 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @oniroproject/core
|
|
2
|
+
|
|
3
|
+
Shared library powering the Oniro/OpenHarmony app-development toolchain. Wraps SDK install, command-line tools install, project scaffolding, signing-config generation, `hvigorw` builds, emulator lifecycle, `hdc` install/launch, and hilog streaming — all behind a vscode-agnostic API that runs on Linux, macOS, and Windows.
|
|
4
|
+
|
|
5
|
+
This package backs [`@oniroproject/oniro-app`](https://www.npmjs.com/package/@oniroproject/oniro-app) (the `oniro-app` CLI). If you just want to build/run Oniro apps from a shell, install the CLI; install this library directly if you're embedding the same functionality into an editor extension or another tool.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @oniroproject/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Node.js 20+.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { installSdk, signProject, buildProject } from '@oniroproject/core';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The exported surface mirrors what the CLI exposes — SDK/cmd-tools/emulator install + lifecycle, project create, sign, build, hdc install/launch, hilog parsing. See the [repository README](https://github.com/eclipse-oniro4openharmony/oniro-app-builder#readme) for the high-level workflow.
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
Apache-2.0
|
package/dist/index.cjs
CHANGED
|
@@ -49,6 +49,7 @@ __export(index_exports, {
|
|
|
49
49
|
defaultContext: () => defaultContext,
|
|
50
50
|
defaultPaths: () => defaultPaths,
|
|
51
51
|
detectProjectSdkVersion: () => detectProjectSdkVersion,
|
|
52
|
+
detectSigningConfigNames: () => detectSigningConfigNames,
|
|
52
53
|
downloadAndInstallSdk: () => downloadAndInstallSdk,
|
|
53
54
|
downloadFile: () => downloadFile,
|
|
54
55
|
encryptPwd: () => encryptPwd,
|
|
@@ -87,6 +88,7 @@ __export(index_exports, {
|
|
|
87
88
|
noopLogger: () => noopLogger,
|
|
88
89
|
noopProgress: () => noopProgress,
|
|
89
90
|
parseHilogLine: () => parseHilogLine,
|
|
91
|
+
pickSigningKind: () => pickSigningKind,
|
|
90
92
|
readJson5File: () => readJson5File,
|
|
91
93
|
readJsonFile: () => readJsonFile,
|
|
92
94
|
removeCmdTools: () => removeCmdTools,
|
|
@@ -929,25 +931,101 @@ var fs10 = __toESM(require("fs"), 1);
|
|
|
929
931
|
var path10 = __toESM(require("path"), 1);
|
|
930
932
|
var import_node_child_process2 = require("child_process");
|
|
931
933
|
var import_json52 = __toESM(require("json5"), 1);
|
|
934
|
+
|
|
935
|
+
// src/sign/applicationCert.ts
|
|
936
|
+
var OPEN_HARMONY_APPLICATION_CERT = `-----BEGIN CERTIFICATE-----
|
|
937
|
+
MIICRDCCAcmgAwIBAgIED+E4izAMBggqhkjOPQQDAwUAMGgxCzAJBgNVBAYTAkNO
|
|
938
|
+
MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh
|
|
939
|
+
bTEoMCYGA1UEAxMfT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gUm9vdCBDQTAeFw0y
|
|
940
|
+
MTAyMDIxMjE0MThaFw00OTEyMzExMjE0MThaMGgxCzAJBgNVBAYTAkNOMRQwEgYD
|
|
941
|
+
VQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVhbTEoMCYG
|
|
942
|
+
A1UEAxMfT3Blbkhhcm1vbnkgQXBwbGlj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sHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci
|
|
975
|
+
FtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl
|
|
976
|
+
cRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps
|
|
977
|
+
LMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o
|
|
978
|
+
zAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/
|
|
979
|
+
-----END CERTIFICATE-----
|
|
980
|
+
`;
|
|
981
|
+
|
|
982
|
+
// src/sign/generateSigningConfigs.ts
|
|
932
983
|
var APL_VALUES = ["normal", "system_basic", "system_core"];
|
|
933
984
|
var APP_FEATURE_VALUES = ["hos_normal_app", "hos_system_app"];
|
|
934
|
-
function
|
|
985
|
+
function pickSigningKind(apl) {
|
|
986
|
+
return apl === "normal" ? "profile-release" : "application-release";
|
|
987
|
+
}
|
|
988
|
+
var SIGNING_KIND_CONFIG = {
|
|
989
|
+
"profile-release": {
|
|
990
|
+
hapKeyAlias: "openharmony application profile release",
|
|
991
|
+
certBasename: "OpenHarmonyProfileRelease.pem"
|
|
992
|
+
},
|
|
993
|
+
"application-release": {
|
|
994
|
+
hapKeyAlias: "OpenHarmony Application Release",
|
|
995
|
+
certBasename: "OpenHarmonyApplication.cer"
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
function copyFilesToProject(projectDir, paths, kind, logger) {
|
|
935
999
|
logger.info("[sign] Copying signing material into project...");
|
|
936
1000
|
const signaturesDir = path10.join(projectDir, "signatures");
|
|
937
1001
|
fs10.mkdirSync(signaturesDir, { recursive: true });
|
|
938
1002
|
fs10.copyFileSync(paths.keystore, path10.join(signaturesDir, "OpenHarmony.p12"));
|
|
939
1003
|
fs10.copyFileSync(paths.profileCert, path10.join(signaturesDir, "OpenHarmonyProfileRelease.pem"));
|
|
940
1004
|
fs10.copyFileSync(paths.unsignedProfileTemplate, path10.join(signaturesDir, "UnsgnedReleasedProfileTemplate.json"));
|
|
1005
|
+
if (kind === "application-release") {
|
|
1006
|
+
fs10.writeFileSync(
|
|
1007
|
+
path10.join(signaturesDir, "OpenHarmonyApplication.cer"),
|
|
1008
|
+
OPEN_HARMONY_APPLICATION_CERT
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
941
1011
|
}
|
|
942
1012
|
function resolveAppFeature(apl, override) {
|
|
943
1013
|
if (override) return override;
|
|
944
1014
|
return apl === "normal" ? "hos_normal_app" : "hos_system_app";
|
|
945
1015
|
}
|
|
946
|
-
function
|
|
947
|
-
|
|
1016
|
+
function extractLeafCertificate(chainPath) {
|
|
1017
|
+
const certContent = fs10.readFileSync(chainPath, "utf-8");
|
|
1018
|
+
const parts = certContent.split("-----END CERTIFICATE-----");
|
|
1019
|
+
if (parts.length < 3) {
|
|
1020
|
+
throw new OniroError(`${chainPath} does not contain enough certificates.`);
|
|
1021
|
+
}
|
|
1022
|
+
return parts[2].trim() + "\n-----END CERTIFICATE-----\n";
|
|
1023
|
+
}
|
|
1024
|
+
function modifyProfileTemplate(projectDir, apl, appFeature, logger, options = {}) {
|
|
1025
|
+
const kind = options.kind ?? pickSigningKind(apl);
|
|
1026
|
+
logger.info(`[sign] Modifying profile template (apl=${apl}, app-feature=${appFeature}, kind=${kind})...`);
|
|
948
1027
|
const appJsonPath = path10.join(projectDir, "AppScope/app.json5");
|
|
949
1028
|
const profileTemplatePath = path10.join(projectDir, "signatures/UnsgnedReleasedProfileTemplate.json");
|
|
950
|
-
const profileCertFilePath = path10.join(projectDir, "signatures/OpenHarmonyProfileRelease.pem");
|
|
951
1029
|
if (!fs10.existsSync(appJsonPath)) {
|
|
952
1030
|
throw new OniroError(`${appJsonPath} does not exist.`);
|
|
953
1031
|
}
|
|
@@ -972,13 +1050,16 @@ function modifyProfileTemplate(projectDir, apl, appFeature, logger) {
|
|
|
972
1050
|
profileTemplate["bundle-info"]["bundle-name"] = appJson.app.bundleName;
|
|
973
1051
|
profileTemplate["bundle-info"]["apl"] = apl;
|
|
974
1052
|
profileTemplate["bundle-info"]["app-feature"] = appFeature;
|
|
975
|
-
const
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1053
|
+
const distCertChainPath = path10.join(
|
|
1054
|
+
projectDir,
|
|
1055
|
+
"signatures",
|
|
1056
|
+
SIGNING_KIND_CONFIG[kind].certBasename
|
|
1057
|
+
);
|
|
1058
|
+
profileTemplate["bundle-info"]["distribution-certificate"] = extractLeafCertificate(distCertChainPath);
|
|
1059
|
+
if (options.acls !== void 0) {
|
|
1060
|
+
profileTemplate.acls = profileTemplate.acls ?? {};
|
|
1061
|
+
profileTemplate.acls["allowed-acls"] = options.acls;
|
|
979
1062
|
}
|
|
980
|
-
const thirdCert = certs[2].trim() + "\n-----END CERTIFICATE-----\n";
|
|
981
|
-
profileTemplate["bundle-info"]["distribution-certificate"] = thirdCert;
|
|
982
1063
|
fs10.writeFileSync(profileTemplatePath, JSON.stringify(profileTemplate, null, 2));
|
|
983
1064
|
}
|
|
984
1065
|
function generateP7bFile(projectDir, paths, logger) {
|
|
@@ -1018,7 +1099,27 @@ function generateP7bFile(projectDir, paths, logger) {
|
|
|
1018
1099
|
);
|
|
1019
1100
|
}
|
|
1020
1101
|
}
|
|
1021
|
-
function
|
|
1102
|
+
function detectSigningConfigNames(projectDir) {
|
|
1103
|
+
const buildProfilePath = path10.join(projectDir, "build-profile.json5");
|
|
1104
|
+
if (!fs10.existsSync(buildProfilePath)) return ["default"];
|
|
1105
|
+
let parsed;
|
|
1106
|
+
try {
|
|
1107
|
+
parsed = import_json52.default.parse(fs10.readFileSync(buildProfilePath, "utf-8"));
|
|
1108
|
+
} catch {
|
|
1109
|
+
return ["default"];
|
|
1110
|
+
}
|
|
1111
|
+
const products = parsed.app?.products;
|
|
1112
|
+
if (!Array.isArray(products) || products.length === 0) return ["default"];
|
|
1113
|
+
const names = [];
|
|
1114
|
+
for (const product of products) {
|
|
1115
|
+
const name = product.signingConfig;
|
|
1116
|
+
if (typeof name === "string" && name.length > 0 && !names.includes(name)) {
|
|
1117
|
+
names.push(name);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
return names.length > 0 ? names : ["default"];
|
|
1121
|
+
}
|
|
1122
|
+
function updateBuildProfile(projectDir, kind, logger) {
|
|
1022
1123
|
logger.info("[sign] Writing signing configs into build-profile.json5...");
|
|
1023
1124
|
const materialDir = path10.join(projectDir, "signatures", "material");
|
|
1024
1125
|
const buildProfilePath = path10.join(projectDir, "build-profile.json5");
|
|
@@ -1032,21 +1133,22 @@ function updateBuildProfile(projectDir, logger) {
|
|
|
1032
1133
|
throw new OniroError(`Error parsing ${buildProfilePath}: ${e.message}`, e);
|
|
1033
1134
|
}
|
|
1034
1135
|
}
|
|
1136
|
+
const { hapKeyAlias, certBasename } = SIGNING_KIND_CONFIG[kind];
|
|
1137
|
+
const configNames = detectSigningConfigNames(projectDir);
|
|
1138
|
+
logger.info(`[sign] Writing signingConfigs entries: ${configNames.join(", ")}`);
|
|
1035
1139
|
buildProfile.app = buildProfile.app ?? {};
|
|
1036
|
-
buildProfile.app.signingConfigs =
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
storeFile: "./signatures/OpenHarmony.p12"
|
|
1047
|
-
}
|
|
1140
|
+
buildProfile.app.signingConfigs = configNames.map((name) => ({
|
|
1141
|
+
name,
|
|
1142
|
+
material: {
|
|
1143
|
+
certpath: `./signatures/${certBasename}`,
|
|
1144
|
+
storePassword: encryptedStorePassword,
|
|
1145
|
+
keyAlias: hapKeyAlias,
|
|
1146
|
+
keyPassword: encryptedKeyPassword,
|
|
1147
|
+
profile: "./signatures/app1-profile.p7b",
|
|
1148
|
+
signAlg: "SHA256withECDSA",
|
|
1149
|
+
storeFile: "./signatures/OpenHarmony.p12"
|
|
1048
1150
|
}
|
|
1049
|
-
|
|
1151
|
+
}));
|
|
1050
1152
|
fs10.writeFileSync(buildProfilePath, JSON.stringify(buildProfile, null, 2));
|
|
1051
1153
|
}
|
|
1052
1154
|
function prepareMaterialDirectory(projectDir, logger) {
|
|
@@ -1086,12 +1188,13 @@ function generateSigningConfigs(options) {
|
|
|
1086
1188
|
profileCert: path10.join(sdkPath, "toolchains/lib/OpenHarmonyProfileRelease.pem"),
|
|
1087
1189
|
unsignedProfileTemplate: path10.join(sdkPath, "toolchains/lib/UnsgnedReleasedProfileTemplate.json")
|
|
1088
1190
|
};
|
|
1191
|
+
const kind = pickSigningKind(apl);
|
|
1089
1192
|
logger.info("[sign] Starting signing configuration generation...");
|
|
1090
|
-
copyFilesToProject(projectDir, paths, logger);
|
|
1091
|
-
modifyProfileTemplate(projectDir, apl, appFeature, logger);
|
|
1193
|
+
copyFilesToProject(projectDir, paths, kind, logger);
|
|
1194
|
+
modifyProfileTemplate(projectDir, apl, appFeature, logger, { kind, acls: options.acls });
|
|
1092
1195
|
generateP7bFile(projectDir, paths, logger);
|
|
1093
1196
|
prepareMaterialDirectory(projectDir, logger);
|
|
1094
|
-
updateBuildProfile(projectDir, logger);
|
|
1197
|
+
updateBuildProfile(projectDir, kind, logger);
|
|
1095
1198
|
logger.info("[sign] Signing configuration generated successfully.");
|
|
1096
1199
|
}
|
|
1097
1200
|
|
|
@@ -1777,7 +1880,7 @@ async function createScaffold(opts) {
|
|
|
1777
1880
|
}
|
|
1778
1881
|
|
|
1779
1882
|
// src/index.ts
|
|
1780
|
-
var VERSION = "0.6.
|
|
1883
|
+
var VERSION = "0.6.2";
|
|
1781
1884
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1782
1885
|
0 && (module.exports = {
|
|
1783
1886
|
ALL_SDKS,
|
|
@@ -1799,6 +1902,7 @@ var VERSION = "0.6.0";
|
|
|
1799
1902
|
defaultContext,
|
|
1800
1903
|
defaultPaths,
|
|
1801
1904
|
detectProjectSdkVersion,
|
|
1905
|
+
detectSigningConfigNames,
|
|
1802
1906
|
downloadAndInstallSdk,
|
|
1803
1907
|
downloadFile,
|
|
1804
1908
|
encryptPwd,
|
|
@@ -1837,6 +1941,7 @@ var VERSION = "0.6.0";
|
|
|
1837
1941
|
noopLogger,
|
|
1838
1942
|
noopProgress,
|
|
1839
1943
|
parseHilogLine,
|
|
1944
|
+
pickSigningKind,
|
|
1840
1945
|
readJson5File,
|
|
1841
1946
|
readJsonFile,
|
|
1842
1947
|
removeCmdTools,
|