@trustless-work/blocks 0.0.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.
Files changed (74) hide show
  1. package/README.md +96 -0
  2. package/bin/index.js +1123 -0
  3. package/package.json +44 -0
  4. package/templates/deps.json +29 -0
  5. package/templates/escrows/details/Actions.tsx +149 -0
  6. package/templates/escrows/details/Entities.tsx +48 -0
  7. package/templates/escrows/details/EntityCard.tsx +98 -0
  8. package/templates/escrows/details/EscrowDetailDialog.tsx +154 -0
  9. package/templates/escrows/details/GeneralInformation.tsx +329 -0
  10. package/templates/escrows/details/MilestoneCard.tsx +254 -0
  11. package/templates/escrows/details/MilestoneDetailDialog.tsx +276 -0
  12. package/templates/escrows/details/Milestones.tsx +87 -0
  13. package/templates/escrows/details/ProgressEscrow.tsx +191 -0
  14. package/templates/escrows/details/StatisticsCard.tsx +79 -0
  15. package/templates/escrows/details/SuccessReleaseDialog.tsx +101 -0
  16. package/templates/escrows/details/useDetailsEscrow.ts +126 -0
  17. package/templates/escrows/escrow-context/EscrowAmountProvider.tsx +86 -0
  18. package/templates/escrows/escrow-context/EscrowDialogsProvider.tsx +108 -0
  19. package/templates/escrows/escrow-context/EscrowProvider.tsx +124 -0
  20. package/templates/escrows/escrows-by-role/cards/EscrowsCards.tsx +503 -0
  21. package/templates/escrows/escrows-by-role/cards/Filters.tsx +421 -0
  22. package/templates/escrows/escrows-by-role/table/EscrowsTable.tsx +427 -0
  23. package/templates/escrows/escrows-by-role/table/Filters.tsx +421 -0
  24. package/templates/escrows/escrows-by-role/useEscrowsByRole.shared.ts +336 -0
  25. package/templates/escrows/escrows-by-signer/cards/EscrowsCards.tsx +502 -0
  26. package/templates/escrows/escrows-by-signer/cards/Filters.tsx +389 -0
  27. package/templates/escrows/escrows-by-signer/table/EscrowsTable.tsx +422 -0
  28. package/templates/escrows/escrows-by-signer/table/Filters.tsx +389 -0
  29. package/templates/escrows/escrows-by-signer/useEscrowsBySigner.shared.ts +320 -0
  30. package/templates/escrows/single-release/approve-milestone/button/ApproveMilestone.tsx +78 -0
  31. package/templates/escrows/single-release/approve-milestone/dialog/ApproveMilestone.tsx +102 -0
  32. package/templates/escrows/single-release/approve-milestone/form/ApproveMilestone.tsx +80 -0
  33. package/templates/escrows/single-release/approve-milestone/shared/schema.ts +9 -0
  34. package/templates/escrows/single-release/approve-milestone/shared/useApproveMilestone.ts +67 -0
  35. package/templates/escrows/single-release/change-milestone-status/button/ChangeMilestoneStatus.tsx +78 -0
  36. package/templates/escrows/single-release/change-milestone-status/dialog/ChangeMilestoneStatus.tsx +167 -0
  37. package/templates/escrows/single-release/change-milestone-status/form/ChangeMilestoneStatus.tsx +114 -0
  38. package/templates/escrows/single-release/change-milestone-status/shared/schema.ts +15 -0
  39. package/templates/escrows/single-release/change-milestone-status/shared/useChangeMilestoneStatus.ts +77 -0
  40. package/templates/escrows/single-release/dispute-escrow/button/DisputeEscrow.tsx +68 -0
  41. package/templates/escrows/single-release/fund-escrow/button/FundEscrow.tsx +84 -0
  42. package/templates/escrows/single-release/fund-escrow/dialog/FundEscrow.tsx +77 -0
  43. package/templates/escrows/single-release/fund-escrow/form/FundEscrow.tsx +54 -0
  44. package/templates/escrows/single-release/fund-escrow/shared/schema.ts +10 -0
  45. package/templates/escrows/single-release/fund-escrow/shared/useFundEscrow.ts +66 -0
  46. package/templates/escrows/single-release/initialize-escrow/dialog/InitializeEscrow.tsx +526 -0
  47. package/templates/escrows/single-release/initialize-escrow/form/InitializeEscrow.tsx +504 -0
  48. package/templates/escrows/single-release/initialize-escrow/shared/schema.ts +232 -0
  49. package/templates/escrows/single-release/initialize-escrow/shared/useInitializeEscrow.ts +115 -0
  50. package/templates/escrows/single-release/release-escrow/button/ReleaseEscrow.tsx +80 -0
  51. package/templates/escrows/single-release/resolve-dispute/button/ResolveDispute.tsx +94 -0
  52. package/templates/escrows/single-release/resolve-dispute/dialog/ResolveDispute.tsx +123 -0
  53. package/templates/escrows/single-release/resolve-dispute/form/ResolveDispute.tsx +82 -0
  54. package/templates/escrows/single-release/resolve-dispute/shared/schema.ts +82 -0
  55. package/templates/escrows/single-release/resolve-dispute/shared/useResolveDispute.ts +58 -0
  56. package/templates/escrows/single-release/update-escrow/dialog/UpdateEscrow.tsx +485 -0
  57. package/templates/escrows/single-release/update-escrow/form/UpdateEscrow.tsx +463 -0
  58. package/templates/escrows/single-release/update-escrow/shared/schema.ts +139 -0
  59. package/templates/escrows/single-release/update-escrow/shared/useUpdateEscrow.ts +211 -0
  60. package/templates/handle-errors/errors.enum.ts +6 -0
  61. package/templates/handle-errors/handle.ts +47 -0
  62. package/templates/helpers/format.helper.ts +27 -0
  63. package/templates/helpers/useCopy.ts +13 -0
  64. package/templates/providers/ReactQueryClientProvider.tsx +28 -0
  65. package/templates/providers/TrustlessWork.tsx +30 -0
  66. package/templates/tanstak/useEscrowsByRoleQuery.ts +87 -0
  67. package/templates/tanstak/useEscrowsBySignerQuery.ts +78 -0
  68. package/templates/tanstak/useEscrowsMutations.ts +411 -0
  69. package/templates/wallet-kit/WalletButtons.tsx +116 -0
  70. package/templates/wallet-kit/WalletProvider.tsx +94 -0
  71. package/templates/wallet-kit/trustlines.ts +40 -0
  72. package/templates/wallet-kit/useWallet.ts +77 -0
  73. package/templates/wallet-kit/validators.ts +12 -0
  74. package/templates/wallet-kit/wallet-kit.ts +30 -0
