Skip to content

Commit 2f4e9f2

Browse files
committed
trying to fix deleting bug
1 parent 68d40dd commit 2f4e9f2

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

deno.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codingap/steve",
3-
"version": "2.0.6",
3+
"version": "2.0.7",
44
"exports": "./index.ts",
55
"description": "STEVE is a configurable template engine that allows JavaScript to run in files to create files. It has a plugin system to allow for custom generation and a built-in site generator.",
66
"tasks": {
@@ -9,7 +9,8 @@
99
},
1010
"imports": {
1111
"@std/fs": "jsr:@std/fs@^1.0.5",
12-
"@std/path": "jsr:@std/path@^1.0.7"
12+
"@std/path": "jsr:@std/path@^1.0.7",
13+
"@std/assert": "jsr:@std/assert@^1.0.8"
1314
},
1415
"fmt": {
1516
"indentWidth": 4,

deno.lock

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugin/site-generator.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,13 @@ class SiteGenerator extends STEVEPlugin {
158158
): void {
159159
// clean up the output directory by removing non-ignored files and directories
160160
if (existsSync(this.#outputDirectory)) {
161-
for (const file of walkSync(this.#outputDirectory)) {
162-
if (
163-
this.#ignoredFiles?.filter((filename) =>
164-
resolve(file.path).includes(filename)
165-
).length > 0 ||
166-
file.name.startsWith('.') ||
167-
resolve(this.#outputDirectory) === file.path
168-
) continue;
161+
const files = [...walkSync(this.#outputDirectory)].filter(file => {
162+
return this.#ignoredFiles?.filter((filename) =>
163+
resolve(file.path).includes(filename)
164+
).length == 0 && !file.name.startsWith('.') && resolve(this.#outputDirectory) !== file.path
165+
});
166+
167+
for (const file of files) {
169168
Deno.removeSync(file.path, { recursive: true });
170169
}
171170
} else {

test/site-generator.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* 11/18/2024
88
*/
99

10-
import { assertEquals, assertThrows } from 'jsr:@std/assert';
10+
import { assertEquals, assertThrows } from '@std/assert';
1111
import { ensureDir, exists } from 'jsr:@std/fs';
1212
import { GeneratorRoute, SingleRoute, SiteGenerator, STEVE } from '../index.ts';
1313

@@ -274,6 +274,10 @@ Deno.test('SiteGenerator: handles ignored files correctly', async () => {
274274
`${outputDir}/delete.txt`,
275275
'This file should be deleted.',
276276
);
277+
await Deno.writeTextFile(
278+
`${outputDir}/.system`,
279+
'This file should not be deleted.',
280+
);
277281

278282
// Create SiteGenerator instance
279283
const generator = new SiteGenerator({
@@ -289,6 +293,7 @@ Deno.test('SiteGenerator: handles ignored files correctly', async () => {
289293

290294
// Validate that ignored files remain
291295
assertEquals(await exists(`${outputDir}/ignore.txt`), true);
296+
assertEquals(await exists(`${outputDir}/.system`), true);
292297

293298
// Validate that non-ignored files are deleted
294299
assertEquals(await exists(`${outputDir}/delete.txt`), false);

0 commit comments

Comments
 (0)