create-avocado-site 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +65 -0
  3. package/assets/generated-images/gdrive_1ql_bdk2KM_27u01rkMd8KoiCRJ_R7UOy.webp +0 -0
  4. package/assets/generated-images/gen_1774991902955_0p1i2o.webp +0 -0
  5. package/assets/generated-images/gen_1776458907692_zlrbkg.webp +0 -0
  6. package/assets/generated-images/gen_1788955681679_454dc316.webp +0 -0
  7. package/assets/generated-images/var_1773434968055_8g99nk.webp +0 -0
  8. package/assets/generated-images/var_1773435042084_wvet78.webp +0 -0
  9. package/assets/generated-images/var_1773435061562_6hf8s6.webp +0 -0
  10. package/assets/generated-images/var_1773435080764_6ocahu.webp +0 -0
  11. package/assets/generated-images/var_1773435101045_1y544z.webp +0 -0
  12. package/assets/generated-images/var_1773872370443_poycxy.webp +0 -0
  13. package/assets/generated-images/var_1776858715876_iuu72w.webp +0 -0
  14. package/assets/logos/avocado-hub.svg +7 -0
  15. package/dist/cms-config.d.ts +34 -0
  16. package/dist/cms-config.js +103 -0
  17. package/dist/generator.d.ts +22 -0
  18. package/dist/generator.js +92 -0
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.js +109 -0
  21. package/dist/instructions.d.ts +19 -0
  22. package/dist/instructions.js +82 -0
  23. package/dist/next-version.d.ts +15 -0
  24. package/dist/next-version.js +43 -0
  25. package/dist/ports.d.ts +11 -0
  26. package/dist/ports.js +61 -0
  27. package/dist/prompts.d.ts +13 -0
  28. package/dist/prompts.js +119 -0
  29. package/dist/templates/assets.d.ts +2 -0
  30. package/dist/templates/assets.js +41 -0
  31. package/dist/templates/common.d.ts +45 -0
  32. package/dist/templates/common.js +174 -0
  33. package/dist/templates/contentful.d.ts +2 -0
  34. package/dist/templates/contentful.js +379 -0
  35. package/dist/templates/demo-app.d.ts +3 -0
  36. package/dist/templates/demo-app.js +465 -0
  37. package/dist/templates/demo-content.d.ts +2 -0
  38. package/dist/templates/demo-content.js +7 -0
  39. package/dist/templates/sanity.d.ts +2 -0
  40. package/dist/templates/sanity.js +289 -0
  41. package/dist/templates/static.d.ts +2 -0
  42. package/dist/templates/static.js +81 -0
  43. package/dist/templates/strapi.d.ts +2 -0
  44. package/dist/templates/strapi.js +235 -0
  45. package/dist/types.d.ts +48 -0
  46. package/dist/types.js +1 -0
  47. package/dist/versions.d.ts +32 -0
  48. package/dist/versions.js +32 -0
  49. package/package.json +51 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Avocado Studio Contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # create-avocado-site
