Skip to content

Commit

Permalink
Last workspace usage: show and filter (#134)
Browse files Browse the repository at this point in the history
* feat: add days since the project was worked on

-technical proof- Each result is assigned the modification time of the most recent file in the workspace (parent directory of the node_module) and the days that have elapsed will be displayed

* test(results): add missing parameter

* feat(results): sort by date

* fix(sort): fix date sort method

* style: improve columns

* fix: fix sort by date

* perf(sort-date): improve sort by date method

* style: align old column to right

* refactor(last-usage): rename some methods

* fix: handle invalid amount for repeat

* refactor: remove id property

* refactor(header): move columns header to constant

* docs(readme): add last_mod to sort options section

* chore: final adjustaments and describe the feat in readme
  • Loading branch information
zaldih authored Nov 7, 2022
1 parent fb9993c commit 0d388ad
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 31 deletions.
7 changes: 4 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ This tool allows you to list any _node_modules_ directories in your system, as w

# :heavy_check_mark: Features

- **Clear space:** Get rid of old and dusty node_modules cluttering up your machine.
- **Clear space:** Get rid of old and dusty *node_modules* cluttering up your machine.

- **Last Workspace Usage**: Check when was the last time you modified a file in the workspace (indicated in the **last_mod** column).

- **Very fast:** NPKILL is written in TypeScript, but searches are performed at a low level, improving performance greatly.

- **Easy to use:** Say goodbye to lengthy commands. Using npkill is as simple as reading a list of your node_modules, and pressing Del to get rid of them. Could it be any easier? ;)

- **Minified:** It barely has any dependencies.

Npkill requir
<a name="installation"></a>

# :cloud: Installation
Expand Down Expand Up @@ -98,7 +99,7 @@ To exit, <kbd>Q</kbd> or <kbd>Ctrl</kbd> + <kbd>c</kbd> if you're brave.
| -gb | Show folders in Gigabytes instead of Megabytes. |
| -h, --help, ? | Show this help page and exit |
| -nu, --no-check-update | Don't check for updates on startup |
| -s, --sort | Sort results by: size or path _[ beta ]_ |
| -s, --sort | Sort results by: `size`, `path` or `last-mod` |
| -t, --target | Specify the name of the directories you want to search (by default, is node_modules) |
| -x, --exclude-hidden-directories | Exclude hidden directories ("dot" directories) from search. |
| -v, --version | Show npkill version |
Expand Down
22 changes: 22 additions & 0 deletions __tests__/result.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Result Service', () => {
path: 'path',
size: 5,
status: 'live',
modificationTime: 0,
isDangerous: false,
};
const resultExpected = [newResult];
Expand All @@ -25,18 +26,21 @@ describe('Result Service', () => {
path: 'path',
size: 1,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
{
path: 'path2',
size: 2,
status: 'deleted',
modificationTime: 0,
isDangerous: false,
},
{
path: 'path3',
size: 3,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
];
Expand All @@ -56,36 +60,42 @@ describe('Result Service', () => {
path: 'pathd',
size: 5,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
{
path: 'patha',
size: 6,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathc',
size: 16,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathcc',
size: 0,
status: 'deleted',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathb',
size: 3,
status: 'deleted',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathz',
size: 8,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
];
Expand All @@ -99,36 +109,42 @@ describe('Result Service', () => {
path: 'patha',
size: 6,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathb',
size: 3,
status: 'deleted',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathc',
size: 16,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathcc',
size: 0,
status: 'deleted',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathd',
size: 5,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathz',
size: 8,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
];
Expand Down Expand Up @@ -189,36 +205,42 @@ describe('Result Service', () => {
path: 'pathd',
size: 5,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
{
path: 'patha',
size: 6,
status: 'deleted',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathc',
size: 16,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathcc',
size: 0,
status: 'deleted',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathb',
size: 3,
status: 'deleted',
modificationTime: 0,
isDangerous: false,
},
{
path: 'pathz',
size: 8,
status: 'live',
modificationTime: 0,
isDangerous: false,
},
];
Expand Down
3 changes: 2 additions & 1 deletion src/constants/cli.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export const OPTIONS: ICliOptions[] = [
},
{
arg: ['-s', '--sort'],
description: 'Sort results by: size or path',
description:
'Sort results by: size, path or date (last time the most recent file was modified in the workspace)',
name: 'sort-by',
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/constants/main.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const CURSOR_SIMBOL = '~>';
export const WIDTH_OVERFLOW = '...';
export const DEFAULT_SIZE = '0 MB';
export const DECIMALS_SIZE = 2;
export const OVERFLOW_CUT_FROM = 8;
export const OVERFLOW_CUT_FROM = 11;

export const DEFAULT_CONFIG: IConfig = {
backgroundColor: 'bgBlue',
Expand All @@ -22,7 +22,7 @@ export const DEFAULT_CONFIG: IConfig = {
};

export const MARGINS = {
FOLDER_COLUMN_END: 16,
FOLDER_COLUMN_END: 19,
FOLDER_COLUMN_START: 1,
FOLDER_SIZE_COLUMN: 10,
ROW_RESULTS_START: 8,
Expand Down
4 changes: 2 additions & 2 deletions src/constants/messages.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const INFO_MSGS = {

DISABLED:
'[-D, --delete-all] option has been disabled until future versions. Please restart npkill without this option.',
HEADER_SIZE_COLUMN: 'folder size',
HEADER_COLUMNS: 'last_mod size',
HELP_TITLE: ' NPKILL HELP ',
MIN_CLI_CLOMUNS:
'Oh no! The terminal is too narrow. Please, ' +
Expand All @@ -18,7 +18,7 @@ export const INFO_MSGS = {
NO_TTY:
// tslint:disable-next-line: max-line-length
'Oh no! Npkill does not support this terminal (TTY is required). This is a bug, which has to be fixed. Please try another command interpreter (for example, CMD in windows)',
NO_VALID_SORT_NAME: 'Invalid sort option. Available: path | size',
NO_VALID_SORT_NAME: 'Invalid sort option. Available: path | size | last-mod',
SEARCHING: 'searching ',
SEARCH_COMPLETED: 'search completed ',
SPACE_RELEASED: 'space saved: ',
Expand Down
15 changes: 15 additions & 0 deletions src/constants/sort.result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,19 @@ import { IFolder } from '../interfaces/folder.interface.js';
export const FOLDER_SORT = {
path: (a: IFolder, b: IFolder) => (a.path > b.path ? 1 : -1),
size: (a: IFolder, b: IFolder) => (a.size < b.size ? 1 : -1),
'last-mod': (a: IFolder, b: IFolder) => {
if (a.modificationTime === b.modificationTime) {
return FOLDER_SORT.path(a, b);
}

if (a.modificationTime === null && b.modificationTime !== null) {
return 1;
}

if (b.modificationTime === null && a.modificationTime !== null) {
return -1;
}

return a.modificationTime - b.modificationTime;
},
};
Loading

0 comments on commit 0d388ad

Please sign in to comment.