@opentf/create-afw 0.5.0 → 0.7.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 +5 -8
- package/esdev/templates/app/_gitignore +18 -0
- package/esdev/templates/app/_option/language/js/entry.js +4 -0
- package/esdev/templates/app/_option/language/js/index.html +13 -0
- package/esdev/templates/app/_option/language/js/jsconfig.json +6 -0
- package/esdev/templates/app/_option/language/js/tests/ui/Counter.test.js +10 -0
- package/esdev/templates/app/_option/language/ts/entry.ts +4 -0
- package/esdev/templates/app/_option/language/ts/index.html +13 -0
- package/esdev/templates/app/_option/language/ts/tests/ui/Counter.test.ts +10 -0
- package/esdev/templates/app/_option/language/ts/tsconfig.json +28 -0
- package/esdev/templates/app/_option/render/client/_option/language/js/app/_config.js +6 -0
- package/esdev/templates/app/_option/render/client/_option/language/ts/app/_config.ts +6 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/css/_option/language/js/README.md +14 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/css/_option/language/js/app/layout.jsx +13 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/css/_option/language/js/package.json +19 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/css/_option/language/ts/README.md +15 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/css/_option/language/ts/app/layout.tsx +13 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/css/_option/language/ts/package.json +21 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/tailwind/_option/language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/tailwind/_option/language/js/app/layout.jsx +13 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/tailwind/_option/language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/tailwind/_option/language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/tailwind/_option/language/ts/app/layout.tsx +13 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/_option/styling/tailwind/_option/language/ts/package.json +22 -0
- package/esdev/templates/app/_option/render/client/_option/server/no/esdev.json +18 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/css/_option/language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/css/_option/language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/css/_option/language/js/package.json +19 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/css/_option/language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/css/_option/language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/css/_option/language/ts/package.json +21 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/tailwind/_option/language/js/README.md +16 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/tailwind/_option/language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/tailwind/_option/language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/tailwind/_option/language/ts/README.md +17 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/tailwind/_option/language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/_option/styling/tailwind/_option/language/ts/package.json +22 -0
- package/esdev/templates/app/_option/render/client/_option/server/yes/esdev.json +28 -0
- package/esdev/templates/app/_option/render/mixed/_option/language/js/app/_config.js +6 -0
- package/esdev/templates/app/_option/render/mixed/_option/language/js/app/about/_config.js +4 -0
- package/esdev/templates/app/_option/render/mixed/_option/language/js/app/dashboard/_config.js +5 -0
- package/esdev/templates/app/_option/render/mixed/_option/language/js/app/dashboard/loader.js +4 -0
- package/esdev/templates/app/_option/render/mixed/_option/language/ts/app/_config.ts +6 -0
- package/esdev/templates/app/_option/render/mixed/_option/language/ts/app/about/_config.ts +4 -0
- package/esdev/templates/app/_option/render/mixed/_option/language/ts/app/dashboard/_config.ts +5 -0
- package/esdev/templates/app/_option/render/mixed/_option/language/ts/app/dashboard/loader.ts +4 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/css/_option/language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/css/_option/language/js/app/layout.jsx +15 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/css/_option/language/js/package.json +19 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/css/_option/language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/css/_option/language/ts/app/layout.tsx +15 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/css/_option/language/ts/package.json +21 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/tailwind/_option/language/js/README.md +16 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/tailwind/_option/language/js/app/layout.jsx +15 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/tailwind/_option/language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/tailwind/_option/language/ts/README.md +17 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/tailwind/_option/language/ts/app/layout.tsx +15 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/_option/styling/tailwind/_option/language/ts/package.json +22 -0
- package/esdev/templates/app/_option/render/mixed/_option/server/yes/esdev.json +28 -0
- package/esdev/templates/app/_option/render/mixed/_option/styling/css/_option/language/js/app/dashboard/page.jsx +13 -0
- package/esdev/templates/app/_option/render/mixed/_option/styling/css/_option/language/ts/app/dashboard/page.tsx +13 -0
- package/esdev/templates/app/_option/render/mixed/_option/styling/tailwind/_option/language/js/app/dashboard/page.jsx +13 -0
- package/esdev/templates/app/_option/render/mixed/_option/styling/tailwind/_option/language/ts/app/dashboard/page.tsx +13 -0
- package/esdev/templates/app/_option/render/server/_option/language/js/app/_config.js +6 -0
- package/esdev/templates/app/_option/render/server/_option/language/ts/app/_config.ts +6 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/css/_option/language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/css/_option/language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/css/_option/language/js/package.json +19 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/css/_option/language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/css/_option/language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/css/_option/language/ts/package.json +21 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/tailwind/_option/language/js/README.md +16 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/tailwind/_option/language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/tailwind/_option/language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/tailwind/_option/language/ts/README.md +17 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/tailwind/_option/language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/_option/styling/tailwind/_option/language/ts/package.json +22 -0
- package/esdev/templates/app/_option/render/server/_option/server/yes/esdev.json +28 -0
- package/esdev/templates/app/_option/render/static/_option/language/js/app/_config.js +6 -0
- package/esdev/templates/app/_option/render/static/_option/language/ts/app/_config.ts +6 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/css/_option/language/js/README.md +14 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/css/_option/language/js/app/layout.jsx +13 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/css/_option/language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/css/_option/language/ts/README.md +15 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/css/_option/language/ts/app/layout.tsx +13 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/css/_option/language/ts/package.json +22 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/tailwind/_option/language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/tailwind/_option/language/js/app/layout.jsx +13 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/tailwind/_option/language/js/package.json +21 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/tailwind/_option/language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/tailwind/_option/language/ts/app/layout.tsx +13 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/_option/styling/tailwind/_option/language/ts/package.json +23 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/esdev.json +32 -0
- package/esdev/templates/app/_option/render/static/_option/server/no/ssg.js +131 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/css/_option/language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/css/_option/language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/css/_option/language/js/package.json +19 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/css/_option/language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/css/_option/language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/css/_option/language/ts/package.json +21 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/tailwind/_option/language/js/README.md +16 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/tailwind/_option/language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/tailwind/_option/language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/tailwind/_option/language/ts/README.md +17 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/tailwind/_option/language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/_option/styling/tailwind/_option/language/ts/package.json +22 -0
- package/esdev/templates/app/_option/render/static/_option/server/yes/esdev.json +28 -0
- package/esdev/templates/app/_option/server/yes/_option/language/js/app/_middleware.js +9 -0
- package/esdev/templates/app/_option/server/yes/_option/language/js/app/api/hello/route.js +4 -0
- package/esdev/templates/app/_option/server/yes/_option/language/js/app/todos/loader.js +7 -0
- package/esdev/templates/app/_option/server/yes/_option/language/js/app/todos/todos.server.js +15 -0
- package/esdev/templates/app/_option/server/yes/_option/language/js/tests/server/api.test.js +8 -0
- package/esdev/templates/app/_option/server/yes/_option/language/ts/app/_middleware.ts +9 -0
- package/esdev/templates/app/_option/server/yes/_option/language/ts/app/api/hello/route.ts +4 -0
- package/esdev/templates/app/_option/server/yes/_option/language/ts/app/todos/loader.ts +7 -0
- package/esdev/templates/app/_option/server/yes/_option/language/ts/app/todos/todos.server.ts +15 -0
- package/esdev/templates/app/_option/server/yes/_option/language/ts/tests/server/api.test.ts +8 -0
- package/esdev/templates/app/_option/server/yes/_option/styling/css/_option/language/js/app/todos/page.jsx +29 -0
- package/esdev/templates/app/_option/server/yes/_option/styling/css/_option/language/ts/app/todos/page.tsx +29 -0
- package/esdev/templates/app/_option/server/yes/_option/styling/tailwind/_option/language/js/app/todos/page.jsx +29 -0
- package/esdev/templates/app/_option/server/yes/_option/styling/tailwind/_option/language/ts/app/todos/page.tsx +29 -0
- package/esdev/templates/app/_option/server/yes/server.js +53 -0
- package/esdev/templates/app/_option/styling/css/_option/language/js/app/Counter.jsx +10 -0
- package/esdev/templates/app/_option/styling/css/_option/language/js/app/page.jsx +13 -0
- package/esdev/templates/app/_option/styling/css/_option/language/ts/app/Counter.tsx +10 -0
- package/esdev/templates/app/_option/styling/css/_option/language/ts/app/page.tsx +13 -0
- package/esdev/templates/app/_option/styling/css/app/global.css +16 -0
- package/esdev/templates/app/_option/styling/tailwind/_option/language/js/app/Counter.jsx +10 -0
- package/esdev/templates/app/_option/styling/tailwind/_option/language/js/app/page.jsx +13 -0
- package/esdev/templates/app/_option/styling/tailwind/_option/language/ts/app/Counter.tsx +10 -0
- package/esdev/templates/app/_option/styling/tailwind/_option/language/ts/app/page.tsx +13 -0
- package/esdev/templates/app/_option/styling/tailwind/app/global.css +7 -0
- package/esdev/templates/app/app/about/page.md +7 -0
- package/esdev/templates/app/template.json +96 -0
- package/esdev/templates/catalog.json +15 -0
- package/esdev/templates/docs/_gitignore +18 -0
- package/esdev/templates/docs/_option/blog/no/_option/language/js/README.md +14 -0
- package/esdev/templates/docs/_option/blog/no/_option/language/js/app/page.jsx +15 -0
- package/esdev/templates/docs/_option/blog/no/_option/language/js/tests/ui/Home.test.js +9 -0
- package/esdev/templates/docs/_option/blog/no/_option/language/ts/README.md +15 -0
- package/esdev/templates/docs/_option/blog/no/_option/language/ts/app/page.tsx +15 -0
- package/esdev/templates/docs/_option/blog/no/_option/language/ts/tests/ui/Home.test.ts +9 -0
- package/esdev/templates/docs/_option/blog/no/afw.config.js +13 -0
- package/esdev/templates/docs/_option/blog/yes/_option/language/js/README.md +14 -0
- package/esdev/templates/docs/_option/blog/yes/_option/language/js/app/blog/layout.jsx +7 -0
- package/esdev/templates/docs/_option/blog/yes/_option/language/js/app/blog/page.jsx +13 -0
- package/esdev/templates/docs/_option/blog/yes/_option/language/js/app/page.jsx +15 -0
- package/esdev/templates/docs/_option/blog/yes/_option/language/js/tests/ui/Home.test.js +10 -0
- package/esdev/templates/docs/_option/blog/yes/_option/language/ts/README.md +15 -0
- package/esdev/templates/docs/_option/blog/yes/_option/language/ts/app/blog/layout.tsx +7 -0
- package/esdev/templates/docs/_option/blog/yes/_option/language/ts/app/blog/page.tsx +13 -0
- package/esdev/templates/docs/_option/blog/yes/_option/language/ts/app/page.tsx +15 -0
- package/esdev/templates/docs/_option/blog/yes/_option/language/ts/tests/ui/Home.test.ts +10 -0
- package/esdev/templates/docs/_option/blog/yes/afw.config.js +15 -0
- package/esdev/templates/docs/_option/blog/yes/app/blog/hello-world/page.mdx +10 -0
- package/esdev/templates/docs/_option/language/js/app/_config.js +4 -0
- package/esdev/templates/docs/_option/language/js/app/docs/layout.jsx +6 -0
- package/esdev/templates/docs/_option/language/js/app/layout.jsx +3 -0
- package/esdev/templates/docs/_option/language/js/entry.js +6 -0
- package/esdev/templates/docs/_option/language/js/index.html +12 -0
- package/esdev/templates/docs/_option/language/js/jsconfig.json +6 -0
- package/esdev/templates/docs/_option/language/js/package.json +21 -0
- package/esdev/templates/docs/_option/language/ts/app/_config.ts +4 -0
- package/esdev/templates/docs/_option/language/ts/app/docs/layout.tsx +6 -0
- package/esdev/templates/docs/_option/language/ts/app/layout.tsx +3 -0
- package/esdev/templates/docs/_option/language/ts/entry.ts +6 -0
- package/esdev/templates/docs/_option/language/ts/index.html +12 -0
- package/esdev/templates/docs/_option/language/ts/package.json +23 -0
- package/esdev/templates/docs/_option/language/ts/tsconfig.json +30 -0
- package/esdev/templates/docs/app/docs/_meta.js +5 -0
- package/esdev/templates/docs/app/docs/getting-started/page.mdx +11 -0
- package/esdev/templates/docs/app/docs/guides/writing-pages/page.mdx +20 -0
- package/esdev/templates/docs/app/docs/page.mdx +14 -0
- package/esdev/templates/docs/app/global.css +1 -0
- package/esdev/templates/docs/esdev.json +39 -0
- package/esdev/templates/docs/ssg.js +131 -0
- package/esdev/templates/docs/template.json +43 -0
- package/esdev/templates/library/_gitignore +18 -0
- package/esdev/templates/library/_option/language/js/entry.js +4 -0
- package/esdev/templates/library/_option/language/js/index.html +13 -0
- package/esdev/templates/library/_option/language/js/index.js +2 -0
- package/esdev/templates/library/_option/language/js/jsconfig.json +6 -0
- package/esdev/templates/library/_option/language/js/tests/ui/Counter.test.js +10 -0
- package/esdev/templates/library/_option/language/ts/entry.ts +4 -0
- package/esdev/templates/library/_option/language/ts/index.html +13 -0
- package/esdev/templates/library/_option/language/ts/index.ts +2 -0
- package/esdev/templates/library/_option/language/ts/tests/ui/Counter.test.ts +10 -0
- package/esdev/templates/library/_option/language/ts/tsconfig.json +30 -0
- package/esdev/templates/library/_option/styling/css/_option/language/js/README.md +12 -0
- package/esdev/templates/library/_option/styling/css/_option/language/js/app/page.jsx +10 -0
- package/esdev/templates/library/_option/styling/css/_option/language/js/package.json +26 -0
- package/esdev/templates/library/_option/styling/css/_option/language/js/src/Counter.jsx +10 -0
- package/esdev/templates/library/_option/styling/css/_option/language/ts/README.md +13 -0
- package/esdev/templates/library/_option/styling/css/_option/language/ts/app/page.tsx +10 -0
- package/esdev/templates/library/_option/styling/css/_option/language/ts/package.json +28 -0
- package/esdev/templates/library/_option/styling/css/_option/language/ts/src/Counter.tsx +10 -0
- package/esdev/templates/library/_option/styling/css/app/global.css +16 -0
- package/esdev/templates/library/_option/styling/tailwind/_option/language/js/README.md +13 -0
- package/esdev/templates/library/_option/styling/tailwind/_option/language/js/app/page.jsx +10 -0
- package/esdev/templates/library/_option/styling/tailwind/_option/language/js/package.json +27 -0
- package/esdev/templates/library/_option/styling/tailwind/_option/language/js/src/Counter.jsx +10 -0
- package/esdev/templates/library/_option/styling/tailwind/_option/language/ts/README.md +14 -0
- package/esdev/templates/library/_option/styling/tailwind/_option/language/ts/app/page.tsx +10 -0
- package/esdev/templates/library/_option/styling/tailwind/_option/language/ts/package.json +29 -0
- package/esdev/templates/library/_option/styling/tailwind/_option/language/ts/src/Counter.tsx +10 -0
- package/esdev/templates/library/_option/styling/tailwind/app/global.css +7 -0
- package/esdev/templates/library/esdev.json +18 -0
- package/esdev/templates/library/template.json +44 -0
- package/index.js +12 -21
- package/package.json +14 -9
- package/templates.js +257 -77
- package/versions.json +4 -4
package/templates.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
// The
|
|
2
|
-
//
|
|
1
|
+
// The AFW project templates, for both workflows: Vite + Node (`npm create @opentf/afw`)
|
|
2
|
+
// and esdev + ES-Runtime (`esdev create`, from the starters generated into esdev/ by
|
|
3
|
+
// scripts/write-esdev-templates.mjs). Each is generated from one source for both
|
|
4
|
+
// toolchains, both languages and both stylings, so the variants never drift apart: the
|
|
5
|
+
// same questions, the same `app/` and `tests/`; only the toolchain's own files differ
|
|
6
|
+
// (`vite.config.js` or `esdev.json`, `server.js`/`ssg.js`, scripts, dependencies).
|
|
3
7
|
//
|
|
4
8
|
// Choices are independent where the framework allows it:
|
|
5
|
-
// app — rendering (
|
|
6
|
-
//
|
|
9
|
+
// app — default rendering (server / static / client / mixed, set in
|
|
10
|
+
// app/_config.js) × server (API routes, middleware, loaders, server
|
|
11
|
+
// functions) × styling (css / tailwind). Server and mixed always have one.
|
|
7
12
|
// docs — an afw-docs site: MDX docs, prerendered, with search; a blog with feeds
|
|
8
13
|
// only when asked for.
|
|
9
14
|
// library — a package of components published as JSX source, with a dev preview.
|
|
10
15
|
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
|
|
11
18
|
import { escapeHTML } from "@opentf/std";
|
|
12
19
|
|
|
13
20
|
export const TEMPLATES = {
|
|
@@ -16,21 +23,21 @@ export const TEMPLATES = {
|
|
|
16
23
|
library: "A component library published as JSX source",
|
|
17
24
|
};
|
|
18
25
|
|
|
26
|
+
/** How an app's pages render by default (`app/_config.js`); any folder can override it. */
|
|
19
27
|
export const RENDERINGS = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
client: "Rendered in the browser: apps behind a login",
|
|
29
|
+
server: "Rendered per request: content sites, search, anything with SEO",
|
|
30
|
+
static: "Built once at build time: marketing sites, docs, blogs",
|
|
31
|
+
mixed: "Server by default, plus a static page and a client section to copy",
|
|
23
32
|
};
|
|
24
33
|
|
|
34
|
+
/** Renderings that always have a server. */
|
|
35
|
+
export const SERVER_RENDERINGS = new Set(["server", "mixed"]);
|
|
36
|
+
|
|
37
|
+
export const TOOLCHAINS = { vite: "Vite + Node", esdev: "esdev + ES-Runtime" };
|
|
38
|
+
|
|
25
39
|
export const STYLINGS = { css: "CSS", tailwind: "Tailwind CSS" };
|
|
26
40
|
|
|
27
|
-
/** The template names of earlier releases, kept as shorthands. */
|
|
28
|
-
export const LEGACY_TEMPLATES = {
|
|
29
|
-
spa: { template: "app", render: "spa", server: false },
|
|
30
|
-
fullstack: { template: "app", render: "spa", server: true },
|
|
31
|
-
ssr: { template: "app", render: "ssr", server: true },
|
|
32
|
-
ssg: { template: "app", render: "ssg", server: false },
|
|
33
|
-
};
|
|
34
41
|
|
|
35
42
|
// The third-party tools a new project starts on. AFW's own packages take the
|
|
36
43
|
// versions this scaffolder was released with (versions.js).
|
|
@@ -46,20 +53,29 @@ export const TOOL_VERSIONS = {
|
|
|
46
53
|
/**
|
|
47
54
|
* The files of a new project, as `{ relativePath: contents }`.
|
|
48
55
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
56
|
+
* `toolchain` picks the workflow's own files (`vite`, the default, or `esdev`); `pm` is the
|
|
57
|
+
* package manager the README names. `versions` maps each package (AFW's, and any tool
|
|
58
|
+
* in it) to the version to write; a tool it leaves out takes `TOOL_VERSIONS`.
|
|
59
|
+
*
|
|
60
|
+
* @param {{ name: string, template: keyof TEMPLATES, render?: string, server?: boolean,
|
|
61
|
+
* styling?: keyof STYLINGS, typescript: boolean, versions: Record<string, string>,
|
|
62
|
+
* toolchain?: keyof TOOLCHAINS, pm?: string, blog?: boolean }} options
|
|
51
63
|
*/
|
|
52
|
-
export function projectFiles({
|
|
64
|
+
export function projectFiles({
|
|
65
|
+
name, template, render = "client", server = false, blog = false, styling = "css", typescript, versions,
|
|
66
|
+
toolchain = "vite", pm = "npm",
|
|
67
|
+
}) {
|
|
53
68
|
if (!TEMPLATES[template]) throw new Error(`Unknown template "${template}". Choose one of: ${Object.keys(TEMPLATES).join(", ")}`);
|
|
54
69
|
if (!RENDERINGS[render]) throw new Error(`Unknown rendering "${render}". Choose one of: ${Object.keys(RENDERINGS).join(", ")}`);
|
|
55
70
|
if (!STYLINGS[styling]) throw new Error(`Unknown styling "${styling}". Choose one of: ${Object.keys(STYLINGS).join(", ")}`);
|
|
71
|
+
if (!TOOLCHAINS[toolchain]) throw new Error(`Unknown toolchain "${toolchain}". Choose one of: ${Object.keys(TOOLCHAINS).join(", ")}`);
|
|
56
72
|
const ctx = {
|
|
57
73
|
name, versions, ts: typescript, js: typescript ? "ts" : "js", jsx: typescript ? "tsx" : "jsx",
|
|
58
|
-
tailwind: styling === "tailwind",
|
|
74
|
+
tailwind: styling === "tailwind", toolchain, esdev: toolchain === "esdev", pm,
|
|
59
75
|
};
|
|
60
76
|
if (template === "docs") return docsFiles({ ...ctx, blog });
|
|
61
77
|
if (template === "library") return libraryFiles(ctx);
|
|
62
|
-
return appFiles({ ...ctx, render, server: render
|
|
78
|
+
return appFiles({ ...ctx, render, server: SERVER_RENDERINGS.has(render) || server });
|
|
63
79
|
}
|
|
64
80
|
|
|
65
81
|
// ---------------------------------------------------------------------------- shared
|
|
@@ -69,19 +85,53 @@ const escapeJs = (text) => String(text).replace(/[\\"]/g, "\\$&");
|
|
|
69
85
|
// ` class="…"` with Tailwind, nothing with plain CSS.
|
|
70
86
|
const tw = (ctx, classes) => (ctx.tailwind ? ` class="${classes}"` : "");
|
|
71
87
|
|
|
88
|
+
/** The version to write for `pkg`: from `versions`, else the tool's default range. */
|
|
89
|
+
const version = (ctx, pkg) => ctx.versions[pkg] ?? TOOL_VERSIONS[pkg];
|
|
90
|
+
|
|
72
91
|
function devDependencies(ctx, extra = {}) {
|
|
92
|
+
const v = (pkg) => version(ctx, pkg);
|
|
93
|
+
if (ctx.esdev) {
|
|
94
|
+
return sortKeys({
|
|
95
|
+
"@opentf/afw-test": v("@opentf/afw-test"),
|
|
96
|
+
"@opentf/esdev-plugin-afw": v("@opentf/esdev-plugin-afw"),
|
|
97
|
+
"@opentf/esrun-types": v("@opentf/esrun-types"),
|
|
98
|
+
...(ctx.ts ? { typescript: v("typescript") } : {}),
|
|
99
|
+
...(ctx.tailwind ? { tailwindcss: v("tailwindcss") } : {}),
|
|
100
|
+
...extra,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
73
103
|
return sortKeys({
|
|
74
|
-
"@opentf/afw-test":
|
|
75
|
-
"@opentf/vite-plugin-afw":
|
|
76
|
-
"happy-dom":
|
|
77
|
-
...(ctx.ts ? { typescript:
|
|
78
|
-
...(ctx.tailwind ? { tailwindcss:
|
|
79
|
-
vite:
|
|
80
|
-
vitest:
|
|
104
|
+
"@opentf/afw-test": v("@opentf/afw-test"),
|
|
105
|
+
"@opentf/vite-plugin-afw": v("@opentf/vite-plugin-afw"),
|
|
106
|
+
"happy-dom": v("happy-dom"),
|
|
107
|
+
...(ctx.ts ? { typescript: v("typescript") } : {}),
|
|
108
|
+
...(ctx.tailwind ? { tailwindcss: v("tailwindcss"), "@tailwindcss/vite": v("@tailwindcss/vite") } : {}),
|
|
109
|
+
vite: v("vite"),
|
|
110
|
+
vitest: v("vitest"),
|
|
81
111
|
...extra,
|
|
82
112
|
});
|
|
83
113
|
}
|
|
84
114
|
|
|
115
|
+
// esdev's own files: read from toolchain/esdev/ when an esdev project is generated.
|
|
116
|
+
const esdevFile = (name) => readFileSync(new URL(`./toolchain/esdev/${name}`, import.meta.url), "utf8");
|
|
117
|
+
|
|
118
|
+
/** esdev.json for a project: the AFW plugin (+ `plugins`), the web target and `targets`. */
|
|
119
|
+
function esdevConfig(ctx, { plugins = [], targets = {}, dev = null, afw = { appDir: "app" } } = {}) {
|
|
120
|
+
return json({
|
|
121
|
+
plugins: [{ module: "@opentf/esdev-plugin-afw", options: afw }, ...plugins],
|
|
122
|
+
build: { targets: { web: { entry: "index.html", outdir: "dist" }, ...targets } },
|
|
123
|
+
...(dev ? { dev } : {}),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The prerender step of a static esdev site: `ssg.js` run after the build. */
|
|
128
|
+
const ESDEV_SSG_TARGET = { "site-ssg": { entry: "ssg.js", out: ".ssg/ssg.js", then: "run" } };
|
|
129
|
+
const ESDEV_SITE_OUTPUT = { module: "@opentf/afw-cli/ssg", export: "siteOutputPlugin", options: { root: ".", target: "web", prerenderTarget: "site-ssg" } };
|
|
130
|
+
const ESDEV_SERVER = {
|
|
131
|
+
targets: { server: { entry: "server.js", out: "dist/server.js" } },
|
|
132
|
+
dev: { run: "server", app: { port: 3000 } },
|
|
133
|
+
};
|
|
134
|
+
|
|
85
135
|
function sortKeys(object) {
|
|
86
136
|
return Object.fromEntries(Object.entries(object).sort(([a], [b]) => a.localeCompare(b)));
|
|
87
137
|
}
|
|
@@ -115,7 +165,11 @@ function tsconfig(ctx, include, { allowJs = false } = {}) {
|
|
|
115
165
|
lib: ["ESNext", "DOM", "DOM.Iterable"],
|
|
116
166
|
jsx: "preserve",
|
|
117
167
|
jsxImportSource: "@opentf/afw",
|
|
118
|
-
types
|
|
168
|
+
// The toolchain's types (the runtime, `@afw/routes`, `.md`/`.css` imports). Under Vite,
|
|
169
|
+
// the `vitest` condition gives `@opentf/afw-test/test` Vitest's types.
|
|
170
|
+
...(ctx.esdev
|
|
171
|
+
? { types: ["@opentf/esrun-types", "@opentf/esdev-plugin-afw/client"] }
|
|
172
|
+
: { types: ["@opentf/vite-plugin-afw/client"], customConditions: ["vitest"] }),
|
|
119
173
|
strict: true,
|
|
120
174
|
noEmit: true,
|
|
121
175
|
isolatedModules: true,
|
|
@@ -133,11 +187,11 @@ function indexHtml(ctx, { title, css = true }) {
|
|
|
133
187
|
<head>
|
|
134
188
|
<meta charset="utf-8" />
|
|
135
189
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
136
|
-
<title>${escapeHTML(title)}</title>${css ? `\n <link rel="stylesheet" href="/app/global.css" />` : ""}
|
|
190
|
+
<title>${escapeHTML(title)}</title>${css ? `\n <link rel="stylesheet" href="${ctx.esdev ? "./" : "/"}app/global.css" />` : ""}
|
|
137
191
|
</head>
|
|
138
192
|
<body>
|
|
139
193
|
<div id="app"></div>
|
|
140
|
-
<script type="module" src="/entry.${ctx.js}"></script>
|
|
194
|
+
<script type="module" src="${ctx.esdev ? "./" : "/"}entry.${ctx.js}"></script>
|
|
141
195
|
</body>
|
|
142
196
|
</html>
|
|
143
197
|
`;
|
|
@@ -195,10 +249,12 @@ function counter(ctx) {
|
|
|
195
249
|
`;
|
|
196
250
|
}
|
|
197
251
|
|
|
252
|
+
// Tests import the test API from `@opentf/afw-test/test`: Vitest under Vite,
|
|
253
|
+
// `runtime:test` under esdev, so the same files run in both workflows.
|
|
198
254
|
function counterTest(ctx, from) {
|
|
199
|
-
return `import { expect, test } from "
|
|
255
|
+
return `import { expect, test } from "@opentf/afw-test/test";
|
|
200
256
|
import { render, userEvent } from "@opentf/afw-test";
|
|
201
|
-
import ${from.
|
|
257
|
+
import ${from.includes("/index.") ? "{ Counter }" : "Counter"} from "${from}";
|
|
202
258
|
|
|
203
259
|
test("counts clicks", async () => {
|
|
204
260
|
const { getByRole, getByText } = render(Counter, { start: 1 });
|
|
@@ -221,46 +277,105 @@ ${rows}
|
|
|
221
277
|
${notes.length ? `\n${notes.map((note) => `- ${note}`).join("\n")}\n` : ""}`;
|
|
222
278
|
}
|
|
223
279
|
|
|
224
|
-
|
|
280
|
+
// The DOM tests (`tests/ui/`) run with a DOM; server tests (`tests/server/`) run as
|
|
281
|
+
// server code, where `*.server.js` imports are the real functions.
|
|
282
|
+
const ESDEV_UI_TESTS = "esdev test --dom --setup=@opentf/afw-test/setup tests/ui";
|
|
283
|
+
|
|
284
|
+
function testScript(ctx, { server = false } = {}) {
|
|
285
|
+
if (!ctx.esdev) return "vitest run";
|
|
286
|
+
return server ? `esdev test tests/server && ${ESDEV_UI_TESTS}` : ESDEV_UI_TESTS;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function scripts(ctx, { server, client = false }) {
|
|
290
|
+
if (ctx.esdev) {
|
|
291
|
+
return {
|
|
292
|
+
dev: "esdev start",
|
|
293
|
+
build: "esdev build",
|
|
294
|
+
...(server
|
|
295
|
+
// Reads only its build (dist/), listens on 3000; it dials nothing, so no --allow-net.
|
|
296
|
+
? { start: "esrun --allow-read=dist --allow-listen=0.0.0.0:3000 --allow-env=PORT --allow-imports dist/server.js" }
|
|
297
|
+
: { preview: client ? "esdev preview --spa" : "esdev preview" }),
|
|
298
|
+
test: testScript(ctx, { server }),
|
|
299
|
+
...(ctx.ts ? { typecheck: "esdev typecheck" } : {}),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
225
302
|
return {
|
|
226
303
|
dev: "vite",
|
|
227
304
|
build: "vite build",
|
|
228
305
|
...(server ? { start: "node dist/server/index.js" } : { preview: "vite preview" }),
|
|
229
|
-
test:
|
|
306
|
+
test: testScript(ctx),
|
|
230
307
|
...(ctx.ts ? { typecheck: "tsc" } : {}),
|
|
231
308
|
};
|
|
232
309
|
}
|
|
233
310
|
|
|
311
|
+
const runner = (ctx) => (ctx.esdev ? "esdev" : "Vitest");
|
|
312
|
+
|
|
234
313
|
function commandRows(ctx, { server }) {
|
|
314
|
+
const pm = ctx.pm;
|
|
235
315
|
return [
|
|
236
|
-
[
|
|
237
|
-
[
|
|
238
|
-
server
|
|
239
|
-
|
|
240
|
-
|
|
316
|
+
[`${pm} run dev`, "Start the dev server"],
|
|
317
|
+
[`${pm} run build`, "Build for production"],
|
|
318
|
+
server
|
|
319
|
+
? [`${pm} run start`, ctx.esdev ? "Run the built server on ES-Runtime (`PORT`)" : "Run the built Node server (`PORT`, `HOST`)"]
|
|
320
|
+
: [`${pm} run preview`, "Preview the production build"],
|
|
321
|
+
[`${pm} run test`, `Run the tests with ${runner(ctx)}`],
|
|
322
|
+
...(ctx.ts ? [[`${pm} run typecheck`, "Check types"]] : []),
|
|
241
323
|
];
|
|
242
324
|
}
|
|
243
325
|
|
|
326
|
+
const gitignore = (ctx) => (ctx.esdev ? esdevFile("gitignore") : "node_modules\ndist\n");
|
|
327
|
+
|
|
328
|
+
/** The toolchain's own config files for a project (`vite.config.*`, or `esdev.json` & co). */
|
|
329
|
+
const jsconfig = () => json({ compilerOptions: { jsx: "preserve", jsxImportSource: "@opentf/afw" } });
|
|
330
|
+
|
|
331
|
+
const onToolchain = (ctx) => (ctx.esdev ? "esdev and ES-Runtime" : "Vite");
|
|
332
|
+
|
|
244
333
|
// ---------------------------------------------------------------------------- app
|
|
245
334
|
|
|
335
|
+
/** `app/_config.*`: how the pages of a folder (and the folders below it) render. */
|
|
336
|
+
function routeConfig(ctx, render, comment) {
|
|
337
|
+
return `import { defineRoute } from "@opentf/afw";
|
|
338
|
+
|
|
339
|
+
${comment}
|
|
340
|
+
export default defineRoute({ render: "${render}" });
|
|
341
|
+
`;
|
|
342
|
+
}
|
|
343
|
+
|
|
246
344
|
function appFiles(ctx) {
|
|
247
345
|
const { ts, js, jsx, render, server } = ctx;
|
|
346
|
+
const mixed = render === "mixed";
|
|
347
|
+
const appDefault = mixed ? "server" : render;
|
|
248
348
|
const files = {};
|
|
249
349
|
files["package.json"] = json({
|
|
250
|
-
name: ctx.name, private: true, type: "module", scripts: scripts(ctx, { server }),
|
|
251
|
-
dependencies: { "@opentf/afw": ctx
|
|
252
|
-
devDependencies: devDependencies(ctx),
|
|
350
|
+
name: ctx.name, private: true, type: "module", scripts: scripts(ctx, { server, client: render === "client" }),
|
|
351
|
+
dependencies: { "@opentf/afw": version(ctx, "@opentf/afw") },
|
|
352
|
+
devDependencies: devDependencies(ctx, ctx.esdev && render === "static" && !server ? { "@opentf/afw-cli": version(ctx, "@opentf/afw-cli") } : {}),
|
|
253
353
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
354
|
+
if (ctx.esdev) {
|
|
355
|
+
// A static site without a server prerenders in a step after the build; a server
|
|
356
|
+
// renders (and serves prebuilt) pages itself.
|
|
357
|
+
const site = render === "static" && !server;
|
|
358
|
+
files["esdev.json"] = esdevConfig(ctx, {
|
|
359
|
+
plugins: site ? [ESDEV_SITE_OUTPUT] : [],
|
|
360
|
+
targets: { ...(server ? ESDEV_SERVER.targets : {}), ...(site ? ESDEV_SSG_TARGET : {}) },
|
|
361
|
+
dev: server ? ESDEV_SERVER.dev : null,
|
|
362
|
+
});
|
|
363
|
+
if (server) files["server.js"] = esdevFile("server.js");
|
|
364
|
+
if (site) files["ssg.js"] = esdevFile("ssg.js");
|
|
365
|
+
if (!ts) files["jsconfig.json"] = jsconfig();
|
|
366
|
+
} else {
|
|
367
|
+
const options = render === "static" ? `{ baseUrl: "" /* your site URL, e.g. "https://example.com", enables sitemap.xml */ }` : "";
|
|
368
|
+
files[`vite.config.${js}`] = viteConfig(ctx, { plugins: [`afw(${options})`] });
|
|
369
|
+
}
|
|
370
|
+
if (ts) files["tsconfig.json"] = tsconfig(ctx, ctx.esdev ? ["app", "tests", "entry.ts"] : ["app", "tests", "entry.ts", "vite.config.ts"]);
|
|
259
371
|
files["index.html"] = indexHtml(ctx, { title: ctx.name });
|
|
260
372
|
files[`entry.${js}`] = entry(ctx);
|
|
261
373
|
files["app/global.css"] = globalCss(ctx);
|
|
374
|
+
files[`app/_config.${js}`] = routeConfig(ctx, appDefault, `// How the pages in app/ render: "server" (per request), "static" (once, at build time) or
|
|
375
|
+
// "client" (in the browser). A folder's own _config.${js} sets it for that folder and
|
|
376
|
+
// the folders below it; the nearest one wins.`);
|
|
262
377
|
|
|
263
|
-
const navLinks = [["/", "Home"], ["/about", "About"], ...(server ? [["/todos", "Todos"]] : [])];
|
|
378
|
+
const navLinks = [["/", "Home"], ["/about", "About"], ...(server ? [["/todos", "Todos"]] : []), ...(mixed ? [["/dashboard", "Dashboard"]] : [])];
|
|
264
379
|
files[`app/layout.${jsx}`] = `import { Link } from "@opentf/afw";
|
|
265
380
|
|
|
266
381
|
export default function Layout({ children }${ts ? ": { children: unknown }" : ""}) {
|
|
@@ -297,16 +412,25 @@ title: About
|
|
|
297
412
|
|
|
298
413
|
This page is Markdown. The AFW compiler turns it into a page like any other.
|
|
299
414
|
`;
|
|
415
|
+
if (mixed) Object.assign(files, mixedFiles(ctx));
|
|
300
416
|
if (server) Object.assign(files, serverFiles(ctx));
|
|
301
|
-
files[`tests/Counter.test.${js}`] = counterTest(ctx,
|
|
302
|
-
files[".gitignore"] =
|
|
303
|
-
|
|
304
|
-
const how = {
|
|
417
|
+
files[`tests/ui/Counter.test.${js}`] = counterTest(ctx, `../../app/Counter.${jsx}`);
|
|
418
|
+
files[".gitignore"] = gitignore(ctx);
|
|
419
|
+
|
|
420
|
+
const how = {
|
|
421
|
+
client: "rendered in the browser",
|
|
422
|
+
server: "rendered on the server per request",
|
|
423
|
+
static: "prerendered to static HTML",
|
|
424
|
+
mixed: "rendered on the server by default, with a prebuilt page (`/about`) and a section rendered in the browser (`/dashboard`)",
|
|
425
|
+
}[render];
|
|
426
|
+
const host = ctx.esdev ? "ES-Runtime" : "Node";
|
|
305
427
|
files["README.md"] = readme(ctx, {
|
|
306
|
-
summary: `An [AFW](https://afw.opentechf.org) app on
|
|
428
|
+
summary: `An [AFW](https://afw.opentechf.org) app on ${onToolchain(ctx)}: pages ${how}${server ? `, with a server on ${host}` : ""}.`,
|
|
307
429
|
commands: commandRows(ctx, { server }),
|
|
308
430
|
notes: [
|
|
309
431
|
`Pages live in \`app/\`: \`app/about/page.md\` is served at \`/about\`.`,
|
|
432
|
+
`\`app/_config.${js}\` sets how pages render (\`server\`, \`static\` or \`client\`); a folder's own \`_config.${js}\` changes it for that folder.`,
|
|
433
|
+
`Component tests live in \`tests/ui/\`${server ? ", server tests (API routes, loaders) in `tests/server/`" : ""}.`,
|
|
310
434
|
...(server ? [
|
|
311
435
|
`On the server: API routes (\`app/api/hello/route.${js}\`), middleware (\`app/_middleware.${js}\`), a loader (\`app/todos/loader.${js}\`) and server functions (\`app/todos/todos.server.${js}\`), which components call like async functions.`,
|
|
312
436
|
] : []),
|
|
@@ -316,9 +440,47 @@ This page is Markdown. The AFW compiler turns it into a page like any other.
|
|
|
316
440
|
return files;
|
|
317
441
|
}
|
|
318
442
|
|
|
443
|
+
/** The mixed app's examples: a prebuilt page and a section rendered in the browser. */
|
|
444
|
+
function mixedFiles(ctx) {
|
|
445
|
+
const { ts, js, jsx } = ctx;
|
|
446
|
+
const files = {};
|
|
447
|
+
files[`app/about/_config.${js}`] = routeConfig(ctx, "static", "// Built once at build time; the rest of the app renders per request.");
|
|
448
|
+
files[`app/dashboard/_config.${js}`] = routeConfig(ctx, "client", `// Rendered in the browser: the server sends the layout and this folder's loader data,
|
|
449
|
+
// and never loads its pages, so they may use browser-only code.`);
|
|
450
|
+
files[`app/dashboard/loader.${js}`] = `// Still runs on the server: a client page gets its data with the page.
|
|
451
|
+
export default function loader() {
|
|
452
|
+
return { visits: 42 };
|
|
453
|
+
}
|
|
454
|
+
`;
|
|
455
|
+
files[`app/dashboard/page.${jsx}`] = `import { router } from "@opentf/afw";
|
|
456
|
+
|
|
457
|
+
export const metadata = { title: "Dashboard" };
|
|
458
|
+
|
|
459
|
+
export default function Dashboard() {
|
|
460
|
+
const visits = $derived(${ts ? "(router.data as { visits?: number } | undefined)" : "router.data"}?.visits ?? 0);
|
|
461
|
+
return (
|
|
462
|
+
<section>
|
|
463
|
+
<h1${tw(ctx, "mb-4 text-2xl font-bold")}>Dashboard</h1>
|
|
464
|
+
<p>Rendered in your browser, {visits} visits. Browser-only code is safe here.</p>
|
|
465
|
+
</section>
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
`;
|
|
469
|
+
return files;
|
|
470
|
+
}
|
|
471
|
+
|
|
319
472
|
function serverFiles(ctx) {
|
|
320
473
|
const { ts, js, jsx } = ctx;
|
|
321
474
|
const files = {};
|
|
475
|
+
files[`tests/server/api.test.${js}`] = `import { expect, test } from "@opentf/afw-test/test";
|
|
476
|
+
import { GET } from "../../app/api/hello/route.${js}";
|
|
477
|
+
|
|
478
|
+
test("GET /api/hello greets by name", async () => {
|
|
479
|
+
const response = GET(new Request("http://localhost/api/hello?name=AFW"), { query: { name: "AFW" }, locals: { requestId: "r1" } });
|
|
480
|
+
expect(response.status).toBe(200);
|
|
481
|
+
expect(await response.json()).toEqual({ message: "Hello, AFW!", requestId: "r1" });
|
|
482
|
+
});
|
|
483
|
+
`;
|
|
322
484
|
files[`app/api/hello/route.${js}`] = `// GET /api/hello?name=… — API routes run on Node, so any npm package works here.
|
|
323
485
|
export function GET(request${ts ? ": Request" : ""}, { query, locals }${ts ? ": { query: Record<string, string>; locals: Record<string, unknown> }" : ""}) {
|
|
324
486
|
return Response.json({ message: \`Hello, \${query.name ?? "world"}!\`, requestId: locals.requestId });
|
|
@@ -398,14 +560,24 @@ function docsFiles(ctx) {
|
|
|
398
560
|
const files = {};
|
|
399
561
|
files["package.json"] = json({
|
|
400
562
|
name: ctx.name, private: true, type: "module", scripts: scripts(ctx, { server: false }),
|
|
401
|
-
dependencies: { "@opentf/afw": ctx
|
|
402
|
-
devDependencies: devDependencies({ ...ctx, tailwind: false }),
|
|
563
|
+
dependencies: { "@opentf/afw": version(ctx, "@opentf/afw"), "@opentf/afw-docs": version(ctx, "@opentf/afw-docs") },
|
|
564
|
+
devDependencies: devDependencies({ ...ctx, tailwind: false }, ctx.esdev ? { "@opentf/afw-cli": version(ctx, "@opentf/afw-cli") } : {}),
|
|
403
565
|
});
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
566
|
+
if (ctx.esdev) {
|
|
567
|
+
files["esdev.json"] = esdevConfig(ctx, {
|
|
568
|
+
plugins: [{ module: "@opentf/afw-docs/build", export: "afwDocsPlugin", options: { appDir: "app" } }, ESDEV_SITE_OUTPUT],
|
|
569
|
+
targets: ESDEV_SSG_TARGET,
|
|
570
|
+
});
|
|
571
|
+
files["ssg.js"] = esdevFile("ssg.js");
|
|
572
|
+
if (!ts) files["jsconfig.json"] = jsconfig();
|
|
573
|
+
} else {
|
|
574
|
+
files[`vite.config.${js}`] = viteConfig({ ...ctx, tailwind: false }, {
|
|
575
|
+
imports: [`import afwDocs from "@opentf/afw-docs/vite";`],
|
|
576
|
+
plugins: ["afw()", "afwDocs()"],
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
files[`app/_config.${js}`] = routeConfig(ctx, "static", "// The site is prerendered: every page is built once, at build time.");
|
|
580
|
+
if (ts) files["tsconfig.json"] = tsconfig(ctx, ctx.esdev ? ["app", "tests", "entry.ts", "afw.config.js"] : ["app", "tests", "entry.ts", "vite.config.ts", "afw.config.js"], { allowJs: true });
|
|
409
581
|
files["afw.config.js"] = `import { defineDocsConfig } from "@opentf/afw-docs/config";
|
|
410
582
|
|
|
411
583
|
export default defineDocsConfig({
|
|
@@ -482,8 +654,8 @@ description: Install and run the project.
|
|
|
482
654
|
# Getting Started
|
|
483
655
|
|
|
484
656
|
\`\`\`bash
|
|
485
|
-
|
|
486
|
-
|
|
657
|
+
${ctx.pm} install
|
|
658
|
+
${ctx.pm} run dev
|
|
487
659
|
\`\`\`
|
|
488
660
|
`;
|
|
489
661
|
files["app/docs/guides/writing-pages/page.mdx"] = `---
|
|
@@ -508,9 +680,9 @@ Markdown with components, like this list of steps.
|
|
|
508
680
|
</Steps>
|
|
509
681
|
`;
|
|
510
682
|
if (blog) Object.assign(files, blogFiles(ctx));
|
|
511
|
-
files[`tests/Home.test.${js}`] = `import { expect, test } from "
|
|
683
|
+
files[`tests/ui/Home.test.${js}`] = `import { expect, test } from "@opentf/afw-test/test";
|
|
512
684
|
import { render } from "@opentf/afw-test";
|
|
513
|
-
import Home from "
|
|
685
|
+
import Home from "../../app/page.${jsx}";
|
|
514
686
|
|
|
515
687
|
test("the home page links to the docs${blog ? " and the blog" : ""}", () => {
|
|
516
688
|
const { getByRole } = render(Home);
|
|
@@ -519,13 +691,13 @@ test("the home page links to the docs${blog ? " and the blog" : ""}", () => {
|
|
|
519
691
|
expect(getByRole("link", { name: "Visit the blog" }).getAttribute("href")).toBe("/blog");` : ""}
|
|
520
692
|
});
|
|
521
693
|
`;
|
|
522
|
-
files[".gitignore"] =
|
|
694
|
+
files[".gitignore"] = gitignore(ctx);
|
|
523
695
|
files["README.md"] = readme(ctx, {
|
|
524
|
-
summary: `A documentation site${blog ? " and blog" : ""} built with [AFW](https://afw.opentechf.org) and \`@opentf/afw-docs\` on
|
|
696
|
+
summary: `A documentation site${blog ? " and blog" : ""} built with [AFW](https://afw.opentechf.org) and \`@opentf/afw-docs\` on ${onToolchain(ctx)}.`,
|
|
525
697
|
commands: commandRows(ctx, { server: false }),
|
|
526
698
|
notes: [
|
|
527
699
|
`Docs pages live in \`app/docs/\`${blog ? ", posts in \`app/blog/\`" : ""}; \`app/docs/_meta.js\` orders the sidebar.`,
|
|
528
|
-
|
|
700
|
+
`\`${ctx.pm} run build\` prerenders every page and writes the search index, \`sitemap.xml\`${blog ? ", RSS and Atom feeds" : ""} and \`llms.txt\`.`,
|
|
529
701
|
"Set your site's URL in `afw.config.js`.",
|
|
530
702
|
],
|
|
531
703
|
});
|
|
@@ -577,7 +749,7 @@ Posts live in \`app/blog/\`; each one appears in the post list and the RSS and A
|
|
|
577
749
|
function libraryFiles(ctx) {
|
|
578
750
|
const { ts, js, jsx } = ctx;
|
|
579
751
|
const files = {};
|
|
580
|
-
const afw = ctx
|
|
752
|
+
const afw = version(ctx, "@opentf/afw");
|
|
581
753
|
files["package.json"] = json({
|
|
582
754
|
name: ctx.name,
|
|
583
755
|
version: "0.1.0",
|
|
@@ -586,12 +758,20 @@ function libraryFiles(ctx) {
|
|
|
586
758
|
exports: { ".": `./index.${js}` },
|
|
587
759
|
files: [`index.${js}`, "src"],
|
|
588
760
|
sideEffects: false,
|
|
589
|
-
scripts:
|
|
590
|
-
|
|
761
|
+
scripts: ctx.esdev
|
|
762
|
+
? { dev: "esdev start", test: testScript(ctx), ...(ts ? { typecheck: "esdev typecheck" } : {}) }
|
|
763
|
+
: { dev: "vite", test: testScript(ctx), ...(ts ? { typecheck: "tsc" } : {}) },
|
|
764
|
+
// A range: apps keep their own AFW release within it.
|
|
765
|
+
peerDependencies: { "@opentf/afw": afw.startsWith("^") ? afw : `^${afw}` },
|
|
591
766
|
devDependencies: devDependencies(ctx, { "@opentf/afw": afw }),
|
|
592
767
|
});
|
|
593
|
-
|
|
594
|
-
|
|
768
|
+
if (ctx.esdev) {
|
|
769
|
+
files["esdev.json"] = esdevConfig(ctx);
|
|
770
|
+
if (!ts) files["jsconfig.json"] = jsconfig();
|
|
771
|
+
} else {
|
|
772
|
+
files[`vite.config.${js}`] = viteConfig(ctx, { plugins: ["afw()"] });
|
|
773
|
+
}
|
|
774
|
+
if (ts) files["tsconfig.json"] = tsconfig(ctx, ctx.esdev ? ["index.ts", "src", "app", "tests", "entry.ts"] : ["index.ts", "src", "app", "tests", "entry.ts", "vite.config.ts"]);
|
|
595
775
|
files[`index.${js}`] = `// The package entry: export each component.
|
|
596
776
|
export { default as Counter } from "./src/Counter.${jsx}";
|
|
597
777
|
`;
|
|
@@ -611,15 +791,15 @@ export default function Preview() {
|
|
|
611
791
|
);
|
|
612
792
|
}
|
|
613
793
|
`;
|
|
614
|
-
files[`tests/Counter.test.${js}`] = counterTest(ctx,
|
|
615
|
-
files[".gitignore"] =
|
|
794
|
+
files[`tests/ui/Counter.test.${js}`] = counterTest(ctx, `../../index.${js}`);
|
|
795
|
+
files[".gitignore"] = gitignore(ctx);
|
|
616
796
|
files["README.md"] = readme(ctx, {
|
|
617
797
|
summary: "A component library for [AFW](https://afw.opentechf.org), published as JSX source.",
|
|
618
798
|
commands: [
|
|
619
|
-
[
|
|
620
|
-
[
|
|
621
|
-
...(ts ? [[
|
|
622
|
-
[
|
|
799
|
+
[`${ctx.pm} run dev`, "Preview the components (`app/page." + jsx + "`)"],
|
|
800
|
+
[`${ctx.pm} run test`, `Run the tests with ${runner(ctx)}`],
|
|
801
|
+
...(ts ? [[`${ctx.pm} run typecheck`, "Check types"]] : []),
|
|
802
|
+
[`${ctx.pm} publish`, "Publish `index." + js + "` and `src/`"],
|
|
623
803
|
],
|
|
624
804
|
notes: [
|
|
625
805
|
`Export each component from \`index.${js}\`.`,
|
package/versions.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"@opentf/afw": "^0.
|
|
3
|
-
"@opentf/afw-docs": "^0.
|
|
4
|
-
"@opentf/afw-test": "^1.
|
|
5
|
-
"@opentf/vite-plugin-afw": "^0.
|
|
2
|
+
"@opentf/afw": "^0.39.0",
|
|
3
|
+
"@opentf/afw-docs": "^0.38.0",
|
|
4
|
+
"@opentf/afw-test": "^1.35.0",
|
|
5
|
+
"@opentf/vite-plugin-afw": "^0.8.0"
|
|
6
6
|
}
|