-
-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathfeatures.ts
More file actions
132 lines (116 loc) · 3.35 KB
/
features.ts
File metadata and controls
132 lines (116 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { getAllAddOns, type AddOn, type AddOnOption } from '@tanstack/create'
import { getFramework, DEFAULT_MODE, DEFAULT_REQUIRED_ADDONS, type FrameworkId } from './config'
import { partners } from '~/utils/partners'
// Set of active partner IDs for matching addons to partners
const activePartnerIds = new Set(
partners.filter((p) => p.status === 'active').map((p) => p.id),
)
const isDev = process.env.NODE_ENV !== 'production'
function normalizeUrl(url: string | undefined) {
if (!url) return url
if (isDev) {
return url.replace(/^https?:\/\/tanstack\.com/, '')
}
return url
}
export interface FeatureOption {
key: string
type: 'select' | 'boolean' | 'string'
label: string
description?: string
default: string | boolean | number | null
choices?: Array<{ value: string; label: string }>
}
export interface FeatureInfo {
id: string
name: string
description: string
category: string
requires: Array<string>
exclusive: Array<string>
hasOptions: boolean
options?: Array<FeatureOption>
link?: string
color?: string
partnerId?: string
requiresTailwind?: boolean
}
export interface FeaturesResponse {
features: Array<FeatureInfo>
examples: Array<FeatureInfo>
version: string
}
function mapAddOnOptions(addOn: AddOn): Array<FeatureOption> | undefined {
if (!addOn.options) return undefined
return Object.entries(addOn.options).map(([key, opt]) => {
const option = opt as AddOnOption
return {
key,
type: option.type,
label: option.label,
description: option.description,
default: option.default,
choices: option.type === 'select' ? option.options : undefined,
}
})
}
function getCategoryFromType(type: string): string {
switch (type) {
case 'deployment':
return 'deploy'
case 'toolchain':
return 'tooling'
case 'example':
return 'example'
default:
return 'other'
}
}
const CATEGORY_OVERRIDES: Record<string, string> = {
shopify: 'ecommerce',
}
function toFeatureInfo(addOn: AddOn): FeatureInfo {
// Type assertion for new fields that may not be in the cta-engine types yet
const addon = addOn as AddOn & {
category?: string
exclusive?: Array<string>
color?: string
}
return {
id: addon.id,
name: addon.name,
description: addon.description,
category:
CATEGORY_OVERRIDES[addon.id] ??
addon.category ??
getCategoryFromType(addon.type),
requires: addon.dependsOn ?? [],
exclusive: addon.exclusive ?? [],
hasOptions: !!addon.options,
options: mapAddOnOptions(addon),
link: normalizeUrl(addon.link),
color: addon.color,
partnerId: activePartnerIds.has(addon.id) ? addon.id : undefined,
requiresTailwind: addon.tailwind === true ? undefined : !addon.tailwind,
}
}
export async function getFeaturesHandler(
frameworkId: FrameworkId = 'react',
): Promise<FeaturesResponse> {
const framework = getFramework(frameworkId)
const allAddOns = getAllAddOns(framework, DEFAULT_MODE)
const features = allAddOns
.filter((addOn: AddOn) => {
if (DEFAULT_REQUIRED_ADDONS.includes(addOn.id)) return false
return ['add-on', 'deployment', 'toolchain'].includes(addOn.type)
})
.map(toFeatureInfo)
const examples = allAddOns
.filter((addOn: AddOn) => addOn.type === 'example')
.map(toFeatureInfo)
return {
features,
examples,
version: '1.0.0',
}
}