-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.js
44 lines (38 loc) · 994 Bytes
/
clean.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
import del from 'del'
import deleteEmpty from 'delete-empty'
import glob from 'fast-glob'
import path from 'path'
import trash from 'trash'
export default async function clean(src, verbose, all = false) {
let views = await glob(['**/view.blocks', '**/view.js'], {
cwd: src,
ignore: ['*node_modules*'],
})
let map = {}
views.forEach((item) => {
let dir = path.dirname(item)
if (!map[dir]) {
map[dir] = new Set()
}
map[dir].add(path.basename(item))
})
let empty = Object.keys(map)
.filter((key) => map[key].size === 1 && map[key].has('view.js'))
.map((item) => path.join(src, item))
await trash(empty)
if (all) {
await del(
[
'**/view.js',
'**/*.graphql.js',
'**/data.js',
`DesignSystem/Fonts/*.js`,
'Views/**',
].map((item) => path.join(src, item))
)
let deleted = await deleteEmpty(src)
if (verbose) {
deleted.forEach((d) => console.log(`x ${d}`))
}
}
}