2022-09-26 18:28:25 +03:00
|
|
|
import fs from 'node:fs'
|
|
|
|
import { join } from 'node:path'
|
2021-04-05 06:46:42 +03:00
|
|
|
|
2022-09-26 16:29:56 +03:00
|
|
|
import { LogHelper } from '@/helpers/log-helper'
|
2022-09-26 16:36:07 +03:00
|
|
|
import { SkillDomainHelper } from '@/helpers/skill-domain-helper'
|
2021-04-05 06:46:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This script delete test DB files if they exist
|
|
|
|
*/
|
2022-09-03 14:12:41 +03:00
|
|
|
export default () =>
|
|
|
|
new Promise(async (resolve, reject) => {
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.info('Cleaning test DB files...')
|
2022-09-03 14:12:41 +03:00
|
|
|
|
2022-09-26 16:36:07 +03:00
|
|
|
const skillDomains = await SkillDomainHelper.getSkillDomains()
|
2022-09-03 14:12:41 +03:00
|
|
|
|
2022-09-13 18:06:57 +03:00
|
|
|
for (const currentDomain of skillDomains.values()) {
|
2022-09-03 14:12:41 +03:00
|
|
|
const skillKeys = Object.keys(currentDomain.skills)
|
|
|
|
|
|
|
|
for (let j = 0; j < skillKeys.length; j += 1) {
|
|
|
|
const currentSkill = currentDomain.skills[skillKeys[j]]
|
|
|
|
|
|
|
|
try {
|
|
|
|
// TODO: handle case where the memory folder contain multiple DB nodes
|
|
|
|
const dbFolder = join(currentSkill.path, 'memory')
|
|
|
|
const dbTestFiles = fs
|
|
|
|
.readdirSync(dbFolder)
|
|
|
|
.filter((entity) => entity.indexOf('.spec.json') !== -1)
|
|
|
|
|
|
|
|
if (dbTestFiles.length > 0) {
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.info(`Deleting ${dbTestFiles[0]}...`)
|
2022-09-03 14:12:41 +03:00
|
|
|
fs.unlinkSync(join(dbFolder, dbTestFiles[0]))
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.success(`${dbTestFiles[0]} deleted`)
|
2022-09-03 14:12:41 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.error(`Failed to clean: "${skillKeys[j]}" test DB file`)
|
2022-09-03 14:12:41 +03:00
|
|
|
reject(e)
|
2022-02-17 15:10:42 +03:00
|
|
|
}
|
2021-04-05 06:46:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.success('Cleaning done')
|
2022-09-03 14:12:41 +03:00
|
|
|
resolve()
|
|
|
|
})
|