Skip to content

Commit 475e6eb

Browse files
committed
chore: more docs and removing unused variables support
1 parent 7e3ad79 commit 475e6eb

File tree

10 files changed

+142
-130
lines changed

10 files changed

+142
-130
lines changed

ARCHITECTURE.md

+25
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,28 @@
2424

2525
- `@tanstack/cta-frameworks-react-cra` - The React (Create React App) framework for TanStack CTA.
2626
- `@tanstack/cta-frameworks-solid` - The Solid framework for TanStack CTA.
27+
28+
## File Templates
29+
30+
The CTA system uses EJS to render the files into the final application.
31+
32+
Below are all of the variables that are available to the file templates.
33+
34+
| Variable | Description |
35+
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
36+
| `packageManager` | The package manager that is being used (e.g. `npm`, `yarn`, `pnpm`) |
37+
| `projectName` | The name of the project |
38+
| `typescript` | Boolean value that is `true` if TypeScript is being used, otherwise it is `false` |
39+
| `tailwind` | Boolean value that is `true` if Tailwind CSS is being used, otherwise it is `false` |
40+
| `js` | The file extension for files that do not include JSX. When in TypeScript mode it is `ts`. When in JavaScript mode it is `js`. |
41+
| `jsx` | The file extension for files that include JSX. When in TypeScript mode it is `tsx`. When in JavaScript mode it is `jsx`. |
42+
| `fileRouter` | Boolean value that is `true` if the file router is being used, otherwise it is `false` |
43+
| `codeRouter` | Boolean value that is `true` if the code router is being used, otherwise it is `false` |
44+
| `addOnEnabled` | An object that contains the enabled add-ons. The keys are the `id` values of the add-ons. For example, if the tanstack-query add-on is enabled the `addOnEnabled]['tanstack-query']` will be `true`. |
45+
| `addOns` | An array of the enabled add-on objects |
46+
| `integrations` | An array of the enabled integrations |
47+
| `routes` | An array containing all of the routes from all of the add-ons. (Used by the header and the `code-router` setup.) |
48+
| `getPackageManagerAddScript` | A function that returns the script to add a dependency to the project. |
49+
| `getPackageManagerRunScript` | A function that returns the script to run a command in the project. |
50+
| `relativePath` | A function that returns the relative path from the current file to the specified target file. |
51+
| `ignoreFile` | A function that if called will tell CTA to not include this file in the application. |

frameworks/react-cra/ADD-ON-AUTHORING.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Add-on Authoring for the React CRA Template System
1+
# Add-on Authoring for the CTA Framework for React CRA
22

33
# Available Integrations
44

@@ -135,3 +135,35 @@ Configuration in `info.json`:
135135
},
136136
]
137137
```
138+
139+
# Routes
140+
141+
If your add-on creates routes you need to specify those in the `info.json` file.
142+
143+
This example will define a route at `/demo/my-demo-route` that will be rendered by the `DemoMyDemoRoute` component. There will be a `Demo Route` link in the header to this route.
144+
145+
```json
146+
"routes": [
147+
{
148+
"url": "/demo/my-demo-route",
149+
"name": "Demo Route",
150+
"path": "src/routes/demo.my-demo-route.tsx",
151+
"jsName": "DemoMyDemoRoute"
152+
}
153+
],
154+
```
155+
156+
If you don't want a header link you can omit the `url` and `name` properties.
157+
158+
```json
159+
"routes": [
160+
{
161+
"path": "src/routes/demo.my-hidden-demo-route.tsx",
162+
"jsName": "DemoMyHiddenDemoRoute"
163+
}
164+
],
165+
```
166+
167+
You **MUST** specify routes in the `info.json` file if your add-on supports the `code-router` mode. This is because the `code-routers` setup needs to import the routes in order to add them to the router.
168+
169+
By convension you should prefix demo routes with `demo` to make it clear that they are demo routes so they can be easily identified and removed.

frameworks/solid/ADD-ON-AUTHORING.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Add-on Authoring for the Solid Framework
1+
# Add-on Authoring for the CTA Framework for Solid
22

33
# Available Integrations
44

@@ -95,3 +95,35 @@ Configuration in `info.json`:
9595
},
9696
]
9797
```
98+
99+
# Routes
100+
101+
If your add-on creates routes you need to specify those in the `info.json` file.
102+
103+
This example will define a route at `/demo/my-demo-route` that will be rendered by the `DemoMyDemoRoute` component. There will be a `Demo Route` link in the header to this route.
104+
105+
```json
106+
"routes": [
107+
{
108+
"url": "/demo/my-demo-route",
109+
"name": "Demo Route",
110+
"path": "src/routes/demo.my-demo-route.tsx",
111+
"jsName": "DemoMyDemoRoute"
112+
}
113+
],
114+
```
115+
116+
If you don't want a header link you can omit the `url` and `name` properties.
117+
118+
```json
119+
"routes": [
120+
{
121+
"path": "src/routes/demo.my-hidden-demo-route.tsx",
122+
"jsName": "DemoMyHiddenDemoRoute"
123+
}
124+
],
125+
```
126+
127+
You **MUST** specify routes in the `info.json` file if your add-on supports the `code-router` mode. This is because the `code-routers` setup needs to import the routes in order to add them to the router.
128+
129+
By convension you should prefix demo routes with `demo` to make it clear that they are demo routes so they can be easily identified and removed.

