@tamagui/cli 2.0.0-rc.4 → 2.0.0-rc.40
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/dist/add.cjs +96 -71
- package/dist/build.cjs +226 -133
- package/dist/cli.cjs +318 -268
- package/dist/generate-prompt.cjs +310 -261
- package/dist/generate.cjs +51 -38
- package/dist/update-template.cjs +43 -31
- package/dist/update.cjs +12 -10
- package/dist/upgrade.cjs +274 -162
- package/dist/utils.cjs +69 -44
- package/package.json +9 -8
- package/src/build.ts +190 -56
- package/src/cli.ts +20 -73
- package/src/generate-prompt.ts +1 -1
- package/src/utils.ts +13 -8
- package/types/build.d.ts +3 -0
- package/types/build.d.ts.map +1 -1
- package/types/generate-prompt.d.ts.map +1 -1
- package/types/utils.d.ts.map +1 -1
- package/dist/add.js +0 -91
- package/dist/add.js.map +0 -6
- package/dist/build.js +0 -188
- package/dist/build.js.map +0 -6
- package/dist/cli.js +0 -266
- package/dist/cli.js.map +0 -6
- package/dist/generate-prompt.js +0 -392
- package/dist/generate-prompt.js.map +0 -6
- package/dist/generate.js +0 -62
- package/dist/generate.js.map +0 -6
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -6
- package/dist/update-template.js +0 -57
- package/dist/update-template.js.map +0 -6
- package/dist/update.js +0 -22
- package/dist/update.js.map +0 -6
- package/dist/upgrade.js +0 -319
- package/dist/upgrade.js.map +0 -6
- package/dist/utils.js +0 -92
- package/dist/utils.js.map +0 -6
package/dist/generate-prompt.cjs
CHANGED
|
@@ -2,355 +2,404 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var generate_prompt_exports = {};
|
|
33
35
|
__export(generate_prompt_exports, {
|
|
34
36
|
generatePrompt: () => generatePrompt
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(generate_prompt_exports);
|
|
37
|
-
var import_node_path = require("node:path")
|
|
38
|
-
|
|
39
|
-
import_static = require("@tamagui/static");
|
|
39
|
+
var import_node_path = require("node:path");
|
|
40
|
+
var FS = __toESM(require("fs-extra"));
|
|
40
41
|
async function generatePrompt(options) {
|
|
41
42
|
const {
|
|
42
43
|
paths,
|
|
43
44
|
output
|
|
44
45
|
} = options;
|
|
45
|
-
|
|
46
|
+
const {
|
|
47
|
+
loadTamagui
|
|
48
|
+
} = require("@tamagui/static/loadTamagui");
|
|
49
|
+
process.env.TAMAGUI_KEEP_THEMES = "1";
|
|
50
|
+
await loadTamagui({
|
|
46
51
|
...options.tamaguiOptions,
|
|
47
52
|
platform: "web"
|
|
48
53
|
});
|
|
49
54
|
const configPath = (0, import_node_path.join)(paths.dotDir, "tamagui.config.json");
|
|
50
|
-
if (!FS.existsSync(configPath))
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
if (!FS.existsSync(configPath)) {
|
|
56
|
+
throw new Error(`Config file not found at ${configPath}. Please run 'tamagui generate' first.`);
|
|
57
|
+
}
|
|
58
|
+
const config = await FS.readJSON(configPath);
|
|
59
|
+
const markdown = generateMarkdown(config);
|
|
60
|
+
const outputPath = output || (0, import_node_path.join)(process.cwd(), "tamagui-prompt.md");
|
|
61
|
+
await FS.writeFile(outputPath, markdown, "utf-8");
|
|
62
|
+
console.info(`
|
|
55
63
|
\u2713 Generated prompt file at ${outputPath}
|
|
56
64
|
`);
|
|
57
65
|
}
|
|
58
66
|
function generateMarkdown(config) {
|
|
59
67
|
const sections = [];
|
|
60
|
-
sections.push(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
sections.push("# Tamagui Configuration\n\n");
|
|
69
|
+
sections.push("This document provides an overview of the Tamagui configuration for this project.\n\n");
|
|
70
|
+
const shorthands = config.tamaguiConfig?.shorthands || {};
|
|
71
|
+
const reverseShorthands = {};
|
|
72
|
+
for (const [short, full] of Object.entries(shorthands)) {
|
|
73
|
+
reverseShorthands[full] = short;
|
|
74
|
+
}
|
|
75
|
+
const getPropName = fullProp => {
|
|
76
|
+
const settings2 = config.tamaguiConfig?.settings || {};
|
|
77
|
+
if (settings2.onlyAllowShorthands && reverseShorthands[fullProp]) {
|
|
78
|
+
return reverseShorthands[fullProp];
|
|
79
|
+
}
|
|
80
|
+
return fullProp;
|
|
81
|
+
};
|
|
82
|
+
const settings = config.tamaguiConfig?.settings || {};
|
|
70
83
|
if (Object.keys(settings).length > 0) {
|
|
71
|
-
sections.push(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
`), settings.defaultFont && (sections.push(`### Default Font: \`${settings.defaultFont}\`
|
|
84
|
+
sections.push("## Configuration Settings\n\n");
|
|
85
|
+
sections.push("**IMPORTANT:** These settings affect how you write Tamagui code in this project.\n\n");
|
|
86
|
+
if (settings.defaultFont) {
|
|
87
|
+
sections.push(`### Default Font: \`${settings.defaultFont}\`
|
|
76
88
|
|
|
77
|
-
`)
|
|
78
|
-
|
|
79
|
-
`)), settings.onlyAllowShorthands !== void 0 && (sections.push(`### Only Allow Shorthands: \`${settings.onlyAllowShorthands}\`
|
|
80
|
-
|
|
81
|
-
`), settings.onlyAllowShorthands ? (sections.push(`**You MUST use shorthand properties in this project.**
|
|
82
|
-
|
|
83
|
-
`), sections.push(`Full property names are not allowed. For example:
|
|
84
|
-
`), sections.push('- \u2705 `<View w="$10" />` (correct)\n'), sections.push('- \u274C `<View width="$10" />` (will error)\n\n'), sections.push(`See the Shorthand Properties section below for all available shorthands.
|
|
85
|
-
|
|
86
|
-
`)) : sections.push(`You can use either shorthand or full property names.
|
|
89
|
+
`);
|
|
90
|
+
sections.push(`All text components will use the "${settings.defaultFont}" font family by default.
|
|
87
91
|
|
|
88
|
-
`)
|
|
92
|
+
`);
|
|
93
|
+
}
|
|
94
|
+
if (settings.onlyAllowShorthands !== void 0) {
|
|
95
|
+
sections.push(`### Only Allow Shorthands: \`${settings.onlyAllowShorthands}\`
|
|
89
96
|
|
|
90
|
-
`)
|
|
97
|
+
`);
|
|
98
|
+
if (settings.onlyAllowShorthands) {
|
|
99
|
+
sections.push("**You MUST use shorthand properties in this project.**\n\n");
|
|
100
|
+
sections.push("Full property names are not allowed. For example:\n");
|
|
101
|
+
sections.push('- \u2705 `<View w="$10" />` (correct)\n');
|
|
102
|
+
sections.push('- \u274C `<View width="$10" />` (will error)\n\n');
|
|
103
|
+
sections.push("See the Shorthand Properties section below for all available shorthands.\n\n");
|
|
104
|
+
} else {
|
|
105
|
+
sections.push("You can use either shorthand or full property names.\n\n");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (settings.themeClassNameOnRoot !== void 0) {
|
|
109
|
+
sections.push(`### Theme Class Name on Root: \`${settings.themeClassNameOnRoot}\`
|
|
91
110
|
|
|
92
|
-
`)
|
|
111
|
+
`);
|
|
112
|
+
if (settings.themeClassNameOnRoot) {
|
|
113
|
+
sections.push("Theme classes are applied to the root HTML element.\n\n");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
93
116
|
const platform = settings.platform || settings.defaultProps?.platform;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
`), platform === "web" ? sections.push(`This project is configured for **web only**.
|
|
97
|
-
|
|
98
|
-
`) : platform === "native" && sections.push(`This project is configured for **React Native only**.
|
|
99
|
-
|
|
100
|
-
`)), settings.webContainerType && (sections.push(`### Web Container Type: \`${settings.webContainerType}\`
|
|
117
|
+
if (platform) {
|
|
118
|
+
sections.push(`### Platform Mode: \`${platform}\`
|
|
101
119
|
|
|
102
|
-
`)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
120
|
+
`);
|
|
121
|
+
if (platform === "web") {
|
|
122
|
+
sections.push("This project is configured for **web only**.\n\n");
|
|
123
|
+
} else if (platform === "native") {
|
|
124
|
+
sections.push("This project is configured for **React Native only**.\n\n");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (settings.webContainerType) {
|
|
128
|
+
sections.push(`### Web Container Type: \`${settings.webContainerType}\`
|
|
108
129
|
|
|
109
|
-
`)
|
|
130
|
+
`);
|
|
131
|
+
sections.push("Enables web-specific container query optimizations.\n\n");
|
|
132
|
+
}
|
|
133
|
+
const configString = JSON.stringify(config.tamaguiConfig);
|
|
134
|
+
if (configString.includes("semi-strict-web")) {
|
|
135
|
+
sections.push("### Mode: `semi-strict-web`\n\n");
|
|
136
|
+
sections.push("This configuration uses semi-strict-web mode, which:\n");
|
|
137
|
+
sections.push("- Optimizes for web performance\n");
|
|
138
|
+
sections.push("- May have limited React Native API support\n");
|
|
139
|
+
sections.push("- Focuses on web-first development\n\n");
|
|
140
|
+
}
|
|
110
141
|
}
|
|
111
|
-
const componentsSection = []
|
|
112
|
-
|
|
142
|
+
const componentsSection = [];
|
|
143
|
+
const allComponents = [];
|
|
113
144
|
for (const componentModule of config.components) {
|
|
114
145
|
const componentNames = Object.keys(componentModule.nameToInfo);
|
|
115
146
|
allComponents.push(...componentNames);
|
|
116
147
|
}
|
|
117
|
-
const componentGroups = /* @__PURE__ */new Map()
|
|
118
|
-
|
|
119
|
-
|
|
148
|
+
const componentGroups = /* @__PURE__ */new Map();
|
|
149
|
+
const processed = /* @__PURE__ */new Set();
|
|
150
|
+
const sortedComponents = [...allComponents].sort((a, b) => a.length - b.length);
|
|
120
151
|
for (const name of sortedComponents) {
|
|
121
152
|
if (processed.has(name)) continue;
|
|
122
153
|
const children = allComponents.filter(other => other !== name && other.startsWith(name) && other[name.length]?.match(/[A-Z]/));
|
|
123
|
-
children.length > 0
|
|
154
|
+
if (children.length > 0) {
|
|
155
|
+
componentGroups.set(name, new Set(children));
|
|
156
|
+
processed.add(name);
|
|
157
|
+
children.forEach(child => processed.add(child));
|
|
158
|
+
}
|
|
124
159
|
}
|
|
125
160
|
const standaloneComponents = allComponents.filter(name => !processed.has(name));
|
|
126
|
-
componentsSection.push(
|
|
127
|
-
|
|
128
|
-
`), componentsSection.push(`The following components are available:
|
|
129
|
-
|
|
130
|
-
`);
|
|
161
|
+
componentsSection.push("## Components\n\n");
|
|
162
|
+
componentsSection.push("The following components are available:\n\n");
|
|
131
163
|
const allBaseComponents = [...standaloneComponents, ...Array.from(componentGroups.keys())].sort();
|
|
132
|
-
for (const name of allBaseComponents)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
164
|
+
for (const name of allBaseComponents) {
|
|
165
|
+
componentsSection.push(`- ${name}
|
|
166
|
+
`);
|
|
167
|
+
if (componentGroups.has(name)) {
|
|
168
|
+
const children = Array.from(componentGroups.get(name)).sort();
|
|
169
|
+
for (const child of children) {
|
|
170
|
+
const suffix = child.slice(name.length);
|
|
171
|
+
componentsSection.push(` - ${name}.${suffix}
|
|
138
172
|
`);
|
|
173
|
+
}
|
|
139
174
|
}
|
|
140
175
|
}
|
|
141
|
-
componentsSection.push(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
`), sections.push(`These shorthand properties are available for styling:
|
|
145
|
-
|
|
146
|
-
`);
|
|
176
|
+
componentsSection.push("\n");
|
|
177
|
+
sections.push("## Shorthand Properties\n\n");
|
|
178
|
+
sections.push("These shorthand properties are available for styling:\n\n");
|
|
147
179
|
const shorthandEntries = Object.entries(shorthands).sort(([a], [b]) => a.localeCompare(b));
|
|
148
|
-
sections.push(shorthandEntries.map(([short, full]) => `- \`${short}\` \u2192 \`${full}\``).join(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
level3: /* @__PURE__ */new Set(),
|
|
160
|
-
components: /* @__PURE__ */new Set()
|
|
161
|
-
};
|
|
180
|
+
sections.push(shorthandEntries.map(([short, full]) => `- \`${short}\` \u2192 \`${full}\``).join("\n"));
|
|
181
|
+
sections.push("\n\n");
|
|
182
|
+
sections.push("## Themes\n\n");
|
|
183
|
+
const themes = config.tamaguiConfig?.themes || {};
|
|
184
|
+
const themeNames = Object.keys(themes).sort();
|
|
185
|
+
const hierarchy = {
|
|
186
|
+
level1: /* @__PURE__ */new Set(),
|
|
187
|
+
level2: /* @__PURE__ */new Set(),
|
|
188
|
+
level3: /* @__PURE__ */new Set(),
|
|
189
|
+
components: /* @__PURE__ */new Set()
|
|
190
|
+
};
|
|
162
191
|
for (const themeName of themeNames) {
|
|
163
192
|
const parts = themeName.split("_");
|
|
164
193
|
if (parts[0] === "light" || parts[0] === "dark") {
|
|
165
|
-
hierarchy.level1.add(parts[0])
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
194
|
+
hierarchy.level1.add(parts[0]);
|
|
195
|
+
if (parts.length > 1 && parts[1] && !parts[1].startsWith("alt") && parts[1] !== "active") {
|
|
196
|
+
if (parts[1][0] === parts[1][0].toLowerCase()) {
|
|
197
|
+
hierarchy.level2.add(parts[1]);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (const part of parts) {
|
|
201
|
+
if (part.startsWith("alt") || part === "active") {
|
|
202
|
+
hierarchy.level3.add(part);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
for (const part of parts) {
|
|
206
|
+
if (part[0] && part[0] === part[0].toUpperCase() && part[0] !== part[0].toLowerCase()) {
|
|
207
|
+
hierarchy.components.add(part);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
if (parts.length === 1) {
|
|
212
|
+
hierarchy.level1.add(themeName);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
169
215
|
}
|
|
170
|
-
sections.push(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
`)
|
|
216
|
+
sections.push("Themes are organized hierarchically and can be combined:\n\n");
|
|
217
|
+
if (hierarchy.level1.size > 0) {
|
|
218
|
+
sections.push("**Level 1 (Base):**\n\n");
|
|
219
|
+
sections.push(Array.from(hierarchy.level1).sort().map(name => `- ${name}`).join("\n"));
|
|
220
|
+
sections.push("\n\n");
|
|
221
|
+
}
|
|
222
|
+
if (hierarchy.level2.size > 0) {
|
|
223
|
+
sections.push("**Level 2 (Color Schemes):**\n\n");
|
|
224
|
+
sections.push(Array.from(hierarchy.level2).sort().map(name => `- ${name}`).join("\n"));
|
|
225
|
+
sections.push("\n\n");
|
|
226
|
+
}
|
|
227
|
+
if (hierarchy.level3.size > 0) {
|
|
228
|
+
sections.push("**Level 3 (Variants):**\n\n");
|
|
229
|
+
sections.push(Array.from(hierarchy.level3).sort().map(name => `- ${name}`).join("\n"));
|
|
230
|
+
sections.push("\n\n");
|
|
231
|
+
}
|
|
232
|
+
if (hierarchy.components.size > 0) {
|
|
233
|
+
sections.push("**Component Themes:**\n\n");
|
|
234
|
+
sections.push(Array.from(hierarchy.components).sort().map(name => `- ${name}`).join("\n"));
|
|
235
|
+
sections.push("\n\n");
|
|
236
|
+
}
|
|
237
|
+
sections.push("### Theme Usage\n\n");
|
|
238
|
+
sections.push("Themes are combined hierarchically. For example, `light_blue_alt1_Button` combines:\n");
|
|
239
|
+
sections.push("- Base: `light`\n");
|
|
240
|
+
sections.push("- Color: `blue`\n");
|
|
241
|
+
sections.push("- Variant: `alt1`\n");
|
|
242
|
+
sections.push("- Component: `Button`\n\n");
|
|
243
|
+
sections.push("**Basic usage:**\n\n");
|
|
244
|
+
sections.push("```tsx\n");
|
|
245
|
+
sections.push("// Apply a theme to components\n");
|
|
246
|
+
sections.push("export default () => (\n");
|
|
247
|
+
sections.push(' <Theme name="dark">\n');
|
|
248
|
+
sections.push(" <Button>I'm a dark button</Button>\n");
|
|
249
|
+
sections.push(" </Theme>\n");
|
|
250
|
+
sections.push(")\n\n");
|
|
251
|
+
sections.push("// Themes nest and combine automatically\n");
|
|
252
|
+
sections.push("export default () => (\n");
|
|
253
|
+
sections.push(' <Theme name="dark">\n');
|
|
254
|
+
sections.push(' <Theme name="blue">\n');
|
|
255
|
+
sections.push(" <Button>Uses dark_blue theme</Button>\n");
|
|
256
|
+
sections.push(" </Theme>\n");
|
|
257
|
+
sections.push(" </Theme>\n");
|
|
258
|
+
sections.push(")\n");
|
|
259
|
+
sections.push("```\n\n");
|
|
260
|
+
sections.push("**Accessing theme values:**\n\n");
|
|
261
|
+
sections.push("Components can access theme values using `$` token syntax:\n\n");
|
|
262
|
+
sections.push("```tsx\n");
|
|
263
|
+
sections.push(`<View ${getPropName("backgroundColor")}="$background" ${getPropName("color")}="$color" />
|
|
264
|
+
`);
|
|
265
|
+
sections.push("```\n\n");
|
|
266
|
+
sections.push("**Special props:**\n\n");
|
|
267
|
+
sections.push("- `inverse`: Automatically swaps light \u2194 dark themes\n");
|
|
268
|
+
sections.push("- `reset`: Reverts to grandparent theme\n\n");
|
|
269
|
+
sections.push("## Tokens\n\n");
|
|
270
|
+
sections.push("Tokens are design system values that can be referenced using the `$` prefix.\n\n");
|
|
219
271
|
const tokens = config.tamaguiConfig?.tokens || {};
|
|
220
272
|
if (tokens.space) {
|
|
221
|
-
sections.push(
|
|
222
|
-
|
|
223
|
-
`);
|
|
273
|
+
sections.push("### Space Tokens\n\n");
|
|
224
274
|
const spaceTokens = Object.entries(tokens.space).sort(([a], [b]) => {
|
|
225
|
-
const numA = parseFloat(a)
|
|
226
|
-
|
|
227
|
-
|
|
275
|
+
const numA = parseFloat(a);
|
|
276
|
+
const numB = parseFloat(b);
|
|
277
|
+
if (!isNaN(numA) && !isNaN(numB)) {
|
|
278
|
+
return numA - numB;
|
|
279
|
+
}
|
|
280
|
+
return a.localeCompare(b);
|
|
228
281
|
});
|
|
229
|
-
sections.push(spaceTokens.map(([key, value]) => `- \`${key}\`: ${formatTokenValue(value)}`).join(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
`);
|
|
282
|
+
sections.push(spaceTokens.map(([key, value]) => `- \`${key}\`: ${formatTokenValue(value)}`).join("\n"));
|
|
283
|
+
sections.push("\n\n");
|
|
233
284
|
}
|
|
234
285
|
if (tokens.size) {
|
|
235
|
-
sections.push(
|
|
236
|
-
|
|
237
|
-
`);
|
|
286
|
+
sections.push("### Size Tokens\n\n");
|
|
238
287
|
const sizeTokens = Object.entries(tokens.size).sort(([a], [b]) => {
|
|
239
|
-
const numA = parseFloat(a)
|
|
240
|
-
|
|
241
|
-
|
|
288
|
+
const numA = parseFloat(a);
|
|
289
|
+
const numB = parseFloat(b);
|
|
290
|
+
if (!isNaN(numA) && !isNaN(numB)) {
|
|
291
|
+
return numA - numB;
|
|
292
|
+
}
|
|
293
|
+
return a.localeCompare(b);
|
|
242
294
|
});
|
|
243
|
-
sections.push(sizeTokens.map(([key, value]) => `- \`${key}\`: ${formatTokenValue(value)}`).join(
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
`);
|
|
295
|
+
sections.push(sizeTokens.map(([key, value]) => `- \`${key}\`: ${formatTokenValue(value)}`).join("\n"));
|
|
296
|
+
sections.push("\n\n");
|
|
247
297
|
}
|
|
248
298
|
if (tokens.radius) {
|
|
249
|
-
sections.push(
|
|
250
|
-
|
|
251
|
-
`);
|
|
299
|
+
sections.push("### Radius Tokens\n\n");
|
|
252
300
|
const radiusTokens = Object.entries(tokens.radius).sort(([a], [b]) => {
|
|
253
|
-
const numA = parseFloat(a)
|
|
254
|
-
|
|
255
|
-
|
|
301
|
+
const numA = parseFloat(a);
|
|
302
|
+
const numB = parseFloat(b);
|
|
303
|
+
if (!isNaN(numA) && !isNaN(numB)) {
|
|
304
|
+
return numA - numB;
|
|
305
|
+
}
|
|
306
|
+
return a.localeCompare(b);
|
|
256
307
|
});
|
|
257
|
-
sections.push(radiusTokens.map(([key, value]) => `- \`${key}\`: ${formatTokenValue(value)}`).join(
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
`);
|
|
308
|
+
sections.push(radiusTokens.map(([key, value]) => `- \`${key}\`: ${formatTokenValue(value)}`).join("\n"));
|
|
309
|
+
sections.push("\n\n");
|
|
261
310
|
}
|
|
262
311
|
if (tokens.zIndex) {
|
|
263
|
-
sections.push(
|
|
264
|
-
|
|
265
|
-
`);
|
|
312
|
+
sections.push("### Z-Index Tokens\n\n");
|
|
266
313
|
const zIndexTokens = Object.entries(tokens.zIndex).sort(([a], [b]) => {
|
|
267
|
-
const numA = parseFloat(a)
|
|
268
|
-
|
|
269
|
-
|
|
314
|
+
const numA = parseFloat(a);
|
|
315
|
+
const numB = parseFloat(b);
|
|
316
|
+
if (!isNaN(numA) && !isNaN(numB)) {
|
|
317
|
+
return numA - numB;
|
|
318
|
+
}
|
|
319
|
+
return a.localeCompare(b);
|
|
270
320
|
});
|
|
271
|
-
sections.push(zIndexTokens.map(([key, value]) => `- \`${key}\`: ${formatTokenValue(value)}`).join(
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
`);
|
|
321
|
+
sections.push(zIndexTokens.map(([key, value]) => `- \`${key}\`: ${formatTokenValue(value)}`).join("\n"));
|
|
322
|
+
sections.push("\n\n");
|
|
275
323
|
}
|
|
276
324
|
if (tokens.color) {
|
|
277
|
-
sections.push(
|
|
278
|
-
|
|
279
|
-
`);
|
|
325
|
+
sections.push("### Color Tokens\n\n");
|
|
280
326
|
const colorTokens = Object.entries(tokens.color).sort(([a], [b]) => a.localeCompare(b));
|
|
281
|
-
sections.push(colorTokens.map(([key, value]) => `- \`${key}\`: ${formatTokenValue(value)}`).join(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
`);
|
|
327
|
+
sections.push(colorTokens.map(([key, value]) => `- \`${key}\`: ${formatTokenValue(value)}`).join("\n"));
|
|
328
|
+
sections.push("\n\n");
|
|
285
329
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
`), sections.push(`// Size tokens - for width, height, dimensions
|
|
292
|
-
`), sections.push(`<View ${getPropName("width")}="$10" ${getPropName("height")}="$6" />
|
|
330
|
+
sections.push("### Token Usage\n\n");
|
|
331
|
+
sections.push("Tokens can be used in component props with the `$` prefix:\n\n");
|
|
332
|
+
sections.push("```tsx\n");
|
|
333
|
+
sections.push("// Space tokens - for margin, padding, gap\n");
|
|
334
|
+
sections.push(`<View ${getPropName("padding")}="$4" ${getPropName("gap")}="$2" ${getPropName("margin")}="$3" />
|
|
293
335
|
|
|
294
|
-
`)
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
`), sections.push(`// Radius tokens - for border-radius
|
|
298
|
-
`), sections.push(`<View ${getPropName("borderRadius")}="$4" />
|
|
299
|
-
`), sections.push("```\n\n"), config.tamaguiConfig?.media) {
|
|
300
|
-
sections.push(`## Media Queries
|
|
336
|
+
`);
|
|
337
|
+
sections.push("// Size tokens - for width, height, dimensions\n");
|
|
338
|
+
sections.push(`<View ${getPropName("width")}="$10" ${getPropName("height")}="$6" />
|
|
301
339
|
|
|
302
|
-
`)
|
|
340
|
+
`);
|
|
341
|
+
sections.push("// Color tokens - for colors and backgrounds\n");
|
|
342
|
+
sections.push(`<View ${getPropName("backgroundColor")}="$blue5" ${getPropName("color")}="$gray12" />
|
|
303
343
|
|
|
304
344
|
`);
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
for (const [name, query] of mediaEntries) sections.push(`- **${name}**: ${JSON.stringify(query)}
|
|
345
|
+
sections.push("// Radius tokens - for border-radius\n");
|
|
346
|
+
sections.push(`<View ${getPropName("borderRadius")}="$4" />
|
|
308
347
|
`);
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
348
|
+
sections.push("```\n\n");
|
|
349
|
+
if (config.tamaguiConfig?.media) {
|
|
350
|
+
sections.push("## Media Queries\n\n");
|
|
351
|
+
sections.push("Available responsive breakpoints:\n\n");
|
|
352
|
+
const media = config.tamaguiConfig.media;
|
|
353
|
+
const mediaEntries = Object.entries(media).sort(([a], [b]) => a.localeCompare(b));
|
|
354
|
+
for (const [name, query] of mediaEntries) {
|
|
355
|
+
sections.push(`- **${name}**: ${JSON.stringify(query)}
|
|
313
356
|
`);
|
|
357
|
+
}
|
|
358
|
+
sections.push("\n");
|
|
359
|
+
sections.push("### Media Query Usage\n\n");
|
|
360
|
+
sections.push("Media queries can be used as style props or with the `useMedia` hook:\n\n");
|
|
361
|
+
sections.push("```tsx\n");
|
|
362
|
+
sections.push("// As style props (prefix with $)\n");
|
|
314
363
|
const firstMediaName = mediaEntries[0]?.[0];
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
`), sections.push(`// Using the useMedia hook
|
|
318
|
-
`), sections.push(`const media = useMedia()
|
|
319
|
-
`), firstMediaName && (sections.push(`if (media.${firstMediaName}) {
|
|
320
|
-
`), sections.push(` // Render for this breakpoint
|
|
321
|
-
`), sections.push(`}
|
|
322
|
-
`)), sections.push("```\n\n");
|
|
323
|
-
}
|
|
324
|
-
if (config.tamaguiConfig?.fonts) {
|
|
325
|
-
sections.push(`## Fonts
|
|
326
|
-
|
|
327
|
-
`), sections.push(`Available font families:
|
|
364
|
+
if (firstMediaName) {
|
|
365
|
+
sections.push(`<View ${getPropName("width")}="100%" $${firstMediaName}={{ ${getPropName("width")}: "50%" }} />
|
|
328
366
|
|
|
329
367
|
`);
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
sections.push(
|
|
333
|
-
|
|
334
|
-
|
|
368
|
+
}
|
|
369
|
+
sections.push("// Using the useMedia hook\n");
|
|
370
|
+
sections.push("const media = useMedia()\n");
|
|
371
|
+
if (firstMediaName) {
|
|
372
|
+
sections.push(`if (media.${firstMediaName}) {
|
|
335
373
|
`);
|
|
374
|
+
sections.push(" // Render for this breakpoint\n");
|
|
375
|
+
sections.push("}\n");
|
|
376
|
+
}
|
|
377
|
+
sections.push("```\n\n");
|
|
378
|
+
}
|
|
379
|
+
if (config.tamaguiConfig?.fonts) {
|
|
380
|
+
sections.push("## Fonts\n\n");
|
|
381
|
+
sections.push("Available font families:\n\n");
|
|
382
|
+
const fonts = config.tamaguiConfig.fonts;
|
|
383
|
+
const fontNames = Object.keys(fonts).sort();
|
|
384
|
+
sections.push(fontNames.map(name => `- ${name}`).join("\n"));
|
|
385
|
+
sections.push("\n\n");
|
|
336
386
|
}
|
|
337
387
|
if (config.tamaguiConfig?.animations) {
|
|
338
|
-
sections.push(
|
|
339
|
-
|
|
340
|
-
`), sections.push(`Available animation presets:
|
|
341
|
-
|
|
342
|
-
`);
|
|
388
|
+
sections.push("## Animations\n\n");
|
|
389
|
+
sections.push("Available animation presets:\n\n");
|
|
343
390
|
const animations = config.tamaguiConfig.animations;
|
|
344
391
|
if (animations.animations) {
|
|
345
392
|
const animationNames = Object.keys(animations.animations).sort();
|
|
346
|
-
sections.push(animationNames.map(name => `- ${name}`).join(
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
`);
|
|
393
|
+
sections.push(animationNames.map(name => `- ${name}`).join("\n"));
|
|
394
|
+
sections.push("\n\n");
|
|
350
395
|
}
|
|
351
396
|
}
|
|
352
|
-
|
|
397
|
+
sections.push(...componentsSection);
|
|
398
|
+
return sections.join("");
|
|
353
399
|
}
|
|
354
400
|
function formatTokenValue(value) {
|
|
355
|
-
|
|
401
|
+
if (typeof value === "object" && value !== null && "val" in value) {
|
|
402
|
+
return String(value.val);
|
|
403
|
+
}
|
|
404
|
+
return String(value);
|
|
356
405
|
}
|