@opentf/create-afw 0.5.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/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 +13 -9
- package/package.json +14 -9
- package/templates.js +263 -74
- 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,20 +23,30 @@ 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
|
+
/** 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
|
+
|
|
25
42
|
export const STYLINGS = { css: "CSS", tailwind: "Tailwind CSS" };
|
|
26
43
|
|
|
27
44
|
/** The template names of earlier releases, kept as shorthands. */
|
|
28
45
|
export const LEGACY_TEMPLATES = {
|
|
29
|
-
spa: { template: "app", render: "
|
|
30
|
-
fullstack: { template: "app", render: "
|
|
31
|
-
ssr: { template: "app", render: "
|
|
32
|
-
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 },
|
|
33
50
|
};
|
|
34
51
|
|
|
35
52
|
// The third-party tools a new project starts on. AFW's own packages take the
|
|
@@ -46,20 +63,30 @@ export const TOOL_VERSIONS = {
|
|
|
46
63
|
/**
|
|
47
64
|
* The files of a new project, as `{ relativePath: contents }`.
|
|
48
65
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
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
|
|
51
73
|
*/
|
|
52
|
-
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
|
+
}) {
|
|
53
78
|
if (!TEMPLATES[template]) throw new Error(`Unknown template "${template}". Choose one of: ${Object.keys(TEMPLATES).join(", ")}`);
|
|
79
|
+
render = RENDER_ALIASES[render] ?? render;
|
|
54
80
|
if (!RENDERINGS[render]) throw new Error(`Unknown rendering "${render}". Choose one of: ${Object.keys(RENDERINGS).join(", ")}`);
|
|
55
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(", ")}`);
|
|
56
83
|
const ctx = {
|
|
57
84
|
name, versions, ts: typescript, js: typescript ? "ts" : "js", jsx: typescript ? "tsx" : "jsx",
|
|
58
|
-
tailwind: styling === "tailwind",
|
|
85
|
+
tailwind: styling === "tailwind", toolchain, esdev: toolchain === "esdev", pm,
|
|
59
86
|
};
|
|
60
87
|
if (template === "docs") return docsFiles({ ...ctx, blog });
|
|
61
88
|
if (template === "library") return libraryFiles(ctx);
|
|
62
|
-
return appFiles({ ...ctx, render, server: render
|
|
89
|
+
return appFiles({ ...ctx, render, server: SERVER_RENDERINGS.has(render) || server });
|
|
63
90
|
}
|
|
64
91
|
|
|
65
92
|
// ---------------------------------------------------------------------------- shared
|
|
@@ -69,19 +96,53 @@ const escapeJs = (text) => String(text).replace(/[\\"]/g, "\\$&");
|
|
|
69
96
|
// ` class="…"` with Tailwind, nothing with plain CSS.
|
|
70
97
|
const tw = (ctx, classes) => (ctx.tailwind ? ` class="${classes}"` : "");
|
|
71
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
|
+
|
|
72
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
|
+
}
|
|
73
114
|
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:
|
|
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"),
|
|
81
122
|
...extra,
|
|
82
123
|
});
|
|
83
124
|
}
|
|
84
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
|
+
|
|
85
146
|
function sortKeys(object) {
|
|
86
147
|
return Object.fromEntries(Object.entries(object).sort(([a], [b]) => a.localeCompare(b)));
|
|
87
148
|
}
|
|
@@ -115,7 +176,10 @@ function tsconfig(ctx, include, { allowJs = false } = {}) {
|
|
|
115
176
|
lib: ["ESNext", "DOM", "DOM.Iterable"],
|
|
116
177
|
jsx: "preserve",
|
|
117
178
|
jsxImportSource: "@opentf/afw",
|
|
118
|
-
|
|
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"] }),
|
|
119
183
|
strict: true,
|
|
120
184
|
noEmit: true,
|
|
121
185
|
isolatedModules: true,
|
|
@@ -133,11 +197,11 @@ function indexHtml(ctx, { title, css = true }) {
|
|
|
133
197
|
<head>
|
|
134
198
|
<meta charset="utf-8" />
|
|
135
199
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
136
|
-
<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" />` : ""}
|
|
137
201
|
</head>
|
|
138
202
|
<body>
|
|
139
203
|
<div id="app"></div>
|
|
140
|
-
<script type="module" src="/entry.${ctx.js}"></script>
|
|
204
|
+
<script type="module" src="${ctx.esdev ? "./" : "/"}entry.${ctx.js}"></script>
|
|
141
205
|
</body>
|
|
142
206
|
</html>
|
|
143
207
|
`;
|
|
@@ -195,10 +259,12 @@ function counter(ctx) {
|
|
|
195
259
|
`;
|
|
196
260
|
}
|
|
197
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.
|
|
198
264
|
function counterTest(ctx, from) {
|
|
199
|
-
return `import { expect, test } from "
|
|
265
|
+
return `import { expect, test } from "@opentf/afw-test/test";
|
|
200
266
|
import { render, userEvent } from "@opentf/afw-test";
|
|
201
|
-
import ${from.
|
|
267
|
+
import ${from.includes("/index.") ? "{ Counter }" : "Counter"} from "${from}";
|
|
202
268
|
|
|
203
269
|
test("counts clicks", async () => {
|
|
204
270
|
const { getByRole, getByText } = render(Counter, { start: 1 });
|
|
@@ -221,46 +287,104 @@ ${rows}
|
|
|
221
287
|
${notes.length ? `\n${notes.map((note) => `- ${note}`).join("\n")}\n` : ""}`;
|
|
222
288
|
}
|
|
223
289
|
|
|
224
|
-
|
|
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
|
+
}
|
|
225
311
|
return {
|
|
226
312
|
dev: "vite",
|
|
227
313
|
build: "vite build",
|
|
228
314
|
...(server ? { start: "node dist/server/index.js" } : { preview: "vite preview" }),
|
|
229
|
-
test:
|
|
315
|
+
test: testScript(ctx),
|
|
230
316
|
...(ctx.ts ? { typecheck: "tsc" } : {}),
|
|
231
317
|
};
|
|
232
318
|
}
|
|
233
319
|
|
|
320
|
+
const runner = (ctx) => (ctx.esdev ? "esdev" : "Vitest");
|
|
321
|
+
|
|
234
322
|
function commandRows(ctx, { server }) {
|
|
323
|
+
const pm = ctx.pm;
|
|
235
324
|
return [
|
|
236
|
-
[
|
|
237
|
-
[
|
|
238
|
-
server
|
|
239
|
-
|
|
240
|
-
|
|
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"]] : []),
|
|
241
332
|
];
|
|
242
333
|
}
|
|
243
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
|
+
|
|
244
342
|
// ---------------------------------------------------------------------------- app
|
|
245
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
|
+
|
|
246
353
|
function appFiles(ctx) {
|
|
247
354
|
const { ts, js, jsx, render, server } = ctx;
|
|
355
|
+
const mixed = render === "mixed";
|
|
356
|
+
const appDefault = mixed ? "server" : render;
|
|
248
357
|
const files = {};
|
|
249
358
|
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),
|
|
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") } : {}),
|
|
253
362
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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"]);
|
|
259
380
|
files["index.html"] = indexHtml(ctx, { title: ctx.name });
|
|
260
381
|
files[`entry.${js}`] = entry(ctx);
|
|
261
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.`);
|
|
262
386
|
|
|
263
|
-
const navLinks = [["/", "Home"], ["/about", "About"], ...(server ? [["/todos", "Todos"]] : [])];
|
|
387
|
+
const navLinks = [["/", "Home"], ["/about", "About"], ...(server ? [["/todos", "Todos"]] : []), ...(mixed ? [["/dashboard", "Dashboard"]] : [])];
|
|
264
388
|
files[`app/layout.${jsx}`] = `import { Link } from "@opentf/afw";
|
|
265
389
|
|
|
266
390
|
export default function Layout({ children }${ts ? ": { children: unknown }" : ""}) {
|
|
@@ -297,16 +421,25 @@ title: About
|
|
|
297
421
|
|
|
298
422
|
This page is Markdown. The AFW compiler turns it into a page like any other.
|
|
299
423
|
`;
|
|
424
|
+
if (mixed) Object.assign(files, mixedFiles(ctx));
|
|
300
425
|
if (server) Object.assign(files, serverFiles(ctx));
|
|
301
|
-
files[`tests/Counter.test.${js}`] = counterTest(ctx,
|
|
302
|
-
files[".gitignore"] =
|
|
303
|
-
|
|
304
|
-
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";
|
|
305
436
|
files["README.md"] = readme(ctx, {
|
|
306
|
-
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}` : ""}.`,
|
|
307
438
|
commands: commandRows(ctx, { server }),
|
|
308
439
|
notes: [
|
|
309
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/`" : ""}.`,
|
|
310
443
|
...(server ? [
|
|
311
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.`,
|
|
312
445
|
] : []),
|
|
@@ -316,9 +449,47 @@ This page is Markdown. The AFW compiler turns it into a page like any other.
|
|
|
316
449
|
return files;
|
|
317
450
|
}
|
|
318
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
|
+
|
|
319
481
|
function serverFiles(ctx) {
|
|
320
482
|
const { ts, js, jsx } = ctx;
|
|
321
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
|
+
`;
|
|
322
493
|
files[`app/api/hello/route.${js}`] = `// GET /api/hello?name=… — API routes run on Node, so any npm package works here.
|
|
323
494
|
export function GET(request${ts ? ": Request" : ""}, { query, locals }${ts ? ": { query: Record<string, string>; locals: Record<string, unknown> }" : ""}) {
|
|
324
495
|
return Response.json({ message: \`Hello, \${query.name ?? "world"}!\`, requestId: locals.requestId });
|
|
@@ -398,14 +569,24 @@ function docsFiles(ctx) {
|
|
|
398
569
|
const files = {};
|
|
399
570
|
files["package.json"] = json({
|
|
400
571
|
name: ctx.name, private: true, type: "module", scripts: scripts(ctx, { server: false }),
|
|
401
|
-
dependencies: { "@opentf/afw": ctx
|
|
402
|
-
devDependencies: devDependencies({ ...ctx, tailwind: false }),
|
|
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") } : {}),
|
|
403
574
|
});
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
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 });
|
|
409
590
|
files["afw.config.js"] = `import { defineDocsConfig } from "@opentf/afw-docs/config";
|
|
410
591
|
|
|
411
592
|
export default defineDocsConfig({
|
|
@@ -482,8 +663,8 @@ description: Install and run the project.
|
|
|
482
663
|
# Getting Started
|
|
483
664
|
|
|
484
665
|
\`\`\`bash
|
|
485
|
-
|
|
486
|
-
|
|
666
|
+
${ctx.pm} install
|
|
667
|
+
${ctx.pm} run dev
|
|
487
668
|
\`\`\`
|
|
488
669
|
`;
|
|
489
670
|
files["app/docs/guides/writing-pages/page.mdx"] = `---
|
|
@@ -508,9 +689,9 @@ Markdown with components, like this list of steps.
|
|
|
508
689
|
</Steps>
|
|
509
690
|
`;
|
|
510
691
|
if (blog) Object.assign(files, blogFiles(ctx));
|
|
511
|
-
files[`tests/Home.test.${js}`] = `import { expect, test } from "
|
|
692
|
+
files[`tests/ui/Home.test.${js}`] = `import { expect, test } from "@opentf/afw-test/test";
|
|
512
693
|
import { render } from "@opentf/afw-test";
|
|
513
|
-
import Home from "
|
|
694
|
+
import Home from "../../app/page.${jsx}";
|
|
514
695
|
|
|
515
696
|
test("the home page links to the docs${blog ? " and the blog" : ""}", () => {
|
|
516
697
|
const { getByRole } = render(Home);
|
|
@@ -519,13 +700,13 @@ test("the home page links to the docs${blog ? " and the blog" : ""}", () => {
|
|
|
519
700
|
expect(getByRole("link", { name: "Visit the blog" }).getAttribute("href")).toBe("/blog");` : ""}
|
|
520
701
|
});
|
|
521
702
|
`;
|
|
522
|
-
files[".gitignore"] =
|
|
703
|
+
files[".gitignore"] = gitignore(ctx);
|
|
523
704
|
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
|
|
705
|
+
summary: `A documentation site${blog ? " and blog" : ""} built with [AFW](https://afw.opentechf.org) and \`@opentf/afw-docs\` on ${onToolchain(ctx)}.`,
|
|
525
706
|
commands: commandRows(ctx, { server: false }),
|
|
526
707
|
notes: [
|
|
527
708
|
`Docs pages live in \`app/docs/\`${blog ? ", posts in \`app/blog/\`" : ""}; \`app/docs/_meta.js\` orders the sidebar.`,
|
|
528
|
-
|
|
709
|
+
`\`${ctx.pm} run build\` prerenders every page and writes the search index, \`sitemap.xml\`${blog ? ", RSS and Atom feeds" : ""} and \`llms.txt\`.`,
|
|
529
710
|
"Set your site's URL in `afw.config.js`.",
|
|
530
711
|
],
|
|
531
712
|
});
|
|
@@ -577,7 +758,7 @@ Posts live in \`app/blog/\`; each one appears in the post list and the RSS and A
|
|
|
577
758
|
function libraryFiles(ctx) {
|
|
578
759
|
const { ts, js, jsx } = ctx;
|
|
579
760
|
const files = {};
|
|
580
|
-
const afw = ctx
|
|
761
|
+
const afw = version(ctx, "@opentf/afw");
|
|
581
762
|
files["package.json"] = json({
|
|
582
763
|
name: ctx.name,
|
|
583
764
|
version: "0.1.0",
|
|
@@ -586,12 +767,20 @@ function libraryFiles(ctx) {
|
|
|
586
767
|
exports: { ".": `./index.${js}` },
|
|
587
768
|
files: [`index.${js}`, "src"],
|
|
588
769
|
sideEffects: false,
|
|
589
|
-
scripts:
|
|
590
|
-
|
|
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}` },
|
|
591
775
|
devDependencies: devDependencies(ctx, { "@opentf/afw": afw }),
|
|
592
776
|
});
|
|
593
|
-
|
|
594
|
-
|
|
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"]);
|
|
595
784
|
files[`index.${js}`] = `// The package entry: export each component.
|
|
596
785
|
export { default as Counter } from "./src/Counter.${jsx}";
|
|
597
786
|
`;
|
|
@@ -611,15 +800,15 @@ export default function Preview() {
|
|
|
611
800
|
);
|
|
612
801
|
}
|
|
613
802
|
`;
|
|
614
|
-
files[`tests/Counter.test.${js}`] = counterTest(ctx,
|
|
615
|
-
files[".gitignore"] =
|
|
803
|
+
files[`tests/ui/Counter.test.${js}`] = counterTest(ctx, `../../index.${js}`);
|
|
804
|
+
files[".gitignore"] = gitignore(ctx);
|
|
616
805
|
files["README.md"] = readme(ctx, {
|
|
617
806
|
summary: "A component library for [AFW](https://afw.opentechf.org), published as JSX source.",
|
|
618
807
|
commands: [
|
|
619
|
-
[
|
|
620
|
-
[
|
|
621
|
-
...(ts ? [[
|
|
622
|
-
[
|
|
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/`"],
|
|
623
812
|
],
|
|
624
813
|
notes: [
|
|
625
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
|
}
|