forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilesystem.js
More file actions
executable file
·50 lines (41 loc) · 1.17 KB
/
filesystem.js
File metadata and controls
executable file
·50 lines (41 loc) · 1.17 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
const _ = require('underscore');
const fs = require('fs');
const path = require('path');
const open = require('open');
const find = require('find-in-files');
const child_process = require('child_process');
class filesystem {
static find(pattern, dir) {
return new Promise((resolve, reject) => {
find.find(pattern, dir)
.then(results => resolve(_.keys(results)))
.catch(error => reject(error));
});
}
static exists(file) {
return fs.existsSync(file);
}
static remove(file) {
return fs.unlinkSync(file);
}
static open(file) {
let editor = process.env.VISUAL;
if (editor || (editor = process.env.EDITOR)) {
return child_process.spawn(editor, [file], {
stdio: 'inherit'
});
} else {
return open(file);
}
}
static join(...args) {
return path.join(...args);
}
static newest(dir) {
return _.max(fs.readdirSync(dir), file => (fs.statSync(path.join(dir, file)).ctime));
}
static readDir(dir) {
return fs.readdirSync(dir);
}
}
module.exports = filesystem;