-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
48 lines (43 loc) · 1.06 KB
/
utils.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
const path = require('path');
/**
* Go throught the files and filter it
* of '.' directories and duplicated directories
* @name getUniqueDirectories
* @param {string[]} files
* @returns {string[]}
*/
exports.getUniqueDirectories = function(files){
return files
.map(path.dirname.bind(null))
.filter((directory, index, array) => array.indexOf(directory) === index && directory !== '.')
}
/**
* Get an array of files and return only the root files
* @name getRootFiles
* @param {string[]} files
* @return {string[]}
*/
exports.getRootFiles = function(files){
return files.filter(file => path.dirname(file) === '.');
}
/**
* Prints a message in strerr with a line break
* @name printLn
* @param {string} message
* @returns {void}
*/
exports.printLn = function(message){
process.stderr.write(message + '\n')
}
/**
* Print a error and return process exit error if the error exists
* @name handleError
* @param {Error} err
* @returns {void|1}
*/
exports.handleError = function(err){
if(err){
console.error(err);
return process.exit(1);
}
}