@arkts/image-manager 0.2.0 → 0.2.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 +63 -13
- package/dist/index.d.cts +21 -1
- package/dist/index.d.mts +21 -1
- package/dist/index.mjs +51 -13
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,6 +35,10 @@ progress_stream = __toESM(progress_stream);
|
|
|
35
35
|
let unzipper = require("unzipper");
|
|
36
36
|
unzipper = __toESM(unzipper);
|
|
37
37
|
|
|
38
|
+
//#region package.json
|
|
39
|
+
var version = "0.2.2";
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
38
42
|
//#region src/deployer/list.ts
|
|
39
43
|
let DevModel = /* @__PURE__ */ function(DevModel) {
|
|
40
44
|
DevModel["MCHEMU_AL00CN"] = "MCHEMU-AL00CN";
|
|
@@ -47,6 +51,27 @@ let DevModel = /* @__PURE__ */ function(DevModel) {
|
|
|
47
51
|
return DevModel;
|
|
48
52
|
}({});
|
|
49
53
|
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/errors/deploy-error.ts
|
|
56
|
+
var DeployError = class extends Error {
|
|
57
|
+
constructor(code, message, cause) {
|
|
58
|
+
super(message, { cause });
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.message = message;
|
|
61
|
+
this.cause = cause;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
(function(_DeployError) {
|
|
65
|
+
_DeployError.Code = /* @__PURE__ */ function(Code) {
|
|
66
|
+
Code["DEVICE_ALREADY_DEPLOYED"] = "DEVICE_ALREADY_DEPLOYED";
|
|
67
|
+
Code["LIST_JSON_NOT_AN_ARRAY"] = "LIST_JSON_NOT_AN_ARRAY";
|
|
68
|
+
Code["CATCHED_ERROR"] = "CATCHED_ERROR";
|
|
69
|
+
Code["MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO"] = "MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO";
|
|
70
|
+
Code["SYMLINK_SDK_PATH_EXISTS"] = "SYMLINK_SDK_PATH_EXISTS";
|
|
71
|
+
return Code;
|
|
72
|
+
}({});
|
|
73
|
+
})(DeployError || (DeployError = {}));
|
|
74
|
+
|
|
50
75
|
//#endregion
|
|
51
76
|
//#region src/errors/request-url-error.ts
|
|
52
77
|
var RequestUrlError = class extends Error {
|
|
@@ -203,23 +228,36 @@ var ImageDeployerImpl = class {
|
|
|
203
228
|
async toIniString() {
|
|
204
229
|
return `${Object.entries(await this.buildIni()).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
|
|
205
230
|
}
|
|
206
|
-
|
|
231
|
+
async writeToListWithCheck(config) {
|
|
207
232
|
const fs = this.image.getImageManager().getOptions().fs;
|
|
208
233
|
const listsPath = this.image.getImageManager().getOptions().path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
234
|
+
try {
|
|
235
|
+
if (!fs.existsSync(listsPath)) fs.writeFileSync(listsPath, JSON.stringify([config], null, 2));
|
|
236
|
+
else {
|
|
237
|
+
const lists = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
|
|
238
|
+
if (!Array.isArray(lists)) return new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "Lists is not an array");
|
|
239
|
+
if (lists.find((item) => item.name === config.name)) return;
|
|
240
|
+
lists.push(config);
|
|
241
|
+
fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
|
|
242
|
+
}
|
|
243
|
+
} catch (err) {
|
|
244
|
+
return err instanceof Error ? new DeployError(DeployError.Code.CATCHED_ERROR, String(err)) : new DeployError(DeployError.Code.CATCHED_ERROR, String(err));
|
|
216
245
|
}
|
|
246
|
+
return new Promise((resolve) => {
|
|
247
|
+
const timer = setTimeout(() => {
|
|
248
|
+
const content = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
|
|
249
|
+
if (!Array.isArray(content)) resolve(new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "List rechecker is not an array!"));
|
|
250
|
+
else if (!content.find((item) => item.name === config.name)) resolve(new DeployError(DeployError.Code.MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO, `Device ${config.name} not found in lists.json! Maybe not deployed yet?`));
|
|
251
|
+
else resolve();
|
|
252
|
+
clearTimeout(timer);
|
|
253
|
+
}, 1e3);
|
|
254
|
+
});
|
|
217
255
|
}
|
|
218
256
|
async deploy(symlinkImage = true) {
|
|
219
257
|
const { fs, path, imageBasePath, sdkPath } = this.image.getImageManager().getOptions();
|
|
220
258
|
const config = await this.buildList();
|
|
221
|
-
if (fs.existsSync(config.path)) return
|
|
222
|
-
const error = this.
|
|
259
|
+
if (fs.existsSync(config.path)) return new DeployError(DeployError.Code.DEVICE_ALREADY_DEPLOYED, `Image ${config.name} already deployed`);
|
|
260
|
+
const error = await this.writeToListWithCheck(config);
|
|
223
261
|
if (error) return error;
|
|
224
262
|
fs.mkdirSync(config.path, { recursive: true });
|
|
225
263
|
fs.writeFileSync(path.join(config.path, "config.ini"), await this.toIniString());
|
|
@@ -227,7 +265,7 @@ var ImageDeployerImpl = class {
|
|
|
227
265
|
if (!fs.existsSync(path.dirname(symlinkSdkPath))) fs.mkdirSync(path.dirname(symlinkSdkPath), { recursive: true });
|
|
228
266
|
try {
|
|
229
267
|
if (fs.lstatSync(symlinkSdkPath).isSymbolicLink()) fs.unlinkSync(symlinkSdkPath);
|
|
230
|
-
else return
|
|
268
|
+
else return new DeployError(DeployError.Code.SYMLINK_SDK_PATH_EXISTS, "Symlink SDK path already exists");
|
|
231
269
|
} catch {}
|
|
232
270
|
fs.symlinkSync(sdkPath, symlinkSdkPath, "dir");
|
|
233
271
|
const systemImageDir = path.join(imageBasePath, "system-image");
|
|
@@ -237,7 +275,7 @@ var ImageDeployerImpl = class {
|
|
|
237
275
|
const target = path.relative(config.path, systemImageDir);
|
|
238
276
|
fs.symlinkSync(target, linkPath);
|
|
239
277
|
} catch (err) {
|
|
240
|
-
return err instanceof Error ? err : new
|
|
278
|
+
return err instanceof Error ? new DeployError(DeployError.Code.CATCHED_ERROR, String(err)) : new DeployError(DeployError.Code.CATCHED_ERROR, String(err));
|
|
241
279
|
}
|
|
242
280
|
}
|
|
243
281
|
}
|
|
@@ -714,7 +752,19 @@ function createDeployedImageConfig(productConfigItem) {
|
|
|
714
752
|
}
|
|
715
753
|
|
|
716
754
|
//#endregion
|
|
755
|
+
Object.defineProperty(exports, 'DeployError', {
|
|
756
|
+
enumerable: true,
|
|
757
|
+
get: function () {
|
|
758
|
+
return DeployError;
|
|
759
|
+
}
|
|
760
|
+
});
|
|
717
761
|
exports.DevModel = DevModel;
|
|
718
762
|
exports.RequestUrlError = RequestUrlError;
|
|
719
763
|
exports.createDeployedImageConfig = createDeployedImageConfig;
|
|
720
|
-
exports.createImageManager = createImageManager;
|
|
764
|
+
exports.createImageManager = createImageManager;
|
|
765
|
+
Object.defineProperty(exports, 'version', {
|
|
766
|
+
enumerable: true,
|
|
767
|
+
get: function () {
|
|
768
|
+
return version;
|
|
769
|
+
}
|
|
770
|
+
});
|
package/dist/index.d.cts
CHANGED
|
@@ -9,6 +9,9 @@ import * as node_path0 from "node:path";
|
|
|
9
9
|
import * as node_process0 from "node:process";
|
|
10
10
|
import * as node_crypto0 from "node:crypto";
|
|
11
11
|
|
|
12
|
+
//#region package.json.d.ts
|
|
13
|
+
declare let version: string;
|
|
14
|
+
//#endregion
|
|
12
15
|
//#region src/images/local-image.d.ts
|
|
13
16
|
interface LocalImage extends BaseImage, Stringifiable<LocalImage.Stringifiable> {
|
|
14
17
|
imageType: 'local';
|
|
@@ -187,6 +190,23 @@ interface ImageManager {
|
|
|
187
190
|
}
|
|
188
191
|
declare function createImageManager(options?: ImageManagerOptions): Promise<ImageManager>;
|
|
189
192
|
//#endregion
|
|
193
|
+
//#region src/errors/deploy-error.d.ts
|
|
194
|
+
declare class DeployError extends Error {
|
|
195
|
+
readonly code: DeployError.Code;
|
|
196
|
+
readonly message: string;
|
|
197
|
+
readonly cause?: Error;
|
|
198
|
+
constructor(code: DeployError.Code, message: string, cause?: Error);
|
|
199
|
+
}
|
|
200
|
+
declare namespace DeployError {
|
|
201
|
+
enum Code {
|
|
202
|
+
DEVICE_ALREADY_DEPLOYED = "DEVICE_ALREADY_DEPLOYED",
|
|
203
|
+
LIST_JSON_NOT_AN_ARRAY = "LIST_JSON_NOT_AN_ARRAY",
|
|
204
|
+
CATCHED_ERROR = "CATCHED_ERROR",
|
|
205
|
+
MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO = "MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO",
|
|
206
|
+
SYMLINK_SDK_PATH_EXISTS = "SYMLINK_SDK_PATH_EXISTS"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
//#endregion
|
|
190
210
|
//#region src/errors/request-url-error.d.ts
|
|
191
211
|
declare class RequestUrlError extends Error {
|
|
192
212
|
readonly message: string;
|
|
@@ -284,4 +304,4 @@ interface Device {
|
|
|
284
304
|
delete(): Promise<void | Error>;
|
|
285
305
|
}
|
|
286
306
|
//#endregion
|
|
287
|
-
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 };
|
|
307
|
+
export { Arch, DeployError, DeployedDevModel, DeployedImageConfig, DeployedImageConfigWithProductName, DeployedImageOptions, DevModel, Device, DeviceType, FullDeployedImageOptions, Image, type ImageManager, type ImageManagerOptions, ImageType, LocalImage, OS, PascalCaseDeviceType, type ProductConfig, type ProductConfigItem, ProductNameable, RemoteImage, RequestUrlError, SnakecaseDeviceType, Stringifiable, createDeployedImageConfig, createImageManager, version };
|
package/dist/index.d.mts
CHANGED
|
@@ -9,6 +9,9 @@ import * as node_os0 from "node:os";
|
|
|
9
9
|
import * as node_path0 from "node:path";
|
|
10
10
|
import * as node_process0 from "node:process";
|
|
11
11
|
|
|
12
|
+
//#region package.json.d.ts
|
|
13
|
+
declare let version: string;
|
|
14
|
+
//#endregion
|
|
12
15
|
//#region src/images/local-image.d.ts
|
|
13
16
|
interface LocalImage extends BaseImage, Stringifiable<LocalImage.Stringifiable> {
|
|
14
17
|
imageType: 'local';
|
|
@@ -187,6 +190,23 @@ interface ImageManager {
|
|
|
187
190
|
}
|
|
188
191
|
declare function createImageManager(options?: ImageManagerOptions): Promise<ImageManager>;
|
|
189
192
|
//#endregion
|
|
193
|
+
//#region src/errors/deploy-error.d.ts
|
|
194
|
+
declare class DeployError extends Error {
|
|
195
|
+
readonly code: DeployError.Code;
|
|
196
|
+
readonly message: string;
|
|
197
|
+
readonly cause?: Error;
|
|
198
|
+
constructor(code: DeployError.Code, message: string, cause?: Error);
|
|
199
|
+
}
|
|
200
|
+
declare namespace DeployError {
|
|
201
|
+
enum Code {
|
|
202
|
+
DEVICE_ALREADY_DEPLOYED = "DEVICE_ALREADY_DEPLOYED",
|
|
203
|
+
LIST_JSON_NOT_AN_ARRAY = "LIST_JSON_NOT_AN_ARRAY",
|
|
204
|
+
CATCHED_ERROR = "CATCHED_ERROR",
|
|
205
|
+
MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO = "MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO",
|
|
206
|
+
SYMLINK_SDK_PATH_EXISTS = "SYMLINK_SDK_PATH_EXISTS"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
//#endregion
|
|
190
210
|
//#region src/errors/request-url-error.d.ts
|
|
191
211
|
declare class RequestUrlError extends Error {
|
|
192
212
|
readonly message: string;
|
|
@@ -284,4 +304,4 @@ interface Device {
|
|
|
284
304
|
delete(): Promise<void | Error>;
|
|
285
305
|
}
|
|
286
306
|
//#endregion
|
|
287
|
-
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 };
|
|
307
|
+
export { Arch, DeployError, DeployedDevModel, DeployedImageConfig, DeployedImageConfigWithProductName, DeployedImageOptions, DevModel, type Device, DeviceType, FullDeployedImageOptions, type Image, type ImageManager, type ImageManagerOptions, type ImageType, type LocalImage, OS, PascalCaseDeviceType, type ProductConfig, type ProductConfigItem, ProductNameable, type RemoteImage, RequestUrlError, SnakecaseDeviceType, Stringifiable, createDeployedImageConfig, createImageManager, version };
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,10 @@ import mitt from "mitt";
|
|
|
3
3
|
import progress from "progress-stream";
|
|
4
4
|
import unzipper from "unzipper";
|
|
5
5
|
|
|
6
|
+
//#region package.json
|
|
7
|
+
var version = "0.2.2";
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
6
10
|
//#region src/deployer/list.ts
|
|
7
11
|
let DevModel = /* @__PURE__ */ function(DevModel) {
|
|
8
12
|
DevModel["MCHEMU_AL00CN"] = "MCHEMU-AL00CN";
|
|
@@ -15,6 +19,27 @@ let DevModel = /* @__PURE__ */ function(DevModel) {
|
|
|
15
19
|
return DevModel;
|
|
16
20
|
}({});
|
|
17
21
|
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/errors/deploy-error.ts
|
|
24
|
+
var DeployError = class extends Error {
|
|
25
|
+
constructor(code, message, cause) {
|
|
26
|
+
super(message, { cause });
|
|
27
|
+
this.code = code;
|
|
28
|
+
this.message = message;
|
|
29
|
+
this.cause = cause;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
(function(_DeployError) {
|
|
33
|
+
_DeployError.Code = /* @__PURE__ */ function(Code) {
|
|
34
|
+
Code["DEVICE_ALREADY_DEPLOYED"] = "DEVICE_ALREADY_DEPLOYED";
|
|
35
|
+
Code["LIST_JSON_NOT_AN_ARRAY"] = "LIST_JSON_NOT_AN_ARRAY";
|
|
36
|
+
Code["CATCHED_ERROR"] = "CATCHED_ERROR";
|
|
37
|
+
Code["MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO"] = "MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO";
|
|
38
|
+
Code["SYMLINK_SDK_PATH_EXISTS"] = "SYMLINK_SDK_PATH_EXISTS";
|
|
39
|
+
return Code;
|
|
40
|
+
}({});
|
|
41
|
+
})(DeployError || (DeployError = {}));
|
|
42
|
+
|
|
18
43
|
//#endregion
|
|
19
44
|
//#region src/errors/request-url-error.ts
|
|
20
45
|
var RequestUrlError = class extends Error {
|
|
@@ -171,23 +196,36 @@ var ImageDeployerImpl = class {
|
|
|
171
196
|
async toIniString() {
|
|
172
197
|
return `${Object.entries(await this.buildIni()).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${value}`).join("\n")}\n`;
|
|
173
198
|
}
|
|
174
|
-
|
|
199
|
+
async writeToListWithCheck(config) {
|
|
175
200
|
const fs = this.image.getImageManager().getOptions().fs;
|
|
176
201
|
const listsPath = this.image.getImageManager().getOptions().path.resolve(this.image.getImageManager().getOptions().deployedPath, "lists.json");
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
202
|
+
try {
|
|
203
|
+
if (!fs.existsSync(listsPath)) fs.writeFileSync(listsPath, JSON.stringify([config], null, 2));
|
|
204
|
+
else {
|
|
205
|
+
const lists = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
|
|
206
|
+
if (!Array.isArray(lists)) return new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "Lists is not an array");
|
|
207
|
+
if (lists.find((item) => item.name === config.name)) return;
|
|
208
|
+
lists.push(config);
|
|
209
|
+
fs.writeFileSync(listsPath, JSON.stringify(lists, null, 2));
|
|
210
|
+
}
|
|
211
|
+
} catch (err) {
|
|
212
|
+
return err instanceof Error ? new DeployError(DeployError.Code.CATCHED_ERROR, String(err)) : new DeployError(DeployError.Code.CATCHED_ERROR, String(err));
|
|
184
213
|
}
|
|
214
|
+
return new Promise((resolve) => {
|
|
215
|
+
const timer = setTimeout(() => {
|
|
216
|
+
const content = JSON.parse(fs.readFileSync(listsPath, "utf-8")) ?? [];
|
|
217
|
+
if (!Array.isArray(content)) resolve(new DeployError(DeployError.Code.LIST_JSON_NOT_AN_ARRAY, "List rechecker is not an array!"));
|
|
218
|
+
else if (!content.find((item) => item.name === config.name)) resolve(new DeployError(DeployError.Code.MAYBE_OPENED_DEVICE_MANAGER_IN_DEVECO_STUDIO, `Device ${config.name} not found in lists.json! Maybe not deployed yet?`));
|
|
219
|
+
else resolve();
|
|
220
|
+
clearTimeout(timer);
|
|
221
|
+
}, 1e3);
|
|
222
|
+
});
|
|
185
223
|
}
|
|
186
224
|
async deploy(symlinkImage = true) {
|
|
187
225
|
const { fs, path, imageBasePath, sdkPath } = this.image.getImageManager().getOptions();
|
|
188
226
|
const config = await this.buildList();
|
|
189
|
-
if (fs.existsSync(config.path)) return
|
|
190
|
-
const error = this.
|
|
227
|
+
if (fs.existsSync(config.path)) return new DeployError(DeployError.Code.DEVICE_ALREADY_DEPLOYED, `Image ${config.name} already deployed`);
|
|
228
|
+
const error = await this.writeToListWithCheck(config);
|
|
191
229
|
if (error) return error;
|
|
192
230
|
fs.mkdirSync(config.path, { recursive: true });
|
|
193
231
|
fs.writeFileSync(path.join(config.path, "config.ini"), await this.toIniString());
|
|
@@ -195,7 +233,7 @@ var ImageDeployerImpl = class {
|
|
|
195
233
|
if (!fs.existsSync(path.dirname(symlinkSdkPath))) fs.mkdirSync(path.dirname(symlinkSdkPath), { recursive: true });
|
|
196
234
|
try {
|
|
197
235
|
if (fs.lstatSync(symlinkSdkPath).isSymbolicLink()) fs.unlinkSync(symlinkSdkPath);
|
|
198
|
-
else return
|
|
236
|
+
else return new DeployError(DeployError.Code.SYMLINK_SDK_PATH_EXISTS, "Symlink SDK path already exists");
|
|
199
237
|
} catch {}
|
|
200
238
|
fs.symlinkSync(sdkPath, symlinkSdkPath, "dir");
|
|
201
239
|
const systemImageDir = path.join(imageBasePath, "system-image");
|
|
@@ -205,7 +243,7 @@ var ImageDeployerImpl = class {
|
|
|
205
243
|
const target = path.relative(config.path, systemImageDir);
|
|
206
244
|
fs.symlinkSync(target, linkPath);
|
|
207
245
|
} catch (err) {
|
|
208
|
-
return err instanceof Error ? err : new
|
|
246
|
+
return err instanceof Error ? new DeployError(DeployError.Code.CATCHED_ERROR, String(err)) : new DeployError(DeployError.Code.CATCHED_ERROR, String(err));
|
|
209
247
|
}
|
|
210
248
|
}
|
|
211
249
|
}
|
|
@@ -682,4 +720,4 @@ function createDeployedImageConfig(productConfigItem) {
|
|
|
682
720
|
}
|
|
683
721
|
|
|
684
722
|
//#endregion
|
|
685
|
-
export { DevModel, RequestUrlError, createDeployedImageConfig, createImageManager };
|
|
723
|
+
export { DeployError, DevModel, RequestUrlError, createDeployedImageConfig, createImageManager, version };
|
package/package.json
CHANGED