alchemy 0.2.1 → 0.2.3
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/alchemy.d.ts +1 -0
- package/lib/alchemy.js +84 -8
- package/lib/apply.d.ts +1 -1
- package/lib/apply.js +13 -10
- package/lib/aws/bucket.d.ts +1 -1
- package/lib/aws/function.d.ts +1 -1
- package/lib/aws/oidc/oidc-provider.d.ts +1 -1
- package/lib/aws/policy-attachment.d.ts +1 -1
- package/lib/aws/policy.d.ts +1 -1
- package/lib/aws/queue.d.ts +1 -1
- package/lib/aws/role.d.ts +1 -1
- package/lib/aws/ses.d.ts +1 -1
- package/lib/aws/table.d.ts +1 -1
- package/lib/cloudflare/bucket.d.ts +1 -1
- package/lib/cloudflare/kv-namespace.d.ts +1 -1
- package/lib/cloudflare/static-site.d.ts +1 -1
- package/lib/cloudflare/worker.d.ts +1 -1
- package/lib/cloudflare/wrangler.json.d.ts +1 -1
- package/lib/cloudflare/zone.d.ts +1 -1
- package/lib/context.d.ts +9 -4
- package/lib/context.js +4 -2
- package/lib/destroy.js +8 -7
- package/lib/docs/document.d.ts +123 -0
- package/lib/docs/document.js +67 -0
- package/lib/docs/index.d.ts +1 -0
- package/lib/docs/index.js +1 -0
- package/lib/esbuild/bundle.d.ts +1 -1
- package/lib/fs/file.d.ts +30 -3
- package/lib/fs/file.js +63 -3
- package/lib/fs/folder.d.ts +3 -3
- package/lib/fs/folder.js +2 -1
- package/lib/github/secret.d.ts +1 -1
- 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/shadcn/component.d.ts +29 -0
- package/lib/shadcn/component.js +31 -0
- package/lib/shadcn/index.d.ts +1 -0
- package/lib/shadcn/index.js +1 -0
- package/lib/state.d.ts +1 -1
- package/lib/state.js +8 -1
- package/lib/stripe/price.d.ts +1 -1
- package/lib/stripe/product.d.ts +1 -1
- package/lib/stripe/webhook.d.ts +1 -1
- package/lib/util/serde.d.ts +3 -1
- package/lib/util/serde.js +6 -4
- package/lib/vite/vite.d.ts +90 -0
- package/lib/vite/vite.js +228 -0
- package/lib/vitepress/dependencies.d.ts +16 -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 +60 -0
- package/lib/vitepress/vitepress.js +260 -0
- package/package.json +19 -11
- package/src/alchemy.ts +105 -13
- package/src/apply.ts +25 -13
- package/src/context.ts +30 -10
- package/src/destroy.ts +10 -7
- package/src/docs/document.ts +225 -0
- package/src/docs/index.ts +1 -0
- package/src/fs/file.ts +114 -6
- package/src/fs/folder.ts +2 -1
- package/src/resource.ts +7 -2
- package/src/scope.ts +9 -9
- package/src/shadcn/component.ts +80 -0
- package/src/shadcn/index.ts +1 -0
- package/src/state.ts +9 -2
- package/src/util/serde.ts +13 -4
- package/src/vite/vite.ts +406 -0
- 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 +361 -0
- package/lib/project/vite.d.ts +0 -39
- package/lib/project/vite.js +0 -68
- package/src/project/vite.ts +0 -152
- /package/lib/{project → vite}/index.d.ts +0 -0
- /package/lib/{project → vite}/index.js +0 -0
- /package/src/{project → vite}/index.ts +0 -0
|
@@ -0,0 +1,361 @@
|
|
|
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
|
+
export interface VitePressProject extends VitePressProjectProps, Resource {
|
|
76
|
+
/**
|
|
77
|
+
* The name/path of the project
|
|
78
|
+
*/
|
|
79
|
+
name: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const VitePressProject = Resource(
|
|
83
|
+
"project::VitePressProject",
|
|
84
|
+
{
|
|
85
|
+
alwaysUpdate: true,
|
|
86
|
+
},
|
|
87
|
+
async function (
|
|
88
|
+
this: Context<VitePressProject>,
|
|
89
|
+
id: string,
|
|
90
|
+
props: VitePressProjectProps,
|
|
91
|
+
): Promise<VitePressProject> {
|
|
92
|
+
if (this.phase === "delete") {
|
|
93
|
+
try {
|
|
94
|
+
if (await fs.exists(props.name)) {
|
|
95
|
+
// Delete the entire project directory
|
|
96
|
+
await execAsync(`rm -rf ${props.name}`);
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error(`Error deleting VitePress project ${id}:`, error);
|
|
100
|
+
}
|
|
101
|
+
return this.destroy();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const cwd = (await Folder(props.name)).path;
|
|
105
|
+
|
|
106
|
+
// Initialize package.json
|
|
107
|
+
await JsonFile(path.join(cwd, "package.json"), {
|
|
108
|
+
name: props.name,
|
|
109
|
+
scripts: {
|
|
110
|
+
"docs:gen": "bun alchemy.run.ts",
|
|
111
|
+
"docs:dev": "vitepress dev",
|
|
112
|
+
"docs:build": "vitepress build",
|
|
113
|
+
"docs:preview": "vitepress preview",
|
|
114
|
+
},
|
|
115
|
+
dependencies: fixedDependencies(props.dependencies || {}),
|
|
116
|
+
devDependencies: fixedDependencies(props.devDependencies || {}),
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
await InstallDependencies("dependencies", {
|
|
120
|
+
cwd,
|
|
121
|
+
dependencies: props.dependencies,
|
|
122
|
+
devDependencies: {
|
|
123
|
+
vue: "latest",
|
|
124
|
+
vitepress: "latest",
|
|
125
|
+
"@shikijs/vitepress-twoslash": "latest",
|
|
126
|
+
"markdown-it-footnote": "latest",
|
|
127
|
+
...props.devDependencies,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
// Create .vitepress directory and config
|
|
131
|
+
await Folder(path.join(cwd, ".vitepress"));
|
|
132
|
+
await Folder(path.join(cwd, ".vitepress", "theme"));
|
|
133
|
+
|
|
134
|
+
await Promise.all([
|
|
135
|
+
TextFile(path.join(cwd, ".gitignore"), `.vitepress/cache\n`),
|
|
136
|
+
JsonFile(path.join(cwd, "tsconfig.json"), {
|
|
137
|
+
extends: props.tsconfig?.extends,
|
|
138
|
+
references: props.tsconfig?.references?.map((path) => ({ path })),
|
|
139
|
+
compilerOptions: props.tsconfig?.compilerOptions,
|
|
140
|
+
}),
|
|
141
|
+
TextFile(
|
|
142
|
+
path.join(cwd, "index.md"),
|
|
143
|
+
`---\n${yaml.stringify(props.home)}---\n`,
|
|
144
|
+
),
|
|
145
|
+
TypeScriptFile(
|
|
146
|
+
path.join(cwd, "alchemy.run.ts"),
|
|
147
|
+
`import alchemy from "alchemy";
|
|
148
|
+
import { Folder } from "alchemy/fs";
|
|
149
|
+
import { Document } from "alchemy/docs";
|
|
150
|
+
import path from "path";
|
|
151
|
+
|
|
152
|
+
await using _ = alchemy("alchemy.run", {
|
|
153
|
+
stage: "prod",
|
|
154
|
+
phase: process.argv.includes("--destroy") ? "destroy" : "up",
|
|
155
|
+
password: process.env.SECRET_PASSPHRASE,
|
|
156
|
+
quiet: !process.argv.includes("--verbose"),
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const docs = await Folder(path.join("alchemy.run", "docs"));
|
|
160
|
+
|
|
161
|
+
await Document("home.md", {
|
|
162
|
+
path: path.join(docs.path, "home.md"),
|
|
163
|
+
prompt: await alchemy\`Generate a landing page.\`,
|
|
164
|
+
});
|
|
165
|
+
`,
|
|
166
|
+
),
|
|
167
|
+
TypeScriptFile(
|
|
168
|
+
path.join(cwd, ".vitepress", "theme", "index.ts"),
|
|
169
|
+
`import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
|
|
170
|
+
import "@shikijs/vitepress-twoslash/style.css";
|
|
171
|
+
import type { Theme as ThemeConfig } from "vitepress";
|
|
172
|
+
import Theme from "vitepress/theme-without-fonts";
|
|
173
|
+
import "./style.css";
|
|
174
|
+
|
|
175
|
+
export default {
|
|
176
|
+
extends: Theme,
|
|
177
|
+
enhanceApp(ctx) {
|
|
178
|
+
ctx.app.use(TwoslashFloatingVue);
|
|
179
|
+
},
|
|
180
|
+
} satisfies ThemeConfig;
|
|
181
|
+
`,
|
|
182
|
+
),
|
|
183
|
+
TextFile(
|
|
184
|
+
path.join(cwd, ".vitepress", "theme", "style.css"),
|
|
185
|
+
`/**
|
|
186
|
+
* Customize default theme styling by overriding CSS variables:
|
|
187
|
+
* https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Colors
|
|
192
|
+
*
|
|
193
|
+
* Each colors have exact same color scale system with 3 levels of solid
|
|
194
|
+
* colors with different brightness, and 1 soft color.
|
|
195
|
+
*
|
|
196
|
+
* - \`XXX-1\`: The most solid color used mainly for colored text. It must
|
|
197
|
+
* satisfy the contrast ratio against when used on top of \`XXX-soft\`.
|
|
198
|
+
*
|
|
199
|
+
* - \`XXX-2\`: The color used mainly for hover state of the button.
|
|
200
|
+
*
|
|
201
|
+
* - \`XXX-3\`: The color for solid background, such as bg color of the button.
|
|
202
|
+
* It must satisfy the contrast ratio with pure white (#ffffff) text on
|
|
203
|
+
* top of it.
|
|
204
|
+
*
|
|
205
|
+
* - \`XXX-soft\`: The color used for subtle background such as custom container
|
|
206
|
+
* or badges. It must satisfy the contrast ratio when putting \`XXX-1\` colors
|
|
207
|
+
* on top of it.
|
|
208
|
+
*
|
|
209
|
+
* The soft color must be semi transparent alpha channel. This is crucial
|
|
210
|
+
* because it allows adding multiple "soft" colors on top of each other
|
|
211
|
+
* to create a accent, such as when having inline code block inside
|
|
212
|
+
* custom containers.
|
|
213
|
+
*
|
|
214
|
+
* - \`default\`: The color used purely for subtle indication without any
|
|
215
|
+
* special meanings attached to it such as bg color for menu hover state.
|
|
216
|
+
*
|
|
217
|
+
* - \`brand\`: Used for primary brand colors, such as link text, button with
|
|
218
|
+
* brand theme, etc.
|
|
219
|
+
*
|
|
220
|
+
* - \`tip\`: Used to indicate useful information. The default theme uses the
|
|
221
|
+
* brand color for this by default.
|
|
222
|
+
*
|
|
223
|
+
* - \`warning\`: Used to indicate warning to the users. Used in custom
|
|
224
|
+
* container, badges, etc.
|
|
225
|
+
*
|
|
226
|
+
* - \`danger\`: Used to show error, or dangerous message to the users. Used
|
|
227
|
+
* in custom container, badges, etc.
|
|
228
|
+
* -------------------------------------------------------------------------- */
|
|
229
|
+
|
|
230
|
+
:root {
|
|
231
|
+
--vp-c-default-1: var(--vp-c-gray-1);
|
|
232
|
+
--vp-c-default-2: var(--vp-c-gray-2);
|
|
233
|
+
--vp-c-default-3: var(--vp-c-gray-3);
|
|
234
|
+
--vp-c-default-soft: var(--vp-c-gray-soft);
|
|
235
|
+
|
|
236
|
+
--vp-c-brand-1: var(--vp-c-indigo-1);
|
|
237
|
+
--vp-c-brand-2: var(--vp-c-indigo-2);
|
|
238
|
+
--vp-c-brand-3: var(--vp-c-indigo-3);
|
|
239
|
+
--vp-c-brand-soft: var(--vp-c-indigo-soft);
|
|
240
|
+
|
|
241
|
+
--vp-c-tip-1: var(--vp-c-brand-1);
|
|
242
|
+
--vp-c-tip-2: var(--vp-c-brand-2);
|
|
243
|
+
--vp-c-tip-3: var(--vp-c-brand-3);
|
|
244
|
+
--vp-c-tip-soft: var(--vp-c-brand-soft);
|
|
245
|
+
|
|
246
|
+
--vp-c-warning-1: var(--vp-c-yellow-1);
|
|
247
|
+
--vp-c-warning-2: var(--vp-c-yellow-2);
|
|
248
|
+
--vp-c-warning-3: var(--vp-c-yellow-3);
|
|
249
|
+
--vp-c-warning-soft: var(--vp-c-yellow-soft);
|
|
250
|
+
|
|
251
|
+
--vp-c-danger-1: var(--vp-c-red-1);
|
|
252
|
+
--vp-c-danger-2: var(--vp-c-red-2);
|
|
253
|
+
--vp-c-danger-3: var(--vp-c-red-3);
|
|
254
|
+
--vp-c-danger-soft: var(--vp-c-red-soft);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Component: Button
|
|
259
|
+
* -------------------------------------------------------------------------- */
|
|
260
|
+
|
|
261
|
+
:root {
|
|
262
|
+
--vp-button-brand-border: transparent;
|
|
263
|
+
--vp-button-brand-text: var(--vp-c-white);
|
|
264
|
+
--vp-button-brand-bg: var(--vp-c-brand-3);
|
|
265
|
+
--vp-button-brand-hover-border: transparent;
|
|
266
|
+
--vp-button-brand-hover-text: var(--vp-c-white);
|
|
267
|
+
--vp-button-brand-hover-bg: var(--vp-c-brand-2);
|
|
268
|
+
--vp-button-brand-active-border: transparent;
|
|
269
|
+
--vp-button-brand-active-text: var(--vp-c-white);
|
|
270
|
+
--vp-button-brand-active-bg: var(--vp-c-brand-1);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Component: Home
|
|
275
|
+
* -------------------------------------------------------------------------- */
|
|
276
|
+
|
|
277
|
+
:root {
|
|
278
|
+
--vp-home-hero-name-color: transparent;
|
|
279
|
+
--vp-home-hero-name-background: -webkit-linear-gradient(
|
|
280
|
+
120deg,
|
|
281
|
+
#bd34fe 30%,
|
|
282
|
+
#41d1ff
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
--vp-home-hero-image-background-image: linear-gradient(
|
|
286
|
+
-45deg,
|
|
287
|
+
#bd34fe 50%,
|
|
288
|
+
#47caff 50%
|
|
289
|
+
);
|
|
290
|
+
--vp-home-hero-image-filter: blur(44px);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
@media (min-width: 640px) {
|
|
294
|
+
:root {
|
|
295
|
+
--vp-home-hero-image-filter: blur(56px);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
@media (min-width: 960px) {
|
|
300
|
+
:root {
|
|
301
|
+
--vp-home-hero-image-filter: blur(68px);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Component: Custom Block
|
|
307
|
+
* -------------------------------------------------------------------------- */
|
|
308
|
+
|
|
309
|
+
:root {
|
|
310
|
+
--vp-custom-block-tip-border: transparent;
|
|
311
|
+
--vp-custom-block-tip-text: var(--vp-c-text-1);
|
|
312
|
+
--vp-custom-block-tip-bg: var(--vp-c-brand-soft);
|
|
313
|
+
--vp-custom-block-tip-code-bg: var(--vp-c-brand-soft);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Component: Algolia
|
|
318
|
+
* -------------------------------------------------------------------------- */
|
|
319
|
+
|
|
320
|
+
.DocSearch {
|
|
321
|
+
--docsearch-primary-color: var(--vp-c-brand-1) !important;
|
|
322
|
+
}
|
|
323
|
+
`,
|
|
324
|
+
),
|
|
325
|
+
TypeScriptFile(
|
|
326
|
+
path.join(cwd, ".vitepress", "config.mts"),
|
|
327
|
+
`import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
|
|
328
|
+
import footnotePlugin from "markdown-it-footnote";
|
|
329
|
+
import { defineConfig } from "vitepress";
|
|
330
|
+
|
|
331
|
+
// https://vitepress.dev/reference/site-config
|
|
332
|
+
export default defineConfig({
|
|
333
|
+
title: ${JSON.stringify(props.title || "Alchemy")},
|
|
334
|
+
description: ${JSON.stringify(props.description || "Alchemy Docs")},
|
|
335
|
+
markdown: {
|
|
336
|
+
// @ts-ignore
|
|
337
|
+
codeTransformers: [transformerTwoslash()],
|
|
338
|
+
theme: ${JSON.stringify(
|
|
339
|
+
props.theme ?? {
|
|
340
|
+
light: "light-plus",
|
|
341
|
+
dark: "dark-plus",
|
|
342
|
+
},
|
|
343
|
+
)},
|
|
344
|
+
config: (md) => md.use(footnotePlugin),
|
|
345
|
+
},
|
|
346
|
+
// https://vitepress.dev/reference/default-theme-config
|
|
347
|
+
themeConfig: ${JSON.stringify({
|
|
348
|
+
...props.themeConfig,
|
|
349
|
+
search: props.themeConfig.search ?? { provider: "local" },
|
|
350
|
+
nav: props.themeConfig.nav ?? [{ text: "Home", link: "/" }],
|
|
351
|
+
sidebar: props.themeConfig.sidebar ?? [],
|
|
352
|
+
socialLinks: props.themeConfig.socialLinks ?? [],
|
|
353
|
+
})}
|
|
354
|
+
});
|
|
355
|
+
`,
|
|
356
|
+
),
|
|
357
|
+
]);
|
|
358
|
+
|
|
359
|
+
return this(props);
|
|
360
|
+
},
|
|
361
|
+
);
|
package/lib/project/vite.d.ts
DELETED
|
@@ -1,39 +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
|
-
* @default false
|
|
23
|
-
*/
|
|
24
|
-
tailwind?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Force overwrite the project config tfiles during the update phase
|
|
27
|
-
*
|
|
28
|
-
* @default false
|
|
29
|
-
*/
|
|
30
|
-
overwrite?: boolean;
|
|
31
|
-
}
|
|
32
|
-
export interface ViteProject extends ViteProjectProps, Resource {
|
|
33
|
-
/**
|
|
34
|
-
* The name/path of the project
|
|
35
|
-
*/
|
|
36
|
-
name: string;
|
|
37
|
-
}
|
|
38
|
-
export declare const ViteProject: ((this: Context<ViteProject>, id: string, props: ViteProjectProps) => Promise<ViteProject>) | (((this: any, id: string, props: ViteProjectProps) => never) & (new (_: never) => never));
|
|
39
|
-
export {};
|
package/lib/project/vite.js
DELETED
|
@@ -1,68 +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 { rm } from "../util/rm";
|
|
7
|
-
const execAsync = promisify(exec);
|
|
8
|
-
export const ViteProject = Resource("project::ViteProject", async function (id, props) {
|
|
9
|
-
if (this.phase === "delete") {
|
|
10
|
-
try {
|
|
11
|
-
if (await fs.exists(props.name)) {
|
|
12
|
-
// TODO: OS agnostic - fs.rm is slow to delete node_modules/
|
|
13
|
-
await execAsync("rm -rf " + props.name);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
console.error(`Error deleting project ${id}:`, error);
|
|
18
|
-
}
|
|
19
|
-
return this.destroy();
|
|
20
|
-
}
|
|
21
|
-
if (this.phase === "update") {
|
|
22
|
-
if (props.overwrite) {
|
|
23
|
-
await modifyConfig(props);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
console.warn("ViteProject does not support updates - the project must be recreated to change the template");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
// Create phase
|
|
31
|
-
await execAsync(`bun create vite ${id} --template ${props.template}`);
|
|
32
|
-
await modifyConfig(props);
|
|
33
|
-
}
|
|
34
|
-
return this(props);
|
|
35
|
-
});
|
|
36
|
-
async function modifyConfig(props) {
|
|
37
|
-
if (props.tailwind) {
|
|
38
|
-
await execAsync(`bun add tailwindcss @tailwindcss/vite`);
|
|
39
|
-
await fs.writeFile(path.join(props.name, "vite.config.ts"), `import tailwindcss from "@tailwindcss/vite";
|
|
40
|
-
import react from "@vitejs/plugin-react";
|
|
41
|
-
import { defineConfig } from "vite";
|
|
42
|
-
|
|
43
|
-
// https://vite.dev/config/
|
|
44
|
-
export default defineConfig({
|
|
45
|
-
plugins: [react(), tailwindcss()],
|
|
46
|
-
});`);
|
|
47
|
-
// Add Tailwind CSS import to index.css
|
|
48
|
-
const indexCssPath = path.join(props.name, "src", "index.css");
|
|
49
|
-
const currentCss = await fs.readFile(indexCssPath, "utf-8");
|
|
50
|
-
if (!currentCss.includes('@import "tailwindcss";')) {
|
|
51
|
-
await fs.writeFile(indexCssPath, '@import "tailwindcss";\n\n' + currentCss);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
await Promise.all([
|
|
55
|
-
rm(path.join(props.name, "tsconfig.app.json")),
|
|
56
|
-
rm(path.join(props.name, "tsconfig.node.json")),
|
|
57
|
-
fs.writeFile(path.join(props.name, "tsconfig.json"), JSON.stringify({
|
|
58
|
-
extends: props.extends,
|
|
59
|
-
compilerOptions: {
|
|
60
|
-
types: ["@cloudflare/workers-types"],
|
|
61
|
-
allowImportingTsExtensions: true,
|
|
62
|
-
jsx: "react-jsx",
|
|
63
|
-
},
|
|
64
|
-
include: ["vite/*.ts", "src/**/*.ts", "src/**/*.tsx", "src/env.d.ts"],
|
|
65
|
-
references: props.references?.map((path) => ({ path })),
|
|
66
|
-
}, null, 2)),
|
|
67
|
-
]);
|
|
68
|
-
}
|
package/src/project/vite.ts
DELETED
|
@@ -1,152 +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 type { Context } from "../context";
|
|
6
|
-
import { Resource } from "../resource";
|
|
7
|
-
import { rm } from "../util/rm";
|
|
8
|
-
const execAsync = promisify(exec);
|
|
9
|
-
|
|
10
|
-
type ViteTemplate =
|
|
11
|
-
| "vanilla"
|
|
12
|
-
| "vanilla-ts"
|
|
13
|
-
| "vue"
|
|
14
|
-
| "vue-ts"
|
|
15
|
-
| "react"
|
|
16
|
-
| "react-ts"
|
|
17
|
-
| "react-swc"
|
|
18
|
-
| "react-swc-ts"
|
|
19
|
-
| "preact"
|
|
20
|
-
| "preact-ts"
|
|
21
|
-
| "lit"
|
|
22
|
-
| "lit-ts"
|
|
23
|
-
| "svelte"
|
|
24
|
-
| "svelte-ts"
|
|
25
|
-
| "solid"
|
|
26
|
-
| "solid-ts"
|
|
27
|
-
| "qwik"
|
|
28
|
-
| "qwik-ts";
|
|
29
|
-
|
|
30
|
-
export interface ViteProjectProps {
|
|
31
|
-
/**
|
|
32
|
-
* The name/path of the project
|
|
33
|
-
*/
|
|
34
|
-
name: string;
|
|
35
|
-
/**
|
|
36
|
-
* The Vite template to use
|
|
37
|
-
*/
|
|
38
|
-
template: ViteTemplate;
|
|
39
|
-
/**
|
|
40
|
-
* The extends to add to the tsconfig.json file
|
|
41
|
-
*/
|
|
42
|
-
extends?: string;
|
|
43
|
-
/**
|
|
44
|
-
* The references to add to the tsconfig.json file
|
|
45
|
-
*/
|
|
46
|
-
references?: string[];
|
|
47
|
-
/**
|
|
48
|
-
* @default false
|
|
49
|
-
*/
|
|
50
|
-
tailwind?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Force overwrite the project config tfiles during the update phase
|
|
53
|
-
*
|
|
54
|
-
* @default false
|
|
55
|
-
*/
|
|
56
|
-
overwrite?: boolean;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface ViteProject extends ViteProjectProps, Resource {
|
|
60
|
-
/**
|
|
61
|
-
* The name/path of the project
|
|
62
|
-
*/
|
|
63
|
-
name: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const ViteProject = Resource(
|
|
67
|
-
"project::ViteProject",
|
|
68
|
-
async function (
|
|
69
|
-
this: Context<ViteProject>,
|
|
70
|
-
id: string,
|
|
71
|
-
props: ViteProjectProps,
|
|
72
|
-
): Promise<ViteProject> {
|
|
73
|
-
if (this.phase === "delete") {
|
|
74
|
-
try {
|
|
75
|
-
if (await fs.exists(props.name)) {
|
|
76
|
-
// TODO: OS agnostic - fs.rm is slow to delete node_modules/
|
|
77
|
-
await execAsync("rm -rf " + props.name);
|
|
78
|
-
}
|
|
79
|
-
} catch (error) {
|
|
80
|
-
console.error(`Error deleting project ${id}:`, error);
|
|
81
|
-
}
|
|
82
|
-
return this.destroy();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (this.phase === "update") {
|
|
86
|
-
if (props.overwrite) {
|
|
87
|
-
await modifyConfig(props);
|
|
88
|
-
} else {
|
|
89
|
-
console.warn(
|
|
90
|
-
"ViteProject does not support updates - the project must be recreated to change the template",
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
// Create phase
|
|
95
|
-
await execAsync(`bun create vite ${id} --template ${props.template}`);
|
|
96
|
-
|
|
97
|
-
await modifyConfig(props);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return this(props);
|
|
101
|
-
},
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
async function modifyConfig(props: ViteProjectProps) {
|
|
105
|
-
if (props.tailwind) {
|
|
106
|
-
await execAsync(`bun add tailwindcss @tailwindcss/vite`);
|
|
107
|
-
|
|
108
|
-
await fs.writeFile(
|
|
109
|
-
path.join(props.name, "vite.config.ts"),
|
|
110
|
-
`import tailwindcss from "@tailwindcss/vite";
|
|
111
|
-
import react from "@vitejs/plugin-react";
|
|
112
|
-
import { defineConfig } from "vite";
|
|
113
|
-
|
|
114
|
-
// https://vite.dev/config/
|
|
115
|
-
export default defineConfig({
|
|
116
|
-
plugins: [react(), tailwindcss()],
|
|
117
|
-
});`,
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
// Add Tailwind CSS import to index.css
|
|
121
|
-
const indexCssPath = path.join(props.name, "src", "index.css");
|
|
122
|
-
const currentCss = await fs.readFile(indexCssPath, "utf-8");
|
|
123
|
-
if (!currentCss.includes('@import "tailwindcss";')) {
|
|
124
|
-
await fs.writeFile(
|
|
125
|
-
indexCssPath,
|
|
126
|
-
'@import "tailwindcss";\n\n' + currentCss,
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
await Promise.all([
|
|
132
|
-
rm(path.join(props.name, "tsconfig.app.json")),
|
|
133
|
-
rm(path.join(props.name, "tsconfig.node.json")),
|
|
134
|
-
fs.writeFile(
|
|
135
|
-
path.join(props.name, "tsconfig.json"),
|
|
136
|
-
JSON.stringify(
|
|
137
|
-
{
|
|
138
|
-
extends: props.extends,
|
|
139
|
-
compilerOptions: {
|
|
140
|
-
types: ["@cloudflare/workers-types"],
|
|
141
|
-
allowImportingTsExtensions: true,
|
|
142
|
-
jsx: "react-jsx",
|
|
143
|
-
},
|
|
144
|
-
include: ["vite/*.ts", "src/**/*.ts", "src/**/*.tsx", "src/env.d.ts"],
|
|
145
|
-
references: props.references?.map((path) => ({ path })),
|
|
146
|
-
},
|
|
147
|
-
null,
|
|
148
|
-
2,
|
|
149
|
-
),
|
|
150
|
-
),
|
|
151
|
-
]);
|
|
152
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|