Skip to content

Commit

Permalink
feat(tasks): list prints the command for tasks and their indented str…
Browse files Browse the repository at this point in the history
…ucture
  • Loading branch information
rafamel committed Feb 19, 2021
1 parent f0dbd5a commit 6bcb47e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
9 changes: 3 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
}
},
"dependencies": {
"as-table": "^1.0.55",
"chalk": "^2.4.2",
"chokidar": "^2.1.8",
"debounce": "^1.2.0",
Expand Down
32 changes: 25 additions & 7 deletions src/tasks/reflection/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@ import { Task, Context } from '../../definitions';
import { parseToArray } from '../../helpers/parse';
import { print } from '../stdio/print';
import { into } from 'pipettes';
import table from 'as-table';
import chalk from 'chalk';

export function list(tasks: Task.Record): Task.Sync {
return (ctx: Context): void => {
const str = parseToArray(tasks)
.map((item) => {
return ' '.repeat((item.route.length - 1) * 2) + item.name;
})
.map((str) => chalk.bold(str))
.join('\n');
const items = parseToArray(tasks);
const maxRouteLength = items.reduce(
(acc, item) => (acc > item.route.length ? acc : item.route.length),
0
);

into(ctx, print(str));
const rows = items.map((item) => {
return [
'kpo ',
chalk.bold(item.name),
' '.repeat(6),
...Array(item.route.length).fill(''),
item.route[item.route.length - 1],
...Array(maxRouteLength - item.route.length).fill('')
];
});

into(
ctx,
print(
table
.configure({ delimiter: '' })(rows)
.trim()
)
);
};
}

0 comments on commit 6bcb47e

Please sign in to comment.