@arkts/image-manager 0.1.0 → 0.1.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 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 deployer = image.createDeployer('MateBook Fold', createDeployedImageConfig(image))
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 deployer.buildList()
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 deployer.buildIni()
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 deployer.toIniString()
67
+ const iniString = await device.toIniString()
68
68
  console.warn(iniString)
69
69
 
70
- // Deploy the image
71
- await deployer.deploy()
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(deployer)
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(deployer)
79
+ image.stop(device)
80
80
  }
81
81
  ```
@@ -1,4 +1,4 @@
1
- import { t as ProductConfig } from "./product-config-KZA5hTtZ.cjs";
1
+ import { t as ProductConfig } from "./product-config-sobL53MD.cjs";
2
2
 
3
3
  //#region src/default-product-config.d.ts
4
4
  declare const _default: ProductConfig;
@@ -1,4 +1,4 @@
1
- import { t as ProductConfig } from "./product-config-BthHVWvs.mjs";
1
+ import { t as ProductConfig } from "./product-config-DtWd8ReR.mjs";
2
2
 
3
3
  //#region src/default-product-config.d.ts
4
4
  declare const _default: ProductConfig;
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;
@@ -241,6 +242,23 @@ var ImageDeployerImpl = class {
241
242
  }
242
243
  }
243
244
  }
245
+ async isDeployed() {
246
+ const { fs, path } = this.image.getImageManager().getOptions();
247
+ const listsPath = path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
248
+ if (!fs.existsSync(listsPath) || !fs.statSync(listsPath).isFile()) return false;
249
+ return (JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? []).find((item) => item.name === this.options.name) !== void 0;
250
+ }
251
+ async delete() {
252
+ const { fs, path } = this.image.getImageManager().getOptions();
253
+ const listsPath = path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
254
+ if (!fs.existsSync(listsPath) || !fs.statSync(listsPath).isFile()) return /* @__PURE__ */ new Error("Lists file not found");
255
+ const lists = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
256
+ const index = lists.findIndex((item) => item.name === this.options.name);
257
+ if (index === -1) return /* @__PURE__ */ new Error(`Device ${this.options.name} not found`);
258
+ lists.splice(index, 1);
259
+ fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
260
+ fs.rmSync(path.resolve(this.options.path ?? ""), { recursive: true });
261
+ }
244
262
  };
245
263
  function createImageDeployer(image, uuid, name, config) {
246
264
  return new ImageDeployerImpl(image, uuid, name, config);
@@ -485,7 +503,7 @@ var ImageBase = class {
485
503
  //#region src/images/local-image.ts
486
504
  var LocalImageImpl = class extends ImageBase {
487
505
  imageType = "local";
488
- createDeployer(name, config) {
506
+ createDevice(name, config) {
489
507
  return createImageDeployer(this, this.getImageManager().getOptions().crypto.randomUUID(), name, config);
490
508
  }
491
509
  async getProductConfig(usingDefaultProductConfig = false) {
@@ -498,10 +516,13 @@ var LocalImageImpl = class extends ImageBase {
498
516
  return [];
499
517
  }
500
518
  async delete() {
501
- const fs = this.getImageManager().getOptions().fs;
519
+ const { fs } = this.getImageManager().getOptions();
502
520
  const path = this.getFsPath();
503
521
  if (!fs.existsSync(path) || !fs.statSync(path).isDirectory()) return /* @__PURE__ */ new Error("Image path does not exist");
504
522
  fs.rmSync(path, { recursive: true });
523
+ const devices = await this.getDevices();
524
+ const error = await Promise.allSettled(devices.map((device) => device.delete())).then((results) => results.find((result) => result.status === "rejected"));
525
+ if (error) return error.reason;
505
526
  }
506
527
  getExecutablePath() {
507
528
  const { emulatorPath, process, path } = this.getImageManager().getOptions();
@@ -530,6 +551,24 @@ var LocalImageImpl = class extends ImageBase {
530
551
  const { child_process, emulatorPath } = this.getImageManager().getOptions();
531
552
  return child_process.exec(await this.buildStopCommand(deployer), { cwd: emulatorPath });
532
553
  }
554
+ typeAssert(value) {}
555
+ async getDevices() {
556
+ const { path, fs, imageBasePath } = this.getImageManager().getOptions();
557
+ const listsJsonPath = path.resolve(this.getImageManager().getOptions().deployedPath, "lists.json");
558
+ if (!fs.existsSync(listsJsonPath) || !fs.statSync(listsJsonPath).isFile()) return [];
559
+ const listsJson = JSON.parse(fs.readFileSync(listsJsonPath, "utf-8"));
560
+ if (!Array.isArray(listsJson) || this.imageType !== "local") return [];
561
+ this.typeAssert(this);
562
+ const devices = [];
563
+ for (const listsJsonItem of listsJson) {
564
+ if (typeof listsJsonItem !== "object" || listsJsonItem === null) continue;
565
+ if (!("imageDir" in listsJsonItem) || typeof listsJsonItem.imageDir !== "string") continue;
566
+ if (!("name" in listsJsonItem) || typeof listsJsonItem.name !== "string") continue;
567
+ if (path.resolve(this.getFsPath()) !== path.resolve(imageBasePath, listsJsonItem.imageDir)) continue;
568
+ devices.push(this.createDevice(listsJsonItem.name, listsJsonItem));
569
+ }
570
+ return devices;
571
+ }
533
572
  toJSON() {
534
573
  return {
535
574
  ...super.toJSON(),
@@ -590,20 +629,20 @@ async function resolveImageManagerOptions(options) {
590
629
  function resolveDefaultEmulatorPath() {
591
630
  switch (process.platform) {
592
631
  case "darwin": return "/Applications/DevEco-Studio.app/Contents/tools/emulator/Emulator";
593
- case "win32": return path.resolve("C:", "Program Files", "Huawei", "DevEco Studio", "tools", "emulator", "Emulator.exe");
632
+ case "win32": return "C:\\Program Files\\Huawei\\DevEco Studio\\tools\\emulator\\Emulator.exe";
594
633
  default: return path.resolve(os.homedir(), ".huawei", "Emulator");
595
634
  }
596
635
  }
597
- const imageBasePath = options.imageBasePath ?? resolveDefaultImageBasePath();
598
- const cachePath = options.cachePath ?? path.resolve(imageBasePath, "cache");
636
+ const imageBasePath = options.imageBasePath || resolveDefaultImageBasePath();
637
+ const cachePath = options.cachePath || path.resolve(imageBasePath, "cache");
599
638
  return {
600
639
  imageBasePath,
601
- deployedPath: options.deployedPath ?? resolveDefaultDeployedPath(),
640
+ deployedPath: options.deployedPath || resolveDefaultDeployedPath(),
602
641
  cachePath,
603
- sdkPath: options.sdkPath ?? resolveDefaultSdkPath(),
604
- configPath: options.configPath ?? resolveDefaultConfigPath(),
605
- logPath: options.logPath ?? resolveDefaultLogPath(),
606
- emulatorPath: options.emulatorPath ?? resolveDefaultEmulatorPath(),
642
+ sdkPath: options.sdkPath || resolveDefaultSdkPath(),
643
+ configPath: options.configPath || resolveDefaultConfigPath(),
644
+ logPath: options.logPath || resolveDefaultLogPath(),
645
+ emulatorPath: options.emulatorPath || resolveDefaultEmulatorPath(),
607
646
  path,
608
647
  os,
609
648
  fs: options.fs ?? await import("node:fs"),
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-KZA5hTtZ.cjs";
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
- createDeployer(name: string, config: DeployedImageConfigWithProductName): ImageDeployer;
15
+ createDevice(name: string, config: DeployedImageConfigWithProductName): Device;
16
16
  getProductConfig(): Promise<ProductConfigItem[]>;
17
17
  delete(): Promise<void | Error>;
18
- buildStartCommand(deployer: ImageDeployer): Promise<string>;
19
- start(deployer: ImageDeployer): Promise<node_child_process0.ChildProcess>;
20
- buildStopCommand(deployer: ImageDeployer): Promise<string>;
21
- stop(deployer: ImageDeployer): Promise<node_child_process0.ChildProcess>;
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 ImageDeployer {
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 image.
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, ImageDeployer, type ImageManager, type ImageManagerOptions, ImageType, LocalImage, OS, PascalCaseDeviceType, type ProductConfig, RemoteImage, RequestUrlError, SnakecaseDeviceType, Stringifiable, createDeployedImageConfig, createImageManager };
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-BthHVWvs.mjs";
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
- createDeployer(name: string, config: DeployedImageConfigWithProductName): ImageDeployer;
15
+ createDevice(name: string, config: DeployedImageConfigWithProductName): Device;
16
16
  getProductConfig(): Promise<ProductConfigItem[]>;
17
17
  delete(): Promise<void | Error>;
18
- buildStartCommand(deployer: ImageDeployer): Promise<string>;
19
- start(deployer: ImageDeployer): Promise<node_child_process0.ChildProcess>;
20
- buildStopCommand(deployer: ImageDeployer): Promise<string>;
21
- stop(deployer: ImageDeployer): Promise<node_child_process0.ChildProcess>;
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 ImageDeployer {
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 image.
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 ImageDeployer, type ImageManager, type ImageManagerOptions, type ImageType, type LocalImage, OS, PascalCaseDeviceType, type ProductConfig, type RemoteImage, RequestUrlError, SnakecaseDeviceType, Stringifiable, createDeployedImageConfig, createImageManager };
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;
@@ -209,6 +210,23 @@ var ImageDeployerImpl = class {
209
210
  }
210
211
  }
211
212
  }
213
+ async isDeployed() {
214
+ const { fs, path } = this.image.getImageManager().getOptions();
215
+ const listsPath = path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
216
+ if (!fs.existsSync(listsPath) || !fs.statSync(listsPath).isFile()) return false;
217
+ return (JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? []).find((item) => item.name === this.options.name) !== void 0;
218
+ }
219
+ async delete() {
220
+ const { fs, path } = this.image.getImageManager().getOptions();
221
+ const listsPath = path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
222
+ if (!fs.existsSync(listsPath) || !fs.statSync(listsPath).isFile()) return /* @__PURE__ */ new Error("Lists file not found");
223
+ const lists = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
224
+ const index = lists.findIndex((item) => item.name === this.options.name);
225
+ if (index === -1) return /* @__PURE__ */ new Error(`Device ${this.options.name} not found`);
226
+ lists.splice(index, 1);
227
+ fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
228
+ fs.rmSync(path.resolve(this.options.path ?? ""), { recursive: true });
229
+ }
212
230
  };
213
231
  function createImageDeployer(image, uuid, name, config) {
214
232
  return new ImageDeployerImpl(image, uuid, name, config);
@@ -453,7 +471,7 @@ var ImageBase = class {
453
471
  //#region src/images/local-image.ts
454
472
  var LocalImageImpl = class extends ImageBase {
455
473
  imageType = "local";
456
- createDeployer(name, config) {
474
+ createDevice(name, config) {
457
475
  return createImageDeployer(this, this.getImageManager().getOptions().crypto.randomUUID(), name, config);
458
476
  }
459
477
  async getProductConfig(usingDefaultProductConfig = false) {
@@ -466,10 +484,13 @@ var LocalImageImpl = class extends ImageBase {
466
484
  return [];
467
485
  }
468
486
  async delete() {
469
- const fs = this.getImageManager().getOptions().fs;
487
+ const { fs } = this.getImageManager().getOptions();
470
488
  const path = this.getFsPath();
471
489
  if (!fs.existsSync(path) || !fs.statSync(path).isDirectory()) return /* @__PURE__ */ new Error("Image path does not exist");
472
490
  fs.rmSync(path, { recursive: true });
491
+ const devices = await this.getDevices();
492
+ const error = await Promise.allSettled(devices.map((device) => device.delete())).then((results) => results.find((result) => result.status === "rejected"));
493
+ if (error) return error.reason;
473
494
  }
474
495
  getExecutablePath() {
475
496
  const { emulatorPath, process, path } = this.getImageManager().getOptions();
@@ -498,6 +519,24 @@ var LocalImageImpl = class extends ImageBase {
498
519
  const { child_process, emulatorPath } = this.getImageManager().getOptions();
499
520
  return child_process.exec(await this.buildStopCommand(deployer), { cwd: emulatorPath });
500
521
  }
522
+ typeAssert(value) {}
523
+ async getDevices() {
524
+ const { path, fs, imageBasePath } = this.getImageManager().getOptions();
525
+ const listsJsonPath = path.resolve(this.getImageManager().getOptions().deployedPath, "lists.json");
526
+ if (!fs.existsSync(listsJsonPath) || !fs.statSync(listsJsonPath).isFile()) return [];
527
+ const listsJson = JSON.parse(fs.readFileSync(listsJsonPath, "utf-8"));
528
+ if (!Array.isArray(listsJson) || this.imageType !== "local") return [];
529
+ this.typeAssert(this);
530
+ const devices = [];
531
+ for (const listsJsonItem of listsJson) {
532
+ if (typeof listsJsonItem !== "object" || listsJsonItem === null) continue;
533
+ if (!("imageDir" in listsJsonItem) || typeof listsJsonItem.imageDir !== "string") continue;
534
+ if (!("name" in listsJsonItem) || typeof listsJsonItem.name !== "string") continue;
535
+ if (path.resolve(this.getFsPath()) !== path.resolve(imageBasePath, listsJsonItem.imageDir)) continue;
536
+ devices.push(this.createDevice(listsJsonItem.name, listsJsonItem));
537
+ }
538
+ return devices;
539
+ }
501
540
  toJSON() {
502
541
  return {
503
542
  ...super.toJSON(),
@@ -558,20 +597,20 @@ async function resolveImageManagerOptions(options) {
558
597
  function resolveDefaultEmulatorPath() {
559
598
  switch (process.platform) {
560
599
  case "darwin": return "/Applications/DevEco-Studio.app/Contents/tools/emulator/Emulator";
561
- case "win32": return path.resolve("C:", "Program Files", "Huawei", "DevEco Studio", "tools", "emulator", "Emulator.exe");
600
+ case "win32": return "C:\\Program Files\\Huawei\\DevEco Studio\\tools\\emulator\\Emulator.exe";
562
601
  default: return path.resolve(os.homedir(), ".huawei", "Emulator");
563
602
  }
564
603
  }
565
- const imageBasePath = options.imageBasePath ?? resolveDefaultImageBasePath();
566
- const cachePath = options.cachePath ?? path.resolve(imageBasePath, "cache");
604
+ const imageBasePath = options.imageBasePath || resolveDefaultImageBasePath();
605
+ const cachePath = options.cachePath || path.resolve(imageBasePath, "cache");
567
606
  return {
568
607
  imageBasePath,
569
- deployedPath: options.deployedPath ?? resolveDefaultDeployedPath(),
608
+ deployedPath: options.deployedPath || resolveDefaultDeployedPath(),
570
609
  cachePath,
571
- sdkPath: options.sdkPath ?? resolveDefaultSdkPath(),
572
- configPath: options.configPath ?? resolveDefaultConfigPath(),
573
- logPath: options.logPath ?? resolveDefaultLogPath(),
574
- emulatorPath: options.emulatorPath ?? resolveDefaultEmulatorPath(),
610
+ sdkPath: options.sdkPath || resolveDefaultSdkPath(),
611
+ configPath: options.configPath || resolveDefaultConfigPath(),
612
+ logPath: options.logPath || resolveDefaultLogPath(),
613
+ emulatorPath: options.emulatorPath || resolveDefaultEmulatorPath(),
575
614
  path,
576
615
  os,
577
616
  fs: options.fs ?? await import("node:fs"),
@@ -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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arkts/image-manager",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "description": "OpenHarmony/HarmonyOS qemu image manager.",
6
6
  "author": "Naily Zero <zero@naily.cc> (https://naily.cc)",
7
7
  "license": "MIT",