diff --git a/core/api.ts b/core/api.ts index 802c2aa..5b69b2c 100644 --- a/core/api.ts +++ b/core/api.ts @@ -31,6 +31,7 @@ import type { import { ContentType } from "../domain.ts"; import { exists, expandGlob, path } from "../deps.ts"; import { + cleanDirectory, createOutputFileWriter, createStaticFileWriter, readContentFile, @@ -67,7 +68,9 @@ const createPagesGetter = ( for (const glob of globArray) { const contentGlob = path.join(options.contentDir, glob); log?.debug(`Getting pages with glob "${contentGlob}"`); - for await (const walkEntry of expandGlob(contentGlob, { extended: true })) { + for await ( + const walkEntry of expandGlob(contentGlob, { extended: true }) + ) { const content = await getContent(processWalkEntry(walkEntry)); if (content?.type === ContentType.Page) { log?.debug(`Found page ${content.location.inputPath}`); @@ -152,7 +155,7 @@ export const build: Builder = async (options) => { if (force && await exists(publicDir)) { log?.warning(`Cleaning public directory ${publicDir}`); - await Deno.remove(publicDir, { recursive: true }); + await cleanDirectory(publicDir); } const walkDirty = createDirtyFileWalker([ diff --git a/core/fs.ts b/core/fs.ts index 6405acb..6ef7122 100644 --- a/core/fs.ts +++ b/core/fs.ts @@ -23,8 +23,8 @@ or email eric.selin@gmail.com import { path } from "../deps.ts"; import type { FileReader, - OutputFileWriterCreator, Location, + OutputFileWriterCreator, StaticFileWriterCreator, } from "../domain.ts"; import { ContentType } from "../domain.ts"; @@ -35,7 +35,7 @@ export const readContentFile: FileReader = () => async (location) => { if (location.type === ContentType.Page) { const content = await Deno.readTextFile(location.inputPath); - location + location; return { type: ContentType.Page, location: location as Location, @@ -64,3 +64,9 @@ export const createStaticFileWriter: StaticFileWriterCreator = ({ log }) => await Deno.copyFile(location.inputPath, location.outputPath); log?.info(`Copied static file to ${location.outputPath}`); }; + +export const cleanDirectory = async (dirpath: DirectoryPath): Promise => { + for await (const dirEntry of Deno.readDir(dirpath)) { + await Deno.remove(path.join(dirpath, dirEntry.name), { recursive: true }); + } +};