@arkts/image-manager 0.3.1 → 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.1";
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");
@@ -655,6 +670,8 @@ var LocalImageImpl = class extends ImageBase {
655
670
  const devices = [];
656
671
  for (const listsJsonItem of listsJson) {
657
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;
658
675
  const device = this.createDevice({
659
676
  name: listsJsonItem.name,
660
677
  cpuNumber: Number(listsJsonItem.cpuNumber),
@@ -662,7 +679,8 @@ var LocalImageImpl = class extends ImageBase {
662
679
  memorySize: Number(listsJsonItem.memoryRamSize),
663
680
  screen: await this.createScreenLike(listsJsonItem)
664
681
  });
665
- if (!fs.existsSync(device.buildList().path) || !fs.statSync(device.buildList().path).isDirectory()) continue;
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;
666
684
  devices.push(device);
667
685
  }
668
686
  return devices;
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.1";
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");
@@ -622,6 +636,8 @@ var LocalImageImpl = class extends ImageBase {
622
636
  const devices = [];
623
637
  for (const listsJsonItem of listsJson) {
624
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;
625
641
  const device = this.createDevice({
626
642
  name: listsJsonItem.name,
627
643
  cpuNumber: Number(listsJsonItem.cpuNumber),
@@ -629,7 +645,8 @@ var LocalImageImpl = class extends ImageBase {
629
645
  memorySize: Number(listsJsonItem.memoryRamSize),
630
646
  screen: await this.createScreenLike(listsJsonItem)
631
647
  });
632
- if (!fs.existsSync(device.buildList().path) || !fs.statSync(device.buildList().path).isDirectory()) continue;
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;
633
650
  devices.push(device);
634
651
  }
635
652
  return devices;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arkts/image-manager",
3
3
  "type": "module",
4
- "version": "0.3.1",
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",