figma2mobile-local 0.1.0 → 0.1.2
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 +5 -3
- package/integrity.json +2 -2
- package/loader.cjs +130 -78
- package/main.obf.cjs +1 -1
- package/package.json +3 -2
- package/plugin/dist/code.js +1 -1
- package/plugin/src/ui.html +48 -213
package/README.md
CHANGED
|
@@ -280,9 +280,11 @@ code must ultimately run on the user's machine.
|
|
|
280
280
|
|
|
281
281
|
## License
|
|
282
282
|
|
|
283
|
-
**UNLICENSED — proprietary.**
|
|
284
|
-
derivative works
|
|
283
|
+
**UNLICENSED — proprietary.** This software is **not open source**, and no license is granted to
|
|
284
|
+
copy, modify, redistribute, or create derivative works from it. By installing and using it, you
|
|
285
|
+
agree to these terms. You are welcome to trust the package as-is, or to freely inspect it for
|
|
286
|
+
malware — either is fine.
|
|
285
287
|
|
|
286
288
|
---
|
|
287
289
|
|
|
288
|
-
Node ≥ 18. Build:
|
|
290
|
+
Node ≥ 18. Build: c4bc4eb-20260730233332
|
package/integrity.json
CHANGED
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 = "
|
|
19
|
+
const BUILD_ID = "c4bc4eb-20260730233332"; // 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
|
|
|
@@ -29,24 +29,25 @@ const sha256 = (file) =>
|
|
|
29
29
|
|
|
30
30
|
function readManifest() {
|
|
31
31
|
const p = path.join(ROOT, "integrity.json");
|
|
32
|
-
if (!fs.existsSync(p))
|
|
32
|
+
if (!fs.existsSync(p))
|
|
33
|
+
die("integrity.json missing — package broken, reinstall.");
|
|
33
34
|
let m;
|
|
34
35
|
try {
|
|
35
36
|
m = JSON.parse(fs.readFileSync(p, "utf8"));
|
|
36
37
|
} catch {
|
|
37
|
-
die("integrity.json
|
|
38
|
+
die("integrity.json unreadable — package broken.");
|
|
38
39
|
}
|
|
39
40
|
// Fingerprint: loader va bundle phai cung build (chong tro doi).
|
|
40
41
|
if (m.buildId !== BUILD_ID)
|
|
41
42
|
die(
|
|
42
|
-
`build mismatch: loader=${BUILD_ID} bundle=${m.buildId}. Loader
|
|
43
|
+
`build mismatch: loader=${BUILD_ID} bundle=${m.buildId}. Loader and bundle are from different builds — refusing to run.`,
|
|
43
44
|
);
|
|
44
45
|
// Integrity: bundle obfuscated khong bi sua.
|
|
45
|
-
if (!fs.existsSync(BUNDLE)) die("main.obf.cjs missing —
|
|
46
|
+
if (!fs.existsSync(BUNDLE)) die("main.obf.cjs missing — package broken.");
|
|
46
47
|
const got = sha256(BUNDLE);
|
|
47
48
|
if (m.bundleSha256 && got !== m.bundleSha256)
|
|
48
49
|
die(
|
|
49
|
-
`integrity fail: main.obf.cjs
|
|
50
|
+
`integrity fail: main.obf.cjs was modified (${got.slice(0, 12)} != ${String(m.bundleSha256).slice(0, 12)}).`,
|
|
50
51
|
);
|
|
51
52
|
return m;
|
|
52
53
|
}
|
|
@@ -89,7 +90,7 @@ function loadViaBytecode() {
|
|
|
89
90
|
process.stderr.write(
|
|
90
91
|
`[figma2mobile-local] bytecode unavailable (${
|
|
91
92
|
err?.message ? err.message : err
|
|
92
|
-
});
|
|
93
|
+
}); running obfuscated JS directly.\n`,
|
|
93
94
|
);
|
|
94
95
|
return false;
|
|
95
96
|
}
|
|
@@ -122,7 +123,7 @@ const AGENTS = [
|
|
|
122
123
|
file: path.join(home, ".claude.json"),
|
|
123
124
|
key: "mcpServers",
|
|
124
125
|
skills: path.join(home, ".claude", "skills"),
|
|
125
|
-
manual: `File: ~/.claude.json (
|
|
126
|
+
manual: `File: ~/.claude.json (or run: claude mcp add ${MCP_NAME} -- npx -y figma2mobile-local)`,
|
|
126
127
|
},
|
|
127
128
|
{
|
|
128
129
|
id: "cursor",
|
|
@@ -131,8 +132,7 @@ const AGENTS = [
|
|
|
131
132
|
file: path.join(home, ".cursor", "mcp.json"),
|
|
132
133
|
key: "mcpServers",
|
|
133
134
|
skills: null,
|
|
134
|
-
manual:
|
|
135
|
-
"File global: ~/.cursor/mcp.json (hoac per-project: .cursor/mcp.json)",
|
|
135
|
+
manual: "Global: ~/.cursor/mcp.json (or per-project: .cursor/mcp.json)",
|
|
136
136
|
},
|
|
137
137
|
{
|
|
138
138
|
id: "codex",
|
|
@@ -172,7 +172,7 @@ function writeJsonMcp(agent) {
|
|
|
172
172
|
cfg = JSON.parse(fs.readFileSync(agent.file, "utf8") || "{}");
|
|
173
173
|
} catch {
|
|
174
174
|
throw new Error(
|
|
175
|
-
`${agent.file}
|
|
175
|
+
`${agent.file} is not valid JSON — refusing to overwrite.`,
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
@@ -241,13 +241,26 @@ function parseArgs(args) {
|
|
|
241
241
|
return { ids, yes, outDir };
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
|
|
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
|
-
out(
|
|
257
|
+
out(
|
|
258
|
+
"\nSelect agent(s) to register the MCP server (auto-writes config, with backup):\n",
|
|
259
|
+
);
|
|
247
260
|
AGENTS.forEach((a, i) => out(` ${i + 1}. ${a.label}\n`));
|
|
248
|
-
out(" a.
|
|
261
|
+
out(" a. All\n");
|
|
249
262
|
const raw = (
|
|
250
|
-
await ask("
|
|
263
|
+
await ask("Enter numbers (e.g. 1,3), 'a' for all, or press Enter for all: ")
|
|
251
264
|
).toLowerCase();
|
|
252
265
|
if (!raw || raw === "a" || raw === "all") return AGENTS.slice();
|
|
253
266
|
const picked = [];
|
|
@@ -262,20 +275,77 @@ async function pickAgents() {
|
|
|
262
275
|
return picked;
|
|
263
276
|
}
|
|
264
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
|
+
|
|
265
330
|
async function installPlugin(args) {
|
|
266
331
|
const out = process.stdout.write.bind(process.stdout);
|
|
267
332
|
const { ids, yes, outDir } = parseArgs(args);
|
|
268
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;
|
|
269
337
|
|
|
270
|
-
|
|
338
|
+
if (clack) clack.intro("figma2mobile-local · install");
|
|
339
|
+
|
|
340
|
+
// 1. Extract plugin + skill.
|
|
271
341
|
const pluginSrc = path.join(ROOT, "plugin");
|
|
272
|
-
if (!fs.existsSync(pluginSrc)) die("
|
|
342
|
+
if (!fs.existsSync(pluginSrc)) die("plugin/ folder missing from package.");
|
|
273
343
|
copyDir(pluginSrc, path.join(target, "plugin"));
|
|
274
344
|
const skillSrc = path.join(ROOT, "skills");
|
|
275
345
|
const hasSkill = fs.existsSync(skillSrc);
|
|
276
346
|
if (hasSkill) copyDir(skillSrc, path.join(target, "skills"));
|
|
277
347
|
|
|
278
|
-
// 2.
|
|
348
|
+
// 2. Pick agents: flags -> use directly; interactive -> clack menu (or readline).
|
|
279
349
|
let selected = [];
|
|
280
350
|
if (ids) {
|
|
281
351
|
if (ids.includes("all")) selected = AGENTS.slice();
|
|
@@ -283,20 +353,24 @@ async function installPlugin(args) {
|
|
|
283
353
|
for (const id of ids) {
|
|
284
354
|
const a = AGENTS.find((x) => x.id === id);
|
|
285
355
|
if (a) selected.push(a);
|
|
286
|
-
else out(` (
|
|
356
|
+
else out(` (skipping unsupported agent: ${id})\n`);
|
|
287
357
|
}
|
|
288
358
|
}
|
|
289
|
-
} else if (
|
|
290
|
-
selected = await
|
|
359
|
+
} else if (clack) {
|
|
360
|
+
selected = await pickAgentsClack(clack);
|
|
361
|
+
} else if (interactive) {
|
|
362
|
+
selected = await pickAgentsPlain();
|
|
291
363
|
}
|
|
292
364
|
|
|
293
|
-
// 3.
|
|
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");
|
|
294
368
|
const results = [];
|
|
295
369
|
for (const agent of selected) {
|
|
296
370
|
try {
|
|
297
371
|
const state = registerAgent(agent);
|
|
298
|
-
// skillSrc
|
|
299
|
-
//
|
|
372
|
+
// skillSrc already contains `figma-mobile-implementation/` -> copy straight
|
|
373
|
+
// into <agent.skills>/ giving <skills>/figma-mobile-implementation/SKILL.md.
|
|
300
374
|
if (hasSkill && agent.skills) copyDir(skillSrc, agent.skills);
|
|
301
375
|
results.push({ agent, state });
|
|
302
376
|
} catch (err) {
|
|
@@ -306,68 +380,46 @@ async function installPlugin(args) {
|
|
|
306
380
|
});
|
|
307
381
|
}
|
|
308
382
|
}
|
|
383
|
+
if (spin) spin.stop("MCP config written");
|
|
309
384
|
|
|
310
|
-
// 4.
|
|
385
|
+
// 4. Report + guide.
|
|
311
386
|
const manifestPath = path.join(target, "plugin", "manifest.json");
|
|
312
|
-
|
|
313
|
-
|
|
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
|
+
}
|
|
314
410
|
|
|
411
|
+
// Plain output (flags / no-TTY / clack unavailable).
|
|
412
|
+
out("\n✓ Plugin + skill extracted to:\n");
|
|
413
|
+
out(` ${target}\n\n`);
|
|
315
414
|
if (results.length) {
|
|
316
|
-
out("MCP
|
|
415
|
+
out("MCP registered (existing files backed up as .bak-<timestamp>):\n");
|
|
317
416
|
for (const r of results) {
|
|
318
417
|
if (r.error) out(` ✗ ${r.agent.label}: ${r.error}\n`);
|
|
319
|
-
else {
|
|
320
|
-
const verb =
|
|
321
|
-
r.state === "added"
|
|
322
|
-
? "them"
|
|
323
|
-
: r.state === "updated"
|
|
324
|
-
? "cap nhat"
|
|
325
|
-
: "da co san";
|
|
326
|
-
out(` ✓ ${r.agent.label}: ${verb} -> ${r.agent.file}\n`);
|
|
327
|
-
}
|
|
418
|
+
else out(` ✓ ${r.agent.label}: ${verbOf(r.state)} -> ${r.agent.file}\n`);
|
|
328
419
|
}
|
|
329
|
-
out("\n
|
|
420
|
+
out("\n Restart the agent to load the new MCP server.\n\n");
|
|
330
421
|
}
|
|
331
|
-
|
|
332
|
-
// 5. Huong dan thu cong (moi agent) — de doi chieu / cai tay.
|
|
333
|
-
// JSON + TOML derive tu MCP_ENTRY -> tren Windows tu hien bien the `cmd /c`.
|
|
334
|
-
const jsonEntry = JSON.stringify(
|
|
335
|
-
{ mcpServers: { [MCP_NAME]: MCP_ENTRY } },
|
|
336
|
-
null,
|
|
337
|
-
2,
|
|
338
|
-
)
|
|
339
|
-
.split("\n")
|
|
340
|
-
.map((l) => ` ${l}`)
|
|
341
|
-
.join("\n");
|
|
342
|
-
const tomlArgs = MCP_ENTRY.args.map((a) => JSON.stringify(a)).join(", ");
|
|
343
|
-
out(
|
|
344
|
-
`Cai thu cong (agent khac, hoac de doi chieu)${IS_WIN ? " [Windows]" : ""}:\n`,
|
|
345
|
-
);
|
|
346
|
-
out(" MCP config JSON:\n");
|
|
347
|
-
out(`${jsonEntry}\n\n`);
|
|
348
|
-
for (const a of AGENTS) out(` ${a.label.padEnd(12)} ${a.manual}\n`);
|
|
349
|
-
out(
|
|
350
|
-
" Claude Desktop File: (macOS) ~/Library/Application Support/Claude/claude_desktop_config.json\n",
|
|
351
|
-
);
|
|
352
|
-
out(
|
|
353
|
-
" (Windows) %APPDATA%\\Claude\\claude_desktop_config.json\n",
|
|
354
|
-
);
|
|
355
|
-
out(
|
|
356
|
-
" (Linux) ~/.config/Claude/claude_desktop_config.json\n",
|
|
357
|
-
);
|
|
358
|
-
out(" Codex TOML block:\n");
|
|
359
|
-
out(` [mcp_servers.${MCP_NAME}]\n`);
|
|
360
|
-
out(` command = ${JSON.stringify(MCP_ENTRY.command)}\n`);
|
|
361
|
-
out(` args = [${tomlArgs}]\n\n`);
|
|
362
|
-
|
|
363
|
-
// 6. Figma import (chung cho moi agent).
|
|
364
|
-
out("Import plugin vao Figma Desktop:\n");
|
|
365
|
-
out(" 1. Mo Figma Desktop (Figma web KHONG goi duoc localhost).\n");
|
|
366
|
-
out(" 2. Menu > Plugins > Development > Import plugin from manifest...\n");
|
|
367
|
-
out(` 3. Chon: ${manifestPath}\n`);
|
|
368
|
-
out(" 4. Chay: Plugins > Development > Figma2Mobile Local\n\n");
|
|
369
|
-
if (hasSkill)
|
|
370
|
-
out(`Skill huong dan layout native: ${path.join(target, "skills")}\n\n`);
|
|
422
|
+
out(`${guide}\n\n`);
|
|
371
423
|
process.exit(0);
|
|
372
424
|
}
|
|
373
425
|
|