From 35c9a324cd3c7f8ef6c505d449ebc1a89be7c96e Mon Sep 17 00:00:00 2001
From: atao
Date: Sat, 10 Apr 2021 17:51:07 +0200
Subject: [PATCH] refactor(ts): enforce typing
---
src/cli.ts | 2 +-
src/index.ts | 2 +-
src/wrapper.ts | 12 ++++++++----
3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/cli.ts b/src/cli.ts
index c5536b8..d98b9af 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -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 {
const { jobTag, options } = await fetchOptionsFrom(args);
await doit(jobTag, options);
}
diff --git a/src/index.ts b/src/index.ts
index 474b046..2e91d46 100755
--- a/src/index.ts
+++ b/src/index.ts
@@ -15,4 +15,4 @@ import { argv } from 'process';
import { cli } from './cli';
-cli(argv);
+void cli(argv);
diff --git a/src/wrapper.ts b/src/wrapper.ts
index d8cb922..60c6183 100644
--- a/src/wrapper.ts
+++ b/src/wrapper.ts
@@ -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) => Promise } = await import(modulePath);
+ return module;
+}
+
- module.job(options);
+export async function doit (jobTag: string, options: Record): Promise {
+ const { job } = await loadModule(jobTag);
+ await job(options);
}