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

Copy all non-svelte files to output directory #42

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions deno.lock

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

File renamed without changes.
File renamed without changes
20 changes: 16 additions & 4 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { walk } from "https://deno.land/[email protected]/fs/walk.ts";
import { create_handler } from "./server.ts";
import { globToRegExp } from "https://deno.land/[email protected]/path/glob.ts";
import { copy } from "https://deno.land/[email protected]/fs/copy.ts";
import { normalize } from "https://deno.land/[email protected]/path/mod.ts";
import { expandGlob } from "https://deno.land/[email protected]/fs/mod.ts";
import { dirname, normalize } from "https://deno.land/[email protected]/path/mod.ts";
sndrs marked this conversation as resolved.
Show resolved Hide resolved

const slashify = (path: string) => normalize(path + "/");

Expand Down Expand Up @@ -73,9 +74,20 @@ export const get_svelte_files = async ({
return files;
};

const copy_assets = (
{ site_dir, out_dir }: Partial<Options>,
) => copy(site_dir + "assets", out_dir + "assets", { overwrite: true });
const copy_assets = async (
{ site_dir, out_dir }: Pick<Options, "site_dir" | "out_dir">,
) => {
for await (
const file of expandGlob("**/*.!(svelte)", { root: site_dir })
) {
const out_file = file.path.replace(site_dir, out_dir);

await ensureDir(dirname(out_file));
await copy(file.path, out_file, {
overwrite: true,
});
Comment on lines +86 to +88
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this lead to overwriting a file that has the same name as one of our outputs–e.g. index.html or islands.js? Might be worth ensuring that there’s no possible conflict.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it could. what do you reckon is the best way to handle that? work out if it would and error with an explanation?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a good error would be best. SvelteKit has a nice error for conflicting routes.

The "/(a)/conf" and "/(b)/conf" routes conflict with each other

Copy link
Owner

@mxdvl mxdvl Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe by not overwriting the file and providing a good error:

await copy(file.path, out_file)
  .catch(() => `File ${file.path} not copied because of conflict`);

}
};

const rebuild = async ({
base,
Expand Down