@opentapd/tplugin-cli 0.32.1-alpha.0 → 0.32.1-alpha.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentapd/tplugin-cli",
|
|
3
|
-
"version": "0.32.1-alpha.
|
|
3
|
+
"version": "0.32.1-alpha.1",
|
|
4
4
|
"description": "tplugin-cli",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tplugin-cli": "index.js"
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"node": ">=14.13.0"
|
|
80
80
|
},
|
|
81
81
|
"main": "index.js",
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "e4ee96999c4f4efc2307e46ed16975a45f777fef"
|
|
83
83
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const crypto = require('crypto');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { difference } = require('lodash');
|
|
5
|
+
|
|
6
|
+
async function getFolderHash(folderPath, git) {
|
|
7
|
+
const hash = crypto.createHash('sha256');
|
|
8
|
+
const files = fs.readdirSync(folderPath).sort(); // 排序读取的文件
|
|
9
|
+
const gitFiles = await ignoreFilter(folderPath, files, git);
|
|
10
|
+
// console.log(gitFiles);
|
|
11
|
+
for (const filePath of gitFiles) {
|
|
12
|
+
const fileStats = fs.statSync(filePath);
|
|
13
|
+
hash.update(filePath);
|
|
14
|
+
|
|
15
|
+
if (fileStats.isDirectory()) {
|
|
16
|
+
hash.update(await getFolderHash(filePath, git)); // 递归加入子目录
|
|
17
|
+
} else {
|
|
18
|
+
const fileData = fs.readFileSync(filePath);
|
|
19
|
+
hash.update(fileData);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return hash.digest('hex');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function ignoreFilter(dir = '', files = [], git) {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const paths = files.map(file => path.join(dir, file));
|
|
28
|
+
git.checkIgnore(
|
|
29
|
+
paths,
|
|
30
|
+
(snoop, ignorePaths) => {
|
|
31
|
+
resolve(difference(paths, ignorePaths));
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = getFolderHash;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const SimpleGit = require('simple-git');
|
|
3
|
+
const getFolderHash = require('./index.js');
|
|
4
|
+
|
|
5
|
+
(async () => {
|
|
6
|
+
const hash = await getFolderHash(
|
|
7
|
+
path.join(__dirname, '../../', 'util'),
|
|
8
|
+
new SimpleGit(path.join(__dirname)),
|
|
9
|
+
);
|
|
10
|
+
console.log(hash);
|
|
11
|
+
})();
|