Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #68: Make moveArtifacts merge directories #69

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.