-
Notifications
You must be signed in to change notification settings - Fork 2
/
progress.js
69 lines (57 loc) · 1.61 KB
/
progress.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
const debug = require('debug')('analyze-module-size:progress')
const ProgressBar = require('progress')
class ProgressHandler {
constructor (stream) {
this.stream = stream
this.foundDepsProgress = new ProgressBar('dependencies found: :current', {total: 1000000, stream: this.stream})
this.loadedDepsProgress = null
}
/**
* Notify the user that a dependency (package.json in node_modules) has been found
* @param {string} file the path to the package.json file
*/
dependencyFound (file) {
this.foundDepsProgress.tick()
}
allDependenciesFound (dep) {
this.stream.write(' ...done\n')
this.loadedDepsProgress = new ProgressBar('Loading dependency details: :bar :locationxxxxxxxxxxxxxxxxxx', {
total: dep,
stream: this.stream
})
}
/**
* Update the progressbar after a dependency has been loaded.
* (Increase the tick-count)
*/
dependencyLoaded (pkg) {
this.loadedDepsProgress.tick({locationxxxxxxxxxxxxxxxxxx: pkg.location().substr(0, 'locationxxxxxxxxxxxxxxxxxx'.length)})
}
connectAll () {
this.stream.write('Connecting dependency graph\n')
}
done () {
this.stream.write('done\n')
}
}
/**
* No actual output (only if DEBUG=anaylze-module-size:progress)
*/
class NullProgressHandler {
dependencyFound (file) {
debug('dependencyFound', file)
}
allDependenciesFound (count) {
debug('allDependenciesFound', count)
}
dependencyLoaded (pkg) {
debug('dependencyLoaded', pkg.location())
}
connectAll () {
debug('connectAll')
}
done () {
debug('done')
}
}
module.exports = {ProgressHandler, NullProgressHandler}