@aiot-toolkit/aiotpack 2.0.5-beta.19 → 2.0.5-beta.20
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/lib/afterCompile/ux/UxAfterCompile.js +5 -8
- package/lib/compiler/tools/icu/ImageIcu.js +1 -1
- package/lib/utils/BeforeCompileUtils.js +1 -8
- package/lib/utils/ux/FileCompare.d.ts +12 -0
- package/lib/utils/ux/FileCompare.js +47 -0
- package/lib/utils/ux/UxFileUtils.d.ts +10 -8
- package/lib/utils/ux/UxFileUtils.js +30 -20
- package/package.json +6 -6
|
@@ -304,19 +304,16 @@ class UxAfterCompile {
|
|
|
304
304
|
if (compalition.trigger === _FileLaneTriggerType.default.START) {
|
|
305
305
|
return;
|
|
306
306
|
}
|
|
307
|
-
const {
|
|
308
|
-
outputPath,
|
|
309
|
-
projectPath
|
|
310
|
-
} = compilerOption;
|
|
311
307
|
// 读取临时项目build文件夹中所有文件路径
|
|
312
|
-
const
|
|
308
|
+
const tempBuildDir = _path.default.join(compilerOption.projectPath, compilerOption.outputPath);
|
|
313
309
|
// 待优化,map文件跟随源文件变化,与时间戳有关文件无需对比
|
|
314
|
-
const tempFileList = _sharedUtils.FileUtil.readAlldirSync(
|
|
315
|
-
const
|
|
310
|
+
const tempFileList = _sharedUtils.FileUtil.readAlldirSync(tempBuildDir);
|
|
311
|
+
const buildDir = _path.default.join(context.projectPath, compilerOption.outputPath);
|
|
312
|
+
const diffList = _UxFileUtils.default.getDiffJSON(compalition.buildFileList, tempFileList, buildDir, tempBuildDir);
|
|
316
313
|
|
|
317
314
|
// 所有差异文件,压缩到 .diff.rpk 中
|
|
318
315
|
if (diffList?.length) {
|
|
319
|
-
const buildFold =
|
|
316
|
+
const buildFold = tempBuildDir;
|
|
320
317
|
const distFold = _path.default.join(compilerOption.projectPath, compilerOption.releasePath);
|
|
321
318
|
const diffFileName = `.diff.rpk`;
|
|
322
319
|
const diffPath = _path.default.join(distFold, diffFileName);
|
|
@@ -53,7 +53,7 @@ class ImageIcu {
|
|
|
53
53
|
recursive: true
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
-
const command =
|
|
56
|
+
const command = `"${binPath}" convert "${resourcePath}" -O "${folder}" -F ${format} -C i8 -r`;
|
|
57
57
|
const message = (0, _child_process.execSync)(command).toString('utf-8');
|
|
58
58
|
if (message) {
|
|
59
59
|
console.log(`convert error: path=${resourcePath} message=${message}`);
|
|
@@ -98,14 +98,7 @@ class BeforeCompileUtils {
|
|
|
98
98
|
if (compilerOption) {
|
|
99
99
|
// 存储build中的文件列表
|
|
100
100
|
const buildPath = _path.default.join(context.projectPath, compilerOption.outputPath);
|
|
101
|
-
const buildFileList = _fsExtra.default.existsSync(buildPath) ? _sharedUtils.FileUtil.readAlldirSync(buildPath).map(filePath =>
|
|
102
|
-
const relativePath = _path.default.relative(buildPath, filePath);
|
|
103
|
-
const fileContent = _fsExtra.default.readFileSync(filePath);
|
|
104
|
-
return {
|
|
105
|
-
path: relativePath,
|
|
106
|
-
content: fileContent
|
|
107
|
-
};
|
|
108
|
-
}) : [];
|
|
101
|
+
const buildFileList = _fsExtra.default.existsSync(buildPath) ? _sharedUtils.FileUtil.readAlldirSync(buildPath).map(filePath => _path.default.relative(buildPath, filePath)) : [];
|
|
109
102
|
if (compalition) {
|
|
110
103
|
compalition.buildFileList = buildFileList;
|
|
111
104
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface FileComparisonResult {
|
|
2
|
+
isEqual: boolean;
|
|
3
|
+
details: {
|
|
4
|
+
hash1: string;
|
|
5
|
+
hash2: string;
|
|
6
|
+
fileSize1: number;
|
|
7
|
+
fileSize2: number;
|
|
8
|
+
comparisonTime: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare function compareFiles(filePath1: string, filePath2: string): FileComparisonResult;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.compareFiles = compareFiles;
|
|
7
|
+
var _crypto = require("crypto");
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
function compareFiles(filePath1, filePath2) {
|
|
11
|
+
const startTime = Date.now();
|
|
12
|
+
|
|
13
|
+
// 快速检查:文件大小不同则内容必然不同
|
|
14
|
+
const size1 = _fs.default.statSync(filePath1).size;
|
|
15
|
+
const size2 = _fs.default.statSync(filePath2).size;
|
|
16
|
+
if (size1 !== size2) {
|
|
17
|
+
return {
|
|
18
|
+
isEqual: false,
|
|
19
|
+
details: {
|
|
20
|
+
hash1: '',
|
|
21
|
+
hash2: '',
|
|
22
|
+
fileSize1: size1,
|
|
23
|
+
fileSize2: size2,
|
|
24
|
+
comparisonTime: Date.now() - startTime
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 计算两个文件的哈希
|
|
30
|
+
const hash1 = computeFileHash(filePath1);
|
|
31
|
+
const hash2 = computeFileHash(filePath2);
|
|
32
|
+
return {
|
|
33
|
+
isEqual: hash1 === hash2,
|
|
34
|
+
details: {
|
|
35
|
+
hash1,
|
|
36
|
+
hash2,
|
|
37
|
+
fileSize1: size1,
|
|
38
|
+
fileSize2: size2,
|
|
39
|
+
comparisonTime: Date.now() - startTime
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function computeFileHash(filePath) {
|
|
44
|
+
const fileData = _fs.default.readFileSync(filePath);
|
|
45
|
+
const hash = (0, _crypto.createHash)('sha-256').update(fileData);
|
|
46
|
+
return hash.digest('hex');
|
|
47
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
|
|
2
1
|
import IManifest from '../../compiler/javascript/vela/interface/IManifest';
|
|
3
2
|
export declare class UxFileUtils {
|
|
4
3
|
static readonly CONFIG_FILE_NAME = "manifest.json";
|
|
@@ -39,15 +38,18 @@ export declare class UxFileUtils {
|
|
|
39
38
|
*/
|
|
40
39
|
static validateSitemap(projectPath: string, sourceRoot?: string): void;
|
|
41
40
|
/**
|
|
41
|
+
* 比较新旧文件列表差异
|
|
42
42
|
* 1. 遍历旧文件列表
|
|
43
|
-
* 1.1 若文件路径在新文件列表
|
|
44
|
-
* 1.2 若文件路径在新文件列表
|
|
43
|
+
* 1.1 若文件路径在新文件列表remainingNewFilest中,且内容一致时,从remainingNewFiles中移除该项
|
|
44
|
+
* 1.2 若文件路径在新文件列表remainingNewFiles中,且内容不一致时,添加到diffList中表示待更新,从remainingNewFiles中移除该项
|
|
45
45
|
* 1.3 若文件路径不在新文件列表中,表示该文件待删除(热更新时,可以不做删除,删除耗费性能)
|
|
46
|
-
* 2. 若遍历完旧文件列表后,
|
|
47
|
-
* @param oldFileList
|
|
48
|
-
* @param newFileList
|
|
49
|
-
* @
|
|
46
|
+
* 2. 若遍历完旧文件列表后,remainingNewFiles长度不为0,表示有文件待新增
|
|
47
|
+
* @param oldFileList 旧文件路径列表(相对路径)
|
|
48
|
+
* @param newFileList 新文件路径列表(绝对路径)
|
|
49
|
+
* @param oldDir 旧文件所在目录(绝对路径)
|
|
50
|
+
* @param newDir 新文件所在目录(绝对路径)
|
|
51
|
+
* @returns 返回差异文件路径列表(相对路径)
|
|
50
52
|
*/
|
|
51
|
-
static getDiffJSON(
|
|
53
|
+
static getDiffJSON(oldFileList: string[], newFileList: string[], oldDir: string, newDir: string): string[];
|
|
52
54
|
}
|
|
53
55
|
export default UxFileUtils;
|
|
@@ -8,6 +8,7 @@ var _CommonUtil = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib
|
|
|
8
8
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
10
|
var _ManifestSchema = _interopRequireDefault(require("./ManifestSchema"));
|
|
11
|
+
var _FileCompare = require("./FileCompare");
|
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
13
|
/**
|
|
13
14
|
* FileUtils
|
|
@@ -112,39 +113,48 @@ class UxFileUtils {
|
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
}
|
|
116
|
+
|
|
115
117
|
/**
|
|
118
|
+
* 比较新旧文件列表差异
|
|
116
119
|
* 1. 遍历旧文件列表
|
|
117
|
-
* 1.1 若文件路径在新文件列表
|
|
118
|
-
* 1.2 若文件路径在新文件列表
|
|
120
|
+
* 1.1 若文件路径在新文件列表remainingNewFilest中,且内容一致时,从remainingNewFiles中移除该项
|
|
121
|
+
* 1.2 若文件路径在新文件列表remainingNewFiles中,且内容不一致时,添加到diffList中表示待更新,从remainingNewFiles中移除该项
|
|
119
122
|
* 1.3 若文件路径不在新文件列表中,表示该文件待删除(热更新时,可以不做删除,删除耗费性能)
|
|
120
|
-
* 2. 若遍历完旧文件列表后,
|
|
121
|
-
* @param oldFileList
|
|
122
|
-
* @param newFileList
|
|
123
|
-
* @
|
|
123
|
+
* 2. 若遍历完旧文件列表后,remainingNewFiles长度不为0,表示有文件待新增
|
|
124
|
+
* @param oldFileList 旧文件路径列表(相对路径)
|
|
125
|
+
* @param newFileList 新文件路径列表(绝对路径)
|
|
126
|
+
* @param oldDir 旧文件所在目录(绝对路径)
|
|
127
|
+
* @param newDir 新文件所在目录(绝对路径)
|
|
128
|
+
* @returns 返回差异文件路径列表(相对路径)
|
|
124
129
|
*/
|
|
125
|
-
static getDiffJSON(
|
|
126
|
-
|
|
127
|
-
if (!oldFileList.length) {
|
|
130
|
+
static getDiffJSON(oldFileList, newFileList, oldDir, newDir) {
|
|
131
|
+
if (!oldFileList.length && !newFileList.length) {
|
|
128
132
|
return [];
|
|
129
133
|
}
|
|
130
134
|
let diffList = [];
|
|
135
|
+
// 剩余待处理的新文件列表
|
|
136
|
+
const remainingNewFiles = [...newFileList];
|
|
131
137
|
// 1.
|
|
132
|
-
for (
|
|
133
|
-
const index =
|
|
134
|
-
|
|
138
|
+
for (const oldFile of oldFileList) {
|
|
139
|
+
const index = remainingNewFiles.findIndex(newFile => {
|
|
140
|
+
const relativePath = _path.default.relative(newDir, newFile);
|
|
141
|
+
return relativePath === oldFile;
|
|
142
|
+
});
|
|
135
143
|
if (index !== -1) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
144
|
+
const oldFilePath = _path.default.join(oldDir, oldFile);
|
|
145
|
+
// 比较文件内容
|
|
146
|
+
const {
|
|
147
|
+
isEqual
|
|
148
|
+
} = (0, _FileCompare.compareFiles)(oldFilePath, newFileList[index]);
|
|
149
|
+
if (!isEqual) {
|
|
150
|
+
diffList.push(_path.default.relative(newDir, remainingNewFiles[index]));
|
|
141
151
|
}
|
|
142
|
-
//
|
|
143
|
-
|
|
152
|
+
// 从新文件列表中移除已比较过的文件
|
|
153
|
+
remainingNewFiles.splice(index, 1);
|
|
144
154
|
}
|
|
145
155
|
}
|
|
146
156
|
// 2.
|
|
147
|
-
|
|
157
|
+
diffList.push(...remainingNewFiles.map(file => _path.default.relative(newDir, file)));
|
|
148
158
|
return diffList;
|
|
149
159
|
}
|
|
150
160
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/aiotpack",
|
|
3
|
-
"version": "2.0.5-beta.
|
|
3
|
+
"version": "2.0.5-beta.20",
|
|
4
4
|
"description": "The process tool for packaging aiot projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aiotpack"
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"test": "node ./__tests__/aiotpack.test.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@aiot-toolkit/generator": "2.0.5-beta.
|
|
23
|
-
"@aiot-toolkit/parser": "2.0.5-beta.
|
|
24
|
-
"@aiot-toolkit/shared-utils": "2.0.5-beta.
|
|
22
|
+
"@aiot-toolkit/generator": "2.0.5-beta.20",
|
|
23
|
+
"@aiot-toolkit/parser": "2.0.5-beta.20",
|
|
24
|
+
"@aiot-toolkit/shared-utils": "2.0.5-beta.20",
|
|
25
25
|
"@hap-toolkit/aaptjs": "^2.0.0",
|
|
26
26
|
"@rspack/core": "^1.3.9",
|
|
27
27
|
"aiot-parse5": "^1.0.2",
|
|
28
28
|
"babel-loader": "^9.1.3",
|
|
29
|
-
"file-lane": "2.0.5-beta.
|
|
29
|
+
"file-lane": "2.0.5-beta.20",
|
|
30
30
|
"file-loader": "^6.2.0",
|
|
31
31
|
"fs-extra": "^11.2.0",
|
|
32
32
|
"hap-toolkit": "^2.0.0",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"@types/jsrsasign": "^10.5.12",
|
|
44
44
|
"@types/webpack-sources": "^3.2.3"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "e34506862fb5e24eb86b4a4aa67fa88bb76f6114"
|
|
47
47
|
}
|