@arkts/image-manager 0.3.2 → 0.3.4

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.4";
44
44
 
45
45
  //#endregion
46
46
  //#region src/devices/list.ts
@@ -289,24 +289,33 @@ 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
- if (await this.isDeployed()) return;
305
+ if (await this.isDeployed()) throw new DeployError(DeployError.Code.DEVICE_ALREADY_DEPLOYED, `Image ${this.options.name} already deployed`);
297
306
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
298
307
  if (!fs.existsSync(deployedPath)) fs.mkdirSync(deployedPath, { recursive: true });
299
308
  const listsPath = path.join(deployedPath, "lists.json");
300
309
  const listConfig = this.buildList();
301
- if (fs.existsSync(listConfig.path)) throw new DeployError(DeployError.Code.DEVICE_ALREADY_DEPLOYED, `Image ${listConfig.name} already deployed`);
302
310
  if (!fs.existsSync(listsPath)) return fs.writeFileSync(listsPath, JSON.stringify([listConfig], null, 2));
303
311
  const lists = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
304
312
  if (!Array.isArray(lists)) throw new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "Lists is not an array");
305
313
  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
314
  lists.push(listConfig);
307
- fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
308
315
  fs.mkdirSync(listConfig.path, { recursive: true });
309
- fs.writeFileSync(path.join(listConfig.path, "config.ini"), await this.toIniString());
316
+ fs.writeFileSync(path.join(listConfig.path, "config.ini"), this.toIniString());
317
+ fs.writeFileSync(path.join(deployedPath, `${this.options.name}.ini`), this.buildDeviceIniString());
318
+ fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
310
319
  }
311
320
  async delete() {
312
321
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
@@ -318,6 +327,7 @@ var DeviceImpl = class {
318
327
  lists.splice(index, 1);
319
328
  fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
320
329
  fs.rmSync(path.resolve(this.buildList().path), { recursive: true });
330
+ fs.rmSync(path.resolve(deployedPath, `${this.options.name}.ini`));
321
331
  }
322
332
  async isDeployed() {
323
333
  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.4";
10
10
 
11
11
  //#endregion
12
12
  //#region src/devices/list.ts
@@ -255,24 +255,33 @@ 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
- if (await this.isDeployed()) return;
271
+ if (await this.isDeployed()) throw new DeployError(DeployError.Code.DEVICE_ALREADY_DEPLOYED, `Image ${this.options.name} already deployed`);
263
272
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
264
273
  if (!fs.existsSync(deployedPath)) fs.mkdirSync(deployedPath, { recursive: true });
265
274
  const listsPath = path.join(deployedPath, "lists.json");
266
275
  const listConfig = this.buildList();
267
- if (fs.existsSync(listConfig.path)) throw new DeployError(DeployError.Code.DEVICE_ALREADY_DEPLOYED, `Image ${listConfig.name} already deployed`);
268
276
  if (!fs.existsSync(listsPath)) return fs.writeFileSync(listsPath, JSON.stringify([listConfig], null, 2));
269
277
  const lists = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
270
278
  if (!Array.isArray(lists)) throw new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "Lists is not an array");
271
279
  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
280
  lists.push(listConfig);
273
- fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
274
281
  fs.mkdirSync(listConfig.path, { recursive: true });
275
- fs.writeFileSync(path.join(listConfig.path, "config.ini"), await this.toIniString());
282
+ fs.writeFileSync(path.join(listConfig.path, "config.ini"), this.toIniString());
283
+ fs.writeFileSync(path.join(deployedPath, `${this.options.name}.ini`), this.buildDeviceIniString());
284
+ fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
276
285
  }
277
286
  async delete() {
278
287
  const { fs, path, deployedPath } = this.image.getImageManager().getOptions();
@@ -284,6 +293,7 @@ var DeviceImpl = class {
284
293
  lists.splice(index, 1);
285
294
  fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
286
295
  fs.rmSync(path.resolve(this.buildList().path), { recursive: true });
296
+ fs.rmSync(path.resolve(deployedPath, `${this.options.name}.ini`));
287
297
  }
288
298
  async isDeployed() {
289
299
  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.4",
5
5
  "description": "OpenHarmony/HarmonyOS qemu image manager.",
6
6
  "author": "Naily Zero <zero@naily.cc> (https://naily.cc)",
7
7
  "license": "MIT",