Skip to content

Commit

Permalink
Merge pull request #69 from FloezeTv/fix-move-artifacts-overwrite
Browse files Browse the repository at this point in the history
Fix #68: Make moveArtifacts merge directories
  • Loading branch information
thejackshelton authored Mar 13, 2024
2 parents 4c0c156 + 001c3f0 commit 6a81955
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 5 deletions.
1 change: 1 addition & 0 deletions libs/qwikdev-astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"dependencies": {
"astro-integration-kit": "^0.2.0",
"fs-extra": "^11.1.1",
"fs-move": "^6.0.0",
"vite-tsconfig-paths": "^4.2.1"
},
"devDependencies": {
Expand Down
18 changes: 18 additions & 0 deletions libs/qwikdev-astro/src/cutom_types/fs-move.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
declare module 'fs-move' {

type MoveOptions = {
overwrite?: bool,
merge?: bool,
purge?: bool,
filter?: (src: string, dest: string) => bool
};

type MoveCallback = (err: any) => unknown;

async function move(src: string, dest: string, callback: MoveCallback);
async function move(src: string, dest: string, options: MoveOptions = {});
async function move(src: string, dest: string, options: MoveOptions, callback: MoveCallback);

export default move;

}
9 changes: 7 additions & 2 deletions libs/qwikdev-astro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import ts from "typescript";
import fs from "node:fs";
import { lstat, readdir, readlink } from "node:fs/promises";
import fsExtra from "fs-extra";
import move from "fs-move"

/* similar to vite's FilterPattern */
const FilternPatternSchema = z.union([
Expand Down Expand Up @@ -260,8 +261,12 @@ export async function moveArtifacts(srcDir: string, destDir: string) {
await fsExtra.ensureDir(destDir);
for (const file of await readdir(srcDir)) {
// move files from source to destintation, overwrite if they exist
await fsExtra.move(join(srcDir, file), join(destDir, file), {
overwrite: true,
await move(join(srcDir, file), join(destDir, file), {
// Merge directories
merge: true,
// Don't overwrite any files, as this would overwrite astro-generated files with files from public.
// This matches astro's default behavior of replacing files in public with generated pages on naming-conflicts.
overwrite: false,
});
}
}
Expand Down
173 changes: 170 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6a81955

Please sign in to comment.