Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ignore directories in frames
  • Loading branch information
ndu2 committed Jun 1, 2025
commit 2cc35bf9bba67efc0e2b4f32e618eca2b82e5f48
34 changes: 17 additions & 17 deletions src/gtt-delete.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import {Command} from 'commander';
import { Command } from 'commander';
import Frame from './models/frame.js';
import Config from './include/file-config.js';
import Cli from './include/cli.js';
import Fs from './include/filesystem.js';


function delCmd() {
const delCmd = new Command('delete', 'delete time record by the given id')
.arguments('[id]')
.action((id, opts, program) => {
.arguments('[id]')
.action((id, opts, program) => {

let config = new Config(process.cwd());
let config = new Config(process.cwd());

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

let file = Fs.join(config.frameDir, id.replace('.json', '') + '.json');
let frame = Frame.fromFile(config, file).stopMe();
Fs.remove(file);
console.log(`Deleting record ${frame.id.magenta}`);
}
);
return delCmd;
let file = Fs.join(config.frameDir, id.replace('.json', '') + '.json');
if (!Fs.exists(file)) {
Cli.error(`Record ${id} not found.`);
} else {
let frame = Frame.fromFile(config, file).stopMe();
Fs.remove(file);
console.log(`Deleting record ${frame.id.magenta}`);
}
}
);
return delCmd;
}

export default delCmd;
2 changes: 1 addition & 1 deletion src/gtt-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function toHumanReadable(input) {
if (!id) {
let lastFrames = Fs.all(config.frameDir).slice(-listSize); // last listSize frames (one page of inquirer)
lastFrames = lastFrames.map((file) =>
Frame.fromFile(config, Fs.join(config.frameDir, file))
Frame.fromFile(config, Fs.join(config.frameDir, file.name))
);

let lastFramesDetails = lastFrames
Expand Down
2 changes: 1 addition & 1 deletion src/gtt-resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function resume() {

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

Expand Down
6 changes: 3 additions & 3 deletions src/include/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ class filesystem {
}

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

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

static readDir(dir) {
return fs.readdirSync(dir);
return fs.readdirSync(dir, { withFileTypes: true }).filter(file=>file.isFile() && file.name.endsWith(".json"));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/models/frameCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class frameCollection extends Base {
Fs.readDir(config.frameDir)
.map(file => {
try {
return Frame.fromFile(this.config, Fs.join(this.config.frameDir, file));
return Frame.fromFile(this.config, Fs.join(this.config.frameDir, file.name));
} catch (e) {
console.log(e);
throw `Error parsing frame file: ${file}`
throw `Error parsing frame file: ${file.name}`
}
})
.filter(frame => frame);
Expand Down