Skip to content

Commit

Permalink
fix: Clean public dir on force instead of deleting
Browse files Browse the repository at this point in the history
Deleting the public dir recursively (previous approach) is not possible in Docker where the public dir is mounted. This changes the behavior to clean the directory instead, i.e. to delete each file/folder inside the public dir.
  • Loading branch information
ericselin committed Jan 13, 2022
1 parent c24c86a commit 21190b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type {
import { ContentType } from "../domain.ts";
import { exists, expandGlob, path } from "../deps.ts";
import {
cleanDirectory,
createOutputFileWriter,
createStaticFileWriter,
readContentFile,
Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -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([
Expand Down
10 changes: 8 additions & 2 deletions core/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ or email [email protected] <mailto:[email protected]>
import { path } from "../deps.ts";
import type {
FileReader,
OutputFileWriterCreator,
Location,
OutputFileWriterCreator,
StaticFileWriterCreator,
} from "../domain.ts";
import { ContentType } from "../domain.ts";
Expand All @@ -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<ContentType.Page>,
Expand Down Expand Up @@ -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<void> => {
for await (const dirEntry of Deno.readDir(dirpath)) {
await Deno.remove(path.join(dirpath, dirEntry.name), { recursive: true });
}
};

0 comments on commit 21190b6

Please sign in to comment.