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

feat: silky smooth scroll and stuff like that #14

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
25 changes: 6 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@

# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
node_modules

# builds
build

# misc
.DS_Store
.env
.env.development
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

_crea
.env.production
build/
cosmos.imports.ts
dist/
node_modules
tsconfig.tsbuildinfo
Binary file modified bun.lockb
Binary file not shown.
61 changes: 24 additions & 37 deletions cosmos.bunserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,18 @@ const buildApp = async () =>
entrypoints: ["./cosmos.entrypoint.tsx"],
target: "browser",
outdir: "build",
})
.then((output) => output)
.catch((e) => {
console.info("\n\n error in build", e);
})
}).then((output) => output)
);

await waitForCosmosImports();
await buildApp().then((output) => {
if (output.success)
console.info(
`app built: ${output.success}; ${output.outputs.length} files `
);
else {
for (const message of output.logs) {
// Bun will pretty print the message object
console.error(message);
}
throw new Error(`build failed`);
}
});
await waitForCosmosImports().then(() =>
buildApp()
.then(({ success, outputs, logs, ...buildData }) => {
if (success) console.info(`app built ${outputs.length} files `);
else for (const message of logs) console.error(message);
})
.then(() => import("./cosmos.imports.ts").catch((e) => e)) // watch imports
.then(() => console.info(`frontend running on ${cosmosConfig.port}`))
);

const returnIndex = () => {
const index = `
Expand All @@ -70,10 +61,10 @@ const returnIndex = () => {
});
};

async function serveFromDir(config: {
const serveFromDir = async (config: {
directory?: string;
path: string;
}): Promise<Response | null> {
}): Promise<Response | null> => {
const filepath = path.join(config.directory || "", config.path);

try {
Expand All @@ -86,7 +77,8 @@ async function serveFromDir(config: {
} catch (err) {}

return null;
}
};

export default {
port: cosmosConfig.rendererUrl.split(":").pop(),
hostname: "0.0.0.0",
Expand All @@ -98,21 +90,16 @@ export default {
else {
const filepath = req.url.replace(cosmosConfig.rendererUrl, "");

const exactResponse = await serveFromDir({ path: filepath });
if (exactResponse) return exactResponse;

const buildResponse = await serveFromDir({
directory: BUILD_DIR,
path: filepath,
});
if (buildResponse) return buildResponse;

return new Response("File not found", {
status: 404,
});
return (
(await serveFromDir({ path: filepath })) ||
(await serveFromDir({
directory: BUILD_DIR,
path: filepath,
})) ||
new Response("File not found", {
status: 404,
})
);
}
},
} satisfies ServeOptions;

// watch imports
await import("./cosmos.imports.ts").catch((e) => e);
23 changes: 0 additions & 23 deletions cosmos.imports.ts

This file was deleted.

Loading