-
Notifications
You must be signed in to change notification settings - Fork 5
/
file-module.js
75 lines (57 loc) · 1.87 KB
/
file-module.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
exports.writeLocal = function (solvetime, scramble, solve_ts) {
var solvestring = solvetime + ', ' + scramble + ', ' + solve_ts + '\n';
var fs = require('fs');
var filepath = require('./file-module.js').checkLocalFile();
fs.appendFileSync(filepath, solvestring);
};
exports.checkLocalFile = function () {
var fs = require('fs');
var touch = require('touch');
var filepath = require('./constants').LOCAL_FILE_PATH;
if(!fs.existsSync(filepath)) {
var mkdirp = require('mkdirp');
var localSaveDir = require('./constants').LOCAL_SAVE_DIR;
mkdirp.sync(localSaveDir);
touch.sync(filepath);
}
return filepath;
};
exports.localFileExists = function () {
return require('fs').existsSync(require('./constants').LOCAL_FILE_PATH);
};
exports.pushedFileExists = function () {
return require('fs').existsSync(require('./constants').PUSHED_FILE_PATH);
};
exports.deleteLocalFile = function () {
// empty the file times.csv
// (Rename and put it inside the same directory with another extension)
var filepath = require('./file-module.js').checkLocalFile();
require('fs').renameSync(filepath, filepath + '.' + Date.now());
};
exports.writeToPushed = function (glob) {
var fs = require('fs');
var xdg = require('xdg-basedir');
var filepath = require('./constants').PUSHED_FILE_PATH;
if(!fs.existsSync(filepath)) {
var mkdirp = require('mkdirp');
var localSaveDir = require('./constants').LOCAL_SAVE_DIR;
mkdirp.sync(localSaveDir);
}
var fs = require('fs');
fs.writeFileSync(filepath, glob);
return filepath;
};
exports.print_paths = function () {
var clc = require('cli-color');
var paths_str = [
'',
' Local file path:',
' ' + require('./constants').LOCAL_FILE_PATH,
'',
' Pushed file path:',
' ' + require('./constants').PUSHED_FILE_PATH,
''
].join('\n');
console.log(paths_str);
return;
}