packages/cta-cli/src/command-line.ts

-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,5 @@ export async function normalizeOptions(
111111
git: !!cliOptions.git,
112112
chosenAddOns,
113113
starter,
114-
variableValues: {},
115114
}
116115
}

packages/cta-cli/src/options.ts

-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ export async function promptForOptions(
122122
options.typescript = true
123123
}
124124

125-
options.variableValues = {}
126-
127125
options.git = cliOptions.git || (await selectGit())
128126

129127
return options

packages/cta-engine/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export type {
3838
Mode,
3939
Options,
4040
Starter,
41-
Variable,
4241
} from './types.js'
4342
export type { PersistedOptions } from './config-file.js'
4443
export type { PackageManager } from './package-manager.js'

packages/cta-engine/src/template-file.ts

-11
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@ export function createTemplateFile(environment: Environment, options: Options) {
6767
}
6868
}
6969

70-
const variables = {
71-
...options.variableValues,
72-
...options.chosenAddOns.reduce<Record<string, any>>((acc, addOn) => {
73-
return {
74-
...acc,
75-
...addOn.variables,
76-
}
77-
}, {}),
78-
}
79-
8070
const addOnEnabled = options.chosenAddOns.reduce<Record<string, boolean>>(
8171
(acc, addOn) => {
8272
acc[addOn.id] = true
@@ -99,7 +89,6 @@ export function createTemplateFile(environment: Environment, options: Options) {
9989
addOns: options.chosenAddOns,
10090
integrations,
10191
routes,
102-
variables,
10392

10493
getPackageManagerAddScript,
10594
getPackageManagerRunScript,

packages/cta-engine/src/types.ts

-26
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export type AddOnDefinition = {
4242
warning?: string
4343
dependsOn?: Array<string>
4444
integrations?: Array<Integration>
45-
variables?: Array<Variable>
4645

4746
files?: Record<string, string>
4847
deletedFiles?: Array<string>
@@ -97,8 +96,6 @@ export interface Options {
9796

9897
chosenAddOns: Array<AddOn>
9998
starter?: AddOn | undefined
100-
101-
variableValues: Record<string, string | number | boolean>
10299
}
103100

104101
type ProjectEnvironment = {
@@ -134,26 +131,3 @@ type UIEnvironment = {
134131
}
135132

136133
export type Environment = ProjectEnvironment & FileEnvironment & UIEnvironment
137-
138-
type BooleanVariable = {
139-
name: string
140-
default: boolean
141-
description: string
142-
type: 'boolean'
143-
}
144-
145-
type NumberVariable = {
146-
name: string
147-
default: number
148-
description: string
149-
type: 'number'
150-
}
151-
152-
type StringVariable = {
153-
name: string
154-
default: string
155-
description: string
156-
type: 'string'
157-
}
158-
159-
export type Variable = BooleanVariable | NumberVariable | StringVariable

0 commit comments

Comments
 (0)