rn-agent-kit 0.0.0-stage → 0.2.1
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/README.md +291 -2
- package/dist/cli.js +2916 -0
- package/dist/cli.js.map +1 -0
- package/dist/scripts/figma-tokens.js +1284 -0
- package/dist/scripts/figma-tokens.js.map +1 -0
- package/dist/scripts/validate-jira-tickets.js +169 -0
- package/dist/scripts/validate-jira-tickets.js.map +1 -0
- package/package.json +66 -4
- package/skills/expo-cli/SKILL.md +213 -0
- package/skills/figma-to-tokens/SKILL.md +288 -0
- package/skills/github-actions-ci/SKILL.md +124 -0
- package/skills/maestro-e2e/SKILL.md +256 -0
- package/skills/prd-to-jira/SKILL.md +237 -0
- package/skills/rn-architecture/SKILL.md +207 -0
- package/skills/rn-native-android-ios/SKILL.md +195 -0
- package/skills/rn-sdk-integrations/SKILL.md +274 -0
- package/skills/rn-typescript-react/SKILL.md +247 -0
- package/skills/ticket-to-code/SKILL.md +192 -0
- package/templates/config/rn-agent-kit.json +4 -0
- package/templates/eslint/eslint.config.snippet.mjs +16 -0
- package/templates/eslint/rn-agent-kit-rules.cjs +137 -0
- package/templates/jira-ticket.md +78 -0
- package/templates/maestro/smoke.yaml +4 -0
- package/templates/scaffold/.husky/commit-msg +4 -0
- package/templates/scaffold/.husky/pre-commit +4 -0
- package/templates/scaffold/.prettierignore +6 -0
- package/templates/scaffold/.prettierrc +6 -0
- package/templates/scaffold/commitlint.config.cjs +4 -0
- package/templates/scaffold/eslint.config.js +22 -0
- package/templates/scaffold/jest.config.cjs +9 -0
- package/templates/scaffold/tsconfig.json +13 -0
- package/templates/workflows/ci.yml +120 -0
- package/templates/workflows/e2e-android.yml +158 -0
- package/templates/workflows/e2e-ios.yml +134 -0
- package/templates/workflows/eas-build.yml +94 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,2916 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
|
|
6
|
+
// src/commands/init.ts
|
|
7
|
+
import * as p from "@clack/prompts";
|
|
8
|
+
import path13 from "path";
|
|
9
|
+
|
|
10
|
+
// src/adapters/agents-md.ts
|
|
11
|
+
import path3 from "path";
|
|
12
|
+
|
|
13
|
+
// src/utils/fs.ts
|
|
14
|
+
import { mkdir, readFile, writeFile, access, constants } from "fs/promises";
|
|
15
|
+
import path from "path";
|
|
16
|
+
async function ensureDir(dir) {
|
|
17
|
+
await mkdir(dir, { recursive: true });
|
|
18
|
+
}
|
|
19
|
+
async function pathExists(target) {
|
|
20
|
+
try {
|
|
21
|
+
await access(target, constants.F_OK);
|
|
22
|
+
return true;
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function readText(filePath) {
|
|
28
|
+
return readFile(filePath, "utf8");
|
|
29
|
+
}
|
|
30
|
+
async function writeText(filePath, content) {
|
|
31
|
+
await ensureDir(path.dirname(filePath));
|
|
32
|
+
await writeFile(filePath, content, "utf8");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/utils/skills.ts
|
|
36
|
+
import { existsSync } from "fs";
|
|
37
|
+
import { readdir, readFile as readFile2 } from "fs/promises";
|
|
38
|
+
import path2 from "path";
|
|
39
|
+
import { fileURLToPath } from "url";
|
|
40
|
+
var __dirname = path2.dirname(fileURLToPath(import.meta.url));
|
|
41
|
+
function getSkillsRoot() {
|
|
42
|
+
const candidates = [
|
|
43
|
+
path2.resolve(__dirname, "../../skills"),
|
|
44
|
+
path2.resolve(__dirname, "../skills")
|
|
45
|
+
];
|
|
46
|
+
for (const candidate of candidates) {
|
|
47
|
+
if (existsSync(candidate)) return candidate;
|
|
48
|
+
}
|
|
49
|
+
return candidates[0];
|
|
50
|
+
}
|
|
51
|
+
function parseFrontmatter(raw) {
|
|
52
|
+
const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/);
|
|
53
|
+
if (!match) {
|
|
54
|
+
return {
|
|
55
|
+
body: raw.trim(),
|
|
56
|
+
description: "rn-agent-kit skill",
|
|
57
|
+
globs: ["**/*.{ts,tsx,js,jsx}"],
|
|
58
|
+
alwaysApply: false
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const yaml = match[1] ?? "";
|
|
62
|
+
const body = (match[2] ?? "").trim();
|
|
63
|
+
const description = parseDescription(yaml);
|
|
64
|
+
const globsLine = yaml.match(/^globs:\s*(.+)$/m)?.[1]?.trim();
|
|
65
|
+
let globs = ["**/*.{ts,tsx,js,jsx}"];
|
|
66
|
+
if (globsLine) {
|
|
67
|
+
if (globsLine.startsWith("[") && globsLine.endsWith("]")) {
|
|
68
|
+
globs = globsLine.slice(1, -1).split(",").map((g) => g.trim().replace(/^["']|["']$/g, "")).filter(Boolean);
|
|
69
|
+
} else {
|
|
70
|
+
globs = [globsLine.replace(/^["']|["']$/g, "")];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const alwaysApply = /^alwaysApply:\s*true\s*$/m.test(yaml);
|
|
74
|
+
return { body, description, globs, alwaysApply };
|
|
75
|
+
}
|
|
76
|
+
function parseDescription(yaml) {
|
|
77
|
+
const folded = yaml.match(/^description:\s*[>|]-?\r?\n((?:[ \t]+.+\r?\n?)+)/m);
|
|
78
|
+
if (folded?.[1]) {
|
|
79
|
+
return folded[1].split(/\r?\n/).map((line) => line.replace(/^[ \t]+/, "").trim()).filter(Boolean).join(" ").trim();
|
|
80
|
+
}
|
|
81
|
+
const single = yaml.match(/^description:\s*(.+)$/m)?.[1]?.trim().replace(/^["']|["']$/g, "") ?? "rn-agent-kit skill";
|
|
82
|
+
return single === ">" || single === ">-" || single === "|" || single === "|-" ? "rn-agent-kit skill" : single;
|
|
83
|
+
}
|
|
84
|
+
async function loadSkills(skillsRoot = getSkillsRoot()) {
|
|
85
|
+
if (!await pathExists(skillsRoot)) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
const entries = await readdir(skillsRoot, { withFileTypes: true });
|
|
89
|
+
const skills = [];
|
|
90
|
+
for (const entry of entries) {
|
|
91
|
+
if (!entry.isDirectory()) continue;
|
|
92
|
+
const skillPath = path2.join(skillsRoot, entry.name, "SKILL.md");
|
|
93
|
+
if (!await pathExists(skillPath)) continue;
|
|
94
|
+
const raw = await readFile2(skillPath, "utf8");
|
|
95
|
+
const parsed = parseFrontmatter(raw);
|
|
96
|
+
skills.push({
|
|
97
|
+
name: entry.name,
|
|
98
|
+
content: raw,
|
|
99
|
+
description: parsed.description,
|
|
100
|
+
globs: parsed.globs,
|
|
101
|
+
alwaysApply: parsed.alwaysApply
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return skills.sort((a, b) => a.name.localeCompare(b.name));
|
|
105
|
+
}
|
|
106
|
+
function skillBody(skill) {
|
|
107
|
+
const match = skill.content.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?([\s\S]*)$/);
|
|
108
|
+
return (match?.[1] ?? skill.content).trim();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/adapters/agents-md.ts
|
|
112
|
+
var START_MARKER = "<!-- rn-agent-kit:start -->";
|
|
113
|
+
var END_MARKER = "<!-- rn-agent-kit:end -->";
|
|
114
|
+
function buildBlock(skills) {
|
|
115
|
+
const sections = skills.map((skill) => {
|
|
116
|
+
return [`## ${skill.name}`, "", skillBody(skill)].join("\n");
|
|
117
|
+
});
|
|
118
|
+
return [
|
|
119
|
+
START_MARKER,
|
|
120
|
+
"",
|
|
121
|
+
"# rn-agent-kit skills",
|
|
122
|
+
"",
|
|
123
|
+
"_Managed by `rn-agent-kit`. Do not edit inside these markers._",
|
|
124
|
+
"",
|
|
125
|
+
...sections.flatMap((s) => [s, ""]),
|
|
126
|
+
END_MARKER
|
|
127
|
+
].join("\n");
|
|
128
|
+
}
|
|
129
|
+
function mergeAgentsMd(existing, skills) {
|
|
130
|
+
const block = buildBlock(skills);
|
|
131
|
+
const startIdx = existing.indexOf(START_MARKER);
|
|
132
|
+
const endIdx = existing.indexOf(END_MARKER);
|
|
133
|
+
if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
|
|
134
|
+
const before = existing.slice(0, startIdx).replace(/\s*$/, "\n\n");
|
|
135
|
+
const after = existing.slice(endIdx + END_MARKER.length).replace(/^\s*/, "\n");
|
|
136
|
+
return `${before}${block}${after}`.replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
|
|
137
|
+
}
|
|
138
|
+
if (startIdx !== -1 || endIdx !== -1) {
|
|
139
|
+
const trimmed = existing.replace(/\s*$/, "\n\n");
|
|
140
|
+
return `${trimmed}${block}
|
|
141
|
+
`;
|
|
142
|
+
}
|
|
143
|
+
if (!existing.trim()) {
|
|
144
|
+
return `${block}
|
|
145
|
+
`;
|
|
146
|
+
}
|
|
147
|
+
return `${existing.replace(/\s*$/, "\n\n")}${block}
|
|
148
|
+
`;
|
|
149
|
+
}
|
|
150
|
+
var agentsMdAdapter = {
|
|
151
|
+
name: "agents-md",
|
|
152
|
+
async detect(cwd) {
|
|
153
|
+
return pathExists(path3.join(cwd, "AGENTS.md"));
|
|
154
|
+
},
|
|
155
|
+
async install(skills, cwd) {
|
|
156
|
+
const dest = path3.join(cwd, "AGENTS.md");
|
|
157
|
+
const existing = await pathExists(dest) ? await readText(dest) : "";
|
|
158
|
+
const next = mergeAgentsMd(existing, skills);
|
|
159
|
+
await writeText(dest, next);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
async function detectAgentsMd(cwd) {
|
|
163
|
+
return agentsMdAdapter.detect(cwd);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/adapters/claude.ts
|
|
167
|
+
import path4 from "path";
|
|
168
|
+
var claudeAdapter = {
|
|
169
|
+
name: "claude",
|
|
170
|
+
async detect(cwd) {
|
|
171
|
+
return await pathExists(path4.join(cwd, ".claude")) || await pathExists(path4.join(cwd, "CLAUDE.md"));
|
|
172
|
+
},
|
|
173
|
+
async install(skills, cwd) {
|
|
174
|
+
const root = path4.join(cwd, ".claude", "skills");
|
|
175
|
+
await ensureDir(root);
|
|
176
|
+
for (const skill of skills) {
|
|
177
|
+
const dest = path4.join(root, skill.name, "SKILL.md");
|
|
178
|
+
await writeText(dest, skill.content.endsWith("\n") ? skill.content : `${skill.content}
|
|
179
|
+
`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
async function detectClaudeProject(cwd) {
|
|
184
|
+
return claudeAdapter.detect(cwd);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/adapters/copilot.ts
|
|
188
|
+
import path5 from "path";
|
|
189
|
+
var COPILOT_START = "<!-- rn-agent-kit:start -->";
|
|
190
|
+
var COPILOT_END = "<!-- rn-agent-kit:end -->";
|
|
191
|
+
function buildBlock2(skills) {
|
|
192
|
+
const sections = skills.map((skill) => [`## ${skill.name}`, "", skillBody(skill)].join("\n"));
|
|
193
|
+
return [
|
|
194
|
+
COPILOT_START,
|
|
195
|
+
"",
|
|
196
|
+
"# rn-agent-kit skills (GitHub Copilot)",
|
|
197
|
+
"",
|
|
198
|
+
"_Managed by `rn-agent-kit`. Do not edit inside these markers._",
|
|
199
|
+
"",
|
|
200
|
+
...sections.flatMap((s) => [s, ""]),
|
|
201
|
+
COPILOT_END
|
|
202
|
+
].join("\n");
|
|
203
|
+
}
|
|
204
|
+
function mergeCopilotInstructions(existing, skills) {
|
|
205
|
+
const block = buildBlock2(skills);
|
|
206
|
+
const startIdx = existing.indexOf(COPILOT_START);
|
|
207
|
+
const endIdx = existing.indexOf(COPILOT_END);
|
|
208
|
+
if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
|
|
209
|
+
const before = existing.slice(0, startIdx).replace(/\s*$/, "\n\n");
|
|
210
|
+
const after = existing.slice(endIdx + COPILOT_END.length).replace(/^\s*/, "\n");
|
|
211
|
+
return `${before}${block}${after}`.replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
|
|
212
|
+
}
|
|
213
|
+
if (!existing.trim()) return `${block}
|
|
214
|
+
`;
|
|
215
|
+
return `${existing.replace(/\s*$/, "\n\n")}${block}
|
|
216
|
+
`;
|
|
217
|
+
}
|
|
218
|
+
var copilotAdapter = {
|
|
219
|
+
name: "copilot",
|
|
220
|
+
async detect(cwd) {
|
|
221
|
+
return await pathExists(path5.join(cwd, ".github", "copilot-instructions.md")) || await pathExists(path5.join(cwd, ".github"));
|
|
222
|
+
},
|
|
223
|
+
async install(skills, cwd) {
|
|
224
|
+
const dest = path5.join(cwd, ".github", "copilot-instructions.md");
|
|
225
|
+
const existing = await pathExists(dest) ? await readText(dest) : "";
|
|
226
|
+
await writeText(dest, mergeCopilotInstructions(existing, skills));
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
async function detectCopilotProject(cwd) {
|
|
230
|
+
return copilotAdapter.detect(cwd);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/adapters/cursor.ts
|
|
234
|
+
import path6 from "path";
|
|
235
|
+
function toMdc(skill) {
|
|
236
|
+
const globs = skill.globs.length === 1 ? skill.globs[0] : `[${skill.globs.map((g) => `"${g}"`).join(", ")}]`;
|
|
237
|
+
return [
|
|
238
|
+
"---",
|
|
239
|
+
`description: ${skill.description}`,
|
|
240
|
+
`globs: ${globs}`,
|
|
241
|
+
`alwaysApply: ${skill.alwaysApply}`,
|
|
242
|
+
"---",
|
|
243
|
+
"",
|
|
244
|
+
skillBody(skill),
|
|
245
|
+
""
|
|
246
|
+
].join("\n");
|
|
247
|
+
}
|
|
248
|
+
var cursorAdapter = {
|
|
249
|
+
name: "cursor",
|
|
250
|
+
async detect(cwd) {
|
|
251
|
+
return await pathExists(path6.join(cwd, ".cursor")) || await pathExists(path6.join(cwd, ".cursorrules"));
|
|
252
|
+
},
|
|
253
|
+
async install(skills, cwd) {
|
|
254
|
+
const root = path6.join(cwd, ".cursor", "rules");
|
|
255
|
+
await ensureDir(root);
|
|
256
|
+
for (const skill of skills) {
|
|
257
|
+
const dest = path6.join(root, `${skill.name}.mdc`);
|
|
258
|
+
await writeText(dest, toMdc(skill));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
async function detectCursorProject(cwd) {
|
|
263
|
+
return cursorAdapter.detect(cwd);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// src/adapters/windsurf.ts
|
|
267
|
+
import path7 from "path";
|
|
268
|
+
function toWindsurfRule(skill) {
|
|
269
|
+
return [`# ${skill.name}`, "", skill.description, "", skillBody(skill), ""].join("\n");
|
|
270
|
+
}
|
|
271
|
+
var windsurfAdapter = {
|
|
272
|
+
name: "windsurf",
|
|
273
|
+
async detect(cwd) {
|
|
274
|
+
return pathExists(path7.join(cwd, ".windsurf"));
|
|
275
|
+
},
|
|
276
|
+
async install(skills, cwd) {
|
|
277
|
+
const root = path7.join(cwd, ".windsurf", "rules");
|
|
278
|
+
await ensureDir(root);
|
|
279
|
+
for (const skill of skills) {
|
|
280
|
+
const dest = path7.join(root, `${skill.name}.md`);
|
|
281
|
+
await writeText(dest, toWindsurfRule(skill));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
async function detectWindsurfProject(cwd) {
|
|
286
|
+
return windsurfAdapter.detect(cwd);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/adapters/index.ts
|
|
290
|
+
var adapters = [
|
|
291
|
+
claudeAdapter,
|
|
292
|
+
cursorAdapter,
|
|
293
|
+
agentsMdAdapter,
|
|
294
|
+
copilotAdapter,
|
|
295
|
+
windsurfAdapter
|
|
296
|
+
];
|
|
297
|
+
var TOOL_ALIASES = {
|
|
298
|
+
claude: "claude",
|
|
299
|
+
"claude-code": "claude",
|
|
300
|
+
cursor: "cursor",
|
|
301
|
+
"agents-md": "agents-md",
|
|
302
|
+
agents: "agents-md",
|
|
303
|
+
codex: "agents-md",
|
|
304
|
+
gemini: "agents-md",
|
|
305
|
+
copilot: "copilot",
|
|
306
|
+
"github-copilot": "copilot",
|
|
307
|
+
windsurf: "windsurf"
|
|
308
|
+
};
|
|
309
|
+
function resolveToolName(input) {
|
|
310
|
+
return TOOL_ALIASES[input.trim().toLowerCase()];
|
|
311
|
+
}
|
|
312
|
+
function getAdapter(name) {
|
|
313
|
+
const resolved = resolveToolName(name) ?? name;
|
|
314
|
+
return adapters.find((a) => a.name === resolved);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/detect/project.ts
|
|
318
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
319
|
+
import path8 from "path";
|
|
320
|
+
async function readPackageJson(cwd) {
|
|
321
|
+
const file = path8.join(cwd, "package.json");
|
|
322
|
+
if (!await pathExists(file)) return null;
|
|
323
|
+
try {
|
|
324
|
+
return JSON.parse(await readFile3(file, "utf8"));
|
|
325
|
+
} catch {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function hasDep(pkg, name) {
|
|
330
|
+
return Boolean(pkg.dependencies?.[name] || pkg.devDependencies?.[name]);
|
|
331
|
+
}
|
|
332
|
+
async function detectPackageManager(cwd) {
|
|
333
|
+
if (await pathExists(path8.join(cwd, "bun.lockb"))) return "bun";
|
|
334
|
+
if (await pathExists(path8.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
335
|
+
if (await pathExists(path8.join(cwd, "yarn.lock"))) return "yarn";
|
|
336
|
+
return "npm";
|
|
337
|
+
}
|
|
338
|
+
async function detectProject(cwd) {
|
|
339
|
+
const pkg = await readPackageJson(cwd);
|
|
340
|
+
if (!pkg) {
|
|
341
|
+
return {
|
|
342
|
+
hasPackageJson: false,
|
|
343
|
+
isReactNative: false,
|
|
344
|
+
stack: "unknown",
|
|
345
|
+
typescript: false,
|
|
346
|
+
packageManager: await detectPackageManager(cwd),
|
|
347
|
+
navigation: "none"
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
const isReactNative = hasDep(pkg, "react-native") || hasDep(pkg, "expo") || await pathExists(path8.join(cwd, "app.json")) || await pathExists(path8.join(cwd, "app.config.ts")) || await pathExists(path8.join(cwd, "app.config.js"));
|
|
351
|
+
let stack = "unknown";
|
|
352
|
+
if (hasDep(pkg, "expo") || await pathExists(path8.join(cwd, "app.json"))) {
|
|
353
|
+
stack = "expo";
|
|
354
|
+
} else if (hasDep(pkg, "react-native")) {
|
|
355
|
+
stack = "cli";
|
|
356
|
+
}
|
|
357
|
+
const typescript = hasDep(pkg, "typescript") || await pathExists(path8.join(cwd, "tsconfig.json")) || await pathExists(path8.join(cwd, "app.config.ts"));
|
|
358
|
+
let navigation = "none";
|
|
359
|
+
if (hasDep(pkg, "expo-router")) navigation = "expo-router";
|
|
360
|
+
else if (hasDep(pkg, "@react-navigation/native") || hasDep(pkg, "@react-navigation/native-stack")) {
|
|
361
|
+
navigation = "react-navigation";
|
|
362
|
+
} else if (isReactNative) {
|
|
363
|
+
navigation = "unknown";
|
|
364
|
+
}
|
|
365
|
+
return {
|
|
366
|
+
hasPackageJson: true,
|
|
367
|
+
isReactNative,
|
|
368
|
+
stack,
|
|
369
|
+
typescript,
|
|
370
|
+
packageManager: await detectPackageManager(cwd),
|
|
371
|
+
navigation,
|
|
372
|
+
packageName: pkg.name
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function formatDetectionSummary(d) {
|
|
376
|
+
const lines = [
|
|
377
|
+
`package.json: ${d.hasPackageJson ? "yes" : "no"}`,
|
|
378
|
+
`react-native: ${d.isReactNative ? "yes" : "no"}`,
|
|
379
|
+
`stack: ${d.stack}`,
|
|
380
|
+
`typescript: ${d.typescript ? "yes" : "no"}`,
|
|
381
|
+
`package manager: ${d.packageManager}`,
|
|
382
|
+
`navigation: ${d.navigation}`
|
|
383
|
+
];
|
|
384
|
+
if (d.packageName) lines.unshift(`name: ${d.packageName}`);
|
|
385
|
+
return lines.join("\n");
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/scaffold/architecture.ts
|
|
389
|
+
import { cp, readFile as readFile4, readdir as readdir2, stat } from "fs/promises";
|
|
390
|
+
import path10 from "path";
|
|
391
|
+
|
|
392
|
+
// src/utils/templates.ts
|
|
393
|
+
import { existsSync as existsSync2 } from "fs";
|
|
394
|
+
import path9 from "path";
|
|
395
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
396
|
+
var __dirname2 = path9.dirname(fileURLToPath2(import.meta.url));
|
|
397
|
+
function getTemplatesRoot() {
|
|
398
|
+
const candidates = [
|
|
399
|
+
path9.resolve(__dirname2, "../../templates"),
|
|
400
|
+
path9.resolve(__dirname2, "../templates")
|
|
401
|
+
];
|
|
402
|
+
for (const candidate of candidates) {
|
|
403
|
+
if (existsSync2(candidate)) return candidate;
|
|
404
|
+
}
|
|
405
|
+
return candidates[0];
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/scaffold/architecture.ts
|
|
409
|
+
var FEATURE_DIRS = [
|
|
410
|
+
"src/features/example/components",
|
|
411
|
+
"src/features/example/hooks",
|
|
412
|
+
"src/features/example/services",
|
|
413
|
+
"src/features/example/store",
|
|
414
|
+
"src/features/example/types",
|
|
415
|
+
"src/shared/components",
|
|
416
|
+
"src/shared/hooks",
|
|
417
|
+
"src/shared/lib",
|
|
418
|
+
"src/shared/theme",
|
|
419
|
+
"src/shared/types",
|
|
420
|
+
"src/config"
|
|
421
|
+
];
|
|
422
|
+
async function copyIfMissing(from, to) {
|
|
423
|
+
if (await pathExists(to)) return false;
|
|
424
|
+
await ensureDir(path10.dirname(to));
|
|
425
|
+
await cp(from, to, { recursive: true });
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
async function mergeTsconfigPaths(projectDir) {
|
|
429
|
+
const tsconfigPath = path10.join(projectDir, "tsconfig.json");
|
|
430
|
+
if (!await pathExists(tsconfigPath)) {
|
|
431
|
+
const template = path10.join(getTemplatesRoot(), "scaffold", "tsconfig.json");
|
|
432
|
+
if (await pathExists(template)) {
|
|
433
|
+
await cp(template, tsconfigPath);
|
|
434
|
+
}
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
try {
|
|
438
|
+
const raw = await readText(tsconfigPath);
|
|
439
|
+
const json = JSON.parse(raw);
|
|
440
|
+
json.compilerOptions ??= {};
|
|
441
|
+
const existing = json.compilerOptions.paths ?? {};
|
|
442
|
+
json.compilerOptions.baseUrl = json.compilerOptions.baseUrl ?? ".";
|
|
443
|
+
json.compilerOptions.paths = {
|
|
444
|
+
...existing,
|
|
445
|
+
"@/*": ["./src/*"],
|
|
446
|
+
"@/features/*": ["./src/features/*"],
|
|
447
|
+
"@/shared/*": ["./src/shared/*"]
|
|
448
|
+
};
|
|
449
|
+
await writeText(tsconfigPath, `${JSON.stringify(json, null, 2)}
|
|
450
|
+
`);
|
|
451
|
+
} catch {
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
async function mergePackageScripts(projectDir) {
|
|
455
|
+
const pkgPath = path10.join(projectDir, "package.json");
|
|
456
|
+
if (!await pathExists(pkgPath)) return;
|
|
457
|
+
try {
|
|
458
|
+
const pkg = JSON.parse(await readFile4(pkgPath, "utf8"));
|
|
459
|
+
pkg.scripts = {
|
|
460
|
+
...pkg.scripts,
|
|
461
|
+
lint: pkg.scripts?.lint ?? "eslint .",
|
|
462
|
+
format: pkg.scripts?.format ?? "prettier --write .",
|
|
463
|
+
test: pkg.scripts?.test ?? "jest",
|
|
464
|
+
prepare: pkg.scripts?.prepare ?? "husky"
|
|
465
|
+
};
|
|
466
|
+
await writeText(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
467
|
+
`);
|
|
468
|
+
} catch {
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
async function copyScaffoldConfigs(projectDir) {
|
|
472
|
+
const written = [];
|
|
473
|
+
const scaffoldRoot = path10.join(getTemplatesRoot(), "scaffold");
|
|
474
|
+
if (!await pathExists(scaffoldRoot)) return written;
|
|
475
|
+
const files = [
|
|
476
|
+
"eslint.config.js",
|
|
477
|
+
".prettierrc",
|
|
478
|
+
".prettierignore",
|
|
479
|
+
"jest.config.cjs",
|
|
480
|
+
"commitlint.config.cjs"
|
|
481
|
+
];
|
|
482
|
+
for (const file of files) {
|
|
483
|
+
const from = path10.join(scaffoldRoot, file);
|
|
484
|
+
const to = path10.join(projectDir, file);
|
|
485
|
+
if (await pathExists(from)) {
|
|
486
|
+
const did = await copyIfMissing(from, to);
|
|
487
|
+
if (did) written.push(file);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
const huskySrc = path10.join(scaffoldRoot, ".husky");
|
|
491
|
+
if (await pathExists(huskySrc)) {
|
|
492
|
+
const entries = await readdir2(huskySrc);
|
|
493
|
+
for (const entry of entries) {
|
|
494
|
+
const from = path10.join(huskySrc, entry);
|
|
495
|
+
const info = await stat(from);
|
|
496
|
+
if (!info.isFile()) continue;
|
|
497
|
+
const to = path10.join(projectDir, ".husky", entry);
|
|
498
|
+
const did = await copyIfMissing(from, to);
|
|
499
|
+
if (did) written.push(`.husky/${entry}`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return written;
|
|
503
|
+
}
|
|
504
|
+
async function applyArchitectureScaffold(projectDir) {
|
|
505
|
+
const dirsCreated = [];
|
|
506
|
+
for (const rel of FEATURE_DIRS) {
|
|
507
|
+
const dir = path10.join(projectDir, rel);
|
|
508
|
+
if (!await pathExists(dir)) {
|
|
509
|
+
await ensureDir(dir);
|
|
510
|
+
await writeText(path10.join(dir, ".gitkeep"), "");
|
|
511
|
+
dirsCreated.push(rel);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
const exampleIndex = path10.join(projectDir, "src/features/example/index.ts");
|
|
515
|
+
if (!await pathExists(exampleIndex)) {
|
|
516
|
+
await writeText(
|
|
517
|
+
exampleIndex,
|
|
518
|
+
`/** Public API for the example feature \u2014 replace with real exports. */
|
|
519
|
+
export {};
|
|
520
|
+
`
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
const configsWritten = await copyScaffoldConfigs(projectDir);
|
|
524
|
+
await mergeTsconfigPaths(projectDir);
|
|
525
|
+
await mergePackageScripts(projectDir);
|
|
526
|
+
return { dirsCreated, configsWritten };
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// src/scaffold/create-project.ts
|
|
530
|
+
import path11 from "path";
|
|
531
|
+
|
|
532
|
+
// src/utils/exec.ts
|
|
533
|
+
import { execa } from "execa";
|
|
534
|
+
var defaultRunCommand = (file, args = [], options = {}) => execa(file, args, { ...options });
|
|
535
|
+
|
|
536
|
+
// src/scaffold/create-project.ts
|
|
537
|
+
async function createNativeProject(options) {
|
|
538
|
+
const run = options.runCommand ?? defaultRunCommand;
|
|
539
|
+
const { name, stack, cwd } = options;
|
|
540
|
+
const projectDir = path11.join(cwd, name);
|
|
541
|
+
if (stack === "expo") {
|
|
542
|
+
await run("npx", ["create-expo-app@latest", name, "--template", "blank-typescript"], {
|
|
543
|
+
cwd,
|
|
544
|
+
stdio: "inherit"
|
|
545
|
+
});
|
|
546
|
+
} else {
|
|
547
|
+
await run("npx", ["@react-native-community/cli@latest", "init", name], {
|
|
548
|
+
cwd,
|
|
549
|
+
stdio: "inherit"
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
return projectDir;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// src/sdlc/setup.ts
|
|
556
|
+
import { cp as cp2 } from "fs/promises";
|
|
557
|
+
import path12 from "path";
|
|
558
|
+
function buildAgentConfig(inputs) {
|
|
559
|
+
return `${JSON.stringify(
|
|
560
|
+
{
|
|
561
|
+
version: 1,
|
|
562
|
+
workflow: "figma-jira-maestro-ci",
|
|
563
|
+
/** When true, prd-to-jira pauses for plan approval before creating issues. */
|
|
564
|
+
confirm: false,
|
|
565
|
+
jira: {
|
|
566
|
+
siteUrl: inputs.jiraSiteUrl,
|
|
567
|
+
projectKey: inputs.jiraProjectKey,
|
|
568
|
+
confirm: false
|
|
569
|
+
},
|
|
570
|
+
figma: {
|
|
571
|
+
fileUrl: inputs.figmaFileUrl
|
|
572
|
+
},
|
|
573
|
+
github: {
|
|
574
|
+
repo: inputs.githubRepo
|
|
575
|
+
}
|
|
576
|
+
},
|
|
577
|
+
null,
|
|
578
|
+
2
|
|
579
|
+
)}
|
|
580
|
+
`;
|
|
581
|
+
}
|
|
582
|
+
function buildEnvExample(inputs) {
|
|
583
|
+
return `# rn-agent-kit SDLC \u2014 copy to .env.local and fill secrets (never commit secrets)
|
|
584
|
+
JIRA_SITE_URL=${inputs.jiraSiteUrl}
|
|
585
|
+
JIRA_PROJECT_KEY=${inputs.jiraProjectKey}
|
|
586
|
+
JIRA_EMAIL=
|
|
587
|
+
JIRA_API_TOKEN=
|
|
588
|
+
|
|
589
|
+
FIGMA_FILE_URL=${inputs.figmaFileUrl}
|
|
590
|
+
FIGMA_ACCESS_TOKEN=
|
|
591
|
+
|
|
592
|
+
GITHUB_REPO=${inputs.githubRepo}
|
|
593
|
+
GITHUB_TOKEN=
|
|
594
|
+
`;
|
|
595
|
+
}
|
|
596
|
+
function buildMcpConfig() {
|
|
597
|
+
return `${JSON.stringify(
|
|
598
|
+
{
|
|
599
|
+
mcpServers: {
|
|
600
|
+
figma: {
|
|
601
|
+
command: "npx",
|
|
602
|
+
args: ["-y", "figma-developer-mcp", "--stdio"],
|
|
603
|
+
env: {
|
|
604
|
+
FIGMA_API_KEY: "${FIGMA_ACCESS_TOKEN}"
|
|
605
|
+
}
|
|
606
|
+
},
|
|
607
|
+
atlassian: {
|
|
608
|
+
command: "npx",
|
|
609
|
+
args: ["-y", "@modelcontextprotocol/server-atlassian"],
|
|
610
|
+
env: {
|
|
611
|
+
JIRA_URL: "${JIRA_SITE_URL}",
|
|
612
|
+
JIRA_EMAIL: "${JIRA_EMAIL}",
|
|
613
|
+
JIRA_API_TOKEN: "${JIRA_API_TOKEN}"
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
null,
|
|
619
|
+
2
|
|
620
|
+
)}
|
|
621
|
+
`;
|
|
622
|
+
}
|
|
623
|
+
async function setupSdlcWorkflow(projectDir, inputs) {
|
|
624
|
+
const filesWritten = [];
|
|
625
|
+
const templates = getTemplatesRoot();
|
|
626
|
+
const agentConfig = path12.join(projectDir, ".agent", "config.json");
|
|
627
|
+
await writeText(agentConfig, buildAgentConfig(inputs));
|
|
628
|
+
filesWritten.push(".agent/config.json");
|
|
629
|
+
const envExample = path12.join(projectDir, ".env.example");
|
|
630
|
+
await writeText(envExample, buildEnvExample(inputs));
|
|
631
|
+
filesWritten.push(".env.example");
|
|
632
|
+
const mcp = buildMcpConfig();
|
|
633
|
+
await writeText(path12.join(projectDir, ".mcp.json"), mcp);
|
|
634
|
+
filesWritten.push(".mcp.json");
|
|
635
|
+
await writeText(path12.join(projectDir, ".cursor", "mcp.json"), mcp);
|
|
636
|
+
filesWritten.push(".cursor/mcp.json");
|
|
637
|
+
const workflowsSrc = path12.join(templates, "workflows");
|
|
638
|
+
const workflowsDest = path12.join(projectDir, ".github", "workflows");
|
|
639
|
+
if (await pathExists(workflowsSrc)) {
|
|
640
|
+
await ensureDir(workflowsDest);
|
|
641
|
+
await cp2(workflowsSrc, workflowsDest, { recursive: true });
|
|
642
|
+
filesWritten.push(".github/workflows/");
|
|
643
|
+
}
|
|
644
|
+
const maestroSrc = path12.join(templates, "maestro");
|
|
645
|
+
const maestroDest = path12.join(projectDir, "maestro");
|
|
646
|
+
if (await pathExists(maestroSrc)) {
|
|
647
|
+
await ensureDir(maestroDest);
|
|
648
|
+
await cp2(maestroSrc, maestroDest, { recursive: true });
|
|
649
|
+
filesWritten.push("maestro/");
|
|
650
|
+
}
|
|
651
|
+
return { filesWritten };
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// src/commands/init.ts
|
|
655
|
+
var TOOL_OPTIONS = [
|
|
656
|
+
{ value: "claude", label: "Claude Code", adapter: "claude" },
|
|
657
|
+
{ value: "cursor", label: "Cursor", adapter: "cursor" },
|
|
658
|
+
{ value: "agents-md", label: "Codex / AGENTS.md", adapter: "agents-md" },
|
|
659
|
+
{ value: "copilot", label: "Copilot", adapter: "copilot" },
|
|
660
|
+
{ value: "windsurf", label: "Windsurf", adapter: "windsurf" }
|
|
661
|
+
];
|
|
662
|
+
function cancelIfNeeded(value) {
|
|
663
|
+
if (p.isCancel(value)) {
|
|
664
|
+
p.cancel("Cancelled.");
|
|
665
|
+
process.exitCode = 1;
|
|
666
|
+
return true;
|
|
667
|
+
}
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
async function detectAiTools(cwd) {
|
|
671
|
+
const found = [];
|
|
672
|
+
if (await detectClaudeProject(cwd)) found.push("claude");
|
|
673
|
+
if (await detectCursorProject(cwd)) found.push("cursor");
|
|
674
|
+
if (await detectAgentsMd(cwd)) found.push("agents-md");
|
|
675
|
+
if (await detectCopilotProject(cwd)) found.push("copilot");
|
|
676
|
+
if (await detectWindsurfProject(cwd)) found.push("windsurf");
|
|
677
|
+
return found;
|
|
678
|
+
}
|
|
679
|
+
function resolveSelectedAdapters(toolIds) {
|
|
680
|
+
const selected = [];
|
|
681
|
+
const missing = [];
|
|
682
|
+
for (const id of toolIds) {
|
|
683
|
+
const adapter = getAdapter(id);
|
|
684
|
+
if (!adapter) missing.push(id);
|
|
685
|
+
else if (!selected.some((a) => a.name === adapter.name)) selected.push(adapter);
|
|
686
|
+
}
|
|
687
|
+
if (missing.length) {
|
|
688
|
+
throw new Error(`Unknown tool(s): ${missing.join(", ")}`);
|
|
689
|
+
}
|
|
690
|
+
return selected;
|
|
691
|
+
}
|
|
692
|
+
function printNextSteps(opts) {
|
|
693
|
+
const rel = path13.basename(opts.projectDir);
|
|
694
|
+
const lines = [
|
|
695
|
+
opts.kind === "new" ? `cd ${rel}` : `Stay in ${rel}`,
|
|
696
|
+
opts.stack === "expo" ? "npx expo start" : "npx react-native start",
|
|
697
|
+
"Fill secrets from .env.example (if SDLC was enabled)",
|
|
698
|
+
`Verify adapters: npx rn-agent-kit doctor --cwd ${rel === path13.basename(process.cwd()) ? "." : rel}`
|
|
699
|
+
];
|
|
700
|
+
if (opts.sdlc) {
|
|
701
|
+
lines.push("Connect Figma + Atlassian MCP using tokens in your environment");
|
|
702
|
+
lines.push("Adjust maestro/smoke.yaml appId to your bundle id");
|
|
703
|
+
}
|
|
704
|
+
lines.push(`Installed tools: ${opts.tools.join(", ") || "(none)"}`);
|
|
705
|
+
p.note(lines.map((l, i) => `${i + 1}. ${l}`).join("\n"), "Next steps");
|
|
706
|
+
}
|
|
707
|
+
async function initCommand(options = {}, deps = {}) {
|
|
708
|
+
const runCommand = deps.runCommand ?? defaultRunCommand;
|
|
709
|
+
const createProject = deps.createProject ?? createNativeProject;
|
|
710
|
+
const applyArchitecture = deps.applyArchitecture ?? applyArchitectureScaffold;
|
|
711
|
+
const setupSdlc = deps.setupSdlc ?? setupSdlcWorkflow;
|
|
712
|
+
const detect = deps.detect ?? detectProject;
|
|
713
|
+
const loadSkillsFn = deps.loadSkillsFn ?? loadSkills;
|
|
714
|
+
const cwd = options.cwd ?? process.cwd();
|
|
715
|
+
const nonInteractive = Boolean(options.yes);
|
|
716
|
+
p.intro("rn-agent-kit init");
|
|
717
|
+
const detection = await detect(cwd);
|
|
718
|
+
const suggestedKind = options.type ?? (detection.isReactNative ? "existing" : "new");
|
|
719
|
+
let kind = suggestedKind;
|
|
720
|
+
if (!options.type && !nonInteractive) {
|
|
721
|
+
const answer = await p.select({
|
|
722
|
+
message: "Is this a NEW project or an EXISTING project?",
|
|
723
|
+
options: [
|
|
724
|
+
{
|
|
725
|
+
value: "new",
|
|
726
|
+
label: "NEW project",
|
|
727
|
+
hint: detection.isReactNative ? void 0 : "suggested"
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
value: "existing",
|
|
731
|
+
label: "EXISTING project",
|
|
732
|
+
hint: detection.isReactNative ? "react-native detected" : void 0
|
|
733
|
+
}
|
|
734
|
+
],
|
|
735
|
+
initialValue: suggestedKind
|
|
736
|
+
});
|
|
737
|
+
if (cancelIfNeeded(answer)) return;
|
|
738
|
+
kind = answer;
|
|
739
|
+
} else if (options.type) {
|
|
740
|
+
kind = options.type;
|
|
741
|
+
} else if (nonInteractive) {
|
|
742
|
+
kind = suggestedKind;
|
|
743
|
+
}
|
|
744
|
+
let stack = options.stack ?? (detection.stack === "cli" ? "cli" : "expo");
|
|
745
|
+
let projectDir = cwd;
|
|
746
|
+
if (kind === "new") {
|
|
747
|
+
let name = options.name ?? "MyApp";
|
|
748
|
+
if (!options.name && !nonInteractive) {
|
|
749
|
+
const nameAnswer = await p.text({
|
|
750
|
+
message: "Project name",
|
|
751
|
+
placeholder: "MyApp",
|
|
752
|
+
defaultValue: "MyApp",
|
|
753
|
+
validate: (v) => {
|
|
754
|
+
if (!v || !/^[A-Za-z][A-Za-z0-9_-]*$/.test(v)) {
|
|
755
|
+
return "Use a valid package name (letters, numbers, _-)";
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
if (cancelIfNeeded(nameAnswer)) return;
|
|
760
|
+
name = nameAnswer;
|
|
761
|
+
}
|
|
762
|
+
let chosenStack = options.stack ?? "expo";
|
|
763
|
+
if (!options.stack && !nonInteractive) {
|
|
764
|
+
const stackAnswer = await p.select({
|
|
765
|
+
message: "Expo or React Native CLI?",
|
|
766
|
+
options: [
|
|
767
|
+
{ value: "expo", label: "Expo", hint: "recommended" },
|
|
768
|
+
{ value: "cli", label: "React Native CLI" }
|
|
769
|
+
],
|
|
770
|
+
initialValue: "expo"
|
|
771
|
+
});
|
|
772
|
+
if (cancelIfNeeded(stackAnswer)) return;
|
|
773
|
+
chosenStack = stackAnswer;
|
|
774
|
+
}
|
|
775
|
+
stack = chosenStack;
|
|
776
|
+
const spinner3 = p.spinner();
|
|
777
|
+
spinner3.start(
|
|
778
|
+
chosenStack === "expo" ? `Creating Expo app "${name}"\u2026` : `Creating React Native CLI app "${name}"\u2026`
|
|
779
|
+
);
|
|
780
|
+
try {
|
|
781
|
+
projectDir = await createProject({
|
|
782
|
+
name,
|
|
783
|
+
stack: chosenStack,
|
|
784
|
+
cwd,
|
|
785
|
+
runCommand
|
|
786
|
+
});
|
|
787
|
+
spinner3.stop(`Created ${name}`);
|
|
788
|
+
} catch (err) {
|
|
789
|
+
spinner3.stop("Project creation failed");
|
|
790
|
+
p.cancel(err instanceof Error ? err.message : String(err));
|
|
791
|
+
process.exitCode = 1;
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
const archSpinner = p.spinner();
|
|
795
|
+
archSpinner.start("Applying architecture scaffold\u2026");
|
|
796
|
+
const arch = await applyArchitecture(projectDir);
|
|
797
|
+
archSpinner.stop(
|
|
798
|
+
`Scaffold ready (${arch.dirsCreated.length} dirs, ${arch.configsWritten.length} configs)`
|
|
799
|
+
);
|
|
800
|
+
} else {
|
|
801
|
+
if (!detection.isReactNative) {
|
|
802
|
+
p.log.warn(
|
|
803
|
+
"No react-native dependency detected in package.json. Continuing anyway \u2014 confirm before scaffolding."
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
p.note(formatDetectionSummary(detection), "Detected project");
|
|
807
|
+
stack = options.stack ?? (detection.stack === "unknown" ? "expo" : detection.stack);
|
|
808
|
+
let applyScaffold = false;
|
|
809
|
+
if (nonInteractive) {
|
|
810
|
+
applyScaffold = false;
|
|
811
|
+
} else {
|
|
812
|
+
const scaffoldAnswer = await p.confirm({
|
|
813
|
+
message: "Apply architecture scaffold (src/features, src/shared, eslint, prettier, husky, jest)? This will not delete existing files.",
|
|
814
|
+
initialValue: false
|
|
815
|
+
});
|
|
816
|
+
if (cancelIfNeeded(scaffoldAnswer)) return;
|
|
817
|
+
applyScaffold = scaffoldAnswer;
|
|
818
|
+
}
|
|
819
|
+
if (applyScaffold) {
|
|
820
|
+
const archSpinner = p.spinner();
|
|
821
|
+
archSpinner.start("Applying architecture scaffold\u2026");
|
|
822
|
+
const arch = await applyArchitecture(projectDir);
|
|
823
|
+
archSpinner.stop(
|
|
824
|
+
`Scaffold applied (${arch.dirsCreated.length} new dirs, ${arch.configsWritten.length} configs)`
|
|
825
|
+
);
|
|
826
|
+
} else {
|
|
827
|
+
p.log.info("Skipping architecture restructure.");
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
const toolIdsFromFlags = options.tools ?? options.adapters;
|
|
831
|
+
let selectedToolIds = [];
|
|
832
|
+
if (toolIdsFromFlags?.length) {
|
|
833
|
+
selectedToolIds = toolIdsFromFlags.map((t) => resolveToolName(t) ?? t).filter(Boolean);
|
|
834
|
+
} else if (nonInteractive) {
|
|
835
|
+
selectedToolIds = TOOL_OPTIONS.map((t) => t.value);
|
|
836
|
+
} else {
|
|
837
|
+
const detectedTools = await detectAiTools(projectDir);
|
|
838
|
+
const toolAnswer = await p.multiselect({
|
|
839
|
+
message: "Which AI tools should we install skills for?",
|
|
840
|
+
options: TOOL_OPTIONS.map((t) => ({
|
|
841
|
+
value: t.value,
|
|
842
|
+
label: t.label,
|
|
843
|
+
hint: detectedTools.includes(t.value) ? "detected" : void 0
|
|
844
|
+
})),
|
|
845
|
+
initialValues: detectedTools.length > 0 ? detectedTools : TOOL_OPTIONS.map((t) => t.value),
|
|
846
|
+
required: true
|
|
847
|
+
});
|
|
848
|
+
if (cancelIfNeeded(toolAnswer)) return;
|
|
849
|
+
selectedToolIds = toolAnswer;
|
|
850
|
+
}
|
|
851
|
+
let selectedAdapters;
|
|
852
|
+
try {
|
|
853
|
+
selectedAdapters = resolveSelectedAdapters(selectedToolIds);
|
|
854
|
+
} catch (err) {
|
|
855
|
+
p.cancel(err instanceof Error ? err.message : String(err));
|
|
856
|
+
process.exitCode = 1;
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
let sdlcEnabled = Boolean(options.sdlc);
|
|
860
|
+
if (options.sdlc === void 0 && !nonInteractive) {
|
|
861
|
+
const sdlcAnswer = await p.confirm({
|
|
862
|
+
message: "Install the SDLC workflow (Figma \u2192 Jira \u2192 Maestro \u2192 CI)?",
|
|
863
|
+
initialValue: false
|
|
864
|
+
});
|
|
865
|
+
if (cancelIfNeeded(sdlcAnswer)) return;
|
|
866
|
+
sdlcEnabled = sdlcAnswer;
|
|
867
|
+
}
|
|
868
|
+
if (sdlcEnabled) {
|
|
869
|
+
let inputs = {
|
|
870
|
+
jiraSiteUrl: options.jiraUrl ?? "https://your-domain.atlassian.net",
|
|
871
|
+
jiraProjectKey: options.jiraKey ?? "APP",
|
|
872
|
+
figmaFileUrl: options.figmaUrl ?? "https://www.figma.com/file/example",
|
|
873
|
+
githubRepo: options.githubRepo ?? "org/repo"
|
|
874
|
+
};
|
|
875
|
+
if (!nonInteractive) {
|
|
876
|
+
const jiraUrl = await p.text({
|
|
877
|
+
message: "Jira site URL",
|
|
878
|
+
placeholder: "https://your-domain.atlassian.net",
|
|
879
|
+
defaultValue: inputs.jiraSiteUrl
|
|
880
|
+
});
|
|
881
|
+
if (cancelIfNeeded(jiraUrl)) return;
|
|
882
|
+
const jiraKey = await p.text({
|
|
883
|
+
message: "Jira project key",
|
|
884
|
+
placeholder: "APP",
|
|
885
|
+
defaultValue: inputs.jiraProjectKey
|
|
886
|
+
});
|
|
887
|
+
if (cancelIfNeeded(jiraKey)) return;
|
|
888
|
+
const figmaUrl = await p.text({
|
|
889
|
+
message: "Figma file URL",
|
|
890
|
+
placeholder: "https://www.figma.com/file/\u2026",
|
|
891
|
+
defaultValue: inputs.figmaFileUrl
|
|
892
|
+
});
|
|
893
|
+
if (cancelIfNeeded(figmaUrl)) return;
|
|
894
|
+
const githubRepo = await p.text({
|
|
895
|
+
message: "GitHub repo (owner/name)",
|
|
896
|
+
placeholder: "acme/my-app",
|
|
897
|
+
defaultValue: inputs.githubRepo
|
|
898
|
+
});
|
|
899
|
+
if (cancelIfNeeded(githubRepo)) return;
|
|
900
|
+
inputs = {
|
|
901
|
+
jiraSiteUrl: jiraUrl,
|
|
902
|
+
jiraProjectKey: jiraKey,
|
|
903
|
+
figmaFileUrl: figmaUrl,
|
|
904
|
+
githubRepo
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
const sdlcSpinner = p.spinner();
|
|
908
|
+
sdlcSpinner.start("Configuring SDLC workflow\u2026");
|
|
909
|
+
const result = await setupSdlc(projectDir, inputs);
|
|
910
|
+
sdlcSpinner.stop(`SDLC files: ${result.filesWritten.join(", ")}`);
|
|
911
|
+
}
|
|
912
|
+
const skills = await loadSkillsFn();
|
|
913
|
+
if (skills.length === 0) {
|
|
914
|
+
p.cancel("No skills found in package. Aborting adapter install.");
|
|
915
|
+
process.exitCode = 1;
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
const installSpinner = p.spinner();
|
|
919
|
+
installSpinner.start("Installing agent skills\u2026");
|
|
920
|
+
for (const adapter of selectedAdapters) {
|
|
921
|
+
await adapter.install(skills, projectDir);
|
|
922
|
+
}
|
|
923
|
+
installSpinner.stop(`Installed: ${selectedAdapters.map((a) => a.name).join(", ") || "(none)"}`);
|
|
924
|
+
printNextSteps({
|
|
925
|
+
projectDir,
|
|
926
|
+
kind,
|
|
927
|
+
stack,
|
|
928
|
+
tools: selectedAdapters.map((a) => a.name),
|
|
929
|
+
sdlc: sdlcEnabled
|
|
930
|
+
});
|
|
931
|
+
p.outro("rn-agent-kit init complete.");
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// src/commands/doctor.ts
|
|
935
|
+
import * as p2 from "@clack/prompts";
|
|
936
|
+
import path15 from "path";
|
|
937
|
+
|
|
938
|
+
// src/commands/doctor-checks.ts
|
|
939
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
940
|
+
import path14 from "path";
|
|
941
|
+
import { execa as execa2 } from "execa";
|
|
942
|
+
async function defaultWhich(cmd) {
|
|
943
|
+
try {
|
|
944
|
+
const r = await execa2(process.platform === "win32" ? "where" : "which", [cmd]);
|
|
945
|
+
const line = r.stdout.trim().split(/\r?\n/)[0];
|
|
946
|
+
return line || null;
|
|
947
|
+
} catch {
|
|
948
|
+
return null;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
async function defaultExec(file, args) {
|
|
952
|
+
try {
|
|
953
|
+
const r = await execa2(file, args, { reject: false });
|
|
954
|
+
return { exitCode: r.exitCode ?? 1, stdout: (r.stdout || r.stderr || "").trim() };
|
|
955
|
+
} catch (e) {
|
|
956
|
+
return { exitCode: 1, stdout: e instanceof Error ? e.message : String(e) };
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
function nodeMajor(version) {
|
|
960
|
+
const m = version.replace(/^v/, "").match(/^(\d+)/);
|
|
961
|
+
return m ? Number(m[1]) : 0;
|
|
962
|
+
}
|
|
963
|
+
async function readJsonSafe(file) {
|
|
964
|
+
try {
|
|
965
|
+
return JSON.parse(await readFile5(file, "utf8"));
|
|
966
|
+
} catch {
|
|
967
|
+
return null;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
async function runDoctorChecks(cwd, deps = {}) {
|
|
971
|
+
const platform = deps.platform ?? process.platform;
|
|
972
|
+
const env = deps.env ?? process.env;
|
|
973
|
+
const which = deps.which ?? defaultWhich;
|
|
974
|
+
const exec = deps.exec ?? defaultExec;
|
|
975
|
+
const results = [];
|
|
976
|
+
const major = nodeMajor(process.versions.node);
|
|
977
|
+
results.push(
|
|
978
|
+
major >= 18 ? {
|
|
979
|
+
id: "node",
|
|
980
|
+
title: "Node.js >= 18",
|
|
981
|
+
status: "pass",
|
|
982
|
+
detail: `v${process.versions.node}`
|
|
983
|
+
} : {
|
|
984
|
+
id: "node",
|
|
985
|
+
title: "Node.js >= 18",
|
|
986
|
+
status: "fail",
|
|
987
|
+
detail: `Found v${process.versions.node}`,
|
|
988
|
+
fix: "Install Node 18+ (https://nodejs.org) or use nvm/fnm."
|
|
989
|
+
}
|
|
990
|
+
);
|
|
991
|
+
const gitPath = await which("git");
|
|
992
|
+
if (gitPath) {
|
|
993
|
+
const g = await exec("git", ["--version"]);
|
|
994
|
+
results.push({
|
|
995
|
+
id: "git",
|
|
996
|
+
title: "git",
|
|
997
|
+
status: "pass",
|
|
998
|
+
detail: g.stdout || gitPath
|
|
999
|
+
});
|
|
1000
|
+
} else {
|
|
1001
|
+
results.push({
|
|
1002
|
+
id: "git",
|
|
1003
|
+
title: "git",
|
|
1004
|
+
status: "fail",
|
|
1005
|
+
detail: "git not found on PATH",
|
|
1006
|
+
fix: "Install Git and ensure it is on PATH (https://git-scm.com)."
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
const javaPath = await which("java");
|
|
1010
|
+
if (javaPath) {
|
|
1011
|
+
const j = await exec("java", ["-version"]);
|
|
1012
|
+
results.push({
|
|
1013
|
+
id: "java",
|
|
1014
|
+
title: "Java",
|
|
1015
|
+
status: "pass",
|
|
1016
|
+
detail: (j.stdout.split("\n")[0] || javaPath).slice(0, 120)
|
|
1017
|
+
});
|
|
1018
|
+
} else {
|
|
1019
|
+
results.push({
|
|
1020
|
+
id: "java",
|
|
1021
|
+
title: "Java",
|
|
1022
|
+
status: "warn",
|
|
1023
|
+
detail: "java not found (needed for Android Gradle builds)",
|
|
1024
|
+
fix: "Install Temurin JDK 17+ and ensure `java` is on PATH."
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
const androidHome = env.ANDROID_HOME || env.ANDROID_SDK_ROOT;
|
|
1028
|
+
if (androidHome && await pathExists(androidHome)) {
|
|
1029
|
+
results.push({
|
|
1030
|
+
id: "android-sdk",
|
|
1031
|
+
title: "Android SDK (ANDROID_HOME)",
|
|
1032
|
+
status: "pass",
|
|
1033
|
+
detail: androidHome
|
|
1034
|
+
});
|
|
1035
|
+
} else {
|
|
1036
|
+
results.push({
|
|
1037
|
+
id: "android-sdk",
|
|
1038
|
+
title: "Android SDK (ANDROID_HOME)",
|
|
1039
|
+
status: "warn",
|
|
1040
|
+
detail: androidHome ? `ANDROID_HOME set but missing: ${androidHome}` : "ANDROID_HOME / ANDROID_SDK_ROOT not set",
|
|
1041
|
+
fix: "Install Android Studio SDK and export ANDROID_HOME (and platform-tools on PATH)."
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
if (platform === "darwin") {
|
|
1045
|
+
const xcode = await which("xcodebuild");
|
|
1046
|
+
if (xcode) {
|
|
1047
|
+
const x = await exec("xcodebuild", ["-version"]);
|
|
1048
|
+
results.push({
|
|
1049
|
+
id: "xcode",
|
|
1050
|
+
title: "Xcode",
|
|
1051
|
+
status: "pass",
|
|
1052
|
+
detail: (x.stdout.split("\n")[0] || xcode).slice(0, 120)
|
|
1053
|
+
});
|
|
1054
|
+
} else {
|
|
1055
|
+
results.push({
|
|
1056
|
+
id: "xcode",
|
|
1057
|
+
title: "Xcode",
|
|
1058
|
+
status: "warn",
|
|
1059
|
+
detail: "xcodebuild not found",
|
|
1060
|
+
fix: "Install Xcode from the App Store and run `xcode-select --install` / `sudo xcode-select -s /Applications/Xcode.app`."
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
} else {
|
|
1064
|
+
results.push({
|
|
1065
|
+
id: "xcode",
|
|
1066
|
+
title: "Xcode",
|
|
1067
|
+
status: "skip",
|
|
1068
|
+
detail: `Skipped on ${platform}`
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
const maestro = await which("maestro");
|
|
1072
|
+
if (maestro) {
|
|
1073
|
+
const m = await exec("maestro", ["--version"]);
|
|
1074
|
+
results.push({
|
|
1075
|
+
id: "maestro",
|
|
1076
|
+
title: "Maestro",
|
|
1077
|
+
status: "pass",
|
|
1078
|
+
detail: m.stdout || maestro
|
|
1079
|
+
});
|
|
1080
|
+
} else {
|
|
1081
|
+
results.push({
|
|
1082
|
+
id: "maestro",
|
|
1083
|
+
title: "Maestro",
|
|
1084
|
+
status: "warn",
|
|
1085
|
+
detail: "maestro not found on PATH",
|
|
1086
|
+
fix: 'Install with: curl -fsSL "https://get.maestro.mobile.dev" | bash then add ~/.maestro/bin to PATH.'
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
const mcpPaths = [path14.join(cwd, ".mcp.json"), path14.join(cwd, ".cursor", "mcp.json")];
|
|
1090
|
+
let mcpRaw = null;
|
|
1091
|
+
let mcpFile = null;
|
|
1092
|
+
for (const pth of mcpPaths) {
|
|
1093
|
+
if (await pathExists(pth)) {
|
|
1094
|
+
mcpRaw = await readJsonSafe(pth);
|
|
1095
|
+
mcpFile = pth;
|
|
1096
|
+
break;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
if (!mcpFile || !mcpRaw || typeof mcpRaw !== "object") {
|
|
1100
|
+
results.push({
|
|
1101
|
+
id: "mcp-config",
|
|
1102
|
+
title: "MCP config (.mcp.json / .cursor/mcp.json)",
|
|
1103
|
+
status: "warn",
|
|
1104
|
+
detail: "No MCP config found in project",
|
|
1105
|
+
fix: "Run `rn-agent-kit init --sdlc` or add Figma + Atlassian servers to .mcp.json / .cursor/mcp.json."
|
|
1106
|
+
});
|
|
1107
|
+
} else {
|
|
1108
|
+
const servers = mcpRaw.mcpServers ?? mcpRaw.servers ?? {};
|
|
1109
|
+
const names = Object.keys(servers).map((k) => k.toLowerCase());
|
|
1110
|
+
const hasFigma = names.some((n) => n.includes("figma"));
|
|
1111
|
+
const hasAtlassian = names.some(
|
|
1112
|
+
(n) => n.includes("atlassian") || n.includes("jira") || n.includes("mcp-atlassian")
|
|
1113
|
+
);
|
|
1114
|
+
if (hasFigma && hasAtlassian) {
|
|
1115
|
+
results.push({
|
|
1116
|
+
id: "mcp-config",
|
|
1117
|
+
title: "MCP config (Figma + Atlassian)",
|
|
1118
|
+
status: "pass",
|
|
1119
|
+
detail: `Found in ${path14.relative(cwd, mcpFile) || mcpFile}: ${Object.keys(servers).join(", ")}`
|
|
1120
|
+
});
|
|
1121
|
+
} else {
|
|
1122
|
+
results.push({
|
|
1123
|
+
id: "mcp-config",
|
|
1124
|
+
title: "MCP config (Figma + Atlassian)",
|
|
1125
|
+
status: "warn",
|
|
1126
|
+
detail: `Partial MCP config in ${path14.relative(cwd, mcpFile)} (figma=${hasFigma}, atlassian=${hasAtlassian})`,
|
|
1127
|
+
fix: "Ensure both Figma and Atlassian/Jira MCP server entries exist (see templates from init --sdlc)."
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
const figmaToken = Boolean(env.FIGMA_TOKEN || env.FIGMA_ACCESS_TOKEN || env.FIGMA_API_KEY);
|
|
1132
|
+
results.push(
|
|
1133
|
+
figmaToken ? {
|
|
1134
|
+
id: "figma-token",
|
|
1135
|
+
title: "Figma token in env",
|
|
1136
|
+
status: "pass",
|
|
1137
|
+
detail: "FIGMA_TOKEN / FIGMA_ACCESS_TOKEN / FIGMA_API_KEY is set"
|
|
1138
|
+
} : {
|
|
1139
|
+
id: "figma-token",
|
|
1140
|
+
title: "Figma token in env",
|
|
1141
|
+
status: "warn",
|
|
1142
|
+
detail: "No Figma token env var set",
|
|
1143
|
+
fix: "Export FIGMA_TOKEN (or FIGMA_ACCESS_TOKEN) for tokens fetch / Figma MCP. Never commit it."
|
|
1144
|
+
}
|
|
1145
|
+
);
|
|
1146
|
+
const jiraOk = Boolean(
|
|
1147
|
+
(env.JIRA_SITE_URL || env.JIRA_URL) && (env.JIRA_EMAIL || env.ATLASSIAN_EMAIL) && (env.JIRA_API_TOKEN || env.ATLASSIAN_API_TOKEN)
|
|
1148
|
+
);
|
|
1149
|
+
results.push(
|
|
1150
|
+
jiraOk ? {
|
|
1151
|
+
id: "jira-env",
|
|
1152
|
+
title: "Jira / Atlassian env",
|
|
1153
|
+
status: "pass",
|
|
1154
|
+
detail: "JIRA_SITE_URL + JIRA_EMAIL + JIRA_API_TOKEN present"
|
|
1155
|
+
} : {
|
|
1156
|
+
id: "jira-env",
|
|
1157
|
+
title: "Jira / Atlassian env",
|
|
1158
|
+
status: "warn",
|
|
1159
|
+
detail: "Missing one of JIRA_SITE_URL / JIRA_EMAIL / JIRA_API_TOKEN",
|
|
1160
|
+
fix: "Set Jira Cloud site URL, email, and API token for Atlassian MCP and CI comments."
|
|
1161
|
+
}
|
|
1162
|
+
);
|
|
1163
|
+
const agentConfigPath = path14.join(cwd, ".agent", "config.json");
|
|
1164
|
+
if (!await pathExists(agentConfigPath)) {
|
|
1165
|
+
results.push({
|
|
1166
|
+
id: "agent-config",
|
|
1167
|
+
title: ".agent/config.json",
|
|
1168
|
+
status: "warn",
|
|
1169
|
+
detail: "Not found",
|
|
1170
|
+
fix: "Run `rn-agent-kit init --sdlc` to create .agent/config.json (no secrets)."
|
|
1171
|
+
});
|
|
1172
|
+
} else {
|
|
1173
|
+
const cfg = await readJsonSafe(agentConfigPath);
|
|
1174
|
+
if (!cfg || typeof cfg !== "object") {
|
|
1175
|
+
results.push({
|
|
1176
|
+
id: "agent-config",
|
|
1177
|
+
title: ".agent/config.json",
|
|
1178
|
+
status: "fail",
|
|
1179
|
+
detail: "Invalid JSON",
|
|
1180
|
+
fix: "Fix JSON syntax or regenerate via init --sdlc."
|
|
1181
|
+
});
|
|
1182
|
+
} else {
|
|
1183
|
+
const c = cfg;
|
|
1184
|
+
const missing = [];
|
|
1185
|
+
if (!c.jira?.siteUrl) missing.push("jira.siteUrl");
|
|
1186
|
+
if (!c.jira?.projectKey) missing.push("jira.projectKey");
|
|
1187
|
+
if (!c.figma?.fileUrl) missing.push("figma.fileUrl");
|
|
1188
|
+
if (missing.length) {
|
|
1189
|
+
results.push({
|
|
1190
|
+
id: "agent-config",
|
|
1191
|
+
title: ".agent/config.json",
|
|
1192
|
+
status: "warn",
|
|
1193
|
+
detail: `Missing fields: ${missing.join(", ")}`,
|
|
1194
|
+
fix: "Fill jira.siteUrl, jira.projectKey, and figma.fileUrl (still no secrets in this file)."
|
|
1195
|
+
});
|
|
1196
|
+
} else {
|
|
1197
|
+
results.push({
|
|
1198
|
+
id: "agent-config",
|
|
1199
|
+
title: ".agent/config.json",
|
|
1200
|
+
status: "pass",
|
|
1201
|
+
detail: `project ${c.jira.projectKey}`
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
return results;
|
|
1207
|
+
}
|
|
1208
|
+
function doctorHasFailures(results) {
|
|
1209
|
+
return results.some((r) => r.status === "fail");
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// src/commands/doctor.ts
|
|
1213
|
+
async function checkClaude(cwd, skillNames) {
|
|
1214
|
+
const issues = [];
|
|
1215
|
+
if (!await detectClaudeProject(cwd)) {
|
|
1216
|
+
issues.push("No .claude/ or CLAUDE.md detected");
|
|
1217
|
+
return issues;
|
|
1218
|
+
}
|
|
1219
|
+
for (const name of skillNames) {
|
|
1220
|
+
const dest = path15.join(cwd, ".claude", "skills", name, "SKILL.md");
|
|
1221
|
+
if (!await pathExists(dest)) issues.push(`Missing Claude skill: ${name}`);
|
|
1222
|
+
}
|
|
1223
|
+
return issues;
|
|
1224
|
+
}
|
|
1225
|
+
async function checkCursor(cwd, skillNames) {
|
|
1226
|
+
const issues = [];
|
|
1227
|
+
if (!await detectCursorProject(cwd)) {
|
|
1228
|
+
issues.push("No .cursor/ or .cursorrules detected");
|
|
1229
|
+
return issues;
|
|
1230
|
+
}
|
|
1231
|
+
for (const name of skillNames) {
|
|
1232
|
+
const dest = path15.join(cwd, ".cursor", "rules", `${name}.mdc`);
|
|
1233
|
+
if (!await pathExists(dest)) issues.push(`Missing Cursor rule: ${name}.mdc`);
|
|
1234
|
+
}
|
|
1235
|
+
return issues;
|
|
1236
|
+
}
|
|
1237
|
+
async function checkAgentsMd(cwd) {
|
|
1238
|
+
const issues = [];
|
|
1239
|
+
if (!await detectAgentsMd(cwd)) {
|
|
1240
|
+
issues.push("AGENTS.md not found");
|
|
1241
|
+
return issues;
|
|
1242
|
+
}
|
|
1243
|
+
const content = await readText(path15.join(cwd, "AGENTS.md"));
|
|
1244
|
+
if (!content.includes(START_MARKER) || !content.includes(END_MARKER)) {
|
|
1245
|
+
issues.push("AGENTS.md missing rn-agent-kit markers");
|
|
1246
|
+
}
|
|
1247
|
+
return issues;
|
|
1248
|
+
}
|
|
1249
|
+
async function checkCopilot(cwd) {
|
|
1250
|
+
const issues = [];
|
|
1251
|
+
if (!await detectCopilotProject(cwd)) {
|
|
1252
|
+
issues.push("No .github/ (Copilot) detected");
|
|
1253
|
+
return issues;
|
|
1254
|
+
}
|
|
1255
|
+
const dest = path15.join(cwd, ".github", "copilot-instructions.md");
|
|
1256
|
+
if (!await pathExists(dest)) {
|
|
1257
|
+
issues.push("Missing .github/copilot-instructions.md");
|
|
1258
|
+
return issues;
|
|
1259
|
+
}
|
|
1260
|
+
const content = await readText(dest);
|
|
1261
|
+
if (!content.includes(COPILOT_START) || !content.includes(COPILOT_END)) {
|
|
1262
|
+
issues.push("copilot-instructions.md missing rn-agent-kit markers");
|
|
1263
|
+
}
|
|
1264
|
+
return issues;
|
|
1265
|
+
}
|
|
1266
|
+
async function checkWindsurf(cwd, skillNames) {
|
|
1267
|
+
const issues = [];
|
|
1268
|
+
if (!await detectWindsurfProject(cwd)) {
|
|
1269
|
+
issues.push("No .windsurf/ detected");
|
|
1270
|
+
return issues;
|
|
1271
|
+
}
|
|
1272
|
+
for (const name of skillNames) {
|
|
1273
|
+
const dest = path15.join(cwd, ".windsurf", "rules", `${name}.md`);
|
|
1274
|
+
if (!await pathExists(dest)) issues.push(`Missing Windsurf rule: ${name}.md`);
|
|
1275
|
+
}
|
|
1276
|
+
return issues;
|
|
1277
|
+
}
|
|
1278
|
+
function printCheck(check) {
|
|
1279
|
+
const line = `${check.title}: ${check.detail}`;
|
|
1280
|
+
if (check.status === "pass") p2.log.success(line);
|
|
1281
|
+
else if (check.status === "skip") p2.log.info(`[skip] ${line}`);
|
|
1282
|
+
else if (check.status === "warn") {
|
|
1283
|
+
p2.log.warn(line);
|
|
1284
|
+
if (check.fix) p2.log.message(` Fix: ${check.fix}`);
|
|
1285
|
+
} else {
|
|
1286
|
+
p2.log.error(line);
|
|
1287
|
+
if (check.fix) p2.log.message(` Fix: ${check.fix}`);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
async function doctorCommand(options = {}, deps = {}) {
|
|
1291
|
+
const cwd = options.cwd ?? process.cwd();
|
|
1292
|
+
p2.intro("rn-agent-kit doctor");
|
|
1293
|
+
const envChecks = await runDoctorChecks(cwd, deps);
|
|
1294
|
+
p2.log.step("Environment & tooling");
|
|
1295
|
+
for (const c of envChecks) printCheck(c);
|
|
1296
|
+
const skills = await loadSkills();
|
|
1297
|
+
const skillNames = skills.map((s) => s.name);
|
|
1298
|
+
p2.log.info(`Packaged skills: ${skillNames.length}`);
|
|
1299
|
+
if (!options.skipAdapters) {
|
|
1300
|
+
p2.log.step("Installed adapters (informational)");
|
|
1301
|
+
const adapterChecks = [
|
|
1302
|
+
{ name: "claude", issues: await checkClaude(cwd, skillNames) },
|
|
1303
|
+
{ name: "cursor", issues: await checkCursor(cwd, skillNames) },
|
|
1304
|
+
{ name: "agents-md", issues: await checkAgentsMd(cwd) },
|
|
1305
|
+
{ name: "copilot", issues: await checkCopilot(cwd) },
|
|
1306
|
+
{ name: "windsurf", issues: await checkWindsurf(cwd, skillNames) }
|
|
1307
|
+
];
|
|
1308
|
+
for (const check of adapterChecks) {
|
|
1309
|
+
if (check.issues.length === 0) {
|
|
1310
|
+
p2.log.success(`${check.name}: ok`);
|
|
1311
|
+
} else {
|
|
1312
|
+
p2.log.warn(`${check.name}:`);
|
|
1313
|
+
for (const issue of check.issues) p2.log.message(` \u2013 ${issue}`);
|
|
1314
|
+
p2.log.message(` Fix: rn-agent-kit update -a ${check.name} or rn-agent-kit init`);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
p2.note(adapters.map((a) => a.name).join(", "), "Available adapters");
|
|
1318
|
+
}
|
|
1319
|
+
const failed = doctorHasFailures(envChecks);
|
|
1320
|
+
const warned = envChecks.some((c) => c.status === "warn");
|
|
1321
|
+
if (failed) {
|
|
1322
|
+
p2.outro("Doctor found failures \u2014 fix the items above, then re-run.");
|
|
1323
|
+
process.exitCode = 1;
|
|
1324
|
+
} else if (warned) {
|
|
1325
|
+
p2.outro("Doctor passed with warnings \u2014 optional tooling may be missing.");
|
|
1326
|
+
} else {
|
|
1327
|
+
p2.outro("All environment checks passed.");
|
|
1328
|
+
}
|
|
1329
|
+
return envChecks;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
// src/commands/update.ts
|
|
1333
|
+
import * as p3 from "@clack/prompts";
|
|
1334
|
+
import path16 from "path";
|
|
1335
|
+
async function detectPreviouslyInstalled(cwd) {
|
|
1336
|
+
const found = [];
|
|
1337
|
+
if (await pathExists(path16.join(cwd, ".claude", "skills"))) {
|
|
1338
|
+
const a = getAdapter("claude");
|
|
1339
|
+
if (a) found.push(a);
|
|
1340
|
+
}
|
|
1341
|
+
if (await pathExists(path16.join(cwd, ".cursor", "rules"))) {
|
|
1342
|
+
const a = getAdapter("cursor");
|
|
1343
|
+
if (a) found.push(a);
|
|
1344
|
+
}
|
|
1345
|
+
if (await pathExists(path16.join(cwd, "AGENTS.md"))) {
|
|
1346
|
+
const content = await readText(path16.join(cwd, "AGENTS.md"));
|
|
1347
|
+
if (content.includes(START_MARKER)) {
|
|
1348
|
+
const a = getAdapter("agents-md");
|
|
1349
|
+
if (a) found.push(a);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
if (await pathExists(path16.join(cwd, ".github", "copilot-instructions.md"))) {
|
|
1353
|
+
const content = await readText(path16.join(cwd, ".github", "copilot-instructions.md"));
|
|
1354
|
+
if (content.includes(COPILOT_START)) {
|
|
1355
|
+
const a = getAdapter("copilot");
|
|
1356
|
+
if (a) found.push(a);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
if (await pathExists(path16.join(cwd, ".windsurf", "rules"))) {
|
|
1360
|
+
const a = getAdapter("windsurf");
|
|
1361
|
+
if (a) found.push(a);
|
|
1362
|
+
}
|
|
1363
|
+
return found;
|
|
1364
|
+
}
|
|
1365
|
+
async function updateCommand(options = {}) {
|
|
1366
|
+
const cwd = options.cwd ?? process.cwd();
|
|
1367
|
+
p3.intro("rn-agent-kit update");
|
|
1368
|
+
p3.log.info(
|
|
1369
|
+
"Refreshing installed skills only. User content outside rn-agent-kit markers is preserved; project source is never modified."
|
|
1370
|
+
);
|
|
1371
|
+
const skills = await loadSkills();
|
|
1372
|
+
if (skills.length === 0) {
|
|
1373
|
+
p3.cancel("No skills found in package. Aborting.");
|
|
1374
|
+
process.exitCode = 1;
|
|
1375
|
+
return [];
|
|
1376
|
+
}
|
|
1377
|
+
let selected;
|
|
1378
|
+
if (options.adapters?.length) {
|
|
1379
|
+
const missing = [];
|
|
1380
|
+
selected = [];
|
|
1381
|
+
for (const name of options.adapters) {
|
|
1382
|
+
const adapter = getAdapter(resolveToolName(name) ?? name);
|
|
1383
|
+
if (!adapter) missing.push(name);
|
|
1384
|
+
else if (!selected.some((a) => a.name === adapter.name)) selected.push(adapter);
|
|
1385
|
+
}
|
|
1386
|
+
if (missing.length) {
|
|
1387
|
+
p3.cancel(`Unknown adapter(s): ${missing.join(", ")}`);
|
|
1388
|
+
process.exitCode = 1;
|
|
1389
|
+
return [];
|
|
1390
|
+
}
|
|
1391
|
+
} else {
|
|
1392
|
+
selected = await detectPreviouslyInstalled(cwd);
|
|
1393
|
+
if (selected.length === 0) {
|
|
1394
|
+
if (options.yes) {
|
|
1395
|
+
selected = [...adapters];
|
|
1396
|
+
p3.log.warn("No previous install detected \u2014 updating all adapters (--yes).");
|
|
1397
|
+
} else {
|
|
1398
|
+
p3.cancel(
|
|
1399
|
+
"No previous install detected. Pass -a claude,cursor,\u2026 or run init first. Use --yes to update all adapters."
|
|
1400
|
+
);
|
|
1401
|
+
process.exitCode = 1;
|
|
1402
|
+
return [];
|
|
1403
|
+
}
|
|
1404
|
+
} else {
|
|
1405
|
+
p3.log.info(`Updating: ${selected.map((a) => a.name).join(", ")}`);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
const spinner3 = p3.spinner();
|
|
1409
|
+
spinner3.start("Updating skills\u2026");
|
|
1410
|
+
for (const adapter of selected) {
|
|
1411
|
+
await adapter.install(skills, cwd);
|
|
1412
|
+
}
|
|
1413
|
+
spinner3.stop(
|
|
1414
|
+
`Skills refreshed (${selected.map((a) => a.name).join(", ")}). Marker-managed files only.`
|
|
1415
|
+
);
|
|
1416
|
+
p3.outro("Update complete.");
|
|
1417
|
+
return selected;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
// src/scripts/figma-tokens.ts
|
|
1421
|
+
import { mkdir as mkdir3, writeFile as writeFile3 } from "fs/promises";
|
|
1422
|
+
import { dirname as dirname2, resolve as resolve2 } from "path";
|
|
1423
|
+
import { pathToFileURL } from "url";
|
|
1424
|
+
import { parseArgs } from "util";
|
|
1425
|
+
|
|
1426
|
+
// src/tokens/fetch-figma.ts
|
|
1427
|
+
function parseFigmaFileKey(url) {
|
|
1428
|
+
const m = /figma\.com\/(?:file|design|make|board)\/([A-Za-z0-9]+)/.exec(url);
|
|
1429
|
+
if (!m) throw new Error(`Not a Figma file URL: ${url}`);
|
|
1430
|
+
return m[1];
|
|
1431
|
+
}
|
|
1432
|
+
async function fetchFigmaSnapshot(fileUrl, token, fetchImpl = fetch) {
|
|
1433
|
+
const key = parseFigmaFileKey(fileUrl);
|
|
1434
|
+
const headers = { "X-Figma-Token": token };
|
|
1435
|
+
const get = async (path17) => {
|
|
1436
|
+
const res = await fetchImpl(`https://api.figma.com/v1${path17}`, { headers });
|
|
1437
|
+
if (!res.ok)
|
|
1438
|
+
throw Object.assign(new Error(`Figma API ${res.status} for ${path17}`), { status: res.status });
|
|
1439
|
+
return await res.json();
|
|
1440
|
+
};
|
|
1441
|
+
const notes = [];
|
|
1442
|
+
const snapshot = { source: "figma", fileUrl };
|
|
1443
|
+
try {
|
|
1444
|
+
const v = await get(`/files/${key}/variables/local`);
|
|
1445
|
+
snapshot.variables = v.meta;
|
|
1446
|
+
} catch (e) {
|
|
1447
|
+
const status = e.status;
|
|
1448
|
+
notes.push(
|
|
1449
|
+
status === 403 || status === 404 ? "Variables REST API not available (requires Figma Enterprise + file_variables:read). Use the Figma MCP path for variables." : `Variables request failed: ${e.message}`
|
|
1450
|
+
);
|
|
1451
|
+
}
|
|
1452
|
+
const styles = (await get(`/files/${key}/styles`)).meta?.styles ?? [];
|
|
1453
|
+
const nodes = {};
|
|
1454
|
+
const ids = styles.map((s) => s.node_id);
|
|
1455
|
+
for (let i = 0; i < ids.length; i += 50) {
|
|
1456
|
+
const chunk = ids.slice(i, i + 50);
|
|
1457
|
+
const res = await get(`/files/${key}/nodes?ids=${chunk.map(encodeURIComponent).join(",")}`);
|
|
1458
|
+
for (const [id, n] of Object.entries(res.nodes ?? {}))
|
|
1459
|
+
nodes[id] = n.document;
|
|
1460
|
+
}
|
|
1461
|
+
const text2 = [];
|
|
1462
|
+
const effect = [];
|
|
1463
|
+
const color = [];
|
|
1464
|
+
for (const s of styles) {
|
|
1465
|
+
const n = nodes[s.node_id];
|
|
1466
|
+
if (!n) continue;
|
|
1467
|
+
if (s.style_type === "TEXT" && n.style) {
|
|
1468
|
+
text2.push({
|
|
1469
|
+
name: s.name,
|
|
1470
|
+
description: s.description || void 0,
|
|
1471
|
+
fontFamily: n.style.fontFamily,
|
|
1472
|
+
fontWeight: n.style.fontWeight,
|
|
1473
|
+
fontSize: n.style.fontSize,
|
|
1474
|
+
lineHeightPx: n.style.lineHeightPx,
|
|
1475
|
+
letterSpacingPx: n.style.letterSpacing
|
|
1476
|
+
});
|
|
1477
|
+
} else if (s.style_type === "EFFECT" && n.effects) {
|
|
1478
|
+
effect.push({ name: s.name, description: s.description || void 0, effects: n.effects });
|
|
1479
|
+
} else if (s.style_type === "FILL") {
|
|
1480
|
+
const fill = n.fills?.find((f) => f.type === "SOLID" && f.color);
|
|
1481
|
+
if (fill?.color)
|
|
1482
|
+
color.push({
|
|
1483
|
+
name: s.name,
|
|
1484
|
+
description: s.description || void 0,
|
|
1485
|
+
color: { ...fill.color, a: (fill.color.a ?? 1) * (fill.opacity ?? 1) }
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
if (text2.length) snapshot.textStyles = text2;
|
|
1490
|
+
if (effect.length) snapshot.effectStyles = effect;
|
|
1491
|
+
if (color.length) snapshot.colorStyles = color;
|
|
1492
|
+
return { snapshot, notes };
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
// src/tokens/tree.ts
|
|
1496
|
+
var MODE_EXT = "mode";
|
|
1497
|
+
var collator = (a, b) => a.localeCompare(b, "en", { numeric: true });
|
|
1498
|
+
function isToken(node) {
|
|
1499
|
+
return typeof node === "object" && node !== null && !Array.isArray(node) && "$value" in node;
|
|
1500
|
+
}
|
|
1501
|
+
function isGroup(node) {
|
|
1502
|
+
return typeof node === "object" && node !== null && !Array.isArray(node) && !("$value" in node);
|
|
1503
|
+
}
|
|
1504
|
+
function flatten(tree) {
|
|
1505
|
+
const out = [];
|
|
1506
|
+
const walk = (node, path17, inherited) => {
|
|
1507
|
+
const groupType = node.$type ?? inherited;
|
|
1508
|
+
for (const key of Object.keys(node).sort(collator)) {
|
|
1509
|
+
if (key.startsWith("$")) continue;
|
|
1510
|
+
const child = node[key];
|
|
1511
|
+
const full = [...path17, key];
|
|
1512
|
+
if (isToken(child)) {
|
|
1513
|
+
const type = child.$type ?? groupType;
|
|
1514
|
+
if (!type)
|
|
1515
|
+
throw new Error(
|
|
1516
|
+
`Token "${full.join(".")}" has no $type (set it on the token or a parent group).`
|
|
1517
|
+
);
|
|
1518
|
+
out.push({
|
|
1519
|
+
path: full.join("."),
|
|
1520
|
+
type,
|
|
1521
|
+
value: child.$value,
|
|
1522
|
+
modes: {
|
|
1523
|
+
...child.$extensions?.[MODE_EXT] ?? {}
|
|
1524
|
+
},
|
|
1525
|
+
description: child.$description
|
|
1526
|
+
});
|
|
1527
|
+
} else if (isGroup(child)) {
|
|
1528
|
+
walk(child, full, groupType);
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
};
|
|
1532
|
+
walk(tree, []);
|
|
1533
|
+
return out;
|
|
1534
|
+
}
|
|
1535
|
+
function setToken(tree, path17, token) {
|
|
1536
|
+
let node = tree;
|
|
1537
|
+
for (const seg of path17.slice(0, -1)) {
|
|
1538
|
+
const next = node[seg];
|
|
1539
|
+
if (next === void 0) {
|
|
1540
|
+
const created = {};
|
|
1541
|
+
node[seg] = created;
|
|
1542
|
+
node = created;
|
|
1543
|
+
} else if (isGroup(next)) {
|
|
1544
|
+
node = next;
|
|
1545
|
+
} else {
|
|
1546
|
+
return false;
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
const leaf = path17[path17.length - 1];
|
|
1550
|
+
if (node[leaf] !== void 0) return false;
|
|
1551
|
+
node[leaf] = token;
|
|
1552
|
+
return true;
|
|
1553
|
+
}
|
|
1554
|
+
function sortNode(node) {
|
|
1555
|
+
if (Array.isArray(node)) return node.map(sortNode);
|
|
1556
|
+
if (typeof node !== "object" || node === null) return node;
|
|
1557
|
+
const rec2 = node;
|
|
1558
|
+
const keys = Object.keys(rec2).sort((a, b) => {
|
|
1559
|
+
const da = a.startsWith("$") ? 0 : 1;
|
|
1560
|
+
const db = b.startsWith("$") ? 0 : 1;
|
|
1561
|
+
return da !== db ? da - db : collator(a, b);
|
|
1562
|
+
});
|
|
1563
|
+
const out = {};
|
|
1564
|
+
for (const k of keys) out[k] = sortNode(rec2[k]);
|
|
1565
|
+
return out;
|
|
1566
|
+
}
|
|
1567
|
+
function serializeTree(tree) {
|
|
1568
|
+
return `${JSON.stringify(sortNode(tree), null, 2)}
|
|
1569
|
+
`;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
// src/tokens/diff.ts
|
|
1573
|
+
var show = (t) => JSON.stringify(t.value) + (Object.keys(t.modes).length ? ` (modes: ${JSON.stringify(t.modes)})` : "");
|
|
1574
|
+
function diffTokens(prev, next) {
|
|
1575
|
+
const nextFlat = new Map(flatten(next).map((t) => [t.path, t]));
|
|
1576
|
+
if (!prev) return { initial: true, added: [...nextFlat.keys()], removed: [], changed: [] };
|
|
1577
|
+
const prevFlat = new Map(flatten(prev).map((t) => [t.path, t]));
|
|
1578
|
+
const added = [...nextFlat.keys()].filter((p4) => !prevFlat.has(p4));
|
|
1579
|
+
const removed = [...prevFlat.keys()].filter((p4) => !nextFlat.has(p4));
|
|
1580
|
+
const changed = [];
|
|
1581
|
+
for (const [path17, n] of nextFlat) {
|
|
1582
|
+
const p4 = prevFlat.get(path17);
|
|
1583
|
+
if (p4 && (show(p4) !== show(n) || p4.type !== n.type))
|
|
1584
|
+
changed.push({ path: path17, before: show(p4), after: show(n) });
|
|
1585
|
+
}
|
|
1586
|
+
return { initial: false, added, removed, changed };
|
|
1587
|
+
}
|
|
1588
|
+
var diffIsEmpty = (d) => !d.initial && !d.added.length && !d.removed.length && !d.changed.length;
|
|
1589
|
+
|
|
1590
|
+
// src/tokens/pipeline.ts
|
|
1591
|
+
import { mkdir as mkdir2, readFile as readFile6, writeFile as writeFile2 } from "fs/promises";
|
|
1592
|
+
import { dirname, resolve } from "path";
|
|
1593
|
+
|
|
1594
|
+
// src/tokens/generate-theme.ts
|
|
1595
|
+
import { createHash } from "crypto";
|
|
1596
|
+
|
|
1597
|
+
// src/tokens/names.ts
|
|
1598
|
+
function slug(input) {
|
|
1599
|
+
const s = input.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
1600
|
+
return s === "" ? "_" : s;
|
|
1601
|
+
}
|
|
1602
|
+
function splitName(name) {
|
|
1603
|
+
return name.split("/").map((p4) => p4.trim()).filter(Boolean).map(slug);
|
|
1604
|
+
}
|
|
1605
|
+
function toThemeKey(seg) {
|
|
1606
|
+
return /^\d+$/.test(seg) ? seg : seg.replace(/-([a-z0-9])/g, (_m, c) => c.toUpperCase());
|
|
1607
|
+
}
|
|
1608
|
+
function round(n, digits = 2) {
|
|
1609
|
+
const f = 10 ** digits;
|
|
1610
|
+
return Math.round(n * f) / f;
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
// src/tokens/color.ts
|
|
1614
|
+
var byte = (n) => Math.round(Math.min(1, Math.max(0, n)) * 255).toString(16).padStart(2, "0");
|
|
1615
|
+
function figmaColorToHex(c) {
|
|
1616
|
+
const base = `#${byte(c.r)}${byte(c.g)}${byte(c.b)}`;
|
|
1617
|
+
const a = c.a ?? 1;
|
|
1618
|
+
return a >= 0.999 ? base : base + byte(a);
|
|
1619
|
+
}
|
|
1620
|
+
function normalizeHex(input) {
|
|
1621
|
+
const m = /^#([0-9a-f]{3,8})$/i.exec(input.trim());
|
|
1622
|
+
if (!m) return null;
|
|
1623
|
+
let h = m[1].toLowerCase();
|
|
1624
|
+
if (h.length === 3 || h.length === 4) h = [...h].map((c) => c + c).join("");
|
|
1625
|
+
if (h.length !== 6 && h.length !== 8) return null;
|
|
1626
|
+
return `#${h}`;
|
|
1627
|
+
}
|
|
1628
|
+
function cssColorToHex(input) {
|
|
1629
|
+
const hex = normalizeHex(input);
|
|
1630
|
+
if (hex) return hex;
|
|
1631
|
+
const m = /^rgba?\(\s*([\d.]+)\s*[, ]\s*([\d.]+)\s*[, ]\s*([\d.]+)\s*(?:[,/]\s*([\d.]+)(%?))?\s*\)$/i.exec(
|
|
1632
|
+
input.trim()
|
|
1633
|
+
);
|
|
1634
|
+
if (!m) return null;
|
|
1635
|
+
const a = m[4] === void 0 ? 1 : m[5] === "%" ? Number(m[4]) / 100 : Number(m[4]);
|
|
1636
|
+
return figmaColorToHex({
|
|
1637
|
+
r: Number(m[1]) / 255,
|
|
1638
|
+
g: Number(m[2]) / 255,
|
|
1639
|
+
b: Number(m[3]) / 255,
|
|
1640
|
+
a
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
function splitAlpha(hex) {
|
|
1644
|
+
if (hex.length === 9)
|
|
1645
|
+
return { rgb: hex.slice(0, 7), alpha: round(parseInt(hex.slice(7, 9), 16) / 255, 2) };
|
|
1646
|
+
return { rgb: hex.slice(0, 7), alpha: 1 };
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
// src/tokens/transform.ts
|
|
1650
|
+
var TokenError = class extends Error {
|
|
1651
|
+
};
|
|
1652
|
+
var ALIAS_RE = /^\{([^{}]+)\}$/;
|
|
1653
|
+
var ROOT_KEYS = {
|
|
1654
|
+
color: "colors",
|
|
1655
|
+
shadow: "shadows",
|
|
1656
|
+
"font-family": "fontFamilies",
|
|
1657
|
+
"font-size": "fontSizes",
|
|
1658
|
+
"line-height": "lineHeights",
|
|
1659
|
+
"font-weight": "fontWeights"
|
|
1660
|
+
};
|
|
1661
|
+
function resolveDeep(value, mode, index, stack) {
|
|
1662
|
+
if (typeof value === "string") {
|
|
1663
|
+
const m = ALIAS_RE.exec(value);
|
|
1664
|
+
if (!m) return value;
|
|
1665
|
+
const target = m[1];
|
|
1666
|
+
if (stack.includes(target))
|
|
1667
|
+
throw new TokenError(`Circular alias: ${[...stack, target].join(" -> ")}`);
|
|
1668
|
+
const t = index.get(target);
|
|
1669
|
+
if (!t) throw new TokenError(`Unresolved alias {${target}} referenced from "${stack[0]}"`);
|
|
1670
|
+
const next = mode === "dark" && "dark" in t.modes ? t.modes.dark : t.value;
|
|
1671
|
+
return resolveDeep(next, mode, index, [...stack, target]);
|
|
1672
|
+
}
|
|
1673
|
+
if (Array.isArray(value)) return value.map((v) => resolveDeep(v, mode, index, stack));
|
|
1674
|
+
if (typeof value === "object" && value !== null) {
|
|
1675
|
+
return Object.fromEntries(
|
|
1676
|
+
Object.entries(value).map(([k, v]) => [k, resolveDeep(v, mode, index, stack)])
|
|
1677
|
+
);
|
|
1678
|
+
}
|
|
1679
|
+
return value;
|
|
1680
|
+
}
|
|
1681
|
+
function px(v, path17) {
|
|
1682
|
+
if (typeof v === "number") return v;
|
|
1683
|
+
if (typeof v === "string") {
|
|
1684
|
+
const m = /^(-?[\d.]+)\s*(px|rem|em)?$/.exec(v.trim());
|
|
1685
|
+
if (m) return round(Number(m[1]) * (m[2] === "rem" || m[2] === "em" ? 16 : 1), 4);
|
|
1686
|
+
}
|
|
1687
|
+
throw new TokenError(`"${path17}": expected a dimension like "16px", got ${JSON.stringify(v)}`);
|
|
1688
|
+
}
|
|
1689
|
+
function rec(v, path17) {
|
|
1690
|
+
if (typeof v === "object" && v !== null && !Array.isArray(v)) return v;
|
|
1691
|
+
throw new TokenError(`"${path17}": expected an object value`);
|
|
1692
|
+
}
|
|
1693
|
+
function family(v, path17) {
|
|
1694
|
+
const f = Array.isArray(v) ? v[0] : v;
|
|
1695
|
+
if (typeof f !== "string" || !f) throw new TokenError(`"${path17}": expected a font family string`);
|
|
1696
|
+
return f;
|
|
1697
|
+
}
|
|
1698
|
+
function convertLeaf(type, v, path17, warnings) {
|
|
1699
|
+
switch (type) {
|
|
1700
|
+
case "color": {
|
|
1701
|
+
if (typeof v !== "string" || !/^#([0-9a-f]{6}|[0-9a-f]{8})$/i.test(v))
|
|
1702
|
+
throw new TokenError(`"${path17}": expected a #rrggbb[aa] color, got ${JSON.stringify(v)}`);
|
|
1703
|
+
return v.toLowerCase();
|
|
1704
|
+
}
|
|
1705
|
+
case "dimension":
|
|
1706
|
+
return px(v, path17);
|
|
1707
|
+
case "number":
|
|
1708
|
+
if (typeof v !== "number") throw new TokenError(`"${path17}": expected a number`);
|
|
1709
|
+
return v;
|
|
1710
|
+
case "fontWeight": {
|
|
1711
|
+
const n = Number(v);
|
|
1712
|
+
if (!Number.isFinite(n)) throw new TokenError(`"${path17}": expected a numeric font weight`);
|
|
1713
|
+
return String(n);
|
|
1714
|
+
}
|
|
1715
|
+
case "fontFamily":
|
|
1716
|
+
return family(v, path17);
|
|
1717
|
+
case "duration": {
|
|
1718
|
+
const m = /^([\d.]+)\s*(ms|s)?$/.exec(String(v));
|
|
1719
|
+
if (!m) throw new TokenError(`"${path17}": expected a duration like "200ms"`);
|
|
1720
|
+
return round(Number(m[1]) * (m[2] === "s" ? 1e3 : 1), 2);
|
|
1721
|
+
}
|
|
1722
|
+
case "cubicBezier":
|
|
1723
|
+
if (!Array.isArray(v) || v.length !== 4)
|
|
1724
|
+
throw new TokenError(`"${path17}": expected 4 numbers`);
|
|
1725
|
+
return v.map(Number);
|
|
1726
|
+
case "shadow": {
|
|
1727
|
+
const layers = Array.isArray(v) ? v : [v];
|
|
1728
|
+
if (layers.length > 1)
|
|
1729
|
+
warnings.push(
|
|
1730
|
+
`"${path17}" has ${layers.length} shadow layers; React Native supports one, using the first.`
|
|
1731
|
+
);
|
|
1732
|
+
const s = rec(layers[0], path17);
|
|
1733
|
+
const color = String(s.color);
|
|
1734
|
+
if (!/^#([0-9a-f]{6}|[0-9a-f]{8})$/i.test(color))
|
|
1735
|
+
throw new TokenError(`"${path17}": shadow.color must be hex`);
|
|
1736
|
+
const { rgb, alpha } = splitAlpha(color.toLowerCase());
|
|
1737
|
+
const blur = px(s.blur ?? 0, path17);
|
|
1738
|
+
return {
|
|
1739
|
+
shadowColor: rgb,
|
|
1740
|
+
shadowOffset: { width: px(s.offsetX ?? 0, path17), height: px(s.offsetY ?? 0, path17) },
|
|
1741
|
+
shadowOpacity: alpha,
|
|
1742
|
+
shadowRadius: round(blur / 2, 2),
|
|
1743
|
+
elevation: Math.round(blur / 2)
|
|
1744
|
+
};
|
|
1745
|
+
}
|
|
1746
|
+
case "typography": {
|
|
1747
|
+
const t = rec(v, path17);
|
|
1748
|
+
const fontSize = px(t.fontSize, `${path17}.fontSize`);
|
|
1749
|
+
const out = {
|
|
1750
|
+
fontFamily: family(t.fontFamily, `${path17}.fontFamily`),
|
|
1751
|
+
fontSize,
|
|
1752
|
+
fontWeight: String(Number(t.fontWeight ?? 400))
|
|
1753
|
+
};
|
|
1754
|
+
if (t.lineHeight !== void 0) {
|
|
1755
|
+
out.lineHeight = typeof t.lineHeight === "number" ? round(fontSize * t.lineHeight, 2) : px(t.lineHeight, `${path17}.lineHeight`);
|
|
1756
|
+
}
|
|
1757
|
+
if (t.letterSpacing !== void 0)
|
|
1758
|
+
out.letterSpacing = px(t.letterSpacing, `${path17}.letterSpacing`);
|
|
1759
|
+
return out;
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
function setNested(tree, keys, value, path17) {
|
|
1764
|
+
let node = tree;
|
|
1765
|
+
for (const k of keys.slice(0, -1)) {
|
|
1766
|
+
const next = node[k];
|
|
1767
|
+
if (next === void 0) {
|
|
1768
|
+
const created = {};
|
|
1769
|
+
node[k] = created;
|
|
1770
|
+
node = created;
|
|
1771
|
+
} else if (typeof next === "object" && !Array.isArray(next)) {
|
|
1772
|
+
node = next;
|
|
1773
|
+
} else {
|
|
1774
|
+
throw new TokenError(`"${path17}": path conflicts with the value at "${k}"`);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
const leaf = keys[keys.length - 1];
|
|
1778
|
+
if (node[leaf] !== void 0)
|
|
1779
|
+
throw new TokenError(
|
|
1780
|
+
`"${path17}": duplicate theme key "${keys.join(".")}" after camelCase conversion`
|
|
1781
|
+
);
|
|
1782
|
+
node[leaf] = value;
|
|
1783
|
+
}
|
|
1784
|
+
var PREFIX_KEYS = {
|
|
1785
|
+
"font.family": "fontFamilies",
|
|
1786
|
+
"font.size": "fontSizes",
|
|
1787
|
+
"font.weight": "fontWeights",
|
|
1788
|
+
"line.height": "lineHeights"
|
|
1789
|
+
};
|
|
1790
|
+
function themeKeys(path17) {
|
|
1791
|
+
const segs = path17.split(".");
|
|
1792
|
+
const prefix = PREFIX_KEYS[segs.slice(0, 2).join(".")];
|
|
1793
|
+
if (prefix && segs.length > 2) return [prefix, ...segs.slice(2).map(toThemeKey)];
|
|
1794
|
+
const [root, ...rest] = segs;
|
|
1795
|
+
return [ROOT_KEYS[root] ?? toThemeKey(root), ...rest.map(toThemeKey)];
|
|
1796
|
+
}
|
|
1797
|
+
function buildThemes(tree) {
|
|
1798
|
+
const flat = flatten(tree);
|
|
1799
|
+
const index = new Map(flat.map((t) => [t.path, t]));
|
|
1800
|
+
const warnings = [];
|
|
1801
|
+
const themes = { light: {}, dark: {} };
|
|
1802
|
+
for (const mode of ["light", "dark"]) {
|
|
1803
|
+
for (const t of flat) {
|
|
1804
|
+
const raw = mode === "dark" && "dark" in t.modes ? t.modes.dark : t.value;
|
|
1805
|
+
const resolved = resolveDeep(raw, mode, index, [t.path]);
|
|
1806
|
+
const leaf = convertLeaf(t.type, resolved, t.path, mode === "light" ? warnings : []);
|
|
1807
|
+
setNested(themes[mode], themeKeys(t.path), leaf, t.path);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
return { ...themes, hasDark: flat.some((t) => "dark" in t.modes), warnings };
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
// src/tokens/generate-theme.ts
|
|
1814
|
+
var IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
1815
|
+
function print(node, indent) {
|
|
1816
|
+
const pad = " ".repeat(indent);
|
|
1817
|
+
if (Array.isArray(node)) return `[${node.join(", ")}]`;
|
|
1818
|
+
if (typeof node === "object") {
|
|
1819
|
+
const entries = Object.entries(node);
|
|
1820
|
+
if (!entries.length) return "{}";
|
|
1821
|
+
const lines = entries.map(
|
|
1822
|
+
([k, v]) => `${pad} ${IDENT.test(k) ? k : JSON.stringify(k)}: ${print(v, indent + 1)},`
|
|
1823
|
+
);
|
|
1824
|
+
return `{
|
|
1825
|
+
${lines.join("\n")}
|
|
1826
|
+
${pad}}`;
|
|
1827
|
+
}
|
|
1828
|
+
return JSON.stringify(node);
|
|
1829
|
+
}
|
|
1830
|
+
var hashOf = (text2) => createHash("sha256").update(text2).digest("hex").slice(0, 12);
|
|
1831
|
+
function renderTokensTs(themes, hash) {
|
|
1832
|
+
return `/* eslint-disable */
|
|
1833
|
+
// @generated by rn-agent-kit (figma-to-tokens). DO NOT EDIT BY HAND.
|
|
1834
|
+
// Source: design/tokens.json (sha256:${hash})
|
|
1835
|
+
// Regenerate: npx rn-agent-kit tokens generate
|
|
1836
|
+
import type { TextStyle } from 'react-native';
|
|
1837
|
+
|
|
1838
|
+
export const lightTheme = ${print(themes.light, 0)} as const;
|
|
1839
|
+
|
|
1840
|
+
type Widen<T> = T extends string
|
|
1841
|
+
? string
|
|
1842
|
+
: T extends number
|
|
1843
|
+
? number
|
|
1844
|
+
: T extends boolean
|
|
1845
|
+
? boolean
|
|
1846
|
+
: T extends readonly unknown[]
|
|
1847
|
+
? { -readonly [K in keyof T]: Widen<T[K]> }
|
|
1848
|
+
: { -readonly [K in keyof T]: K extends 'fontWeight' ? NonNullable<TextStyle['fontWeight']> : Widen<T[K]> };
|
|
1849
|
+
|
|
1850
|
+
/** Shape shared by every theme. A missing/extra key in darkTheme is a compile error. */
|
|
1851
|
+
export type Theme = Widen<typeof lightTheme>;
|
|
1852
|
+
|
|
1853
|
+
${themes.hasDark ? `export const darkTheme: Theme = ${print(themes.dark, 0)};` : `// No dark values found in design/tokens.json; dark mirrors light until a Dark mode exists.
|
|
1854
|
+
export const darkTheme: Theme = lightTheme;`}
|
|
1855
|
+
|
|
1856
|
+
export const themes = { light: lightTheme, dark: darkTheme } as const;
|
|
1857
|
+
export type ThemeName = keyof typeof themes;
|
|
1858
|
+
`;
|
|
1859
|
+
}
|
|
1860
|
+
function generateFromTokensJson(tokensJsonText) {
|
|
1861
|
+
const tree = JSON.parse(tokensJsonText);
|
|
1862
|
+
const built = buildThemes(tree);
|
|
1863
|
+
return { ts: renderTokensTs(built, hashOf(tokensJsonText)), warnings: built.warnings };
|
|
1864
|
+
}
|
|
1865
|
+
var THEME_PROVIDER_TSX = `import React, { createContext, useContext, useMemo, type ReactNode } from 'react';
|
|
1866
|
+
import { useColorScheme } from 'react-native';
|
|
1867
|
+
import { themes, type Theme, type ThemeName } from './tokens';
|
|
1868
|
+
|
|
1869
|
+
interface ThemeContextValue {
|
|
1870
|
+
theme: Theme;
|
|
1871
|
+
name: ThemeName;
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
const ThemeContext = createContext<ThemeContextValue>({ theme: themes.light, name: 'light' });
|
|
1875
|
+
|
|
1876
|
+
export function ThemeProvider({ children, forcedTheme }: { children: ReactNode; forcedTheme?: ThemeName }) {
|
|
1877
|
+
const scheme = useColorScheme();
|
|
1878
|
+
const name: ThemeName = forcedTheme ?? (scheme === 'dark' ? 'dark' : 'light');
|
|
1879
|
+
const value = useMemo(() => ({ theme: themes[name], name }), [name]);
|
|
1880
|
+
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
/** The only way components should read colors, spacing, radius, typography and shadows. */
|
|
1884
|
+
export const useTheme = () => useContext(ThemeContext);
|
|
1885
|
+
`;
|
|
1886
|
+
|
|
1887
|
+
// src/tokens/normalize-figma.ts
|
|
1888
|
+
var UNNAMED_RE = /^(color|colour|fill|stroke|untitled|rectangle|frame|group|style|variable|paint|text|effect)[\s_-]*\d*$/i;
|
|
1889
|
+
var HEXISH_RE = /^(#[0-9a-f]{3,8}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
1890
|
+
var WEIGHTS = {
|
|
1891
|
+
thin: 100,
|
|
1892
|
+
extralight: 200,
|
|
1893
|
+
ultralight: 200,
|
|
1894
|
+
light: 300,
|
|
1895
|
+
regular: 400,
|
|
1896
|
+
normal: 400,
|
|
1897
|
+
book: 400,
|
|
1898
|
+
medium: 500,
|
|
1899
|
+
semibold: 600,
|
|
1900
|
+
demibold: 600,
|
|
1901
|
+
bold: 700,
|
|
1902
|
+
extrabold: 800,
|
|
1903
|
+
ultrabold: 800,
|
|
1904
|
+
black: 900,
|
|
1905
|
+
heavy: 900
|
|
1906
|
+
};
|
|
1907
|
+
function weightFromStyleName(style) {
|
|
1908
|
+
if (!style) return void 0;
|
|
1909
|
+
const key = style.toLowerCase().replace(/italic|oblique|[\s_-]/g, "");
|
|
1910
|
+
return key === "" ? 400 : WEIGHTS[key];
|
|
1911
|
+
}
|
|
1912
|
+
function put(ctx, path17, token) {
|
|
1913
|
+
if (setToken(ctx.tree, path17, token)) return true;
|
|
1914
|
+
ctx.issues.push({
|
|
1915
|
+
severity: "error",
|
|
1916
|
+
code: "name-collision",
|
|
1917
|
+
token: path17.join("."),
|
|
1918
|
+
message: `"${path17.join(".")}" collides with another token or group after name normalization; this one was skipped.`,
|
|
1919
|
+
fix: 'Give the two variables/styles distinct names (names are lower-cased and non-alphanumerics become "-").'
|
|
1920
|
+
});
|
|
1921
|
+
return false;
|
|
1922
|
+
}
|
|
1923
|
+
function checkColorName(raw, ctx, tokenPath, requireGroup = true) {
|
|
1924
|
+
const name = raw.trim();
|
|
1925
|
+
if (UNNAMED_RE.test(name) || HEXISH_RE.test(name)) {
|
|
1926
|
+
ctx.issues.push({
|
|
1927
|
+
severity: "warning",
|
|
1928
|
+
code: "unnamed-token",
|
|
1929
|
+
token: tokenPath,
|
|
1930
|
+
message: `Color "${raw}" has a placeholder/unnamed name, so it cannot carry meaning in code.`,
|
|
1931
|
+
fix: 'Rename it in Figma to a semantic path, e.g. "color/brand/primary" or "color/text/muted".'
|
|
1932
|
+
});
|
|
1933
|
+
} else if (requireGroup && !name.includes("/")) {
|
|
1934
|
+
ctx.issues.push({
|
|
1935
|
+
severity: "info",
|
|
1936
|
+
code: "ungrouped-token",
|
|
1937
|
+
token: tokenPath,
|
|
1938
|
+
message: `Color "${raw}" is not inside a group (no "/" in its name).`,
|
|
1939
|
+
fix: 'Prefix it with a group, e.g. "color/neutral/white".'
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
function inferNumberType(name) {
|
|
1944
|
+
const n = name.toLowerCase();
|
|
1945
|
+
if (/(^|\/)(opacity|alpha)($|\/|-)/.test(n)) return "number";
|
|
1946
|
+
if (/weight/.test(n)) return "fontWeight";
|
|
1947
|
+
if (/(duration|delay|time)/.test(n)) return "duration";
|
|
1948
|
+
if (/(space|spacing|gap|padding|margin|size|radius|radii|rounded|stroke|border|width|height|font|line-height|letter)/.test(
|
|
1949
|
+
n
|
|
1950
|
+
))
|
|
1951
|
+
return "dimension";
|
|
1952
|
+
return null;
|
|
1953
|
+
}
|
|
1954
|
+
function colorPath(name) {
|
|
1955
|
+
const segs = splitName(name);
|
|
1956
|
+
if (["color", "colors", "colour", "colours"].includes(segs[0]))
|
|
1957
|
+
return ["color", ...segs.slice(1)];
|
|
1958
|
+
return ["color", ...segs];
|
|
1959
|
+
}
|
|
1960
|
+
function modeRoles(c) {
|
|
1961
|
+
const find = (re, exclude) => c.modes.find((m) => re.test(m.name) && m.modeId !== exclude)?.modeId;
|
|
1962
|
+
const base = find(/light/i) ?? c.defaultModeId;
|
|
1963
|
+
const dark = find(/dark/i, base);
|
|
1964
|
+
const ignored = c.modes.filter((m) => m.modeId !== base && m.modeId !== dark).map((m) => m.name);
|
|
1965
|
+
return { base, dark, ignored };
|
|
1966
|
+
}
|
|
1967
|
+
function isAlias(v) {
|
|
1968
|
+
return typeof v === "object" && v !== null && "type" in v && v.type === "VARIABLE_ALIAS";
|
|
1969
|
+
}
|
|
1970
|
+
function normalizeVariables(meta, ctx) {
|
|
1971
|
+
const vars = Object.values(meta.variables).sort(
|
|
1972
|
+
(a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id)
|
|
1973
|
+
);
|
|
1974
|
+
const pathOf = new Map(
|
|
1975
|
+
vars.map((v) => [v.id, v.resolvedType === "COLOR" ? colorPath(v.name) : splitName(v.name)])
|
|
1976
|
+
);
|
|
1977
|
+
const reportedModes = /* @__PURE__ */ new Set();
|
|
1978
|
+
const convert = (value, type, v, tokenPath) => {
|
|
1979
|
+
if (value === void 0) return void 0;
|
|
1980
|
+
if (isAlias(value)) {
|
|
1981
|
+
const target = pathOf.get(value.id);
|
|
1982
|
+
if (!target) {
|
|
1983
|
+
ctx.issues.push({
|
|
1984
|
+
severity: "error",
|
|
1985
|
+
code: "unresolved-alias",
|
|
1986
|
+
token: tokenPath,
|
|
1987
|
+
message: `"${v.name}" aliases a variable that is not in this file (likely from an external library).`,
|
|
1988
|
+
fix: "Publish/enable the library and re-run, or detach the alias in Figma so the variable has its own value."
|
|
1989
|
+
});
|
|
1990
|
+
return void 0;
|
|
1991
|
+
}
|
|
1992
|
+
return `{${target.join(".")}}`;
|
|
1993
|
+
}
|
|
1994
|
+
switch (type) {
|
|
1995
|
+
case "color":
|
|
1996
|
+
return typeof value === "object" && "r" in value ? figmaColorToHex(value) : void 0;
|
|
1997
|
+
case "dimension":
|
|
1998
|
+
return typeof value === "number" ? `${round(value)}px` : void 0;
|
|
1999
|
+
case "duration":
|
|
2000
|
+
return typeof value === "number" ? `${round(value)}ms` : void 0;
|
|
2001
|
+
case "number":
|
|
2002
|
+
case "fontWeight":
|
|
2003
|
+
return typeof value === "number" ? value : void 0;
|
|
2004
|
+
case "fontFamily":
|
|
2005
|
+
return typeof value === "string" ? value : void 0;
|
|
2006
|
+
default:
|
|
2007
|
+
return void 0;
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
for (const v of vars) {
|
|
2011
|
+
const col = meta.variableCollections[v.variableCollectionId];
|
|
2012
|
+
if (!col) continue;
|
|
2013
|
+
const path17 = pathOf.get(v.id) ?? [];
|
|
2014
|
+
const tokenPath = path17.join(".");
|
|
2015
|
+
let type = null;
|
|
2016
|
+
if (v.resolvedType === "COLOR") type = "color";
|
|
2017
|
+
else if (v.resolvedType === "FLOAT") {
|
|
2018
|
+
type = inferNumberType(v.name);
|
|
2019
|
+
if (!type) {
|
|
2020
|
+
type = "number";
|
|
2021
|
+
ctx.issues.push({
|
|
2022
|
+
severity: "info",
|
|
2023
|
+
code: "ambiguous-type",
|
|
2024
|
+
token: tokenPath,
|
|
2025
|
+
message: `Number "${v.name}" has no unit hint in its name; exported as a plain number.`,
|
|
2026
|
+
fix: 'Rename with a category, e.g. "spacing/md", "radius/lg", "opacity/disabled", "font-size/body".'
|
|
2027
|
+
});
|
|
2028
|
+
}
|
|
2029
|
+
} else if (v.resolvedType === "STRING") {
|
|
2030
|
+
type = /font|family|typeface/i.test(v.name) ? "fontFamily" : null;
|
|
2031
|
+
}
|
|
2032
|
+
if (!type) {
|
|
2033
|
+
ctx.issues.push({
|
|
2034
|
+
severity: "info",
|
|
2035
|
+
code: "unsupported-type",
|
|
2036
|
+
token: tokenPath,
|
|
2037
|
+
message: `Variable "${v.name}" (${v.resolvedType}) is not exportable as a design token and was skipped.`,
|
|
2038
|
+
fix: 'Only COLOR, FLOAT and font-family STRING variables are exported. Rename string variables with "font-family" if they are fonts.'
|
|
2039
|
+
});
|
|
2040
|
+
continue;
|
|
2041
|
+
}
|
|
2042
|
+
if (type === "color") checkColorName(v.name, ctx, tokenPath);
|
|
2043
|
+
const roles = modeRoles(col);
|
|
2044
|
+
if (roles.ignored.length && !reportedModes.has(col.id)) {
|
|
2045
|
+
reportedModes.add(col.id);
|
|
2046
|
+
ctx.issues.push({
|
|
2047
|
+
severity: "info",
|
|
2048
|
+
code: "ignored-mode",
|
|
2049
|
+
token: col.name,
|
|
2050
|
+
message: `Collection "${col.name}" has extra modes that are ignored: ${roles.ignored.join(", ")}.`,
|
|
2051
|
+
fix: 'Only "Light"/default and "Dark" modes are exported. Rename modes accordingly if they should be included.'
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
const base = convert(v.valuesByMode[roles.base], type, v, tokenPath);
|
|
2055
|
+
if (base === void 0) continue;
|
|
2056
|
+
const token = { $type: type, $value: base };
|
|
2057
|
+
if (v.description) token.$description = v.description;
|
|
2058
|
+
if (roles.dark) {
|
|
2059
|
+
const dark = convert(v.valuesByMode[roles.dark], type, v, tokenPath);
|
|
2060
|
+
if (dark !== void 0 && JSON.stringify(dark) !== JSON.stringify(base))
|
|
2061
|
+
token.$extensions = { mode: { dark } };
|
|
2062
|
+
}
|
|
2063
|
+
put(ctx, path17, token);
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
function normalizeFlat(light, dark, ctx) {
|
|
2067
|
+
const parse = (name, val) => {
|
|
2068
|
+
if (typeof val === "number") {
|
|
2069
|
+
const type = inferNumberType(name) ?? "number";
|
|
2070
|
+
if (type === "dimension") return { type, value: `${round(val)}px` };
|
|
2071
|
+
if (type === "duration") return { type, value: `${round(val)}ms` };
|
|
2072
|
+
return { type, value: val };
|
|
2073
|
+
}
|
|
2074
|
+
const color = cssColorToHex(val);
|
|
2075
|
+
if (color) return { type: "color", value: color };
|
|
2076
|
+
if (/^Font\(/i.test(val)) {
|
|
2077
|
+
const family2 = /family:\s*"([^"]+)"/.exec(val)?.[1];
|
|
2078
|
+
const size = Number(/size:\s*([\d.]+)/.exec(val)?.[1]);
|
|
2079
|
+
if (!family2 || !size) return null;
|
|
2080
|
+
const weight = Number(/weight:\s*(\d+)/.exec(val)?.[1]) || weightFromStyleName(/style:\s*([A-Za-z ]+)/.exec(val)?.[1]) || 400;
|
|
2081
|
+
const lh = Number(/lineHeight:\s*([\d.]+)/.exec(val)?.[1]);
|
|
2082
|
+
const ls = Number(/letterSpacing:\s*(-?[\d.]+)/.exec(val)?.[1]);
|
|
2083
|
+
const value = {
|
|
2084
|
+
fontFamily: family2,
|
|
2085
|
+
fontSize: `${size}px`,
|
|
2086
|
+
fontWeight: weight
|
|
2087
|
+
};
|
|
2088
|
+
if (lh) value.lineHeight = round(lh / size, 4);
|
|
2089
|
+
if (ls) value.letterSpacing = `${round(ls)}px`;
|
|
2090
|
+
return { type: "typography", value };
|
|
2091
|
+
}
|
|
2092
|
+
if (/^\d+(\.\d+)?$/.test(val.trim()) === false && /font|family/i.test(name))
|
|
2093
|
+
return { type: "fontFamily", value: val };
|
|
2094
|
+
return null;
|
|
2095
|
+
};
|
|
2096
|
+
for (const name of Object.keys(light).sort()) {
|
|
2097
|
+
const parsed = parse(name, light[name]);
|
|
2098
|
+
const path17 = parsed?.type === "color" ? colorPath(name) : splitName(name);
|
|
2099
|
+
const tokenPath = path17.join(".");
|
|
2100
|
+
if (!parsed) {
|
|
2101
|
+
ctx.issues.push({
|
|
2102
|
+
severity: "info",
|
|
2103
|
+
code: "invalid-value",
|
|
2104
|
+
token: tokenPath,
|
|
2105
|
+
message: `Value of "${name}" could not be interpreted (${JSON.stringify(light[name])}); skipped.`,
|
|
2106
|
+
fix: "Check the variable type in Figma, or provide full variables via the REST API / agent snapshot."
|
|
2107
|
+
});
|
|
2108
|
+
continue;
|
|
2109
|
+
}
|
|
2110
|
+
if (parsed.type === "color") checkColorName(name, ctx, tokenPath);
|
|
2111
|
+
const token = { $type: parsed.type, $value: parsed.value };
|
|
2112
|
+
const darkRaw = dark?.[name];
|
|
2113
|
+
if (darkRaw !== void 0) {
|
|
2114
|
+
const d = parse(name, darkRaw);
|
|
2115
|
+
if (d && JSON.stringify(d.value) !== JSON.stringify(parsed.value))
|
|
2116
|
+
token.$extensions = { mode: { dark: d.value } };
|
|
2117
|
+
}
|
|
2118
|
+
put(ctx, path17, token);
|
|
2119
|
+
}
|
|
2120
|
+
if (!dark) {
|
|
2121
|
+
ctx.issues.push({
|
|
2122
|
+
severity: "info",
|
|
2123
|
+
code: "single-mode-source",
|
|
2124
|
+
message: "Variables came from a single-mode source (MCP get_variable_defs); no dark values were captured.",
|
|
2125
|
+
fix: 'Put a frame in Dark mode, run get_variable_defs on it and store the result as "flatVariablesDark" (or use the Variables REST API on Enterprise).'
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
function stripRoot(path17, roots) {
|
|
2130
|
+
return path17.length > 1 && roots.includes(path17[0]) ? path17.slice(1) : path17;
|
|
2131
|
+
}
|
|
2132
|
+
function normalizeColorStyles(styles, ctx) {
|
|
2133
|
+
for (const s of [...styles].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2134
|
+
const path17 = ["color", ...stripRoot(splitName(s.name), ["color", "colour"])];
|
|
2135
|
+
const tokenPath = path17.join(".");
|
|
2136
|
+
checkColorName(s.name, ctx, tokenPath);
|
|
2137
|
+
const token = { $type: "color", $value: figmaColorToHex(s.color) };
|
|
2138
|
+
if (s.description) token.$description = s.description;
|
|
2139
|
+
if (put(ctx, path17, token)) {
|
|
2140
|
+
ctx.issues.push({
|
|
2141
|
+
severity: "info",
|
|
2142
|
+
code: "style-without-variable",
|
|
2143
|
+
token: tokenPath,
|
|
2144
|
+
message: `Color style "${s.name}" is not backed by a variable, so it has no light/dark values.`,
|
|
2145
|
+
fix: "Convert it to a Figma variable (with Light/Dark modes) to get dark-mode support."
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
function normalizeTextStyles(styles, ctx) {
|
|
2151
|
+
for (const s of [...styles].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2152
|
+
const path17 = ["typography", ...stripRoot(splitName(s.name), ["typography", "text", "font"])];
|
|
2153
|
+
const tokenPath = path17.join(".");
|
|
2154
|
+
const value = {
|
|
2155
|
+
fontFamily: s.fontFamily,
|
|
2156
|
+
fontSize: `${round(s.fontSize)}px`,
|
|
2157
|
+
fontWeight: s.fontWeight ?? weightFromStyleName(s.fontStyle) ?? 400
|
|
2158
|
+
};
|
|
2159
|
+
const lhPx = s.lineHeightPx ?? (s.lineHeightPercent !== void 0 ? s.fontSize * s.lineHeightPercent / 100 : void 0);
|
|
2160
|
+
if (lhPx !== void 0) value.lineHeight = round(lhPx / s.fontSize, 4);
|
|
2161
|
+
else {
|
|
2162
|
+
ctx.issues.push({
|
|
2163
|
+
severity: "warning",
|
|
2164
|
+
code: "missing-line-height",
|
|
2165
|
+
token: tokenPath,
|
|
2166
|
+
message: `Text style "${s.name}" has automatic line height; RN will use the font default.`,
|
|
2167
|
+
fix: "Set an explicit line height on the text style in Figma."
|
|
2168
|
+
});
|
|
2169
|
+
}
|
|
2170
|
+
const lsPx = s.letterSpacingPx ?? (s.letterSpacingPercent !== void 0 ? s.fontSize * s.letterSpacingPercent / 100 : 0);
|
|
2171
|
+
if (lsPx) value.letterSpacing = `${round(lsPx)}px`;
|
|
2172
|
+
const token = { $type: "typography", $value: value };
|
|
2173
|
+
if (s.description) token.$description = s.description;
|
|
2174
|
+
put(ctx, path17, token);
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
function normalizeEffectStyles(styles, ctx) {
|
|
2178
|
+
for (const s of [...styles].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2179
|
+
const path17 = [
|
|
2180
|
+
"shadow",
|
|
2181
|
+
...stripRoot(splitName(s.name), ["shadow", "shadows", "elevation", "effect"])
|
|
2182
|
+
];
|
|
2183
|
+
const tokenPath = path17.join(".");
|
|
2184
|
+
const layers = [];
|
|
2185
|
+
for (const e of s.effects) {
|
|
2186
|
+
if (e.visible === false) continue;
|
|
2187
|
+
if (e.type === "DROP_SHADOW" && e.color) {
|
|
2188
|
+
layers.push({
|
|
2189
|
+
color: figmaColorToHex(e.color),
|
|
2190
|
+
offsetX: `${round(e.offset?.x ?? 0)}px`,
|
|
2191
|
+
offsetY: `${round(e.offset?.y ?? 0)}px`,
|
|
2192
|
+
blur: `${round(e.radius ?? 0)}px`,
|
|
2193
|
+
spread: `${round(e.spread ?? 0)}px`
|
|
2194
|
+
});
|
|
2195
|
+
} else {
|
|
2196
|
+
ctx.issues.push({
|
|
2197
|
+
severity: "warning",
|
|
2198
|
+
code: "unsupported-effect",
|
|
2199
|
+
token: tokenPath,
|
|
2200
|
+
message: `Effect "${e.type}" in "${s.name}" is not supported by React Native and was skipped.`,
|
|
2201
|
+
fix: "Use drop shadows only for elevation. Blurs/inner shadows need a custom native or Skia implementation."
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
if (!layers.length) continue;
|
|
2206
|
+
const token = { $type: "shadow", $value: layers.length === 1 ? layers[0] : layers };
|
|
2207
|
+
if (s.description) token.$description = s.description;
|
|
2208
|
+
put(ctx, path17, token);
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
// src/tokens/normalize-stitch.ts
|
|
2213
|
+
function cssLengthToPx(v) {
|
|
2214
|
+
const m = /^(-?[\d.]+)\s*(px|rem|em)?$/.exec(v.trim());
|
|
2215
|
+
if (!m) return null;
|
|
2216
|
+
const n = Number(m[1]);
|
|
2217
|
+
return m[2] === "rem" || m[2] === "em" ? n * 16 : n;
|
|
2218
|
+
}
|
|
2219
|
+
function splitTopLevel(input, sep) {
|
|
2220
|
+
const out = [];
|
|
2221
|
+
let depth = 0;
|
|
2222
|
+
let cur = "";
|
|
2223
|
+
for (const ch of input) {
|
|
2224
|
+
if (ch === "(") depth++;
|
|
2225
|
+
if (ch === ")") depth--;
|
|
2226
|
+
if (ch === sep && depth === 0) {
|
|
2227
|
+
out.push(cur);
|
|
2228
|
+
cur = "";
|
|
2229
|
+
} else cur += ch;
|
|
2230
|
+
}
|
|
2231
|
+
if (cur.trim()) out.push(cur);
|
|
2232
|
+
return out;
|
|
2233
|
+
}
|
|
2234
|
+
function parseBoxShadow(css) {
|
|
2235
|
+
const first = splitTopLevel(css, ",")[0]?.trim();
|
|
2236
|
+
if (!first || first === "none") return null;
|
|
2237
|
+
const parts = first.match(/[^\s(]+\([^)]*\)|\S+/g) ?? [];
|
|
2238
|
+
if (parts.includes("inset")) return null;
|
|
2239
|
+
const lengths = [];
|
|
2240
|
+
let color = "#000000";
|
|
2241
|
+
for (const p4 of parts) {
|
|
2242
|
+
const px2 = cssLengthToPx(p4);
|
|
2243
|
+
if (px2 !== null) lengths.push(px2);
|
|
2244
|
+
else {
|
|
2245
|
+
const c = cssColorToHex(p4);
|
|
2246
|
+
if (c) color = c;
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
if (lengths.length < 2) return null;
|
|
2250
|
+
const [x, y, blur = 0, spread = 0] = lengths;
|
|
2251
|
+
return {
|
|
2252
|
+
color,
|
|
2253
|
+
offsetX: `${round(x)}px`,
|
|
2254
|
+
offsetY: `${round(y)}px`,
|
|
2255
|
+
blur: `${round(blur)}px`,
|
|
2256
|
+
spread: `${round(spread)}px`
|
|
2257
|
+
};
|
|
2258
|
+
}
|
|
2259
|
+
function colorEntries(colors, ctx) {
|
|
2260
|
+
const out = /* @__PURE__ */ new Map();
|
|
2261
|
+
for (const [group, val] of Object.entries(colors)) {
|
|
2262
|
+
const entries = typeof val === "string" ? [[[slug(group)], val]] : Object.entries(val).map(([k, v]) => [[slug(group), slug(k)], v]);
|
|
2263
|
+
for (const [path17, raw] of entries) {
|
|
2264
|
+
const hex = cssColorToHex(raw);
|
|
2265
|
+
if (!hex) {
|
|
2266
|
+
ctx.issues.push({
|
|
2267
|
+
severity: "warning",
|
|
2268
|
+
code: "invalid-value",
|
|
2269
|
+
token: ["color", ...path17].join("."),
|
|
2270
|
+
message: `Color "${raw}" is not hex/rgb(a) and was skipped.`,
|
|
2271
|
+
fix: "Use hex or rgb()/rgba() colors in the Stitch design (hsl, oklch and CSS variables are not converted)."
|
|
2272
|
+
});
|
|
2273
|
+
continue;
|
|
2274
|
+
}
|
|
2275
|
+
out.set(path17.join("."), hex);
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
return out;
|
|
2279
|
+
}
|
|
2280
|
+
function normalizeTailwind(tw, ctx) {
|
|
2281
|
+
if (tw.colors) {
|
|
2282
|
+
const light = colorEntries(tw.colors, ctx);
|
|
2283
|
+
const dark = tw.darkColors ? colorEntries(tw.darkColors, ctx) : /* @__PURE__ */ new Map();
|
|
2284
|
+
for (const [path17, hex] of [...light.entries()].sort(([a], [b]) => a.localeCompare(b))) {
|
|
2285
|
+
const segs = ["color", ...path17.split(".")];
|
|
2286
|
+
checkColorName(path17.split(".").join("/"), ctx, segs.join("."), false);
|
|
2287
|
+
const token = { $type: "color", $value: hex };
|
|
2288
|
+
const d = dark.get(path17);
|
|
2289
|
+
if (d && d !== hex) token.$extensions = { mode: { dark: d } };
|
|
2290
|
+
put(ctx, segs, token);
|
|
2291
|
+
}
|
|
2292
|
+
for (const path17 of dark.keys()) {
|
|
2293
|
+
if (!light.has(path17)) {
|
|
2294
|
+
ctx.issues.push({
|
|
2295
|
+
severity: "warning",
|
|
2296
|
+
code: "invalid-value",
|
|
2297
|
+
token: `color.${path17}`,
|
|
2298
|
+
message: `Dark color "${path17}" has no light counterpart and was skipped.`,
|
|
2299
|
+
fix: "Define the same color name for both light and dark palettes."
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
if (!tw.darkColors) {
|
|
2304
|
+
ctx.issues.push({
|
|
2305
|
+
severity: "info",
|
|
2306
|
+
code: "single-mode-source",
|
|
2307
|
+
message: "Stitch export contained only one color palette; dark theme will equal light.",
|
|
2308
|
+
fix: 'Generate a dark variant of the design in Stitch and add its palette as "tailwind.darkColors".'
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
const lengthGroup = (record, root) => {
|
|
2313
|
+
for (const [k, v] of Object.entries(record ?? {}).sort(([a], [b]) => a.localeCompare(b))) {
|
|
2314
|
+
const px2 = cssLengthToPx(v);
|
|
2315
|
+
if (px2 === null) {
|
|
2316
|
+
ctx.issues.push({
|
|
2317
|
+
severity: "info",
|
|
2318
|
+
code: "invalid-value",
|
|
2319
|
+
token: `${root}.${slug(k)}`,
|
|
2320
|
+
message: `Length "${v}" could not be converted to px; skipped.`,
|
|
2321
|
+
fix: "Use px or rem values."
|
|
2322
|
+
});
|
|
2323
|
+
continue;
|
|
2324
|
+
}
|
|
2325
|
+
put(ctx, [root, slug(k)], { $type: "dimension", $value: `${round(px2)}px` });
|
|
2326
|
+
}
|
|
2327
|
+
};
|
|
2328
|
+
lengthGroup(tw.spacing, "spacing");
|
|
2329
|
+
lengthGroup(tw.borderRadius, "radius");
|
|
2330
|
+
for (const [k, v] of Object.entries(tw.fontFamily ?? {}).sort(([a], [b]) => a.localeCompare(b))) {
|
|
2331
|
+
const first = (Array.isArray(v) ? v[0] : v.split(",")[0])?.trim().replace(/^['"]|['"]$/g, "");
|
|
2332
|
+
if (first) put(ctx, ["font-family", slug(k)], { $type: "fontFamily", $value: first });
|
|
2333
|
+
}
|
|
2334
|
+
for (const [k, v] of Object.entries(tw.fontSize ?? {}).sort(([a], [b]) => a.localeCompare(b))) {
|
|
2335
|
+
const size = typeof v === "string" ? v : v[0];
|
|
2336
|
+
const px2 = cssLengthToPx(size);
|
|
2337
|
+
if (px2 === null) continue;
|
|
2338
|
+
put(ctx, ["font-size", slug(k)], { $type: "dimension", $value: `${round(px2)}px` });
|
|
2339
|
+
const lh = Array.isArray(v) && typeof v[1] === "object" ? v[1].lineHeight : Array.isArray(v) ? v[1] : void 0;
|
|
2340
|
+
if (lh) {
|
|
2341
|
+
const lhPx = /^[\d.]+$/.test(lh) ? Number(lh) * px2 : cssLengthToPx(lh);
|
|
2342
|
+
if (lhPx !== null)
|
|
2343
|
+
put(ctx, ["line-height", slug(k)], { $type: "dimension", $value: `${round(lhPx)}px` });
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
if (tw.fontSize) {
|
|
2347
|
+
ctx.issues.push({
|
|
2348
|
+
severity: "info",
|
|
2349
|
+
code: "invalid-value",
|
|
2350
|
+
message: "Stitch/Tailwind has no text styles; only font-size/line-height/font-family tokens were created.",
|
|
2351
|
+
fix: 'Compose "typography.*" tokens in Figma (text styles) if you need ready-made text styles.'
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
for (const [k, v] of Object.entries(tw.boxShadow ?? {}).sort(([a], [b]) => a.localeCompare(b))) {
|
|
2355
|
+
const shadow = parseBoxShadow(v);
|
|
2356
|
+
if (!shadow) {
|
|
2357
|
+
ctx.issues.push({
|
|
2358
|
+
severity: "warning",
|
|
2359
|
+
code: "unsupported-effect",
|
|
2360
|
+
token: `shadow.${slug(k)}`,
|
|
2361
|
+
message: `Shadow "${k}: ${v}" is inset/unparsable and was skipped.`,
|
|
2362
|
+
fix: "RN supports outer drop shadows only."
|
|
2363
|
+
});
|
|
2364
|
+
continue;
|
|
2365
|
+
}
|
|
2366
|
+
put(ctx, ["shadow", slug(k)], { $type: "shadow", $value: shadow });
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
// src/tokens/normalize.ts
|
|
2371
|
+
var RANK = { error: 0, warning: 1, info: 2 };
|
|
2372
|
+
function sortIssues(issues) {
|
|
2373
|
+
return [...issues].sort(
|
|
2374
|
+
(a, b) => RANK[a.severity] - RANK[b.severity] || a.code.localeCompare(b.code) || (a.token ?? "").localeCompare(b.token ?? "") || a.message.localeCompare(b.message)
|
|
2375
|
+
);
|
|
2376
|
+
}
|
|
2377
|
+
function postChecks(ctx) {
|
|
2378
|
+
const flat = flatten(ctx.tree);
|
|
2379
|
+
const roots = new Set(flat.map((t) => t.path.split(".")[0]));
|
|
2380
|
+
const required = [
|
|
2381
|
+
["color", "colors", "warning"],
|
|
2382
|
+
["spacing", "spacing scale", "warning"],
|
|
2383
|
+
["radius", "border radius", "warning"],
|
|
2384
|
+
["typography", "text styles", "warning"],
|
|
2385
|
+
["shadow", "shadows/elevation", "info"]
|
|
2386
|
+
];
|
|
2387
|
+
for (const [root, label, severity] of required) {
|
|
2388
|
+
if (!roots.has(root)) {
|
|
2389
|
+
ctx.issues.push({
|
|
2390
|
+
severity,
|
|
2391
|
+
code: "missing-category",
|
|
2392
|
+
token: root,
|
|
2393
|
+
message: `No "${root}.*" tokens found (${label}). Components would have to hardcode them.`,
|
|
2394
|
+
fix: `Add ${label} as Figma variables/styles named "${root}/...", then re-run.`
|
|
2395
|
+
});
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
const colors = flat.filter((t) => t.type === "color");
|
|
2399
|
+
const aliasColors = colors.filter((t) => typeof t.value === "string" && /^\{.+\}$/.test(t.value));
|
|
2400
|
+
const hasDark = colors.some((t) => "dark" in t.modes);
|
|
2401
|
+
if (colors.length && !hasDark) {
|
|
2402
|
+
ctx.issues.push({
|
|
2403
|
+
severity: "warning",
|
|
2404
|
+
code: "missing-dark-mode",
|
|
2405
|
+
message: "No color token has a Dark value. darkTheme will be identical to lightTheme.",
|
|
2406
|
+
fix: 'Add a "Dark" mode to your semantic color collection in Figma (or a dark palette in Stitch).'
|
|
2407
|
+
});
|
|
2408
|
+
} else if (hasDark) {
|
|
2409
|
+
for (const t of aliasColors.filter((c) => !("dark" in c.modes))) {
|
|
2410
|
+
ctx.issues.push({
|
|
2411
|
+
severity: "warning",
|
|
2412
|
+
code: "missing-dark-mode",
|
|
2413
|
+
token: t.path,
|
|
2414
|
+
message: `Semantic color "${t.path}" has the same value in Light and Dark.`,
|
|
2415
|
+
fix: "If that is intentional, ignore. Otherwise set a different value for the Dark mode in Figma."
|
|
2416
|
+
});
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
const families = /* @__PURE__ */ new Set();
|
|
2420
|
+
for (const t of flat) {
|
|
2421
|
+
if (t.type === "fontFamily" && typeof t.value === "string") families.add(t.value);
|
|
2422
|
+
if (t.type === "typography" && typeof t.value === "object" && t.value) {
|
|
2423
|
+
const f = t.value.fontFamily;
|
|
2424
|
+
if (typeof f === "string") families.add(f);
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
if (families.size) {
|
|
2428
|
+
ctx.issues.push({
|
|
2429
|
+
severity: "info",
|
|
2430
|
+
code: "font-loading",
|
|
2431
|
+
message: `Fonts used: ${[...families].sort().join(", ")}. React Native needs each family/weight loaded under the exact name used in the theme.`,
|
|
2432
|
+
fix: "Load fonts with expo-font (useFonts) or link them natively, and verify the registered family names."
|
|
2433
|
+
});
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
function normalizeSnapshot(snap) {
|
|
2437
|
+
const ctx = { tree: {}, issues: [] };
|
|
2438
|
+
if (snap.variables) normalizeVariables(snap.variables, ctx);
|
|
2439
|
+
if (snap.flatVariables) normalizeFlat(snap.flatVariables, snap.flatVariablesDark, ctx);
|
|
2440
|
+
if (snap.colorStyles) normalizeColorStyles(snap.colorStyles, ctx);
|
|
2441
|
+
if (snap.textStyles) normalizeTextStyles(snap.textStyles, ctx);
|
|
2442
|
+
if (snap.effectStyles) normalizeEffectStyles(snap.effectStyles, ctx);
|
|
2443
|
+
if (snap.tailwind) normalizeTailwind(snap.tailwind, ctx);
|
|
2444
|
+
postChecks(ctx);
|
|
2445
|
+
return { tree: ctx.tree, issues: sortIssues(ctx.issues) };
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
// src/tokens/report.ts
|
|
2449
|
+
var ICON = { error: "\u{1F534}", warning: "\u{1F7E1}", info: "\u{1F535}" };
|
|
2450
|
+
var LIMIT = 40;
|
|
2451
|
+
function list(items) {
|
|
2452
|
+
const shown = items.slice(0, LIMIT).map((i) => `- \`${i}\``);
|
|
2453
|
+
if (items.length > LIMIT) shown.push(`- \u2026 and ${items.length - LIMIT} more`);
|
|
2454
|
+
return shown.join("\n");
|
|
2455
|
+
}
|
|
2456
|
+
function renderReport(input) {
|
|
2457
|
+
const flat = flatten(input.tree);
|
|
2458
|
+
const byType = /* @__PURE__ */ new Map();
|
|
2459
|
+
for (const t of flat) byType.set(t.type, (byType.get(t.type) ?? 0) + 1);
|
|
2460
|
+
const count = (s) => input.issues.filter((i) => i.severity === s).length;
|
|
2461
|
+
const out = ["# Design tokens report", ""];
|
|
2462
|
+
out.push(`Source: **${input.source}**${input.fileUrl ? ` \u2014 ${input.fileUrl}` : ""}`, "");
|
|
2463
|
+
out.push("## Summary", "", "| Type | Tokens |", "| --- | ---: |");
|
|
2464
|
+
for (const [type, n] of [...byType.entries()].sort()) out.push(`| ${type} | ${n} |`);
|
|
2465
|
+
out.push(`| **total** | **${flat.length}** |`, "");
|
|
2466
|
+
out.push(
|
|
2467
|
+
`Issues: ${count("error")} error(s), ${count("warning")} warning(s), ${count("info")} info.`,
|
|
2468
|
+
""
|
|
2469
|
+
);
|
|
2470
|
+
out.push("## Changes since last run", "");
|
|
2471
|
+
if (input.diff.initial)
|
|
2472
|
+
out.push(`Initial generation: ${input.diff.added.length} tokens created.`, "");
|
|
2473
|
+
else if (diffIsEmpty(input.diff)) out.push("No changes.", "");
|
|
2474
|
+
else {
|
|
2475
|
+
if (input.diff.added.length)
|
|
2476
|
+
out.push(`### Added (${input.diff.added.length})`, "", list(input.diff.added), "");
|
|
2477
|
+
if (input.diff.removed.length)
|
|
2478
|
+
out.push(
|
|
2479
|
+
`### Removed (${input.diff.removed.length})`,
|
|
2480
|
+
"",
|
|
2481
|
+
list(input.diff.removed),
|
|
2482
|
+
"",
|
|
2483
|
+
"> Removed tokens may break components that still use them \u2014 `tsc` will flag them.",
|
|
2484
|
+
""
|
|
2485
|
+
);
|
|
2486
|
+
if (input.diff.changed.length) {
|
|
2487
|
+
out.push(`### Changed (${input.diff.changed.length})`, "");
|
|
2488
|
+
for (const c of input.diff.changed.slice(0, LIMIT))
|
|
2489
|
+
out.push(`- \`${c.path}\`: ${c.before} \u2192 ${c.after}`);
|
|
2490
|
+
if (input.diff.changed.length > LIMIT)
|
|
2491
|
+
out.push(`- \u2026 and ${input.diff.changed.length - LIMIT} more`);
|
|
2492
|
+
out.push("");
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
out.push("## Needs attention in the design file", "");
|
|
2496
|
+
if (!input.issues.length) out.push("\u2705 Nothing to fix.", "");
|
|
2497
|
+
for (const sev of ["error", "warning", "info"]) {
|
|
2498
|
+
const items = input.issues.filter((i) => i.severity === sev);
|
|
2499
|
+
if (!items.length) continue;
|
|
2500
|
+
out.push(`### ${ICON[sev]} ${sev[0].toUpperCase()}${sev.slice(1)}s (${items.length})`, "");
|
|
2501
|
+
for (const i of items) {
|
|
2502
|
+
out.push(`- ${i.token ? `\`${i.token}\` \u2014 ` : ""}${i.message}`);
|
|
2503
|
+
out.push(` - **Fix:** ${i.fix}`);
|
|
2504
|
+
}
|
|
2505
|
+
out.push("");
|
|
2506
|
+
}
|
|
2507
|
+
return `${out.join("\n").trimEnd()}
|
|
2508
|
+
`;
|
|
2509
|
+
}
|
|
2510
|
+
|
|
2511
|
+
// src/tokens/snapshot.ts
|
|
2512
|
+
function parseSnapshot(json) {
|
|
2513
|
+
if (typeof json !== "object" || json === null) throw new Error("Snapshot must be a JSON object.");
|
|
2514
|
+
const s = json;
|
|
2515
|
+
const hasData = s.variables || s.flatVariables || s.colorStyles || s.textStyles || s.effectStyles || s.tailwind;
|
|
2516
|
+
if (!hasData) {
|
|
2517
|
+
throw new Error(
|
|
2518
|
+
"Snapshot has no data. Expected at least one of: variables, flatVariables, colorStyles, textStyles, effectStyles, tailwind."
|
|
2519
|
+
);
|
|
2520
|
+
}
|
|
2521
|
+
if (!s.source) s.source = s.tailwind && !s.variables && !s.flatVariables ? "stitch" : "figma";
|
|
2522
|
+
return s;
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
// src/tokens/pipeline.ts
|
|
2526
|
+
var DEFAULT_PATHS = {
|
|
2527
|
+
snapshot: "design/source-snapshot.json",
|
|
2528
|
+
tokens: "design/tokens.json",
|
|
2529
|
+
theme: "src/shared/theme/tokens.ts",
|
|
2530
|
+
report: "design/tokens-report.md"
|
|
2531
|
+
};
|
|
2532
|
+
function buildArtifacts(snapshot, previousTokensJson) {
|
|
2533
|
+
const { tree, issues } = normalizeSnapshot(snapshot);
|
|
2534
|
+
const tokensJson = serializeTree(tree);
|
|
2535
|
+
const { ts, warnings } = generateFromTokensJson(tokensJson);
|
|
2536
|
+
const prev = previousTokensJson ? JSON.parse(previousTokensJson) : null;
|
|
2537
|
+
const diff = diffTokens(prev, JSON.parse(tokensJson));
|
|
2538
|
+
const report = renderReport({
|
|
2539
|
+
source: snapshot.source,
|
|
2540
|
+
fileUrl: snapshot.fileUrl,
|
|
2541
|
+
tree,
|
|
2542
|
+
issues,
|
|
2543
|
+
diff
|
|
2544
|
+
});
|
|
2545
|
+
return { tokensJson, tokensTs: ts, report, diff, issues, warnings };
|
|
2546
|
+
}
|
|
2547
|
+
async function readOptional(path17) {
|
|
2548
|
+
try {
|
|
2549
|
+
return await readFile6(path17, "utf8");
|
|
2550
|
+
} catch {
|
|
2551
|
+
return null;
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
async function writeIfChanged(path17, content) {
|
|
2555
|
+
if (await readOptional(path17) === content) return false;
|
|
2556
|
+
await mkdir2(dirname(path17), { recursive: true });
|
|
2557
|
+
await writeFile2(path17, content, "utf8");
|
|
2558
|
+
return true;
|
|
2559
|
+
}
|
|
2560
|
+
var abs = (cwd, p4) => resolve(cwd, p4);
|
|
2561
|
+
async function runBuild(cwd, paths) {
|
|
2562
|
+
const raw = await readOptional(abs(cwd, paths.snapshot));
|
|
2563
|
+
if (raw === null)
|
|
2564
|
+
throw new Error(
|
|
2565
|
+
`Snapshot not found: ${paths.snapshot}. Ask the agent to create it (see the figma-to-tokens skill) or run "fetch".`
|
|
2566
|
+
);
|
|
2567
|
+
const snapshot = parseSnapshot(JSON.parse(raw));
|
|
2568
|
+
const previous = await readOptional(abs(cwd, paths.tokens));
|
|
2569
|
+
const out = buildArtifacts(snapshot, previous);
|
|
2570
|
+
const written = {
|
|
2571
|
+
tokens: await writeIfChanged(abs(cwd, paths.tokens), out.tokensJson),
|
|
2572
|
+
theme: await writeIfChanged(abs(cwd, paths.theme), out.tokensTs),
|
|
2573
|
+
report: await writeIfChanged(abs(cwd, paths.report), out.report),
|
|
2574
|
+
provider: false
|
|
2575
|
+
};
|
|
2576
|
+
const providerPath = resolve(dirname(abs(cwd, paths.theme)), "ThemeProvider.tsx");
|
|
2577
|
+
if (await readOptional(providerPath) === null)
|
|
2578
|
+
written.provider = await writeIfChanged(providerPath, THEME_PROVIDER_TSX);
|
|
2579
|
+
return { ...out, written };
|
|
2580
|
+
}
|
|
2581
|
+
async function runGenerate(cwd, paths) {
|
|
2582
|
+
const text2 = await readOptional(abs(cwd, paths.tokens));
|
|
2583
|
+
if (text2 === null) throw new Error(`${paths.tokens} not found. Run "build" first.`);
|
|
2584
|
+
const { ts, warnings } = generateFromTokensJson(text2);
|
|
2585
|
+
const changed = await writeIfChanged(abs(cwd, paths.theme), ts);
|
|
2586
|
+
return { changed, warnings };
|
|
2587
|
+
}
|
|
2588
|
+
async function runCheck(cwd, paths) {
|
|
2589
|
+
const problems = [];
|
|
2590
|
+
const tokensText = await readOptional(abs(cwd, paths.tokens));
|
|
2591
|
+
if (tokensText === null) return { ok: false, problems: [`${paths.tokens} is missing.`] };
|
|
2592
|
+
const theme = await readOptional(abs(cwd, paths.theme));
|
|
2593
|
+
const expectedTs = generateFromTokensJson(tokensText).ts;
|
|
2594
|
+
if (theme === null) problems.push(`${paths.theme} is missing. Run: tokens generate`);
|
|
2595
|
+
else if (theme !== expectedTs)
|
|
2596
|
+
problems.push(`${paths.theme} is out of date with ${paths.tokens}. Run: tokens generate`);
|
|
2597
|
+
const snap = await readOptional(abs(cwd, paths.snapshot));
|
|
2598
|
+
if (snap !== null) {
|
|
2599
|
+
const expectedJson = buildArtifacts(parseSnapshot(JSON.parse(snap)), null).tokensJson;
|
|
2600
|
+
if (expectedJson !== tokensText)
|
|
2601
|
+
problems.push(`${paths.tokens} does not match ${paths.snapshot}. Run: tokens build`);
|
|
2602
|
+
}
|
|
2603
|
+
return { ok: problems.length === 0, problems };
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
// src/scripts/figma-tokens.ts
|
|
2607
|
+
var HELP = `Usage: figma-tokens <build|generate|check|fetch> [options]
|
|
2608
|
+
|
|
2609
|
+
--snapshot <file> default ${DEFAULT_PATHS.snapshot}
|
|
2610
|
+
--tokens <file> default ${DEFAULT_PATHS.tokens}
|
|
2611
|
+
--theme <file> default ${DEFAULT_PATHS.theme}
|
|
2612
|
+
--report <file> default ${DEFAULT_PATHS.report}
|
|
2613
|
+
--strict build: exit 1 if the report contains errors
|
|
2614
|
+
--url <figma-url> fetch: Figma file URL (token from FIGMA_TOKEN)
|
|
2615
|
+
`;
|
|
2616
|
+
async function runCli(argv, cwd = process.cwd()) {
|
|
2617
|
+
const { positionals, values } = parseArgs({
|
|
2618
|
+
args: argv,
|
|
2619
|
+
allowPositionals: true,
|
|
2620
|
+
options: {
|
|
2621
|
+
snapshot: { type: "string" },
|
|
2622
|
+
tokens: { type: "string" },
|
|
2623
|
+
theme: { type: "string" },
|
|
2624
|
+
report: { type: "string" },
|
|
2625
|
+
url: { type: "string" },
|
|
2626
|
+
strict: { type: "boolean", default: false },
|
|
2627
|
+
help: { type: "boolean", short: "h", default: false }
|
|
2628
|
+
}
|
|
2629
|
+
});
|
|
2630
|
+
const paths = {
|
|
2631
|
+
snapshot: values.snapshot ?? DEFAULT_PATHS.snapshot,
|
|
2632
|
+
tokens: values.tokens ?? DEFAULT_PATHS.tokens,
|
|
2633
|
+
theme: values.theme ?? DEFAULT_PATHS.theme,
|
|
2634
|
+
report: values.report ?? DEFAULT_PATHS.report
|
|
2635
|
+
};
|
|
2636
|
+
const cmd = positionals[0];
|
|
2637
|
+
if (!cmd || values.help) {
|
|
2638
|
+
console.log(HELP);
|
|
2639
|
+
return cmd ? 0 : 1;
|
|
2640
|
+
}
|
|
2641
|
+
try {
|
|
2642
|
+
if (cmd === "build") {
|
|
2643
|
+
const r = await runBuild(cwd, paths);
|
|
2644
|
+
const errors = r.issues.filter((i) => i.severity === "error").length;
|
|
2645
|
+
const warnings = r.issues.filter((i) => i.severity === "warning").length;
|
|
2646
|
+
console.log(
|
|
2647
|
+
r.diff.initial ? `\u2714 Created ${r.diff.added.length} tokens.` : diffIsEmpty(r.diff) ? "\u2714 No token changes." : `\u2714 Tokens updated: +${r.diff.added.length} \u2212${r.diff.removed.length} ~${r.diff.changed.length}`
|
|
2648
|
+
);
|
|
2649
|
+
console.log(
|
|
2650
|
+
` wrote: ${paths.tokens}${r.written.tokens ? "" : " (unchanged)"}, ${paths.theme}${r.written.theme ? "" : " (unchanged)"}, ${paths.report}`
|
|
2651
|
+
);
|
|
2652
|
+
if (r.written.provider)
|
|
2653
|
+
console.log(" created ThemeProvider.tsx (not overwritten on later runs)");
|
|
2654
|
+
for (const w of r.warnings) console.warn(` ! ${w}`);
|
|
2655
|
+
console.log(` report: ${errors} error(s), ${warnings} warning(s) \u2192 see ${paths.report}`);
|
|
2656
|
+
return values.strict && errors > 0 ? 1 : 0;
|
|
2657
|
+
}
|
|
2658
|
+
if (cmd === "generate") {
|
|
2659
|
+
const r = await runGenerate(cwd, paths);
|
|
2660
|
+
console.log(r.changed ? `\u2714 Regenerated ${paths.theme}` : "\u2714 Already up to date.");
|
|
2661
|
+
for (const w of r.warnings) console.warn(` ! ${w}`);
|
|
2662
|
+
return 0;
|
|
2663
|
+
}
|
|
2664
|
+
if (cmd === "check") {
|
|
2665
|
+
const r = await runCheck(cwd, paths);
|
|
2666
|
+
if (r.ok) console.log("\u2714 Design tokens are up to date.");
|
|
2667
|
+
else for (const p4 of r.problems) console.error(`\u2716 ${p4}`);
|
|
2668
|
+
return r.ok ? 0 : 1;
|
|
2669
|
+
}
|
|
2670
|
+
if (cmd === "fetch") {
|
|
2671
|
+
const token = process.env.FIGMA_TOKEN;
|
|
2672
|
+
if (!values.url) throw new Error("--url <figma-file-url> is required");
|
|
2673
|
+
if (!token)
|
|
2674
|
+
throw new Error(
|
|
2675
|
+
"FIGMA_TOKEN is not set. Create a personal access token in Figma (scopes: file_content:read, file_variables:read)."
|
|
2676
|
+
);
|
|
2677
|
+
const { snapshot, notes } = await fetchFigmaSnapshot(values.url, token);
|
|
2678
|
+
const file = resolve2(cwd, paths.snapshot);
|
|
2679
|
+
await mkdir3(dirname2(file), { recursive: true });
|
|
2680
|
+
await writeFile3(file, `${JSON.stringify(snapshot, null, 2)}
|
|
2681
|
+
`, "utf8");
|
|
2682
|
+
console.log(`\u2714 Wrote ${paths.snapshot}`);
|
|
2683
|
+
for (const n of notes) console.warn(` ! ${n}`);
|
|
2684
|
+
return 0;
|
|
2685
|
+
}
|
|
2686
|
+
console.error(`Unknown command "${cmd}".
|
|
2687
|
+
${HELP}`);
|
|
2688
|
+
return 1;
|
|
2689
|
+
} catch (e) {
|
|
2690
|
+
console.error(`\u2716 ${e.message}`);
|
|
2691
|
+
return 1;
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
var entryPath = process.argv[1] ?? "";
|
|
2695
|
+
if (/figma-tokens\.(ts|js|mjs|cjs)$/.test(entryPath) && import.meta.url === pathToFileURL(entryPath).href) {
|
|
2696
|
+
runCli(process.argv.slice(2)).then((code) => process.exit(code));
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
// src/scripts/validate-jira-tickets.ts
|
|
2700
|
+
import { readdir as readdir3, readFile as readFile7 } from "fs/promises";
|
|
2701
|
+
import { join, resolve as resolve3 } from "path";
|
|
2702
|
+
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
2703
|
+
import { parseArgs as parseArgs2 } from "util";
|
|
2704
|
+
|
|
2705
|
+
// src/jira/validate.ts
|
|
2706
|
+
var FIGMA_LINK_RE = /https?:\/\/(?:www\.)?figma\.com\/\S+/i;
|
|
2707
|
+
var NEEDS_FIGMA_RE = /\bNEEDS_FIGMA\b/;
|
|
2708
|
+
var AC_HEADING_RE = /#{1,3}\s*Acceptance Criteria\b/i;
|
|
2709
|
+
var GHERKIN_RE = /\b(Given|When|Then)\b/;
|
|
2710
|
+
var TEST_IDS_HEADING_RE = /#{1,3}\s*testIDs?\b/i;
|
|
2711
|
+
var TEST_ID_ITEM_RE = /^\s*[-*]\s+`?[A-Za-z][A-Za-z0-9_-{}.]*`?/m;
|
|
2712
|
+
function validateTicketMarkdown(file, body) {
|
|
2713
|
+
const issues = [];
|
|
2714
|
+
const text2 = body ?? "";
|
|
2715
|
+
if (!FIGMA_LINK_RE.test(text2) && !NEEDS_FIGMA_RE.test(text2)) {
|
|
2716
|
+
issues.push({
|
|
2717
|
+
file,
|
|
2718
|
+
code: "missing-figma-link",
|
|
2719
|
+
message: "Missing Figma deep link (figma.com URL) or explicit NEEDS_FIGMA marker."
|
|
2720
|
+
});
|
|
2721
|
+
}
|
|
2722
|
+
const hasAcHeading = AC_HEADING_RE.test(text2);
|
|
2723
|
+
const hasGherkin = GHERKIN_RE.test(text2);
|
|
2724
|
+
if (!hasAcHeading && !hasGherkin) {
|
|
2725
|
+
issues.push({
|
|
2726
|
+
file,
|
|
2727
|
+
code: "missing-acceptance-criteria",
|
|
2728
|
+
message: 'Missing Acceptance Criteria \u2014 add a "## Acceptance Criteria" section and/or Gherkin Given/When/Then.'
|
|
2729
|
+
});
|
|
2730
|
+
}
|
|
2731
|
+
const testIdsIdx = text2.search(TEST_IDS_HEADING_RE);
|
|
2732
|
+
if (testIdsIdx === -1) {
|
|
2733
|
+
issues.push({
|
|
2734
|
+
file,
|
|
2735
|
+
code: "missing-test-ids",
|
|
2736
|
+
message: 'Missing "## testIDs" section with at least one listed id.'
|
|
2737
|
+
});
|
|
2738
|
+
} else {
|
|
2739
|
+
const after = text2.slice(testIdsIdx);
|
|
2740
|
+
const nextHeading = after.slice(1).search(/\n#{1,3}\s+/);
|
|
2741
|
+
const section = nextHeading === -1 ? after : after.slice(0, nextHeading + 1);
|
|
2742
|
+
if (!TEST_ID_ITEM_RE.test(section)) {
|
|
2743
|
+
issues.push({
|
|
2744
|
+
file,
|
|
2745
|
+
code: "missing-test-ids",
|
|
2746
|
+
message: 'The "## testIDs" section has no bullet list items.'
|
|
2747
|
+
});
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
return issues;
|
|
2751
|
+
}
|
|
2752
|
+
function validateTickets(tickets) {
|
|
2753
|
+
const issues = [];
|
|
2754
|
+
for (const t of tickets) {
|
|
2755
|
+
issues.push(...validateTicketMarkdown(t.file, t.body));
|
|
2756
|
+
}
|
|
2757
|
+
return { ok: issues.length === 0, checked: tickets.length, issues };
|
|
2758
|
+
}
|
|
2759
|
+
function ticketsFromMap(map) {
|
|
2760
|
+
const out = [];
|
|
2761
|
+
if (map.epic?.key && (map.epic.body || map.epic.description)) {
|
|
2762
|
+
out.push({
|
|
2763
|
+
file: `map:epic:${map.epic.key}`,
|
|
2764
|
+
body: map.epic.body ?? map.epic.description ?? ""
|
|
2765
|
+
});
|
|
2766
|
+
}
|
|
2767
|
+
for (const [slug2, story] of Object.entries(map.stories ?? {})) {
|
|
2768
|
+
const body = story.body ?? story.description;
|
|
2769
|
+
if (story.key && body) {
|
|
2770
|
+
const enriched = story.figmaUrl && !FIGMA_LINK_RE.test(body) && !NEEDS_FIGMA_RE.test(body) ? `${body}
|
|
2771
|
+
|
|
2772
|
+
## Figma
|
|
2773
|
+
|
|
2774
|
+
- **Link:** ${story.figmaUrl}
|
|
2775
|
+
` : body;
|
|
2776
|
+
out.push({ file: `map:story:${slug2}:${story.key}`, body: enriched });
|
|
2777
|
+
}
|
|
2778
|
+
for (const [subSlug, sub] of Object.entries(story.subtasks ?? {})) {
|
|
2779
|
+
const subBody = sub.body ?? sub.description;
|
|
2780
|
+
if (sub.key && subBody) {
|
|
2781
|
+
const enriched = story.figmaUrl && !FIGMA_LINK_RE.test(subBody) && !NEEDS_FIGMA_RE.test(subBody) ? `${subBody}
|
|
2782
|
+
|
|
2783
|
+
## Figma
|
|
2784
|
+
|
|
2785
|
+
- **Link:** ${story.figmaUrl}
|
|
2786
|
+
` : subBody;
|
|
2787
|
+
out.push({ file: `map:subtask:${slug2}/${subSlug}:${sub.key}`, body: enriched });
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
return out;
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2794
|
+
// src/scripts/validate-jira-tickets.ts
|
|
2795
|
+
var HELP2 = `Usage: validate-jira-tickets [--dir <path>] [--map <jira-map.json>]
|
|
2796
|
+
|
|
2797
|
+
--dir Folder of <KEY>.md ticket dumps (default: .agent/jira-tickets)
|
|
2798
|
+
--map Also validate inline body/description fields on .agent/jira-map.json
|
|
2799
|
+
-h Show help
|
|
2800
|
+
|
|
2801
|
+
Exits 1 if any ticket is missing a Figma link, Acceptance Criteria, or testIDs.
|
|
2802
|
+
`;
|
|
2803
|
+
async function runValidateJiraTickets(argv, cwd = process.cwd()) {
|
|
2804
|
+
const { values } = parseArgs2({
|
|
2805
|
+
args: argv,
|
|
2806
|
+
options: {
|
|
2807
|
+
dir: { type: "string" },
|
|
2808
|
+
map: { type: "string" },
|
|
2809
|
+
help: { type: "boolean", short: "h", default: false }
|
|
2810
|
+
}
|
|
2811
|
+
});
|
|
2812
|
+
if (values.help) {
|
|
2813
|
+
console.log(HELP2);
|
|
2814
|
+
return 0;
|
|
2815
|
+
}
|
|
2816
|
+
const tickets = [];
|
|
2817
|
+
const dir = resolve3(cwd, values.dir ?? ".agent/jira-tickets");
|
|
2818
|
+
try {
|
|
2819
|
+
const entries = await readdir3(dir);
|
|
2820
|
+
for (const name of entries) {
|
|
2821
|
+
if (!name.endsWith(".md")) continue;
|
|
2822
|
+
const file = join(dir, name);
|
|
2823
|
+
tickets.push({ file, body: await readFile7(file, "utf8") });
|
|
2824
|
+
}
|
|
2825
|
+
} catch {
|
|
2826
|
+
}
|
|
2827
|
+
if (values.map) {
|
|
2828
|
+
const mapPath = resolve3(cwd, values.map);
|
|
2829
|
+
try {
|
|
2830
|
+
const map = JSON.parse(await readFile7(mapPath, "utf8"));
|
|
2831
|
+
tickets.push(...ticketsFromMap(map));
|
|
2832
|
+
} catch (e) {
|
|
2833
|
+
console.error(`\u2716 Cannot read map ${values.map}: ${e.message}`);
|
|
2834
|
+
return 1;
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
if (tickets.length === 0) {
|
|
2838
|
+
console.error(
|
|
2839
|
+
`\u2716 No tickets found. Dump issue descriptions to ${values.dir ?? ".agent/jira-tickets"}/*.md or pass --map with inline bodies.`
|
|
2840
|
+
);
|
|
2841
|
+
return 1;
|
|
2842
|
+
}
|
|
2843
|
+
const result = validateTickets(tickets);
|
|
2844
|
+
console.log(`Checked ${result.checked} ticket(s).`);
|
|
2845
|
+
if (result.ok) {
|
|
2846
|
+
console.log("\u2714 All tickets include Figma link, Acceptance Criteria, and testIDs.");
|
|
2847
|
+
return 0;
|
|
2848
|
+
}
|
|
2849
|
+
for (const issue of result.issues) {
|
|
2850
|
+
console.error(`\u2716 [${issue.code}] ${issue.file}: ${issue.message}`);
|
|
2851
|
+
}
|
|
2852
|
+
console.error(
|
|
2853
|
+
`
|
|
2854
|
+
${result.issues.length} issue(s). Fix tickets (see templates/jira-ticket.md) and re-run.`
|
|
2855
|
+
);
|
|
2856
|
+
return 1;
|
|
2857
|
+
}
|
|
2858
|
+
var entryPath2 = process.argv[1] ?? "";
|
|
2859
|
+
if (/validate-jira-tickets\.(ts|js|mjs|cjs)$/.test(entryPath2) && import.meta.url === pathToFileURL2(entryPath2).href) {
|
|
2860
|
+
runValidateJiraTickets(process.argv.slice(2)).then((code) => process.exit(code));
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
// src/cli.ts
|
|
2864
|
+
var program = new Command();
|
|
2865
|
+
program.name("rn-agent-kit").description(
|
|
2866
|
+
"Install React Native agent skills into Claude, Cursor, Windsurf, Copilot, and AGENTS.md"
|
|
2867
|
+
).version("0.1.0");
|
|
2868
|
+
program.command("init").description("Scaffold or detect a RN project and install agent skills").option("-y, --yes", "Non-interactive defaults (no prompts)").option("--type <kind>", "new | existing").option("--stack <stack>", "expo | cli").option("--name <name>", "Project name when --type new").option("-t, --tools <list>", "Comma-separated tools: claude,cursor,agents-md,copilot,windsurf").option("-a, --adapters <list>", "Alias of --tools (claude,cursor,agents-md,copilot,windsurf)").option("--sdlc", "Install Figma \u2192 Jira \u2192 Maestro \u2192 CI workflow").option("--jira-url <url>", "Jira site URL (with --sdlc)").option("--jira-key <key>", "Jira project key (with --sdlc)").option("--figma-url <url>", "Figma file URL (with --sdlc)").option("--github-repo <repo>", "GitHub owner/name (with --sdlc)").option("--cwd <path>", "Working directory", process.cwd()).action(
|
|
2869
|
+
async (opts) => {
|
|
2870
|
+
const type = opts.type === "new" || opts.type === "existing" ? opts.type : void 0;
|
|
2871
|
+
const stack = opts.stack === "expo" || opts.stack === "cli" ? opts.stack : void 0;
|
|
2872
|
+
const split = (v) => v?.split(",").map((s) => s.trim()).filter(Boolean);
|
|
2873
|
+
await initCommand({
|
|
2874
|
+
cwd: opts.cwd,
|
|
2875
|
+
yes: opts.yes,
|
|
2876
|
+
type,
|
|
2877
|
+
stack,
|
|
2878
|
+
name: opts.name,
|
|
2879
|
+
tools: split(opts.tools) ?? split(opts.adapters),
|
|
2880
|
+
sdlc: opts.sdlc,
|
|
2881
|
+
jiraUrl: opts.jiraUrl,
|
|
2882
|
+
jiraKey: opts.jiraKey,
|
|
2883
|
+
figmaUrl: opts.figmaUrl,
|
|
2884
|
+
githubRepo: opts.githubRepo
|
|
2885
|
+
});
|
|
2886
|
+
}
|
|
2887
|
+
);
|
|
2888
|
+
program.command("doctor").description(
|
|
2889
|
+
"Check Node, git, Android/Xcode, Maestro, MCP, env tokens, .agent/config.json (+ adapters)"
|
|
2890
|
+
).option("--cwd <path>", "Target project directory", process.cwd()).option("--skip-adapters", "Only run environment checks").action(async (opts) => {
|
|
2891
|
+
await doctorCommand({ cwd: opts.cwd, skipAdapters: opts.skipAdapters });
|
|
2892
|
+
});
|
|
2893
|
+
program.command("update").description("Refresh installed skills without touching user content outside markers").option("-y, --yes", "If nothing installed yet, update all adapters").option(
|
|
2894
|
+
"-a, --adapters <list>",
|
|
2895
|
+
"Comma-separated adapters (claude,cursor,agents-md,copilot,windsurf)"
|
|
2896
|
+
).option("--cwd <path>", "Target project directory", process.cwd()).action(async (opts) => {
|
|
2897
|
+
await updateCommand({
|
|
2898
|
+
cwd: opts.cwd,
|
|
2899
|
+
yes: opts.yes,
|
|
2900
|
+
adapters: opts.adapters?.split(",").map((s) => s.trim()).filter(Boolean)
|
|
2901
|
+
});
|
|
2902
|
+
});
|
|
2903
|
+
program.command("tokens").description("Design token pipeline: build | generate | check | fetch").allowUnknownOption().helpOption(false).argument("[args...]", "Passed through to figma-tokens").action(async () => {
|
|
2904
|
+
const idx = process.argv.findIndex((a) => a === "tokens");
|
|
2905
|
+
const args = idx >= 0 ? process.argv.slice(idx + 1) : [];
|
|
2906
|
+
const code = await runCli(args);
|
|
2907
|
+
process.exitCode = code;
|
|
2908
|
+
});
|
|
2909
|
+
program.command("jira-validate").description("Validate prd-to-jira ticket markdown (Figma link, AC, testIDs)").option("--dir <path>", "Folder of <KEY>.md dumps", ".agent/jira-tickets").option("--map <path>", "Also validate inline bodies on jira-map.json").option("--cwd <path>", "Working directory", process.cwd()).action(async (opts) => {
|
|
2910
|
+
const args = ["--dir", opts.dir ?? ".agent/jira-tickets"];
|
|
2911
|
+
if (opts.map) args.push("--map", opts.map);
|
|
2912
|
+
const code = await runValidateJiraTickets(args, opts.cwd);
|
|
2913
|
+
process.exitCode = code;
|
|
2914
|
+
});
|
|
2915
|
+
await program.parseAsync(process.argv);
|
|
2916
|
+
//# sourceMappingURL=cli.js.map
|