Repository navigation
Expand file tree
/
Copy pathevent-logger.js
More file actions
106 lines (86 loc) · 2.43 KB
/
Copy pathevent-logger.js
File metadata and controls
106 lines (86 loc) · 2.43 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import path from 'path';
import {remote} from 'electron';
let headless = null;
export default class EventLogger {
constructor(kind) {
this.kind = kind;
this.directory = '<unknown>';
this.shortDirectory = '<unknown>';
if (headless === null) {
headless = !remote.getCurrentWindow().isVisible();
}
}
showStarted(directory, implementation) {
this.directory = directory;
this.shortDirectory = directory.split(path.sep).slice(-2).join(path.sep);
if (!this.isEnabled()) {
return;
}
this.shortLog(`${implementation} watcher started`);
}
showEvents(events) {
if (!this.isEnabled()) {
return;
}
const uniqueRelativeNames = new Set(events.map(event => {
return path.relative(this.directory, event.path);
}));
const fileNames = Array.from(uniqueRelativeNames).slice(0, 3);
const elipses = uniqueRelativeNames.size > 3 ? '...' : '';
const summary = `${this.getShortName()}: ${fileNames.join(', ')}${elipses}`;
/* eslint-disable no-console */
if (headless) {
const eventText = events.map(event => {
if (event.action === 'renamed') {
return ` ${event.oldPath} => ${event.path} (${event.action})\n`;
} else {
return ` ${event.path} (${event.action})\n`;
}
}).join('\n');
console.log(summary + '\n' + eventText);
} else {
console.groupCollapsed(summary);
console.table(events, ['action', 'path', 'oldPath']);
console.groupEnd();
}
/* eslint-enable no-console */
}
showFocusEvent() {
if (!this.isEnabled()) {
return;
}
this.shortLog('focus triggered');
}
showWorkdirOrHeadEvents() {
if (!this.isEnabled()) {
return;
}
this.shortLog('working directory or HEAD change');
}
showStopped() {
if (!this.isEnabled()) {
return;
}
this.shortLog('stopped');
}
isEnabled() {
return process.env.ATOM_GITHUB_FS_EVENT_LOG || atom.config.get('github.filesystemEventDiagnostics');
}
getShortName() {
return `${this.kind} @ ${this.shortDirectory}`;
}
shortLog(line) {
if (headless) {
// eslint-disable-next-line no-console
console.log(`${this.getShortName()}: ${line}`);
return;
}
// eslint-disable-next-line no-console
console.log('%c%s%c: %s',
'font-weight: bold; color: blue;',
this.getShortName(),
'font-weight: normal; color: black;',
line,
);
}
}