Skip to content

Commit

Permalink
refactor(ts): enforce typing
Browse files Browse the repository at this point in the history
  • Loading branch information
atao60 committed Apr 10, 2021
1 parent a9681d5 commit 35c9a32
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fetchOptionsFrom } from './config';
import { doit } from './wrapper';

export async function cli(args: string[]) {
export async function cli(args: string[]):Promise<void> {
const { jobTag, options } = await fetchOptionsFrom(args);
await doit(jobTag, options);
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ import { argv } from 'process';

import { cli } from './cli';

cli(argv);
void cli(argv);
12 changes: 8 additions & 4 deletions src/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { join } from 'path';

const tasksSubDir = 'tasks';

export async function doit (jobTag: string, options: {} ) {

async function loadModule(jobTag: string) {
// dynamic import is fine here as `jobTag` validity has been checked already
const modulePath = join(__dirname, tasksSubDir, jobTag);
const module = await import(modulePath);
const module: { job: (options: Record<string, unknown>) => Promise<void> } = await import(modulePath);
return module;
}


module.job(options);
export async function doit (jobTag: string, options: Record<string, unknown>): Promise<void> {
const { job } = await loadModule(jobTag);
await job(options);
}

0 comments on commit 35c9a32

Please sign in to comment.