-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (52 loc) · 1.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
const { exec } = require('child_process')
const { cosmiconfigSync } = require('cosmiconfig')
const explorerSync = cosmiconfigSync('duplicates', {
noExt: "defaultLoaders['.json']"
})
const appCfg = explorerSync.search().config.ignore || []
exec(
`git ls-files -z | xargs -0 md5 | awk -F '=' '{print $2 "\t" $1}' | sort `,
(error, stdout, stderr) => {
if (error) {
console.error(`error: ${error.message}`)
return
}
if (stderr) {
console.error(`stderr: ${stderr}`)
return
}
// Remove from config
const uniqAfterFilter = stdout
.split('\n')
.filter(function (line) {
return !appCfg.some(v => line.includes(v))
})
.join('\n')
// Group in map
const files = uniqAfterFilter.split('\n')
const myMap = new Map()
for (const file of files) {
const [k, v] = file.split('MD5')
if (!v) {
continue
}
const filePath = v.trim().substr(1).slice(0, -1)
if (myMap.has(k)) {
myMap.set(k, [...myMap.get(k), filePath])
} else {
myMap.set(k, [filePath])
}
}
// Remove uniq
for (const [k, v] of myMap) {
if (v.length === 1) {
myMap.delete(k)
}
}
for (const v of myMap.values()) {
console.log('duplicate files: ', v)
}
console.log('count: ', myMap.size)
}
)