2
+
3
+ Bootstrap a runnable [Avocado Studio](https://docs.avocadostudio.dev) demo — or
4
+ wire Avocado into a Next.js project you already have.
5
+
6
+ ## See the demo
7
+
8
+ ```bash
9
+ npm create avocado-site@latest my-demo
10
+ cd my-demo
11
+ npm run dev
12
+ ```
13
+
14
+ That is the whole of it. The command creates the project, installs it, and
15
+ `npm run dev` starts both halves and opens the editor.
16
+
17
+ You get the **Avocado Hub**: nine pages, sixty blocks, every built-in block
18
+ type — a real site to talk to, rather than a placeholder to look at. The
19
+ orchestrator runs inside the Next app at `/api/avocado`, so there is no third
20
+ service to start and nothing to deploy.
21
+
22
+ | | |
23
+ |---|---|
24
+ | Editor | `http://localhost:4100/?siteId=my-demo&session=dev` |
25
+ | Site | `http://localhost:3000` |
26
+
27
+ Both ports are chosen at scaffold time from what is actually free, so this
28
+ works next to whatever else you have running.
29
+
30
+ ### No API key needed to look
31
+
32
+ The pages render, click-to-select works, and the property panel edits real
33
+ fields with no key configured at all. Chat is the one thing that needs a model:
34
+ put `ANTHROPIC_API_KEY`, `OPENAI_API_KEY` or `GOOGLE_GENAI_API_KEY` in
35
+ `.env.local` and restart. Avocado runs on your key and never resells tokens.
36
+
37
+ ## Wire it into an existing project
38
+
39
+ ```bash
40
+ cd my-existing-next-app
41
+ npm create avocado-site@latest
42
+ ```
43
+
44
+ With no directory argument the CLI asks what you want. Choose **Wire Avocado
45
+ into this project** and it writes the editor API route, the page routes, the
46
+ block manifest and the request rewrite — `proxy.ts` on Next 16, `middleware.ts`
47
+ on 15 — and touches nothing it did not create. Sanity, Contentful and Strapi
48
+ templates are included; so is a plain JSON file.
49
+
50
+ It then prints the handful of things it will not do to your repository: the
51
+ install command, the `withAvocado` wrapper for your Next config, and the
52
+ stylesheet import.
53
+
54
+ For an existing site of any size this is the smaller half of the job. The
55
+ larger half — your components, your content model, your CMS — is at
56
+ [docs.avocadostudio.dev/sites](https://docs.avocadostudio.dev/sites).
57
+
58
+ ## Requirements
59
+
60
+ - Node.js 22+
61
+ - For the integrate path, a Next.js 15 or 16 project on the App Router
62
+
63
+ ## License
64
+
65
+ Apache-2.0.
@@ -0,0 +1,7 @@
1
+ <svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="title desc">
2
+ <title id="title">The Avocado Hub logo</title>
3
+ <desc id="desc">Stylized avocado mark — dark green shell, light green flesh, brown pit.</desc>
4
+ <path d="M64 8C88 8 112 40 112 72C112 104 88 120 64 120C40 120 16 104 16 72C16 40 40 8 64 8Z" fill="#1F7A3A"/>
5
+ <path d="M64 18C82 18 100 44 100 72C100 100 82 110 64 110C46 110 28 100 28 72C28 44 46 18 64 18Z" fill="#7ED957"/>
6
+ <circle cx="64" cy="72" r="20" fill="#8B5E3C"/>
7
+ </svg>
@@ -0,0 +1,34 @@
1
+ import type { CmsChoice } from "./types.js";
2
+ export type CmsDescriptor = {
3
+ /** Import statement for the publish handler */
4
+ publishImport: string;
5
+ /** Import statement for getPages */
6
+ getPagesImport: string;
7
+ /** Expression for onPublish in createEditorApiHandler */
8
+ onPublish: string;
9
+ /** Expression for getPages in createEditorApiHandler */
10
+ getPages: string;
11
+ /** Import for page component (getPage, getSlugs, getSiteConfig) */
12
+ pageImport: string;
13
+ /** Function names for createSitePage */
14
+ getPage: string;
15
+ getSlugs: string;
16
+ getSiteConfig: string | null;
17
+ /** Revalidation config */
18
+ revalidate: {
19
+ secretEnvVar: string;
20
+ secretHeader: string | null;
21
+ extractSlug: string;
22
+ getPagesImport: string;
23
+ getPagesFn: string;
24
+ } | null;
25
+ /** Env var template */
26
+ envVars: string;
27
+ /** Additional npm dependencies */
28
+ npmDeps: string;
29
+ /** Additional next.config image hostname */
30
+ imageHostname: string | null;
31
+ /** Additional next.config compiler options */
32
+ compilerConfig: string;
33
+ };
34
+ export declare const CMS_CONFIGS: Record<CmsChoice, CmsDescriptor>;
@@ -0,0 +1,103 @@
1
+ export const CMS_CONFIGS = {
2
+ sanity: {
3
+ publishImport: `import { createSanityPublishHandler } from "../../../../lib/publish"`,
4
+ getPagesImport: `import { getSanityPages } from "../../../../lib/sanity.fetch"`,
5
+ onPublish: `createSanityPublishHandler()`,
6
+ getPages: `() => getSanityPages()`,
7
+ pageImport: `import { getSanityPage, getSanitySlugs, getSanitySiteConfig } from "../../lib/sanity.fetch"`,
8
+ getPage: "getSanityPage",
9
+ getSlugs: "getSanitySlugs",
10
+ getSiteConfig: "getSanitySiteConfig",
11
+ revalidate: {
12
+ secretEnvVar: "SANITY_WEBHOOK_SECRET",
13
+ secretHeader: `["query:secret", "x-sanity-webhook-secret"]`,
14
+ extractSlug: `(body) => (body as { slug?: { current?: string } })?.slug?.current ?? null`,
15
+ getPagesImport: `import { getSanityPages } from "../../../lib/sanity.fetch"`,
16
+ getPagesFn: "getSanityPages",
17
+ },
18
+ envVars: `# Sanity
19
+ NEXT_PUBLIC_SANITY_PROJECT_ID=
20
+ NEXT_PUBLIC_SANITY_DATASET=production
21
+ SANITY_API_TOKEN=
22
+ SANITY_WEBHOOK_SECRET=`,
23
+ npmDeps: " @sanity/client @sanity/image-url groq",
24
+ imageHostname: "cdn.sanity.io",
25
+ compilerConfig: ` compiler: { styledComponents: true },\n`,
26
+ },
27
+ contentful: {
28
+ publishImport: `import { createContentfulPublishHandler } from "../../../../lib/publish"`,
29
+ getPagesImport: `import { getContentfulPages } from "../../../../lib/contentful"`,
30
+ onPublish: `createContentfulPublishHandler({
31
+ spaceId: process.env.CONTENTFUL_SPACE_ID!,
32
+ managementToken: process.env.CONTENTFUL_MANAGEMENT_TOKEN!,
33
+ environmentId: process.env.CONTENTFUL_ENVIRONMENT ?? "master",
34
+ })`,
35
+ getPages: `() => getContentfulPages()`,
36
+ pageImport: `import { getContentfulPage, getContentfulSlugs, getContentfulSiteConfig } from "../../lib/contentful"`,
37
+ getPage: "getContentfulPage",
38
+ getSlugs: "getContentfulSlugs",
39
+ getSiteConfig: "getContentfulSiteConfig",
40
+ revalidate: {
41
+ secretEnvVar: "REVALIDATION_SECRET",
42
+ secretHeader: null,
43
+ extractSlug: `(body) =>\n (body as { fields?: { slug?: { "en-US"?: string } } })?.fields?.slug?.["en-US"] ?? null`,
44
+ getPagesImport: `import { getContentfulPages } from "../../../lib/contentful"`,
45
+ getPagesFn: "getContentfulPages",
46
+ },
47
+ envVars: `# Contentful
48
+ CONTENTFUL_SPACE_ID=
49
+ CONTENTFUL_ENVIRONMENT=master
50
+ CONTENTFUL_DELIVERY_TOKEN=
51
+ CONTENTFUL_MANAGEMENT_TOKEN=
52
+ REVALIDATION_SECRET=`,
53
+ npmDeps: " contentful contentful-management",
54
+ imageHostname: "images.ctfassets.net",
55
+ compilerConfig: "",
56
+ },
57
+ strapi: {
58
+ publishImport: `import { createStrapiPublishHandler } from "../../../../lib/publish"`,
59
+ getPagesImport: `import { getStrapiPages } from "../../../../lib/strapi.fetch"`,
60
+ onPublish: `createStrapiPublishHandler()`,
61
+ getPages: `() => getStrapiPages()`,
62
+ pageImport: `import { getStrapiPage, getStrapiSlugs, getStrapiSiteConfig } from "../../lib/strapi.fetch"`,
63
+ getPage: "getStrapiPage",
64
+ getSlugs: "getStrapiSlugs",
65
+ getSiteConfig: "getStrapiSiteConfig",
66
+ revalidate: {
67
+ secretEnvVar: "STRAPI_WEBHOOK_SECRET",
68
+ secretHeader: null,
69
+ extractSlug: `(body) =>\n (body as { entry?: { slug?: string } })?.entry?.slug ?? null`,
70
+ getPagesImport: `import { getStrapiPages } from "../../../lib/strapi.fetch"`,
71
+ getPagesFn: "getStrapiPages",
72
+ },
73
+ envVars: `# Strapi
74
+ STRAPI_URL=http://localhost:1337
75
+ STRAPI_API_TOKEN=
76
+ STRAPI_WEBHOOK_SECRET=`,
77
+ npmDeps: "",
78
+ imageHostname: null,
79
+ compilerConfig: "",
80
+ },
81
+ none: {
82
+ publishImport: `import { createJsonFilePublishHandler } from "@avocadostudio-ai/site-sdk/publish-handlers/json-file"
83
+ import { resolve } from "node:path"`,
84
+ /*
85
+ * This was `() => Promise.resolve([])` — a literal empty array, in the one
86
+ * call the editor uses to discover what pages a site has. The scaffold
87
+ * rendered nine pages and reported none of them, and because the preview
88
+ * pane showed the site correctly the failure read as an editor bug.
89
+ */
90
+ getPagesImport: `import { getPages } from "../../../../lib/content"`,
91
+ onPublish: `createJsonFilePublishHandler(resolve(process.cwd(), "content/pages.json"))`,
92
+ getPages: `() => getPages()`,
93
+ pageImport: `import { getPage, getSlugs, getSiteConfig } from "../../lib/content"`,
94
+ getPage: "getPage",
95
+ getSlugs: "getSlugs",
96
+ getSiteConfig: "getSiteConfig",
97
+ revalidate: null,
98
+ envVars: "",
99
+ npmDeps: "",
100
+ imageHostname: null,
101
+ compilerConfig: "",
102
+ },
103
+ };
@@ -0,0 +1,22 @@
1
+ import type { ScaffoldConfig, GeneratedFile } from "./types.js";
2
+ /**
3
+ * A whole project, not a patch to one.
4
+ *
5
+ * The distinction from `collectFiles` is what it is allowed to own. This path
6
+ * creates an empty directory and fills it, so it writes the package manifest,
7
+ * the Next config, the root layout and the stylesheet — files that in the
8
+ * integrate path belong to the host app and must not be touched.
9
+ *
10
+ * It also scaffolds `mode: "auto"`: one route file that decides published
11
+ * versus editor per request. That removes the proxy (or middleware), the
12
+ * second `preview-draft` route, and the class of failure where the two route
13
+ * files drift apart — at the cost of static rendering, which a local demo does
14
+ * not have and does not want.
15
+ */
16
+ export declare function collectDemoFiles(config: ScaffoldConfig): GeneratedFile[];
17
+ /** Wiring for a Next.js app that already exists. Touches nothing it did not create. */
18
+ export declare function collectFiles(config: ScaffoldConfig): GeneratedFile[];
19
+ export declare function generateFiles(cwd: string, files: GeneratedFile[]): Promise<{
20
+ written: string[];
21
+ skipped: string[];
22
+ }>;
@@ -0,0 +1,92 @@
1
+ import { constants, copyFile, mkdir, writeFile } from "node:fs/promises";
2
+ import { dirname, join } from "node:path";
3
+ import { editorApiRoute, revalidateRoute, manifestFile, pageFile, middlewareFile, proxyFile, notFoundFile, envExample, } from "./templates/common.js";
4
+ import { demoAppTemplates } from "./templates/demo-app.js";
5
+ import { demoAssets } from "./templates/assets.js";
6
+ import { sanityTemplates } from "./templates/sanity.js";
7
+ import { contentfulTemplates } from "./templates/contentful.js";
8
+ import { strapiTemplates } from "./templates/strapi.js";
9
+ import { staticTemplates } from "./templates/static.js";
10
+ function cmsTemplates(config) {
11
+ switch (config.cms) {
12
+ case "sanity": return sanityTemplates(config);
13
+ case "contentful": return contentfulTemplates(config);
14
+ case "strapi": return strapiTemplates(config);
15
+ case "none": return staticTemplates(config);
16
+ }
17
+ }
18
+ /**
19
+ * A whole project, not a patch to one.
20
+ *
21
+ * The distinction from `collectFiles` is what it is allowed to own. This path
22
+ * creates an empty directory and fills it, so it writes the package manifest,
23
+ * the Next config, the root layout and the stylesheet — files that in the
24
+ * integrate path belong to the host app and must not be touched.
25
+ *
26
+ * It also scaffolds `mode: "auto"`: one route file that decides published
27
+ * versus editor per request. That removes the proxy (or middleware), the
28
+ * second `preview-draft` route, and the class of failure where the two route
29
+ * files drift apart — at the cost of static rendering, which a local demo does
30
+ * not have and does not want.
31
+ */
32
+ export function collectDemoFiles(config) {
33
+ return [
34
+ ...demoAppTemplates(config),
35
+ ...demoAssets(),
36
+ { path: "app/[[...slug]]/page.tsx", content: pageFile(config, "auto") },
37
+ { path: "app/not-found.tsx", content: notFoundFile() },
38
+ { path: "app/api/editor/[...path]/route.ts", content: editorApiRoute(config) },
39
+ { path: "lib/manifest.ts", content: manifestFile(config) },
40
+ ...cmsTemplates(config),
41
+ ];
42
+ }
43
+ /** Wiring for a Next.js app that already exists. Touches nothing it did not create. */
44
+ export function collectFiles(config) {
45
+ const files = [];
46
+ files.push({ path: "app/api/editor/[...path]/route.ts", content: editorApiRoute(config) });
47
+ const revalidate = revalidateRoute(config);
48
+ if (revalidate)
49
+ files.push({ path: "app/api/revalidate/route.ts", content: revalidate });
50
+ files.push({ path: "lib/manifest.ts", content: manifestFile(config) });
51
+ files.push({ path: "app/[[...slug]]/page.tsx", content: pageFile(config, "static") });
52
+ files.push({ path: "app/preview-draft/[[...slug]]/page.tsx", content: pageFile(config, "preview") });
53
+ files.push({ path: "app/not-found.tsx", content: notFoundFile() });
54
+ // Next.js 16 renamed `middleware` to `proxy`; older majors keep middleware.ts.
55
+ files.push((config.nextMajor ?? 15) >= 16
56
+ ? { path: "proxy.ts", content: proxyFile() }
57
+ : { path: "middleware.ts", content: middlewareFile() });
58
+ files.push({ path: ".env.local.example", content: envExample(config) });
59
+ files.push(...cmsTemplates(config));
60
+ return files;
61
+ }
62
+ export async function generateFiles(cwd, files) {
63
+ const written = [];
64
+ const skipped = [];
65
+ // Create all unique directories upfront
66
+ const dirs = new Set(files.map((f) => dirname(join(cwd, f.path))));
67
+ await Promise.all([...dirs].map((d) => mkdir(d, { recursive: true })));
68
+ for (const file of files) {
69
+ const fullPath = join(cwd, file.path);
70
+ try {
71
+ // Never clobber, either way. The integrate path writes into somebody's
72
+ // repository, and a scaffolder that overwrites an existing route file is
73
+ // a scaffolder that destroys work. `wx` and `COPYFILE_EXCL` are the same
74
+ // promise for the two kinds of file.
75
+ if (file.source !== undefined) {
76
+ await copyFile(file.source, fullPath, constants.COPYFILE_EXCL);
77
+ }
78
+ else {
79
+ await writeFile(fullPath, file.content ?? "", { encoding: "utf-8", flag: "wx" });
80
+ }
81
+ written.push(file.path);
82
+ }
83
+ catch (err) {
84
+ if (err && typeof err === "object" && "code" in err && err.code === "EEXIST") {
85
+ skipped.push(file.path);
86
+ continue;
87
+ }
88
+ throw err;
89
+ }
90
+ }
91
+ return { written, skipped };
92
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};