diff --git a/src/index.ts b/src/index.ts index 44e554448..774bc0dab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import dotenv from 'dotenv'; dotenv.config(); import { intro, outro, spinner, select } from '@clack/prompts'; -import { delay, replaceAll, sleep } from './lib/util'; +import { delay, replaceAll, sleep, clearFolder } from './lib/util'; import { scrapeMetaData } from './scrapper/meta_data'; import { write_metadata, writeTimetableData, calculateTeachersTimetable, calculatePastTimetableInputOptions, calculateRoomsTimeTable } from './lib/firebase'; @@ -65,6 +65,9 @@ else if(option as CLI_OPTIONS == CLI_OPTIONS.rooms_timetable) if ((option as CLI_OPTIONS) != CLI_OPTIONS.crawler) process.exit(0) +// removes all screen shots +clearFolder("./dist") + /// INTRO intro('Welcome to LGU Timetable Crawler 🤖'); @@ -78,7 +81,6 @@ const intro_cli = async () => { await intro_cli(); var metaData = undefined; - var hasCache = existsSync(CACHE_FILE_NAME); if (hasCache) { diff --git a/src/lib/util.ts b/src/lib/util.ts index b36eb701e..83bfa7e55 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -1,3 +1,6 @@ +import { readdirSync, unlinkSync } from "fs" +import { join } from "path" + /** Stops the main thread for given time @param number of seconds @@ -43,3 +46,13 @@ export function shouldExcludeStr(str: string | undefined) { return typeof str !== 'string' || str.length == 0 || potentialInvalidFlags.filter(flag => str.toLocaleLowerCase().includes(flag)).length > 0 } + +/** + * removes all files from the given folder path + * @param string path of folder + */ +export function clearFolder(folderPath: string) { + readdirSync(folderPath).forEach(file=> unlinkSync(join (folderPath, file))) +} + +