diff --git a/CHANGELOG.md b/CHANGELOG.md index aa820cb..ffd0e84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ -# Version 2.1.1 +# Version 2.1.2 + + - Remove old schema files when genereating new schema files. + - This is to remove files of deleted collections. + +## Version 2.1.1 - Outputs additional helpful information when error occurs. - Link to an issue when trying to import empty files. diff --git a/src/collectionExporter.ts b/src/collectionExporter.ts index a91ee39..ae5d649 100644 --- a/src/collectionExporter.ts +++ b/src/collectionExporter.ts @@ -237,12 +237,10 @@ class CollectionExporter implements IExporter { return map; }, {} as Record); - let hasDependents = false; items.forEach(o => { for (const fieldName of linkedFields) { const value = o[fieldName]; if (value && itemsMap[value]) { - hasDependents = true; itemsMap[value].__dependents.push(o); } } diff --git a/src/schemaExporter.ts b/src/schemaExporter.ts index 464aa49..1fb6b1e 100644 --- a/src/schemaExporter.ts +++ b/src/schemaExporter.ts @@ -1,7 +1,7 @@ import type { Snapshot, SnapshotField, SnapshotRelation } from '@directus/api/dist/types'; import type { ApiExtensionContext } from '@directus/extensions'; import { Collection } from '@directus/types'; -import { readFile, writeFile, mkdir } from 'fs/promises'; +import { readFile, writeFile, mkdir, rm } from 'fs/promises'; import { glob } from 'glob'; import { condenseAction } from './condenseAction.js'; import { exportHook } from './schemaExporterHooks.js'; @@ -26,6 +26,12 @@ export class SchemaExporter implements IExporter { protected ensureSchemaFilesDir = async () => { if (!(await ExportHelper.fileExists(`${ExportHelper.dataDir}/schema`))) { await mkdir(`${ExportHelper.dataDir}/schema`, { recursive: true }); + } else { + // Clean up old schema files + const files = await glob(this.schemaFilesPath('*')); + for (const file of files) { + await rm(file); + } } };