@tanstack/cta-engine 0.10.0-alpha.6
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/LICENSE +21 -0
- package/dist/add-ons.js +109 -0
- package/dist/add.js +127 -0
- package/dist/cli.js +112 -0
- package/dist/config-file.js +23 -0
- package/dist/constants.js +5 -0
- package/dist/create-app.js +491 -0
- package/dist/custom-add-on.js +254 -0
- package/dist/environment.js +119 -0
- package/dist/index.js +1 -0
- package/dist/mcp.js +211 -0
- package/dist/options.js +309 -0
- package/dist/package-manager.js +30 -0
- package/dist/templates.js +6 -0
- package/dist/toolchain.js +6 -0
- package/dist/types/add-ons.d.ts +5 -0
- package/dist/types/add.d.ts +3 -0
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/config-file.d.ts +7 -0
- package/dist/types/constants.d.ts +6 -0
- package/dist/types/create-app.d.ts +6 -0
- package/dist/types/custom-add-on.d.ts +3 -0
- package/dist/types/environment.d.ts +12 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mcp.d.ts +1 -0
- package/dist/types/options.d.ts +3 -0
- package/dist/types/package-manager.d.ts +6 -0
- package/dist/types/templates.d.ts +1 -0
- package/dist/types/toolchain.d.ts +3 -0
- package/dist/types/types.d.ts +107 -0
- package/dist/types/utils.d.ts +1 -0
- package/dist/types.js +1 -0
- package/dist/utils.js +8 -0
- package/package.json +49 -0
- package/src/add-ons.ts +145 -0
- package/src/add.ts +184 -0
- package/src/cli.ts +163 -0
- package/src/config-file.ts +45 -0
- package/src/constants.ts +9 -0
- package/src/create-app.ts +791 -0
- package/src/custom-add-on.ts +323 -0
- package/src/environment.ts +144 -0
- package/src/index.ts +1 -0
- package/src/mcp.ts +252 -0
- package/src/options.ts +359 -0
- package/src/package-manager.ts +46 -0
- package/src/templates.ts +7 -0
- package/src/toolchain.ts +7 -0
- package/src/types.ts +119 -0
- package/src/utils.ts +10 -0
- package/templates/react/add-on/clerk/README.md +3 -0
- package/templates/react/add-on/clerk/assets/_dot_env.local.append +2 -0
- package/templates/react/add-on/clerk/assets/src/integrations/clerk/header-user.tsx +19 -0
- package/templates/react/add-on/clerk/assets/src/integrations/clerk/provider.tsx +18 -0
- package/templates/react/add-on/clerk/assets/src/routes/demo.clerk.tsx +20 -0
- package/templates/react/add-on/clerk/info.json +13 -0
- package/templates/react/add-on/clerk/package.json +5 -0
- package/templates/react/add-on/convex/README.md +4 -0
- package/templates/react/add-on/convex/assets/_dot_cursorrules.append +93 -0
- package/templates/react/add-on/convex/assets/_dot_env.local.append +3 -0
- package/templates/react/add-on/convex/assets/convex/products.ts +8 -0
- package/templates/react/add-on/convex/assets/convex/schema.ts +10 -0
- package/templates/react/add-on/convex/assets/src/integrations/convex/provider.tsx +20 -0
- package/templates/react/add-on/convex/assets/src/routes/demo.convex.tsx +33 -0
- package/templates/react/add-on/convex/info.json +13 -0
- package/templates/react/add-on/convex/package.json +6 -0
- package/templates/react/add-on/form/assets/src/components/demo.FormComponents.tsx.ejs +300 -0
- package/templates/react/add-on/form/assets/src/hooks/demo.form-context.ts +4 -0
- package/templates/react/add-on/form/assets/src/hooks/demo.form.ts +22 -0
- package/templates/react/add-on/form/assets/src/routes/demo.form.address.tsx.ejs +213 -0
- package/templates/react/add-on/form/assets/src/routes/demo.form.simple.tsx.ejs +77 -0
- package/templates/react/add-on/form/info.json +26 -0
- package/templates/react/add-on/form/package.json +6 -0
- package/templates/react/add-on/module-federation/assets/module-federation.config.js.ejs +31 -0
- package/templates/react/add-on/module-federation/assets/src/demo-mf-component.tsx +3 -0
- package/templates/react/add-on/module-federation/assets/src/demo-mf-self-contained.tsx +11 -0
- package/templates/react/add-on/module-federation/info.json +7 -0
- package/templates/react/add-on/module-federation/package.json +5 -0
- package/templates/react/add-on/netlify/README.md +11 -0
- package/templates/react/add-on/netlify/info.json +7 -0
- package/templates/react/add-on/sentry/assets/_dot_cursorrules.append +22 -0
- package/templates/react/add-on/sentry/assets/_dot_env.local.append +2 -0
- package/templates/react/add-on/sentry/assets/src/app/global-middleware.ts +25 -0
- package/templates/react/add-on/sentry/assets/src/routes/demo.sentry.testing.tsx +480 -0
- package/templates/react/add-on/sentry/info.json +14 -0
- package/templates/react/add-on/sentry/package.json +7 -0
- package/templates/react/add-on/shadcn/README.md +7 -0
- package/templates/react/add-on/shadcn/assets/_dot_cursorrules.append +7 -0
- package/templates/react/add-on/shadcn/assets/components.json +21 -0
- package/templates/react/add-on/shadcn/assets/src/lib/utils.ts +6 -0
- package/templates/react/add-on/shadcn/assets/src/styles.css +138 -0
- package/templates/react/add-on/shadcn/info.json +7 -0
- package/templates/react/add-on/shadcn/package.json +9 -0
- package/templates/react/add-on/start/assets/_dot_gitignore.append +2 -0
- package/templates/react/add-on/start/assets/app.config.ts.ejs +19 -0
- package/templates/react/add-on/start/assets/src/api.ts +6 -0
- package/templates/react/add-on/start/assets/src/client.tsx +8 -0
- package/templates/react/add-on/start/assets/src/router.tsx.ejs +77 -0
- package/templates/react/add-on/start/assets/src/routes/api.demo-names.ts +11 -0
- package/templates/react/add-on/start/assets/src/routes/demo.start.api-request.tsx.ejs +33 -0
- package/templates/react/add-on/start/assets/src/routes/demo.start.server-funcs.tsx +50 -0
- package/templates/react/add-on/start/assets/src/ssr.tsx +12 -0
- package/templates/react/add-on/start/info.json +18 -0
- package/templates/react/add-on/start/package.json +13 -0
- package/templates/react/add-on/store/assets/src/lib/demo-store.ts +13 -0
- package/templates/react/add-on/store/assets/src/routes/demo.store.tsx.ejs +75 -0
- package/templates/react/add-on/store/info.json +13 -0
- package/templates/react/add-on/store/package.json +6 -0
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/init.ts +9 -0
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/react.ts +4 -0
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/router.ts +18 -0
- package/templates/react/add-on/tRPC/assets/src/routes/api.trpc.$.tsx +16 -0
- package/templates/react/add-on/tRPC/info.json +9 -0
- package/templates/react/add-on/tRPC/package.json +9 -0
- package/templates/react/add-on/table/assets/src/data/demo-table-data.ts +50 -0
- package/templates/react/add-on/table/assets/src/routes/demo.table.tsx.ejs +373 -0
- package/templates/react/add-on/table/info.json +13 -0
- package/templates/react/add-on/table/package.json +7 -0
- package/templates/react/add-on/tanstack-query/assets/src/integrations/tanstack-query/layout.tsx +5 -0
- package/templates/react/add-on/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs +70 -0
- package/templates/react/add-on/tanstack-query/assets/src/routes/demo.tanstack-query.tsx.ejs +53 -0
- package/templates/react/add-on/tanstack-query/info.json +13 -0
- package/templates/react/add-on/tanstack-query/package.json +6 -0
- package/templates/react/base/README.md.ejs +558 -0
- package/templates/react/base/_dot_gitignore +5 -0
- package/templates/react/base/_dot_vscode/settings.biome.json +38 -0
- package/templates/react/base/_dot_vscode/settings.json +11 -0
- package/templates/react/base/index.html.ejs +20 -0
- package/templates/react/base/package.biome.json +10 -0
- package/templates/react/base/package.eslintprettier.json +11 -0
- package/templates/react/base/package.json +29 -0
- package/templates/react/base/package.ts.json +7 -0
- package/templates/react/base/package.tw.json +6 -0
- package/templates/react/base/public/favicon.ico +0 -0
- package/templates/react/base/public/logo192.png +0 -0
- package/templates/react/base/public/logo512.png +0 -0
- package/templates/react/base/public/manifest.json +25 -0
- package/templates/react/base/public/robots.txt +3 -0
- package/templates/react/base/src/App.css +38 -0
- package/templates/react/base/src/App.test.tsx.ejs +10 -0
- package/templates/react/base/src/App.tsx.ejs +74 -0
- package/templates/react/base/src/components/Header.tsx.ejs +27 -0
- package/templates/react/base/src/logo.svg +44 -0
- package/templates/react/base/src/reportWebVitals.ts.ejs +28 -0
- package/templates/react/base/src/styles.css.ejs +15 -0
- package/templates/react/base/toolchain/.prettierignore +3 -0
- package/templates/react/base/toolchain/biome.json +31 -0
- package/templates/react/base/toolchain/eslint.config.js +5 -0
- package/templates/react/base/toolchain/prettier.config.js +10 -0
- package/templates/react/base/tsconfig.json.ejs +29 -0
- package/templates/react/base/vite.config.js.ejs +23 -0
- package/templates/react/code-router/src/main.tsx.ejs +92 -0
- package/templates/react/example/tanchat/README.md +37 -0
- package/templates/react/example/tanchat/assets/_dot_env.local.append +2 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-flowers.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-motherboard.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-racing.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-steamer-trunk.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-superhero.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-traveling.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-video-games.jpg +0 -0
- package/templates/react/example/tanchat/assets/src/components/example-AIAssistant.tsx +173 -0
- package/templates/react/example/tanchat/assets/src/components/example-GuitarRecommendation.tsx +47 -0
- package/templates/react/example/tanchat/assets/src/data/example-guitars.ts +83 -0
- package/templates/react/example/tanchat/assets/src/demo.index.css +220 -0
- package/templates/react/example/tanchat/assets/src/integrations/tanchat/header-user.tsx +5 -0
- package/templates/react/example/tanchat/assets/src/routes/example.chat.tsx +159 -0
- package/templates/react/example/tanchat/assets/src/routes/example.guitars/$guitarId.tsx +50 -0
- package/templates/react/example/tanchat/assets/src/routes/example.guitars/index.tsx +54 -0
- package/templates/react/example/tanchat/assets/src/store/example-assistant.ts +3 -0
- package/templates/react/example/tanchat/assets/src/utils/demo.ai.ts +62 -0
- package/templates/react/example/tanchat/assets/src/utils/demo.tools.ts +47 -0
- package/templates/react/example/tanchat/info.json +19 -0
- package/templates/react/example/tanchat/package.json +15 -0
- package/templates/react/file-router/package.fr.json +5 -0
- package/templates/react/file-router/src/main.tsx.ejs +55 -0
- package/templates/react/file-router/src/routes/__root.tsx.ejs +82 -0
- package/templates/solid/add-on/form/assets/src/routes/demo.form.tsx.ejs +352 -0
- package/templates/solid/add-on/form/info.json +13 -0
- package/templates/solid/add-on/form/package.json +5 -0
- package/templates/solid/add-on/module-federation/assets/module-federation.config.js.ejs +27 -0
- package/templates/solid/add-on/module-federation/assets/src/demo-mf-component.tsx +3 -0
- package/templates/solid/add-on/module-federation/assets/src/demo-mf-self-contained.tsx +9 -0
- package/templates/solid/add-on/module-federation/info.json +7 -0
- package/templates/solid/add-on/module-federation/package.json +5 -0
- package/templates/solid/add-on/sentry/assets/_dot_cursorrules.append +22 -0
- package/templates/solid/add-on/sentry/assets/_dot_env.local.append +2 -0
- package/templates/solid/add-on/sentry/assets/src/routes/demo.sentry.bad-event-handler.tsx +20 -0
- package/templates/solid/add-on/sentry/info.json +13 -0
- package/templates/solid/add-on/sentry/package.json +5 -0
- package/templates/solid/add-on/solid-ui/README.md +9 -0
- package/templates/solid/add-on/solid-ui/assets/src/lib/utils.ts +6 -0
- package/templates/solid/add-on/solid-ui/assets/src/styles.css +138 -0
- package/templates/solid/add-on/solid-ui/assets/ui.config.json +13 -0
- package/templates/solid/add-on/solid-ui/info.json +11 -0
- package/templates/solid/add-on/solid-ui/package.json +9 -0
- package/templates/solid/add-on/start/assets/app.config.ts +16 -0
- package/templates/solid/add-on/start/assets/src/api.ts +6 -0
- package/templates/solid/add-on/start/assets/src/client.tsx +7 -0
- package/templates/solid/add-on/start/assets/src/router.tsx.ejs +24 -0
- package/templates/solid/add-on/start/assets/src/routes/demo.start.server-funcs.tsx +49 -0
- package/templates/solid/add-on/start/assets/src/ssr.tsx +12 -0
- package/templates/solid/add-on/start/info.json +14 -0
- package/templates/solid/add-on/start/package.json +12 -0
- package/templates/solid/add-on/store/assets/src/lib/demo-store.ts +13 -0
- package/templates/solid/add-on/store/assets/src/routes/demo.store.tsx.ejs +77 -0
- package/templates/solid/add-on/store/info.json +13 -0
- package/templates/solid/add-on/store/package.json +6 -0
- package/templates/solid/add-on/tanstack-query/assets/src/integrations/tanstack-query/header-user.tsx +5 -0
- package/templates/solid/add-on/tanstack-query/assets/src/integrations/tanstack-query/provider.tsx +15 -0
- package/templates/solid/add-on/tanstack-query/assets/src/routes/demo.tanstack-query.tsx +30 -0
- package/templates/solid/add-on/tanstack-query/info.json +13 -0
- package/templates/solid/add-on/tanstack-query/package.json +6 -0
- package/templates/solid/base/README.md.ejs +215 -0
- package/templates/solid/base/_dot_cursorrules.append +35 -0
- package/templates/solid/base/_dot_gitignore +5 -0
- package/templates/solid/base/_dot_vscode/settings.biome.json +38 -0
- package/templates/solid/base/_dot_vscode/settings.json +11 -0
- package/templates/solid/base/index.html.ejs +20 -0
- package/templates/solid/base/package.biome.json +10 -0
- package/templates/solid/base/package.eslintprettier.json +11 -0
- package/templates/solid/base/package.json +22 -0
- package/templates/solid/base/package.ts.json +5 -0
- package/templates/solid/base/package.tw.json +6 -0
- package/templates/solid/base/public/favicon.ico +0 -0
- package/templates/solid/base/public/logo192.png +0 -0
- package/templates/solid/base/public/logo512.png +0 -0
- package/templates/solid/base/public/manifest.json +25 -0
- package/templates/solid/base/public/robots.txt +3 -0
- package/templates/solid/base/src/App.css +0 -0
- package/templates/solid/base/src/App.tsx.ejs +47 -0
- package/templates/solid/base/src/components/Header.tsx.ejs +26 -0
- package/templates/solid/base/src/logo.svg +120 -0
- package/templates/solid/base/src/styles.css.ejs +15 -0
- package/templates/solid/base/toolchain/.prettierignore +3 -0
- package/templates/solid/base/toolchain/biome.json +31 -0
- package/templates/solid/base/toolchain/eslint.config.js +5 -0
- package/templates/solid/base/toolchain/prettier.config.js +10 -0
- package/templates/solid/base/tsconfig.json.ejs +31 -0
- package/templates/solid/base/vite.config.js.ejs +22 -0
- package/templates/solid/code-router/src/main.tsx.ejs +71 -0
- package/templates/solid/example/tanchat/README.md +52 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/README.md +110 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/_dot_env.example +1 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/package.json +26 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/src/index.ts +102 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/tsconfig.json +15 -0
- package/templates/solid/example/tanchat/assets/src/components/demo.SettingsDialog.tsx +149 -0
- package/templates/solid/example/tanchat/assets/src/demo.index.css +227 -0
- package/templates/solid/example/tanchat/assets/src/lib/demo-store.ts +13 -0
- package/templates/solid/example/tanchat/assets/src/routes/example.chat.tsx +435 -0
- package/templates/solid/example/tanchat/assets/src/store/demo.hooks.ts +17 -0
- package/templates/solid/example/tanchat/assets/src/store/demo.store.ts +133 -0
- package/templates/solid/example/tanchat/info.json +14 -0
- package/templates/solid/example/tanchat/package.json +7 -0
- package/templates/solid/file-router/package.fr.json +5 -0
- package/templates/solid/file-router/src/main.tsx.ejs +47 -0
- package/templates/solid/file-router/src/routes/__root.tsx.ejs +41 -0
- package/templates/solid/file-router/src/routes/index.tsx +43 -0
- package/tests/cra.test.ts +293 -0
- package/tests/snapshots/cra/cr-js-npm.json +33 -0
- package/tests/snapshots/cra/cr-ts-npm.json +34 -0
- package/tests/snapshots/cra/cr-ts-start-npm.json +38 -0
- package/tests/snapshots/cra/fr-ts-npm.json +34 -0
- package/tests/snapshots/cra/fr-ts-tw-npm.json +33 -0
- package/tests/snapshots/cra/solid-cr-js-npm.json +31 -0
- package/tests/snapshots/cra/solid-cr-ts-npm.json +32 -0
- package/tests/snapshots/cra/solid-cr-ts-start-npm.json +36 -0
- package/tests/snapshots/cra/solid-fr-ts-npm.json +33 -0
- package/tests/snapshots/cra/solid-fr-ts-tw-npm.json +32 -0
- package/tests/test-utilities.ts +87 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { readFile, readdir } from 'node:fs/promises'
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { basename, dirname, resolve } from 'node:path'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
|
|
6
|
+
import { createMemoryEnvironment } from './environment.js'
|
|
7
|
+
import { createApp } from './create-app.js'
|
|
8
|
+
import { readConfigFile } from './config-file.js'
|
|
9
|
+
import { finalizeAddOns } from './add-ons.js'
|
|
10
|
+
|
|
11
|
+
import type { Options } from './types.js'
|
|
12
|
+
import type { PersistedOptions } from './config-file.js'
|
|
13
|
+
|
|
14
|
+
type AddOnMode = 'add-on' | 'overlay'
|
|
15
|
+
|
|
16
|
+
const INFO_FILE: Record<AddOnMode, string> = {
|
|
17
|
+
'add-on': '.add-on/info.json',
|
|
18
|
+
overlay: 'overlay-info.json',
|
|
19
|
+
}
|
|
20
|
+
const COMPILED_FILE: Record<AddOnMode, string> = {
|
|
21
|
+
'add-on': 'add-on.json',
|
|
22
|
+
overlay: 'overlay.json',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const ADD_ON_DIR = '.add-on'
|
|
26
|
+
const ASSETS_DIR = 'assets'
|
|
27
|
+
|
|
28
|
+
const IGNORE_FILES = [
|
|
29
|
+
ADD_ON_DIR,
|
|
30
|
+
'node_modules',
|
|
31
|
+
'dist',
|
|
32
|
+
'build',
|
|
33
|
+
'.git',
|
|
34
|
+
'pnpm-lock.yaml',
|
|
35
|
+
'package-lock.json',
|
|
36
|
+
'yarn.lock',
|
|
37
|
+
'bun.lockb',
|
|
38
|
+
'bun.lock',
|
|
39
|
+
'deno.lock',
|
|
40
|
+
'add-on.json',
|
|
41
|
+
'add-on-info.json',
|
|
42
|
+
'package.json',
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
const ADD_ON_IGNORE_FILES: Array<string> = [
|
|
46
|
+
'main.jsx',
|
|
47
|
+
'App.jsx',
|
|
48
|
+
'main.tsx',
|
|
49
|
+
'App.tsx',
|
|
50
|
+
'routeTree.gen.ts',
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
function templatize(routeCode: string, routeFile: string) {
|
|
54
|
+
let code = routeCode
|
|
55
|
+
|
|
56
|
+
// Replace the import
|
|
57
|
+
code = code.replace(
|
|
58
|
+
/import { createFileRoute } from '@tanstack\/react-router'/g,
|
|
59
|
+
`import { <% if (fileRouter) { %>createFileRoute<% } else { %>createRoute<% } %> } from '@tanstack/react-router'`,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
// Extract route path and definition, then transform the route declaration
|
|
63
|
+
const routeMatch = code.match(
|
|
64
|
+
/export\s+const\s+Route\s*=\s*createFileRoute\(['"]([^'"]+)['"]\)\s*\(\{([^}]+)\}\)/,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
let path = ''
|
|
68
|
+
|
|
69
|
+
if (routeMatch) {
|
|
70
|
+
const fullMatch = routeMatch[0]
|
|
71
|
+
path = routeMatch[1]
|
|
72
|
+
const routeDefinition = routeMatch[2]
|
|
73
|
+
code = code.replace(
|
|
74
|
+
fullMatch,
|
|
75
|
+
`<% if (codeRouter) { %>
|
|
76
|
+
import type { RootRoute } from '@tanstack/react-router'
|
|
77
|
+
<% } else { %>
|
|
78
|
+
export const Route = createFileRoute('${path}')({${routeDefinition}})
|
|
79
|
+
<% } %>`,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
code += `
|
|
83
|
+
<% if (codeRouter) { %>
|
|
84
|
+
export default (parentRoute: RootRoute) => createRoute({
|
|
85
|
+
path: '${path}',
|
|
86
|
+
${routeDefinition}
|
|
87
|
+
getParentRoute: () => parentRoute,
|
|
88
|
+
})
|
|
89
|
+
<% } %>
|
|
90
|
+
`
|
|
91
|
+
} else {
|
|
92
|
+
console.error(`No route found in the file: ${routeFile}`)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const name = basename(path)
|
|
96
|
+
.replace('.tsx', '')
|
|
97
|
+
.replace(/^demo/, '')
|
|
98
|
+
.replace('.', ' ')
|
|
99
|
+
.trim()
|
|
100
|
+
|
|
101
|
+
return { url: path, code, name }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function createOptions(
|
|
105
|
+
json: PersistedOptions,
|
|
106
|
+
): Promise<Required<Options>> {
|
|
107
|
+
return {
|
|
108
|
+
...json,
|
|
109
|
+
chosenAddOns: await finalizeAddOns(json.framework!, json.mode!, [
|
|
110
|
+
...json.existingAddOns,
|
|
111
|
+
]),
|
|
112
|
+
} as Required<Options>
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function runCreateApp(options: Required<Options>) {
|
|
116
|
+
const { environment, output } = createMemoryEnvironment()
|
|
117
|
+
await createApp(options, {
|
|
118
|
+
silent: true,
|
|
119
|
+
environment,
|
|
120
|
+
cwd: process.cwd(),
|
|
121
|
+
})
|
|
122
|
+
return output
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function recursivelyGatherFiles(
|
|
126
|
+
path: string,
|
|
127
|
+
files: Record<string, string>,
|
|
128
|
+
) {
|
|
129
|
+
const dirFiles = await readdir(path, { withFileTypes: true })
|
|
130
|
+
for (const file of dirFiles) {
|
|
131
|
+
if (file.isDirectory()) {
|
|
132
|
+
await recursivelyGatherFiles(resolve(path, file.name), files)
|
|
133
|
+
} else {
|
|
134
|
+
files[resolve(path, file.name)] = (
|
|
135
|
+
await readFile(resolve(path, file.name))
|
|
136
|
+
).toString()
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function compareFiles(
|
|
142
|
+
path: string,
|
|
143
|
+
ignore: Array<string>,
|
|
144
|
+
original: Record<string, string>,
|
|
145
|
+
changedFiles: Record<string, string>,
|
|
146
|
+
) {
|
|
147
|
+
const files = await readdir(path, { withFileTypes: true })
|
|
148
|
+
for (const file of files) {
|
|
149
|
+
const filePath = `${path}/${file.name}`
|
|
150
|
+
if (!ignore.includes(file.name)) {
|
|
151
|
+
if (file.isDirectory()) {
|
|
152
|
+
await compareFiles(filePath, ignore, original, changedFiles)
|
|
153
|
+
} else {
|
|
154
|
+
const contents = (await readFile(filePath)).toString()
|
|
155
|
+
const absolutePath = resolve(process.cwd(), filePath)
|
|
156
|
+
if (!original[absolutePath] || original[absolutePath] !== contents) {
|
|
157
|
+
changedFiles[filePath] = contents
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export async function initAddOn(mode: AddOnMode) {
|
|
165
|
+
const persistedOptions = await readConfigFile(process.cwd())
|
|
166
|
+
if (!persistedOptions) {
|
|
167
|
+
console.error(`${chalk.red('There is no .cta.json file in your project.')}
|
|
168
|
+
|
|
169
|
+
This is probably because this was created with an older version of create-tsrouter-app.`)
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (mode === 'add-on') {
|
|
174
|
+
if (persistedOptions.mode !== 'file-router') {
|
|
175
|
+
console.error(`${chalk.red('This project is not using file-router mode.')}
|
|
176
|
+
|
|
177
|
+
To create an add-on, the project must be created with the file-router mode.`)
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
if (!persistedOptions.tailwind) {
|
|
181
|
+
console.error(`${chalk.red('This project is not using Tailwind CSS.')}
|
|
182
|
+
|
|
183
|
+
To create an add-on, the project must be created with Tailwind CSS.`)
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
if (!persistedOptions.typescript) {
|
|
187
|
+
console.error(`${chalk.red('This project is not using TypeScript.')}
|
|
188
|
+
|
|
189
|
+
To create an add-on, the project must be created with TypeScript.`)
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const info = existsSync(INFO_FILE[mode])
|
|
195
|
+
? JSON.parse((await readFile(INFO_FILE[mode])).toString())
|
|
196
|
+
: {
|
|
197
|
+
name: `${persistedOptions.projectName}-${mode}`,
|
|
198
|
+
version: '0.0.1',
|
|
199
|
+
description: mode === 'add-on' ? 'Add-on' : 'Project overlay',
|
|
200
|
+
author: 'Jane Smith <jane.smith@example.com>',
|
|
201
|
+
license: 'MIT',
|
|
202
|
+
link: `https://github.com/jane-smith/${persistedOptions.projectName}-${mode}`,
|
|
203
|
+
command: {},
|
|
204
|
+
shadcnComponents: [],
|
|
205
|
+
templates: [persistedOptions.mode],
|
|
206
|
+
routes: [],
|
|
207
|
+
warning: '',
|
|
208
|
+
variables: {},
|
|
209
|
+
phase: 'add-on',
|
|
210
|
+
type: mode,
|
|
211
|
+
packageAdditions: {
|
|
212
|
+
scripts: {},
|
|
213
|
+
dependencies: {},
|
|
214
|
+
devDependencies: {},
|
|
215
|
+
},
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const compiledInfo = JSON.parse(JSON.stringify(info))
|
|
219
|
+
|
|
220
|
+
const originalOutput = await runCreateApp(
|
|
221
|
+
await createOptions(persistedOptions),
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
const originalPackageJson = JSON.parse(
|
|
225
|
+
originalOutput.files[resolve(process.cwd(), 'package.json')],
|
|
226
|
+
)
|
|
227
|
+
const currentPackageJson = JSON.parse(
|
|
228
|
+
(await readFile('package.json')).toString(),
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
for (const script of Object.keys(currentPackageJson.scripts)) {
|
|
232
|
+
if (
|
|
233
|
+
originalPackageJson.scripts[script] !== currentPackageJson.scripts[script]
|
|
234
|
+
) {
|
|
235
|
+
info.packageAdditions.scripts[script] = currentPackageJson.scripts[script]
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const dependencies: Record<string, string> = {}
|
|
240
|
+
for (const dependency of Object.keys(currentPackageJson.dependencies)) {
|
|
241
|
+
if (
|
|
242
|
+
originalPackageJson.dependencies[dependency] !==
|
|
243
|
+
currentPackageJson.dependencies[dependency]
|
|
244
|
+
) {
|
|
245
|
+
dependencies[dependency] = currentPackageJson.dependencies[dependency]
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
info.packageAdditions.dependencies = dependencies
|
|
249
|
+
|
|
250
|
+
const devDependencies: Record<string, string> = {}
|
|
251
|
+
for (const dependency of Object.keys(currentPackageJson.devDependencies)) {
|
|
252
|
+
if (
|
|
253
|
+
originalPackageJson.devDependencies[dependency] !==
|
|
254
|
+
currentPackageJson.devDependencies[dependency]
|
|
255
|
+
) {
|
|
256
|
+
devDependencies[dependency] =
|
|
257
|
+
currentPackageJson.devDependencies[dependency]
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
info.packageAdditions.devDependencies = devDependencies
|
|
261
|
+
|
|
262
|
+
// Find altered files
|
|
263
|
+
const changedFiles: Record<string, string> = {}
|
|
264
|
+
await compareFiles('.', IGNORE_FILES, originalOutput.files, changedFiles)
|
|
265
|
+
if (mode === 'overlay') {
|
|
266
|
+
compiledInfo.files = changedFiles
|
|
267
|
+
} else {
|
|
268
|
+
const assetsDir = resolve(ADD_ON_DIR, ASSETS_DIR)
|
|
269
|
+
if (!existsSync(assetsDir)) {
|
|
270
|
+
await compareFiles('.', IGNORE_FILES, originalOutput.files, changedFiles)
|
|
271
|
+
for (const file of Object.keys(changedFiles).filter(
|
|
272
|
+
(file) => !ADD_ON_IGNORE_FILES.includes(basename(file)),
|
|
273
|
+
)) {
|
|
274
|
+
mkdirSync(dirname(resolve(assetsDir, file)), {
|
|
275
|
+
recursive: true,
|
|
276
|
+
})
|
|
277
|
+
if (file.includes('/routes/')) {
|
|
278
|
+
const { url, code, name } = templatize(changedFiles[file], file)
|
|
279
|
+
info.routes.push({
|
|
280
|
+
url,
|
|
281
|
+
name,
|
|
282
|
+
})
|
|
283
|
+
writeFileSync(resolve(assetsDir, `${file}.ejs`), code)
|
|
284
|
+
} else {
|
|
285
|
+
writeFileSync(resolve(assetsDir, file), changedFiles[file])
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const addOnFiles: Record<string, string> = {}
|
|
290
|
+
await recursivelyGatherFiles(assetsDir, addOnFiles)
|
|
291
|
+
compiledInfo.files = Object.keys(addOnFiles).reduce(
|
|
292
|
+
(acc, file) => {
|
|
293
|
+
acc[file.replace(assetsDir, '.')] = addOnFiles[file]
|
|
294
|
+
return acc
|
|
295
|
+
},
|
|
296
|
+
{} as Record<string, string>,
|
|
297
|
+
)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
compiledInfo.routes = info.routes
|
|
301
|
+
compiledInfo.framework = persistedOptions.framework
|
|
302
|
+
compiledInfo.addDependencies = persistedOptions.existingAddOns
|
|
303
|
+
|
|
304
|
+
if (mode === 'overlay') {
|
|
305
|
+
compiledInfo.mode = persistedOptions.mode
|
|
306
|
+
compiledInfo.typescript = persistedOptions.typescript
|
|
307
|
+
compiledInfo.tailwind = persistedOptions.tailwind
|
|
308
|
+
|
|
309
|
+
compiledInfo.deletedFiles = []
|
|
310
|
+
for (const file of Object.keys(originalOutput.files)) {
|
|
311
|
+
if (!existsSync(file)) {
|
|
312
|
+
compiledInfo.deletedFiles.push(file.replace(process.cwd(), '.'))
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (!existsSync(resolve(INFO_FILE[mode]))) {
|
|
318
|
+
mkdirSync(resolve(dirname(INFO_FILE[mode])), { recursive: true })
|
|
319
|
+
writeFileSync(INFO_FILE[mode], JSON.stringify(info, null, 2))
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
writeFileSync(COMPILED_FILE[mode], JSON.stringify(compiledInfo, null, 2))
|
|
323
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appendFile,
|
|
3
|
+
copyFile,
|
|
4
|
+
mkdir,
|
|
5
|
+
readFile,
|
|
6
|
+
unlink,
|
|
7
|
+
writeFile,
|
|
8
|
+
} from 'node:fs/promises'
|
|
9
|
+
import { existsSync, readdirSync, statSync } from 'node:fs'
|
|
10
|
+
import { dirname } from 'node:path'
|
|
11
|
+
import { execa } from 'execa'
|
|
12
|
+
import { memfs } from 'memfs'
|
|
13
|
+
|
|
14
|
+
import type { Environment } from './types.js'
|
|
15
|
+
|
|
16
|
+
export function createDefaultEnvironment(): Environment {
|
|
17
|
+
let errors: Array<string> = []
|
|
18
|
+
return {
|
|
19
|
+
startRun: () => {
|
|
20
|
+
errors = []
|
|
21
|
+
},
|
|
22
|
+
finishRun: () => {},
|
|
23
|
+
getErrors: () => errors,
|
|
24
|
+
|
|
25
|
+
appendFile: async (path: string, contents: string) => {
|
|
26
|
+
await mkdir(dirname(path), { recursive: true })
|
|
27
|
+
return appendFile(path, contents)
|
|
28
|
+
},
|
|
29
|
+
copyFile: async (from: string, to: string) => {
|
|
30
|
+
await mkdir(dirname(to), { recursive: true })
|
|
31
|
+
return copyFile(from, to)
|
|
32
|
+
},
|
|
33
|
+
writeFile: async (path: string, contents: string) => {
|
|
34
|
+
await mkdir(dirname(path), { recursive: true })
|
|
35
|
+
return writeFile(path, contents)
|
|
36
|
+
},
|
|
37
|
+
execute: async (command: string, args: Array<string>, cwd: string) => {
|
|
38
|
+
try {
|
|
39
|
+
await execa(command, args, {
|
|
40
|
+
cwd,
|
|
41
|
+
})
|
|
42
|
+
} catch {
|
|
43
|
+
errors.push(
|
|
44
|
+
`Command "${command} ${args.join(' ')}" did not run successfully. Please run this manually in your project.`,
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
deleteFile: async (path: string) => {
|
|
49
|
+
await unlink(path)
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
readFile: (path: string, encoding?: BufferEncoding) =>
|
|
53
|
+
readFile(path, { encoding: encoding || 'utf8' }),
|
|
54
|
+
exists: (path: string) => existsSync(path),
|
|
55
|
+
readdir: (path) => readdirSync(path),
|
|
56
|
+
isDirectory: (path) => {
|
|
57
|
+
const stat = statSync(path)
|
|
58
|
+
return stat.isDirectory()
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function createMemoryEnvironment() {
|
|
64
|
+
const environment = createDefaultEnvironment()
|
|
65
|
+
|
|
66
|
+
const output: {
|
|
67
|
+
files: Record<string, string>
|
|
68
|
+
commands: Array<{
|
|
69
|
+
command: string
|
|
70
|
+
args: Array<string>
|
|
71
|
+
}>
|
|
72
|
+
} = {
|
|
73
|
+
files: {},
|
|
74
|
+
commands: [],
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const { fs, vol } = memfs({})
|
|
78
|
+
|
|
79
|
+
const cwd = process.cwd()
|
|
80
|
+
const isInCwd = (path: string) => path.startsWith(cwd)
|
|
81
|
+
const isTemplatePath = (path: string) => !isInCwd(path)
|
|
82
|
+
|
|
83
|
+
environment.appendFile = async (path: string, contents: string) => {
|
|
84
|
+
fs.mkdirSync(dirname(path), { recursive: true })
|
|
85
|
+
await fs.appendFileSync(path, contents)
|
|
86
|
+
}
|
|
87
|
+
environment.copyFile = async (from: string, to: string) => {
|
|
88
|
+
if (isTemplatePath(from)) {
|
|
89
|
+
const contents = (await readFile(from)).toString()
|
|
90
|
+
fs.mkdirSync(dirname(to), { recursive: true })
|
|
91
|
+
fs.writeFileSync(to, contents)
|
|
92
|
+
} else {
|
|
93
|
+
fs.mkdirSync(dirname(to), { recursive: true })
|
|
94
|
+
fs.copyFileSync(from, to)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
environment.execute = async (command: string, args: Array<string>) => {
|
|
98
|
+
output.commands.push({
|
|
99
|
+
command,
|
|
100
|
+
args,
|
|
101
|
+
})
|
|
102
|
+
return Promise.resolve()
|
|
103
|
+
}
|
|
104
|
+
environment.readFile = async (path: string, encoding?: BufferEncoding) => {
|
|
105
|
+
if (isTemplatePath(path)) {
|
|
106
|
+
return (await readFile(path, encoding)).toString()
|
|
107
|
+
}
|
|
108
|
+
return fs.readFileSync(path, 'utf8').toString()
|
|
109
|
+
}
|
|
110
|
+
environment.writeFile = async (path: string, contents: string) => {
|
|
111
|
+
fs.mkdirSync(dirname(path), { recursive: true })
|
|
112
|
+
await fs.writeFileSync(path, contents)
|
|
113
|
+
}
|
|
114
|
+
environment.deleteFile = async (path: string) => {
|
|
115
|
+
await fs.unlinkSync(path)
|
|
116
|
+
}
|
|
117
|
+
environment.exists = (path: string) => {
|
|
118
|
+
if (isTemplatePath(path)) {
|
|
119
|
+
return existsSync(path)
|
|
120
|
+
}
|
|
121
|
+
return fs.existsSync(path)
|
|
122
|
+
}
|
|
123
|
+
environment.readdir = (path: string) => {
|
|
124
|
+
if (isTemplatePath(path)) {
|
|
125
|
+
return readdirSync(path)
|
|
126
|
+
}
|
|
127
|
+
return fs.readdirSync(path).map((file) => file.toString())
|
|
128
|
+
}
|
|
129
|
+
environment.isDirectory = (path) => {
|
|
130
|
+
if (isTemplatePath(path)) {
|
|
131
|
+
const stat = statSync(path)
|
|
132
|
+
return stat.isDirectory()
|
|
133
|
+
}
|
|
134
|
+
return fs.statSync(path).isDirectory()
|
|
135
|
+
}
|
|
136
|
+
environment.finishRun = () => {
|
|
137
|
+
output.files = vol.toJSON() as Record<string, string>
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
environment,
|
|
142
|
+
output,
|
|
143
|
+
}
|
|
144
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { cli } from './cli.js'
|
package/src/mcp.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
+
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
4
|
+
import express from 'express'
|
|
5
|
+
import { z } from 'zod'
|
|
6
|
+
|
|
7
|
+
import { createApp } from './create-app.js'
|
|
8
|
+
import { finalizeAddOns } from './add-ons.js'
|
|
9
|
+
import { createDefaultEnvironment } from './environment.js'
|
|
10
|
+
|
|
11
|
+
const server = new McpServer({
|
|
12
|
+
name: 'Demo',
|
|
13
|
+
version: '1.0.0',
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const tanStackReactAddOns = [
|
|
17
|
+
{
|
|
18
|
+
id: 'clerk',
|
|
19
|
+
description: 'Enable authentication with Clerk',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: 'convex',
|
|
23
|
+
description: 'Enable a database using Convex',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 'form',
|
|
27
|
+
description: 'Form handling library',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: 'netlify',
|
|
31
|
+
description: 'Enable deployments to Netlify',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'sentry',
|
|
35
|
+
description: 'Enable Sentry error tracking',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'shadcn',
|
|
39
|
+
description: 'Enable integration of the Shadcn UI component library',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'start',
|
|
43
|
+
description:
|
|
44
|
+
'Set this if you want a TanStack Start application that supports server functions or APIs',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'tanstack-query',
|
|
48
|
+
description: 'Enable TanStack Query for data fetching',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'store',
|
|
52
|
+
description: 'Enable the TanStack Store state management library',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'tanchat',
|
|
56
|
+
description: 'Add an AI chatbot example to the application',
|
|
57
|
+
},
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
server.tool('listTanStackReactAddOns', {}, () => {
|
|
61
|
+
return {
|
|
62
|
+
content: [{ type: 'text', text: JSON.stringify(tanStackReactAddOns) }],
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
server.tool(
|
|
67
|
+
'createTanStackReactApplication',
|
|
68
|
+
{
|
|
69
|
+
projectName: z
|
|
70
|
+
.string()
|
|
71
|
+
.describe(
|
|
72
|
+
'The package.json module name of the application (will also be the directory name)',
|
|
73
|
+
),
|
|
74
|
+
cwd: z.string().describe('The directory to create the application in'),
|
|
75
|
+
addOns: z
|
|
76
|
+
.array(
|
|
77
|
+
z.enum([
|
|
78
|
+
'clerk',
|
|
79
|
+
'convex',
|
|
80
|
+
'form',
|
|
81
|
+
'netlify',
|
|
82
|
+
'sentry',
|
|
83
|
+
'shadcn',
|
|
84
|
+
'start',
|
|
85
|
+
'store',
|
|
86
|
+
'tanstack-query',
|
|
87
|
+
'tanchat',
|
|
88
|
+
]),
|
|
89
|
+
)
|
|
90
|
+
.describe('The IDs of the add-ons to install'),
|
|
91
|
+
},
|
|
92
|
+
async ({ projectName, addOns, cwd }) => {
|
|
93
|
+
try {
|
|
94
|
+
process.chdir(cwd)
|
|
95
|
+
const chosenAddOns = await finalizeAddOns(
|
|
96
|
+
'react',
|
|
97
|
+
'file-router',
|
|
98
|
+
addOns as unknown as Array<string>,
|
|
99
|
+
)
|
|
100
|
+
await createApp(
|
|
101
|
+
{
|
|
102
|
+
projectName: projectName.replace(/^\//, './'),
|
|
103
|
+
framework: 'react',
|
|
104
|
+
typescript: true,
|
|
105
|
+
tailwind: true,
|
|
106
|
+
packageManager: 'pnpm',
|
|
107
|
+
toolchain: 'none',
|
|
108
|
+
mode: 'file-router',
|
|
109
|
+
addOns: true,
|
|
110
|
+
chosenAddOns,
|
|
111
|
+
git: true,
|
|
112
|
+
variableValues: {},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
silent: true,
|
|
116
|
+
environment: createDefaultEnvironment(),
|
|
117
|
+
},
|
|
118
|
+
)
|
|
119
|
+
return {
|
|
120
|
+
content: [{ type: 'text', text: 'Application created successfully' }],
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
return {
|
|
124
|
+
content: [
|
|
125
|
+
{ type: 'text', text: `Error creating application: ${error}` },
|
|
126
|
+
],
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
const tanStackSolidAddOns = [
|
|
133
|
+
{
|
|
134
|
+
id: 'solid-ui',
|
|
135
|
+
description: 'Enable integration of the Solid UI component library',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: 'form',
|
|
139
|
+
description: 'Form handling library',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: 'sentry',
|
|
143
|
+
description: 'Enable Sentry error tracking',
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: 'store',
|
|
147
|
+
description: 'Enable the TanStack Store state management library',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: 'tanstack-query',
|
|
151
|
+
description: 'Enable TanStack Query for data fetching',
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: 'tanchat',
|
|
155
|
+
description: 'Add an AI chatbot example to the application',
|
|
156
|
+
},
|
|
157
|
+
]
|
|
158
|
+
|
|
159
|
+
server.tool('listTanStackSolidAddOns', {}, () => {
|
|
160
|
+
return {
|
|
161
|
+
content: [{ type: 'text', text: JSON.stringify(tanStackSolidAddOns) }],
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
server.tool(
|
|
166
|
+
'createTanStackSolidApplication',
|
|
167
|
+
{
|
|
168
|
+
projectName: z
|
|
169
|
+
.string()
|
|
170
|
+
.describe(
|
|
171
|
+
'The package.json module name of the application (will also be the directory name)',
|
|
172
|
+
),
|
|
173
|
+
cwd: z.string().describe('The directory to create the application in'),
|
|
174
|
+
addOns: z
|
|
175
|
+
.array(
|
|
176
|
+
z.enum([
|
|
177
|
+
'solid-ui',
|
|
178
|
+
'form',
|
|
179
|
+
'sentry',
|
|
180
|
+
'store',
|
|
181
|
+
'tanstack-query',
|
|
182
|
+
'tanchat',
|
|
183
|
+
]),
|
|
184
|
+
)
|
|
185
|
+
.describe('The IDs of the add-ons to install'),
|
|
186
|
+
},
|
|
187
|
+
async ({ projectName, addOns, cwd }) => {
|
|
188
|
+
try {
|
|
189
|
+
process.chdir(cwd)
|
|
190
|
+
const chosenAddOns = await finalizeAddOns(
|
|
191
|
+
'solid',
|
|
192
|
+
'file-router',
|
|
193
|
+
addOns as unknown as Array<string>,
|
|
194
|
+
)
|
|
195
|
+
await createApp(
|
|
196
|
+
{
|
|
197
|
+
projectName: projectName.replace(/^\//, './'),
|
|
198
|
+
framework: 'solid',
|
|
199
|
+
typescript: true,
|
|
200
|
+
tailwind: true,
|
|
201
|
+
packageManager: 'pnpm',
|
|
202
|
+
toolchain: 'none',
|
|
203
|
+
mode: 'file-router',
|
|
204
|
+
addOns: true,
|
|
205
|
+
chosenAddOns,
|
|
206
|
+
git: true,
|
|
207
|
+
variableValues: {},
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
silent: true,
|
|
211
|
+
environment: createDefaultEnvironment(),
|
|
212
|
+
},
|
|
213
|
+
)
|
|
214
|
+
return {
|
|
215
|
+
content: [{ type: 'text', text: 'Application created successfully' }],
|
|
216
|
+
}
|
|
217
|
+
} catch (error) {
|
|
218
|
+
return {
|
|
219
|
+
content: [
|
|
220
|
+
{ type: 'text', text: `Error creating application: ${error}` },
|
|
221
|
+
],
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
export default async function runServer(sse: boolean) {
|
|
228
|
+
if (sse) {
|
|
229
|
+
const app = express()
|
|
230
|
+
|
|
231
|
+
let transport: SSEServerTransport | null = null
|
|
232
|
+
|
|
233
|
+
app.get('/sse', (req, res) => {
|
|
234
|
+
transport = new SSEServerTransport('/messages', res)
|
|
235
|
+
server.connect(transport)
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
app.post('/messages', (req, res) => {
|
|
239
|
+
if (transport) {
|
|
240
|
+
transport.handlePostMessage(req, res)
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
const port = process.env.PORT || 8080
|
|
245
|
+
app.listen(port, () => {
|
|
246
|
+
console.log(`Server is running on port http://localhost:${port}/sse`)
|
|
247
|
+
})
|
|
248
|
+
} else {
|
|
249
|
+
const transport = new StdioServerTransport()
|
|
250
|
+
await server.connect(transport)
|
|
251
|
+
}
|
|
252
|
+
}
|