@rshono/create 1.0.0-rc.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.
Files changed (34) hide show
  1. package/README.md +105 -0
  2. package/bin/create-rshono.mjs +29 -0
  3. package/dist/api.mjs +749 -0
  4. package/dist/cli.mjs +3930 -0
  5. package/package.json +59 -0
  6. package/templates/base/README.md +42 -0
  7. package/templates/base/_env +9 -0
  8. package/templates/base/_gitignore +8 -0
  9. package/templates/base/public/favicon.svg +1 -0
  10. package/templates/base/public/robots.txt +2 -0
  11. package/templates/base/rshono.config.ts +35 -0
  12. package/templates/base/src/actions.ts +19 -0
  13. package/templates/base/src/components/404.tsx +17 -0
  14. package/templates/base/src/components/500.tsx +21 -0
  15. package/templates/base/src/components/greet-form.tsx +27 -0
  16. package/templates/base/src/components/home.tsx +50 -0
  17. package/templates/base/src/components/layout.tsx +45 -0
  18. package/templates/base/src/env.d.ts +2 -0
  19. package/templates/base/src/lib/env.ts +26 -0
  20. package/templates/base/src/routes.ts +32 -0
  21. package/templates/base/src/server.ts +59 -0
  22. package/templates/base/src/styles.css +178 -0
  23. package/templates/base/tsconfig.json +20 -0
  24. package/templates/biome/biome.json +7 -0
  25. package/templates/biome-tailwind/biome.json +7 -0
  26. package/templates/oxfmt/_oxfmtrc.json +7 -0
  27. package/templates/oxlint/_oxlintrc.json +7 -0
  28. package/templates/prettier/_prettierignore +10 -0
  29. package/templates/prettier/_prettierrc.json +7 -0
  30. package/templates/tailwind/postcss.config.mjs +9 -0
  31. package/templates/tailwind/rshono.config.ts +45 -0
  32. package/templates/tailwind/src/components/home.tsx +50 -0
  33. package/templates/tailwind/src/components/layout.tsx +45 -0
  34. package/templates/tailwind/src/styles.css +40 -0
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # @rshono/create
2
+
3
+ Scaffolds a new [rshono](https://github.com/rshono/rshono) app — Hono + Rspack + React Server Components.
4
+
5
+ ```bash
6
+ npm create @rshono@latest my-app
7
+ pnpm create @rshono my-app
8
+ yarn create @rshono my-app
9
+ bun create @rshono my-app
10
+ ```
11
+
12
+ The package manager that ran it is the one the project gets: it is read from `npm_config_user_agent`, used
13
+ for the install, written into `packageManager` for Corepack, and used in every command the closing summary
14
+ prints. Nothing asks you which one you meant.
15
+
16
+ ## The questions
17
+
18
+ Six, each with a default, and each answerable by a flag instead:
19
+
20
+ | Question | Default | Flag |
21
+ | --------------------- | ------------------ | ------------------------------------------------------------------- |
22
+ | Where should it go? | `my-rshono-app` | first positional argument, or `.` |
23
+ | Where is it deployed? | `node` | `--deploy node\|bun\|deno\|cloudflare\|vercel\|netlify\|aws-lambda` |
24
+ | Styling | plain CSS | `--tailwind` / `--no-tailwind` |
25
+ | Formatting & linting | Prettier + oxlint | `--quality prettier-oxlint\|biome\|oxc\|none` |
26
+ | Install dependencies? | yes | `--no-install` |
27
+ | Initialize git? | yes, unless nested | `--no-git` |
28
+
29
+ Plus `--formatter` and `--linter` to set either half of the quality preset on its own, `--force` to
30
+ scaffold into a directory that is not empty, `--dry-run` to see the file list and write nothing, and `-y`
31
+ to take the defaults for everything not given. **A non-interactive terminal implies `-y`**, so this is one
32
+ command in CI or from an agent:
33
+
34
+ ```bash
35
+ npm create @rshono@latest my-app -y --deploy cloudflare --tailwind --quality biome
36
+ ```
37
+
38
+ The deploy targets, and the deploy command each one prints, are generated from the framework's own
39
+ presets — a target added to rshono appears here with no edit.
40
+
41
+ ## What you get
42
+
43
+ ```
44
+ rshono.config.ts the chosen deploy target; everything else commented with its default
45
+ tsconfig.json strict, with @/* → ./src/*
46
+ .env committed defaults; secrets go in .env.local
47
+ public/ favicon.svg, robots.txt
48
+ src/routes.ts one page, a 404 and a 500, with the other route kinds commented
49
+ src/server.ts AppEnv, request-id middleware, error reporting, /api/health, redirects, AppType
50
+ src/actions.ts a 'use server' action, called from a form that works without JavaScript
51
+ src/components/ layout, home, greet-form ('use client'), 404, 500
52
+ src/lib/env.ts both sides of the PUBLIC_ boundary in one place
53
+ src/styles.css element-level CSS, or the Tailwind entry
54
+ ```
55
+
56
+ Then, if the dependencies were installed, the scaffold is run through its own formatter — so a fresh
57
+ project passes its own `format:check` rather than reporting a diff nobody made.
58
+
59
+ `react` and `react-dom` are pinned **exactly**, at the versions the framework is tested against, and those
60
+ pins are generated from rshono's own manifest. That is not tidiness: the RSC runtime reaches into React's
61
+ internals, and an app installed with npm or bun has no workspace overrides to keep a single copy of it.
62
+
63
+ ## Adding an option
64
+
65
+ Every difference between two scaffolds is a `Feature` — files to overlay, dependencies, scripts,
66
+ `.gitignore` lines, a closing note. Nothing in the generator knows what Tailwind is. So an option is three
67
+ edits and no new machinery:
68
+
69
+ 1. A `Feature` in `src/features/` — `templates/<id>` for the files it brings, plus whatever it adds to the
70
+ manifest.
71
+ 2. The template directory itself, as **real files**. They are copied over the base, so an overlay replaces
72
+ a file rather than patching it, and template files stay valid TypeScript that an editor can check.
73
+ `_name` becomes `.name` on write, because npm strips a literal `.gitignore` out of a published tarball.
74
+ 3. A prompt in `src/cli.ts`, if it deserves a question of its own — and a flag, which it always does.
75
+
76
+ `plan(answers)` is pure: answers in, a `Map` of path → contents out, no directory touched. That is what
77
+ makes the whole matrix of options testable in milliseconds (`test/plan.test.mjs`) and `--dry-run` free. It
78
+ is also exported, for a tool that wants to scaffold without the prompts:
79
+
80
+ ```ts
81
+ import { plan, writePlan } from '@rshono/create';
82
+ ```
83
+
84
+ ## Two things worth knowing
85
+
86
+ **There is no ESLint option.** Linting TypeScript with ESLint means `typescript-eslint`, whose peer range is
87
+ `typescript >=4.8.4 <6.1.0`; rshono is built and tested against TypeScript 7. `npm install` fails outright
88
+ on the conflict, and forcing past it would hand you a linter running against a compiler API it was never
89
+ built for. When upstream widens the range, ESLint becomes one more entry in `features/quality.ts`.
90
+
91
+ **Tailwind is four packages, a `postcss.config.mjs` and one rule in `rshono.config.ts`.** rshono compiles
92
+ CSS natively and has no PostCSS in it — that is deliberate, and it means an app that wants a plugin chain
93
+ brings its own, through the `rspack` hook. The overlay writes all of it, with a comment saying what to
94
+ delete to go back to plain CSS.
95
+
96
+ ## Development
97
+
98
+ ```bash
99
+ pnpm --filter @rshono/create build # codegen, then one bundled dist/cli.mjs with no runtime deps
100
+ pnpm --filter @rshono/create test # the plan matrix — fast, no I/O
101
+ CREATE_RSHONO_E2E=1 pnpm --filter @rshono/create test # also: pack, install and build real apps
102
+ ```
103
+
104
+ `@clack/prompts` (MIT) is bundled rather than depended on, so `npm create` downloads one tarball before it
105
+ can ask its first question.
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ // Thin launcher, kept deliberately old-syntax and dependency-free: it is the one file that has to
3
+ // parse and run on whatever Node the user happens to have. The CLI itself is a bundle — its imports
4
+ // are evaluated before any statement in it, so a version check *inside* it would be too late to
5
+ // produce anything friendlier than a stack trace.
6
+ var MINIMUM = [22, 1, 0];
7
+
8
+ var current = process.versions.node.split('.').map(Number);
9
+ var older = false;
10
+ for (var i = 0; i < MINIMUM.length; i++) {
11
+ if (current[i] === MINIMUM[i]) continue;
12
+ older = current[i] < MINIMUM[i];
13
+ break;
14
+ }
15
+
16
+ if (older) {
17
+ console.error(
18
+ '\ncreate-rshono needs Node ' +
19
+ MINIMUM.join('.') +
20
+ ' or newer — you are on ' +
21
+ process.versions.node +
22
+ '.\n' +
23
+ 'rshono itself requires it too (worker threads, process.loadEnvFile, Promise.withResolvers),\n' +
24
+ 'so scaffolding on this version would produce an app that cannot start.\n',
25
+ );
26
+ process.exit(1);
27
+ }
28
+
29
+ import('../dist/cli.mjs');