figma2mobile-local 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -287,4 +287,4 @@ malware — either is fine.
287
287
 
288
288
  ---
289
289
 
290
- Node ≥ 18. Build: d98936a-20260730232046
290
+ Node ≥ 18. Build: c5bd9a3-20260802103746
package/integrity.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "buildId": "d98936a-20260730232046",
3
- "bundleSha256": "123a44df880c67120491c3cf916f8cd82e3dc95239f5fc5bb3559f0465eec448"
2
+ "buildId": "c5bd9a3-20260802103746",
3
+ "bundleSha256": "f94cceaed9831ccd05a2fd96daecdc42848d55c4f06390fea8a1009fee728a54"
4
4
  }
package/loader.cjs CHANGED
@@ -16,7 +16,7 @@ const path = require("node:path");
16
16
  const crypto = require("node:crypto");
17
17
  const readline = require("node:readline");
18
18
 
19
- const BUILD_ID = "d98936a-20260730232046"; // pack-npx.sh thay bang build id that
19
+ const BUILD_ID = "c5bd9a3-20260802103746"; // pack-npx.sh thay bang build id that
20
20
  const ROOT = __dirname;
21
21
  const BUNDLE = path.join(ROOT, "main.obf.cjs");
22
22
 
@@ -241,7 +241,18 @@ function parseArgs(args) {
241
241
  return { ids, yes, outDir };
242
242
  }
243
243
 
