Skip to content

Commit

Permalink
feat: takes a task record or task record returning function as defaul…
Browse files Browse the repository at this point in the history
…t export for kpo.tasks.js
  • Loading branch information
rafamel committed Jun 18, 2021
1 parent e265161 commit 74b04cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { into } from 'pipettes';
import path from 'path';

export const constants = into(
{ pkg: require('../package.json') },
({ pkg }) => ({
root: path.join(__dirname, '../'),
cli: {
bin: 'kpo',
file: 'kpo.tasks.js',
Expand Down
6 changes: 4 additions & 2 deletions src/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ export async function fetch(options?: FetchOptions): Promise<Task.Record> {

if (
!Object.hasOwnProperty.call(data, 'default') ||
!TypeGuard.isRecord(data.default)
!(TypeGuard.isRecord(data.default) || TypeGuard.isFunction(data.default))
) {
throw Error(`Default tasks export not found: ${filepath}`);
}

const tasks = data.default;
const tasks = TypeGuard.isFunction(data.default)
? data.default(await import(constants.root))
: data.default;

const empty = Object.keys(tasks).filter((name) => !name);
if (empty.length) {
Expand Down

0 comments on commit 74b04cb

Please sign in to comment.