alchemy 0.2.5 → 0.3.1

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 (197) hide show
  1. package/README.md +3 -3
  2. package/lib/ai/approve.d.ts +99 -0
  3. package/lib/ai/approve.js +76 -0
  4. package/lib/ai/astro-file.d.ts +137 -0
  5. package/lib/ai/astro-file.js +156 -0
  6. package/lib/ai/client.d.ts +7 -8
  7. package/lib/ai/client.js +48 -19
  8. package/lib/ai/css-file.d.ts +131 -0
  9. package/lib/ai/css-file.js +141 -0
  10. package/lib/ai/data.d.ts +51 -6
  11. package/lib/ai/data.js +58 -12
  12. package/lib/ai/document.d.ts +108 -24
  13. package/lib/ai/document.js +166 -52
  14. package/lib/ai/html-file.d.ts +128 -0
  15. package/lib/ai/html-file.js +138 -0
  16. package/lib/ai/index.d.ts +9 -0
  17. package/lib/ai/index.js +9 -0
  18. package/lib/ai/json-file.d.ts +160 -0
  19. package/lib/ai/json-file.js +187 -0
  20. package/lib/ai/review.d.ts +122 -0
  21. package/lib/ai/review.js +101 -0
  22. package/lib/ai/typescript-file.d.ts +139 -0
  23. package/lib/ai/typescript-file.js +145 -0
  24. package/lib/ai/vue-file.d.ts +126 -0
  25. package/lib/ai/vue-file.js +136 -0
  26. package/lib/ai/yaml-file.d.ts +169 -0
  27. package/lib/ai/yaml-file.js +200 -0
  28. package/lib/alchemy.js +17 -2
  29. package/lib/apply.js +1 -1
  30. package/lib/cloudflare/dns.d.ts +88 -0
  31. package/lib/cloudflare/dns.js +192 -0
  32. package/lib/cloudflare/generate-asset-manifest.js +1 -1
  33. package/lib/cloudflare/index.d.ts +2 -1
  34. package/lib/cloudflare/index.js +2 -1
  35. package/lib/cloudflare/r2-rest-state-store.d.ts +125 -0
  36. package/lib/cloudflare/r2-rest-state-store.js +254 -0
  37. package/lib/cloudflare/response.d.ts +12 -0
  38. package/lib/cloudflare/response.js +0 -0
  39. package/lib/cloudflare/static-site-router.js +16 -7
  40. package/lib/cloudflare/static-site.js +3 -0
  41. package/lib/cloudflare/upload-asset-manifest.js +4 -2
  42. package/lib/cloudflare/zone.d.ts +18 -0
  43. package/lib/cloudflare/zone.js +17 -4
  44. package/lib/dns/godaddy.d.ts +7 -0
  45. package/lib/dns/godaddy.js +21 -0
  46. package/lib/dns/import-dns.d.ts +82 -0
  47. package/lib/dns/import-dns.js +114 -0
  48. package/lib/dns/index.d.ts +2 -0
  49. package/lib/dns/index.js +2 -0
  50. package/lib/dns/record.d.ts +88 -0
  51. package/lib/dns/record.js +13 -0
  52. package/lib/fs/copy-file.d.ts +54 -0
  53. package/lib/fs/copy-file.js +63 -0
  54. package/lib/fs/file-system-state-store.d.ts +17 -0
  55. package/lib/fs/file-system-state-store.js +87 -0
  56. package/lib/fs/file.d.ts +13 -0
  57. package/lib/fs/file.js +24 -5
  58. package/lib/fs/folder.d.ts +10 -0
  59. package/lib/fs/folder.js +2 -2
  60. package/lib/fs/index.d.ts +10 -4
  61. package/lib/fs/index.js +10 -4
  62. package/lib/fs/static-astro-file.d.ts +34 -0
  63. package/lib/fs/static-astro-file.js +39 -0
  64. package/lib/fs/static-css-file.d.ts +24 -0
  65. package/lib/fs/static-css-file.js +29 -0
  66. package/lib/fs/static-html-file.d.ts +31 -0
  67. package/lib/fs/static-html-file.js +36 -0
  68. package/lib/fs/{json-file.d.ts → static-json-file.d.ts} +3 -3
  69. package/lib/fs/static-json-file.js +15 -0
  70. package/lib/fs/{text-file.d.ts → static-text-file.d.ts} +2 -2
  71. package/lib/fs/static-text-file.js +8 -0
  72. package/lib/fs/{typescript-file.d.ts → static-typescript-file.d.ts} +3 -3
  73. package/lib/fs/{typescript-file.js → static-typescript-file.js} +3 -2
  74. package/lib/fs/static-vue-file.d.ts +28 -0
  75. package/lib/fs/static-vue-file.js +33 -0
  76. package/lib/fs/static-yaml-file.d.ts +22 -0
  77. package/lib/fs/{yaml-file.js → static-yaml-file.js} +3 -2
  78. package/lib/internal/getting-started.d.ts +21 -0
  79. package/lib/internal/getting-started.js +87 -0
  80. package/lib/internal/index.d.ts +3 -0
  81. package/lib/internal/index.js +3 -0
  82. package/lib/internal/providers.d.ts +27 -0
  83. package/lib/internal/providers.js +172 -0
  84. package/lib/internal/tutorial.d.ts +104 -0
  85. package/lib/internal/tutorial.js +251 -0
  86. package/lib/resource.js +8 -1
  87. package/lib/scope.d.ts +1 -1
  88. package/lib/scope.js +4 -2
  89. package/lib/state.d.ts +1 -16
  90. package/lib/state.js +0 -87
  91. package/lib/test/bun.d.ts +11 -0
  92. package/lib/test/bun.js +36 -8
  93. package/lib/web/astro.d.ts +147 -0
  94. package/lib/web/astro.js +414 -0
  95. package/lib/{shadcn/component.js → web/shadcn-component.js} +2 -9
  96. package/lib/web/shadcn.d.ts +97 -0
  97. package/lib/web/shadcn.js +99 -0
  98. package/lib/web/tailwind.d.ts +64 -0
  99. package/lib/web/tailwind.js +97 -0
  100. package/lib/{vite → web}/vite.d.ts +5 -0
  101. package/lib/{vite → web}/vite.js +44 -44
  102. package/lib/web/vitepress/config.d.ts +10 -0
  103. package/lib/web/vitepress/config.js +31 -0
  104. package/lib/web/vitepress/custom-theme.d.ts +173 -0
  105. package/lib/web/vitepress/custom-theme.js +336 -0
  106. package/lib/{vitepress → web/vitepress}/dependencies.d.ts +2 -2
  107. package/lib/{vitepress → web/vitepress}/dependencies.js +1 -1
  108. package/lib/web/vitepress/home-page.d.ts +246 -0
  109. package/lib/web/vitepress/home-page.js +147 -0
  110. package/lib/{vitepress → web/vitepress}/index.d.ts +2 -0
  111. package/lib/{vitepress → web/vitepress}/index.js +2 -0
  112. package/lib/{vitepress → web/vitepress}/vitepress.d.ts +15 -12
  113. package/lib/{vitepress → web/vitepress}/vitepress.js +26 -44
  114. package/package.json +6 -2
  115. package/src/ai/approve.ts +163 -0
  116. package/src/ai/astro-file.ts +269 -0
  117. package/src/ai/client.ts +60 -21
  118. package/src/ai/css-file.ts +247 -0
  119. package/src/ai/data.ts +81 -19
  120. package/src/ai/document.ts +240 -62
  121. package/src/ai/html-file.ts +244 -0
  122. package/src/ai/index.ts +9 -0
  123. package/src/ai/json-file.ts +325 -0
  124. package/src/ai/review.ts +213 -0
  125. package/src/ai/typescript-file.ts +259 -0
  126. package/src/ai/vue-file.ts +242 -0
  127. package/src/ai/yaml-file.ts +328 -0
  128. package/src/alchemy.ts +18 -7
  129. package/src/apply.ts +8 -9
  130. package/src/cloudflare/dns.ts +344 -0
  131. package/src/cloudflare/generate-asset-manifest.ts +4 -4
  132. package/src/cloudflare/index.ts +2 -1
  133. package/src/cloudflare/r2-rest-state-store.ts +353 -0
  134. package/src/cloudflare/response.ts +9 -0
  135. package/src/cloudflare/static-site-router.ts +18 -8
  136. package/src/cloudflare/static-site.ts +11 -7
  137. package/src/cloudflare/upload-asset-manifest.ts +6 -4
  138. package/src/cloudflare/worker.ts +44 -43
  139. package/src/cloudflare/zone.ts +39 -23
  140. package/src/dns/godaddy.ts +29 -0
  141. package/src/dns/import-dns.ts +213 -0
  142. package/src/dns/index.ts +2 -0
  143. package/src/dns/record.ts +121 -0
  144. package/src/fs/copy-file.ts +115 -0
  145. package/src/fs/file-system-state-store.ts +109 -0
  146. package/src/fs/file.ts +35 -9
  147. package/src/fs/folder.ts +14 -2
  148. package/src/fs/index.ts +10 -4
  149. package/src/fs/static-astro-file.ts +45 -0
  150. package/src/fs/static-css-file.ts +35 -0
  151. package/src/fs/static-html-file.ts +42 -0
  152. package/src/fs/static-json-file.ts +34 -0
  153. package/src/fs/{text-file.ts → static-text-file.ts} +9 -3
  154. package/src/fs/{typescript-file.ts → static-typescript-file.ts} +7 -6
  155. package/src/fs/static-vue-file.ts +39 -0
  156. package/src/fs/static-yaml-file.ts +33 -0
  157. package/src/internal/getting-started.ts +115 -0
  158. package/src/internal/index.ts +3 -0
  159. package/src/internal/providers.ts +241 -0
  160. package/src/internal/tutorial.ts +392 -0
  161. package/src/resource.ts +10 -1
  162. package/src/scope.ts +5 -6
  163. package/src/state.ts +1 -111
  164. package/src/test/bun.ts +60 -10
  165. package/src/web/astro.ts +644 -0
  166. package/src/{shadcn/component.ts → web/shadcn-component.ts} +5 -13
  167. package/src/web/shadcn.ts +219 -0
  168. package/src/web/tailwind.ts +167 -0
  169. package/src/{vite → web}/vite.ts +54 -56
  170. package/src/web/vitepress/config.ts +48 -0
  171. package/src/web/vitepress/custom-theme.ts +514 -0
  172. package/src/{vitepress → web/vitepress}/dependencies.ts +2 -2
  173. package/src/web/vitepress/home-page.ts +375 -0
  174. package/src/{vitepress → web/vitepress}/index.ts +2 -0
  175. package/src/{vitepress → web/vitepress}/vitepress.ts +62 -72
  176. package/lib/cloudflare/state.d.ts +0 -82
  177. package/lib/cloudflare/state.js +0 -108
  178. package/lib/fs/json-file.js +0 -7
  179. package/lib/fs/text-file.js +0 -7
  180. package/lib/fs/yaml-file.d.ts +0 -19
  181. package/lib/internal/docs.d.ts +0 -5
  182. package/lib/internal/docs.js +0 -287
  183. package/lib/shadcn/index.d.ts +0 -1
  184. package/lib/shadcn/index.js +0 -1
  185. package/lib/vite/index.d.ts +0 -1
  186. package/lib/vite/index.js +0 -1
  187. package/lib/vitepress/home-page.d.ts +0 -133
  188. package/lib/vitepress/home-page.js +0 -11
  189. package/src/cloudflare/state.ts +0 -138
  190. package/src/fs/json-file.ts +0 -23
  191. package/src/fs/yaml-file.ts +0 -26
  192. package/src/internal/docs.ts +0 -338
  193. package/src/shadcn/index.ts +0 -1
  194. package/src/vite/index.ts +0 -1
  195. package/src/vitepress/home-page.ts +0 -166
  196. /package/lib/{shadcn/component.d.ts → web/shadcn-component.d.ts} +0 -0
  197. /package/src/{vitepress → web/vitepress}/index.md +0 -0
