-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.js
155 lines (139 loc) · 3.88 KB
/
logging.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* Module for printing beautiful text to the terminal
*/
const signale = require('signale');
// Always show the timestamp when using signale
signale.config({displayTimestamp: true});
/**
* Logger for uploading files
*/
const uploadProgress = new signale.Signale({interactive: true, scope: 'File Upload'});
/**
* Logger for downloading files
*/
const downloadProgress = new signale.Signale({interactive: true, scope: 'File Download'});
/**
* Logger for API messages
*/
const apiLogger = new signale.Signale({scope: 'API'});
/**
* Get the API logger
*/
function getAPILogger() {
return apiLogger;
}
/**
* Generate error message for missing entry
* @param {String} path The path of the given entry
*/
function pathNotFound(path) {
signale.error('Failed to located the following path: ' + path);
}
/**
* Print an entry to the terminal
* @param {Object} entry The entry result from the listFiles function
*/
function logEntry(entry) {
if (entry.isDir) console.log(`\x1b[36m${entry.name}\x1b[0m/`);
else console.log(entry.name);
}
/**
* Print successful authentication to the terminal
*/
function authSuccess() {
signale.success('Authentication to wdc successful');
}
/**
* Print failed authentication to the terminal
*/
function authFailed() {
signale.error('Failed to authenticate to the wdc with given credentials');
}
/**
* Upadte the progress of the file upload
* @param {String} fileName The name of the currently uploading file
* @param {Number} progress The progress of the upload
*/
function setUploadProgress(fileName, progress) {
uploadProgress.await('Uploading %s is %d%% done', fileName, progress);
}
/**
* Print starting upload notification
* @param {String} fileName The name of the file
*/
function startFileUpload(fileName) {
uploadProgress.pending('Starting upload for %s', fileName);
}
/**
* Print a file upload done notification
*/
function fileUploadDone() {
signale.complete('File upload done');
}
/**
* Print a file upload failed notification along with the thrown error
* @param {Error} internalError The error thrown by the API
*/
function fileUploadFail(internalError) {
signale.fatal('Failed to upload file');
signale.error(internalError);
}
/**
* Upadte the progress of the file download
* @param {String} fileName The name of the currently downloading file
* @param {Number} progress The progress of the download
*/
function setDownloadProgress(fileName, progress) {
downloadProgress.await('Downloading %s is %d%% done', fileName, progress);
}
/**
* Print starting download notification
* @param {String} fileName The name of the file
*/
function startFileDownload(fileName) {
downloadProgress.pending('Starting download for %s', fileName);
}
/**
* Print a file download done notification
*/
function fileDownloadDone(filePath) {
signale.complete('File download done, file saved to: ' + filePath);
}
/**
* Print a file download failed notification along with the thrown error
* @param {Error} internalError The error thrown by the API
*/
function fileDownloadFail(internalError) {
signale.fatal('Failed to download file');
signale.error(internalError);
}
/**
* Error when user specifies a non-relative/more than one level deep path
*/
function onlyRelativePath() {
signale.error('Path must be relative (the specified path should not contain path separator characters)');
}
/**
* Print folder creationg successful message
* @param {string} folderName The name of the new folder
*/
function folderCreated(folderName) {
signale.success('Folder \'%s\' created successfully', folderName);
}
module.exports = {
authSuccess,
authFailed,
fileDownloadDone,
startFileDownload,
setDownloadProgress,
fileUploadDone,
startFileUpload,
setUploadProgress,
logEntry,
pathNotFound,
onlyRelativePath,
fileUploadFail,
fileDownloadFail,
getAPILogger,
folderCreated
};