forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframe.js
More file actions
executable file
·54 lines (45 loc) · 1.24 KB
/
frame.js
File metadata and controls
executable file
·54 lines (45 loc) · 1.24 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
const fs = require('fs');
const path = require('path');
const moment = require('moment');
const BaseFrame = require('./baseFrame.js');
class frame extends BaseFrame {
static fromFile(config, file) {
return frame.fromJson(config, JSON.parse(fs.readFileSync(file)));
}
startMe() {
this._start = this._getCurrentDate();
this.write();
return this;
}
stopMe() {
this._stop = this._getCurrentDate();
this.write();
return this;
}
/**
* assert file exists
*/
assertFile() {
if (!fs.existsSync(this.file)) fs.appendFileSync(this.file, '');
}
/**
* write data to file
*/
write(skipModified) {
if (fs.existsSync(this.file)) fs.unlinkSync(this.file);
fs.appendFileSync(this.file, JSON.stringify({
id: this.id,
project: this.project,
resource: this.resource,
notes: this.notes,
start: this._start,
stop: this._stop,
timezone: this.timezone,
modified: skipModified ? this.modified : moment()
}, null, "\t"));
}
get file() {
return path.join(this.config.frameDir, this.id + '.json');
}
}
module.exports = frame;