hoosat-create 1.5.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +228 -169
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,169 +1,228 @@
|
|
|
1
|
-
# Hoosat Create
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
- `
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
1
|
+
# Hoosat Create
|
|
2
|
+
|
|
3
|
+
**React server rendering, without the framework.**
|
|
4
|
+
|
|
5
|
+
Hoosat Create scaffolds a full-stack React and TypeScript app that streams HTML from a small, dependency-light Node.js server. No Express, no magic, just code you can read and own.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npx hoosat-create@latest
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
[Website](https://create.hoosat.fi) · [Tutorial](https://create.hoosat.fi/tutorial) · [Template](https://github.com/TMKCodes/hoosat-template) · [Server core](https://github.com/TMKCodes/hoosat-server-core) · [npm](https://www.npmjs.com/package/hoosat-create) · [Discord](https://discord.gg/UXPFcPaPBg)
|
|
12
|
+
|
|
13
|
+
| | |
|
|
14
|
+
|---|---|
|
|
15
|
+
| **1** | command to a running SSR app |
|
|
16
|
+
| **0** | Express or Babel dependencies |
|
|
17
|
+
| **3** | precompressed formats: br, gzip, deflate |
|
|
18
|
+
| **100%** | TypeScript, build tools included |
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
You need **Node.js 22, 24 or 26** and **git**. Node.js 20 and older are end-of-life, and the build tools are TypeScript files that only current Node.js can run directly.
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
$ npx hoosat-create@latest
|
|
26
|
+
Creating a new project from Hoosat React SSR Template.
|
|
27
|
+
Enter destination project name: my-site
|
|
28
|
+
Do you want to initialize a git repository? [Y/n] y
|
|
29
|
+
Project cloned successfully.
|
|
30
|
+
Project template dependencies installed with npm.
|
|
31
|
+
$ cd my-site && npm run dev
|
|
32
|
+
Server is running on port 8181
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Open http://localhost:8181. The port comes from `PORT` in `.env`.
|
|
36
|
+
|
|
37
|
+
The script clones [hoosat-template](https://github.com/TMKCodes/hoosat-template) over HTTPS together with the [hoosat-server-core](https://github.com/TMKCodes/hoosat-server-core) submodule, writes your details into `package.json`, runs `npm install` and can initialise a fresh git repository for you.
|
|
38
|
+
|
|
39
|
+
For the full walkthrough, from an empty folder to a deployed site, read the [tutorial](https://create.hoosat.fi/tutorial). It is exactly how [create.hoosat.fi](https://create.hoosat.fi) was built.
|
|
40
|
+
|
|
41
|
+
### Command line arguments
|
|
42
|
+
|
|
43
|
+
Every question can be answered up front. Anything you leave out is asked interactively, and you can press Enter to leave it empty.
|
|
44
|
+
|
|
45
|
+
| Argument | Sets |
|
|
46
|
+
|---|---|
|
|
47
|
+
| `--destination` | Project folder and `package.json` name |
|
|
48
|
+
| `--description` | `package.json` description |
|
|
49
|
+
| `--author` | `package.json` author |
|
|
50
|
+
| `--license` | `package.json` license |
|
|
51
|
+
| `--keywords` | `package.json` keywords, comma-separated |
|
|
52
|
+
| `--gitInit` | Initialise a git repository: `Y` or `n` |
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
npx hoosat-create@latest --destination my-site --author "Your Name" --license MIT --gitInit Y
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Values containing `;`, `|`, `&&`, `>`, `<`, `` ` `` or `$(` are rejected, and git and npm are run without a shell, so a project name can never be run as a command.
|
|
59
|
+
|
|
60
|
+
### Create a submodule
|
|
61
|
+
|
|
62
|
+
Inside an existing git repository, this creates an empty git repository at the destination and registers it as a submodule, ready for code you want to share with other projects later:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
npx hoosat-create@latest submodule --destination src/client/submodule
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Client and server, kept apart
|
|
69
|
+
|
|
70
|
+
Many React frameworks fuse server and client code into the same files with server components, loaders and server actions, and decide at build time what runs where. In Hoosat Create, **the folder decides**.
|
|
71
|
+
|
|
72
|
+
| Folder | Runs in | What lives there |
|
|
73
|
+
|---|---|---|
|
|
74
|
+
| `src/client` | Browser | Your React app: pages, components and CSS. Bundled for the browser, starting from `src/client/index.tsx`. |
|
|
75
|
+
| `src/server` | Node.js | Your own HTTP server: middlewares, API routes and rendering. Bundled into `build/server.js`, starting from `src/server/index.tsx`. |
|
|
76
|
+
|
|
77
|
+
Two webpack configs, two bundles and no `"use client"` or `"use server"` directives. You always know what ships to the browser.
|
|
78
|
+
|
|
79
|
+
## Features
|
|
80
|
+
|
|
81
|
+
The template is a starting point you copy, not a framework you depend on. Every feature below is plain code in your repository.
|
|
82
|
+
|
|
83
|
+
- **Streaming SSR.** Pages render with React 19's `renderToPipeableStream`, so the browser gets real HTML first and then hydrates it into an interactive app.
|
|
84
|
+
- **A router you can read.** The server core is a few hundred lines of TypeScript on Node's `http` and `https` modules: middlewares, `:params`, wildcards and composable routers.
|
|
85
|
+
- **SEO in the first bytes.** Titles, meta, Open Graph and JSON-LD written with `react-helmet-async` are streamed into the `<head>`, so crawlers see them without running JavaScript.
|
|
86
|
+
- **Precompressed assets.** The build writes Brotli, gzip and deflate copies of every public file. The server picks one by `Accept-Encoding` and sets long cache headers.
|
|
87
|
+
- **TypeScript everywhere.** Strict TypeScript 6 for client and server code. Even the build tools are `.ts` files that Node runs directly with type stripping.
|
|
88
|
+
- **Built-in i18n.** i18next and react-i18next are wired in on both the server and the client.
|
|
89
|
+
- **Secure defaults.** A Content-Security-Policy header with a nonce, path traversal safe static files, and an `.npmrc` that only installs package versions that have been public for 7 days.
|
|
90
|
+
- **Tests from day one.** Jest 30 and Testing Library come configured, with example tests for the server core.
|
|
91
|
+
- **Fast dev loop.** `npm run dev` rebuilds the client and the server whenever you save and restarts the server with nodemon, so changes show up in seconds.
|
|
92
|
+
|
|
93
|
+
## How a request becomes a page
|
|
94
|
+
|
|
95
|
+
One request through the stack, from socket to interactive page. Each step is a file you can open.
|
|
96
|
+
|
|
97
|
+
1. **Request.** Node's `http` or `https` server accepts the request, and the URL is sanitised against path traversal.
|
|
98
|
+
2. **Middlewares.** Middlewares run in order, for example CORS, file uploads and precompressed static files.
|
|
99
|
+
3. **Routes.** API routes such as `/api/ping/:id` answer directly. Everything else falls through to the `*` route.
|
|
100
|
+
4. **React render.** The `*` route renders `<App />` inside a `StaticRouter` and streams it to the client.
|
|
101
|
+
5. **Head injection.** A transform stream writes Helmet tags, preload links and the bundles into the `<head>` while the HTML streams out.
|
|
102
|
+
6. **Hydration.** In the browser `hydrateRoot` attaches React to the existing markup. From here on, navigation happens on the client.
|
|
103
|
+
|
|
104
|
+
## Your server is just a file
|
|
105
|
+
|
|
106
|
+
`src/server/index.tsx` is the whole server. Middlewares and routes are plain functions:
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { createRouter, createServer, listen } from './core/server';
|
|
110
|
+
import { assets } from './core/assets';
|
|
111
|
+
import { renderer } from './core/renderer';
|
|
112
|
+
|
|
113
|
+
const router = createRouter();
|
|
114
|
+
|
|
115
|
+
// Middlewares run in order, before any route.
|
|
116
|
+
router.Middleware(assets(publicDir));
|
|
117
|
+
|
|
118
|
+
// API routes answer directly.
|
|
119
|
+
router.Get("/api/hello/:name", (req, res) => {
|
|
120
|
+
res.status(200).json({ message: "Hello, " + req.params!["name"] });
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Every other GET request is a React page.
|
|
124
|
+
router.Get("*", async (req, res) => {
|
|
125
|
+
renderer({ res, jsx: <App url={req.url} />, publicDir });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
listen(createServer(router), 8181, () => console.log("Ready"));
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Path parameters are in `req.params`, and `res.status()`, `res.send()` and `res.json()` cover most responses. Group routes with `createRouter()` and mount them with `router.UseRouter()`.
|
|
132
|
+
|
|
133
|
+
## Project layout
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
my-site/
|
|
137
|
+
├── public/ static files, copied into the build
|
|
138
|
+
├── src/
|
|
139
|
+
│ ├── client/ React app: App.tsx, routes/, components, *.css
|
|
140
|
+
│ ├── server/
|
|
141
|
+
│ │ ├── api-routes/ your API endpoints
|
|
142
|
+
│ │ ├── core/ hoosat-server-core (git submodule)
|
|
143
|
+
│ │ └── index.tsx the server itself
|
|
144
|
+
│ └── __tests__/ Jest tests
|
|
145
|
+
├── build-tools/ TypeScript build helpers run by Node
|
|
146
|
+
├── webpack.client.config.js
|
|
147
|
+
└── webpack.server.config.js
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`src/server/core` is a git submodule shared by every Hoosat project. Update it with `git submodule update --remote` instead of editing it in place.
|
|
151
|
+
|
|
152
|
+
Plain `.css` files anywhere under `src/client` are merged and minified into `/public/styles.css`, which the renderer links in every page. No imports needed.
|
|
153
|
+
|
|
154
|
+
## Scripts
|
|
155
|
+
|
|
156
|
+
| Command | What it does |
|
|
157
|
+
|---|---|
|
|
158
|
+
| `npm run dev` | Builds into `build-dev`, starts the server and rebuilds whenever a file in `src` or `public` changes |
|
|
159
|
+
| `npm run build` | Production build into `build`, including precompressed copies of every asset |
|
|
160
|
+
| `npm start` | Runs the production server from `build/server.js` |
|
|
161
|
+
| `npm test` | Runs the Jest tests |
|
|
162
|
+
| `npm run typecheck` | Type checks the whole project with `tsc --noEmit` |
|
|
163
|
+
|
|
164
|
+
Webpack bundles the server and its dependencies into `build/server.js`, so production only needs the `build` folder. Put it behind a reverse proxy such as Caddy or nginx for TLS, or run it as a container.
|
|
165
|
+
|
|
166
|
+
## Current, boring, supported
|
|
167
|
+
|
|
168
|
+
Every dependency is on its latest major release, and the template is tested on all supported Node.js LTS lines.
|
|
169
|
+
|
|
170
|
+
| | |
|
|
171
|
+
|---|---|
|
|
172
|
+
| React | 19 |
|
|
173
|
+
| React Router | 8 |
|
|
174
|
+
| TypeScript | 6 |
|
|
175
|
+
| react-helmet-async | 3 |
|
|
176
|
+
| i18next | 27 |
|
|
177
|
+
| Webpack | 5 |
|
|
178
|
+
| Jest | 30 |
|
|
179
|
+
| Node.js | 22 · 24 · 26 |
|
|
180
|
+
|
|
181
|
+
## Release changes
|
|
182
|
+
|
|
183
|
+
### 1.5.0 -> 1.5.1
|
|
184
|
+
- Remove HoosatUI from the stack. The CLI no longer asks to install it, and `--hoosatui` is ignored with a warning.
|
|
185
|
+
- Template: drop the unused `react-markdown`, `rehype-highlight` and `remark-gfm` dependencies and the HoosatUI special case in the CSS build.
|
|
186
|
+
|
|
187
|
+
### 1.4.7 -> 1.5.0
|
|
188
|
+
- Requires Node.js 22 or newer (Node.js 20 is end-of-life), template is tested on Node.js 22, 24 and 26.
|
|
189
|
+
- Clone the template and its submodule over HTTPS, so no GitHub SSH key is needed.
|
|
190
|
+
- Run git and npm without a shell and with argument lists, so project names can not be interpreted as shell commands.
|
|
191
|
+
- Fix `--gitInit n` and `--hoosatui n` being treated as yes.
|
|
192
|
+
- Stop when cloning the template fails instead of continuing in the wrong directory.
|
|
193
|
+
- Fix `submodule` command on Windows and with git 2.38.1+.
|
|
194
|
+
- Template: React 19, React Router 8, TypeScript 6, Jest 30, i18next 27, security fixes in server core and all dependency vulnerabilities resolved.
|
|
195
|
+
|
|
196
|
+
### 1.4.5 -> 1.4.6
|
|
197
|
+
- Use submodule for server, make cloning of template recursive.
|
|
198
|
+
|
|
199
|
+
### 1.4.4 -> 1.4.5
|
|
200
|
+
- One small document change in server code example, to make your life easier.
|
|
201
|
+
- Add support for command line arguments.
|
|
202
|
+
- Add support for `npx hoosat-create submodule`.
|
|
203
|
+
|
|
204
|
+
### 1.4.3 -> 1.4.4
|
|
205
|
+
- Bring back the `#!/usr/bin/env node` line.
|
|
206
|
+
|
|
207
|
+
### 1.4.2 -> 1.4.3
|
|
208
|
+
- Update package.json to contain metadata.
|
|
209
|
+
|
|
210
|
+
### 1.4.1 -> 1.4.2
|
|
211
|
+
- Remove the `download-git-repo` dependency from hoosat-create.
|
|
212
|
+
- Validate input in hoosat-create. The following characters do not work in the project name: `;`, `|`, `&&`, `>`, `<`, `` ` ``, `$(`, `$()`
|
|
213
|
+
|
|
214
|
+
### 1.4.0 -> 1.4.1
|
|
215
|
+
- Changed `createServer` to include an options argument for changing the server protocol and to include SSL certificate information.
|
|
216
|
+
- JSDoc has been added and more documentation work.
|
|
217
|
+
|
|
218
|
+
### 1.3.5 -> 1.4.0
|
|
219
|
+
- Dropped Express.js and Babel from dependencies.
|
|
220
|
+
- Updated package.json scripts to use concurrently and nodemon.
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
The `hoosat-create` CLI is licensed under the [ISC License](LICENSE.txt). Use it for your own projects or as a starting point for your own templates.
|
|
225
|
+
|
|
226
|
+
## Join us
|
|
227
|
+
|
|
228
|
+
Questions, ideas or something broken? Open an [issue](https://github.com/TMKCodes/hoosat-create/issues) or come talk on [Discord](https://discord.gg/UXPFcPaPBg).
|
package/package.json
CHANGED