@arkts/image-manager 0.2.1 → 0.2.3
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/default-product-config.cjs +4 -2
- package/dist/default-product-config.mjs +4 -2
- package/dist/index.cjs +53 -13
- package/dist/index.d.cts +18 -1
- package/dist/index.d.mts +18 -1
- package/dist/index.mjs +48 -14
- package/package.json +1 -1
|
@@ -9,7 +9,8 @@ var default_product_config_default = {
|
|
|
9
9
|
screenDiagonal: "6.84",
|
|
10
10
|
screenDensity: "560",
|
|
11
11
|
oneCutoutPath: "M517 45 L802 45 v 103 h -285 Z",
|
|
12
|
-
visible: true
|
|
12
|
+
visible: true,
|
|
13
|
+
devModel: "PHEMU-FD00"
|
|
13
14
|
},
|
|
14
15
|
{
|
|
15
16
|
name: "nova 15",
|
|
@@ -18,7 +19,8 @@ var default_product_config_default = {
|
|
|
18
19
|
screenDiagonal: "6.7",
|
|
19
20
|
screenDensity: "480",
|
|
20
21
|
oneCutoutPath: "M504 16 L580 16 v 76 h -76 Z",
|
|
21
|
-
visible: true
|
|
22
|
+
visible: true,
|
|
23
|
+
devModel: "PHEMU-FD00"
|
|
22
24
|
},
|
|
23
25
|
{
|
|
24
26
|
name: "Mate 80 Pro Max、Mate 80 RS",
|
|
@@ -8,7 +8,8 @@ var default_product_config_default = {
|
|
|
8
8
|
screenDiagonal: "6.84",
|
|
9
9
|
screenDensity: "560",
|
|
10
10
|
oneCutoutPath: "M517 45 L802 45 v 103 h -285 Z",
|
|
11
|
-
visible: true
|
|
11
|
+
visible: true,
|
|
12
|
+
devModel: "PHEMU-FD00"
|
|
12
13
|
},
|
|
13
14
|
{
|
|
14
15
|
name: "nova 15",
|
|
@@ -17,7 +18,8 @@ var default_product_config_default = {
|
|
|
17
18
|
screenDiagonal: "6.7",
|
|
18
19
|
screenDensity: "480",
|
|
19
20
|
oneCutoutPath: "M504 16 L580 16 v 76 h -76 Z",
|
|
20
|
-
visible: true
|
|
21
|
+
visible: true,
|
|
22
|
+
devModel: "PHEMU-FD00"
|
|
21
23
|
},
|
|
22
24
|
{
|
|
23
25
|
name: "Mate 80 Pro Max、Mate 80 RS",
|
package/dist/index.cjs
CHANGED
|
@@ -36,7 +36,7 @@ let unzipper = require("unzipper");
|
|
|
36
36
|
unzipper = __toESM(unzipper);
|
|
37
37
|
|
|
38
38
|
//#region package.json
|
|
39
|
-
var version = "0.2.
|
|
39
|
+
var version = "0.2.3";
|
|
40
40
|
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region src/deployer/list.ts
|
|
@@ -51,6 +51,27 @@ let DevModel = /* @__PURE__ */ function(DevModel) {
|
|
|
51
51
|
return DevModel;
|
|
52
52
|
}({});
|
|
53
53
|
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/errors/deploy-error.ts
|
|
56
|
+
var DeployError = class extends Error {
|
|
57
|
+
constructor(code, message, cause) {
|
|
58
|
+
super(message, { cause });
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.message = message;
|
|
61
|
+
this.cause = cause;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
(function(_DeployError) {
|
|
65
|
+
_DeployError.Code = /* @__PURE__ */ function(Code) {
|
|
66
|
+
Code["DEVICE_ALREADY_DEPLOYED"] = "DEVICE_ALREADY_DEPLOYED";
|
|
67
|
+
Code["LIST_JSON_NOT_AN_ARRAY"] = "LIST_JSON_NOT_AN_ARRAY";
|
|
68
|
+
Code["CATCHED_ERROR"] = "CATCHED_ERROR";
|
|
69
|
+
Code["MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO"] = "MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO";
|
|
70
|
+
Code["SYMLINK_SDK_PATH_EXISTS"] = "SYMLINK_SDK_PATH_EXISTS";
|
|
71
|
+
return Code;
|
|
72
|
+
}({});
|
|
73
|
+
})(DeployError || (DeployError = {}));
|
|
74
|
+
|
|
54
75
|
//#endregion
|
|
55
76
|
//#region src/errors/request-url-error.ts
|
|
56
77
|
var RequestUrlError = class extends Error {
|
|
@@ -207,23 +228,36 @@ var ImageDeployerImpl = class {
|
|
|
207
228
|
async toIniString() {
|
|
208
229
|
return `${Object.entries(await this.buildIni()).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
|
|
209
230
|
}
|
|
210
|
-
|
|
231
|
+
async writeToListWithCheck(config) {
|
|
211
232
|
const fs = this.image.getImageManager().getOptions().fs;
|
|
212
233
|
const listsPath = this.image.getImageManager().getOptions().path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
234
|
+
try {
|
|
235
|
+
if (!fs.existsSync(listsPath)) fs.writeFileSync(listsPath, JSON.stringify([config], null, 2));
|
|
236
|
+
else {
|
|
237
|
+
const lists = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
|
|
238
|
+
if (!Array.isArray(lists)) return new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "Lists is not an array");
|
|
239
|
+
if (lists.find((item) => item.name === config.name)) return;
|
|
240
|
+
lists.push(config);
|
|
241
|
+
fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
|
|
242
|
+
}
|
|
243
|
+
} catch (err) {
|
|
244
|
+
return err instanceof Error ? new DeployError(DeployError.Code.CATCHED_ERROR, String(err)) : new DeployError(DeployError.Code.CATCHED_ERROR, String(err));
|
|
220
245
|
}
|
|
246
|
+
return new Promise((resolve) => {
|
|
247
|
+
const timer = setTimeout(() => {
|
|
248
|
+
const content = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
|
|
249
|
+
if (!Array.isArray(content)) resolve(new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "List rechecker is not an array!"));
|
|
250
|
+
else if (!content.find((item) => item.name === config.name)) resolve(new DeployError(DeployError.Code.MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO, `Device ${config.name} not found in lists.json! Maybe not deployed yet?`));
|
|
251
|
+
else resolve();
|
|
252
|
+
clearTimeout(timer);
|
|
253
|
+
}, 1e3);
|
|
254
|
+
});
|
|
221
255
|
}
|
|
222
256
|
async deploy(symlinkImage = true) {
|
|
223
257
|
const { fs, path, imageBasePath, sdkPath } = this.image.getImageManager().getOptions();
|
|
224
258
|
const config = await this.buildList();
|
|
225
|
-
if (fs.existsSync(config.path)) return
|
|
226
|
-
const error = this.
|
|
259
|
+
if (fs.existsSync(config.path)) return new DeployError(DeployError.Code.DEVICE_ALREADY_DEPLOYED, `Image ${config.name} already deployed`);
|
|
260
|
+
const error = await this.writeToListWithCheck(config);
|
|
227
261
|
if (error) return error;
|
|
228
262
|
fs.mkdirSync(config.path, { recursive: true });
|
|
229
263
|
fs.writeFileSync(path.join(config.path, "config.ini"), await this.toIniString());
|
|
@@ -231,7 +265,7 @@ var ImageDeployerImpl = class {
|
|
|
231
265
|
if (!fs.existsSync(path.dirname(symlinkSdkPath))) fs.mkdirSync(path.dirname(symlinkSdkPath), { recursive: true });
|
|
232
266
|
try {
|
|
233
267
|
if (fs.lstatSync(symlinkSdkPath).isSymbolicLink()) fs.unlinkSync(symlinkSdkPath);
|
|
234
|
-
else return
|
|
268
|
+
else return new DeployError(DeployError.Code.SYMLINK_SDK_PATH_EXISTS, "Symlink SDK path already exists");
|
|
235
269
|
} catch {}
|
|
236
270
|
fs.symlinkSync(sdkPath, symlinkSdkPath, "dir");
|
|
237
271
|
const systemImageDir = path.join(imageBasePath, "system-image");
|
|
@@ -241,7 +275,7 @@ var ImageDeployerImpl = class {
|
|
|
241
275
|
const target = path.relative(config.path, systemImageDir);
|
|
242
276
|
fs.symlinkSync(target, linkPath);
|
|
243
277
|
} catch (err) {
|
|
244
|
-
return err instanceof Error ? err : new
|
|
278
|
+
return err instanceof Error ? new DeployError(DeployError.Code.CATCHED_ERROR, String(err)) : new DeployError(DeployError.Code.CATCHED_ERROR, String(err));
|
|
245
279
|
}
|
|
246
280
|
}
|
|
247
281
|
}
|
|
@@ -718,6 +752,12 @@ function createDeployedImageConfig(productConfigItem) {
|
|
|
718
752
|
}
|
|
719
753
|
|
|
720
754
|
//#endregion
|
|
755
|
+
Object.defineProperty(exports, 'DeployError', {
|
|
756
|
+
enumerable: true,
|
|
757
|
+
get: function () {
|
|
758
|
+
return DeployError;
|
|
759
|
+
}
|
|
760
|
+
});
|
|
721
761
|
exports.DevModel = DevModel;
|
|
722
762
|
exports.RequestUrlError = RequestUrlError;
|
|
723
763
|
exports.createDeployedImageConfig = createDeployedImageConfig;
|
package/dist/index.d.cts
CHANGED
|
@@ -190,6 +190,23 @@ interface ImageManager {
|
|
|
190
190
|
}
|
|
191
191
|
declare function createImageManager(options?: ImageManagerOptions): Promise<ImageManager>;
|
|
192
192
|
//#endregion
|
|
193
|
+
//#region src/errors/deploy-error.d.ts
|
|
194
|
+
declare class DeployError extends Error {
|
|
195
|
+
readonly code: DeployError.Code;
|
|
196
|
+
readonly message: string;
|
|
197
|
+
readonly cause?: Error;
|
|
198
|
+
constructor(code: DeployError.Code, message: string, cause?: Error);
|
|
199
|
+
}
|
|
200
|
+
declare namespace DeployError {
|
|
201
|
+
enum Code {
|
|
202
|
+
DEVICE_ALREADY_DEPLOYED = "DEVICE_ALREADY_DEPLOYED",
|
|
203
|
+
LIST_JSON_NOT_AN_ARRAY = "LIST_JSON_NOT_AN_ARRAY",
|
|
204
|
+
CATCHED_ERROR = "CATCHED_ERROR",
|
|
205
|
+
MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO = "MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO",
|
|
206
|
+
SYMLINK_SDK_PATH_EXISTS = "SYMLINK_SDK_PATH_EXISTS"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
//#endregion
|
|
193
210
|
//#region src/errors/request-url-error.d.ts
|
|
194
211
|
declare class RequestUrlError extends Error {
|
|
195
212
|
readonly message: string;
|
|
@@ -287,4 +304,4 @@ interface Device {
|
|
|
287
304
|
delete(): Promise<void | Error>;
|
|
288
305
|
}
|
|
289
306
|
//#endregion
|
|
290
|
-
export { Arch, DeployedDevModel, DeployedImageConfig, DeployedImageConfigWithProductName, DeployedImageOptions, DevModel, Device, DeviceType, FullDeployedImageOptions, Image, type ImageManager, type ImageManagerOptions, ImageType, LocalImage, OS, PascalCaseDeviceType, type ProductConfig, type ProductConfigItem, ProductNameable, RemoteImage, RequestUrlError, SnakecaseDeviceType, Stringifiable, createDeployedImageConfig, createImageManager, version };
|
|
307
|
+
export { Arch, DeployError, DeployedDevModel, DeployedImageConfig, DeployedImageConfigWithProductName, DeployedImageOptions, DevModel, Device, DeviceType, FullDeployedImageOptions, Image, type ImageManager, type ImageManagerOptions, ImageType, LocalImage, OS, PascalCaseDeviceType, type ProductConfig, type ProductConfigItem, ProductNameable, RemoteImage, RequestUrlError, SnakecaseDeviceType, Stringifiable, createDeployedImageConfig, createImageManager, version };
|
package/dist/index.d.mts
CHANGED
|
@@ -190,6 +190,23 @@ interface ImageManager {
|
|
|
190
190
|
}
|
|
191
191
|
declare function createImageManager(options?: ImageManagerOptions): Promise<ImageManager>;
|
|
192
192
|
//#endregion
|
|
193
|
+
//#region src/errors/deploy-error.d.ts
|
|
194
|
+
declare class DeployError extends Error {
|
|
195
|
+
readonly code: DeployError.Code;
|
|
196
|
+
readonly message: string;
|
|
197
|
+
readonly cause?: Error;
|
|
198
|
+
constructor(code: DeployError.Code, message: string, cause?: Error);
|
|
199
|
+
}
|
|
200
|
+
declare namespace DeployError {
|
|
201
|
+
enum Code {
|
|
202
|
+
DEVICE_ALREADY_DEPLOYED = "DEVICE_ALREADY_DEPLOYED",
|
|
203
|
+
LIST_JSON_NOT_AN_ARRAY = "LIST_JSON_NOT_AN_ARRAY",
|
|
204
|
+
CATCHED_ERROR = "CATCHED_ERROR",
|
|
205
|
+
MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO = "MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO",
|
|
206
|
+
SYMLINK_SDK_PATH_EXISTS = "SYMLINK_SDK_PATH_EXISTS"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
//#endregion
|
|
193
210
|
//#region src/errors/request-url-error.d.ts
|
|
194
211
|
declare class RequestUrlError extends Error {
|
|
195
212
|
readonly message: string;
|
|
@@ -287,4 +304,4 @@ interface Device {
|
|
|
287
304
|
delete(): Promise<void | Error>;
|
|
288
305
|
}
|
|
289
306
|
//#endregion
|
|
290
|
-
export { Arch, DeployedDevModel, DeployedImageConfig, DeployedImageConfigWithProductName, DeployedImageOptions, DevModel, type Device, DeviceType, FullDeployedImageOptions, type Image, type ImageManager, type ImageManagerOptions, type ImageType, type LocalImage, OS, PascalCaseDeviceType, type ProductConfig, type ProductConfigItem, ProductNameable, type RemoteImage, RequestUrlError, SnakecaseDeviceType, Stringifiable, createDeployedImageConfig, createImageManager, version };
|
|
307
|
+
export { Arch, DeployError, DeployedDevModel, DeployedImageConfig, DeployedImageConfigWithProductName, DeployedImageOptions, DevModel, type Device, DeviceType, FullDeployedImageOptions, type Image, type ImageManager, type ImageManagerOptions, type ImageType, type LocalImage, OS, PascalCaseDeviceType, type ProductConfig, type ProductConfigItem, ProductNameable, type RemoteImage, RequestUrlError, SnakecaseDeviceType, Stringifiable, createDeployedImageConfig, createImageManager, version };
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import progress from "progress-stream";
|
|
|
4
4
|
import unzipper from "unzipper";
|
|
5
5
|
|
|
6
6
|
//#region package.json
|
|
7
|
-
var version = "0.2.
|
|
7
|
+
var version = "0.2.3";
|
|
8
8
|
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/deployer/list.ts
|
|
@@ -19,6 +19,27 @@ let DevModel = /* @__PURE__ */ function(DevModel) {
|
|
|
19
19
|
return DevModel;
|
|
20
20
|
}({});
|
|
21
21
|
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/errors/deploy-error.ts
|
|
24
|
+
var DeployError = class extends Error {
|
|
25
|
+
constructor(code, message, cause) {
|
|
26
|
+
super(message, { cause });
|
|
27
|
+
this.code = code;
|
|
28
|
+
this.message = message;
|
|
29
|
+
this.cause = cause;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
(function(_DeployError) {
|
|
33
|
+
_DeployError.Code = /* @__PURE__ */ function(Code) {
|
|
34
|
+
Code["DEVICE_ALREADY_DEPLOYED"] = "DEVICE_ALREADY_DEPLOYED";
|
|
35
|
+
Code["LIST_JSON_NOT_AN_ARRAY"] = "LIST_JSON_NOT_AN_ARRAY";
|
|
36
|
+
Code["CATCHED_ERROR"] = "CATCHED_ERROR";
|
|
37
|
+
Code["MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO"] = "MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO";
|
|
38
|
+
Code["SYMLINK_SDK_PATH_EXISTS"] = "SYMLINK_SDK_PATH_EXISTS";
|
|
39
|
+
return Code;
|
|
40
|
+
}({});
|
|
41
|
+
})(DeployError || (DeployError = {}));
|
|
42
|
+
|
|
22
43
|
//#endregion
|
|
23
44
|
//#region src/errors/request-url-error.ts
|
|
24
45
|
var RequestUrlError = class extends Error {
|
|
@@ -175,23 +196,36 @@ var ImageDeployerImpl = class {
|
|
|
175
196
|
async toIniString() {
|
|
176
197
|
return `${Object.entries(await this.buildIni()).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
|
|
177
198
|
}
|
|
178
|
-
|
|
199
|
+
async writeToListWithCheck(config) {
|
|
179
200
|
const fs = this.image.getImageManager().getOptions().fs;
|
|
180
201
|
const listsPath = this.image.getImageManager().getOptions().path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
202
|
+
try {
|
|
203
|
+
if (!fs.existsSync(listsPath)) fs.writeFileSync(listsPath, JSON.stringify([config], null, 2));
|
|
204
|
+
else {
|
|
205
|
+
const lists = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
|
|
206
|
+
if (!Array.isArray(lists)) return new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "Lists is not an array");
|
|
207
|
+
if (lists.find((item) => item.name === config.name)) return;
|
|
208
|
+
lists.push(config);
|
|
209
|
+
fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
|
|
210
|
+
}
|
|
211
|
+
} catch (err) {
|
|
212
|
+
return err instanceof Error ? new DeployError(DeployError.Code.CATCHED_ERROR, String(err)) : new DeployError(DeployError.Code.CATCHED_ERROR, String(err));
|
|
188
213
|
}
|
|
214
|
+
return new Promise((resolve) => {
|
|
215
|
+
const timer = setTimeout(() => {
|
|
216
|
+
const content = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
|
|
217
|
+
if (!Array.isArray(content)) resolve(new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "List rechecker is not an array!"));
|
|
218
|
+
else if (!content.find((item) => item.name === config.name)) resolve(new DeployError(DeployError.Code.MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO, `Device ${config.name} not found in lists.json! Maybe not deployed yet?`));
|
|
219
|
+
else resolve();
|
|
220
|
+
clearTimeout(timer);
|
|
221
|
+
}, 1e3);
|
|
222
|
+
});
|
|
189
223
|
}
|
|
190
224
|
async deploy(symlinkImage = true) {
|
|
191
225
|
const { fs, path, imageBasePath, sdkPath } = this.image.getImageManager().getOptions();
|
|
192
226
|
const config = await this.buildList();
|
|
193
|
-
if (fs.existsSync(config.path)) return
|
|
194
|
-
const error = this.
|
|
227
|
+
if (fs.existsSync(config.path)) return new DeployError(DeployError.Code.DEVICE_ALREADY_DEPLOYED, `Image ${config.name} already deployed`);
|
|
228
|
+
const error = await this.writeToListWithCheck(config);
|
|
195
229
|
if (error) return error;
|
|
196
230
|
fs.mkdirSync(config.path, { recursive: true });
|
|
197
231
|
fs.writeFileSync(path.join(config.path, "config.ini"), await this.toIniString());
|
|
@@ -199,7 +233,7 @@ var ImageDeployerImpl = class {
|
|
|
199
233
|
if (!fs.existsSync(path.dirname(symlinkSdkPath))) fs.mkdirSync(path.dirname(symlinkSdkPath), { recursive: true });
|
|
200
234
|
try {
|
|
201
235
|
if (fs.lstatSync(symlinkSdkPath).isSymbolicLink()) fs.unlinkSync(symlinkSdkPath);
|
|
202
|
-
else return
|
|
236
|
+
else return new DeployError(DeployError.Code.SYMLINK_SDK_PATH_EXISTS, "Symlink SDK path already exists");
|
|
203
237
|
} catch {}
|
|
204
238
|
fs.symlinkSync(sdkPath, symlinkSdkPath, "dir");
|
|
205
239
|
const systemImageDir = path.join(imageBasePath, "system-image");
|
|
@@ -209,7 +243,7 @@ var ImageDeployerImpl = class {
|
|
|
209
243
|
const target = path.relative(config.path, systemImageDir);
|
|
210
244
|
fs.symlinkSync(target, linkPath);
|
|
211
245
|
} catch (err) {
|
|
212
|
-
return err instanceof Error ? err : new
|
|
246
|
+
return err instanceof Error ? new DeployError(DeployError.Code.CATCHED_ERROR, String(err)) : new DeployError(DeployError.Code.CATCHED_ERROR, String(err));
|
|
213
247
|
}
|
|
214
248
|
}
|
|
215
249
|
}
|
|
@@ -686,4 +720,4 @@ function createDeployedImageConfig(productConfigItem) {
|
|
|
686
720
|
}
|
|
687
721
|
|
|
688
722
|
//#endregion
|
|
689
|
-
export { DevModel, RequestUrlError, createDeployedImageConfig, createImageManager, version };
|
|
723
|
+
export { DeployError, DevModel, RequestUrlError, createDeployedImageConfig, createImageManager, version };
|
package/package.json
CHANGED