feat: allow prepared directory clean up for custom preparers

When using custom preparer for TechDocs, the `preparedDir` might
end up taking disk space. This requires all custom preparers to
implement a new method `shouldCleanPreparedDirectory` which indicates
whether the prepared directory should be cleaned after generation.

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2023-10-05 09:37:10 +03:00
parent e5b6767025
commit 344cfbcfbc
6 changed files with 31 additions and 3 deletions
@@ -14,8 +14,8 @@
* limitations under the License.
*/
import {
Entity,
DEFAULT_NAMESPACE,
Entity,
stringifyEntityRef,
} from '@backstage/catalog-model';
import { Config } from '@backstage/config';
@@ -28,7 +28,6 @@ import {
PreparerBase,
PreparerBuilder,
PublisherBase,
UrlPreparer,
} from '@backstage/plugin-techdocs-node';
import fs from 'fs-extra';
import os from 'os';
@@ -194,7 +193,7 @@ export class DocsBuilder {
// Remove Prepared directory since it is no longer needed.
// Caveat: Can not remove prepared directory in case of git preparer since the
// local git repository is used to get etag on subsequent requests.
if (this.preparer instanceof UrlPreparer) {
if (this.preparer.shouldCleanPreparedDirectory()) {
this.logger.debug(
`Removing prepared directory ${preparedDir} since the site has been generated`,
);