feat: remove fresh cli, do manifest generation in process (#223)
This commit removes the `fresh` cli, replacing it with a small bootstrap script, and JIT generation of the manifest that happens in process during development.
This commit is contained in:
@@ -17,10 +17,10 @@ static page might need a little bit of JavaScript to power a image carousel or
|
||||
[islands architecture][islands-architecture]. This refers to a page having
|
||||
little "islands" of interactivity, in a sea of otherwise static content.
|
||||
|
||||
`fresh` embraces this model. All pages are rendered server side, but you can
|
||||
Fresh embraces this model. All pages are rendered server side, but you can
|
||||
create "island components" that are _also_ rendered client side. To do this,
|
||||
`fresh` projects have a special `islands/` folder. The modules in this folder
|
||||
each encapsulate a single island component. The name of the module should be the
|
||||
Fresh projects have a special `islands/` folder. The modules in this folder each
|
||||
encapsulate a single island component. The name of the module should be the
|
||||
[pascal case][pascal-case] name of the island component. For example a counter
|
||||
component would be defined in the file `islands/Counter.tsx`. A buy now button
|
||||
would be defined in the file `islands/BuyNowButton.tsx`.
|
||||
@@ -87,11 +87,7 @@ export default function Page() {
|
||||
}
|
||||
```
|
||||
|
||||
Before trying this out, one must run `fresh manifest` again to update the
|
||||
`fresh.gen.ts` file with the new island component. Just like routes, island
|
||||
components need to be registered in the manifest file. This means that
|
||||
`fresh manifest` needs to be run every time a new island component is added,
|
||||
removed, or renamed.
|
||||
The page that is rendered on the client now has an interactive countdown.
|
||||
|
||||
[islands-architecture]: https://jasonformat.com/islands-architecture
|
||||
[pascal-case]: https://en.wiktionary.org/wiki/Pascal_case
|
||||
|
||||
@@ -1,30 +1,34 @@
|
||||
---
|
||||
description: |
|
||||
Create a new fresh project by running `fresh init`. This scaffolds out the
|
||||
various files and folders a fresh project needs.
|
||||
Create a new fresh project by running the fresh project creation tool. This
|
||||
scaffolds out the various files and folders a fresh project needs.
|
||||
---
|
||||
|
||||
New `fresh` projects can be created with the `fresh` CLI tool. It will scaffold
|
||||
out a new project with some example files to get you started.
|
||||
New Fresh projects can be created with using the fresh project creation tool. It
|
||||
will scaffold out a new project with some example files to get you started.
|
||||
|
||||
To create a new project in the directory `"my-project"`, run:
|
||||
|
||||
```
|
||||
$ fresh init my-project
|
||||
Manifest generated and written to ./my-project/fresh.gen.ts
|
||||
$ deno run -A --no-check https://raw.githubusercontent.com/lucacasonato/fresh/main/init.ts my-project
|
||||
The manifest has been generated for 3 routes and 1 islands.
|
||||
|
||||
Project created!
|
||||
Run `deno task start` in the project directory to get started.
|
||||
```
|
||||
|
||||
This will create a directory containing some files and directories. There are 3
|
||||
This will create a directory containing some files and directories. There are 4
|
||||
files that are strictly necessary to run a fresh project:
|
||||
|
||||
- **`main.ts`**: This is the entrypoint for your project. It is the file that
|
||||
will you run to start your fresh application. This file doesn't actually need
|
||||
to be called `main.ts`, but it's best practice to call the entrypoint
|
||||
`main.ts`.
|
||||
- **`dev.ts`**: This is the development entrypoint for your project. This is the
|
||||
file that you run to start your project. This file doesn't need to be called
|
||||
`dev.ts`, but this is the convention.
|
||||
- **`main.ts`**: This is the production entrypoint for your project. It is the
|
||||
file that you link to Deno Deploy. This file doesn't actually need to be
|
||||
`main.ts`, but this is the convention.
|
||||
- **`fresh.gen.ts`**: This is the manifest file that contains information about
|
||||
your routes and islands. This file is automatically generated based on your
|
||||
`routes/` and `islands/` folder by the `fresh` CLI when running the
|
||||
`fresh manifest` command.
|
||||
your routes and islands. This file is automatically generated in development
|
||||
based on your `routes/` and `islands/` folders.
|
||||
- **`import_map.json`**: This is an [import map][import-map] that is used to
|
||||
manage dependencies for the project. This allows for easy importing and
|
||||
updating of dependencies.
|
||||
|
||||
@@ -30,7 +30,7 @@ declare a component that should be rendered every time a user visits the page.
|
||||
This is done with JSX.
|
||||
|
||||
> ℹ️ To learn more about JSX, you can read [this article][jsx] in the React
|
||||
> documentation. Beware that `fresh` does not use React, but rather
|
||||
> documentation. Beware that Fresh does not use React, but rather
|
||||
> [Preact][preact], a lighter weight virtual dom library that works similar to
|
||||
> React.
|
||||
|
||||
@@ -54,24 +54,7 @@ export default function AboutPage() {
|
||||
> element function. These are just boilerplate. You don't need to know exactly
|
||||
> what they do - they just ensure that JSX get's rendered correctly.
|
||||
|
||||
This alone is not yet enough to actually view the page in the browser though. If
|
||||
one tries to visit `http://localhost:8000/about`, the server will return a 404
|
||||
code.
|
||||
|
||||
Before `fresh` can render the page, the `fresh.gen.ts` manifest needs to be
|
||||
updated to reflect this new route. To do this, one can run the `fresh manifest`
|
||||
command:
|
||||
|
||||
```
|
||||
$ fresh manifest
|
||||
Manifest generated and written to ./my-project/fresh.gen.ts
|
||||
```
|
||||
|
||||
> ℹ️ Updating the manifest needs to be done every time you add, remove, or
|
||||
> rename a page. It does not need to be done if just the contents of a page are
|
||||
> edited.
|
||||
|
||||
Now the page will be visible at `http://localhost:8000/about`.
|
||||
The new page will be visible at `http://localhost:8000/about`.
|
||||
|
||||
<!-- You can find more in depth information about routes on the
|
||||
[_Concepts: Routes_][concepts-routes] documentation page page. The following
|
||||
|
||||
@@ -44,8 +44,6 @@ The `PageProps` interface actually contains a bunch of useful properties that
|
||||
can be used to customize the rendered output. Next to the matched url pattern
|
||||
parameters, the raw `url`, and the `route` name can also be found in here.
|
||||
|
||||
As this is a new page, the manifest needs to be updated again: `fresh manifest`.
|
||||
|
||||
Navigating to `https://localhost:8000/greet/Luca` will now render a page showing
|
||||
"Greetings to you, Luca!".
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ for interactivity, but it is much worse for resiliency and user experience as a
|
||||
whole. Browsers have great built in systems for form submission, revolving
|
||||
around the HTML `<form>` element.
|
||||
|
||||
`fresh` builds the core of it's form submission infrastructure around the native
|
||||
`<form>` element. This page explains how to use `<form>` in `fresh`, and the
|
||||
next chapter explains how to progressively enhance your forms with client side
|
||||
Fresh builds the core of it's form submission infrastructure around the native
|
||||
`<form>` element. This page explains how to use `<form>` in Fresh, and the next
|
||||
chapter explains how to progressively enhance your forms with client side
|
||||
JavaScript to make them more interactive.
|
||||
|
||||
The way forms work in the browser, is that they perform a HTML navigation action
|
||||
@@ -21,7 +21,7 @@ when the user submits the form. In most cases this means that when the form is
|
||||
submitted, a GET or POST request is sent to the server with the form data, which
|
||||
then responds with a new page to render.
|
||||
|
||||
`fresh` can handle both GET and POST requests through the
|
||||
Fresh can handle both GET and POST requests through the
|
||||
[custom handlers][custom-handlers] feature of routes. The handlers can perform
|
||||
any necessary processing on the form data, and then pass data to the
|
||||
`ctx.render()` call to render a new page.
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
---
|
||||
description: |
|
||||
In this chapter of the `fresh` documentation, you'll be introduced to the
|
||||
In this chapter of the Fresh documentation, you'll be introduced to the
|
||||
framework. Create a new project, run it locally, edit and create pages, fetch
|
||||
data, handle user interactions, and deploy it.
|
||||
---
|
||||
|
||||
In this chapter of the `fresh` documentation, you'll be introduced to the
|
||||
In this chapter of the Fresh documentation, you'll be introduced to the
|
||||
framework. You'll learn how to create a new project, run it locally, edit and
|
||||
create pages, fetch data, handle user interactions, and how to then deploy the
|
||||
project to [Deno Deploy][deno-deploy].
|
||||
|
||||
The documentation assumes you have Deno 1.12.0 or later installed.
|
||||
The documentation assumes you have Deno 1.22.3 or later installed.
|
||||
|
||||
To install Deno, follow the
|
||||
[installation instructions in the Deno manual][manual-installation].
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
---
|
||||
description: |
|
||||
Install the `fresh` CLI tool to scaffold new projects and generate the fresh
|
||||
manifest. The CLI tool can be installed with `deno install`.
|
||||
---
|
||||
|
||||
`fresh` comes with a CLI tool, conveniently also called `fresh`. It is used to
|
||||
scaffold new projects and generate the fresh manifest (more on that later). This
|
||||
tool is only needed to create a new project, or to re-generate the fresh
|
||||
manifest after you have added, removed, or renamed a pages or islands in an
|
||||
existing project.
|
||||
|
||||
The CLI tool is not required for most development or in CI, as `fresh` does not
|
||||
have a build step. This means that if you are only doing some light editing on
|
||||
an existing project, you do not need to install or use the `fresh` CLI.
|
||||
|
||||
To install the `fresh` CLI:
|
||||
|
||||
```
|
||||
deno install -A -f --no-check -n fresh -r https://raw.githubusercontent.com/lucacasonato/fresh/main/cli.ts
|
||||
```
|
||||
|
||||
The tool should now be available as `fresh` in your terminal. To try out if
|
||||
installation was successful you can just run `fresh` without any arguments:
|
||||
|
||||
```
|
||||
$ fresh
|
||||
fresh 0.1.0
|
||||
The next-gen web framework.
|
||||
|
||||
To initalize a new project:
|
||||
fresh init ./myproject
|
||||
|
||||
To (re-)generate the manifest file:
|
||||
fresh manifest
|
||||
|
||||
SUBCOMMANDS:
|
||||
init Initalize a fresh project
|
||||
manifest (Re-)generate the manifest file
|
||||
```
|
||||
Reference in New Issue
Block a user