package/bin/index.js ADDED
@@ -0,0 +1,1123 @@
1
+ #!/usr/bin/env node
2
+
3
+ /*
4
+ AUTHOR: @trustless-work / Joel Vargas
5
+ COPYRIGHT: 2025 Trustless Work
6
+ LICENSE: MIT
7
+ VERSION: 1.0.0
8
+ */
9
+
10
+ import fs from "node:fs";
11
+ import path from "node:path";
12
+ import { fileURLToPath } from "node:url";
13
+ import { spawnSync, spawn } from "node:child_process";
14
+ import readline from "node:readline";
15
+
16
+ const __filename = fileURLToPath(import.meta.url);
17
+ const __dirname = path.dirname(__filename);
18
+
19
+ const PROJECT_ROOT = process.cwd();
20
+ const TEMPLATES_DIR = path.join(__dirname, "..", "templates");
21
+ const GLOBAL_DEPS_FILE = path.join(TEMPLATES_DIR, "deps.json");
22
+
23
+ const args = process.argv.slice(2);
24
+
25
+ function detectPM() {
26
+ if (fs.existsSync(path.join(PROJECT_ROOT, "pnpm-lock.yaml"))) return "pnpm";
27
+ if (fs.existsSync(path.join(PROJECT_ROOT, "yarn.lock"))) return "yarn";
28
+ if (fs.existsSync(path.join(PROJECT_ROOT, "bun.lockb"))) return "bun";
29
+ return "npm";
30
+ }
31
+
32
+ function run(cmd, args) {
33
+ const r = spawnSync(cmd, args.filter(Boolean), {
34
+ stdio: "inherit",
35
+ cwd: PROJECT_ROOT,
36
+ shell: true,
37
+ });
38
+ if (r.status !== 0) process.exit(r.status ?? 1);
39
+ }
40
+
41
+ function tryRun(cmd, args, errorMessage) {
42
+ const r = spawnSync(cmd, args.filter(Boolean), {
43
+ stdio: "inherit",
44
+ cwd: PROJECT_ROOT,
45
+ shell: true,
46
+ });
47
+ if (r.status !== 0) {
48
+ console.error(errorMessage);
49
+ process.exit(r.status ?? 1);
50
+ }
51
+ }
52
+
53
+ async function runAsync(cmd, args) {
54
+ return new Promise((resolve, reject) => {
55
+ const child = spawn(cmd, args.filter(Boolean), {
56
+ stdio: "inherit",
57
+ cwd: PROJECT_ROOT,
58
+ shell: true,
59
+ });
60
+ child.on("close", (code) => {
61
+ if (code === 0) resolve();
62
+ else reject(new Error(`${cmd} exited with code ${code}`));
63
+ });
64
+ });
65
+ }
66
+
67
+ const COLORS = {
68
+ reset: "\x1b[0m",
69
+ green: "\x1b[32m",
70
+ gray: "\x1b[90m",
71
+ blueTW: "\x1b[38;2;0;107;228m",
72
+ };
73
+
74
+ function logCheck(message) {
75
+ console.log(`${COLORS.green}✔${COLORS.reset} ${message}`);
76
+ }
77
+
78
+ function startSpinner(message) {
79
+ const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
80
+ let i = 0;
81
+ process.stdout.write(`${frames[0]} ${message}`);
82
+ const timer = setInterval(() => {
83
+ i = (i + 1) % frames.length;
84
+ process.stdout.write(`\r${frames[i]} ${message}`);
85
+ }, 80);
86
+ return () => {
87
+ clearInterval(timer);
88
+ process.stdout.write("\r");
89
+ };
90
+ }
91
+
92
+ async function withSpinner(message, fn) {
93
+ const stop = startSpinner(message);
94
+ try {
95
+ await fn();
96
+ stop();
97
+ logCheck(message);
98
+ } catch (err) {
99
+ stop();
100
+ throw err;
101
+ }
102
+ }
103
+
104
+ async function promptYesNo(question, def = true) {
105
+ const rl = readline.createInterface({
106
+ input: process.stdin,
107
+ output: process.stdout,
108
+ });
109
+ const suffix = def ? "(Y/n)" : "(y/N)";
110
+ const answer = await new Promise((res) =>
111
+ rl.question(`${question} ${suffix} `, (ans) => res(ans))
112
+ );
113
+ rl.close();
114
+ const a = String(answer).trim().toLowerCase();
115
+ if (!a) return def;
116
+ return a.startsWith("y");
117
+ }
118
+
119
+ function oscHyperlink(text, url) {
120
+ return `\x1b]8;;${url}\x1b\\${text}\x1b]8;;\x1b\\`;
121
+ }
122
+
123
+ function printBannerTRUSTLESSWORK() {
124
+ const map = {
125
+ T: ["******", " ** ", " ** ", " ** ", " ** "],
126
+ R: ["***** ", "** **", "***** ", "** ** ", "** **"],
127
+ U: ["** **", "** **", "** **", "** **", " **** "],
128
+ S: [" **** ", "** ", " **** ", " **", " **** "],
129
+ L: ["** ", "** ", "** ", "** ", "******"],
130
+ E: ["******", "** ", "***** ", "** ", "******"],
131
+ W: ["** **", "** **", "** * **", "*** ***", "** **"],
132
+ O: [" **** ", "** **", "** **", "** **", " **** "],
133
+ K: ["** **", "** ** ", "**** ", "** ** ", "** **"],
134
+ " ": [" ", " ", " ", " ", " "],
135
+ };
136
+ const text = "TRUSTLESS WORK";
137
+ const rows = ["", "", "", "", ""];
138
+ for (const ch of text) {
139
+ const glyph = map[ch] || map[" "];
140
+ for (let i = 0; i < 5; i++) {
141
+ rows[i] += glyph[i] + " ";
142
+ }
143
+ }
144
+ console.log("\n\n");
145
+ for (const line of rows) {
146
+ console.log(`${COLORS.blueTW}${line}${COLORS.reset}`);
147
+ }
148
+ }
149
+
150
+ function readProjectPackageJson() {
151
+ const pkgPath = path.join(PROJECT_ROOT, "package.json");
152
+ if (!fs.existsSync(pkgPath)) return null;
153
+ try {
154
+ return JSON.parse(fs.readFileSync(pkgPath, "utf8"));
155
+ } catch {
156
+ return null;
157
+ }
158
+ }
159
+
160
+ function installDeps({ dependencies = {}, devDependencies = {} }) {
161
+ const pm = detectPM();
162
+ const BLOCKED = new Set([
163
+ "tailwindcss",
164
+ "@tailwindcss/cli",
165
+ "@tailwindcss/postcss",
166
+ "@tailwindcss/vite",
167
+ "postcss",
168
+ "autoprefixer",
169
+ "postcss-import",
170
+ ]);
171
+ const depList = Object.entries(dependencies)
172
+ .filter(([k]) => !BLOCKED.has(k))
173
+ .map(([k, v]) => `${k}@${v}`);
174
+ const devList = Object.entries(devDependencies)
175
+ .filter(([k]) => !BLOCKED.has(k))
176
+ .map(([k, v]) => `${k}@${v}`);
177
+
178
+ if (depList.length) {
179
+ if (pm === "pnpm") run("pnpm", ["add", ...depList]);
180
+ else if (pm === "yarn") run("yarn", ["add", ...depList]);
181
+ else if (pm === "bun") run("bun", ["add", ...depList]);
182
+ else run("npm", ["install", ...depList]);
183
+ }
184
+
185
+ if (devList.length) {
186
+ if (pm === "pnpm") run("pnpm", ["add", "-D", ...devList]);
187
+ else if (pm === "yarn") run("yarn", ["add", "-D", ...devList]);
188
+ else if (pm === "bun") run("bun", ["add", "-d", ...devList]);
189
+ else run("npm", ["install", "-D", ...devList]);
190
+ }
191
+ }
192
+
193
+ function loadConfig() {
194
+ const cfgPath = path.join(PROJECT_ROOT, ".twblocks.json");
195
+ if (fs.existsSync(cfgPath)) {
196
+ try {
197
+ return JSON.parse(fs.readFileSync(cfgPath, "utf8"));
198
+ } catch (e) {
199
+ console.warn("⚠️ Failed to parse .twblocks.json, ignoring.");
200
+ }
201
+ }
202
+ return {};
203
+ }
204
+
205
+ function parseFlags(argv) {
206
+ const flags = {};
207
+ for (let i = 0; i < argv.length; i++) {
208
+ const a = argv[i];
209
+ if (a.startsWith("--ui-base=")) {
210
+ flags.uiBase = a.split("=").slice(1).join("=");
211
+ } else if (a === "--ui-base") {
212
+ flags.uiBase = argv[i + 1];
213
+ i++;
214
+ } else if (a === "--install" || a === "-i") {
215
+ flags.install = true;
216
+ }
217
+ }
218
+ return flags;
219
+ }
220
+
221
+ function copyTemplate(name, { uiBase, shouldInstall = false } = {}) {
222
+ const srcFile = path.join(TEMPLATES_DIR, `${name}.tsx`);
223
+ const srcDir = path.join(TEMPLATES_DIR, name);
224
+ const outRoot = path.join(PROJECT_ROOT, "src", "components", "tw-blocks");
225
+
226
+ const config = loadConfig();
227
+ const effectiveUiBase = uiBase || config.uiBase || "@/components/ui";
228
+
229
+ function writeTransformed(srcPath, destPath) {
230
+ const raw = fs.readFileSync(srcPath, "utf8");
231
+ const transformed = raw.replaceAll("__UI_BASE__", effectiveUiBase);
232
+ fs.mkdirSync(path.dirname(destPath), { recursive: true });
233
+ fs.writeFileSync(destPath, transformed, "utf8");
234
+ console.log(`✅ ${path.relative(PROJECT_ROOT, destPath)} created`);
235
+ }
236
+
237
+ if (fs.existsSync(srcDir) && fs.lstatSync(srcDir).isDirectory()) {
238
+ const skipDetails =
239
+ name === "escrows/escrows-by-role" ||
240
+ name === "escrows/escrows-by-signer" ||
241
+ name === "escrows";
242
+ // Copy directory recursively
243
+ const destDir = path.join(outRoot, name);
244
+ fs.mkdirSync(destDir, { recursive: true });
245
+ const stack = [""];
246
+ while (stack.length) {
247
+ const rel = stack.pop();
248
+ const current = path.join(srcDir, rel);
249
+ const entries = fs.readdirSync(current, { withFileTypes: true });
250
+ for (const entry of entries) {
251
+ const entryRel = path.join(rel, entry.name);
252
+ // Skip copying any shared directory at any depth
253
+ const parts = entryRel.split(path.sep);
254
+ if (parts.includes("shared")) {
255
+ continue;
256
+ }
257
+ if (skipDetails) {
258
+ const top = parts[0] || "";
259
+ const firstTwo = parts.slice(0, 2).join(path.sep);
260
+ if (
261
+ top === "details" ||
262
+ firstTwo === path.join("escrows-by-role", "details") ||
263
+ firstTwo === path.join("escrows-by-signer", "details")
264
+ ) {
265
+ continue;
266
+ }
267
+ }
268
+ const entrySrc = path.join(srcDir, entryRel);
269
+ const entryDest = path.join(destDir, entryRel);
270
+ if (entry.isDirectory()) {
271
+ stack.push(entryRel);
272
+ continue;
273
+ }
274
+ // Only process text files (.ts, .tsx, .js, .jsx)
275
+ if (/\.(tsx?|jsx?)$/i.test(entry.name)) {
276
+ writeTransformed(entrySrc, entryDest);
277
+ } else {
278
+ fs.mkdirSync(path.dirname(entryDest), { recursive: true });
279
+ fs.copyFileSync(entrySrc, entryDest);
280
+ console.log(`✅ ${path.relative(PROJECT_ROOT, entryDest)} created`);
281
+ }
282
+ }
283
+ }
284
+
285
+ // Post-copy: materialize shared initialize-escrow files into dialog/form
286
+ try {
287
+ const isSingleReleaseInitRoot =
288
+ name === "escrows/single-release/initialize-escrow";
289
+ const isSingleReleaseInitDialog =
290
+ name === "escrows/single-release/initialize-escrow/dialog";
291
+ const isSingleReleaseInitForm =
292
+ name === "escrows/single-release/initialize-escrow/form";
293
+
294
+ const srcSharedDir = path.join(
295
+ TEMPLATES_DIR,
296
+ "escrows",
297
+ "single-release",
298
+ "initialize-escrow",
299
+ "shared"
300
+ );
301
+
302
+ function copySharedInto(targetDir) {
303
+ if (!fs.existsSync(srcSharedDir)) return;
304
+ const entries = fs.readdirSync(srcSharedDir, { withFileTypes: true });
305
+ for (const entry of entries) {
306
+ if (!/\.(tsx?|jsx?)$/i.test(entry.name)) continue;
307
+ const entrySrc = path.join(srcSharedDir, entry.name);
308
+ const entryDest = path.join(targetDir, entry.name);
309
+ writeTransformed(entrySrc, entryDest);
310
+ }
311
+ }
312
+
313
+ if (isSingleReleaseInitRoot) {
314
+ copySharedInto(path.join(destDir, "dialog"));
315
+ copySharedInto(path.join(destDir, "form"));
316
+ } else if (isSingleReleaseInitDialog) {
317
+ copySharedInto(destDir);
318
+ } else if (isSingleReleaseInitForm) {
319
+ copySharedInto(destDir);
320
+ }
321
+ } catch (e) {
322
+ console.warn(
323
+ "⚠️ Failed to materialize shared initialize-escrow files:",
324
+ e?.message || e
325
+ );
326
+ }
327
+
328
+ try {
329
+ const isSingleReleaseInitRoot =
330
+ name === "escrows/single-release/approve-milestone";
331
+ const isSingleReleaseInitDialog =
332
+ name === "escrows/single-release/approve-milestone/dialog";
333
+ const isSingleReleaseInitForm =
334
+ name === "escrows/single-release/approve-milestone/form";
335
+
336
+ const srcSharedDir = path.join(
337
+ TEMPLATES_DIR,
338
+ "escrows",
339
+ "single-release",
340
+ "approve-milestone",
341
+ "shared"
342
+ );
343
+
344
+ function copySharedInto(targetDir) {
345
+ if (!fs.existsSync(srcSharedDir)) return;
346
+ const entries = fs.readdirSync(srcSharedDir, { withFileTypes: true });
347
+ for (const entry of entries) {
348
+ if (!/\.(tsx?|jsx?)$/i.test(entry.name)) continue;
349
+ const entrySrc = path.join(srcSharedDir, entry.name);
350
+ const entryDest = path.join(targetDir, entry.name);
351
+ writeTransformed(entrySrc, entryDest);
352
+ }
353
+ }
354
+
355
+ if (isSingleReleaseInitRoot) {
356
+ copySharedInto(path.join(destDir, "dialog"));
357
+ copySharedInto(path.join(destDir, "form"));
358
+ } else if (isSingleReleaseInitDialog) {
359
+ copySharedInto(destDir);
360
+ } else if (isSingleReleaseInitForm) {
361
+ copySharedInto(destDir);
362
+ }
363
+ } catch (e) {
364
+ console.warn(
365
+ "⚠️ Failed to materialize shared approve-milestone files:",
366
+ e?.message || e
367
+ );
368
+ }
369
+
370
+ try {
371
+ const isSingleReleaseInitRoot =
372
+ name === "escrows/single-release/change-milestone-status";
373
+ const isSingleReleaseInitDialog =
374
+ name === "escrows/single-release/change-milestone-status/dialog";
375
+ const isSingleReleaseInitForm =
376
+ name === "escrows/single-release/change-milestone-status/form";
377
+
378
+ const srcSharedDir = path.join(
379
+ TEMPLATES_DIR,
380
+ "escrows",
381
+ "single-release",
382
+ "change-milestone-status",
383
+ "shared"
384
+ );
385
+
386
+ function copySharedInto(targetDir) {
387
+ if (!fs.existsSync(srcSharedDir)) return;
388
+ const entries = fs.readdirSync(srcSharedDir, { withFileTypes: true });
389
+ for (const entry of entries) {
390
+ if (!/\.(tsx?|jsx?)$/i.test(entry.name)) continue;
391
+ const entrySrc = path.join(srcSharedDir, entry.name);
392
+ const entryDest = path.join(targetDir, entry.name);
393
+ writeTransformed(entrySrc, entryDest);
394
+ }
395
+ }
396
+
397
+ if (isSingleReleaseInitRoot) {
398
+ copySharedInto(path.join(destDir, "dialog"));
399
+ copySharedInto(path.join(destDir, "form"));
400
+ } else if (isSingleReleaseInitDialog) {
401
+ copySharedInto(destDir);
402
+ } else if (isSingleReleaseInitForm) {
403
+ copySharedInto(destDir);
404
+ }
405
+ } catch (e) {
406
+ console.warn(
407
+ "⚠️ Failed to materialize shared change-milestone-status files:",
408
+ e?.message || e
409
+ );
410
+ }
411
+
412
+ try {
413
+ const isSingleReleaseInitRoot =
414
+ name === "escrows/single-release/fund-escrow";
415
+ const isSingleReleaseInitDialog =
416
+ name === "escrows/single-release/fund-escrow/dialog";
417
+ const isSingleReleaseInitForm =
418
+ name === "escrows/single-release/fund-escrow/form";
419
+
420
+ const srcSharedDir = path.join(
421
+ TEMPLATES_DIR,
422
+ "escrows",
423
+ "single-release",
424
+ "fund-escrow",
425
+ "shared"
426
+ );
427
+
428
+ function copySharedInto(targetDir) {
429
+ if (!fs.existsSync(srcSharedDir)) return;
430
+ const entries = fs.readdirSync(srcSharedDir, { withFileTypes: true });
431
+ for (const entry of entries) {
432
+ if (!/\.(tsx?|jsx?)$/i.test(entry.name)) continue;
433
+ const entrySrc = path.join(srcSharedDir, entry.name);
434
+ const entryDest = path.join(targetDir, entry.name);
435
+ writeTransformed(entrySrc, entryDest);
436
+ }
437
+ }
438
+
439
+ if (isSingleReleaseInitRoot) {
440
+ copySharedInto(path.join(destDir, "dialog"));
441
+ copySharedInto(path.join(destDir, "form"));
442
+ } else if (isSingleReleaseInitDialog) {
443
+ copySharedInto(destDir);
444
+ } else if (isSingleReleaseInitForm) {
445
+ copySharedInto(destDir);
446
+ }
447
+ } catch (e) {
448
+ console.warn(
449
+ "⚠️ Failed to materialize shared fund-escrow files:",
450
+ e?.message || e
451
+ );
452
+ }
453
+
454
+ try {
455
+ const isSingleReleaseInitRoot =
456
+ name === "escrows/single-release/resolve-dispute";
457
+ const isSingleReleaseInitDialog =
458
+ name === "escrows/single-release/resolve-dispute/dialog";
459
+ const isSingleReleaseInitForm =
460
+ name === "escrows/single-release/resolve-dispute/form";
461
+
462
+ const srcSharedDir = path.join(
463
+ TEMPLATES_DIR,
464
+ "escrows",
465
+ "single-release",
466
+ "resolve-dispute",
467
+ "shared"
468
+ );
469
+
470
+ function copySharedInto(targetDir) {
471
+ if (!fs.existsSync(srcSharedDir)) return;
472
+ const entries = fs.readdirSync(srcSharedDir, { withFileTypes: true });
473
+ for (const entry of entries) {
474
+ if (!/\.(tsx?|jsx?)$/i.test(entry.name)) continue;
475
+ const entrySrc = path.join(srcSharedDir, entry.name);
476
+ const entryDest = path.join(targetDir, entry.name);
477
+ writeTransformed(entrySrc, entryDest);
478
+ }
479
+ }
480
+
481
+ if (isSingleReleaseInitRoot) {
482
+ copySharedInto(path.join(destDir, "dialog"));
483
+ copySharedInto(path.join(destDir, "form"));
484
+ } else if (isSingleReleaseInitDialog) {
485
+ copySharedInto(destDir);
486
+ } else if (isSingleReleaseInitForm) {
487
+ copySharedInto(destDir);
488
+ }
489
+ } catch (e) {
490
+ console.warn(
491
+ "⚠️ Failed to materialize shared resolve-dispute files:",
492
+ e?.message || e
493
+ );
494
+ }
495
+
496
+ try {
497
+ const isSingleReleaseInitRoot =
498
+ name === "escrows/single-release/update-escrow";
499
+ const isSingleReleaseInitDialog =
500
+ name === "escrows/single-release/update-escrow/dialog";
501
+ const isSingleReleaseInitForm =
502
+ name === "escrows/single-release/update-escrow/form";
503
+
504
+ const srcSharedDir = path.join(
505
+ TEMPLATES_DIR,
506
+ "escrows",
507
+ "single-release",
508
+ "update-escrow",
509
+ "shared"
510
+ );
511
+
512
+ function copySharedInto(targetDir) {
513
+ if (!fs.existsSync(srcSharedDir)) return;
514
+ const entries = fs.readdirSync(srcSharedDir, { withFileTypes: true });
515
+ for (const entry of entries) {
516
+ if (!/\.(tsx?|jsx?)$/i.test(entry.name)) continue;
517
+ const entrySrc = path.join(srcSharedDir, entry.name);
518
+ const entryDest = path.join(targetDir, entry.name);
519
+ writeTransformed(entrySrc, entryDest);
520
+ }
521
+ }
522
+
523
+ if (isSingleReleaseInitRoot) {
524
+ copySharedInto(path.join(destDir, "dialog"));
525
+ copySharedInto(path.join(destDir, "form"));
526
+ } else if (isSingleReleaseInitDialog) {
527
+ copySharedInto(destDir);
528
+ } else if (isSingleReleaseInitForm) {
529
+ copySharedInto(destDir);
530
+ }
531
+ } catch (e) {
532
+ console.warn(
533
+ "⚠️ Failed to materialize shared update-escrow files:",
534
+ e?.message || e
535
+ );
536
+ }
537
+
538
+ // If adding the whole single-release bundle, materialize all shared files
539
+ try {
540
+ if (name === "escrows/single-release") {
541
+ const modules = [
542
+ "initialize-escrow",
543
+ "approve-milestone",
544
+ "change-milestone-status",
545
+ "fund-escrow",
546
+ "resolve-dispute",
547
+ "update-escrow",
548
+ ];
549
+
550
+ for (const mod of modules) {
551
+ const srcSharedDir = path.join(
552
+ TEMPLATES_DIR,
553
+ "escrows",
554
+ "single-release",
555
+ mod,
556
+ "shared"
557
+ );
558
+ if (!fs.existsSync(srcSharedDir)) continue;
559
+
560
+ const targets = [
561
+ path.join(destDir, mod, "dialog"),
562
+ path.join(destDir, mod, "form"),
563
+ ];
564
+
565
+ const entries = fs.readdirSync(srcSharedDir, { withFileTypes: true });
566
+ for (const entry of entries) {
567
+ if (!/\.(tsx?|jsx?)$/i.test(entry.name)) continue;
568
+ const entrySrc = path.join(srcSharedDir, entry.name);
569
+ for (const t of targets) {
570
+ const entryDest = path.join(t, entry.name);
571
+ writeTransformed(entrySrc, entryDest);
572
+ }
573
+ }
574
+ }
575
+ }
576
+ } catch (e) {
577
+ console.warn(
578
+ "⚠️ Failed to materialize shared files for single-release bundle:",
579
+ e?.message || e
580
+ );
581
+ }
582
+
583
+ // If adding the root escrows bundle, also materialize single-release shared files
584
+ try {
585
+ if (name === "escrows") {
586
+ const modules = [
587
+ "initialize-escrow",
588
+ "approve-milestone",
589
+ "change-milestone-status",
590
+ "fund-escrow",
591
+ "resolve-dispute",
592
+ "update-escrow",
593
+ ];
594
+
595
+ const baseTarget = path.join(destDir, "single-release");
596
+ for (const mod of modules) {
597
+ const srcSharedDir = path.join(
598
+ TEMPLATES_DIR,
599
+ "escrows",
600
+ "single-release",
601
+ mod,
602
+ "shared"
603
+ );
604
+ if (!fs.existsSync(srcSharedDir)) continue;
605
+
606
+ const targets = [
607
+ path.join(baseTarget, mod, "dialog"),
608
+ path.join(baseTarget, mod, "form"),
609
+ ];
610
+
611
+ const entries = fs.readdirSync(srcSharedDir, { withFileTypes: true });
612
+ for (const entry of entries) {
613
+ if (!/\.(tsx?|jsx?)$/i.test(entry.name)) continue;
614
+ const entrySrc = path.join(srcSharedDir, entry.name);
615
+ for (const t of targets) {
616
+ const entryDest = path.join(t, entry.name);
617
+ writeTransformed(entrySrc, entryDest);
618
+ }
619
+ }
620
+ }
621
+ }
622
+ } catch (e) {
623
+ console.warn(
624
+ "⚠️ Failed to materialize shared files for escrows root:",
625
+ e?.message || e
626
+ );
627
+ }
628
+ } else if (fs.existsSync(srcFile)) {
629
+ fs.mkdirSync(outRoot, { recursive: true });
630
+ const destFile = path.join(outRoot, name + ".tsx");
631
+ writeTransformed(srcFile, destFile);
632
+ } else {
633
+ console.error(`❌ The template "${name}" does not exist`);
634
+ process.exit(1);
635
+ }
636
+
637
+ if (shouldInstall && fs.existsSync(GLOBAL_DEPS_FILE)) {
638
+ const meta = JSON.parse(fs.readFileSync(GLOBAL_DEPS_FILE, "utf8"));
639
+ installDeps(meta);
640
+ }
641
+ }
642
+
643
+ function copySharedDetailsInto(targetRelativeDir, { uiBase } = {}) {
644
+ const srcDir = path.join(TEMPLATES_DIR, "escrows", "details");
645
+ const outRoot = path.join(PROJECT_ROOT, "src", "components", "tw-blocks");
646
+ const destDir = path.join(outRoot, targetRelativeDir);
647
+ const config = loadConfig();
648
+ const effectiveUiBase = uiBase || config.uiBase || "@/components/ui";
649
+
650
+ if (!fs.existsSync(srcDir)) return;
651
+ fs.mkdirSync(destDir, { recursive: true });
652
+
653
+ function writeTransformed(srcPath, destPath) {
654
+ const raw = fs.readFileSync(srcPath, "utf8");
655
+ const transformed = raw.replaceAll("__UI_BASE__", effectiveUiBase);
656
+ fs.mkdirSync(path.dirname(destPath), { recursive: true });
657
+ fs.writeFileSync(destPath, transformed, "utf8");
658
+ console.log(`✅ ${path.relative(PROJECT_ROOT, destPath)} created`);
659
+ }
660
+
661
+ const stack = [""];
662
+ while (stack.length) {
663
+ const rel = stack.pop();
664
+ const current = path.join(srcDir, rel);
665
+ const entries = fs.readdirSync(current, { withFileTypes: true });
666
+ for (const entry of entries) {
667
+ const entryRel = path.join(rel, entry.name);
668
+ const entrySrc = path.join(srcDir, entryRel);
669
+ const entryDest = path.join(destDir, entryRel);
670
+ if (entry.isDirectory()) {
671
+ stack.push(entryRel);
672
+ continue;
673
+ }
674
+ if (/\.(tsx?|jsx?)$/i.test(entry.name)) {
675
+ writeTransformed(entrySrc, entryDest);
676
+ } else {
677
+ fs.mkdirSync(path.dirname(entryDest), { recursive: true });
678
+ fs.copyFileSync(entrySrc, entryDest);
679
+ console.log(`✅ ${path.relative(PROJECT_ROOT, entryDest)} created`);
680
+ }
681
+ }
682
+ }
683
+ }
684
+
685
+ function copySharedRoleSignerHooks() {
686
+ const srcDir = path.join(TEMPLATES_DIR, "tanstak");
687
+ const outRoot = path.join(PROJECT_ROOT, "src", "components", "tw-blocks");
688
+
689
+ const files = [
690
+ {
691
+ shared: "useEscrowsByRole.shared.ts",
692
+ targets: [
693
+ path.join(
694
+ outRoot,
695
+ "escrows",
696
+ "escrows-by-role",
697
+ "cards",
698
+ "useEsrowsByRole.ts"
699
+ ),
700
+ path.join(
701
+ outRoot,
702
+ "escrows",
703
+ "escrows-by-role",
704
+ "table",
705
+ "useEsrowsByRole.ts"
706
+ ),
707
+ ],
708
+ },
709
+ {
710
+ shared: "useEscrowsBySigner.shared.ts",
711
+ targets: [
712
+ path.join(
713
+ outRoot,
714
+ "escrows",
715
+ "escrows-by-signer",
716
+ "cards",
717
+ "useEsrowsBySigner.ts"
718
+ ),
719
+ path.join(
720
+ outRoot,
721
+ "escrows",
722
+ "escrows-by-signer",
723
+ "table",
724
+ "useEsrowsBySigner.ts"
725
+ ),
726
+ ],
727
+ },
728
+ ];
729
+
730
+ for (const group of files) {
731
+ const src = path.join(srcDir, group.shared);
732
+ if (!fs.existsSync(src)) continue;
733
+ const raw = fs.readFileSync(src, "utf8");
734
+ for (const dest of group.targets) {
735
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
736
+ fs.writeFileSync(dest, raw, "utf8");
737
+ console.log(`✅ ${path.relative(PROJECT_ROOT, dest)} created`);
738
+ }
739
+ }
740
+ }
741
+
742
+ function findLayoutFile() {
743
+ const candidates = [
744
+ path.join(PROJECT_ROOT, "app", "layout.tsx"),
745
+ path.join(PROJECT_ROOT, "app", "layout.ts"),
746
+ path.join(PROJECT_ROOT, "app", "layout.jsx"),
747
+ path.join(PROJECT_ROOT, "app", "layout.js"),
748
+ path.join(PROJECT_ROOT, "src", "app", "layout.tsx"),
749
+ path.join(PROJECT_ROOT, "src", "app", "layout.ts"),
750
+ path.join(PROJECT_ROOT, "src", "app", "layout.jsx"),
751
+ path.join(PROJECT_ROOT, "src", "app", "layout.js"),
752
+ ];
753
+ return candidates.find((p) => fs.existsSync(p)) || null;
754
+ }
755
+
756
+ function injectProvidersIntoLayout(
757
+ layoutPath,
758
+ { reactQuery = false, trustless = false, wallet = false, escrow = false } = {}
759
+ ) {
760
+ try {
761
+ let content = fs.readFileSync(layoutPath, "utf8");
762
+
763
+ const importRQ =
764
+ 'import { ReactQueryClientProvider } from "@/components/tw-blocks/providers/ReactQueryClientProvider";\n';
765
+ const importTW =
766
+ 'import { TrustlessWorkProvider } from "@/components/tw-blocks/providers/TrustlessWork";\n';
767
+ const importEscrow =
768
+ 'import { EscrowProvider } from "@/components/tw-blocks/escrows/escrow-context/EscrowProvider";\n';
769
+ const importWallet =
770
+ 'import { WalletProvider } from "@/components/tw-blocks/wallet-kit/WalletProvider";\n';
771
+ const commentText =
772
+ "// Use these imports to wrap your application (<ReactQueryClientProvider>, <TrustlessWorkProvider>, <WalletProvider> y <EscrowProvider>)\n";
773
+
774
+ const needImport = (name) =>
775
+ !new RegExp(
776
+ `import\\s+[^;]*${name}[^;]*from\\s+['\"][^'\"]+['\"];?`
777
+ ).test(content);
778
+
779
+ let importsToAdd = "";
780
+ if (reactQuery && needImport("ReactQueryClientProvider"))
781
+ importsToAdd += importRQ;
782
+ if (trustless && needImport("TrustlessWorkProvider"))
783
+ importsToAdd += importTW;
784
+ if (wallet && needImport("WalletProvider")) importsToAdd += importWallet;
785
+ if (escrow && needImport("EscrowProvider")) importsToAdd += importEscrow;
786
+
787
+ if (importsToAdd) {
788
+ const importStmtRegex = /^import.*;\s*$/gm;
789
+ let last = null;
790
+ for (const m of content.matchAll(importStmtRegex)) last = m;
791
+ if (last) {
792
+ const idx = last.index + last[0].length;
793
+ content =
794
+ content.slice(0, idx) +
795
+ "\n" +
796
+ importsToAdd +
797
+ commentText +
798
+ content.slice(idx);
799
+ } else {
800
+ content = importsToAdd + commentText + content;
801
+ }
802
+ }
803
+
804
+ const hasTag = (tag) => new RegExp(`<${tag}[\\s>]`).test(content);
805
+ const wrapInside = (containerTag, newTag) => {
806
+ const open = content.match(new RegExp(`<${containerTag}(\\s[^>]*)?>`));
807
+ if (!open) return false;
808
+ const openIdx = open.index + open[0].length;
809
+ const closeIdx = content.indexOf(`</${containerTag}>`, openIdx);
810
+ if (closeIdx === -1) return false;
811
+ content =
812
+ content.slice(0, openIdx) +
813
+ `\n<${newTag}>\n` +
814
+ content.slice(openIdx, closeIdx) +
815
+ `\n</${newTag}>\n` +
816
+ content.slice(closeIdx);
817
+ return true;
818
+ };
819
+
820
+ const ensureTag = (tag) => {
821
+ if (hasTag(tag)) return;
822
+ const bodyOpen = content.match(/<body[^>]*>/);
823
+ const bodyCloseIdx = content.lastIndexOf("</body>");
824
+ if (!bodyOpen || bodyCloseIdx === -1) return;
825
+ const bodyOpenIdx = bodyOpen.index + bodyOpen[0].length;
826
+ if (tag === "TrustlessWorkProvider") {
827
+ if (wrapInside("ReactQueryClientProvider", tag)) return;
828
+ }
829
+ if (tag === "WalletProvider") {
830
+ if (wrapInside("TrustlessWorkProvider", tag)) return;
831
+ if (wrapInside("ReactQueryClientProvider", tag)) return;
832
+ }
833
+ if (tag === "EscrowProvider") {
834
+ if (wrapInside("WalletProvider", tag)) return;
835
+ if (wrapInside("TrustlessWorkProvider", tag)) return;
836
+ if (wrapInside("ReactQueryClientProvider", tag)) return;
837
+ }
838
+ content =
839
+ content.slice(0, bodyOpenIdx) +
840
+ `\n<${tag}>\n` +
841
+ content.slice(bodyOpenIdx, bodyCloseIdx) +
842
+ `\n</${tag}>\n` +
843
+ content.slice(bodyCloseIdx);
844
+ };
845
+
846
+ if (reactQuery) ensureTag("ReactQueryClientProvider");
847
+ if (trustless) ensureTag("TrustlessWorkProvider");
848
+ if (wallet) ensureTag("WalletProvider");
849
+ if (escrow) ensureTag("EscrowProvider");
850
+
851
+ fs.writeFileSync(layoutPath, content, "utf8");
852
+ logCheck(
853
+ `Updated ${path.relative(PROJECT_ROOT, layoutPath)} with providers`
854
+ );
855
+ } catch (e) {
856
+ console.error("❌ Failed to update layout with providers:", e.message);
857
+ }
858
+ }
859
+
860
+ if (args[0] === "init") {
861
+ console.log("\n▶ Setting up shadcn/ui components...");
862
+ const doInit = await promptYesNo("Run shadcn init now?", true);
863
+ if (doInit) {
864
+ run("npx", ["shadcn@latest", "init"]);
865
+ } else {
866
+ console.log("\x1b[90m– Skipped shadcn init\x1b[0m");
867
+ }
868
+
869
+ const addShadcn = await promptYesNo(
870
+ "Add shadcn components (button, input, form, card, sonner, checkbox, dialog, textarea, sonner, select, table, calendar, popover, separator, calendar-05, badge, sheet, tabs, avatar)?",
871
+ true
872
+ );
873
+ if (addShadcn) {
874
+ await withSpinner("Installing shadcn/ui components", async () => {
875
+ await runAsync("npx", [
876
+ "shadcn@latest",
877
+ "add",
878
+ "button",
879
+ "input",
880
+ "form",
881
+ "card",
882
+ "sonner",
883
+ "checkbox",
884
+ "dialog",
885
+ "textarea",
886
+ "sonner",
887
+ "select",
888
+ "table",
889
+ "calendar",
890
+ "popover",
891
+ "separator",
892
+ "calendar-05",
893
+ "badge",
894
+ "sheet",
895
+ "tabs",
896
+ "avatar",
897
+ ]);
898
+ });
899
+ } else {
900
+ console.log("\x1b[90m– Skipped adding shadcn components\x1b[0m");
901
+ }
902
+
903
+ if (!fs.existsSync(GLOBAL_DEPS_FILE)) {
904
+ console.error("❌ deps.json not found in templates/");
905
+ process.exit(1);
906
+ }
907
+ const meta = JSON.parse(fs.readFileSync(GLOBAL_DEPS_FILE, "utf8"));
908
+ const installLibs = await promptYesNo(
909
+ "Install (react-hook-form, @tanstack/react-query, @tanstack/react-query-devtools, @trustless-work/escrow, @hookform/resolvers, axios, @creit.tech/stellar-wallets-kit, react-day-picker & zod) dependencies now?",
910
+ true
911
+ );
912
+ if (installLibs) {
913
+ await withSpinner("Installing required dependencies", async () => {
914
+ installDeps(meta);
915
+ });
916
+ } else {
917
+ console.log("\x1b[90m– Skipped installing required dependencies\x1b[0m");
918
+ }
919
+ const cfgPath = path.join(PROJECT_ROOT, ".twblocks.json");
920
+ if (!fs.existsSync(cfgPath)) {
921
+ fs.writeFileSync(
922
+ cfgPath,
923
+ JSON.stringify({ uiBase: "@/components/ui" }, null, 2)
924
+ );
925
+ console.log(
926
+ `\x1b[32m✔\x1b[0m Created ${path.relative(
927
+ PROJECT_ROOT,
928
+ cfgPath
929
+ )} with default uiBase`
930
+ );
931
+ }
932
+ console.log("\x1b[32m✔\x1b[0m shadcn/ui components step completed");
933
+
934
+ const wantProviders = await promptYesNo(
935
+ "Install TanStack Query and Trustless Work providers and wrap app/layout with them?",
936
+ true
937
+ );
938
+ if (wantProviders) {
939
+ await withSpinner("Installing providers", async () => {
940
+ copyTemplate("providers");
941
+ });
942
+ const layoutPath = findLayoutFile();
943
+ if (layoutPath) {
944
+ await withSpinner("Updating app/layout with providers", async () => {
945
+ injectProvidersIntoLayout(layoutPath, {
946
+ reactQuery: true,
947
+ trustless: true,
948
+ });
949
+ });
950
+ } else {
951
+ console.warn(
952
+ "⚠️ Could not find app/layout file. Skipped automatic wiring."
953
+ );
954
+ }
955
+ } else {
956
+ console.log("\x1b[90m– Skipped installing providers\x1b[0m");
957
+ }
958
+
959
+ printBannerTRUSTLESSWORK();
960
+ console.log("\n\nResources");
961
+ console.log("- " + oscHyperlink("Website", "https://trustlesswork.com"));
962
+ console.log(
963
+ "- " + oscHyperlink("Documentation", "https://docs.trustlesswork.com")
964
+ );
965
+ console.log("- " + oscHyperlink("Demo", "https://demo.trustlesswork.com"));
966
+ console.log(
967
+ "- " + oscHyperlink("Backoffice", "https://dapp.trustlesswork.com")
968
+ );
969
+ console.log(
970
+ "- " + oscHyperlink("GitHub", "https://github.com/trustless-work")
971
+ );
972
+ console.log(
973
+ "- " + oscHyperlink("Escrow Viewer", "https://viewer.trustlesswork.com")
974
+ );
975
+ console.log(
976
+ "- " + oscHyperlink("Telegram", "https://t.me/+kmr8tGegxLU0NTA5")
977
+ );
978
+ console.log(
979
+ "- " +
980
+ oscHyperlink(
981
+ "LinkedIn",
982
+ "https://www.linkedin.com/company/trustlesswork/posts/?feedView=all"
983
+ )
984
+ );
985
+ console.log("- " + oscHyperlink("X", "https://x.com/TrustlessWork"));
986
+ } else if (args[0] === "add" && args[1]) {
987
+ const flags = parseFlags(args.slice(2));
988
+ const cfgPath = path.join(PROJECT_ROOT, ".twblocks.json");
989
+ if (!fs.existsSync(cfgPath)) {
990
+ console.error(
991
+ "❌ Missing initial setup. Run 'trustless-work init' first to install dependencies and create .twblocks.json (uiBase)."
992
+ );
993
+ console.error(
994
+ " After init, re-run: trustless-work add " +
995
+ args[1] +
996
+ (flags.uiBase ? ' --ui-base "' + flags.uiBase + '"' : "")
997
+ );
998
+ process.exit(1);
999
+ }
1000
+ copyTemplate(args[1], {
1001
+ uiBase: flags.uiBase,
1002
+ shouldInstall: !!flags.install,
1003
+ });
1004
+
1005
+ // Post-add wiring for specific templates
1006
+ const layoutPath = findLayoutFile();
1007
+ if (layoutPath) {
1008
+ if (args[1] === "wallet-kit" || args[1].startsWith("wallet-kit/")) {
1009
+ injectProvidersIntoLayout(layoutPath, { wallet: true });
1010
+ }
1011
+ if (
1012
+ args[1] === "escrows/escrow-context" ||
1013
+ args[1].startsWith("escrows/escrow-context/")
1014
+ ) {
1015
+ injectProvidersIntoLayout(layoutPath, { escrow: true });
1016
+ }
1017
+ }
1018
+
1019
+ // Copy shared details into role/signer targets when applicable
1020
+ try {
1021
+ if (args[1] === "escrows") {
1022
+ copySharedDetailsInto("escrows/escrows-by-role/details", {
1023
+ uiBase: flags.uiBase,
1024
+ });
1025
+ copySharedDetailsInto("escrows/escrows-by-signer/details", {
1026
+ uiBase: flags.uiBase,
1027
+ });
1028
+ copySharedRoleSignerHooks();
1029
+ }
1030
+ if (
1031
+ args[1] === "escrows/escrows-by-role" ||
1032
+ args[1].startsWith("escrows/escrows-by-role/")
1033
+ ) {
1034
+ copySharedDetailsInto("escrows/escrows-by-role/details", {
1035
+ uiBase: flags.uiBase,
1036
+ });
1037
+ copySharedRoleSignerHooks();
1038
+ }
1039
+ if (
1040
+ args[1] === "escrows/escrows-by-signer" ||
1041
+ args[1].startsWith("escrows/escrows-by-signer/")
1042
+ ) {
1043
+ copySharedDetailsInto("escrows/escrows-by-signer/details", {
1044
+ uiBase: flags.uiBase,
1045
+ });
1046
+ copySharedRoleSignerHooks();
1047
+ }
1048
+ } catch (e) {
1049
+ console.warn("⚠️ Failed to copy shared details:", e?.message || e);
1050
+ }
1051
+ } else {
1052
+ console.log(`
1053
+
1054
+ Usage:
1055
+
1056
+ trustless-work init
1057
+ trustless-work add <template> [--install]
1058
+
1059
+ Options:
1060
+
1061
+ --ui-base <path> Base import path to your shadcn/ui components (default: "@/components/ui")
1062
+ --install, -i Also install dependencies (normally use 'init' once instead)
1063
+
1064
+ Examples:
1065
+
1066
+ --- Get started ---
1067
+ trustless-work init
1068
+
1069
+ --- Providers ---
1070
+ trustless-work add providers
1071
+
1072
+ --- Wallet-kit ---
1073
+ trustless-work add wallet-kit
1074
+
1075
+ --- Handle-errors ---
1076
+ trustless-work add handle-errors
1077
+
1078
+ --- Tanstack ---
1079
+ trustless-work add tanstak
1080
+
1081
+ --- Escrows ---
1082
+ trustless-work add escrows
1083
+
1084
+ --- Escrow context ---
1085
+ trustless-work add escrows/escrow-context
1086
+
1087
+ --- Escrows by role ---
1088
+ trustless-work add escrows/escrows-by-role
1089
+ trustless-work add escrows/escrows-by-role/table
1090
+ trustless-work add escrows/escrows-by-role/cards
1091
+
1092
+ --- Escrows by signer ---
1093
+ trustless-work add escrows/escrows-by-signer
1094
+ trustless-work add escrows/escrows-by-signer/table
1095
+ trustless-work add escrows/escrows-by-signer/cards
1096
+
1097
+ ----------------------
1098
+ --- SINGLE-RELEASE ---
1099
+ trustless-work add escrows/single-release
1100
+
1101
+ --- Initialize escrow ---
1102
+ - trustless-work add escrows/single-release/initialize-escrow
1103
+
1104
+ --- Fund escrow ---
1105
+ - trustless-work add escrows/single-release/fund-escrow
1106
+ - trustless-work add escrows/single-release/fund-escrow/form
1107
+ - trustless-work add escrows/single-release/fund-escrow/button
1108
+ - trustless-work add escrows/single-release/fund-escrow/dialog
1109
+
1110
+ ---------------------
1111
+ --- MULTI-RELEASE ---
1112
+ trustless-work add escrows/multi-release
1113
+
1114
+ --- Initialize escrow ---
1115
+ - trustless-work add escrows/multi-release/initialize-escrow
1116
+
1117
+ --- Fund escrow ---
1118
+ - trustless-work add escrows/multi-release/fund-escrow
1119
+ - trustless-work add escrows/multi-release/fund-escrow/form
1120
+ - trustless-work add escrows/multi-release/fund-escrow/button
1121
+ - trustless-work add escrows/multi-release/fund-escrow/dialog
1122
+ `);
1123
+ }