Skip to content

Commit

Permalink
feat(tasks): lift and list tasks can no longer fetch task files
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 4, 2021
1 parent 3182d0a commit 2079576
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 38 deletions.
15 changes: 0 additions & 15 deletions src/helpers/get-task-record.ts

This file was deleted.

7 changes: 3 additions & 4 deletions src/tasks/reflection/lift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { Task, Context } from '../../definitions';
import { parseToRecord } from '../../helpers/parse';
import { getAbsolutePath } from '../../helpers/paths';
import { styleString } from '../../helpers/style-string';
import { getTaskRecord } from '../../helpers/get-task-record';
import { isCancelled } from '../../utils/is-cancelled';
import { run } from '../../utils/run';
import { constants } from '../../constants';
import { select } from '../transform/select';
import { write } from '../filesystem/write';
import { print } from '../stdio/print';
import { shallow } from 'merge-strategies';
import { Empty, Members } from 'type-core';
import { Members, NullaryFn, TypeGuard } from 'type-core';
import { into } from 'pipettes';
import fs from 'fs-extra';

Expand Down Expand Up @@ -46,7 +45,7 @@ export interface LiftOptions {
* @returns Task
*/
export function lift(
tasks: string | Task.Record | Empty,
tasks: Task.Record | NullaryFn<Task.Record>,
options?: LiftOptions
): Task.Async {
return async (ctx: Context): Promise<void> => {
Expand All @@ -55,7 +54,7 @@ export function lift(
options || undefined
);

const source = await getTaskRecord(tasks);
const source = TypeGuard.isFunction(tasks) ? tasks() : tasks;
const pkgPath = getAbsolutePath('package.json', ctx);
const pkgExists = await fs.pathExists(pkgPath);
if (!pkgExists) {
Expand Down
31 changes: 12 additions & 19 deletions src/tasks/reflection/list.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Task, Context } from '../../definitions';
import { parseToArray } from '../../helpers/parse';
import { styleString } from '../../helpers/style-string';
import { getTaskRecord } from '../../helpers/get-task-record';
import { constants } from '../../constants';
import { print } from '../stdio/print';
import { Empty } from 'type-core';
import { NullaryFn, TypeGuard } from 'type-core';
import { shallow } from 'merge-strategies';
import { into } from 'pipettes';
import table from 'as-table';
Expand All @@ -26,17 +25,16 @@ export interface ListOptions {
* @returns Task
*/
export function list(
tasks?: Task.Record | Empty,
options?: ListOptions | Empty,
map?: (name: string, route: string[]) => string[]
tasks: Task.Record | NullaryFn<Task.Record>,
options?: ListOptions
): Task.Async {
return async (ctx: Context): Promise<void> => {
const opts = shallow(
{ defaults: false, bin: constants.bin },
options || undefined
);

const source = await getTaskRecord(tasks);
const source = TypeGuard.isFunction(tasks) ? tasks() : tasks;
const items = parseToArray(
{ roots: true, defaults: opts.defaults },
source
Expand All @@ -46,19 +44,14 @@ export function list(
0
);

const rows = map
? items.map((item) => map(item.name, item.route))
: items.map((item) => {
return [
opts.bin +
' ' +
styleString(item.name, { bold: true }) +
' '.repeat(4),
...Array(item.route.length).fill(''),
item.route[item.route.length - 1],
...Array(maxRouteLength - item.route.length).fill('')
];
});
const rows = items.map((item) => {
return [
opts.bin + ' ' + styleString(item.name, { bold: true }) + ' '.repeat(4),
...Array(item.route.length).fill(''),
item.route[item.route.length - 1],
...Array(maxRouteLength - item.route.length).fill('')
];
});

into(
ctx,
Expand Down

0 comments on commit 2079576

Please sign in to comment.