meminsight-core-publish 1.0.0
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.d.ts +21 -0
- package/dist/Index.d.ts.map +1 -0
- package/dist/Index.js +65 -0
- package/dist/analyzer/AnalysisInfo.d.ts +112 -0
- package/dist/analyzer/AnalysisInfo.d.ts.map +1 -0
- package/dist/analyzer/AnalysisInfo.js +217 -0
- package/dist/analyzer/ArkAnalyzer.d.ts +30 -0
- package/dist/analyzer/ArkAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/ArkAnalyzer.js +52 -0
- package/dist/analyzer/ArkCmpCfg.d.ts +15 -0
- package/dist/analyzer/ArkCmpCfg.d.ts.map +1 -0
- package/dist/analyzer/ArkCmpCfg.js +15 -0
- package/dist/analyzer/ArkCompareAnalyzer.d.ts +52 -0
- package/dist/analyzer/ArkCompareAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/ArkCompareAnalyzer.js +144 -0
- package/dist/analyzer/ArkLeakAnalyzer.d.ts +14 -0
- package/dist/analyzer/ArkLeakAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/ArkLeakAnalyzer.js +18 -0
- package/dist/analyzer/ArkSerializer.d.ts +18 -0
- package/dist/analyzer/ArkSerializer.d.ts.map +1 -0
- package/dist/analyzer/ArkSerializer.js +155 -0
- package/dist/analyzer/ArkStatAnalyzer.d.ts +56 -0
- package/dist/analyzer/ArkStatAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/ArkStatAnalyzer.js +224 -0
- package/dist/analyzer/ArkStatCfg.d.ts +42 -0
- package/dist/analyzer/ArkStatCfg.d.ts.map +1 -0
- package/dist/analyzer/ArkStatCfg.js +42 -0
- package/dist/analyzer/ArkTracePath.d.ts +90 -0
- package/dist/analyzer/ArkTracePath.d.ts.map +1 -0
- package/dist/analyzer/ArkTracePath.js +245 -0
- package/dist/analyzer/ArkTracer.d.ts +17 -0
- package/dist/analyzer/ArkTracer.d.ts.map +1 -0
- package/dist/analyzer/ArkTracer.js +27 -0
- package/dist/analyzer/ArkXAnalyzer.d.ts +69 -0
- package/dist/analyzer/ArkXAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/ArkXAnalyzer.js +616 -0
- package/dist/analyzer/IAnalyzer.d.ts +25 -0
- package/dist/analyzer/IAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/IAnalyzer.js +2 -0
- package/dist/file/FileReader.d.ts +51 -0
- package/dist/file/FileReader.d.ts.map +1 -0
- package/dist/file/FileReader.js +110 -0
- package/dist/file/FileService.d.ts +23 -0
- package/dist/file/FileService.d.ts.map +1 -0
- package/dist/file/FileService.js +65 -0
- package/dist/file/FileWriter.d.ts +82 -0
- package/dist/file/FileWriter.d.ts.map +1 -0
- package/dist/file/FileWriter.js +160 -0
- package/dist/report/Reporter.d.ts +27 -0
- package/dist/report/Reporter.d.ts.map +1 -0
- package/dist/report/Reporter.js +61 -0
- package/dist/report/templates/template.d.ts +3 -0
- package/dist/report/templates/template.d.ts.map +1 -0
- package/dist/report/templates/template.js +106 -0
- package/dist/shell/DeviceShell.d.ts +96 -0
- package/dist/shell/DeviceShell.d.ts.map +1 -0
- package/dist/shell/DeviceShell.js +180 -0
- package/dist/shell/Shell.d.ts +52 -0
- package/dist/shell/Shell.d.ts.map +1 -0
- package/dist/shell/Shell.js +79 -0
- package/dist/types/Constants.d.ts +15 -0
- package/dist/types/Constants.d.ts.map +1 -0
- package/dist/types/Constants.js +18 -0
- package/dist/types/LeakTypes.d.ts +18 -0
- package/dist/types/LeakTypes.d.ts.map +1 -0
- package/dist/types/LeakTypes.js +2 -0
- package/dist/types/OhosTypes.d.ts +74 -0
- package/dist/types/OhosTypes.d.ts.map +1 -0
- package/dist/types/OhosTypes.js +83 -0
- package/dist/utils/Common.d.ts +14 -0
- package/dist/utils/Common.d.ts.map +1 -0
- package/dist/utils/Common.js +38 -0
- package/dist/utils/Finder.d.ts +163 -0
- package/dist/utils/Finder.d.ts.map +1 -0
- package/dist/utils/Finder.js +355 -0
- package/dist/utils/Loader.d.ts +30 -0
- package/dist/utils/Loader.d.ts.map +1 -0
- package/dist/utils/Loader.js +71 -0
- package/dist/utils/Log.d.ts +140 -0
- package/dist/utils/Log.d.ts.map +1 -0
- package/dist/utils/Log.js +177 -0
- package/dist/utils/Output.d.ts +126 -0
- package/dist/utils/Output.d.ts.map +1 -0
- package/dist/utils/Output.js +225 -0
- package/package.json +61 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ILoggable } from '../utils/Log';
|
|
2
|
+
/**
|
|
3
|
+
* interface of reader
|
|
4
|
+
*/
|
|
5
|
+
export interface IReader {
|
|
6
|
+
getType(): string;
|
|
7
|
+
readFromFile<T>(filepath: string, encoding: BufferEncoding): Promise<T | undefined>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* base reader
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class BaseReader implements ILoggable, IReader {
|
|
13
|
+
readonly DOMAIN: string;
|
|
14
|
+
readonly TAG: string;
|
|
15
|
+
protected type: string;
|
|
16
|
+
/**
|
|
17
|
+
* get type
|
|
18
|
+
* @returns type
|
|
19
|
+
*/
|
|
20
|
+
getType(): string;
|
|
21
|
+
/**
|
|
22
|
+
* write to file
|
|
23
|
+
* @param file filepath
|
|
24
|
+
* @param data data
|
|
25
|
+
* @returns T | undefined
|
|
26
|
+
*/
|
|
27
|
+
readFromFile<T>(filepath: string, encoding?: BufferEncoding): Promise<T | undefined>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* JsonReader
|
|
31
|
+
*/
|
|
32
|
+
export declare class JsonReader extends BaseReader {
|
|
33
|
+
readonly DOMAIN: string;
|
|
34
|
+
readonly TAG: string;
|
|
35
|
+
protected type: string;
|
|
36
|
+
private static _instance;
|
|
37
|
+
constructor();
|
|
38
|
+
/**
|
|
39
|
+
* JsonReader instance
|
|
40
|
+
* @returns instance
|
|
41
|
+
*/
|
|
42
|
+
static instance(): JsonReader;
|
|
43
|
+
/**
|
|
44
|
+
* read json file
|
|
45
|
+
* @param filepath json file path
|
|
46
|
+
* @param encode encoding, default is utf-
|
|
47
|
+
* @returns T | undefined
|
|
48
|
+
*/
|
|
49
|
+
readFromFile<T>(filepath: string, encoding?: BufferEncoding): Promise<T | undefined>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=FileReader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileReader.d.ts","sourceRoot":"","sources":["../../src/file/FileReader.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,OAAO;IACpB,OAAO,IAAI,MAAM,CAAC;IAClB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;CACvF;AAED;;GAEG;AACH,8BAAsB,UAAW,YAAW,SAAS,EAAE,OAAO;IAC1D,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACI,OAAO,IAAI,MAAM;IAIxB;;;;;OAKG;IACU,YAAY,CAAC,CAAC,EACvB,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,cAAwB,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;CAGlE;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,UAAU;IACtC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAa;;IASrC;;;OAGG;WACW,QAAQ,IAAI,UAAU;IAOpC;;;;;OAKG;IACU,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EACzC,QAAQ,GAAE,cAAwB,GAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;CAQnE"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.JsonReader = exports.BaseReader = void 0;
|
|
46
|
+
const fse = __importStar(require("fs-extra"));
|
|
47
|
+
const Log_1 = require("../utils/Log");
|
|
48
|
+
/**
|
|
49
|
+
* base reader
|
|
50
|
+
*/
|
|
51
|
+
class BaseReader {
|
|
52
|
+
/**
|
|
53
|
+
* get type
|
|
54
|
+
* @returns type
|
|
55
|
+
*/
|
|
56
|
+
getType() {
|
|
57
|
+
return this.type;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* write to file
|
|
61
|
+
* @param file filepath
|
|
62
|
+
* @param data data
|
|
63
|
+
* @returns T | undefined
|
|
64
|
+
*/
|
|
65
|
+
readFromFile(filepath_1) {
|
|
66
|
+
return __awaiter(this, arguments, void 0, function* (filepath, encoding = 'utf-8') {
|
|
67
|
+
return undefined;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.BaseReader = BaseReader;
|
|
72
|
+
/**
|
|
73
|
+
* JsonReader
|
|
74
|
+
*/
|
|
75
|
+
class JsonReader extends BaseReader {
|
|
76
|
+
constructor() {
|
|
77
|
+
super();
|
|
78
|
+
this.DOMAIN = 'meminsight';
|
|
79
|
+
this.TAG = JsonReader.name;
|
|
80
|
+
this.type = JsonReader.name;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* JsonReader instance
|
|
84
|
+
* @returns instance
|
|
85
|
+
*/
|
|
86
|
+
static instance() {
|
|
87
|
+
if (!JsonReader._instance) {
|
|
88
|
+
JsonReader._instance = new JsonReader();
|
|
89
|
+
}
|
|
90
|
+
return JsonReader._instance;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* read json file
|
|
94
|
+
* @param filepath json file path
|
|
95
|
+
* @param encode encoding, default is utf-
|
|
96
|
+
* @returns T | undefined
|
|
97
|
+
*/
|
|
98
|
+
readFromFile(filepath_1) {
|
|
99
|
+
return __awaiter(this, arguments, void 0, function* (filepath, encoding = 'utf-8') {
|
|
100
|
+
try {
|
|
101
|
+
return fse.readJSONSync(filepath, encoding);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
Log_1.Log.errorX(this, `Failed to read json from file, Status Code: ${error}`);
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.JsonReader = JsonReader;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ILoggable } from '../utils/Log';
|
|
2
|
+
/**
|
|
3
|
+
* File Service
|
|
4
|
+
*/
|
|
5
|
+
export declare class FileService implements ILoggable {
|
|
6
|
+
readonly DOMAIN = "meminsight";
|
|
7
|
+
readonly TAG: string;
|
|
8
|
+
private static _instance;
|
|
9
|
+
private constructor();
|
|
10
|
+
/**
|
|
11
|
+
* FileService instance
|
|
12
|
+
* @returns FileService instance
|
|
13
|
+
*/
|
|
14
|
+
static instance(): FileService;
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param url file url
|
|
18
|
+
* @param filepath filepath
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
download(url: string, filepath: string): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=FileService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileService.d.ts","sourceRoot":"","sources":["../../src/file/FileService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAO,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C;;GAEG;AACH,qBAAa,WAAY,YAAW,SAAS;IACzC,SAAgB,MAAM,gBAAgB;IACtC,SAAgB,GAAG,SAAoB;IACvC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAc;IACtC,OAAO;IAEP;;;OAGG;WACW,QAAQ,IAAI,WAAW;IAOrC;;;;;OAKG;IACU,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAmBtE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.FileService = void 0;
|
|
16
|
+
const fs_1 = require("fs");
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const Log_1 = require("../utils/Log");
|
|
19
|
+
/**
|
|
20
|
+
* File Service
|
|
21
|
+
*/
|
|
22
|
+
class FileService {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.DOMAIN = 'meminsight';
|
|
25
|
+
this.TAG = FileService.name;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* FileService instance
|
|
29
|
+
* @returns FileService instance
|
|
30
|
+
*/
|
|
31
|
+
static instance() {
|
|
32
|
+
if (!FileService._instance) {
|
|
33
|
+
FileService._instance = new FileService();
|
|
34
|
+
}
|
|
35
|
+
return FileService._instance;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param url file url
|
|
40
|
+
* @param filepath filepath
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
download(url, filepath) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const response = yield (0, axios_1.default)({
|
|
46
|
+
url,
|
|
47
|
+
method: 'GET',
|
|
48
|
+
responseType: 'stream'
|
|
49
|
+
});
|
|
50
|
+
const fileWriter = (0, fs_1.createWriteStream)(filepath);
|
|
51
|
+
response.data.pipe(fileWriter);
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
fileWriter.on('finish', () => {
|
|
54
|
+
Log_1.Log.infoX(this, `File ${url} downloaded to ${filepath} successfully`);
|
|
55
|
+
resolve();
|
|
56
|
+
});
|
|
57
|
+
fileWriter.on('error', (err) => {
|
|
58
|
+
Log_1.Log.errorX(this, `Failed to download file ${url}, Status code: ${err}`);
|
|
59
|
+
reject(err);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.FileService = FileService;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ILoggable } from '../utils/Log';
|
|
2
|
+
/**
|
|
3
|
+
* writer interface
|
|
4
|
+
*/
|
|
5
|
+
export interface IWriter {
|
|
6
|
+
/**
|
|
7
|
+
* get type of writer
|
|
8
|
+
*/
|
|
9
|
+
getType(): string;
|
|
10
|
+
/**
|
|
11
|
+
* write to file
|
|
12
|
+
* @param file filepath
|
|
13
|
+
* @param data data
|
|
14
|
+
* @param encode encode, default is utf-8
|
|
15
|
+
*/
|
|
16
|
+
writeToFile(filepath: string, data: any, encode: BufferEncoding): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* base writer
|
|
20
|
+
*/
|
|
21
|
+
export declare class BaseWriter implements ILoggable, IWriter {
|
|
22
|
+
readonly DOMAIN: string;
|
|
23
|
+
readonly TAG: string;
|
|
24
|
+
protected type: string;
|
|
25
|
+
/**
|
|
26
|
+
* get type
|
|
27
|
+
* @returns type
|
|
28
|
+
*/
|
|
29
|
+
getType(): string;
|
|
30
|
+
/**
|
|
31
|
+
* write to file
|
|
32
|
+
* @param file filepath
|
|
33
|
+
* @param data data
|
|
34
|
+
* @param encoding encoding, default is utf-8
|
|
35
|
+
*/
|
|
36
|
+
writeToFile(filepath: string, data: any, encoding: BufferEncoding): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* text writer
|
|
40
|
+
*/
|
|
41
|
+
export declare class TextWriter extends BaseWriter {
|
|
42
|
+
readonly DOMAIN: string;
|
|
43
|
+
readonly TAG: string;
|
|
44
|
+
protected type: string;
|
|
45
|
+
protected static _instance: IWriter;
|
|
46
|
+
static instance(): IWriter;
|
|
47
|
+
constructor();
|
|
48
|
+
writeToFile(filepath: string, data: any, encoding: BufferEncoding): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* json writer
|
|
52
|
+
*/
|
|
53
|
+
export declare class JsonWriter extends BaseWriter {
|
|
54
|
+
readonly DOMAIN: string;
|
|
55
|
+
readonly TAG: string;
|
|
56
|
+
protected type: string;
|
|
57
|
+
protected static _instance: IWriter;
|
|
58
|
+
static instance(): IWriter;
|
|
59
|
+
constructor();
|
|
60
|
+
writeToFile(filepath: string, data: any, encoding: BufferEncoding): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* html writer
|
|
64
|
+
*/
|
|
65
|
+
export declare class HtmlWriter extends BaseWriter {
|
|
66
|
+
readonly DOMAIN: string;
|
|
67
|
+
readonly TAG: string;
|
|
68
|
+
protected type: string;
|
|
69
|
+
protected static _instance: IWriter;
|
|
70
|
+
static instance(): IWriter;
|
|
71
|
+
constructor();
|
|
72
|
+
writeToFile(filepath: string, data: any, encoding: BufferEncoding): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* 从template读取数据并将data插入模板数据中
|
|
75
|
+
* @param template 模板路径
|
|
76
|
+
* @param data 待插入数据
|
|
77
|
+
* @param delimiter 分隔符
|
|
78
|
+
* @return 插入data后的模板数据
|
|
79
|
+
*/
|
|
80
|
+
getDataByTemplate(template: string, data: string, delimiter: string): string;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=FileWriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileWriter.d.ts","sourceRoot":"","sources":["../../src/file/FileWriter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,OAAO;IACpB;;OAEG;IACH,OAAO,IAAI,MAAM,CAAC;IAElB;;;;;OAKG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnF;AAED;;GAEG;AACH,qBAAa,UAAW,YAAW,SAAS,EAAE,OAAO;IACjD,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACI,OAAO,IAAI,MAAM;IAIxB;;;;;OAKG;IACU,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAG,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAIlG;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,UAAU;IACtC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC;WAEtB,QAAQ,IAAI,OAAO;;IAcpB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAG,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlG;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,UAAU;IACtC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC;WAEtB,QAAQ,IAAI,OAAO;;IAcpB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAGjG;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,UAAU;IACtC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC;WAEtB,QAAQ,IAAI,OAAO;;IAcpB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAG,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/F;;;;;;OAMG;IACI,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM;CAOtF"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.HtmlWriter = exports.JsonWriter = exports.TextWriter = exports.BaseWriter = void 0;
|
|
46
|
+
const fse = __importStar(require("fs-extra"));
|
|
47
|
+
/**
|
|
48
|
+
* base writer
|
|
49
|
+
*/
|
|
50
|
+
class BaseWriter {
|
|
51
|
+
/**
|
|
52
|
+
* get type
|
|
53
|
+
* @returns type
|
|
54
|
+
*/
|
|
55
|
+
getType() {
|
|
56
|
+
return this.type;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* write to file
|
|
60
|
+
* @param file filepath
|
|
61
|
+
* @param data data
|
|
62
|
+
* @param encoding encoding, default is utf-8
|
|
63
|
+
*/
|
|
64
|
+
writeToFile(filepath, data, encoding) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const buf = Buffer.isBuffer(data) ? data : Buffer.from(data, encoding);
|
|
67
|
+
fse.outputFileSync(filepath, buf);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.BaseWriter = BaseWriter;
|
|
72
|
+
/**
|
|
73
|
+
* text writer
|
|
74
|
+
*/
|
|
75
|
+
class TextWriter extends BaseWriter {
|
|
76
|
+
static instance() {
|
|
77
|
+
if (this._instance == null) {
|
|
78
|
+
this._instance = new TextWriter();
|
|
79
|
+
}
|
|
80
|
+
return this._instance;
|
|
81
|
+
}
|
|
82
|
+
constructor() {
|
|
83
|
+
super();
|
|
84
|
+
this.DOMAIN = 'meminsight';
|
|
85
|
+
this.TAG = TextWriter.name;
|
|
86
|
+
this.type = TextWriter.name;
|
|
87
|
+
}
|
|
88
|
+
writeToFile(filepath, data, encoding) {
|
|
89
|
+
const _super = Object.create(null, {
|
|
90
|
+
writeToFile: { get: () => super.writeToFile }
|
|
91
|
+
});
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
_super.writeToFile.call(this, filepath, data, encoding);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.TextWriter = TextWriter;
|
|
98
|
+
/**
|
|
99
|
+
* json writer
|
|
100
|
+
*/
|
|
101
|
+
class JsonWriter extends BaseWriter {
|
|
102
|
+
static instance() {
|
|
103
|
+
if (this._instance == null) {
|
|
104
|
+
this._instance = new JsonWriter();
|
|
105
|
+
}
|
|
106
|
+
return this._instance;
|
|
107
|
+
}
|
|
108
|
+
constructor() {
|
|
109
|
+
super();
|
|
110
|
+
this.DOMAIN = 'meminsight';
|
|
111
|
+
this.TAG = JsonWriter.name;
|
|
112
|
+
this.type = JsonWriter.name;
|
|
113
|
+
}
|
|
114
|
+
writeToFile(filepath, data, encoding) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
fse.outputJSONSync(filepath, data, { encoding: encoding, spaces: 4 });
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.JsonWriter = JsonWriter;
|
|
121
|
+
/**
|
|
122
|
+
* html writer
|
|
123
|
+
*/
|
|
124
|
+
class HtmlWriter extends BaseWriter {
|
|
125
|
+
static instance() {
|
|
126
|
+
if (this._instance == null) {
|
|
127
|
+
this._instance = new HtmlWriter();
|
|
128
|
+
}
|
|
129
|
+
return this._instance;
|
|
130
|
+
}
|
|
131
|
+
constructor() {
|
|
132
|
+
super();
|
|
133
|
+
this.DOMAIN = 'meminsight';
|
|
134
|
+
this.TAG = HtmlWriter.name;
|
|
135
|
+
this.type = HtmlWriter.name;
|
|
136
|
+
}
|
|
137
|
+
writeToFile(filepath, data, encoding) {
|
|
138
|
+
const _super = Object.create(null, {
|
|
139
|
+
writeToFile: { get: () => super.writeToFile }
|
|
140
|
+
});
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
_super.writeToFile.call(this, filepath, data, encoding);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 从template读取数据并将data插入模板数据中
|
|
147
|
+
* @param template 模板路径
|
|
148
|
+
* @param data 待插入数据
|
|
149
|
+
* @param delimiter 分隔符
|
|
150
|
+
* @return 插入data后的模板数据
|
|
151
|
+
*/
|
|
152
|
+
getDataByTemplate(template, data, delimiter) {
|
|
153
|
+
const templateStrs = fse.readFileSync(template, 'utf-8').split(delimiter);
|
|
154
|
+
if (templateStrs.length !== 2) {
|
|
155
|
+
return '';
|
|
156
|
+
}
|
|
157
|
+
return templateStrs[0] + delimiter + data + templateStrs[1];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.HtmlWriter = HtmlWriter;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface ReportConfig {
|
|
2
|
+
fileName: string;
|
|
3
|
+
fileTitle: string;
|
|
4
|
+
createTime: string;
|
|
5
|
+
data: ReportData[];
|
|
6
|
+
}
|
|
7
|
+
export interface ReportTable {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
export interface ReportData {
|
|
11
|
+
feature: string;
|
|
12
|
+
messages: string[];
|
|
13
|
+
columns: Map<string, string>;
|
|
14
|
+
data: ReportTable;
|
|
15
|
+
}
|
|
16
|
+
export declare class ReporterHTML {
|
|
17
|
+
/**
|
|
18
|
+
* 生成HTML
|
|
19
|
+
*/
|
|
20
|
+
private static generate;
|
|
21
|
+
/**
|
|
22
|
+
* 生成并保存HTML
|
|
23
|
+
*/
|
|
24
|
+
private static generateAndSave;
|
|
25
|
+
static generateByTemplate(datas: ReportData[], fileName?: string): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=Reporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Reporter.d.ts","sourceRoot":"","sources":["../../src/report/Reporter.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,IAAI,EAAE,WAAW,CAAC;CACrB;AAED,qBAAa,YAAY;IACvB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ;IAUvB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;WAmBhB,kBAAkB,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM;CAiBxE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ReporterHTML = void 0;
|
|
7
|
+
const ejs_1 = __importDefault(require("ejs"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const Common_1 = require("../utils/Common");
|
|
11
|
+
const template_1 = require("./templates/template");
|
|
12
|
+
class ReporterHTML {
|
|
13
|
+
/**
|
|
14
|
+
* 生成HTML
|
|
15
|
+
*/
|
|
16
|
+
static generate(config) {
|
|
17
|
+
const templateData = {
|
|
18
|
+
title: config.fileTitle,
|
|
19
|
+
time: config.createTime,
|
|
20
|
+
data: config.data
|
|
21
|
+
};
|
|
22
|
+
return ejs_1.default.render(template_1.TEMPLATE_CTX, templateData);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 生成并保存HTML
|
|
26
|
+
*/
|
|
27
|
+
static generateAndSave(config, outputDir) {
|
|
28
|
+
const html = this.generate(config);
|
|
29
|
+
// 确定输出目录
|
|
30
|
+
const dir = outputDir || path_1.default.join(process.cwd(), 'output');
|
|
31
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
32
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
// 确定文件名
|
|
35
|
+
const fileName = config.fileName || `${config.fileTitle.replace(/\s+/g, '-')}.html`;
|
|
36
|
+
const filePath = path_1.default.join(dir, fileName);
|
|
37
|
+
// 保存文件
|
|
38
|
+
fs_1.default.writeFileSync(filePath, html, 'utf-8');
|
|
39
|
+
return filePath;
|
|
40
|
+
}
|
|
41
|
+
static generateByTemplate(datas, fileName) {
|
|
42
|
+
let generateTime = (0, Common_1.formatDate)(new Date());
|
|
43
|
+
let fileConfig = {
|
|
44
|
+
fileName: `${fileName ? fileName.split('.')[0] : 'report'}-${generateTime}.html`,
|
|
45
|
+
fileTitle: `${fileName || ''} 内存分析报告`,
|
|
46
|
+
createTime: generateTime,
|
|
47
|
+
data: datas
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
const filePath = ReporterHTML.generateAndSave(fileConfig);
|
|
51
|
+
console.log('🎉 报告生成成功!');
|
|
52
|
+
console.log(`📁 文件: ${filePath}`);
|
|
53
|
+
console.log('🔗 用浏览器打开查看结果');
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error('❌ 出错了:', error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ReporterHTML = ReporterHTML;
|
|
61
|
+
// 生成报告
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const TEMPLATE_CTX = "\n<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"UTF-8\">\n <title><%= title %></title>\n <style>\n body { \n font-family: Arial, sans-serif; \n margin: 20px; \n line-height: 1.6; \n }\n h1 { color: #333; }\n .info { \n color: #666; \n margin-bottom: 20px; \n padding: 10px;\n background: #f5f5f5;\n border-radius: 5px;\n display: flex;\n flex-direction: column;\n align-items: start;\n }\n table {\n width: 100%;\n border-collapse: collapse;\n margin-top: 20px;\n box-shadow: 0 2px 5px rgba(0,0,0,0.1);\n font-size: 14px;\n }\n th {\n background-color: #4CAF50;\n color: white;\n padding: 12px;\n text-align: left;\n }\n td {\n padding: 10px;\n border-bottom: 1px solid #ddd;\n max-width: 300px;\n word-break: break-word;\n }\n tr:hover {\n background-color: #f5f5f5;\n }\n tr:nth-child(even) {\n background-color: #f9f9f9;\n }\n .empty {\n text-align: center;\n color: #999;\n padding: 20px;\n }\n .analyze-container {\n display: flex;\n flex-direction: column;\n align-items: start;\n }\n </style>\n</head>\n<body>\n <h1><%= title %></h1>\n <div class=\"info\">\n \u751F\u6210\u65F6\u95F4: <%= time %> | \u5171 <%= data.length %> \u4E2A\u529F\u80FD\n </div>\n <% if (data.length === 0) { %>\n <div class=\"empty\">\u6682\u65E0\u6570\u636E</div>\n <% } else { %>\n <% data.forEach(function(analyze) { %>\n <div class=\"analyze-container\">\n <h2><%= analyze.feature %></h2>\n <div class=\"info\">\n <% analyze.messages.forEach(function(mes) { %>\n <div>\n <%= mes %>\n </div>\n <% }) %>\n </div>\n <table>\n <thead>\n <tr>\n <% analyze.columns.forEach(function(value, key) { %>\n <th><%= value %></th>\n <% }); %>\n </tr>\n </thead>\n <tbody>\n <% analyze.data.forEach(function(row, index) { %>\n <tr>\n <% analyze.columns.forEach(function(value, col) { %>\n <td><%= row[col] !== undefined ? row[col] : '-' %></td>\n <% }); %>\n </tr>\n <% }); %>\n </tbody>\n </table>\n </div>\n <% }) %>\n <% } %>\n</body>\n</html>\n";
|
|
2
|
+
export { TEMPLATE_CTX };
|
|
3
|
+
//# sourceMappingURL=template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../../src/report/templates/template.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY,u/FAqGjB,CAAA;AACD,OAAO,EAAE,YAAY,EAAE,CAAA"}
|