@arkts/image-manager 0.1.1 → 0.1.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/README.md +8 -8
- package/dist/default-product-config.d.cts +1 -1
- package/dist/default-product-config.d.mts +1 -1
- package/dist/index.cjs +41 -3
- package/dist/index.d.cts +22 -9
- package/dist/index.d.mts +22 -9
- package/dist/index.mjs +41 -3
- package/dist/{product-config-BthHVWvs.d.mts → product-config-DtWd8ReR.d.mts} +9 -1
- package/dist/{product-config-KZA5hTtZ.d.cts → product-config-sobL53MD.d.cts} +9 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,33 +49,33 @@ async function main() {
|
|
|
49
49
|
throw new Error('MateBook Fold not found')
|
|
50
50
|
|
|
51
51
|
// Create the deployer
|
|
52
|
-
const
|
|
52
|
+
const device = image.createDevice('MateBook Fold', createDeployedImageConfig(image))
|
|
53
53
|
.setCpuNumber(4)
|
|
54
54
|
.setMemoryRamSize(4096)
|
|
55
55
|
.setDataDiskSize(6144)
|
|
56
56
|
|
|
57
57
|
// We can get the final deployed image options,
|
|
58
58
|
// it will be written to the `imageBasePath/lists.json` file when deployed.
|
|
59
|
-
const list = await
|
|
59
|
+
const list = await device.buildList()
|
|
60
60
|
console.warn(list)
|
|
61
61
|
|
|
62
62
|
// We can get the `config.ini` object,
|
|
63
63
|
// it will be written to the `deployedPath/MateBook Fold/config.ini` file when deployed.
|
|
64
|
-
const config = await
|
|
64
|
+
const config = await device.buildIni()
|
|
65
65
|
console.warn(config)
|
|
66
66
|
// You also can get the `config.ini` string version:
|
|
67
|
-
const iniString = await
|
|
67
|
+
const iniString = await device.toIniString()
|
|
68
68
|
console.warn(iniString)
|
|
69
69
|
|
|
70
|
-
// Deploy the
|
|
71
|
-
await
|
|
70
|
+
// Deploy the device
|
|
71
|
+
await device.deploy()
|
|
72
72
|
console.warn('Image deployed successfully')
|
|
73
73
|
|
|
74
74
|
// Start the emulator
|
|
75
|
-
await image.start(
|
|
75
|
+
await image.start(device)
|
|
76
76
|
|
|
77
77
|
await new Promise<void>(resolve => setTimeout(resolve, 1000 * 60))
|
|
78
78
|
// Stop the emulator
|
|
79
|
-
image.stop(
|
|
79
|
+
image.stop(device)
|
|
80
80
|
}
|
|
81
81
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -73,6 +73,7 @@ var ImageDeployerImpl = class {
|
|
|
73
73
|
this.options.uuid = uuid;
|
|
74
74
|
this.options.name = name;
|
|
75
75
|
Object.assign(this.options, config);
|
|
76
|
+
if ("productName" in this.options) delete this.options.productName;
|
|
76
77
|
}
|
|
77
78
|
setUuid(uuid) {
|
|
78
79
|
this.options.uuid = uuid;
|
|
@@ -140,7 +141,6 @@ var ImageDeployerImpl = class {
|
|
|
140
141
|
if (defaultProductConfigItem.devModel) return defaultProductConfigItem.devModel;
|
|
141
142
|
}
|
|
142
143
|
async buildList() {
|
|
143
|
-
if (!(await this.image.getProductConfig()).find((item) => item.name === this.config.productName)) throw new Error(`Product config item ${this.config.productName} not found`);
|
|
144
144
|
return {
|
|
145
145
|
...this.options,
|
|
146
146
|
"imageDir": this.image.getPath().split(",").join(this.image.getImageManager().getOptions().path.sep) + this.image.getImageManager().getOptions().path.sep,
|
|
@@ -241,6 +241,23 @@ var ImageDeployerImpl = class {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
+
async isDeployed() {
|
|
245
|
+
const { fs, path } = this.image.getImageManager().getOptions();
|
|
246
|
+
const listsPath = path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
|
|
247
|
+
if (!fs.existsSync(listsPath) || !fs.statSync(listsPath).isFile()) return false;
|
|
248
|
+
return (JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? []).find((item) => item.name === this.options.name) !== void 0;
|
|
249
|
+
}
|
|
250
|
+
async delete() {
|
|
251
|
+
const { fs, path } = this.image.getImageManager().getOptions();
|
|
252
|
+
const listsPath = path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
|
|
253
|
+
if (!fs.existsSync(listsPath) || !fs.statSync(listsPath).isFile()) return /* @__PURE__ */ new Error("Lists file not found");
|
|
254
|
+
const lists = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
|
|
255
|
+
const index = lists.findIndex((item) => item.name === this.options.name);
|
|
256
|
+
if (index === -1) return /* @__PURE__ */ new Error(`Device ${this.options.name} not found`);
|
|
257
|
+
lists.splice(index, 1);
|
|
258
|
+
fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
|
|
259
|
+
fs.rmSync(path.resolve(this.options.path ?? ""), { recursive: true });
|
|
260
|
+
}
|
|
244
261
|
};
|
|
245
262
|
function createImageDeployer(image, uuid, name, config) {
|
|
246
263
|
return new ImageDeployerImpl(image, uuid, name, config);
|
|
@@ -485,7 +502,7 @@ var ImageBase = class {
|
|
|
485
502
|
//#region src/images/local-image.ts
|
|
486
503
|
var LocalImageImpl = class extends ImageBase {
|
|
487
504
|
imageType = "local";
|
|
488
|
-
|
|
505
|
+
createDevice(name, config) {
|
|
489
506
|
return createImageDeployer(this, this.getImageManager().getOptions().crypto.randomUUID(), name, config);
|
|
490
507
|
}
|
|
491
508
|
async getProductConfig(usingDefaultProductConfig = false) {
|
|
@@ -498,10 +515,13 @@ var LocalImageImpl = class extends ImageBase {
|
|
|
498
515
|
return [];
|
|
499
516
|
}
|
|
500
517
|
async delete() {
|
|
501
|
-
const fs = this.getImageManager().getOptions()
|
|
518
|
+
const { fs } = this.getImageManager().getOptions();
|
|
502
519
|
const path = this.getFsPath();
|
|
503
520
|
if (!fs.existsSync(path) || !fs.statSync(path).isDirectory()) return /* @__PURE__ */ new Error("Image path does not exist");
|
|
504
521
|
fs.rmSync(path, { recursive: true });
|
|
522
|
+
const devices = await this.getDevices();
|
|
523
|
+
const error = await Promise.allSettled(devices.map((device) => device.delete())).then((results) => results.find((result) => result.status === "rejected"));
|
|
524
|
+
if (error) return error.reason;
|
|
505
525
|
}
|
|
506
526
|
getExecutablePath() {
|
|
507
527
|
const { emulatorPath, process, path } = this.getImageManager().getOptions();
|
|
@@ -530,6 +550,24 @@ var LocalImageImpl = class extends ImageBase {
|
|
|
530
550
|
const { child_process, emulatorPath } = this.getImageManager().getOptions();
|
|
531
551
|
return child_process.exec(await this.buildStopCommand(deployer), { cwd: emulatorPath });
|
|
532
552
|
}
|
|
553
|
+
typeAssert(value) {}
|
|
554
|
+
async getDevices() {
|
|
555
|
+
const { path, fs, imageBasePath } = this.getImageManager().getOptions();
|
|
556
|
+
const listsJsonPath = path.resolve(this.getImageManager().getOptions().deployedPath, "lists.json");
|
|
557
|
+
if (!fs.existsSync(listsJsonPath) || !fs.statSync(listsJsonPath).isFile()) return [];
|
|
558
|
+
const listsJson = JSON.parse(fs.readFileSync(listsJsonPath, "utf-8"));
|
|
559
|
+
if (!Array.isArray(listsJson) || this.imageType !== "local") return [];
|
|
560
|
+
this.typeAssert(this);
|
|
561
|
+
const devices = [];
|
|
562
|
+
for (const listsJsonItem of listsJson) {
|
|
563
|
+
if (typeof listsJsonItem !== "object" || listsJsonItem === null) continue;
|
|
564
|
+
if (!("imageDir" in listsJsonItem) || typeof listsJsonItem.imageDir !== "string") continue;
|
|
565
|
+
if (!("name" in listsJsonItem) || typeof listsJsonItem.name !== "string") continue;
|
|
566
|
+
if (path.resolve(this.getFsPath()) !== path.resolve(imageBasePath, listsJsonItem.imageDir)) continue;
|
|
567
|
+
devices.push(this.createDevice(listsJsonItem.name, listsJsonItem));
|
|
568
|
+
}
|
|
569
|
+
return devices;
|
|
570
|
+
}
|
|
533
571
|
toJSON() {
|
|
534
572
|
return {
|
|
535
573
|
...super.toJSON(),
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as DeviceType, c as SnakecaseDeviceType, d as DeployedImageConfig, f as DeployedImageConfigWithProductName, h as FullDeployedImageOptions, i as Arch, l as Stringifiable, m as DevModel, n as ProductConfigItem, o as OS, p as DeployedImageOptions, r as createDeployedImageConfig, s as PascalCaseDeviceType, t as ProductConfig, u as DeployedDevModel } from "./product-config-
|
|
1
|
+
import { a as DeviceType, c as SnakecaseDeviceType, d as DeployedImageConfig, f as DeployedImageConfigWithProductName, g as ProductNameable, h as FullDeployedImageOptions, i as Arch, l as Stringifiable, m as DevModel, n as ProductConfigItem, o as OS, p as DeployedImageOptions, r as createDeployedImageConfig, s as PascalCaseDeviceType, t as ProductConfig, u as DeployedDevModel } from "./product-config-sobL53MD.cjs";
|
|
2
2
|
import { AxiosProgressEvent } from "axios";
|
|
3
3
|
import { Emitter } from "mitt";
|
|
4
4
|
import * as node_child_process0 from "node:child_process";
|
|
@@ -12,13 +12,14 @@ import * as node_crypto0 from "node:crypto";
|
|
|
12
12
|
//#region src/images/local-image.d.ts
|
|
13
13
|
interface LocalImage extends BaseImage, Stringifiable<LocalImage.Stringifiable> {
|
|
14
14
|
imageType: 'local';
|
|
15
|
-
|
|
15
|
+
createDevice(name: string, config: DeployedImageConfigWithProductName): Device;
|
|
16
16
|
getProductConfig(): Promise<ProductConfigItem[]>;
|
|
17
17
|
delete(): Promise<void | Error>;
|
|
18
|
-
buildStartCommand(deployer:
|
|
19
|
-
start(deployer:
|
|
20
|
-
buildStopCommand(deployer:
|
|
21
|
-
stop(deployer:
|
|
18
|
+
buildStartCommand(deployer: Device): Promise<string>;
|
|
19
|
+
start(deployer: Device): Promise<node_child_process0.ChildProcess>;
|
|
20
|
+
buildStopCommand(deployer: Device): Promise<string>;
|
|
21
|
+
stop(deployer: Device): Promise<node_child_process0.ChildProcess>;
|
|
22
|
+
getDevices(): Promise<Device[]>;
|
|
22
23
|
}
|
|
23
24
|
declare namespace LocalImage {
|
|
24
25
|
interface Stringifiable extends Omit<BaseImage.Stringifiable, 'imageType'> {
|
|
@@ -228,7 +229,7 @@ type Image = LocalImage | RemoteImage;
|
|
|
228
229
|
type ImageType = 'local' | 'remote';
|
|
229
230
|
//#endregion
|
|
230
231
|
//#region src/deployer/image-deployer.d.ts
|
|
231
|
-
interface
|
|
232
|
+
interface Device {
|
|
232
233
|
setUuid(uuid: `${string}-${string}-${string}-${string}-${string}`): this;
|
|
233
234
|
setModel(model: string): this;
|
|
234
235
|
setDevModel(devModel: FullDeployedImageOptions['devModel']): this;
|
|
@@ -262,11 +263,23 @@ interface ImageDeployer {
|
|
|
262
263
|
*/
|
|
263
264
|
toIniString(): Promise<string>;
|
|
264
265
|
/**
|
|
265
|
-
* Deploy the
|
|
266
|
+
* Deploy the device.
|
|
266
267
|
*
|
|
267
268
|
* @param symlinkImage - If true, symlink the system image to current device directory. Default is `true`.
|
|
268
269
|
*/
|
|
269
270
|
deploy(symlinkImage?: boolean): Promise<void | Error>;
|
|
271
|
+
/**
|
|
272
|
+
* Check if the device is deployed.
|
|
273
|
+
*
|
|
274
|
+
* @returns True if the device is deployed, false otherwise.
|
|
275
|
+
*/
|
|
276
|
+
isDeployed(): Promise<boolean>;
|
|
277
|
+
/**
|
|
278
|
+
* Delete the device.
|
|
279
|
+
*
|
|
280
|
+
* @returns True if the device is deleted, false otherwise.
|
|
281
|
+
*/
|
|
282
|
+
delete(): Promise<void | Error>;
|
|
270
283
|
}
|
|
271
284
|
//#endregion
|
|
272
|
-
export { Arch, DeployedDevModel, DeployedImageConfig, DeployedImageConfigWithProductName, DeployedImageOptions, DevModel, DeviceType, FullDeployedImageOptions, Image,
|
|
285
|
+
export { Arch, DeployedDevModel, DeployedImageConfig, DeployedImageConfigWithProductName, DeployedImageOptions, DevModel, Device, DeviceType, FullDeployedImageOptions, Image, type ImageManager, type ImageManagerOptions, ImageType, LocalImage, OS, PascalCaseDeviceType, type ProductConfig, ProductNameable, RemoteImage, RequestUrlError, SnakecaseDeviceType, Stringifiable, createDeployedImageConfig, createImageManager };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as DeviceType, c as SnakecaseDeviceType, d as DeployedImageConfig, f as DeployedImageConfigWithProductName, h as FullDeployedImageOptions, i as Arch, l as Stringifiable, m as DevModel, n as ProductConfigItem, o as OS, p as DeployedImageOptions, r as createDeployedImageConfig, s as PascalCaseDeviceType, t as ProductConfig, u as DeployedDevModel } from "./product-config-
|
|
1
|
+
import { a as DeviceType, c as SnakecaseDeviceType, d as DeployedImageConfig, f as DeployedImageConfigWithProductName, g as ProductNameable, h as FullDeployedImageOptions, i as Arch, l as Stringifiable, m as DevModel, n as ProductConfigItem, o as OS, p as DeployedImageOptions, r as createDeployedImageConfig, s as PascalCaseDeviceType, t as ProductConfig, u as DeployedDevModel } from "./product-config-DtWd8ReR.mjs";
|
|
2
2
|
import { AxiosProgressEvent } from "axios";
|
|
3
3
|
import { Emitter } from "mitt";
|
|
4
4
|
import progress from "progress-stream";
|
|
@@ -12,13 +12,14 @@ import * as node_process0 from "node:process";
|
|
|
12
12
|
//#region src/images/local-image.d.ts
|
|
13
13
|
interface LocalImage extends BaseImage, Stringifiable<LocalImage.Stringifiable> {
|
|
14
14
|
imageType: 'local';
|
|
15
|
-
|
|
15
|
+
createDevice(name: string, config: DeployedImageConfigWithProductName): Device;
|
|
16
16
|
getProductConfig(): Promise<ProductConfigItem[]>;
|
|
17
17
|
delete(): Promise<void | Error>;
|
|
18
|
-
buildStartCommand(deployer:
|
|
19
|
-
start(deployer:
|
|
20
|
-
buildStopCommand(deployer:
|
|
21
|
-
stop(deployer:
|
|
18
|
+
buildStartCommand(deployer: Device): Promise<string>;
|
|
19
|
+
start(deployer: Device): Promise<node_child_process0.ChildProcess>;
|
|
20
|
+
buildStopCommand(deployer: Device): Promise<string>;
|
|
21
|
+
stop(deployer: Device): Promise<node_child_process0.ChildProcess>;
|
|
22
|
+
getDevices(): Promise<Device[]>;
|
|
22
23
|
}
|
|
23
24
|
declare namespace LocalImage {
|
|
24
25
|
interface Stringifiable extends Omit<BaseImage.Stringifiable, 'imageType'> {
|
|
@@ -228,7 +229,7 @@ type Image = LocalImage | RemoteImage;
|
|
|
228
229
|
type ImageType = 'local' | 'remote';
|
|
229
230
|
//#endregion
|
|
230
231
|
//#region src/deployer/image-deployer.d.ts
|
|
231
|
-
interface
|
|
232
|
+
interface Device {
|
|
232
233
|
setUuid(uuid: `${string}-${string}-${string}-${string}-${string}`): this;
|
|
233
234
|
setModel(model: string): this;
|
|
234
235
|
setDevModel(devModel: FullDeployedImageOptions['devModel']): this;
|
|
@@ -262,11 +263,23 @@ interface ImageDeployer {
|
|
|
262
263
|
*/
|
|
263
264
|
toIniString(): Promise<string>;
|
|
264
265
|
/**
|
|
265
|
-
* Deploy the
|
|
266
|
+
* Deploy the device.
|
|
266
267
|
*
|
|
267
268
|
* @param symlinkImage - If true, symlink the system image to current device directory. Default is `true`.
|
|
268
269
|
*/
|
|
269
270
|
deploy(symlinkImage?: boolean): Promise<void | Error>;
|
|
271
|
+
/**
|
|
272
|
+
* Check if the device is deployed.
|
|
273
|
+
*
|
|
274
|
+
* @returns True if the device is deployed, false otherwise.
|
|
275
|
+
*/
|
|
276
|
+
isDeployed(): Promise<boolean>;
|
|
277
|
+
/**
|
|
278
|
+
* Delete the device.
|
|
279
|
+
*
|
|
280
|
+
* @returns True if the device is deleted, false otherwise.
|
|
281
|
+
*/
|
|
282
|
+
delete(): Promise<void | Error>;
|
|
270
283
|
}
|
|
271
284
|
//#endregion
|
|
272
|
-
export { Arch, DeployedDevModel, DeployedImageConfig, DeployedImageConfigWithProductName, DeployedImageOptions, DevModel, DeviceType, FullDeployedImageOptions, type Image, type
|
|
285
|
+
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, ProductNameable, type RemoteImage, RequestUrlError, SnakecaseDeviceType, Stringifiable, createDeployedImageConfig, createImageManager };
|
package/dist/index.mjs
CHANGED
|
@@ -41,6 +41,7 @@ var ImageDeployerImpl = class {
|
|
|
41
41
|
this.options.uuid = uuid;
|
|
42
42
|
this.options.name = name;
|
|
43
43
|
Object.assign(this.options, config);
|
|
44
|
+
if ("productName" in this.options) delete this.options.productName;
|
|
44
45
|
}
|
|
45
46
|
setUuid(uuid) {
|
|
46
47
|
this.options.uuid = uuid;
|
|
@@ -108,7 +109,6 @@ var ImageDeployerImpl = class {
|
|
|
108
109
|
if (defaultProductConfigItem.devModel) return defaultProductConfigItem.devModel;
|
|
109
110
|
}
|
|
110
111
|
async buildList() {
|
|
111
|
-
if (!(await this.image.getProductConfig()).find((item) => item.name === this.config.productName)) throw new Error(`Product config item ${this.config.productName} not found`);
|
|
112
112
|
return {
|
|
113
113
|
...this.options,
|
|
114
114
|
"imageDir": this.image.getPath().split(",").join(this.image.getImageManager().getOptions().path.sep) + this.image.getImageManager().getOptions().path.sep,
|
|
@@ -209,6 +209,23 @@ var ImageDeployerImpl = class {
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
|
+
async isDeployed() {
|
|
213
|
+
const { fs, path } = this.image.getImageManager().getOptions();
|
|
214
|
+
const listsPath = path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
|
|
215
|
+
if (!fs.existsSync(listsPath) || !fs.statSync(listsPath).isFile()) return false;
|
|
216
|
+
return (JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? []).find((item) => item.name === this.options.name) !== void 0;
|
|
217
|
+
}
|
|
218
|
+
async delete() {
|
|
219
|
+
const { fs, path } = this.image.getImageManager().getOptions();
|
|
220
|
+
const listsPath = path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
|
|
221
|
+
if (!fs.existsSync(listsPath) || !fs.statSync(listsPath).isFile()) return /* @__PURE__ */ new Error("Lists file not found");
|
|
222
|
+
const lists = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
|
|
223
|
+
const index = lists.findIndex((item) => item.name === this.options.name);
|
|
224
|
+
if (index === -1) return /* @__PURE__ */ new Error(`Device ${this.options.name} not found`);
|
|
225
|
+
lists.splice(index, 1);
|
|
226
|
+
fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
|
|
227
|
+
fs.rmSync(path.resolve(this.options.path ?? ""), { recursive: true });
|
|
228
|
+
}
|
|
212
229
|
};
|
|
213
230
|
function createImageDeployer(image, uuid, name, config) {
|
|
214
231
|
return new ImageDeployerImpl(image, uuid, name, config);
|
|
@@ -453,7 +470,7 @@ var ImageBase = class {
|
|
|
453
470
|
//#region src/images/local-image.ts
|
|
454
471
|
var LocalImageImpl = class extends ImageBase {
|
|
455
472
|
imageType = "local";
|
|
456
|
-
|
|
473
|
+
createDevice(name, config) {
|
|
457
474
|
return createImageDeployer(this, this.getImageManager().getOptions().crypto.randomUUID(), name, config);
|
|
458
475
|
}
|
|
459
476
|
async getProductConfig(usingDefaultProductConfig = false) {
|
|
@@ -466,10 +483,13 @@ var LocalImageImpl = class extends ImageBase {
|
|
|
466
483
|
return [];
|
|
467
484
|
}
|
|
468
485
|
async delete() {
|
|
469
|
-
const fs = this.getImageManager().getOptions()
|
|
486
|
+
const { fs } = this.getImageManager().getOptions();
|
|
470
487
|
const path = this.getFsPath();
|
|
471
488
|
if (!fs.existsSync(path) || !fs.statSync(path).isDirectory()) return /* @__PURE__ */ new Error("Image path does not exist");
|
|
472
489
|
fs.rmSync(path, { recursive: true });
|
|
490
|
+
const devices = await this.getDevices();
|
|
491
|
+
const error = await Promise.allSettled(devices.map((device) => device.delete())).then((results) => results.find((result) => result.status === "rejected"));
|
|
492
|
+
if (error) return error.reason;
|
|
473
493
|
}
|
|
474
494
|
getExecutablePath() {
|
|
475
495
|
const { emulatorPath, process, path } = this.getImageManager().getOptions();
|
|
@@ -498,6 +518,24 @@ var LocalImageImpl = class extends ImageBase {
|
|
|
498
518
|
const { child_process, emulatorPath } = this.getImageManager().getOptions();
|
|
499
519
|
return child_process.exec(await this.buildStopCommand(deployer), { cwd: emulatorPath });
|
|
500
520
|
}
|
|
521
|
+
typeAssert(value) {}
|
|
522
|
+
async getDevices() {
|
|
523
|
+
const { path, fs, imageBasePath } = this.getImageManager().getOptions();
|
|
524
|
+
const listsJsonPath = path.resolve(this.getImageManager().getOptions().deployedPath, "lists.json");
|
|
525
|
+
if (!fs.existsSync(listsJsonPath) || !fs.statSync(listsJsonPath).isFile()) return [];
|
|
526
|
+
const listsJson = JSON.parse(fs.readFileSync(listsJsonPath, "utf-8"));
|
|
527
|
+
if (!Array.isArray(listsJson) || this.imageType !== "local") return [];
|
|
528
|
+
this.typeAssert(this);
|
|
529
|
+
const devices = [];
|
|
530
|
+
for (const listsJsonItem of listsJson) {
|
|
531
|
+
if (typeof listsJsonItem !== "object" || listsJsonItem === null) continue;
|
|
532
|
+
if (!("imageDir" in listsJsonItem) || typeof listsJsonItem.imageDir !== "string") continue;
|
|
533
|
+
if (!("name" in listsJsonItem) || typeof listsJsonItem.name !== "string") continue;
|
|
534
|
+
if (path.resolve(this.getFsPath()) !== path.resolve(imageBasePath, listsJsonItem.imageDir)) continue;
|
|
535
|
+
devices.push(this.createDevice(listsJsonItem.name, listsJsonItem));
|
|
536
|
+
}
|
|
537
|
+
return devices;
|
|
538
|
+
}
|
|
501
539
|
toJSON() {
|
|
502
540
|
return {
|
|
503
541
|
...super.toJSON(),
|
|
@@ -9,6 +9,14 @@ declare enum DevModel {
|
|
|
9
9
|
PCEMU_FD05 = "PCEMU-FD05"
|
|
10
10
|
}
|
|
11
11
|
type DeployedDevModel = 'MCHEMU-AL00CN' | 'PHEMU-FD00' | 'PHEMU-FD01' | 'PHEMU-FD02' | 'PHEMU-FD06' | 'PCEMU-FD00' | 'PCEMU-FD05' | DevModel | (string & {});
|
|
12
|
+
type ProductNameable<T> = T & {
|
|
13
|
+
/**
|
|
14
|
+
* The name of the product.
|
|
15
|
+
*
|
|
16
|
+
* @example 'Mate 80 Pro Max、Mate 80 RS'
|
|
17
|
+
*/
|
|
18
|
+
productName: string;
|
|
19
|
+
};
|
|
12
20
|
interface DeployedImageConfig {
|
|
13
21
|
/**
|
|
14
22
|
* Diagonal size.
|
|
@@ -248,4 +256,4 @@ interface ProductConfigItem {
|
|
|
248
256
|
type ProductConfig = Record<PascalCaseDeviceType, ProductConfigItem[]>;
|
|
249
257
|
declare function createDeployedImageConfig(productConfigItem: ProductConfigItem): DeployedImageConfigWithProductName;
|
|
250
258
|
//#endregion
|
|
251
|
-
export { DeviceType as a, SnakecaseDeviceType as c, DeployedImageConfig as d, DeployedImageConfigWithProductName as f, FullDeployedImageOptions as h, Arch as i, Stringifiable as l, DevModel as m, ProductConfigItem as n, OS as o, DeployedImageOptions as p, createDeployedImageConfig as r, PascalCaseDeviceType as s, ProductConfig as t, DeployedDevModel as u };
|
|
259
|
+
export { DeviceType as a, SnakecaseDeviceType as c, DeployedImageConfig as d, DeployedImageConfigWithProductName as f, ProductNameable as g, FullDeployedImageOptions as h, Arch as i, Stringifiable as l, DevModel as m, ProductConfigItem as n, OS as o, DeployedImageOptions as p, createDeployedImageConfig as r, PascalCaseDeviceType as s, ProductConfig as t, DeployedDevModel as u };
|
|
@@ -9,6 +9,14 @@ declare enum DevModel {
|
|
|
9
9
|
PCEMU_FD05 = "PCEMU-FD05"
|
|
10
10
|
}
|
|
11
11
|
type DeployedDevModel = 'MCHEMU-AL00CN' | 'PHEMU-FD00' | 'PHEMU-FD01' | 'PHEMU-FD02' | 'PHEMU-FD06' | 'PCEMU-FD00' | 'PCEMU-FD05' | DevModel | (string & {});
|
|
12
|
+
type ProductNameable<T> = T & {
|
|
13
|
+
/**
|
|
14
|
+
* The name of the product.
|
|
15
|
+
*
|
|
16
|
+
* @example 'Mate 80 Pro Max、Mate 80 RS'
|
|
17
|
+
*/
|
|
18
|
+
productName: string;
|
|
19
|
+
};
|
|
12
20
|
interface DeployedImageConfig {
|
|
13
21
|
/**
|
|
14
22
|
* Diagonal size.
|
|
@@ -248,4 +256,4 @@ interface ProductConfigItem {
|
|
|
248
256
|
type ProductConfig = Record<PascalCaseDeviceType, ProductConfigItem[]>;
|
|
249
257
|
declare function createDeployedImageConfig(productConfigItem: ProductConfigItem): DeployedImageConfigWithProductName;
|
|
250
258
|
//#endregion
|
|
251
|
-
export { DeviceType as a, SnakecaseDeviceType as c, DeployedImageConfig as d, DeployedImageConfigWithProductName as f, FullDeployedImageOptions as h, Arch as i, Stringifiable as l, DevModel as m, ProductConfigItem as n, OS as o, DeployedImageOptions as p, createDeployedImageConfig as r, PascalCaseDeviceType as s, ProductConfig as t, DeployedDevModel as u };
|
|
259
|
+
export { DeviceType as a, SnakecaseDeviceType as c, DeployedImageConfig as d, DeployedImageConfigWithProductName as f, ProductNameable as g, FullDeployedImageOptions as h, Arch as i, Stringifiable as l, DevModel as m, ProductConfigItem as n, OS as o, DeployedImageOptions as p, createDeployedImageConfig as r, PascalCaseDeviceType as s, ProductConfig as t, DeployedDevModel as u };
|
package/package.json
CHANGED