244
- async function pickAgents() {
244
+ // Try the pretty @clack/prompts UI (ESM -> dynamic import from this CJS file).
245
+ // Null -> khong co (offline/loi) -> fallback readline.
246
+ async function loadClack() {
247
+ try {
248
+ return await import("@clack/prompts");
249
+ } catch {
250
+ return null;
251
+ }
252
+ }
253
+
254
+ // Readline fallback picker (khi khong co clack hoac khong TTY dep).
255
+ async function pickAgentsPlain() {
245
256
  const out = process.stdout.write.bind(process.stdout);
246
257
  out(
247
258
  "\nSelect agent(s) to register the MCP server (auto-writes config, with backup):\n",
@@ -264,12 +275,69 @@ async function pickAgents() {
264
275
  return picked;
265
276
  }
266
277
 
278
+ // Clack multiselect (checkbox, mac dinh chon het). Cancel -> thoat sach.
279
+ async function pickAgentsClack(clack) {
280
+ const picked = await clack.multiselect({
281
+ message:
282
+ "Select agents to register the MCP server (Space toggle, Enter confirm)",
283
+ options: AGENTS.map((a) => ({ value: a.id, label: a.label, hint: a.file })),
284
+ initialValues: AGENTS.map((a) => a.id),
285
+ required: false,
286
+ });
287
+ if (clack.isCancel(picked)) {
288
+ clack.cancel("Cancelled. Nothing was changed.");
289
+ process.exit(0);
290
+ }
291
+ return AGENTS.filter((a) => picked.includes(a.id));
292
+ }
293
+
294
+ // Build the manual-config + Figma-import guide (reused by clack note & plain out).
295
+ function guideText(manifestPath, hasSkill, target) {
296
+ const jsonEntry = JSON.stringify(
297
+ { mcpServers: { [MCP_NAME]: MCP_ENTRY } },
298
+ null,
299
+ 2,
300
+ );
301
+ const tomlArgs = MCP_ENTRY.args.map((a) => JSON.stringify(a)).join(", ");
302
+ const lines = [
303
+ `Manual install (other agents, or to verify)${IS_WIN ? " [Windows]" : ""}:`,
304
+ " MCP config JSON:",
305
+ ...jsonEntry.split("\n").map((l) => ` ${l}`),
306
+ "",
307
+ ...AGENTS.map((a) => ` ${a.label.padEnd(12)} ${a.manual}`),
308
+ " Claude Desktop File: (macOS) ~/Library/Application Support/Claude/claude_desktop_config.json",
309
+ " (Windows) %APPDATA%\\Claude\\claude_desktop_config.json",
310
+ " (Linux) ~/.config/Claude/claude_desktop_config.json",
311
+ " Codex TOML block:",
312
+ ` [mcp_servers.${MCP_NAME}]`,
313
+ ` command = ${JSON.stringify(MCP_ENTRY.command)}`,
314
+ ` args = [${tomlArgs}]`,
315
+ "",
316
+ "Import the plugin into Figma Desktop:",
317
+ " 1. Open Figma Desktop (Figma web cannot reach localhost).",
318
+ " 2. Menu > Plugins > Development > Import plugin from manifest...",
319
+ ` 3. Select: ${manifestPath}`,
320
+ " 4. Run: Plugins > Development > Figma2Mobile Local",
321
+ ];
322
+ if (hasSkill)
323
+ lines.push(
324
+ "",
325
+ `Native-layout implementation skill: ${path.join(target, "skills")}`,
326
+ );
327
+ return lines.join("\n");
328
+ }
329
+
267
330
  async function installPlugin(args) {
268
331
  const out = process.stdout.write.bind(process.stdout);
269
332
  const { ids, yes, outDir } = parseArgs(args);
270
333
  const target = path.resolve(outDir || "figma2mobile-local");
334
+ const interactive =
335
+ !ids && !yes && process.stdin.isTTY && process.stdout.isTTY;
336
+ const clack = interactive ? await loadClack() : null;
271
337
 
272
- // 1. Rai plugin + skill ra thu muc.
338
+ if (clack) clack.intro("figma2mobile-local · install");
339
+
340
+ // 1. Extract plugin + skill.
273
341
  const pluginSrc = path.join(ROOT, "plugin");
274
342
  if (!fs.existsSync(pluginSrc)) die("plugin/ folder missing from package.");
275
343
  copyDir(pluginSrc, path.join(target, "plugin"));
@@ -277,7 +345,7 @@ async function installPlugin(args) {
277
345
  const hasSkill = fs.existsSync(skillSrc);
278
346
  if (hasSkill) copyDir(skillSrc, path.join(target, "skills"));
279
347
 
280
- // 2. Chon agent: flags -> dung luon; khong flag + TTY -> menu; khong TTY -> bo qua auto.
348
+ // 2. Pick agents: flags -> use directly; interactive -> clack menu (or readline).
281
349
  let selected = [];
282
350
  if (ids) {
283
351
  if (ids.includes("all")) selected = AGENTS.slice();
@@ -288,17 +356,21 @@ async function installPlugin(args) {
288
356
  else out(` (skipping unsupported agent: ${id})\n`);
289
357
  }
290
358
  }
291
- } else if (process.stdin.isTTY && process.stdout.isTTY && !yes) {
292
- selected = await pickAgents();
359
+ } else if (clack) {
360
+ selected = await pickAgentsClack(clack);
361
+ } else if (interactive) {
362
+ selected = await pickAgentsPlain();
293
363
  }
294
364
 
295
- // 3. Dang ky MCP cho tung agent (tu ghi + backup).
365
+ // 3. Register MCP per agent (auto-write + backup), under a spinner when pretty.
366
+ const spin = clack ? clack.spinner() : null;
367
+ if (spin) spin.start("Writing MCP config");
296
368
  const results = [];
297
369
  for (const agent of selected) {
298
370
  try {
299
371
  const state = registerAgent(agent);
300
- // skillSrc chua san thu muc `figma-mobile-implementation/` -> copy thang
301
- // vao <agent.skills>/ de ra <skills>/figma-mobile-implementation/SKILL.md.
372
+ // skillSrc already contains `figma-mobile-implementation/` -> copy straight
373
+ // into <agent.skills>/ giving <skills>/figma-mobile-implementation/SKILL.md.
302
374
  if (hasSkill && agent.skills) copyDir(skillSrc, agent.skills);
303
375
  results.push({ agent, state });
304
376
  } catch (err) {
@@ -308,70 +380,46 @@ async function installPlugin(args) {
308
380
  });
309
381
  }
310
382
  }
383
+ if (spin) spin.stop("MCP config written");
311
384
 
312
- // 4. Bao cao.
385
+ // 4. Report + guide.
313
386
  const manifestPath = path.join(target, "plugin", "manifest.json");
387
+ const guide = guideText(manifestPath, hasSkill, target);
388
+ const verbOf = (s) =>
389
+ s === "added" ? "added" : s === "updated" ? "updated" : "already present";
390
+
391
+ if (clack) {
392
+ const reg = results.length
393
+ ? results
394
+ .map((r) =>
395
+ r.error
396
+ ? `✗ ${r.agent.label}: ${r.error}`
397
+ : `✓ ${r.agent.label}: ${verbOf(r.state)} -> ${r.agent.file}`,
398
+ )
399
+ .join("\n")
400
+ : "No agent selected — plugin extracted only.";
401
+ clack.note(`${target}\n\n${reg}`, "Plugin extracted + MCP registered");
402
+ clack.note(guide, "Next steps");
403
+ clack.outro(
404
+ results.length
405
+ ? "Done. Restart your MCP client, then import the plugin into Figma."
406
+ : "Done. Import the plugin into Figma when ready.",
407
+ );
408
+ process.exit(0);
409
+ }
410
+
411
+ // Plain output (flags / no-TTY / clack unavailable).
314
412
  out("\n✓ Plugin + skill extracted to:\n");
315
413
  out(` ${target}\n\n`);
316
-
317
414
  if (results.length) {
318
415
  out("MCP registered (existing files backed up as .bak-<timestamp>):\n");
319
416
  for (const r of results) {
320
417
  if (r.error) out(` ✗ ${r.agent.label}: ${r.error}\n`);
321
- else {
322
- const verb =
323
- r.state === "added"
324
- ? "added"
325
- : r.state === "updated"
326
- ? "updated"
327
- : "already present";
328
- out(` ✓ ${r.agent.label}: ${verb} -> ${r.agent.file}\n`);
329
- }
418
+ else out(` ✓ ${r.agent.label}: ${verbOf(r.state)} -> ${r.agent.file}\n`);
330
419
  }
331
420
  out("\n Restart the agent to load the new MCP server.\n\n");
332
421
  }
333
-
334
- // 5. Huong dan thu cong (moi agent) — de doi chieu / cai tay.
335
- // JSON + TOML derive tu MCP_ENTRY -> tren Windows tu hien bien the `cmd /c`.
336
- const jsonEntry = JSON.stringify(
337
- { mcpServers: { [MCP_NAME]: MCP_ENTRY } },
338
- null,
339
- 2,
340
- )
341
- .split("\n")
342
- .map((l) => ` ${l}`)
343
- .join("\n");
344
- const tomlArgs = MCP_ENTRY.args.map((a) => JSON.stringify(a)).join(", ");
345
- out(
346
- `Manual install (other agents, or to verify)${IS_WIN ? " [Windows]" : ""}:\n`,
347
- );
348
- out(" MCP config JSON:\n");
349
- out(`${jsonEntry}\n\n`);
350
- for (const a of AGENTS) out(` ${a.label.padEnd(12)} ${a.manual}\n`);
351
- out(
352
- " Claude Desktop File: (macOS) ~/Library/Application Support/Claude/claude_desktop_config.json\n",
353
- );
354
- out(
355
- " (Windows) %APPDATA%\\Claude\\claude_desktop_config.json\n",
356
- );
357
- out(
358
- " (Linux) ~/.config/Claude/claude_desktop_config.json\n",
359
- );
360
- out(" Codex TOML block:\n");
361
- out(` [mcp_servers.${MCP_NAME}]\n`);
362
- out(` command = ${JSON.stringify(MCP_ENTRY.command)}\n`);
363
- out(` args = [${tomlArgs}]\n\n`);
364
-
365
- // 6. Figma import (chung cho moi agent).
366
- out("Import the plugin into Figma Desktop:\n");
367
- out(" 1. Open Figma Desktop (Figma web cannot reach localhost).\n");
368
- out(" 2. Menu > Plugins > Development > Import plugin from manifest...\n");
369
- out(` 3. Select: ${manifestPath}\n`);
370
- out(" 4. Run: Plugins > Development > Figma2Mobile Local\n\n");
371
- if (hasSkill)
372
- out(
373
- `Native-layout implementation skill: ${path.join(target, "skills")}\n\n`,
374
- );
422
+ out(`${guide}\n\n`);
375
423
  process.exit(0);
376
424
  }
377
425