@arkts/image-manager 0.3.0 → 0.3.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/dist/index.cjs CHANGED
@@ -30,6 +30,8 @@ let axios = require("axios");
30
30
  axios = __toESM(axios);
31
31
  let semver_functions_satisfies = require("semver/functions/satisfies");
32
32
  semver_functions_satisfies = __toESM(semver_functions_satisfies);
33
+ let ini = require("ini");
34
+ ini = __toESM(ini);
33
35
  let mitt = require("mitt");
34
36
  mitt = __toESM(mitt);
35
37
  let progress_stream = require("progress-stream");
@@ -38,7 +40,7 @@ let unzipper = require("unzipper");
38
40
  unzipper = __toESM(unzipper);
39
41
 
40
42
  //#region package.json
41
- var version = "0.3.0";
43
+ var version = "0.3.2";
42
44
 
43
45
  //#endregion
44
46
  //#region src/devices/list.ts
@@ -188,7 +190,18 @@ var DeviceImpl = class {
188
190
  getUuid() {
189
191
  return this.uuid;
190
192
  }
193
+ cachedList = null;
194
+ setCachedList(list) {
195
+ this.cachedList = list;
196
+ return this;
197
+ }
198
+ cachedIni = null;
199
+ setCachedIni(ini) {
200
+ this.cachedIni = ini;
201
+ return this;
202
+ }
191
203
  buildList() {
204
+ if (this.cachedList) return this.cachedList;
192
205
  const { path, deployedPath, imageBasePath, configPath, logPath } = this.image.getImageManager().getOptions();
193
206
  const screen = this.getScreen();
194
207
  const list = {
@@ -223,6 +236,7 @@ var DeviceImpl = class {
223
236
  return list;
224
237
  }
225
238
  buildIni(options = {}) {
239
+ if (this.cachedIni) return this.cachedIni;
226
240
  const listConfig = this.buildList();
227
241
  const screen = this.getScreen();
228
242
  const is2in1Foldable = listConfig.type === "2in1_foldable";
@@ -279,6 +293,7 @@ var DeviceImpl = class {
279
293
  return `${Object.entries(this.buildIni()).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
280
294
  }
281
295
  async deploy() {
296
+ if (await this.isDeployed()) return;
282
297
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
283
298
  if (!fs.existsSync(deployedPath)) fs.mkdirSync(deployedPath, { recursive: true });
284
299
  const listsPath = path.join(deployedPath, "lists.json");
@@ -647,19 +662,27 @@ var LocalImageImpl = class extends ImageBase {
647
662
  return createProductPreset(productConfigItem, pascalCaseDeviceType);
648
663
  }
649
664
  async getDevices() {
650
- const { path, fs, deployedPath } = this.getImageManager().getOptions();
665
+ const { path, fs, deployedPath, imageBasePath } = this.getImageManager().getOptions();
651
666
  const listsJsonPath = path.resolve(deployedPath, "lists.json");
652
667
  if (!fs.existsSync(listsJsonPath) || !fs.statSync(listsJsonPath).isFile()) return [];
653
668
  const listsJson = JSON.parse(fs.readFileSync(listsJsonPath, "utf-8"));
654
669
  if (!Array.isArray(listsJson) || this.imageType !== "local") return [];
655
670
  const devices = [];
656
- for (const listsJsonItem of listsJson) devices.push(this.createDevice({
657
- name: listsJsonItem.name,
658
- cpuNumber: Number(listsJsonItem.cpuNumber),
659
- diskSize: Number(listsJsonItem.dataDiskSize),
660
- memorySize: Number(listsJsonItem.memoryRamSize),
661
- screen: await this.createScreenLike(listsJsonItem)
662
- }));
671
+ for (const listsJsonItem of listsJson) {
672
+ if (path.resolve(imageBasePath, listsJsonItem.imageDir) !== this.getFsPath()) continue;
673
+ const iniFilePath = path.resolve(listsJsonItem.path, "config.ini");
674
+ if (!fs.existsSync(iniFilePath) || !fs.statSync(iniFilePath).isFile()) continue;
675
+ const device = this.createDevice({
676
+ name: listsJsonItem.name,
677
+ cpuNumber: Number(listsJsonItem.cpuNumber),
678
+ diskSize: Number(listsJsonItem.dataDiskSize),
679
+ memorySize: Number(listsJsonItem.memoryRamSize),
680
+ screen: await this.createScreenLike(listsJsonItem)
681
+ });
682
+ device.setUuid(listsJsonItem.uuid).setCachedList(listsJsonItem).setCachedIni(ini.default.parse(fs.readFileSync(iniFilePath, "utf-8")));
683
+ if (!fs.existsSync(listsJsonItem.path) || !fs.statSync(listsJsonItem.path).isDirectory()) continue;
684
+ devices.push(device);
685
+ }
663
686
  return devices;
664
687
  }
665
688
  toJSON() {
package/dist/index.mjs CHANGED
@@ -1,11 +1,12 @@
1
1
  import axios, { AxiosError } from "axios";
2
2
  import satisfies from "semver/functions/satisfies";
3
+ import INI from "ini";
3
4
  import mitt from "mitt";
4
5
  import progress from "progress-stream";
5
6
  import unzipper from "unzipper";
6
7
 
7
8
  //#region package.json
8
- var version = "0.3.0";
9
+ var version = "0.3.2";
9
10
 
10
11
  //#endregion
11
12
  //#region src/devices/list.ts
@@ -155,7 +156,18 @@ var DeviceImpl = class {
155
156
  getUuid() {
156
157
  return this.uuid;
157
158
  }
159
+ cachedList = null;
160
+ setCachedList(list) {
161
+ this.cachedList = list;
162
+ return this;
163
+ }
164
+ cachedIni = null;
165
+ setCachedIni(ini) {
166
+ this.cachedIni = ini;
167
+ return this;
168
+ }
158
169
  buildList() {
170
+ if (this.cachedList) return this.cachedList;
159
171
  const { path, deployedPath, imageBasePath, configPath, logPath } = this.image.getImageManager().getOptions();
160
172
  const screen = this.getScreen();
161
173
  const list = {
@@ -190,6 +202,7 @@ var DeviceImpl = class {
190
202
  return list;
191
203
  }
192
204
  buildIni(options = {}) {
205
+ if (this.cachedIni) return this.cachedIni;
193
206
  const listConfig = this.buildList();
194
207
  const screen = this.getScreen();
195
208
  const is2in1Foldable = listConfig.type === "2in1_foldable";
@@ -246,6 +259,7 @@ var DeviceImpl = class {
246
259
  return `${Object.entries(this.buildIni()).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
247
260
  }
248
261
  async deploy() {
262
+ if (await this.isDeployed()) return;
249
263
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
250
264
  if (!fs.existsSync(deployedPath)) fs.mkdirSync(deployedPath, { recursive: true });
251
265
  const listsPath = path.join(deployedPath, "lists.json");
@@ -614,19 +628,27 @@ var LocalImageImpl = class extends ImageBase {
614
628
  return createProductPreset(productConfigItem, pascalCaseDeviceType);
615
629
  }
616
630
  async getDevices() {
617
- const { path, fs, deployedPath } = this.getImageManager().getOptions();
631
+ const { path, fs, deployedPath, imageBasePath } = this.getImageManager().getOptions();
618
632
  const listsJsonPath = path.resolve(deployedPath, "lists.json");
619
633
  if (!fs.existsSync(listsJsonPath) || !fs.statSync(listsJsonPath).isFile()) return [];
620
634
  const listsJson = JSON.parse(fs.readFileSync(listsJsonPath, "utf-8"));
621
635
  if (!Array.isArray(listsJson) || this.imageType !== "local") return [];
622
636
  const devices = [];
623
- for (const listsJsonItem of listsJson) devices.push(this.createDevice({
624
- name: listsJsonItem.name,
625
- cpuNumber: Number(listsJsonItem.cpuNumber),
626
- diskSize: Number(listsJsonItem.dataDiskSize),
627
- memorySize: Number(listsJsonItem.memoryRamSize),
628
- screen: await this.createScreenLike(listsJsonItem)
629
- }));
637
+ for (const listsJsonItem of listsJson) {
638
+ if (path.resolve(imageBasePath, listsJsonItem.imageDir) !== this.getFsPath()) continue;
639
+ const iniFilePath = path.resolve(listsJsonItem.path, "config.ini");
640
+ if (!fs.existsSync(iniFilePath) || !fs.statSync(iniFilePath).isFile()) continue;
641
+ const device = this.createDevice({
642
+ name: listsJsonItem.name,
643
+ cpuNumber: Number(listsJsonItem.cpuNumber),
644
+ diskSize: Number(listsJsonItem.dataDiskSize),
645
+ memorySize: Number(listsJsonItem.memoryRamSize),
646
+ screen: await this.createScreenLike(listsJsonItem)
647
+ });
648
+ device.setUuid(listsJsonItem.uuid).setCachedList(listsJsonItem).setCachedIni(INI.parse(fs.readFileSync(iniFilePath, "utf-8")));
649
+ if (!fs.existsSync(listsJsonItem.path) || !fs.statSync(listsJsonItem.path).isDirectory()) continue;
650
+ devices.push(device);
651
+ }
630
652
  return devices;
631
653
  }
632
654
  toJSON() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arkts/image-manager",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "description": "OpenHarmony/HarmonyOS qemu image manager.",
6
6
  "author": "Naily Zero <zero@naily.cc> (https://naily.cc)",
7
7
  "license": "MIT",
@@ -43,6 +43,7 @@
43
43
  "@types/progress-stream": "^2.0.5",
44
44
  "@types/unzipper": "^0.10.11",
45
45
  "axios": "^1.13.4",
46
+ "ini": "^6.0.0",
46
47
  "mitt": "^3.0.1",
47
48
  "progress-stream": "^2.0.0",
48
49
  "semver": "^7.7.4",
@@ -51,6 +52,7 @@
51
52
  "devDependencies": {
52
53
  "@antfu/eslint-config": "^7.2.0",
53
54
  "@changesets/cli": "^2.29.8",
55
+ "@types/ini": "^4.1.1",
54
56
  "@types/node": "^25.2.0",
55
57
  "@types/semver": "^7.7.1",
56
58
  "@vitest/coverage-v8": "4.0.18",