alchemy 0.2.2 → 0.2.4
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/lib/ai/ark.d.ts +11 -0
- package/lib/ai/ark.js +86 -0
- package/lib/ai/client.d.ts +51 -0
- package/lib/ai/client.js +29 -0
- package/lib/ai/document.d.ts +97 -0
- package/lib/ai/document.js +82 -0
- package/lib/ai/index.d.ts +2 -0
- package/lib/ai/index.js +2 -0
- package/lib/ai/object.d.ts +101 -0
- package/lib/ai/object.js +70 -0
- package/lib/alchemy.d.ts +84 -2
- package/lib/alchemy.js +114 -10
- package/lib/apply.d.ts +1 -1
- package/lib/apply.js +13 -10
- package/lib/aws/bucket.d.ts +87 -1
- package/lib/aws/bucket.js +48 -1
- package/lib/aws/function.d.ts +186 -1
- package/lib/aws/function.js +62 -8
- package/lib/aws/oidc/github-oidc-provider.d.ts +81 -0
- package/lib/aws/oidc/github-oidc-provider.js +68 -0
- package/lib/aws/oidc/oidc-provider.d.ts +14 -6
- package/lib/aws/oidc/oidc-provider.js +26 -5
- package/lib/aws/policy-attachment.d.ts +44 -1
- package/lib/aws/policy-attachment.js +31 -0
- package/lib/aws/policy.d.ts +160 -1
- package/lib/aws/policy.js +78 -0
- package/lib/aws/queue.d.ts +83 -1
- package/lib/aws/queue.js +39 -0
- package/lib/aws/role.d.ts +162 -1
- package/lib/aws/role.js +114 -0
- package/lib/aws/ses.d.ts +57 -2
- package/lib/aws/ses.js +42 -1
- package/lib/aws/table.d.ts +96 -1
- package/lib/aws/table.js +36 -0
- package/lib/cloudflare/asset-manifest.js +0 -1
- package/lib/cloudflare/bound.js +0 -1
- package/lib/cloudflare/bucket.d.ts +37 -1
- package/lib/cloudflare/bucket.js +36 -0
- package/lib/cloudflare/durable-object-namespace.d.ts +25 -0
- package/lib/cloudflare/durable-object-namespace.js +22 -0
- package/lib/cloudflare/kv-namespace.d.ts +37 -1
- package/lib/cloudflare/kv-namespace.js +36 -0
- package/lib/cloudflare/static-site.d.ts +53 -1
- package/lib/cloudflare/static-site.js +53 -1
- package/lib/cloudflare/worker-metadata.js +0 -1
- package/lib/cloudflare/worker.d.ts +64 -1
- package/lib/cloudflare/worker.js +63 -0
- package/lib/cloudflare/wrangler.json.d.ts +1 -1
- package/lib/cloudflare/zone-settings.js +0 -1
- package/lib/cloudflare/zone.d.ts +56 -1
- package/lib/cloudflare/zone.js +55 -0
- package/lib/context.d.ts +9 -4
- package/lib/context.js +4 -2
- package/lib/destroy.js +9 -8
- package/lib/esbuild/bundle.d.ts +43 -4
- package/lib/esbuild/bundle.js +16 -0
- package/lib/fs/file-collection.d.ts +16 -0
- package/lib/fs/file-collection.js +6 -0
- package/lib/fs/file-ref.d.ts +14 -0
- package/lib/fs/file-ref.js +6 -0
- package/lib/fs/file.d.ts +78 -5
- package/lib/fs/file.js +39 -3
- package/lib/fs/folder.d.ts +37 -5
- package/lib/fs/folder.js +28 -3
- package/lib/fs/index.d.ts +6 -0
- package/lib/fs/index.js +6 -0
- package/lib/fs/json-file.d.ts +16 -0
- package/lib/fs/json-file.js +7 -0
- package/lib/fs/text-file.d.ts +12 -0
- package/lib/fs/text-file.js +7 -0
- package/lib/fs/typescript-file.d.ts +19 -0
- package/lib/fs/typescript-file.js +14 -0
- package/lib/fs/yaml-file.d.ts +19 -0
- package/lib/fs/yaml-file.js +8 -0
- package/lib/github/secret.d.ts +63 -2
- package/lib/github/secret.js +61 -1
- package/lib/internal/docs.d.ts +5 -0
- package/lib/internal/docs.js +324 -0
- package/lib/resource.d.ts +2 -2
- package/lib/resource.js +4 -0
- package/lib/scope.d.ts +1 -1
- package/lib/scope.js +6 -6
- package/lib/secret.d.ts +67 -0
- package/lib/secret.js +67 -0
- package/lib/shadcn/component.d.ts +1 -1
- package/lib/state.d.ts +1 -1
- package/lib/state.js +8 -1
- package/lib/stripe/price.d.ts +51 -1
- package/lib/stripe/price.js +50 -0
- package/lib/stripe/product.d.ts +39 -1
- package/lib/stripe/product.js +38 -0
- package/lib/stripe/webhook.d.ts +46 -1
- package/lib/stripe/webhook.js +45 -0
- package/lib/test/bun.d.ts +64 -0
- package/lib/test/bun.js +35 -3
- package/lib/util/serde.d.ts +3 -1
- package/lib/util/serde.js +20 -4
- package/lib/vite/vite.d.ts +1 -1
- package/lib/vitepress/dependencies.d.ts +12 -0
- package/lib/vitepress/dependencies.js +35 -0
- package/lib/vitepress/home-page.d.ts +133 -0
- package/lib/vitepress/home-page.js +11 -0
- package/lib/vitepress/index.d.ts +2 -0
- package/lib/vitepress/index.js +2 -0
- package/lib/vitepress/vitepress.d.ts +71 -0
- package/lib/vitepress/vitepress.js +266 -0
- package/package.json +22 -10
- package/src/ai/ark.ts +118 -0
- package/src/ai/client.ts +78 -0
- package/src/ai/document.ts +160 -0
- package/src/ai/index.ts +2 -0
- package/src/ai/object.ts +149 -0
- package/src/alchemy.ts +192 -17
- package/src/apply.ts +25 -13
- package/src/aws/bucket.ts +111 -7
- package/src/aws/function.ts +231 -10
- package/src/aws/oidc/github-oidc-provider.ts +83 -0
- package/src/aws/oidc/oidc-provider.ts +39 -7
- package/src/aws/policy-attachment.ts +44 -1
- package/src/aws/policy.ts +177 -2
- package/src/aws/queue.ts +89 -0
- package/src/aws/role.ts +174 -2
- package/src/aws/ses.ts +56 -1
- package/src/aws/table.ts +103 -0
- package/src/cloudflare/bucket.ts +36 -0
- package/src/cloudflare/durable-object-namespace.ts +25 -0
- package/src/cloudflare/kv-namespace.ts +36 -0
- package/src/cloudflare/static-site.ts +53 -1
- package/src/cloudflare/worker.ts +63 -0
- package/src/cloudflare/zone.ts +55 -0
- package/src/context.ts +30 -10
- package/src/destroy.ts +11 -8
- package/src/esbuild/bundle.ts +53 -3
- package/src/fs/file-collection.ts +24 -0
- package/src/fs/file-ref.ts +22 -0
- package/src/fs/file.ts +107 -6
- package/src/fs/folder.ts +45 -5
- package/src/fs/index.ts +6 -0
- package/src/fs/json-file.ts +23 -0
- package/src/fs/text-file.ts +19 -0
- package/src/fs/typescript-file.ts +36 -0
- package/src/fs/yaml-file.ts +26 -0
- package/src/github/secret.ts +65 -2
- package/src/internal/docs.ts +369 -0
- package/src/resource.ts +7 -2
- package/src/scope.ts +9 -9
- package/src/secret.ts +67 -0
- package/src/state.ts +9 -2
- package/src/stripe/price.ts +50 -0
- package/src/stripe/product.ts +38 -0
- package/src/stripe/webhook.ts +45 -0
- package/src/test/bun.ts +83 -3
- package/src/util/serde.ts +30 -4
- package/src/vitepress/dependencies.ts +68 -0
- package/src/vitepress/home-page.ts +166 -0
- package/src/vitepress/index.md +75 -0
- package/src/vitepress/index.ts +2 -0
- package/src/vitepress/vitepress.ts +382 -0
- package/lib/project/vite.d.ts +0 -90
- package/lib/project/vite.js +0 -228
- package/src/project/vite.ts +0 -406
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { exec } from "child_process";
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
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";
|
|
10
|
+
import { InstallDependencies, fixedDependencies } from "./dependencies";
|
|
11
|
+
import type { HomePage } from "./home-page";
|
|
12
|
+
|
|
13
|
+
const execAsync = promisify(exec);
|
|
14
|
+
|
|
15
|
+
export interface VitePressProjectProps {
|
|
16
|
+
/**
|
|
17
|
+
* The name/path of the project
|
|
18
|
+
*/
|
|
19
|
+
name: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The title of the documentation site
|
|
23
|
+
*/
|
|
24
|
+
title?: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The description of the documentation site
|
|
28
|
+
*/
|
|
29
|
+
description?: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether to use TypeScript for config and theme files
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
typescript?: boolean;
|
|
36
|
+
|
|
37
|
+
tsconfig?: {
|
|
38
|
+
extends?: string;
|
|
39
|
+
references?: string[];
|
|
40
|
+
compilerOptions?: Record<string, any>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Force overwrite the project config files during the update phase
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
47
|
+
overwrite?: boolean;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The dependencies to install
|
|
51
|
+
*/
|
|
52
|
+
dependencies?: Record<string, string>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The dev dependencies to install
|
|
56
|
+
*/
|
|
57
|
+
devDependencies?: Record<string, string>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The theme options to use
|
|
61
|
+
*/
|
|
62
|
+
theme?: ThemeOptions;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The theme config to use
|
|
66
|
+
*/
|
|
67
|
+
themeConfig: DefaultTheme.Config;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The home page configuration
|
|
71
|
+
*/
|
|
72
|
+
home: HomePage;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Whether to delete the project folder during the delete phase
|
|
76
|
+
* @default true
|
|
77
|
+
*/
|
|
78
|
+
delete?: boolean;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The directory to generate the docs in
|
|
82
|
+
*
|
|
83
|
+
* @default {@link name}
|
|
84
|
+
*/
|
|
85
|
+
dir?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface VitePressProject extends VitePressProjectProps, Resource {
|
|
89
|
+
/**
|
|
90
|
+
* The name/path of the project
|
|
91
|
+
*/
|
|
92
|
+
name: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const VitePressProject = Resource(
|
|
96
|
+
"project::VitePressProject",
|
|
97
|
+
{
|
|
98
|
+
alwaysUpdate: true,
|
|
99
|
+
},
|
|
100
|
+
async function (
|
|
101
|
+
this: Context<VitePressProject>,
|
|
102
|
+
id: string,
|
|
103
|
+
props: VitePressProjectProps,
|
|
104
|
+
): Promise<VitePressProject> {
|
|
105
|
+
const dir = props.dir ?? props.name;
|
|
106
|
+
if (this.phase === "delete") {
|
|
107
|
+
try {
|
|
108
|
+
if (props.delete !== false) {
|
|
109
|
+
if (await fs.exists(dir)) {
|
|
110
|
+
// Delete the entire project directory
|
|
111
|
+
await execAsync(`rm -rf ${dir}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error(`Error deleting VitePress project ${id}:`, error);
|
|
116
|
+
}
|
|
117
|
+
return this.destroy();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const cwd = (
|
|
121
|
+
await Folder("dir", {
|
|
122
|
+
path: dir,
|
|
123
|
+
delete: props.delete,
|
|
124
|
+
})
|
|
125
|
+
).path;
|
|
126
|
+
|
|
127
|
+
// Initialize package.json
|
|
128
|
+
await JsonFile(path.join(cwd, "package.json"), {
|
|
129
|
+
name: props.name,
|
|
130
|
+
scripts: {
|
|
131
|
+
"docs:gen": "bun alchemy.run.ts",
|
|
132
|
+
"docs:dev": "vitepress dev",
|
|
133
|
+
"docs:build": "vitepress build",
|
|
134
|
+
"docs:preview": "vitepress preview",
|
|
135
|
+
},
|
|
136
|
+
dependencies: fixedDependencies(props.dependencies || {}),
|
|
137
|
+
devDependencies: fixedDependencies(props.devDependencies || {}),
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
await InstallDependencies("dependencies", {
|
|
141
|
+
cwd,
|
|
142
|
+
dependencies: props.dependencies,
|
|
143
|
+
devDependencies: {
|
|
144
|
+
vue: "latest",
|
|
145
|
+
vitepress: "latest",
|
|
146
|
+
"@shikijs/vitepress-twoslash": "latest",
|
|
147
|
+
"markdown-it-footnote": "latest",
|
|
148
|
+
...props.devDependencies,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
// Create .vitepress directory and config
|
|
152
|
+
await Folder(path.join(cwd, ".vitepress"));
|
|
153
|
+
await Folder(path.join(cwd, ".vitepress", "theme"));
|
|
154
|
+
|
|
155
|
+
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
|
+
),
|
|
166
|
+
// TypeScriptFile(
|
|
167
|
+
// path.join(cwd, "alchemy.run.ts"),
|
|
168
|
+
// `import alchemy from "alchemy";
|
|
169
|
+
// import { Folder } from "alchemy/fs";
|
|
170
|
+
// import { Document } from "alchemy/docs";
|
|
171
|
+
// import path from "path";
|
|
172
|
+
|
|
173
|
+
// await using _ = alchemy("alchemy.run", {
|
|
174
|
+
// stage: "prod",
|
|
175
|
+
// phase: process.argv.includes("--destroy") ? "destroy" : "up",
|
|
176
|
+
// password: process.env.SECRET_PASSPHRASE,
|
|
177
|
+
// quiet: !process.argv.includes("--verbose"),
|
|
178
|
+
// });
|
|
179
|
+
|
|
180
|
+
// const docs = await Folder(path.join("alchemy.run", "docs"));
|
|
181
|
+
|
|
182
|
+
// await Document("home.md", {
|
|
183
|
+
// path: path.join(docs.path, "home.md"),
|
|
184
|
+
// prompt: await alchemy\`Generate a landing page.\`,
|
|
185
|
+
// });
|
|
186
|
+
// `,
|
|
187
|
+
// ),
|
|
188
|
+
TypeScriptFile(
|
|
189
|
+
path.join(cwd, ".vitepress", "theme", "index.ts"),
|
|
190
|
+
`import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
|
|
191
|
+
import "@shikijs/vitepress-twoslash/style.css";
|
|
192
|
+
import type { Theme as ThemeConfig } from "vitepress";
|
|
193
|
+
import Theme from "vitepress/theme-without-fonts";
|
|
194
|
+
import "./style.css";
|
|
195
|
+
|
|
196
|
+
export default {
|
|
197
|
+
extends: Theme,
|
|
198
|
+
enhanceApp(ctx) {
|
|
199
|
+
ctx.app.use(TwoslashFloatingVue);
|
|
200
|
+
},
|
|
201
|
+
} satisfies ThemeConfig;
|
|
202
|
+
`,
|
|
203
|
+
),
|
|
204
|
+
TextFile(
|
|
205
|
+
path.join(cwd, ".vitepress", "theme", "style.css"),
|
|
206
|
+
`/**
|
|
207
|
+
* Customize default theme styling by overriding CSS variables:
|
|
208
|
+
* https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Colors
|
|
213
|
+
*
|
|
214
|
+
* Each colors have exact same color scale system with 3 levels of solid
|
|
215
|
+
* colors with different brightness, and 1 soft color.
|
|
216
|
+
*
|
|
217
|
+
* - \`XXX-1\`: The most solid color used mainly for colored text. It must
|
|
218
|
+
* satisfy the contrast ratio against when used on top of \`XXX-soft\`.
|
|
219
|
+
*
|
|
220
|
+
* - \`XXX-2\`: The color used mainly for hover state of the button.
|
|
221
|
+
*
|
|
222
|
+
* - \`XXX-3\`: The color for solid background, such as bg color of the button.
|
|
223
|
+
* It must satisfy the contrast ratio with pure white (#ffffff) text on
|
|
224
|
+
* top of it.
|
|
225
|
+
*
|
|
226
|
+
* - \`XXX-soft\`: The color used for subtle background such as custom container
|
|
227
|
+
* or badges. It must satisfy the contrast ratio when putting \`XXX-1\` colors
|
|
228
|
+
* on top of it.
|
|
229
|
+
*
|
|
230
|
+
* The soft color must be semi transparent alpha channel. This is crucial
|
|
231
|
+
* because it allows adding multiple "soft" colors on top of each other
|
|
232
|
+
* to create a accent, such as when having inline code block inside
|
|
233
|
+
* custom containers.
|
|
234
|
+
*
|
|
235
|
+
* - \`default\`: The color used purely for subtle indication without any
|
|
236
|
+
* special meanings attached to it such as bg color for menu hover state.
|
|
237
|
+
*
|
|
238
|
+
* - \`brand\`: Used for primary brand colors, such as link text, button with
|
|
239
|
+
* brand theme, etc.
|
|
240
|
+
*
|
|
241
|
+
* - \`tip\`: Used to indicate useful information. The default theme uses the
|
|
242
|
+
* brand color for this by default.
|
|
243
|
+
*
|
|
244
|
+
* - \`warning\`: Used to indicate warning to the users. Used in custom
|
|
245
|
+
* container, badges, etc.
|
|
246
|
+
*
|
|
247
|
+
* - \`danger\`: Used to show error, or dangerous message to the users. Used
|
|
248
|
+
* in custom container, badges, etc.
|
|
249
|
+
* -------------------------------------------------------------------------- */
|
|
250
|
+
|
|
251
|
+
:root {
|
|
252
|
+
--vp-c-default-1: var(--vp-c-gray-1);
|
|
253
|
+
--vp-c-default-2: var(--vp-c-gray-2);
|
|
254
|
+
--vp-c-default-3: var(--vp-c-gray-3);
|
|
255
|
+
--vp-c-default-soft: var(--vp-c-gray-soft);
|
|
256
|
+
|
|
257
|
+
--vp-c-brand-1: var(--vp-c-indigo-1);
|
|
258
|
+
--vp-c-brand-2: var(--vp-c-indigo-2);
|
|
259
|
+
--vp-c-brand-3: var(--vp-c-indigo-3);
|
|
260
|
+
--vp-c-brand-soft: var(--vp-c-indigo-soft);
|
|
261
|
+
|
|
262
|
+
--vp-c-tip-1: var(--vp-c-brand-1);
|
|
263
|
+
--vp-c-tip-2: var(--vp-c-brand-2);
|
|
264
|
+
--vp-c-tip-3: var(--vp-c-brand-3);
|
|
265
|
+
--vp-c-tip-soft: var(--vp-c-brand-soft);
|
|
266
|
+
|
|
267
|
+
--vp-c-warning-1: var(--vp-c-yellow-1);
|
|
268
|
+
--vp-c-warning-2: var(--vp-c-yellow-2);
|
|
269
|
+
--vp-c-warning-3: var(--vp-c-yellow-3);
|
|
270
|
+
--vp-c-warning-soft: var(--vp-c-yellow-soft);
|
|
271
|
+
|
|
272
|
+
--vp-c-danger-1: var(--vp-c-red-1);
|
|
273
|
+
--vp-c-danger-2: var(--vp-c-red-2);
|
|
274
|
+
--vp-c-danger-3: var(--vp-c-red-3);
|
|
275
|
+
--vp-c-danger-soft: var(--vp-c-red-soft);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Component: Button
|
|
280
|
+
* -------------------------------------------------------------------------- */
|
|
281
|
+
|
|
282
|
+
:root {
|
|
283
|
+
--vp-button-brand-border: transparent;
|
|
284
|
+
--vp-button-brand-text: var(--vp-c-white);
|
|
285
|
+
--vp-button-brand-bg: var(--vp-c-brand-3);
|
|
286
|
+
--vp-button-brand-hover-border: transparent;
|
|
287
|
+
--vp-button-brand-hover-text: var(--vp-c-white);
|
|
288
|
+
--vp-button-brand-hover-bg: var(--vp-c-brand-2);
|
|
289
|
+
--vp-button-brand-active-border: transparent;
|
|
290
|
+
--vp-button-brand-active-text: var(--vp-c-white);
|
|
291
|
+
--vp-button-brand-active-bg: var(--vp-c-brand-1);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Component: Home
|
|
296
|
+
* -------------------------------------------------------------------------- */
|
|
297
|
+
|
|
298
|
+
:root {
|
|
299
|
+
--vp-home-hero-name-color: transparent;
|
|
300
|
+
--vp-home-hero-name-background: -webkit-linear-gradient(
|
|
301
|
+
120deg,
|
|
302
|
+
#bd34fe 30%,
|
|
303
|
+
#41d1ff
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
--vp-home-hero-image-background-image: linear-gradient(
|
|
307
|
+
-45deg,
|
|
308
|
+
#bd34fe 50%,
|
|
309
|
+
#47caff 50%
|
|
310
|
+
);
|
|
311
|
+
--vp-home-hero-image-filter: blur(44px);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
@media (min-width: 640px) {
|
|
315
|
+
:root {
|
|
316
|
+
--vp-home-hero-image-filter: blur(56px);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
@media (min-width: 960px) {
|
|
321
|
+
:root {
|
|
322
|
+
--vp-home-hero-image-filter: blur(68px);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Component: Custom Block
|
|
328
|
+
* -------------------------------------------------------------------------- */
|
|
329
|
+
|
|
330
|
+
:root {
|
|
331
|
+
--vp-custom-block-tip-border: transparent;
|
|
332
|
+
--vp-custom-block-tip-text: var(--vp-c-text-1);
|
|
333
|
+
--vp-custom-block-tip-bg: var(--vp-c-brand-soft);
|
|
334
|
+
--vp-custom-block-tip-code-bg: var(--vp-c-brand-soft);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Component: Algolia
|
|
339
|
+
* -------------------------------------------------------------------------- */
|
|
340
|
+
|
|
341
|
+
.DocSearch {
|
|
342
|
+
--docsearch-primary-color: var(--vp-c-brand-1) !important;
|
|
343
|
+
}
|
|
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
|
+
`,
|
|
377
|
+
),
|
|
378
|
+
]);
|
|
379
|
+
|
|
380
|
+
return this(props);
|
|
381
|
+
},
|
|
382
|
+
);
|
package/lib/project/vite.d.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import type { Context } from "../context";
|
|
2
|
-
import { Resource } from "../resource";
|
|
3
|
-
type ViteTemplate = "vanilla" | "vanilla-ts" | "vue" | "vue-ts" | "react" | "react-ts" | "react-swc" | "react-swc-ts" | "preact" | "preact-ts" | "lit" | "lit-ts" | "svelte" | "svelte-ts" | "solid" | "solid-ts" | "qwik" | "qwik-ts";
|
|
4
|
-
export interface ViteProjectProps {
|
|
5
|
-
/**
|
|
6
|
-
* The name/path of the project
|
|
7
|
-
*/
|
|
8
|
-
name: string;
|
|
9
|
-
/**
|
|
10
|
-
* The Vite template to use
|
|
11
|
-
*/
|
|
12
|
-
template: ViteTemplate;
|
|
13
|
-
/**
|
|
14
|
-
* The extends to add to the tsconfig.json file
|
|
15
|
-
*/
|
|
16
|
-
extends?: string;
|
|
17
|
-
/**
|
|
18
|
-
* The references to add to the tsconfig.json file
|
|
19
|
-
*/
|
|
20
|
-
references?: string[];
|
|
21
|
-
/**
|
|
22
|
-
* Add Tailwind CSS to the project
|
|
23
|
-
* @default false
|
|
24
|
-
*/
|
|
25
|
-
tailwind?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Add Tanstack Router to the project
|
|
28
|
-
* @default false
|
|
29
|
-
*/
|
|
30
|
-
tanstack?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Add Shadcn UI to the project
|
|
33
|
-
* @default false
|
|
34
|
-
*/
|
|
35
|
-
shadcn?: {
|
|
36
|
-
/**
|
|
37
|
-
* The base color to use
|
|
38
|
-
* @default "neutral"
|
|
39
|
-
*/
|
|
40
|
-
baseColor?: "neutral" | "gray" | "zinc" | "stone" | "slate";
|
|
41
|
-
/**
|
|
42
|
-
* Use default configuration
|
|
43
|
-
* @default false
|
|
44
|
-
*/
|
|
45
|
-
defaults?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Force overwrite of existing configuration
|
|
48
|
-
* @default false
|
|
49
|
-
*/
|
|
50
|
-
force?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* The working directory
|
|
53
|
-
* @default current directory
|
|
54
|
-
*/
|
|
55
|
-
cwd?: string;
|
|
56
|
-
/**
|
|
57
|
-
* Mute output
|
|
58
|
-
* @default false
|
|
59
|
-
*/
|
|
60
|
-
silent?: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Use the src directory when creating a new project
|
|
63
|
-
* @default false
|
|
64
|
-
*/
|
|
65
|
-
srcDir?: boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Use css variables for theming
|
|
68
|
-
* @default true
|
|
69
|
-
*/
|
|
70
|
-
cssVariables?: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* The components to add
|
|
73
|
-
*/
|
|
74
|
-
components?: string[];
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Force overwrite the project config files during the update phase
|
|
78
|
-
*
|
|
79
|
-
* @default false
|
|
80
|
-
*/
|
|
81
|
-
overwrite?: boolean;
|
|
82
|
-
}
|
|
83
|
-
export interface ViteProject extends ViteProjectProps, Resource {
|
|
84
|
-
/**
|
|
85
|
-
* The name/path of the project
|
|
86
|
-
*/
|
|
87
|
-
name: string;
|
|
88
|
-
}
|
|
89
|
-
export declare const ViteProject: ((this: Context<ViteProject>, id: string, props: ViteProjectProps) => Promise<ViteProject>) | (((this: any, id: string, props: ViteProjectProps) => never) & (new (_: never) => never));
|
|
90
|
-
export {};
|
package/lib/project/vite.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import { exec } from "child_process";
|
|
2
|
-
import fs from "fs/promises";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { promisify } from "util";
|
|
5
|
-
import { Resource } from "../resource";
|
|
6
|
-
import { ShadcnComponent } from "../shadcn/component";
|
|
7
|
-
import { rm } from "../util/rm";
|
|
8
|
-
const execAsync = promisify(exec);
|
|
9
|
-
export const ViteProject = Resource("project::ViteProject", {
|
|
10
|
-
alwaysUpdate: true,
|
|
11
|
-
}, async function (id, props) {
|
|
12
|
-
const phase = this.phase;
|
|
13
|
-
if (this.phase === "delete") {
|
|
14
|
-
try {
|
|
15
|
-
if (await fs.exists(props.name)) {
|
|
16
|
-
// TODO: OS agnostic - fs.rm is slow to delete node_modules/
|
|
17
|
-
await execAsync("rm -rf " + props.name);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
console.error(`Error deleting project ${id}:`, error);
|
|
22
|
-
}
|
|
23
|
-
return this.destroy();
|
|
24
|
-
}
|
|
25
|
-
if (this.phase === "update") {
|
|
26
|
-
if (props.overwrite) {
|
|
27
|
-
await modifyConfig(props);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
console.warn("ViteProject does not support updates - the project must be recreated to change the template");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
await execAsync(`bun create vite ${id} --template ${props.template}`);
|
|
35
|
-
await modifyConfig(props);
|
|
36
|
-
}
|
|
37
|
-
return this(props);
|
|
38
|
-
async function modifyConfig(props) {
|
|
39
|
-
const tailwind = props.tailwind ?? false;
|
|
40
|
-
const tanstack = props.tanstack ?? false;
|
|
41
|
-
const plugins = [
|
|
42
|
-
tailwind && "tailwindcss()",
|
|
43
|
-
tanstack &&
|
|
44
|
-
"TanStackRouterVite({ target: 'react', autoCodeSplitting: true })",
|
|
45
|
-
"react()",
|
|
46
|
-
].filter((s) => typeof s === "string");
|
|
47
|
-
const cwd = path.resolve(process.cwd(), props.name);
|
|
48
|
-
const exec = (command) => execAsync(command, { cwd });
|
|
49
|
-
if (phase === "create" || props.overwrite) {
|
|
50
|
-
await removeUnnecessaryFiles();
|
|
51
|
-
}
|
|
52
|
-
await patchTsConfig();
|
|
53
|
-
if (props.tailwind) {
|
|
54
|
-
await installTailwind();
|
|
55
|
-
}
|
|
56
|
-
if (props.tanstack) {
|
|
57
|
-
await installTanstack();
|
|
58
|
-
}
|
|
59
|
-
if (props.shadcn !== undefined) {
|
|
60
|
-
await installShadcn();
|
|
61
|
-
}
|
|
62
|
-
await build();
|
|
63
|
-
async function build() {
|
|
64
|
-
// tsc -b will fail if we have not invoked tan stacks' code gen
|
|
65
|
-
await execAsync(`bun vite build`, { cwd: props.name });
|
|
66
|
-
}
|
|
67
|
-
async function installTailwind() {
|
|
68
|
-
await exec(`bun add tailwindcss @tailwindcss/vite`);
|
|
69
|
-
await fs.writeFile(path.join(props.name, "vite.config.ts"), `import path from "path";
|
|
70
|
-
import react from "@vitejs/plugin-react";
|
|
71
|
-
import { defineConfig } from "vite";
|
|
72
|
-
${tailwind ? "import tailwindcss from '@tailwindcss/vite';" : ""}
|
|
73
|
-
${tanstack ? 'import { TanStackRouterVite } from "@tanstack/router-plugin/vite";' : ""}
|
|
74
|
-
|
|
75
|
-
// https://vite.dev/config/
|
|
76
|
-
export default defineConfig({
|
|
77
|
-
plugins: [${plugins.join(", ")}],
|
|
78
|
-
resolve: {
|
|
79
|
-
alias: {
|
|
80
|
-
"@": path.resolve(__dirname, "./src"),
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
});`);
|
|
84
|
-
// Add Tailwind CSS import to index.css
|
|
85
|
-
const indexCssPath = path.join(props.name, "src", "index.css");
|
|
86
|
-
const currentCss = await fs.readFile(indexCssPath, "utf-8");
|
|
87
|
-
if (!currentCss.includes('@import "tailwindcss";')) {
|
|
88
|
-
await fs.writeFile(indexCssPath, '@import "tailwindcss";\n\n' + currentCss);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
async function installShadcn() {
|
|
92
|
-
await exec("bun add -D @types/node");
|
|
93
|
-
// Build the shadcn init command with all options
|
|
94
|
-
const shadcnOptions = props.shadcn;
|
|
95
|
-
const initCommand = [
|
|
96
|
-
"bunx --bun shadcn@latest init",
|
|
97
|
-
shadcnOptions?.baseColor && `-b ${shadcnOptions.baseColor}`,
|
|
98
|
-
shadcnOptions?.defaults && "-d",
|
|
99
|
-
shadcnOptions?.force && "-f",
|
|
100
|
-
shadcnOptions?.cwd && `-c ${shadcnOptions.cwd}`,
|
|
101
|
-
shadcnOptions?.silent && "-s",
|
|
102
|
-
shadcnOptions?.srcDir && "--src-dir",
|
|
103
|
-
shadcnOptions?.cssVariables === false && "--no-css-variables",
|
|
104
|
-
]
|
|
105
|
-
.filter(Boolean)
|
|
106
|
-
.join(" ");
|
|
107
|
-
await exec(initCommand);
|
|
108
|
-
// Install requested components using the ShadcnComponent resource
|
|
109
|
-
for (const componentName of props.shadcn?.components ?? []) {
|
|
110
|
-
await ShadcnComponent(`shadcn-component-${componentName}`, {
|
|
111
|
-
name: componentName,
|
|
112
|
-
cwd: props.name,
|
|
113
|
-
force: props.shadcn?.force,
|
|
114
|
-
silent: props.shadcn?.silent,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
async function installTanstack() {
|
|
119
|
-
await exec(`bun add @tanstack/react-router`);
|
|
120
|
-
await exec(`bun add -D @tanstack/router-plugin @tanstack/react-router-devtools`);
|
|
121
|
-
const src = path.join(props.name, "src");
|
|
122
|
-
const routes = path.join(src, "routes");
|
|
123
|
-
await fs.mkdir(routes, { recursive: true });
|
|
124
|
-
await fs.writeFile(path.join(routes, "__root.tsx"), `import { Link, Outlet, createRootRoute } from "@tanstack/react-router";
|
|
125
|
-
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
|
|
126
|
-
|
|
127
|
-
export const Route = createRootRoute({
|
|
128
|
-
component: () => (
|
|
129
|
-
<div className="w-full min-h-screen flex flex-col">
|
|
130
|
-
<div className="p-2 flex gap-2">
|
|
131
|
-
<Link to="/" className="[&.active]:font-bold">
|
|
132
|
-
Home
|
|
133
|
-
</Link>{" "}
|
|
134
|
-
<Link to="/about" className="[&.active]:font-bold">
|
|
135
|
-
About
|
|
136
|
-
</Link>
|
|
137
|
-
</div>
|
|
138
|
-
<hr />
|
|
139
|
-
<Outlet />
|
|
140
|
-
<TanStackRouterDevtools />
|
|
141
|
-
</div>
|
|
142
|
-
),
|
|
143
|
-
});
|
|
144
|
-
`);
|
|
145
|
-
await fs.writeFile(path.join(routes, "index.tsx"), `import { createLazyFileRoute } from '@tanstack/react-router'
|
|
146
|
-
|
|
147
|
-
export const Route = createLazyFileRoute('/')({
|
|
148
|
-
component: Index,
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
function Index() {
|
|
152
|
-
return (
|
|
153
|
-
<div className="p-2">
|
|
154
|
-
<h3>Welcome Home!</h3>
|
|
155
|
-
</div>
|
|
156
|
-
)
|
|
157
|
-
}`);
|
|
158
|
-
await fs.writeFile(path.join(routes, "about.tsx"), `import { createLazyFileRoute } from '@tanstack/react-router'
|
|
159
|
-
|
|
160
|
-
export const Route = createLazyFileRoute('/about')({
|
|
161
|
-
component: About,
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
function About() {
|
|
165
|
-
return <div className="p-2">Hello from About!</div>
|
|
166
|
-
}`);
|
|
167
|
-
await fs.writeFile(path.join(src, "main.tsx"), `import { StrictMode } from 'react'
|
|
168
|
-
import ReactDOM from 'react-dom/client'
|
|
169
|
-
import { RouterProvider, createRouter } from '@tanstack/react-router'
|
|
170
|
-
import './index.css'
|
|
171
|
-
|
|
172
|
-
// Import the generated route tree
|
|
173
|
-
import { routeTree } from './routeTree.gen'
|
|
174
|
-
|
|
175
|
-
// Create a new router instance
|
|
176
|
-
const router = createRouter({ routeTree })
|
|
177
|
-
|
|
178
|
-
// Register the router instance for type safety
|
|
179
|
-
declare module '@tanstack/react-router' {
|
|
180
|
-
interface Register {
|
|
181
|
-
router: typeof router
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Render the app
|
|
186
|
-
const rootElement = document.getElementById('root')!
|
|
187
|
-
if (!rootElement.innerHTML) {
|
|
188
|
-
const root = ReactDOM.createRoot(rootElement)
|
|
189
|
-
root.render(
|
|
190
|
-
<StrictMode>
|
|
191
|
-
<RouterProvider router={router} />
|
|
192
|
-
</StrictMode>,
|
|
193
|
-
)
|
|
194
|
-
}`);
|
|
195
|
-
}
|
|
196
|
-
async function removeUnnecessaryFiles() {
|
|
197
|
-
await Promise.all([
|
|
198
|
-
rm(path.join(props.name, "src", "App.tsx")),
|
|
199
|
-
rm(path.join(props.name, "src", "App.css")),
|
|
200
|
-
]);
|
|
201
|
-
}
|
|
202
|
-
async function patchTsConfig() {
|
|
203
|
-
await Promise.all([
|
|
204
|
-
rm(path.join(props.name, "tsconfig.app.json")),
|
|
205
|
-
rm(path.join(props.name, "tsconfig.node.json")),
|
|
206
|
-
fs.writeFile(path.join(props.name, "tsconfig.json"), JSON.stringify({
|
|
207
|
-
extends: props.extends,
|
|
208
|
-
compilerOptions: {
|
|
209
|
-
baseUrl: ".",
|
|
210
|
-
paths: {
|
|
211
|
-
"@/*": ["./src/*"],
|
|
212
|
-
},
|
|
213
|
-
types: ["@cloudflare/workers-types"],
|
|
214
|
-
allowImportingTsExtensions: true,
|
|
215
|
-
jsx: "react-jsx",
|
|
216
|
-
},
|
|
217
|
-
include: [
|
|
218
|
-
"vite/*.ts",
|
|
219
|
-
"src/**/*.ts",
|
|
220
|
-
"src/**/*.tsx",
|
|
221
|
-
"src/env.d.ts",
|
|
222
|
-
],
|
|
223
|
-
references: props.references?.map((path) => ({ path })),
|
|
224
|
-
}, null, 2)),
|
|
225
|
-
]);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
});
|