@arkts/image-manager 0.3.2 → 0.3.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/index.cjs CHANGED
@@ -40,7 +40,7 @@ let unzipper = require("unzipper");
40
40
  unzipper = __toESM(unzipper);
41
41
 
42
42
  //#region package.json
43
- var version = "0.3.2";
43
+ var version = "0.3.3";
44
44
 
45
45
  //#endregion
46
46
  //#region src/devices/list.ts
@@ -289,9 +289,18 @@ var DeviceImpl = class {
289
289
  }
290
290
  return ini;
291
291
  }
292
- async toIniString() {
292
+ toIniString() {
293
293
  return `${Object.entries(this.buildIni()).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
294
294
  }
295
+ buildDeviceIni() {
296
+ return {
297
+ "hvd.ini.encoding": "UTF-8",
298
+ "path": this.buildList().path
299
+ };
300
+ }
301
+ buildDeviceIniString() {
302
+ return `${Object.entries(this.buildDeviceIni()).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
303
+ }
295
304
  async deploy() {
296
305
  if (await this.isDeployed()) return;
297
306
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
@@ -304,9 +313,10 @@ var DeviceImpl = class {
304
313
  if (!Array.isArray(lists)) throw new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "Lists is not an array");
305
314
  if (lists.find((item) => item.name === listConfig.name)) throw new DeployError(DeployError.Code.DEVICE_ALREADY_DEPLOYED, `Image ${listConfig.name} already deployed in lists.json`);
306
315
  lists.push(listConfig);
307
- fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
308
316
  fs.mkdirSync(listConfig.path, { recursive: true });
309
- fs.writeFileSync(path.join(listConfig.path, "config.ini"), await this.toIniString());
317
+ fs.writeFileSync(path.join(listConfig.path, "config.ini"), this.toIniString());
318
+ fs.writeFileSync(path.join(deployedPath, `${this.options.name}.ini`), this.buildDeviceIniString());
319
+ fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
310
320
  }
311
321
  async delete() {
312
322
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
@@ -318,6 +328,7 @@ var DeviceImpl = class {
318
328
  lists.splice(index, 1);
319
329
  fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
320
330
  fs.rmSync(path.resolve(this.buildList().path), { recursive: true });
331
+ fs.rmSync(path.resolve(deployedPath, `${this.options.name}.ini`));
321
332
  }
322
333
  async isDeployed() {
323
334
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
package/dist/index.d.cts CHANGED
@@ -498,7 +498,7 @@ interface Device {
498
498
  getUuid(): Device.UUID;
499
499
  buildList(): FullDeployedImageOptions;
500
500
  buildIni(): Record<string, string | undefined>;
501
- toIniString(): Promise<string>;
501
+ toIniString(): string;
502
502
  deploy(): Promise<void>;
503
503
  delete(): Promise<void>;
504
504
  isDeployed(): Promise<boolean>;
package/dist/index.d.mts CHANGED
@@ -498,7 +498,7 @@ interface Device {
498
498
  getUuid(): Device.UUID;
499
499
  buildList(): FullDeployedImageOptions;
500
500
  buildIni(): Record<string, string | undefined>;
501
- toIniString(): Promise<string>;
501
+ toIniString(): string;
502
502
  deploy(): Promise<void>;
503
503
  delete(): Promise<void>;
504
504
  isDeployed(): Promise<boolean>;
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ import progress from "progress-stream";
6
6
  import unzipper from "unzipper";
7
7
 
8
8
  //#region package.json
9
- var version = "0.3.2";
9
+ var version = "0.3.3";
10
10
 
11
11
  //#endregion
12
12
  //#region src/devices/list.ts
@@ -255,9 +255,18 @@ var DeviceImpl = class {
255
255
  }
256
256
  return ini;
257
257
  }
258
- async toIniString() {
258
+ toIniString() {
259
259
  return `${Object.entries(this.buildIni()).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
260
260
  }
261
+ buildDeviceIni() {
262
+ return {
263
+ "hvd.ini.encoding": "UTF-8",
264
+ "path": this.buildList().path
265
+ };
266
+ }
267
+ buildDeviceIniString() {
268
+ return `${Object.entries(this.buildDeviceIni()).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
269
+ }
261
270
  async deploy() {
262
271
  if (await this.isDeployed()) return;
263
272
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
@@ -270,9 +279,10 @@ var DeviceImpl = class {
270
279
  if (!Array.isArray(lists)) throw new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "Lists is not an array");
271
280
  if (lists.find((item) => item.name === listConfig.name)) throw new DeployError(DeployError.Code.DEVICE_ALREADY_DEPLOYED, `Image ${listConfig.name} already deployed in lists.json`);
272
281
  lists.push(listConfig);
273
- fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
274
282
  fs.mkdirSync(listConfig.path, { recursive: true });
275
- fs.writeFileSync(path.join(listConfig.path, "config.ini"), await this.toIniString());
283
+ fs.writeFileSync(path.join(listConfig.path, "config.ini"), this.toIniString());
284
+ fs.writeFileSync(path.join(deployedPath, `${this.options.name}.ini`), this.buildDeviceIniString());
285
+ fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
276
286
  }
277
287
  async delete() {
278
288
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
@@ -284,6 +294,7 @@ var DeviceImpl = class {
284
294
  lists.splice(index, 1);
285
295
  fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
286
296
  fs.rmSync(path.resolve(this.buildList().path), { recursive: true });
297
+ fs.rmSync(path.resolve(deployedPath, `${this.options.name}.ini`));
287
298
  }
288
299
  async isDeployed() {
289
300
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arkts/image-manager",
3
3
  "type": "module",
4
- "version": "0.3.2",
4
+ "version": "0.3.3",
5
5
  "description": "OpenHarmony/HarmonyOS qemu image manager.",
6
6
  "author": "Naily Zero <zero@naily.cc> (https://naily.cc)",
7
7
  "license": "MIT",