diff --git a/README.md b/README.md index 7c7e09dc..18a103ca 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,50 @@ # fresh Preact, but super edgy. + +Fresh is a web framework that lets you build projects very fast, highly dynamic, +and without the need of a build step. Fresh embraces isomorphic JavaScript like +never before. Write a JSX component, have it render on the edge just-in-time, +and then enhance it with client side JS for great interactivity. + +Fresh does not have a build step - you write your code, deploy it to +[Deno Deploy](https://deno.com/deploy), and from there everything is handled by +the framework. + +- No build step +- Zero config +- JIT rendering on the edge +- Tiny (example is 3KB of JS) +- Client side hydration +- TypeScript out of the box +- File-system routing à la Next.js + +## Install + +To install, run the following command. This will add `fresh` CLI to your PATH. +Make sure to have Deno 1.9.1 or later installed. + +```sh +deno install -A -f https://deno.land/x/fresh/cli.ts +``` + +## Getting started + +The `fresh` CLI can scaffold a new project for you. To scaffold a project in the +`myproject` folder, run the following: + +```sh +fresh init myproject +``` + +To now start the project, use [`deployctl`](https://deno.land/x/deploy): + +``` +deployctl run --no-check --watch server.ts +``` + +To deploy the script to [Deno Deploy](https://deno.com/deploy), push your +project to GitHub, create a `fresh` project, and link it to `server.ts` file in +the created repository. + +To learn more about how to use `fresh`, visit the documentation. diff --git a/cli.ts b/cli.ts index 67acbc42..e88457d1 100644 --- a/cli.ts +++ b/cli.ts @@ -35,7 +35,7 @@ switch (subcommand) { await initSubcommand(args); break; case "routes": - await routesSubcommand(); + await routesSubcommand(args); break; default: if (args.version) { diff --git a/src/cli/init.ts b/src/cli/init.ts index 9ebdee6a..5625da24 100644 --- a/src/cli/init.ts +++ b/src/cli/init.ts @@ -1,5 +1,6 @@ import { join } from "./deps.ts"; import { error } from "./error.ts"; +import { routes } from "./routes.ts"; const help = `fresh init @@ -10,10 +11,10 @@ To generate a project in the './foobar' subdirectory: fresh init ./foobar To generate a project in the current directory: -fresh init . + fresh init . USAGE: -fresh init [OPTIONS] + fresh init [OPTIONS] OPTIONS: -h, --help Prints help information @@ -143,4 +144,6 @@ fresh routes join(directory, "README.md"), README_MD, ); + + await routes(directory); } diff --git a/src/cli/routes.ts b/src/cli/routes.ts index 4aceebf5..2c502b14 100644 --- a/src/cli/routes.ts +++ b/src/cli/routes.ts @@ -1,8 +1,43 @@ import { join, toFileUrl, walk } from "./deps.ts"; -export async function routesSubcommand() { +const help = `fresh routes + +Regenerate the route mapping for your fresh project. + +To regenerate the mapping in the current directory: + fresh routes + +To regenerate the mapping in the './foobar' subdirectory: + fresh routes ./foobar + +USAGE: + fresh routes [OPTIONS] [DIRECTORY] + +OPTIONS: + -h, --help Prints help information +`; + +export interface Args { + help: boolean; +} + +export async function routesSubcommand(rawArgs: Record) { + const args: Args = { + help: !!rawArgs.help, + }; + const directory: string | null = typeof rawArgs._[0] === "string" + ? rawArgs._[0] + : Deno.cwd(); + if (args.help) { + console.log(help); + Deno.exit(0); + } + await routes(directory); +} + +export async function routes(directory: string) { const files = []; - const pagesDir = join(Deno.cwd(), "./pages"); + const pagesDir = join(Deno.cwd(), directory, "./pages"); const pagesUrl = new URL(pagesDir, "file:///"); const folder = walk(pagesDir, { includeDirs: false, @@ -30,5 +65,5 @@ setup([${ }], import.meta.url); `; - await Deno.writeTextFile("./server.ts", output); + await Deno.writeTextFile(join(directory, "./server.ts"), output); } diff --git a/src/server/bundle.ts b/src/server/bundle.ts index 865b4726..72f772ef 100644 --- a/src/server/bundle.ts +++ b/src/server/bundle.ts @@ -32,6 +32,7 @@ addEventListener("DOMContentLoaded", () => { write: false, bundle: true, minify: true, + treeShaking: true, platform: "neutral", outfile: "", jsxFactory: "h", diff --git a/src/server/deps.ts b/src/server/deps.ts index d09e5e18..03a457e0 100644 --- a/src/server/deps.ts +++ b/src/server/deps.ts @@ -14,6 +14,7 @@ globalThis.performance = { return new Date().getTime() - start; }, }; +// @deno-types="https://unpkg.com/esbuild-wasm@0.11.19/esm/browser.d.ts" import * as esbuild from "https://gist.githubusercontent.com/lucacasonato/358c6b7e8198bfb2cf3d220e49fdcf5f/raw/3714cb0f59606eefc29ed0fea36d4cd93549938b/esbuild-wasm.js"; export { esbuild }; export { denoPlugin } from "https://raw.githubusercontent.com/lucacasonato/esbuild_deno_loader/fa2219c3df9494da6c33e3e4dffb1a33b5cc0345/mod.ts";