From 1e5e38219b8ab653fae5734749e804943a91e6f9 Mon Sep 17 00:00:00 2001 From: Alex Fang Date: Fri, 26 Aug 2022 05:41:50 +0800 Subject: [PATCH 1/9] chore(npm): change npm package name for release with Kongying CLI --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index aa885c1..466e5e6 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,9 @@ { - "name": "file-compare", + "name": "@kongying-tavern/file-compare", "version": "0.0.0", "main": "index.js", "type": "module", "license": "MIT", - "private": false, "scripts": { "commit": "cz", "compare": "node index.js", From e3fe4ac28cdf96c2040b958de7fc6b87cae4cfa1 Mon Sep 17 00:00:00 2001 From: Alex Fang Date: Fri, 26 Aug 2022 06:09:30 +0800 Subject: [PATCH 2/9] ci: add yalc mocking local tester --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 466e5e6..f69048b 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "commit": "cz", "compare": "node index.js", "lint": "eslint --ext .js,.ts .", - "release": "semantic-release" + "release": "semantic-release", + "yalc": "yalc publish" }, "description": "Compare file differences between two directories and generate report", "keywords": [ From 37f530c8878272bf721b90e2a34c4d1eff2d8827 Mon Sep 17 00:00:00 2001 From: Alex Fang Date: Mon, 15 Jul 2024 15:36:31 +0800 Subject: [PATCH 3/9] fix: fix compare hashing method --- util/compare.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/util/compare.js b/util/compare.js index 9ce687f..83902b7 100644 --- a/util/compare.js +++ b/util/compare.js @@ -6,15 +6,21 @@ import UtilProgress from './progress.js'; const currentPath = UtilPath.fromUrl(import.meta.url); -async function getFileSummary (base = '', paths = [], queue = null) { +async function getFileSummary(base = '', paths = [], queue = null) { const countTotal = paths.length; const progress = UtilProgress.createProgressbar({ total: countTotal }); const summary = []; - const hashChunkConfig = UtilHash.getHashChunkPlots({ name: 'single plot', offset: 0, limit: 100 * 1024 }); _.each(paths, async path => { await queue.add(() => { - const filename = UtilPath.relative(base, path); + const filename = UtilPath.resolve(base, path); + const hashChunkConfig = UtilHash.getHashChunkPlots({ + name: 'distribution plots', + file: filename, + chunks: 10, + offset: 0, + limit: 100 * 1024 + }); const md5 = UtilHash.getHashByChunks(path, { chunks: hashChunkConfig }); @@ -35,7 +41,7 @@ async function getFileSummary (base = '', paths = [], queue = null) { return summary; } -async function rehashFileSummary (files = [], queue = null) { +async function rehashFileSummary(files = [], queue = null) { const countTotal = files.length; const progress = UtilProgress.createProgressbar({ total: countTotal }); const summary = []; @@ -46,7 +52,7 @@ async function rehashFileSummary (files = [], queue = null) { const chunkConfig = UtilHash.getHashChunkPlots({ name: 'distribution plots', file: path, - chunks: 10, + chunks: 100, offset: 0, limit: 10 * 1024 }); @@ -71,7 +77,7 @@ async function rehashFileSummary (files = [], queue = null) { return summary; } -function getCompareSummary (lhs = [], rhs = []) { +function getCompareSummary(lhs = [], rhs = []) { const lhsMap = _.groupBy(lhs, 'md5'); const lhsHashes = _.keys(lhsMap); const rhsMap = _.groupBy(rhs, 'md5'); @@ -106,7 +112,7 @@ function getCompareSummary (lhs = [], rhs = []) { return summary; } -async function revalidateCompareSummary (summary = [], lhsQueue = null, rhsQueue = null) { +async function revalidateCompareSummary(summary = [], lhsQueue = null, rhsQueue = null) { const summaryUnsame = _.filter(summary, v => v.type !== 'same'); const summarySame = _.filter(summary, v => v.type === 'same'); @@ -121,7 +127,7 @@ async function revalidateCompareSummary (summary = [], lhsQueue = null, rhsQueue return summaryNew; } -function getCompareReport (summary = []) { +function getCompareReport(summary = []) { const templatePath = UtilPath.resolve(currentPath, '../../template/compare.summary.vue'); const template = UtilFs.readFile(templatePath); const renderer = _.template(template, { From 0315173e0f5b0ad6fbf779eec7f4eeae06567052 Mon Sep 17 00:00:00 2001 From: Alex Fang Date: Mon, 15 Jul 2024 15:37:35 +0800 Subject: [PATCH 4/9] fix: fix hash display in output summary report --- template/compare.summary.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/template/compare.summary.vue b/template/compare.summary.vue index 4456e06..2554c36 100644 --- a/template/compare.summary.vue +++ b/template/compare.summary.vue @@ -79,6 +79,9 @@ circle @click="popupFilterDrawer"> +
+ +
From f03c91386142aaac5fb79b570a7239f481fcf7bf Mon Sep 17 00:00:00 2001 From: Alex Fang Date: Mon, 15 Jul 2024 15:49:04 +0800 Subject: [PATCH 5/9] feat(summary): add count by type summary in report --- template/compare.summary.vue | 43 ++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/template/compare.summary.vue b/template/compare.summary.vue index 2554c36..4997db0 100644 --- a/template/compare.summary.vue +++ b/template/compare.summary.vue @@ -25,6 +25,15 @@ .action-wrapper { flex: none; margin-bottom: .7rem; + display: flex; + gap: .2rem; + align-items: center; + } + .action-wrapper .wrapper { + flex: auto; + } + .action-wrapper .summary { + flex: none; } .table-wrapper { position: relative; @@ -71,19 +80,26 @@ +
- - -
- +
+ + +
+
+
+
+ { + res[val.type] = (res[val.type] ?? 0) + 1; + return res; + }, {}); } }, methods: { From 51bbd0d487a04f01d9e35a45dbd02db00f4c0634 Mon Sep 17 00:00:00 2001 From: Alex Fang Date: Mon, 15 Jul 2024 16:11:04 +0800 Subject: [PATCH 6/9] feat: add natural string compare in filename in generation stage --- index.js | 5 ++++- package.json | 4 +++- util/compare.js | 12 ++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 05911a0..031999c 100644 --- a/index.js +++ b/index.js @@ -31,9 +31,12 @@ const argv = UtilArgs.getArgv(); const compareRevalidateQueueRhs = UtilQueue.createQueue({ concurrency: argv.m }); const compareRevalidateSummary = await UtilCompare.revalidateCompareSummary(compareSummary, compareRevalidateQueueLhs, compareRevalidateQueueRhs); + // resort compare summary + const compareResortSummary = UtilCompare.resortCompareSummary(compareRevalidateSummary); + // save compare summary const compareSummaryOutputPath = UtilPath.resolve(argv.o, './compare-summary.json'); - UtilFs.writeJson(compareSummaryOutputPath, compareRevalidateSummary); + UtilFs.writeJson(compareSummaryOutputPath, compareResortSummary); // compare report const compareReport = UtilCompare.getCompareReport(compareRevalidateSummary); diff --git a/package.json b/package.json index f69048b..b268ad1 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "md5": "^2.3.0", "p-queue": "^7.2.0", "progress": "^2.0.3", + "string-natural-compare": "^3.0.1", "yargs": "^17.3.1" }, "devDependencies": { @@ -56,5 +57,6 @@ }, "publishConfig": { "access": "public" - } + }, + "packageManager": "pnpm@8.10.0+sha512.9c2cb83f2b6cf6a25d8c58300bf99197c7ef3be84cf3e766f29054b40b83b42f8aaba6fcc314a9ecf27c00f7ce80a757bb4c608800e7adbe2d29dc5c7056f5be" } diff --git a/util/compare.js b/util/compare.js index 83902b7..2ba753d 100644 --- a/util/compare.js +++ b/util/compare.js @@ -1,4 +1,5 @@ import _ from 'lodash'; +import StringNaturalCompare from 'string-natural-compare'; import UtilFs from './fs.js'; import UtilPath from './path.js'; import UtilHash from './hash.js'; @@ -127,6 +128,16 @@ async function revalidateCompareSummary(summary = [], lhsQueue = null, rhsQueue return summaryNew; } +function resortCompareSummary(summary = []) { + return _.map(summary, v => { + const lhs = _.chain(v.lhs || []).flattenDeep().sortBy((a, b) => a && b && StringNaturalCompare(a.filename, b.filename)).value(); + const rhs = _.chain(v.rhs || []).flattenDeep().sortBy((a, b) => a && b && StringNaturalCompare(a.filename, b.filename)).value(); + v.lhs = lhs; + v.rhs = rhs; + return v; + }); +} + function getCompareReport(summary = []) { const templatePath = UtilPath.resolve(currentPath, '../../template/compare.summary.vue'); const template = UtilFs.readFile(templatePath); @@ -142,5 +153,6 @@ export default { rehashFileSummary, getCompareSummary, revalidateCompareSummary, + resortCompareSummary, getCompareReport }; From e30dae9bd5ed3a4ecf06fc0e2dde3891873be480 Mon Sep 17 00:00:00 2001 From: Alex Fang Date: Mon, 15 Jul 2024 16:11:29 +0800 Subject: [PATCH 7/9] fix: fix filename generation in compare stage --- util/compare.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/compare.js b/util/compare.js index 2ba753d..d3105cc 100644 --- a/util/compare.js +++ b/util/compare.js @@ -14,10 +14,10 @@ async function getFileSummary(base = '', paths = [], queue = null) { _.each(paths, async path => { await queue.add(() => { - const filename = UtilPath.resolve(base, path); + const filename = UtilPath.relative(base, path); const hashChunkConfig = UtilHash.getHashChunkPlots({ name: 'distribution plots', - file: filename, + file: path, chunks: 10, offset: 0, limit: 100 * 1024 From 89cd126a2069d576567957c9985ef25c91de2fbe Mon Sep 17 00:00:00 2001 From: Alex Fang Date: Mon, 15 Jul 2024 19:10:21 +0800 Subject: [PATCH 8/9] feat: add natural string compare to table sort --- template/compare.summary.vue | 86 +++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 12 deletions(-) diff --git a/template/compare.summary.vue b/template/compare.summary.vue index 4997db0..e216360 100644 --- a/template/compare.summary.vue +++ b/template/compare.summary.vue @@ -106,21 +106,22 @@ :data="compareDataFiltered" size="mini" border - height="auto"> + height="auto" + @sort-change="sortChange"> + sortable="custom" + prop="hash"> + sortable="custom" + prop="lhs">