Add support for profiles + excluding directories from lookup for tasks
This commit is contained in:
@@ -2,10 +2,10 @@ import { loadTasks } from "../loader";
|
||||
import { createDatabase, dumpDatabase } from "../database/serializer";
|
||||
import { loadDatabase } from "../database/deserializer";
|
||||
import { remind } from "../backend";
|
||||
import { Config } from "../types/config";
|
||||
import { Config, ProfileConfig } from "../types/config";
|
||||
|
||||
export async function test(config: Config) {
|
||||
const tasks = await loadTasks(config.sources, config.query);
|
||||
export const test = handleProfile(async config => {
|
||||
const tasks = await loadTasks(config.sources, config.query, config.exclude);
|
||||
const db = createDatabase(tasks);
|
||||
|
||||
for (const time of Object.keys(db)) {
|
||||
@@ -17,14 +17,30 @@ export async function test(config: Config) {
|
||||
|
||||
console.log();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export async function scan(config: Config) {
|
||||
const tasks = await loadTasks(config.sources, config.query);
|
||||
export const scan = handleProfile(async config => {
|
||||
const tasks = await loadTasks(config.sources, config.query, config.exclude);
|
||||
dumpDatabase(config.databaseFile, tasks);
|
||||
}
|
||||
});
|
||||
|
||||
export async function notify(config: Config) {
|
||||
export const notify = handleProfile(async config => {
|
||||
const db = loadDatabase(config.databaseFile);
|
||||
remind(config, db);
|
||||
});
|
||||
|
||||
function handleProfile(handler: (profile: ProfileConfig) => Promise<void>) {
|
||||
return async (config: Config, profile?: string) => {
|
||||
if (profile !== undefined) {
|
||||
const cfg = config.profiles[profile];
|
||||
|
||||
if (cfg === undefined) {
|
||||
throw new Error(`Undefined profile: ${profile}`);
|
||||
}
|
||||
|
||||
return handler(cfg);
|
||||
}
|
||||
|
||||
return await Promise.all(Object.values(config.profiles).map(handler));
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user