Skip to content

Commit 2cc35bf

Browse files
committed
ignore directories in frames
1 parent 3d684d2 commit 2cc35bf

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

src/gtt-delete.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import {Command} from 'commander';
1+
import { Command } from 'commander';
22
import Frame from './models/frame.js';
33
import Config from './include/file-config.js';
44
import Cli from './include/cli.js';
55
import Fs from './include/filesystem.js';
66

7-
87
function delCmd() {
98
const delCmd = new Command('delete', 'delete time record by the given id')
10-
.arguments('[id]')
11-
.action((id, opts, program) => {
9+
.arguments('[id]')
10+
.action((id, opts, program) => {
1211

13-
let config = new Config(process.cwd());
12+
let config = new Config(process.cwd());
1413

15-
if (
16-
(!id || !Fs.exists(Fs.join(config.frameDir, id + '.json')))
17-
&& -Infinity === (id = Fs.newest(config.frameDir))
18-
)
19-
Cli.error('No record found.');
14+
if (!id && -Infinity === (id = Fs.newest(config.frameDir).name))
15+
Cli.error('No record found.');
2016

21-
let file = Fs.join(config.frameDir, id.replace('.json', '') + '.json');
22-
let frame = Frame.fromFile(config, file).stopMe();
23-
Fs.remove(file);
24-
console.log(`Deleting record ${frame.id.magenta}`);
25-
}
26-
);
27-
return delCmd;
17+
let file = Fs.join(config.frameDir, id.replace('.json', '') + '.json');
18+
if (!Fs.exists(file)) {
19+
Cli.error(`Record ${id} not found.`);
20+
} else {
21+
let frame = Frame.fromFile(config, file).stopMe();
22+
Fs.remove(file);
23+
console.log(`Deleting record ${frame.id.magenta}`);
24+
}
25+
}
26+
);
27+
return delCmd;
2828
}
2929

3030
export default delCmd;

src/gtt-edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function toHumanReadable(input) {
3232
if (!id) {
3333
let lastFrames = Fs.all(config.frameDir).slice(-listSize); // last listSize frames (one page of inquirer)
3434
lastFrames = lastFrames.map((file) =>
35-
Frame.fromFile(config, Fs.join(config.frameDir, file))
35+
Frame.fromFile(config, Fs.join(config.frameDir, file.name))
3636
);
3737

3838
let lastFramesDetails = lastFrames

src/gtt-resume.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function resume() {
4040

4141
let lastFrames = Fs.all(config.frameDir).slice(-listSize); // last listSize frames (one page of inquirer)
4242
lastFrames = lastFrames.map((file) =>
43-
Frame.fromFile(config, Fs.join(config.frameDir, file))
43+
Frame.fromFile(config, Fs.join(config.frameDir, file.name))
4444
);
4545
lastFrames = lastFrames.sort((a, b) => moment(a.stop || moment()).isBefore(moment(b.stop || moment())) ? 1 : -1);
4646

src/include/filesystem.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ class filesystem {
3939
}
4040

4141
static newest(dir) {
42-
return _.max(fs.readdirSync(dir), file => (fs.statSync(path.join(dir, file)).ctime));
42+
return _.max(filesystem.readDir(dir), file => (fs.statSync(path.join(dir, file.name)).ctime));
4343
}
4444

4545
static all(dir) {
46-
return _.sortBy(fs.readdirSync(dir), file => (fs.statSync(path.join(dir, file)).ctime));
46+
return _.sortBy(filesystem.readDir(dir), file => (fs.statSync(path.join(dir, file.name)).ctime));
4747
}
4848

4949
static readDir(dir) {
50-
return fs.readdirSync(dir);
50+
return fs.readdirSync(dir, { withFileTypes: true }).filter(file=>file.isFile() && file.name.endsWith(".json"));
5151
}
5252
}
5353

src/models/frameCollection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ class frameCollection extends Base {
1010
Fs.readDir(config.frameDir)
1111
.map(file => {
1212
try {
13-
return Frame.fromFile(this.config, Fs.join(this.config.frameDir, file));
13+
return Frame.fromFile(this.config, Fs.join(this.config.frameDir, file.name));
1414
} catch (e) {
1515
console.log(e);
16-
throw `Error parsing frame file: ${file}`
16+
throw `Error parsing frame file: ${file.name}`
1717
}
1818
})
1919
.filter(frame => frame);

0 commit comments

Comments
 (0)