46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { loadTasks } from "../loader";
|
|
import { createDatabase, dumpDatabase } from "../database/serializer";
|
|
import { loadDatabase } from "../database/deserializer";
|
|
import { remind } from "../backend";
|
|
import { Config, ProfileConfig } from "../types/config";
|
|
|
|
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)) {
|
|
console.log(time);
|
|
|
|
for (const task of db[time]) {
|
|
console.log(task.toString());
|
|
}
|
|
|
|
console.log();
|
|
}
|
|
});
|
|
|
|
export const scan = handleProfile(async config => {
|
|
const tasks = await loadTasks(config.sources, config.query, config.exclude);
|
|
dumpDatabase(config.databaseFile, tasks);
|
|
});
|
|
|
|
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));
|
|
};
|
|
} |