-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
executable file
·70 lines (59 loc) · 1.5 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
65
66
67
68
69
70
#! /usr/bin/env node
const path = require('path')
const version = require('./package.json').version
const microloader = require('microloader')
const program = require('commander')
const {
getGitStatuses,
getFileList,
buildNodes,
buildTree,
filesFromGitStatus,
printTree,
getGitLineChanges,
collect
} = microloader('.', {
objectify: true,
cwd: path.join(__dirname, 'utils')
})
program
.version(version)
.usage('[options] [dir]')
.option('-m, --modified', 'only show modified files')
.option('-t, --tracked', 'only show tracked files')
.option('-c, --collapse', 'collapse directory nodes that contain a single child')
.option('-d, --devicons', 'print matching devicons next to files')
.option('-I, --ignore <pattern>', 'do not list files that match the given pattern', collect, [])
.parse(process.argv)
gitree(program.args[0] || '.')
async function gitree (p) {
let gitStatuses, files, gitLineChanges
if (program.modified) {
;([
gitStatuses,
gitLineChanges
] = await Promise.all([
getGitStatuses(p).then((result) => {
files = filesFromGitStatus(result)
return result
}),
getGitLineChanges(p)
]))
} else {
;([
gitStatuses,
files,
gitLineChanges
] = await Promise.all([
getGitStatuses(p),
getFileList(p),
getGitLineChanges(p)
]))
}
if (!files.length) {
return
}
const nodes = await buildNodes(files, gitStatuses, gitLineChanges, p, program.tracked)
const tree = buildTree(nodes, p, program.ignore)
printTree(tree, program.collapse, program.devicons)
}