Commit f0ad0856d705f540141a5c19183f99eae95181be
read file and process it
Avinash committed on 12/3/2018, 11:44:07 AMParent: 395b3f0b3ea99421ead4e9ae4790da2493d71a6b
Files changed
main.js | changed |
timelog.js | changed |
main.js | ||
---|---|---|
@@ -6,6 +6,4 @@ | ||
6 | 6 … | mb.on('ready', function ready () { |
7 | 7 … | console.log('app is ready') |
8 | 8 … | // your app code here |
9 | 9 … | }) |
10 | - | |
11 | -console.log(timeLog) |
timelog.js | ||
---|---|---|
@@ -1,14 +1,40 @@ | ||
1 | -const path = require('path'); | |
1 … | +const path = require('path') | |
2 … | +const os = require('os') | |
3 … | +const fs = require('fs') | |
2 | 4 … | |
3 | 5 … | class TimeLog { |
6 … | + | |
4 | 7 … | constructor() { |
5 | 8 … | const DS = path.sep |
6 | - const basePath = `~${DS}.local${DS}share${DS}gtimelog${DS}` | |
9 … | + const basePath = `${os.homedir()}${DS}.local${DS}share${DS}gtimelog${DS}` | |
7 | 10 … | this.paths = { |
8 | 11 … | log: `${basePath}timelog.txt`, |
9 | 12 … | tasks: `${basePath}tasks.txt` |
10 | 13 … | } |
14 … | + this.init() | |
15 … | + this.updateLog() | |
16 … | + this.processLog() | |
11 | 17 … | } |
18 … | + | |
19 … | + init() { | |
20 … | + this.tasks = [] | |
21 … | + } | |
22 … | + | |
23 … | + today() { | |
24 … | + } | |
25 … | + | |
26 … | + updateLog() { | |
27 … | + const file = fs.readFileSync(this.paths.log, 'utf-8') | |
28 … | + this.log = | |
29 … | + file | |
30 … | + .split('\n') | |
31 … | + .filter((line) => {return line !== ''}) | |
32 … | + } | |
33 … | + | |
34 … | + processLog() { | |
35 … | + console.log(this.log) | |
36 … | + console.log(this.tasks) | |
37 … | + } | |
12 | 38 … | } |
13 | 39 … | |
14 | 40 … | module.exports = new TimeLog() |
Built with git-ssb-web