@opentf/create-afw 0.4.0 → 0.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 +4 -2
- 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 +30 -0
- package/esdev/templates/app/_option/render/client+language/js/app/_config.js +6 -0
- package/esdev/templates/app/_option/render/client+language/ts/app/_config.ts +6 -0
- package/esdev/templates/app/_option/render/client+server/no/esdev.json +18 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/css+language/js/README.md +14 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/css+language/js/app/layout.jsx +13 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/css+language/js/package.json +19 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/css+language/ts/README.md +15 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/css+language/ts/app/layout.tsx +13 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/css+language/ts/package.json +21 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/tailwind+language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/tailwind+language/js/app/layout.jsx +13 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/tailwind+language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/tailwind+language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/tailwind+language/ts/app/layout.tsx +13 -0
- package/esdev/templates/app/_option/render/client+server/no+styling/tailwind+language/ts/package.json +22 -0
- package/esdev/templates/app/_option/render/client+server/yes/esdev.json +28 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/css+language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/css+language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/css+language/js/package.json +19 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/css+language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/css+language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/css+language/ts/package.json +21 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/tailwind+language/js/README.md +16 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/tailwind+language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/tailwind+language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/tailwind+language/ts/README.md +17 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/tailwind+language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/client+server/yes+styling/tailwind+language/ts/package.json +22 -0
- package/esdev/templates/app/_option/render/mixed+language/js/app/_config.js +6 -0
- package/esdev/templates/app/_option/render/mixed+language/js/app/about/_config.js +4 -0
- package/esdev/templates/app/_option/render/mixed+language/js/app/dashboard/_config.js +5 -0
- package/esdev/templates/app/_option/render/mixed+language/js/app/dashboard/loader.js +4 -0
- package/esdev/templates/app/_option/render/mixed+language/ts/app/_config.ts +6 -0
- package/esdev/templates/app/_option/render/mixed+language/ts/app/about/_config.ts +4 -0
- package/esdev/templates/app/_option/render/mixed+language/ts/app/dashboard/_config.ts +5 -0
- package/esdev/templates/app/_option/render/mixed+language/ts/app/dashboard/loader.ts +4 -0
- package/esdev/templates/app/_option/render/mixed+server/yes/esdev.json +28 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/css+language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/css+language/js/app/layout.jsx +15 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/css+language/js/package.json +19 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/css+language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/css+language/ts/app/layout.tsx +15 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/css+language/ts/package.json +21 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/tailwind+language/js/README.md +16 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/tailwind+language/js/app/layout.jsx +15 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/tailwind+language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/tailwind+language/ts/README.md +17 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/tailwind+language/ts/app/layout.tsx +15 -0
- package/esdev/templates/app/_option/render/mixed+server/yes+styling/tailwind+language/ts/package.json +22 -0
- package/esdev/templates/app/_option/render/mixed+styling/css+language/js/app/dashboard/page.jsx +13 -0
- package/esdev/templates/app/_option/render/mixed+styling/css+language/ts/app/dashboard/page.tsx +13 -0
- package/esdev/templates/app/_option/render/mixed+styling/tailwind+language/js/app/dashboard/page.jsx +13 -0
- package/esdev/templates/app/_option/render/mixed+styling/tailwind+language/ts/app/dashboard/page.tsx +13 -0
- package/esdev/templates/app/_option/render/server+language/js/app/_config.js +6 -0
- package/esdev/templates/app/_option/render/server+language/ts/app/_config.ts +6 -0
- package/esdev/templates/app/_option/render/server+server/yes/esdev.json +28 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/css+language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/css+language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/css+language/js/package.json +19 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/css+language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/css+language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/css+language/ts/package.json +21 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/tailwind+language/js/README.md +16 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/tailwind+language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/tailwind+language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/tailwind+language/ts/README.md +17 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/tailwind+language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/server+server/yes+styling/tailwind+language/ts/package.json +22 -0
- package/esdev/templates/app/_option/render/static+language/js/app/_config.js +6 -0
- package/esdev/templates/app/_option/render/static+language/ts/app/_config.ts +6 -0
- package/esdev/templates/app/_option/render/static+server/no/esdev.json +32 -0
- package/esdev/templates/app/_option/render/static+server/no/ssg.js +131 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/css+language/js/README.md +14 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/css+language/js/app/layout.jsx +13 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/css+language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/css+language/ts/README.md +15 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/css+language/ts/app/layout.tsx +13 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/css+language/ts/package.json +22 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/tailwind+language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/tailwind+language/js/app/layout.jsx +13 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/tailwind+language/js/package.json +21 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/tailwind+language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/tailwind+language/ts/app/layout.tsx +13 -0
- package/esdev/templates/app/_option/render/static+server/no+styling/tailwind+language/ts/package.json +23 -0
- package/esdev/templates/app/_option/render/static+server/yes/esdev.json +28 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/css+language/js/README.md +15 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/css+language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/css+language/js/package.json +19 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/css+language/ts/README.md +16 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/css+language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/css+language/ts/package.json +21 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/tailwind+language/js/README.md +16 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/tailwind+language/js/app/layout.jsx +14 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/tailwind+language/js/package.json +20 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/tailwind+language/ts/README.md +17 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/tailwind+language/ts/app/layout.tsx +14 -0
- package/esdev/templates/app/_option/render/static+server/yes+styling/tailwind+language/ts/package.json +22 -0
- package/esdev/templates/app/_option/server/yes/server.js +52 -0
- package/esdev/templates/app/_option/server/yes+language/js/app/_middleware.js +9 -0
- package/esdev/templates/app/_option/server/yes+language/js/app/api/hello/route.js +4 -0
- package/esdev/templates/app/_option/server/yes+language/js/app/todos/loader.js +7 -0
- package/esdev/templates/app/_option/server/yes+language/js/app/todos/todos.server.js +15 -0
- package/esdev/templates/app/_option/server/yes+language/js/tests/server/api.test.js +8 -0
- package/esdev/templates/app/_option/server/yes+language/ts/app/_middleware.ts +9 -0
- package/esdev/templates/app/_option/server/yes+language/ts/app/api/hello/route.ts +4 -0
- package/esdev/templates/app/_option/server/yes+language/ts/app/todos/loader.ts +7 -0
- package/esdev/templates/app/_option/server/yes+language/ts/app/todos/todos.server.ts +15 -0
- package/esdev/templates/app/_option/server/yes+language/ts/tests/server/api.test.ts +8 -0
- package/esdev/templates/app/_option/server/yes+styling/css+language/js/app/todos/page.jsx +29 -0
- package/esdev/templates/app/_option/server/yes+styling/css+language/ts/app/todos/page.tsx +29 -0
- package/esdev/templates/app/_option/server/yes+styling/tailwind+language/js/app/todos/page.jsx +29 -0
- package/esdev/templates/app/_option/server/yes+styling/tailwind+language/ts/app/todos/page.tsx +29 -0
- package/esdev/templates/app/_option/styling/css/app/global.css +16 -0
- package/esdev/templates/app/_option/styling/css+language/js/app/Counter.jsx +10 -0
- package/esdev/templates/app/_option/styling/css+language/js/app/page.jsx +13 -0
- package/esdev/templates/app/_option/styling/css+language/ts/app/Counter.tsx +10 -0
- package/esdev/templates/app/_option/styling/css+language/ts/app/page.tsx +13 -0
- package/esdev/templates/app/_option/styling/tailwind/app/global.css +7 -0
- package/esdev/templates/app/_option/styling/tailwind+language/js/app/Counter.jsx +10 -0
- package/esdev/templates/app/_option/styling/tailwind+language/js/app/page.jsx +13 -0
- package/esdev/templates/app/_option/styling/tailwind+language/ts/app/Counter.tsx +10 -0
- package/esdev/templates/app/_option/styling/tailwind+language/ts/app/page.tsx +13 -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/afw.config.js +13 -0
- package/esdev/templates/docs/_option/blog/no+language/js/README.md +14 -0
- package/esdev/templates/docs/_option/blog/no+language/js/app/page.jsx +15 -0
- package/esdev/templates/docs/_option/blog/no+language/js/tests/ui/Home.test.js +9 -0
- package/esdev/templates/docs/_option/blog/no+language/ts/README.md +15 -0
- package/esdev/templates/docs/_option/blog/no+language/ts/app/page.tsx +15 -0
- package/esdev/templates/docs/_option/blog/no+language/ts/tests/ui/Home.test.ts +9 -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/blog/yes+language/js/README.md +14 -0
- package/esdev/templates/docs/_option/blog/yes+language/js/app/blog/layout.jsx +7 -0
- package/esdev/templates/docs/_option/blog/yes+language/js/app/blog/page.jsx +13 -0
- package/esdev/templates/docs/_option/blog/yes+language/js/app/page.jsx +15 -0
- package/esdev/templates/docs/_option/blog/yes+language/js/tests/ui/Home.test.js +10 -0
- package/esdev/templates/docs/_option/blog/yes+language/ts/README.md +15 -0
- package/esdev/templates/docs/_option/blog/yes+language/ts/app/blog/layout.tsx +7 -0
- package/esdev/templates/docs/_option/blog/yes+language/ts/app/blog/page.tsx +13 -0
- package/esdev/templates/docs/_option/blog/yes+language/ts/app/page.tsx +15 -0
- package/esdev/templates/docs/_option/blog/yes+language/ts/tests/ui/Home.test.ts +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 +32 -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 +32 -0
- package/esdev/templates/library/_option/styling/css/app/global.css +16 -0
- package/esdev/templates/library/_option/styling/css+language/js/README.md +12 -0
- package/esdev/templates/library/_option/styling/css+language/js/app/page.jsx +10 -0
- package/esdev/templates/library/_option/styling/css+language/js/package.json +26 -0
- package/esdev/templates/library/_option/styling/css+language/js/src/Counter.jsx +10 -0
- package/esdev/templates/library/_option/styling/css+language/ts/README.md +13 -0
- package/esdev/templates/library/_option/styling/css+language/ts/app/page.tsx +10 -0
- package/esdev/templates/library/_option/styling/css+language/ts/package.json +28 -0
- package/esdev/templates/library/_option/styling/css+language/ts/src/Counter.tsx +10 -0
- package/esdev/templates/library/_option/styling/tailwind/app/global.css +7 -0
- package/esdev/templates/library/_option/styling/tailwind+language/js/README.md +13 -0
- package/esdev/templates/library/_option/styling/tailwind+language/js/app/page.jsx +10 -0
- package/esdev/templates/library/_option/styling/tailwind+language/js/package.json +27 -0
- package/esdev/templates/library/_option/styling/tailwind+language/js/src/Counter.jsx +10 -0
- package/esdev/templates/library/_option/styling/tailwind+language/ts/README.md +14 -0
- package/esdev/templates/library/_option/styling/tailwind+language/ts/app/page.tsx +10 -0
- package/esdev/templates/library/_option/styling/tailwind+language/ts/package.json +29 -0
- package/esdev/templates/library/_option/styling/tailwind+language/ts/src/Counter.tsx +10 -0
- package/esdev/templates/library/esdev.json +18 -0
- package/esdev/templates/library/template.json +44 -0
- package/index.js +28 -13
- package/package.json +14 -9
- package/templates.js +300 -101
- package/versions.json +4 -4
package/templates.js
CHANGED
|
@@ -1,34 +1,52 @@
|
|
|
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
|
-
//
|
|
7
|
-
//
|
|
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.
|
|
12
|
+
// docs — an afw-docs site: MDX docs, prerendered, with search; a blog with feeds
|
|
13
|
+
// only when asked for.
|
|
8
14
|
// library — a package of components published as JSX source, with a dev preview.
|
|
9
15
|
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
|
|
10
18
|
import { escapeHTML } from "@opentf/std";
|
|
11
19
|
|
|
12
20
|
export const TEMPLATES = {
|
|
13
21
|
app: "An app: choose how pages render and whether it has a server",
|
|
14
|
-
docs: "A documentation site with
|
|
22
|
+
docs: "A documentation site with search, and optionally a blog (afw-docs)",
|
|
15
23
|
library: "A component library published as JSX source",
|
|
16
24
|
};
|
|
17
25
|
|
|
26
|
+
/** How an app's pages render by default (`app/_config.js`); any folder can override it. */
|
|
18
27
|
export const RENDERINGS = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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",
|
|
22
32
|
};
|
|
23
33
|
|
|
34
|
+
/** The rendering names of earlier releases, kept as shorthands. */
|
|
35
|
+
export const RENDER_ALIASES = { spa: "client", ssr: "server", ssg: "static" };
|
|
36
|
+
|
|
37
|
+
/** Renderings that always have a server. */
|
|
38
|
+
export const SERVER_RENDERINGS = new Set(["server", "mixed"]);
|
|
39
|
+
|
|
40
|
+
export const TOOLCHAINS = { vite: "Vite + Node", esdev: "esdev + ES-Runtime" };
|
|
41
|
+
|
|
24
42
|
export const STYLINGS = { css: "CSS", tailwind: "Tailwind CSS" };
|
|
25
43
|
|
|
26
44
|
/** The template names of earlier releases, kept as shorthands. */
|
|
27
45
|
export const LEGACY_TEMPLATES = {
|
|
28
|
-
spa: { template: "app", render: "
|
|
29
|
-
fullstack: { template: "app", render: "
|
|
30
|
-
ssr: { template: "app", render: "
|
|
31
|
-
ssg: { template: "app", render: "
|
|
46
|
+
spa: { template: "app", render: "client", server: false },
|
|
47
|
+
fullstack: { template: "app", render: "client", server: true },
|
|
48
|
+
ssr: { template: "app", render: "server", server: true },
|
|
49
|
+
ssg: { template: "app", render: "static", server: false },
|
|
32
50
|
};
|
|
33
51
|
|
|
34
52
|
// The third-party tools a new project starts on. AFW's own packages take the
|
|
@@ -45,20 +63,30 @@ export const TOOL_VERSIONS = {
|
|
|
45
63
|
/**
|
|
46
64
|
* The files of a new project, as `{ relativePath: contents }`.
|
|
47
65
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
66
|
+
* `toolchain` picks the workflow's own files (`vite`, the default, or `esdev`); `pm` is the
|
|
67
|
+
* package manager the README names. `versions` maps each package (AFW's, and any tool
|
|
68
|
+
* in it) to the version to write; a tool it leaves out takes `TOOL_VERSIONS`.
|
|
69
|
+
*
|
|
70
|
+
* @param {{ name: string, template: keyof TEMPLATES, render?: string, server?: boolean,
|
|
71
|
+
* styling?: keyof STYLINGS, typescript: boolean, versions: Record<string, string>,
|
|
72
|
+
* toolchain?: keyof TOOLCHAINS, pm?: string, blog?: boolean }} options
|
|
50
73
|
*/
|
|
51
|
-
export function projectFiles({
|
|
74
|
+
export function projectFiles({
|
|
75
|
+
name, template, render = "client", server = false, blog = false, styling = "css", typescript, versions,
|
|
76
|
+
toolchain = "vite", pm = "npm",
|
|
77
|
+
}) {
|
|
52
78
|
if (!TEMPLATES[template]) throw new Error(`Unknown template "${template}". Choose one of: ${Object.keys(TEMPLATES).join(", ")}`);
|
|
79
|
+
render = RENDER_ALIASES[render] ?? render;
|
|
53
80
|
if (!RENDERINGS[render]) throw new Error(`Unknown rendering "${render}". Choose one of: ${Object.keys(RENDERINGS).join(", ")}`);
|
|
54
81
|
if (!STYLINGS[styling]) throw new Error(`Unknown styling "${styling}". Choose one of: ${Object.keys(STYLINGS).join(", ")}`);
|
|
82
|
+
if (!TOOLCHAINS[toolchain]) throw new Error(`Unknown toolchain "${toolchain}". Choose one of: ${Object.keys(TOOLCHAINS).join(", ")}`);
|
|
55
83
|
const ctx = {
|
|
56
84
|
name, versions, ts: typescript, js: typescript ? "ts" : "js", jsx: typescript ? "tsx" : "jsx",
|
|
57
|
-
tailwind: styling === "tailwind",
|
|
85
|
+
tailwind: styling === "tailwind", toolchain, esdev: toolchain === "esdev", pm,
|
|
58
86
|
};
|
|
59
|
-
if (template === "docs") return docsFiles(ctx);
|
|
87
|
+
if (template === "docs") return docsFiles({ ...ctx, blog });
|
|
60
88
|
if (template === "library") return libraryFiles(ctx);
|
|
61
|
-
return appFiles({ ...ctx, render, server: render
|
|
89
|
+
return appFiles({ ...ctx, render, server: SERVER_RENDERINGS.has(render) || server });
|
|
62
90
|
}
|
|
63
91
|
|
|
64
92
|
// ---------------------------------------------------------------------------- shared
|
|
@@ -68,19 +96,53 @@ const escapeJs = (text) => String(text).replace(/[\\"]/g, "\\$&");
|
|
|
68
96
|
// ` class="…"` with Tailwind, nothing with plain CSS.
|
|
69
97
|
const tw = (ctx, classes) => (ctx.tailwind ? ` class="${classes}"` : "");
|
|
70
98
|
|
|
99
|
+
/** The version to write for `pkg`: from `versions`, else the tool's default range. */
|
|
100
|
+
const version = (ctx, pkg) => ctx.versions[pkg] ?? TOOL_VERSIONS[pkg];
|
|
101
|
+
|
|
71
102
|
function devDependencies(ctx, extra = {}) {
|
|
103
|
+
const v = (pkg) => version(ctx, pkg);
|
|
104
|
+
if (ctx.esdev) {
|
|
105
|
+
return sortKeys({
|
|
106
|
+
"@opentf/afw-test": v("@opentf/afw-test"),
|
|
107
|
+
"@opentf/esdev-plugin-afw": v("@opentf/esdev-plugin-afw"),
|
|
108
|
+
"@opentf/esrun-types": v("@opentf/esrun-types"),
|
|
109
|
+
...(ctx.ts ? { typescript: v("typescript") } : {}),
|
|
110
|
+
...(ctx.tailwind ? { tailwindcss: v("tailwindcss") } : {}),
|
|
111
|
+
...extra,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
72
114
|
return sortKeys({
|
|
73
|
-
"@opentf/afw-test":
|
|
74
|
-
"@opentf/vite-plugin-afw":
|
|
75
|
-
"happy-dom":
|
|
76
|
-
...(ctx.ts ? { typescript:
|
|
77
|
-
...(ctx.tailwind ? { tailwindcss:
|
|
78
|
-
vite:
|
|
79
|
-
vitest:
|
|
115
|
+
"@opentf/afw-test": v("@opentf/afw-test"),
|
|
116
|
+
"@opentf/vite-plugin-afw": v("@opentf/vite-plugin-afw"),
|
|
117
|
+
"happy-dom": v("happy-dom"),
|
|
118
|
+
...(ctx.ts ? { typescript: v("typescript") } : {}),
|
|
119
|
+
...(ctx.tailwind ? { tailwindcss: v("tailwindcss"), "@tailwindcss/vite": v("@tailwindcss/vite") } : {}),
|
|
120
|
+
vite: v("vite"),
|
|
121
|
+
vitest: v("vitest"),
|
|
80
122
|
...extra,
|
|
81
123
|
});
|
|
82
124
|
}
|
|
83
125
|
|
|
126
|
+
// esdev's own files: read from toolchain/esdev/ when an esdev project is generated.
|
|
127
|
+
const esdevFile = (name) => readFileSync(new URL(`./toolchain/esdev/${name}`, import.meta.url), "utf8");
|
|
128
|
+
|
|
129
|
+
/** esdev.json for a project: the AFW plugin (+ `plugins`), the web target and `targets`. */
|
|
130
|
+
function esdevConfig(ctx, { plugins = [], targets = {}, dev = null, afw = { appDir: "app" } } = {}) {
|
|
131
|
+
return json({
|
|
132
|
+
plugins: [{ module: "@opentf/esdev-plugin-afw", options: afw }, ...plugins],
|
|
133
|
+
build: { targets: { web: { entry: "index.html", outdir: "dist" }, ...targets } },
|
|
134
|
+
...(dev ? { dev } : {}),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The prerender step of a static esdev site: `ssg.js` run after the build. */
|
|
139
|
+
const ESDEV_SSG_TARGET = { "site-ssg": { entry: "ssg.js", out: ".ssg/ssg.js", then: "run" } };
|
|
140
|
+
const ESDEV_SITE_OUTPUT = { module: "@opentf/afw-cli/ssg", export: "siteOutputPlugin", options: { root: ".", target: "web", prerenderTarget: "site-ssg" } };
|
|
141
|
+
const ESDEV_SERVER = {
|
|
142
|
+
targets: { server: { entry: "server.js", out: "dist/server.js" } },
|
|
143
|
+
dev: { run: "server", app: { port: 3000 } },
|
|
144
|
+
};
|
|
145
|
+
|
|
84
146
|
function sortKeys(object) {
|
|
85
147
|
return Object.fromEntries(Object.entries(object).sort(([a], [b]) => a.localeCompare(b)));
|
|
86
148
|
}
|
|
@@ -114,7 +176,10 @@ function tsconfig(ctx, include, { allowJs = false } = {}) {
|
|
|
114
176
|
lib: ["ESNext", "DOM", "DOM.Iterable"],
|
|
115
177
|
jsx: "preserve",
|
|
116
178
|
jsxImportSource: "@opentf/afw",
|
|
117
|
-
|
|
179
|
+
// esdev: the runtime's types, and the `esdev` condition `@opentf/afw-test/test` uses.
|
|
180
|
+
...(ctx.esdev
|
|
181
|
+
? { types: ["@opentf/esrun-types"], customConditions: ["esdev"] }
|
|
182
|
+
: { types: ["@opentf/vite-plugin-afw/client"] }),
|
|
118
183
|
strict: true,
|
|
119
184
|
noEmit: true,
|
|
120
185
|
isolatedModules: true,
|
|
@@ -132,11 +197,11 @@ function indexHtml(ctx, { title, css = true }) {
|
|
|
132
197
|
<head>
|
|
133
198
|
<meta charset="utf-8" />
|
|
134
199
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
135
|
-
<title>${escapeHTML(title)}</title>${css ? `\n <link rel="stylesheet" href="/app/global.css" />` : ""}
|
|
200
|
+
<title>${escapeHTML(title)}</title>${css ? `\n <link rel="stylesheet" href="${ctx.esdev ? "./" : "/"}app/global.css" />` : ""}
|
|
136
201
|
</head>
|
|
137
202
|
<body>
|
|
138
203
|
<div id="app"></div>
|
|
139
|
-
<script type="module" src="/entry.${ctx.js}"></script>
|
|
204
|
+
<script type="module" src="${ctx.esdev ? "./" : "/"}entry.${ctx.js}"></script>
|
|
140
205
|
</body>
|
|
141
206
|
</html>
|
|
142
207
|
`;
|
|
@@ -194,10 +259,12 @@ function counter(ctx) {
|
|
|
194
259
|
`;
|
|
195
260
|
}
|
|
196
261
|
|
|
262
|
+
// Tests import the test API from `@opentf/afw-test/test`: Vitest under Vite,
|
|
263
|
+
// `runtime:test` under esdev, so the same files run in both workflows.
|
|
197
264
|
function counterTest(ctx, from) {
|
|
198
|
-
return `import { expect, test } from "
|
|
265
|
+
return `import { expect, test } from "@opentf/afw-test/test";
|
|
199
266
|
import { render, userEvent } from "@opentf/afw-test";
|
|
200
|
-
import ${from.
|
|
267
|
+
import ${from.includes("/index.") ? "{ Counter }" : "Counter"} from "${from}";
|
|
201
268
|
|
|
202
269
|
test("counts clicks", async () => {
|
|
203
270
|
const { getByRole, getByText } = render(Counter, { start: 1 });
|
|
@@ -220,46 +287,104 @@ ${rows}
|
|
|
220
287
|
${notes.length ? `\n${notes.map((note) => `- ${note}`).join("\n")}\n` : ""}`;
|
|
221
288
|
}
|
|
222
289
|
|
|
223
|
-
|
|
290
|
+
// The DOM tests (`tests/ui/`) run with a DOM; server tests (`tests/server/`) run as
|
|
291
|
+
// server code, where `*.server.js` imports are the real functions.
|
|
292
|
+
const ESDEV_UI_TESTS = "esdev test --dom --setup=@opentf/afw-test/setup tests/ui";
|
|
293
|
+
|
|
294
|
+
function testScript(ctx, { server = false } = {}) {
|
|
295
|
+
if (!ctx.esdev) return "vitest run";
|
|
296
|
+
return server ? `esdev test tests/server && ${ESDEV_UI_TESTS}` : ESDEV_UI_TESTS;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function scripts(ctx, { server, client = false }) {
|
|
300
|
+
if (ctx.esdev) {
|
|
301
|
+
return {
|
|
302
|
+
dev: "esdev start",
|
|
303
|
+
build: "esdev build",
|
|
304
|
+
...(server
|
|
305
|
+
? { start: "esrun --allow-read --allow-net --allow-listen=3000 --allow-env=PORT --allow-imports dist/server.js" }
|
|
306
|
+
: { preview: client ? "esdev preview --spa" : "esdev preview" }),
|
|
307
|
+
test: testScript(ctx, { server }),
|
|
308
|
+
...(ctx.ts ? { typecheck: "esdev typecheck" } : {}),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
224
311
|
return {
|
|
225
312
|
dev: "vite",
|
|
226
313
|
build: "vite build",
|
|
227
314
|
...(server ? { start: "node dist/server/index.js" } : { preview: "vite preview" }),
|
|
228
|
-
test:
|
|
315
|
+
test: testScript(ctx),
|
|
229
316
|
...(ctx.ts ? { typecheck: "tsc" } : {}),
|
|
230
317
|
};
|
|
231
318
|
}
|
|
232
319
|
|
|
320
|
+
const runner = (ctx) => (ctx.esdev ? "esdev" : "Vitest");
|
|
321
|
+
|
|
233
322
|
function commandRows(ctx, { server }) {
|
|
323
|
+
const pm = ctx.pm;
|
|
234
324
|
return [
|
|
235
|
-
[
|
|
236
|
-
[
|
|
237
|
-
server
|
|
238
|
-
|
|
239
|
-
|
|
325
|
+
[`${pm} run dev`, "Start the dev server"],
|
|
326
|
+
[`${pm} run build`, "Build for production"],
|
|
327
|
+
server
|
|
328
|
+
? [`${pm} run start`, ctx.esdev ? "Run the built server on ES-Runtime (`PORT`)" : "Run the built Node server (`PORT`, `HOST`)"]
|
|
329
|
+
: [`${pm} run preview`, "Preview the production build"],
|
|
330
|
+
[`${pm} run test`, `Run the tests with ${runner(ctx)}`],
|
|
331
|
+
...(ctx.ts ? [[`${pm} run typecheck`, "Check types"]] : []),
|
|
240
332
|
];
|
|
241
333
|
}
|
|
242
334
|
|
|
335
|
+
const gitignore = (ctx) => (ctx.esdev ? esdevFile("gitignore") : "node_modules\ndist\n");
|
|
336
|
+
|
|
337
|
+
/** The toolchain's own config files for a project (`vite.config.*`, or `esdev.json` & co). */
|
|
338
|
+
const jsconfig = () => json({ compilerOptions: { jsx: "preserve", jsxImportSource: "@opentf/afw" } });
|
|
339
|
+
|
|
340
|
+
const onToolchain = (ctx) => (ctx.esdev ? "esdev and ES-Runtime" : "Vite");
|
|
341
|
+
|
|
243
342
|
// ---------------------------------------------------------------------------- app
|
|
244
343
|
|
|
344
|
+
/** `app/_config.*`: how the pages of a folder (and the folders below it) render. */
|
|
345
|
+
function routeConfig(ctx, render, comment) {
|
|
346
|
+
return `import { defineRoute } from "@opentf/afw";
|
|
347
|
+
|
|
348
|
+
${comment}
|
|
349
|
+
export default defineRoute({ render: "${render}" });
|
|
350
|
+
`;
|
|
351
|
+
}
|
|
352
|
+
|
|
245
353
|
function appFiles(ctx) {
|
|
246
354
|
const { ts, js, jsx, render, server } = ctx;
|
|
355
|
+
const mixed = render === "mixed";
|
|
356
|
+
const appDefault = mixed ? "server" : render;
|
|
247
357
|
const files = {};
|
|
248
358
|
files["package.json"] = json({
|
|
249
|
-
name: ctx.name, private: true, type: "module", scripts: scripts(ctx, { server }),
|
|
250
|
-
dependencies: { "@opentf/afw": ctx
|
|
251
|
-
devDependencies: devDependencies(ctx),
|
|
359
|
+
name: ctx.name, private: true, type: "module", scripts: scripts(ctx, { server, client: render === "client" }),
|
|
360
|
+
dependencies: { "@opentf/afw": version(ctx, "@opentf/afw") },
|
|
361
|
+
devDependencies: devDependencies(ctx, ctx.esdev && render === "static" && !server ? { "@opentf/afw-cli": version(ctx, "@opentf/afw-cli") } : {}),
|
|
252
362
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
363
|
+
if (ctx.esdev) {
|
|
364
|
+
// A static site without a server prerenders in a step after the build; a server
|
|
365
|
+
// renders (and serves prebuilt) pages itself.
|
|
366
|
+
const site = render === "static" && !server;
|
|
367
|
+
files["esdev.json"] = esdevConfig(ctx, {
|
|
368
|
+
plugins: site ? [ESDEV_SITE_OUTPUT] : [],
|
|
369
|
+
targets: { ...(server ? ESDEV_SERVER.targets : {}), ...(site ? ESDEV_SSG_TARGET : {}) },
|
|
370
|
+
dev: server ? ESDEV_SERVER.dev : null,
|
|
371
|
+
});
|
|
372
|
+
if (server) files["server.js"] = esdevFile("server.js");
|
|
373
|
+
if (site) files["ssg.js"] = esdevFile("ssg.js");
|
|
374
|
+
if (!ts) files["jsconfig.json"] = jsconfig();
|
|
375
|
+
} else {
|
|
376
|
+
const options = render === "static" ? `{ baseUrl: "" /* your site URL, e.g. "https://example.com", enables sitemap.xml */ }` : "";
|
|
377
|
+
files[`vite.config.${js}`] = viteConfig(ctx, { plugins: [`afw(${options})`] });
|
|
378
|
+
}
|
|
379
|
+
if (ts) files["tsconfig.json"] = tsconfig(ctx, ctx.esdev ? ["app", "tests", "entry.ts"] : ["app", "tests", "entry.ts", "vite.config.ts"]);
|
|
258
380
|
files["index.html"] = indexHtml(ctx, { title: ctx.name });
|
|
259
381
|
files[`entry.${js}`] = entry(ctx);
|
|
260
382
|
files["app/global.css"] = globalCss(ctx);
|
|
383
|
+
files[`app/_config.${js}`] = routeConfig(ctx, appDefault, `// How the pages in app/ render: "server" (per request), "static" (once, at build time) or
|
|
384
|
+
// "client" (in the browser). A folder's own _config.${js} sets it for that folder and
|
|
385
|
+
// the folders below it; the nearest one wins.`);
|
|
261
386
|
|
|
262
|
-
const navLinks = [["/", "Home"], ["/about", "About"], ...(server ? [["/todos", "Todos"]] : [])];
|
|
387
|
+
const navLinks = [["/", "Home"], ["/about", "About"], ...(server ? [["/todos", "Todos"]] : []), ...(mixed ? [["/dashboard", "Dashboard"]] : [])];
|
|
263
388
|
files[`app/layout.${jsx}`] = `import { Link } from "@opentf/afw";
|
|
264
389
|
|
|
265
390
|
export default function Layout({ children }${ts ? ": { children: unknown }" : ""}) {
|
|
@@ -296,16 +421,25 @@ title: About
|
|
|
296
421
|
|
|
297
422
|
This page is Markdown. The AFW compiler turns it into a page like any other.
|
|
298
423
|
`;
|
|
424
|
+
if (mixed) Object.assign(files, mixedFiles(ctx));
|
|
299
425
|
if (server) Object.assign(files, serverFiles(ctx));
|
|
300
|
-
files[`tests/Counter.test.${js}`] = counterTest(ctx,
|
|
301
|
-
files[".gitignore"] =
|
|
302
|
-
|
|
303
|
-
const how = {
|
|
426
|
+
files[`tests/ui/Counter.test.${js}`] = counterTest(ctx, `../../app/Counter.${jsx}`);
|
|
427
|
+
files[".gitignore"] = gitignore(ctx);
|
|
428
|
+
|
|
429
|
+
const how = {
|
|
430
|
+
client: "rendered in the browser",
|
|
431
|
+
server: "rendered on the server per request",
|
|
432
|
+
static: "prerendered to static HTML",
|
|
433
|
+
mixed: "rendered on the server by default, with a prebuilt page (`/about`) and a section rendered in the browser (`/dashboard`)",
|
|
434
|
+
}[render];
|
|
435
|
+
const host = ctx.esdev ? "ES-Runtime" : "Node";
|
|
304
436
|
files["README.md"] = readme(ctx, {
|
|
305
|
-
summary: `An [AFW](https://afw.opentechf.org) app on
|
|
437
|
+
summary: `An [AFW](https://afw.opentechf.org) app on ${onToolchain(ctx)}: pages ${how}${server ? `, with a server on ${host}` : ""}.`,
|
|
306
438
|
commands: commandRows(ctx, { server }),
|
|
307
439
|
notes: [
|
|
308
440
|
`Pages live in \`app/\`: \`app/about/page.md\` is served at \`/about\`.`,
|
|
441
|
+
`\`app/_config.${js}\` sets how pages render (\`server\`, \`static\` or \`client\`); a folder's own \`_config.${js}\` changes it for that folder.`,
|
|
442
|
+
`Component tests live in \`tests/ui/\`${server ? ", server tests (API routes, loaders) in `tests/server/`" : ""}.`,
|
|
309
443
|
...(server ? [
|
|
310
444
|
`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.`,
|
|
311
445
|
] : []),
|
|
@@ -315,9 +449,47 @@ This page is Markdown. The AFW compiler turns it into a page like any other.
|
|
|
315
449
|
return files;
|
|
316
450
|
}
|
|
317
451
|
|
|
452
|
+
/** The mixed app's examples: a prebuilt page and a section rendered in the browser. */
|
|
453
|
+
function mixedFiles(ctx) {
|
|
454
|
+
const { ts, js, jsx } = ctx;
|
|
455
|
+
const files = {};
|
|
456
|
+
files[`app/about/_config.${js}`] = routeConfig(ctx, "static", "// Built once at build time; the rest of the app renders per request.");
|
|
457
|
+
files[`app/dashboard/_config.${js}`] = routeConfig(ctx, "client", `// Rendered in the browser: the server sends the layout and this folder's loader data,
|
|
458
|
+
// and never loads its pages, so they may use browser-only code.`);
|
|
459
|
+
files[`app/dashboard/loader.${js}`] = `// Still runs on the server: a client page gets its data with the page.
|
|
460
|
+
export default function loader() {
|
|
461
|
+
return { visits: 42 };
|
|
462
|
+
}
|
|
463
|
+
`;
|
|
464
|
+
files[`app/dashboard/page.${jsx}`] = `import { router } from "@opentf/afw";
|
|
465
|
+
|
|
466
|
+
export const metadata = { title: "Dashboard" };
|
|
467
|
+
|
|
468
|
+
export default function Dashboard() {
|
|
469
|
+
const visits = $derived(${ts ? "(router.data as { visits?: number } | undefined)" : "router.data"}?.visits ?? 0);
|
|
470
|
+
return (
|
|
471
|
+
<section>
|
|
472
|
+
<h1${tw(ctx, "mb-4 text-2xl font-bold")}>Dashboard</h1>
|
|
473
|
+
<p>Rendered in your browser, {visits} visits. Browser-only code is safe here.</p>
|
|
474
|
+
</section>
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
`;
|
|
478
|
+
return files;
|
|
479
|
+
}
|
|
480
|
+
|
|
318
481
|
function serverFiles(ctx) {
|
|
319
482
|
const { ts, js, jsx } = ctx;
|
|
320
483
|
const files = {};
|
|
484
|
+
files[`tests/server/api.test.${js}`] = `import { expect, test } from "@opentf/afw-test/test";
|
|
485
|
+
import { GET } from "../../app/api/hello/route.${js}";
|
|
486
|
+
|
|
487
|
+
test("GET /api/hello greets by name", async () => {
|
|
488
|
+
const response = GET(new Request("http://localhost/api/hello?name=AFW"), { query: { name: "AFW" }, locals: { requestId: "r1" } });
|
|
489
|
+
expect(response.status).toBe(200);
|
|
490
|
+
expect(await response.json()).toEqual({ message: "Hello, AFW!", requestId: "r1" });
|
|
491
|
+
});
|
|
492
|
+
`;
|
|
321
493
|
files[`app/api/hello/route.${js}`] = `// GET /api/hello?name=… — API routes run on Node, so any npm package works here.
|
|
322
494
|
export function GET(request${ts ? ": Request" : ""}, { query, locals }${ts ? ": { query: Record<string, string>; locals: Record<string, unknown> }" : ""}) {
|
|
323
495
|
return Response.json({ message: \`Hello, \${query.name ?? "world"}!\`, requestId: locals.requestId });
|
|
@@ -393,32 +565,42 @@ export default function Todos() {
|
|
|
393
565
|
// ---------------------------------------------------------------------------- docs
|
|
394
566
|
|
|
395
567
|
function docsFiles(ctx) {
|
|
396
|
-
const { ts, js, jsx } = ctx;
|
|
568
|
+
const { ts, js, jsx, blog } = ctx;
|
|
397
569
|
const files = {};
|
|
398
570
|
files["package.json"] = json({
|
|
399
571
|
name: ctx.name, private: true, type: "module", scripts: scripts(ctx, { server: false }),
|
|
400
|
-
dependencies: { "@opentf/afw": ctx
|
|
401
|
-
devDependencies: devDependencies({ ...ctx, tailwind: false }),
|
|
402
|
-
});
|
|
403
|
-
files[`vite.config.${js}`] = viteConfig({ ...ctx, tailwind: false }, {
|
|
404
|
-
imports: [`import afwDocs from "@opentf/afw-docs/vite";`],
|
|
405
|
-
plugins: [`afw({ mode: "ssg" })`, "afwDocs()"],
|
|
572
|
+
dependencies: { "@opentf/afw": version(ctx, "@opentf/afw"), "@opentf/afw-docs": version(ctx, "@opentf/afw-docs") },
|
|
573
|
+
devDependencies: devDependencies({ ...ctx, tailwind: false }, ctx.esdev ? { "@opentf/afw-cli": version(ctx, "@opentf/afw-cli") } : {}),
|
|
406
574
|
});
|
|
407
|
-
if (
|
|
575
|
+
if (ctx.esdev) {
|
|
576
|
+
files["esdev.json"] = esdevConfig(ctx, {
|
|
577
|
+
plugins: [{ module: "@opentf/afw-docs/build", export: "afwDocsPlugin", options: { appDir: "app" } }, ESDEV_SITE_OUTPUT],
|
|
578
|
+
targets: ESDEV_SSG_TARGET,
|
|
579
|
+
});
|
|
580
|
+
files["ssg.js"] = esdevFile("ssg.js");
|
|
581
|
+
if (!ts) files["jsconfig.json"] = jsconfig();
|
|
582
|
+
} else {
|
|
583
|
+
files[`vite.config.${js}`] = viteConfig({ ...ctx, tailwind: false }, {
|
|
584
|
+
imports: [`import afwDocs from "@opentf/afw-docs/vite";`],
|
|
585
|
+
plugins: ["afw()", "afwDocs()"],
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
files[`app/_config.${js}`] = routeConfig(ctx, "static", "// The site is prerendered: every page is built once, at build time.");
|
|
589
|
+
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 });
|
|
408
590
|
files["afw.config.js"] = `import { defineDocsConfig } from "@opentf/afw-docs/config";
|
|
409
591
|
|
|
410
592
|
export default defineDocsConfig({
|
|
411
|
-
// Your site's URL: canonical links, sitemap.xml, feeds and llms.txt use it.
|
|
593
|
+
// Your site's URL: canonical links, sitemap.xml${blog ? ", feeds" : ""} and llms.txt use it.
|
|
412
594
|
site: { url: "https://example.com" },
|
|
413
595
|
docs: {
|
|
414
596
|
title: "${escapeJs(ctx.name)}",
|
|
415
597
|
nav: [
|
|
416
|
-
{ label: "Docs", href: "/docs" }
|
|
417
|
-
{ label: "Blog", href: "/blog" }
|
|
598
|
+
{ label: "Docs", href: "/docs" },${blog ? `
|
|
599
|
+
{ label: "Blog", href: "/blog" },` : ""}
|
|
418
600
|
],
|
|
419
601
|
search: { provider: "afw" },
|
|
420
|
-
}
|
|
421
|
-
blog: { dir: "blog", title: "${escapeJs(ctx.name)} Blog" }
|
|
602
|
+
},${blog ? `
|
|
603
|
+
blog: { dir: "blog", title: "${escapeJs(ctx.name)} Blog" },` : ""}
|
|
422
604
|
});
|
|
423
605
|
`;
|
|
424
606
|
files["index.html"] = indexHtml(ctx, { title: ctx.name, css: false });
|
|
@@ -431,15 +613,15 @@ export default defineDocsConfig({
|
|
|
431
613
|
`;
|
|
432
614
|
files[`app/page.${jsx}`] = `import { Link } from "@opentf/afw";
|
|
433
615
|
|
|
434
|
-
export const metadata = { title: "${escapeJs(ctx.name)}", description: "Documentation and blog." };
|
|
616
|
+
export const metadata = { title: "${escapeJs(ctx.name)}", description: "${blog ? "Documentation and blog." : "Documentation."}" };
|
|
435
617
|
|
|
436
618
|
export default function Home() {
|
|
437
619
|
return (
|
|
438
620
|
<main class="afwd-prose">
|
|
439
621
|
<h1>${escapeHTML(ctx.name)}</h1>
|
|
440
|
-
<p
|
|
622
|
+
<p>${blog ? "Documentation and a blog" : "Documentation"}, written in MDX.</p>
|
|
441
623
|
<p>
|
|
442
|
-
<Link href="/docs">Read the docs</Link
|
|
624
|
+
<Link href="/docs">Read the docs</Link>${blog ? ` · <Link href="/blog">Visit the blog</Link>` : ""}
|
|
443
625
|
</p>
|
|
444
626
|
</main>
|
|
445
627
|
);
|
|
@@ -481,8 +663,8 @@ description: Install and run the project.
|
|
|
481
663
|
# Getting Started
|
|
482
664
|
|
|
483
665
|
\`\`\`bash
|
|
484
|
-
|
|
485
|
-
|
|
666
|
+
${ctx.pm} install
|
|
667
|
+
${ctx.pm} run dev
|
|
486
668
|
\`\`\`
|
|
487
669
|
`;
|
|
488
670
|
files["app/docs/guides/writing-pages/page.mdx"] = `---
|
|
@@ -506,6 +688,35 @@ Markdown with components, like this list of steps.
|
|
|
506
688
|
|
|
507
689
|
</Steps>
|
|
508
690
|
`;
|
|
691
|
+
if (blog) Object.assign(files, blogFiles(ctx));
|
|
692
|
+
files[`tests/ui/Home.test.${js}`] = `import { expect, test } from "@opentf/afw-test/test";
|
|
693
|
+
import { render } from "@opentf/afw-test";
|
|
694
|
+
import Home from "../../app/page.${jsx}";
|
|
695
|
+
|
|
696
|
+
test("the home page links to the docs${blog ? " and the blog" : ""}", () => {
|
|
697
|
+
const { getByRole } = render(Home);
|
|
698
|
+
expect(getByRole("heading", { level: 1 }).textContent).toBe("${escapeJs(ctx.name)}");
|
|
699
|
+
expect(getByRole("link", { name: "Read the docs" }).getAttribute("href")).toBe("/docs");${blog ? `
|
|
700
|
+
expect(getByRole("link", { name: "Visit the blog" }).getAttribute("href")).toBe("/blog");` : ""}
|
|
701
|
+
});
|
|
702
|
+
`;
|
|
703
|
+
files[".gitignore"] = gitignore(ctx);
|
|
704
|
+
files["README.md"] = readme(ctx, {
|
|
705
|
+
summary: `A documentation site${blog ? " and blog" : ""} built with [AFW](https://afw.opentechf.org) and \`@opentf/afw-docs\` on ${onToolchain(ctx)}.`,
|
|
706
|
+
commands: commandRows(ctx, { server: false }),
|
|
707
|
+
notes: [
|
|
708
|
+
`Docs pages live in \`app/docs/\`${blog ? ", posts in \`app/blog/\`" : ""}; \`app/docs/_meta.js\` orders the sidebar.`,
|
|
709
|
+
`\`${ctx.pm} run build\` prerenders every page and writes the search index, \`sitemap.xml\`${blog ? ", RSS and Atom feeds" : ""} and \`llms.txt\`.`,
|
|
710
|
+
"Set your site's URL in `afw.config.js`.",
|
|
711
|
+
],
|
|
712
|
+
});
|
|
713
|
+
return files;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/** The blog of a docs site: its layout, the post list and a first post. */
|
|
717
|
+
function blogFiles(ctx) {
|
|
718
|
+
const { ts, jsx } = ctx;
|
|
719
|
+
const files = {};
|
|
509
720
|
files[`app/blog/layout.${jsx}`] = `import { BlogLayout } from "@opentf/afw-docs";
|
|
510
721
|
import { posts } from "@opentf/afw-docs/posts";
|
|
511
722
|
import config from "../../afw.config.js";
|
|
@@ -539,26 +750,6 @@ author: ${escapeHTML(ctx.name)}
|
|
|
539
750
|
|
|
540
751
|
Posts live in \`app/blog/\`; each one appears in the post list and the RSS and Atom feeds.
|
|
541
752
|
`;
|
|
542
|
-
files[`tests/Home.test.${js}`] = `import { expect, test } from "vitest";
|
|
543
|
-
import { render } from "@opentf/afw-test";
|
|
544
|
-
import Home from "../app/page.${jsx}";
|
|
545
|
-
|
|
546
|
-
test("the home page links to the docs and the blog", () => {
|
|
547
|
-
const { getByRole } = render(Home);
|
|
548
|
-
expect(getByRole("heading", { level: 1 }).textContent).toBe("${escapeJs(ctx.name)}");
|
|
549
|
-
expect(getByRole("link", { name: "Read the docs" }).getAttribute("href")).toBe("/docs");
|
|
550
|
-
});
|
|
551
|
-
`;
|
|
552
|
-
files[".gitignore"] = "node_modules\ndist\n";
|
|
553
|
-
files["README.md"] = readme(ctx, {
|
|
554
|
-
summary: "A documentation site and blog built with [AFW](https://afw.opentechf.org) and `@opentf/afw-docs` on Vite.",
|
|
555
|
-
commands: commandRows(ctx, { server: false }),
|
|
556
|
-
notes: [
|
|
557
|
-
"Docs pages live in `app/docs/`, posts in `app/blog/`; `app/docs/_meta.js` orders the sidebar.",
|
|
558
|
-
"`npm run build` prerenders every page and writes the search index, `sitemap.xml`, RSS and Atom feeds and `llms.txt`.",
|
|
559
|
-
"Set your site's URL in `afw.config.js`.",
|
|
560
|
-
],
|
|
561
|
-
});
|
|
562
753
|
return files;
|
|
563
754
|
}
|
|
564
755
|
|
|
@@ -567,7 +758,7 @@ test("the home page links to the docs and the blog", () => {
|
|
|
567
758
|
function libraryFiles(ctx) {
|
|
568
759
|
const { ts, js, jsx } = ctx;
|
|
569
760
|
const files = {};
|
|
570
|
-
const afw = ctx
|
|
761
|
+
const afw = version(ctx, "@opentf/afw");
|
|
571
762
|
files["package.json"] = json({
|
|
572
763
|
name: ctx.name,
|
|
573
764
|
version: "0.1.0",
|
|
@@ -576,12 +767,20 @@ function libraryFiles(ctx) {
|
|
|
576
767
|
exports: { ".": `./index.${js}` },
|
|
577
768
|
files: [`index.${js}`, "src"],
|
|
578
769
|
sideEffects: false,
|
|
579
|
-
scripts:
|
|
580
|
-
|
|
770
|
+
scripts: ctx.esdev
|
|
771
|
+
? { dev: "esdev start", test: testScript(ctx), ...(ts ? { typecheck: "esdev typecheck" } : {}) }
|
|
772
|
+
: { dev: "vite", test: testScript(ctx), ...(ts ? { typecheck: "tsc" } : {}) },
|
|
773
|
+
// A range: apps keep their own AFW release within it.
|
|
774
|
+
peerDependencies: { "@opentf/afw": afw.startsWith("^") ? afw : `^${afw}` },
|
|
581
775
|
devDependencies: devDependencies(ctx, { "@opentf/afw": afw }),
|
|
582
776
|
});
|
|
583
|
-
|
|
584
|
-
|
|
777
|
+
if (ctx.esdev) {
|
|
778
|
+
files["esdev.json"] = esdevConfig(ctx);
|
|
779
|
+
if (!ts) files["jsconfig.json"] = jsconfig();
|
|
780
|
+
} else {
|
|
781
|
+
files[`vite.config.${js}`] = viteConfig(ctx, { plugins: ["afw()"] });
|
|
782
|
+
}
|
|
783
|
+
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"]);
|
|
585
784
|
files[`index.${js}`] = `// The package entry: export each component.
|
|
586
785
|
export { default as Counter } from "./src/Counter.${jsx}";
|
|
587
786
|
`;
|
|
@@ -601,15 +800,15 @@ export default function Preview() {
|
|
|
601
800
|
);
|
|
602
801
|
}
|
|
603
802
|
`;
|
|
604
|
-
files[`tests/Counter.test.${js}`] = counterTest(ctx,
|
|
605
|
-
files[".gitignore"] =
|
|
803
|
+
files[`tests/ui/Counter.test.${js}`] = counterTest(ctx, `../../index.${js}`);
|
|
804
|
+
files[".gitignore"] = gitignore(ctx);
|
|
606
805
|
files["README.md"] = readme(ctx, {
|
|
607
806
|
summary: "A component library for [AFW](https://afw.opentechf.org), published as JSX source.",
|
|
608
807
|
commands: [
|
|
609
|
-
[
|
|
610
|
-
[
|
|
611
|
-
...(ts ? [[
|
|
612
|
-
[
|
|
808
|
+
[`${ctx.pm} run dev`, "Preview the components (`app/page." + jsx + "`)"],
|
|
809
|
+
[`${ctx.pm} run test`, `Run the tests with ${runner(ctx)}`],
|
|
810
|
+
...(ts ? [[`${ctx.pm} run typecheck`, "Check types"]] : []),
|
|
811
|
+
[`${ctx.pm} publish`, "Publish `index." + js + "` and `src/`"],
|
|
613
812
|
],
|
|
614
813
|
notes: [
|
|
615
814
|
`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.37.0",
|
|
4
|
+
"@opentf/afw-test": "^1.34.0",
|
|
5
|
+
"@opentf/vite-plugin-afw": "^0.7.0"
|
|
6
6
|
}
|