@@ -0,0 +1,375 @@
1
+ import yaml from "yaml";
2
+ import { Document } from "../../ai/document";
3
+ import { alchemy } from "../../alchemy";
4
+ import { StaticTextFile } from "../../fs";
5
+ import type { Secret } from "../../secret";
6
+
7
+ /**
8
+ * Image that can be themed for light/dark mode
9
+ */
10
+ export interface ThemeableImage {
11
+ /**
12
+ * Image source URL
13
+ */
14
+ src?: string;
15
+
16
+ /**
17
+ * Image alt text
18
+ */
19
+ alt?: string;
20
+
21
+ /**
22
+ * Light theme image URL
23
+ */
24
+ light?: string;
25
+
26
+ /**
27
+ * Dark theme image URL
28
+ */
29
+ dark?: string;
30
+ }
31
+
32
+ /**
33
+ * Hero action button configuration
34
+ */
35
+ export interface HeroAction {
36
+ /**
37
+ * Color theme of the button
38
+ * @default "brand"
39
+ */
40
+ theme?: "brand" | "alt";
41
+
42
+ /**
43
+ * Label of the button
44
+ */
45
+ text: string;
46
+
47
+ /**
48
+ * Destination link of the button
49
+ */
50
+ link: string;
51
+
52
+ /**
53
+ * Link target attribute
54
+ */
55
+ target?: string;
56
+
57
+ /**
58
+ * Link rel attribute
59
+ */
60
+ rel?: string;
61
+ }
62
+
63
+ /**
64
+ * Hero section configuration
65
+ */
66
+ export interface Hero {
67
+ /**
68
+ * The string shown top of text. Comes with brand color
69
+ * and expected to be short, such as product name.
70
+ */
71
+ name?: string;
72
+
73
+ /**
74
+ * The main text for the hero section. This will be defined
75
+ * as h1 tag.
76
+ */
77
+ text: string;
78
+
79
+ /**
80
+ * Tagline displayed below text
81
+ */
82
+ tagline?: string;
83
+
84
+ /**
85
+ * The image displayed next to the text and tagline area
86
+ */
87
+ image?: string | ThemeableImage;
88
+
89
+ /**
90
+ * Action buttons to display in home hero section
91
+ */
92
+ actions?: HeroAction[];
93
+ }
94
+
95
+ /**
96
+ * Feature item configuration
97
+ */
98
+ export interface Feature {
99
+ /**
100
+ * Show icon on each feature box
101
+ */
102
+ icon?: string | ThemeableImage;
103
+
104
+ /**
105
+ * Title of the feature
106
+ */
107
+ title: string;
108
+
109
+ /**
110
+ * Details of the feature
111
+ */
112
+ details: string;
113
+
114
+ /**
115
+ * Link when clicked on feature component
116
+ */
117
+ link?: string;
118
+
119
+ /**
120
+ * Link text to be shown inside feature component
121
+ */
122
+ linkText?: string;
123
+
124
+ /**
125
+ * Link rel attribute
126
+ */
127
+ rel?: string;
128
+
129
+ /**
130
+ * Link target attribute
131
+ */
132
+ target?: string;
133
+ }
134
+
135
+ /**
136
+ * VitePress home page configuration
137
+ */
138
+ export interface HomePageConfig {
139
+ /**
140
+ * Use home page layout
141
+ */
142
+ layout: "home";
143
+
144
+ /**
145
+ * Hero section configuration
146
+ */
147
+ hero?: Hero;
148
+
149
+ /**
150
+ * Features section configuration
151
+ */
152
+ features?: Feature[];
153
+
154
+ /**
155
+ * Whether to apply default markdown styles
156
+ * @default true
157
+ */
158
+ markdownStyles?: boolean;
159
+ }
160
+
161
+ /**
162
+ * Properties for creating or updating a VitePress HomePage
163
+ */
164
+ export interface HomePageProps {
165
+ /**
166
+ * Output directory for the home page markdown file
167
+ */
168
+ outFile: string;
169
+
170
+ /**
171
+ * Title of the home page document
172
+ */
173
+ title: string;
174
+
175
+ /**
176
+ * Hero section configuration
177
+ */
178
+ hero?: Hero;
179
+
180
+ /**
181
+ * Features section configuration
182
+ */
183
+ features?: Feature[];
184
+
185
+ /**
186
+ * User prompt describing the design of the home page
187
+ */
188
+ prompt?: string;
189
+
190
+ /**
191
+ * Optional extension to the built-in system prompt
192
+ */
193
+ system?: string;
194
+
195
+ /**
196
+ * Base URL for the OpenAI API
197
+ * @default 'https://api.openai.com/v1'
198
+ */
199
+ baseURL?: string;
200
+
201
+ /**
202
+ * OpenAI API key to use for generating content
203
+ * If not provided, will use OPENAI_API_KEY environment variable
204
+ */
205
+ apiKey?: Secret;
206
+
207
+ /**
208
+ * Model configuration for the AI generator
209
+ */
210
+ model?: import("../../ai/client").ModelConfig;
211
+
212
+ /**
213
+ * Temperature for controlling randomness in generation
214
+ * @default 0.7
215
+ */
216
+ temperature?: number;
217
+ }
218
+
219
+ /**
220
+ * Output type for the HomePage resource
221
+ */
222
+ export type HomePage = StaticTextFile | Document;
223
+
224
+ /**
225
+ * Parse YAML frontmatter to home page config
226
+ */
227
+ export function parseHomePage(content: string): HomePageConfig {
228
+ const match = content.match(/^---\n([\s\S]*?)\n---/);
229
+ if (!match) {
230
+ throw new Error("Invalid frontmatter format");
231
+ }
232
+ return yaml.parse(match[1]) as HomePageConfig;
233
+ }
234
+
235
+ /**
236
+ * Resource for generating a VitePress homepage using AI.
237
+ * Creates an index.md file with the appropriate frontmatter and content
238
+ * based on the provided prompt and configuration.
239
+ *
240
+ * @example
241
+ * // Create a basic home page with just a prompt
242
+ * const homePage = await HomePage("docs-home", {
243
+ * outDir: "./docs",
244
+ * title: "My Project Documentation",
245
+ * prompt: "Create a welcoming homepage for a JavaScript utility library with modern design"
246
+ * });
247
+ *
248
+ * @example
249
+ * // Create a home page with hero and features configuration
250
+ * const detailedHome = await HomePage("product-home", {
251
+ * outDir: "./website",
252
+ * title: "Product Landing Page",
253
+ * prompt: "Create an engaging product page for our cloud database service",
254
+ * hero: {
255
+ * name: "CloudDB",
256
+ * text: "The database built for the cloud era",
257
+ * tagline: "Scalable, reliable, and developer-friendly",
258
+ * image: "/images/cloud-db-logo.png",
259
+ * actions: [
260
+ * { text: "Get Started", link: "/guide/", theme: "brand" },
261
+ * { text: "View on GitHub", link: "https://github.com/org/cloud-db" }
262
+ * ]
263
+ * },
264
+ * features: [
265
+ * {
266
+ * icon: "🚀",
267
+ * title: "Lightning Fast",
268
+ * details: "Optimized for performance at any scale"
269
+ * },
270
+ * {
271
+ * icon: "🔒",
272
+ * title: "Secure by Default",
273
+ * details: "Enterprise-grade security built in"
274
+ * }
275
+ * ]
276
+ * });
277
+ *
278
+ * @example
279
+ * // Create a home page with custom model settings
280
+ * const customHome = await HomePage("docs-home", {
281
+ * outDir: "./docs",
282
+ * title: "API Documentation",
283
+ * prompt: "Create a technical homepage for our REST API documentation",
284
+ * model: {
285
+ * id: "gpt-4o",
286
+ * provider: "openai"
287
+ * },
288
+ * temperature: 0.3,
289
+ * systemPromptExtension: "Make sure to use technical terminology appropriate for developers."
290
+ * });
291
+ */
292
+ export async function HomePage(
293
+ id: string,
294
+ props: HomePageProps,
295
+ ): Promise<HomePage> {
296
+ // Build the system prompt with optional extension
297
+ const systemPrompt = `
298
+ You are creating a VitePress homepage (index.md file).
299
+
300
+ VitePress uses YAML frontmatter to configure the homepage.
301
+ The homepage must have "layout: home" in its frontmatter.
302
+
303
+ The homepage can include:
304
+ - A hero section with name, text, tagline, image, and action buttons
305
+ - A features section with multiple feature items (title, icon, details)
306
+ - Additional markdown content below the frontmatter
307
+
308
+ Follow these guidelines:
309
+ 1. Start with YAML frontmatter (--- at beginning and end)
310
+ 2. Include "layout: home" in the frontmatter
311
+ 3. Use the provided hero and features configuration if supplied
312
+ 4. Add any additional sections or content based on the user's prompt
313
+ 5. Create visually appealing, well-structured content
314
+ 6. Ensure all links are properly formatted
315
+ 7. Use appropriate markdown formatting for headings, lists, etc.
316
+
317
+ ${props.system || ""}
318
+ `;
319
+
320
+ // Convert hero and features to YAML strings if provided
321
+ const heroYaml = props.hero ? JSON.stringify(props.hero, null, 2) : "";
322
+ const featuresYaml = props.features
323
+ ? JSON.stringify(props.features, null, 2)
324
+ : "";
325
+
326
+ if (props.prompt) {
327
+ return Document(id, {
328
+ title: props.title,
329
+ path: props.outFile,
330
+ baseURL: props.baseURL,
331
+ apiKey: props.apiKey,
332
+ model: props.model ?? {
333
+ id: "claude-3-7-sonnet-latest",
334
+ provider: "anthropic",
335
+ },
336
+ temperature: props.temperature ?? 0.7,
337
+ prompt: await alchemy`
338
+ ${systemPrompt}
339
+
340
+ Create a VitePress homepage based on the following description:
341
+ ${props.prompt}
342
+
343
+ ${
344
+ props.hero
345
+ ? `Use this hero section configuration:
346
+ \`\`\`json
347
+ ${heroYaml}
348
+ \`\`\``
349
+ : ""
350
+ }
351
+
352
+ ${
353
+ props.features
354
+ ? `Use these features:
355
+ \`\`\`json
356
+ ${featuresYaml}
357
+ \`\`\``
358
+ : ""
359
+ }
360
+
361
+ The output should be a complete index.md file with proper YAML frontmatter and markdown content.
362
+ `,
363
+ });
364
+ } else {
365
+ return StaticTextFile(id, props.outFile, `---
366
+ ${yaml.stringify({
367
+ layout: "home",
368
+ name: props.title,
369
+ hero: props.hero,
370
+ features: props.features,
371
+ })}
372
+ ---
373
+ `);
374
+ }
375
+ }
@@ -1,2 +1,4 @@
1
+ export * from "./config";
2
+ export * from "./custom-theme";
1
3
  export * from "./home-page";
2
4
  export * from "./vitepress";
@@ -2,13 +2,15 @@ import { exec } from "child_process";
2
2
  import fs from "fs/promises";
3
3
  import path from "path";
4
4
  import { promisify } from "util";
5
- import type { DefaultTheme, ThemeOptions } from "vitepress";
6
- import yaml from "yaml";
7
- import type { Context } from "../context";
8
- import { Folder, JsonFile, TextFile, TypeScriptFile } from "../fs";
9
- import { Resource } from "../resource";
5
+ import type { Context } from "../../context";
6
+ import {
7
+ Folder,
8
+ StaticJsonFile,
9
+ StaticTextFile,
10
+ StaticTypeScriptFile,
11
+ } from "../../fs";
12
+ import { Resource } from "../../resource";
10
13
  import { InstallDependencies, fixedDependencies } from "./dependencies";
11
- import type { HomePage } from "./home-page";
12
14
 
13
15
  const execAsync = promisify(exec);
14
16
 
@@ -34,6 +36,14 @@ export interface VitePressProjectProps {
34
36
  */
35
37
  typescript?: boolean;
36
38
 
39
+ /**
40
+ * The scripts to add to the project
41
+ */
42
+ scripts?: Record<string, string>;
43
+
44
+ /**
45
+ * The tsconfig to use
46
+ */
37
47
  tsconfig?: {
38
48
  extends?: string;
39
49
  references?: string[];
@@ -59,17 +69,12 @@ export interface VitePressProjectProps {
59
69
  /**
60
70
  * The theme options to use
61
71
  */
62
- theme?: ThemeOptions;
72
+ // theme?: ThemeOptions;
63
73
 
64
74
  /**
65
75
  * The theme config to use
66
76
  */
67
- themeConfig: DefaultTheme.Config;
68
-
69
- /**
70
- * The home page configuration
71
- */
72
- home: HomePage;
77
+ // themeConfig: DefaultTheme.Config;
73
78
 
74
79
  /**
75
80
  * Whether to delete the project folder during the delete phase
@@ -78,7 +83,7 @@ export interface VitePressProjectProps {
78
83
  delete?: boolean;
79
84
 
80
85
  /**
81
- * The directory to generate the docs in
86
+ * The directory to initialize the project in.
82
87
  *
83
88
  * @default {@link name}
84
89
  */
@@ -90,17 +95,22 @@ export interface VitePressProject extends VitePressProjectProps, Resource {
90
95
  * The name/path of the project
91
96
  */
92
97
  name: string;
98
+
99
+ /**
100
+ * The directory of the project
101
+ */
102
+ dir: string;
93
103
  }
94
104
 
95
- export const VitePressProject = Resource(
96
- "project::VitePressProject",
105
+ export const VitepressProject = Resource(
106
+ "project::VitepressProject",
97
107
  {
98
108
  alwaysUpdate: true,
99
109
  },
100
110
  async function (
101
111
  this: Context<VitePressProject>,
102
112
  id: string,
103
- props: VitePressProjectProps,
113
+ props: VitePressProjectProps
104
114
  ): Promise<VitePressProject> {
105
115
  const dir = props.dir ?? props.name;
106
116
  if (this.phase === "delete") {
@@ -117,21 +127,25 @@ export const VitePressProject = Resource(
117
127
  return this.destroy();
118
128
  }
119
129
 
120
- const cwd = (
121
- await Folder("dir", {
122
- path: dir,
123
- delete: props.delete,
124
- })
125
- ).path;
130
+ const cwd = path.relative(
131
+ process.cwd(),
132
+ (
133
+ await Folder("dir", {
134
+ path: dir,
135
+ delete: props.delete,
136
+ })
137
+ ).path
138
+ );
126
139
 
127
140
  // Initialize package.json
128
- await JsonFile(path.join(cwd, "package.json"), {
141
+ await StaticJsonFile(path.join(cwd, "package.json"), {
129
142
  name: props.name,
130
143
  scripts: {
131
144
  "docs:gen": "bun alchemy.run.ts",
132
145
  "docs:dev": "vitepress dev",
133
146
  "docs:build": "vitepress build",
134
147
  "docs:preview": "vitepress preview",
148
+ ...props.scripts,
135
149
  },
136
150
  dependencies: fixedDependencies(props.dependencies || {}),
137
151
  devDependencies: fixedDependencies(props.devDependencies || {}),
@@ -153,16 +167,21 @@ export const VitePressProject = Resource(
153
167
  await Folder(path.join(cwd, ".vitepress", "theme"));
154
168
 
155
169
  await Promise.all([
156
- TextFile(path.join(cwd, ".gitignore"), `.vitepress/cache\n`),
157
- JsonFile(path.join(cwd, "tsconfig.json"), {
158
- extends: props.tsconfig?.extends,
159
- references: props.tsconfig?.references?.map((path) => ({ path })),
160
- compilerOptions: props.tsconfig?.compilerOptions,
161
- }),
162
- TextFile(
163
- path.join(cwd, "index.md"),
164
- `---\n${yaml.stringify(props.home)}---\n`,
165
- ),
170
+ StaticTextFile(path.join(cwd, ".gitignore"), `.vitepress/cache\n`),
171
+ // StaticJsonFile(path.join(cwd, "tsconfig.json"), {
172
+ // extends: props.tsconfig?.extends,
173
+ // references: props.tsconfig?.references?.map((path) => ({ path })),
174
+ // compilerOptions: props.tsconfig?.compilerOptions ?? {
175
+ // target: "ES2020",
176
+ // module: "ESNext",
177
+ // moduleResolution: "Node",
178
+ // allowJs: true,
179
+ // skipLibCheck: true,
180
+ // forceConsistentCasingInFileNames: true,
181
+
182
+ // },
183
+ // }),
184
+
166
185
  // TypeScriptFile(
167
186
  // path.join(cwd, "alchemy.run.ts"),
168
187
  // `import alchemy from "alchemy";
@@ -185,7 +204,7 @@ export const VitePressProject = Resource(
185
204
  // });
186
205
  // `,
187
206
  // ),
188
- TypeScriptFile(
207
+ StaticTypeScriptFile(
189
208
  path.join(cwd, ".vitepress", "theme", "index.ts"),
190
209
  `import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
191
210
  import "@shikijs/vitepress-twoslash/style.css";
@@ -199,9 +218,9 @@ export default {
199
218
  ctx.app.use(TwoslashFloatingVue);
200
219
  },
201
220
  } satisfies ThemeConfig;
202
- `,
221
+ `
203
222
  ),
204
- TextFile(
223
+ StaticTextFile(
205
224
  path.join(cwd, ".vitepress", "theme", "style.css"),
206
225
  `/**
207
226
  * Customize default theme styling by overriding CSS variables:
@@ -341,42 +360,13 @@ export default {
341
360
  .DocSearch {
342
361
  --docsearch-primary-color: var(--vp-c-brand-1) !important;
343
362
  }
344
- `,
345
- ),
346
- TypeScriptFile(
347
- path.join(cwd, ".vitepress", "config.mts"),
348
- `import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
349
- import footnotePlugin from "markdown-it-footnote";
350
- import { defineConfig } from "vitepress";
351
-
352
- // https://vitepress.dev/reference/site-config
353
- export default defineConfig({
354
- title: ${JSON.stringify(props.title || "Alchemy")},
355
- description: ${JSON.stringify(props.description || "Alchemy Docs")},
356
- markdown: {
357
- // @ts-ignore
358
- codeTransformers: [transformerTwoslash()],
359
- theme: ${JSON.stringify(
360
- props.theme ?? {
361
- light: "light-plus",
362
- dark: "dark-plus",
363
- },
364
- )},
365
- config: (md) => md.use(footnotePlugin),
366
- },
367
- // https://vitepress.dev/reference/default-theme-config
368
- themeConfig: ${JSON.stringify({
369
- ...props.themeConfig,
370
- search: props.themeConfig.search ?? { provider: "local" },
371
- nav: props.themeConfig.nav ?? [{ text: "Home", link: "/" }],
372
- sidebar: props.themeConfig.sidebar ?? [],
373
- socialLinks: props.themeConfig.socialLinks ?? [],
374
- })}
375
- });
376
- `,
363
+ `
377
364
  ),
378
365
  ]);
379
366
 
380
- return this(props);
381
- },
367
+ return this({
368
+ ...props,
369
+ dir,
370
+ });
371
+ }
382
372
  );
@@ -1,82 +0,0 @@
1
- import type { KVNamespace } from "@cloudflare/workers-types";
2
- import type { State, StateStore } from "../state";
3
- /**
4
- * Options for CloudflareStateStore
5
- */
6
- export interface CloudflareStateStoreOptions {
7
- /**
8
- * The prefix to use for keys in the KV namespace
9
- * This allows multiple state stores to use the same KV namespace
10
- */
11
- prefix?: string;
12
- }
13
- /**
14
- * State store implementation using Cloudflare KV Namespace
15
- */
16
- export declare class CloudflareStateStore implements StateStore {
17
- private namespace;
18
- private prefix;
19
- /**
20
- * Create a new CloudflareStateStore
21
- *
22
- * @param namespace The KV namespace to use for storing state
23
- * @param options Options for the state store
24
- */
25
- constructor(namespace: KVNamespace, options?: CloudflareStateStoreOptions);
26
- /**
27
- * No initialization needed for KV namespaces as they are pre-provisioned
28
- */
29
- init(): Promise<void>;
30
- /**
31
- * KV namespaces cannot be deleted programmatically
32
- */
33
- deinit(): Promise<void>;
34
- /**
35
- * List all resources in the state store
36
- */
37
- list(): Promise<string[]>;
38
- /**
39
- * Count the number of items in the state store
40
- */
41
- count(): Promise<number>;
42
- /**
43
- * Get a state by key
44
- *
45
- * @param key The key to look up
46
- * @returns The state or undefined if not found
47
- */
48
- get(key: string): Promise<State | undefined>;
49
- /**
50
- * Get multiple states by their keys
51
- *
52
- * @param ids Array of keys to fetch
53
- * @returns Record mapping keys to their states
54
- */
55
- getBatch(ids: string[]): Promise<Record<string, State>>;
56
- /**
57
- * Get all states in the store
58
- *
59
- * @returns Record mapping all keys to their states
60
- */
61
- all(): Promise<Record<string, State>>;
62
- /**
63
- * Set a state for a key
64
- *
65
- * @param key The key to set
66
- * @param value The state to store
67
- */
68
- set(key: string, value: State): Promise<void>;
69
- /**
70
- * Delete a state by key
71
- *
72
- * @param key The key to delete
73
- */
74
- delete(key: string): Promise<void>;
75
- /**
76
- * Get the namespaced key for storage
77
- *
78
- * @param key The original key
79
- * @returns The key with prefix for use in the KV namespace
80
- */
81
- private getNamespacedKey;
82
- }