designsource 0.12.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +647 -432
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -119,9 +119,9 @@ function resolveAlias(alias, tsconfig) {
|
|
|
119
119
|
best = { prefixLength: prefix.length, resolved: star === -1 ? target : target.replace("*", () => rest) };
|
|
120
120
|
}
|
|
121
121
|
if (!best) throw noAlias(alias);
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
return
|
|
122
|
+
const relative7 = posix.normalize(posix.join(tsconfig.baseUrl, best.resolved));
|
|
123
|
+
if (relative7 === ".." || relative7.startsWith("../") || posix.isAbsolute(relative7)) throw outside(alias);
|
|
124
|
+
return relative7 === "." ? "" : relative7;
|
|
125
125
|
}
|
|
126
126
|
function resolveTargets(root, shadcn) {
|
|
127
127
|
const { aliases, tailwind } = shadcn ?? {};
|
|
@@ -1038,7 +1038,7 @@ ${TOKEN_LINE}
|
|
|
1038
1038
|
${API_LINE}
|
|
1039
1039
|
--force overwrite files the bundle writes when design-system/ already exists
|
|
1040
1040
|
`;
|
|
1041
|
-
var ADD_USAGE = `designsource add [names\u2026] [--yes] [--all] [--force] [--skip-install] [--no-blocks] [--screen <name>|all|shell|site] [--token <project token>] [--api <origin>]
|
|
1041
|
+
var ADD_USAGE = `designsource add [names\u2026] [--yes] [--all] [--force] [--skip-install] [--blocks] [--no-blocks] [--screen <name>|all|shell|site] [--token <project token>] [--api <origin>]
|
|
1042
1042
|
|
|
1043
1043
|
Adds your design system's UI kit to the React app in this folder: the theme in its global stylesheet, the
|
|
1044
1044
|
components and the libraries they import. Sets up Tailwind and the shadcn config when the app has none.
|
|
@@ -1050,11 +1050,13 @@ your components, blocks and sample pages.
|
|
|
1050
1050
|
--yes no questions (also outside a terminal): all components on a first run, edited files kept
|
|
1051
1051
|
--force replace component files add did not write, and edited ones
|
|
1052
1052
|
--skip-install write the files, then print the install command instead of running it
|
|
1053
|
+
--blocks add the blocks and their libraries to a /design-system section that has none
|
|
1053
1054
|
--no-blocks the /design-system section without its blocks and their libraries (blocks already there stay)
|
|
1054
1055
|
--screen screens and pages from DS source, by file name (repeatable, or comma-separated); all for every one;
|
|
1055
1056
|
shell for a sidebar app shell listing the screens in the app; site for the menu and footer around
|
|
1056
1057
|
the pages in the app
|
|
1057
|
-
--token the project token (workbench \u2192 Project settings); or DS_SYNC_TOKEN
|
|
1058
|
+
--token the project token (workbench \u2192 Project settings); or DS_SYNC_TOKEN. Without one, the token saved by
|
|
1059
|
+
connect, else the sign-in from login when this folder is linked to a design system
|
|
1058
1060
|
--api API origin (default ${DEFAULT_API_ORIGIN})
|
|
1059
1061
|
`;
|
|
1060
1062
|
var APP_IDS = APPS.map((a) => a.id);
|
|
@@ -1173,7 +1175,8 @@ function switchOf(arg, usage) {
|
|
|
1173
1175
|
return true;
|
|
1174
1176
|
}
|
|
1175
1177
|
var unknownOption = (arg, usage) => new ArgsError(`Unknown option ${arg.name}`, usage);
|
|
1176
|
-
var ADD_SWITCHES = /* @__PURE__ */ new Map([["yes", "yes"], ["all", "all"], ["force", "force"], ["skip-install", "skipInstall"], ["no-blocks", "noBlocks"]]);
|
|
1178
|
+
var ADD_SWITCHES = /* @__PURE__ */ new Map([["yes", "yes"], ["all", "all"], ["force", "force"], ["skip-install", "skipInstall"], ["no-blocks", "noBlocks"], ["blocks", "blocks"]]);
|
|
1179
|
+
var BLOCKS_BOTH = "--blocks and --no-blocks cannot be used together.";
|
|
1177
1180
|
var SCREEN_NAME_MESSAGE = "--screen takes screen names from DS source (letters, digits and dashes), or all.";
|
|
1178
1181
|
function screensIn(values, usage) {
|
|
1179
1182
|
const words = values.flatMap((v) => v.split(",").map((w) => w.trim()));
|
|
@@ -1187,7 +1190,7 @@ function screensIn(values, usage) {
|
|
|
1187
1190
|
return { ...names.length > 0 ? { screens: [...new Set(names)] } : {}, ...shell };
|
|
1188
1191
|
}
|
|
1189
1192
|
function parseAdd(argv, env) {
|
|
1190
|
-
const args = { components: [], api: DEFAULT_API_ORIGIN, yes: false, all: false, force: false, skipInstall: false, noBlocks: false };
|
|
1193
|
+
const args = { components: [], api: DEFAULT_API_ORIGIN, yes: false, all: false, force: false, skipInstall: false, noBlocks: false, blocks: false };
|
|
1191
1194
|
if (env.DS_SYNC_TOKEN) args.token = env.DS_SYNC_TOKEN;
|
|
1192
1195
|
const screenValues = [];
|
|
1193
1196
|
for (const arg of scan(argv, ["token", "api", "screen"], [...ADD_SWITCHES.keys()])) {
|
|
@@ -1207,6 +1210,7 @@ function parseAdd(argv, env) {
|
|
|
1207
1210
|
}
|
|
1208
1211
|
}
|
|
1209
1212
|
if (screenValues.length) Object.assign(args, screensIn(screenValues, ADD_USAGE));
|
|
1213
|
+
if (args.blocks && args.noBlocks) throw new ArgsError(BLOCKS_BOTH, ADD_USAGE);
|
|
1210
1214
|
return { kind: "add", args };
|
|
1211
1215
|
}
|
|
1212
1216
|
function appsIn(value, usage = CONNECT_USAGE) {
|
|
@@ -1370,14 +1374,14 @@ function quoteArg(arg) {
|
|
|
1370
1374
|
function childEnv(env) {
|
|
1371
1375
|
return Object.fromEntries(Object.entries(env).filter(([name]) => name.toUpperCase() !== "DS_SYNC_TOKEN"));
|
|
1372
1376
|
}
|
|
1373
|
-
var spawnExec = (cmd, args, { cwd, timeoutMs, input, stdoutOnly }) => new Promise((
|
|
1377
|
+
var spawnExec = (cmd, args, { cwd, timeoutMs, input, stdoutOnly }) => new Promise((resolve10) => {
|
|
1374
1378
|
let output = "";
|
|
1375
1379
|
let child;
|
|
1376
1380
|
try {
|
|
1377
1381
|
const shell = process.platform === "win32";
|
|
1378
1382
|
child = spawn(cmd, shell ? args.map(quoteArg) : args, { cwd, env: childEnv(process.env), stdio: [input === void 0 ? "ignore" : "pipe", "pipe", "pipe"], shell });
|
|
1379
1383
|
} catch (e) {
|
|
1380
|
-
|
|
1384
|
+
resolve10({ code: 127, output: e instanceof Error ? e.message : String(e) });
|
|
1381
1385
|
return;
|
|
1382
1386
|
}
|
|
1383
1387
|
let timedOut = false;
|
|
@@ -1387,7 +1391,7 @@ var spawnExec = (cmd, args, { cwd, timeoutMs, input, stdoutOnly }) => new Promis
|
|
|
1387
1391
|
}, timeoutMs);
|
|
1388
1392
|
const done = (result) => {
|
|
1389
1393
|
if (timer) clearTimeout(timer);
|
|
1390
|
-
|
|
1394
|
+
resolve10(timedOut ? { code: result.code === 0 ? 124 : result.code, output: `${result.output.trimEnd()}
|
|
1391
1395
|
timed out after ${timeoutMs / 1e3}s` } : result);
|
|
1392
1396
|
};
|
|
1393
1397
|
child.stdout?.on("data", (chunk) => {
|
|
@@ -2535,7 +2539,7 @@ async function postNdjson(opts, fetchImpl = fetch) {
|
|
|
2535
2539
|
|
|
2536
2540
|
// src/connect/open-browser.ts
|
|
2537
2541
|
import { spawn as spawn2 } from "node:child_process";
|
|
2538
|
-
var launchDetached = (cmd, args) => new Promise((
|
|
2542
|
+
var launchDetached = (cmd, args) => new Promise((resolve10) => {
|
|
2539
2543
|
try {
|
|
2540
2544
|
const child = spawn2(cmd, args, {
|
|
2541
2545
|
shell: false,
|
|
@@ -2543,13 +2547,13 @@ var launchDetached = (cmd, args) => new Promise((resolve9) => {
|
|
|
2543
2547
|
detached: true,
|
|
2544
2548
|
windowsHide: true
|
|
2545
2549
|
});
|
|
2546
|
-
child.once("error", () =>
|
|
2550
|
+
child.once("error", () => resolve10(false));
|
|
2547
2551
|
child.once("spawn", () => {
|
|
2548
2552
|
child.unref();
|
|
2549
|
-
|
|
2553
|
+
resolve10(true);
|
|
2550
2554
|
});
|
|
2551
2555
|
} catch {
|
|
2552
|
-
|
|
2556
|
+
resolve10(false);
|
|
2553
2557
|
}
|
|
2554
2558
|
});
|
|
2555
2559
|
function deviceUrl(api) {
|
|
@@ -3484,13 +3488,15 @@ function selectScreens(query, explicit, manifest, appDeps) {
|
|
|
3484
3488
|
return selection;
|
|
3485
3489
|
}
|
|
3486
3490
|
var SECTION_FRAMEWORKS = ["next", "vite"];
|
|
3491
|
+
var BLOCKS_NOT_ADDED = "No blocks were added: they go into the /design-system section, which only a run with every component writes. Run designsource add --blocks with no component names.";
|
|
3492
|
+
var BLOCKS_NOT_ADDED_FOR_AGENT = "No blocks were added: they go into the /design-system section, which only a call with every component writes. Call add_ui_kit with blocks: true and no components.";
|
|
3487
3493
|
function sectionDecision(input) {
|
|
3488
3494
|
const none = (note) => ({ write: false, blocks: "skip", note });
|
|
3489
3495
|
if (!SECTION_FRAMEWORKS.includes(input.framework)) return none(null);
|
|
3490
3496
|
if (input.framework === "next" && input.appDir === null) return none(NO_APP_ROUTER);
|
|
3491
3497
|
const chosen = new Set(input.chosen);
|
|
3492
3498
|
if (!input.allComponents.every((n) => chosen.has(n))) return none(input.present ? null : SECTION_NEEDS_FULL_KIT);
|
|
3493
|
-
const blocks = !input.present ? input.blocksWanted ? "write" : "skip" : input.blocksOnDisk ? input.blocksWanted ? "write" : "keep" : "skip";
|
|
3499
|
+
const blocks = !input.present ? input.blocksWanted ? "write" : "skip" : input.blocksOnDisk ? input.blocksWanted ? "write" : "keep" : input.addBlocks === true ? "write" : "skip";
|
|
3494
3500
|
return { write: true, blocks, note: null };
|
|
3495
3501
|
}
|
|
3496
3502
|
function planSection(root, input, info, t, manifest, chosen, onDisk, screens, screenLinks) {
|
|
@@ -3502,7 +3508,7 @@ function planSection(root, input, info, t, manifest, chosen, onDisk, screens, sc
|
|
|
3502
3508
|
if (own) return none(OWN_DESIGN_SYSTEM_ROUTE(own));
|
|
3503
3509
|
const { present, blocksOnDisk, blockIds } = onDisk;
|
|
3504
3510
|
const allComponents = manifest.components.map((c) => c.name).filter((n) => n !== PORTAL);
|
|
3505
|
-
const decision = sectionDecision({ chosen, allComponents, present, blocksOnDisk, blocksWanted: input.blocks ?? true, framework: info.framework, appDir });
|
|
3511
|
+
const decision = sectionDecision({ chosen, allComponents, present, blocksOnDisk, blocksWanted: input.blocks ?? true, addBlocks: input.addBlocks, framework: info.framework, appDir });
|
|
3506
3512
|
if (!decision.write) return none(decision.note);
|
|
3507
3513
|
if (t.componentsDir === null) return none(NO_COMPONENTS_DIR(t.componentsAlias));
|
|
3508
3514
|
if (!t.libAlias) return none(NO_LIB_ALIAS(t.utilsAlias));
|
|
@@ -3592,6 +3598,7 @@ async function runAdd(input, deps) {
|
|
|
3592
3598
|
sectionNote = SECTION_CONFLICT(blocking);
|
|
3593
3599
|
} else packages = withSection;
|
|
3594
3600
|
}
|
|
3601
|
+
if (input.addBlocks && sectionNote === null && !(writeSection && section.decision.blocks === "write")) sectionNote = BLOCKS_NOT_ADDED;
|
|
3595
3602
|
const shellBlocker = shellPlan === null ? null : SHELL_COMPONENTS.map(
|
|
3596
3603
|
(name) => !manifest.components.some((c) => c.name === name) ? SHELL_NOT_IN_KIT(name) : packages.skipped.find((k) => k.name === name)?.reason ?? null
|
|
3597
3604
|
).find((r) => r !== null) ?? null;
|
|
@@ -3718,7 +3725,7 @@ async function runAdd(input, deps) {
|
|
|
3718
3725
|
|
|
3719
3726
|
// src/add/summary.ts
|
|
3720
3727
|
var leftBlocksLine = (n, reader) => `Left ${n} block${n === 1 ? "" : "s"} in place; ${reader === "agent" ? "no_blocks" : "--no-blocks"} does not remove ${n === 1 ? "it" : "them"}.`;
|
|
3721
|
-
var sectionNoteFor = (note, reader) => reader
|
|
3728
|
+
var sectionNoteFor = (note, reader) => reader !== "agent" ? note : note === SECTION_NEEDS_FULL_KIT ? SECTION_NEEDS_FULL_KIT_FOR_AGENT : note === BLOCKS_NOT_ADDED ? BLOCKS_NOT_ADDED_FOR_AGENT : note;
|
|
3722
3729
|
var screenSkipLine = (s, reader) => screenSkipText(s.slug, reader === "agent" && s.agentReason ? s.agentReason : s.reason);
|
|
3723
3730
|
var GET_SITE_SHELL = {
|
|
3724
3731
|
cli: "Get <SiteShell> with npx designsource add --screen site.",
|
|
@@ -3761,298 +3768,8 @@ function summaryLines(r, reader = "cli") {
|
|
|
3761
3768
|
];
|
|
3762
3769
|
}
|
|
3763
3770
|
|
|
3764
|
-
// src/connect/
|
|
3765
|
-
var SAVED_TOKEN_OTHER_SERVER = (name, saved, asked) => `The saved token for "${name}" was connected to ${saved}, so designsource will not send it to ${asked}. Pass --token for that server, or leave out --api.`;
|
|
3766
|
-
var UNTRUSTED_SERVER = (asked) => `designsource will not send a token to ${asked}: that server was never connected on this computer. If you trust it, run npx designsource connect --api ${asked} in your project folder yourself.`;
|
|
3767
|
-
function apiFor(args, saved) {
|
|
3768
|
-
if (!saved) return args.api;
|
|
3769
|
-
if (!args.apiGiven) return saved.api ?? args.api;
|
|
3770
|
-
const origin = saved.api ?? DEFAULT_API_ORIGIN;
|
|
3771
|
-
if (!sameApi(args.api, origin)) throw new CliError(SAVED_TOKEN_OTHER_SERVER(saved.name, origin, args.api));
|
|
3772
|
-
return origin;
|
|
3773
|
-
}
|
|
3774
|
-
function givenTokenApi(args, entry) {
|
|
3775
|
-
if (!args.apiGiven) return entry?.api ?? args.api;
|
|
3776
|
-
const trusted = sameApi(args.api, DEFAULT_API_ORIGIN) || isLoopback(args.api) || entry?.api !== void 0 && sameApi(args.api, entry.api);
|
|
3777
|
-
if (!trusted) throw new CliError(UNTRUSTED_SERVER(args.api));
|
|
3778
|
-
return args.api;
|
|
3779
|
-
}
|
|
3780
|
-
function sameApi(a, b) {
|
|
3781
|
-
const key = (value) => {
|
|
3782
|
-
try {
|
|
3783
|
-
const url = new URL(value);
|
|
3784
|
-
if (url.username || url.password) return null;
|
|
3785
|
-
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
3786
|
-
} catch {
|
|
3787
|
-
return null;
|
|
3788
|
-
}
|
|
3789
|
-
};
|
|
3790
|
-
const ka = key(a);
|
|
3791
|
-
return ka !== null && ka === key(b);
|
|
3792
|
-
}
|
|
3793
|
-
function isLoopback(value) {
|
|
3794
|
-
let host;
|
|
3795
|
-
try {
|
|
3796
|
-
host = new URL(value).hostname;
|
|
3797
|
-
} catch {
|
|
3798
|
-
return false;
|
|
3799
|
-
}
|
|
3800
|
-
return host === "localhost" || host.endsWith(".localhost") || /^127(?:\.\d{1,3}){3}$/.test(host) || host === "[::1]";
|
|
3801
|
-
}
|
|
3802
|
-
|
|
3803
|
-
// src/picker.ts
|
|
3804
|
-
import { emitKeypressEvents } from "node:readline";
|
|
3805
|
-
|
|
3806
|
-
// src/prompts.ts
|
|
3807
|
-
import { createInterface } from "node:readline";
|
|
3808
|
-
var shared;
|
|
3809
|
-
var closed = false;
|
|
3810
|
-
var queued = [];
|
|
3811
|
-
var waiting = [];
|
|
3812
|
-
var EOF_MESSAGE = "No more input. Pass the answer as a flag (for example --token or DS_SYNC_TOKEN) when running without a terminal.";
|
|
3813
|
-
function iface() {
|
|
3814
|
-
if (shared) return shared;
|
|
3815
|
-
const r = createInterface({ input: process.stdin, output: process.stdout, terminal: process.stdin.isTTY === true });
|
|
3816
|
-
r.on("line", (line) => {
|
|
3817
|
-
const next = waiting.shift();
|
|
3818
|
-
if (next) next.resolve(line);
|
|
3819
|
-
else queued.push(line);
|
|
3820
|
-
});
|
|
3821
|
-
r.on("close", () => {
|
|
3822
|
-
closed = true;
|
|
3823
|
-
while (waiting.length) waiting.shift().reject(new CliError(EOF_MESSAGE));
|
|
3824
|
-
});
|
|
3825
|
-
if (process.stdin.isTTY === true) {
|
|
3826
|
-
r.on("SIGINT", () => {
|
|
3827
|
-
process.stdout.write("\n");
|
|
3828
|
-
closed = true;
|
|
3829
|
-
while (waiting.length) waiting.shift().reject(new CliError(CANCELLED, 130));
|
|
3830
|
-
r.close();
|
|
3831
|
-
});
|
|
3832
|
-
}
|
|
3833
|
-
shared = r;
|
|
3834
|
-
return r;
|
|
3835
|
-
}
|
|
3836
|
-
function hasInterface() {
|
|
3837
|
-
return shared !== void 0;
|
|
3838
|
-
}
|
|
3839
|
-
function nextLine() {
|
|
3840
|
-
iface();
|
|
3841
|
-
const line = queued.shift();
|
|
3842
|
-
if (line !== void 0) return Promise.resolve(line);
|
|
3843
|
-
if (closed) return Promise.reject(new CliError(EOF_MESSAGE));
|
|
3844
|
-
process.stdin.ref?.();
|
|
3845
|
-
return new Promise((resolve9, reject) => waiting.push({
|
|
3846
|
-
resolve: (line2) => {
|
|
3847
|
-
process.stdin.unref?.();
|
|
3848
|
-
resolve9(line2);
|
|
3849
|
-
},
|
|
3850
|
-
reject: (err) => {
|
|
3851
|
-
process.stdin.unref?.();
|
|
3852
|
-
reject(err);
|
|
3853
|
-
}
|
|
3854
|
-
}));
|
|
3855
|
-
}
|
|
3856
|
-
function promptLine(promptText, fallback) {
|
|
3857
|
-
const r = iface();
|
|
3858
|
-
r.setPrompt(promptText);
|
|
3859
|
-
r.prompt();
|
|
3860
|
-
return nextLine().then((a) => a.trim() || fallback);
|
|
3861
|
-
}
|
|
3862
|
-
function ask(question, fallback) {
|
|
3863
|
-
return promptLine(`${question} (${fallback}) `, fallback);
|
|
3864
|
-
}
|
|
3865
|
-
async function confirm(question, defaultYes = false) {
|
|
3866
|
-
const answer = await promptLine(`${question} ${defaultYes ? "(Y/n)" : "(y/N)"} `, "");
|
|
3867
|
-
return /^y/i.test(answer) ? true : /^n/i.test(answer) ? false : defaultYes;
|
|
3868
|
-
}
|
|
3869
|
-
function askLine(question) {
|
|
3870
|
-
return promptLine(`${question} `, "");
|
|
3871
|
-
}
|
|
3872
|
-
async function askChoice(question, options, defaultIndex) {
|
|
3873
|
-
const list = options.map((o, i) => ` ${i + 1}) ${o}${i === defaultIndex ? " (default)" : ""}`).join("\n");
|
|
3874
|
-
process.stdout.write(`${question}
|
|
3875
|
-
${list}
|
|
3876
|
-
`);
|
|
3877
|
-
for (; ; ) {
|
|
3878
|
-
const answer = await ask("Choice", String(defaultIndex + 1));
|
|
3879
|
-
const idx = Number(answer) - 1;
|
|
3880
|
-
const byName = options.indexOf(answer);
|
|
3881
|
-
if (byName !== -1) return options[byName];
|
|
3882
|
-
if (Number.isInteger(idx) && options[idx] !== void 0) return options[idx];
|
|
3883
|
-
process.stdout.write(`Pick 1-${options.length}.
|
|
3884
|
-
`);
|
|
3885
|
-
}
|
|
3886
|
-
}
|
|
3887
|
-
async function askHidden(question) {
|
|
3888
|
-
const r = iface();
|
|
3889
|
-
const original = typeof r._writeToOutput === "function" ? r._writeToOutput.bind(r) : void 0;
|
|
3890
|
-
if (!original) {
|
|
3891
|
-
throw new CliError("Cannot hide input on this terminal. Pass --token or set DS_SYNC_TOKEN instead.");
|
|
3892
|
-
}
|
|
3893
|
-
let muted = false;
|
|
3894
|
-
r._writeToOutput = (s) => {
|
|
3895
|
-
if (!muted) original(s);
|
|
3896
|
-
};
|
|
3897
|
-
r.setPrompt(`${question} `);
|
|
3898
|
-
r.prompt();
|
|
3899
|
-
muted = true;
|
|
3900
|
-
try {
|
|
3901
|
-
const a = await nextLine();
|
|
3902
|
-
return a.trim();
|
|
3903
|
-
} finally {
|
|
3904
|
-
muted = false;
|
|
3905
|
-
original("\n");
|
|
3906
|
-
r._writeToOutput = original;
|
|
3907
|
-
}
|
|
3908
|
-
}
|
|
3909
|
-
|
|
3910
|
-
// src/picker.ts
|
|
3911
|
-
function pick(question, options, defaultIndex = 0) {
|
|
3912
|
-
if (!rawTerminal()) return askChoice(question, options.map((o) => o.value), defaultIndex);
|
|
3913
|
-
return pickTty(question, options, defaultIndex, process.stdin, process.stdout);
|
|
3914
|
-
}
|
|
3915
|
-
function rawTerminal() {
|
|
3916
|
-
const { stdin, stdout } = process;
|
|
3917
|
-
return stdin.isTTY === true && stdout.isTTY === true && typeof stdin.setRawMode === "function" && !hasInterface();
|
|
3918
|
-
}
|
|
3919
|
-
function pickMany(question, options, preselected) {
|
|
3920
|
-
if (!rawTerminal()) return pickManyNumbered(question, options, preselected);
|
|
3921
|
-
return pickManyTty(question, options, preselected, process.stdin, process.stdout);
|
|
3922
|
-
}
|
|
3923
|
-
async function pickManyNumbered(question, options, preselected) {
|
|
3924
|
-
const list = options.map((o, i) => ` ${i + 1}) ${o.label}${preselected.includes(o.value) ? " (picked)" : ""}`).join("\n");
|
|
3925
|
-
process.stdout.write(`${question}
|
|
3926
|
-
${list}
|
|
3927
|
-
`);
|
|
3928
|
-
const defaults = options.flatMap((o, i) => preselected.includes(o.value) ? [String(i + 1)] : []);
|
|
3929
|
-
const fallback = defaults.length > 0 ? defaults.join(",") : "none";
|
|
3930
|
-
for (; ; ) {
|
|
3931
|
-
const answer = await ask("Choices", fallback);
|
|
3932
|
-
if (answer === "none") return [];
|
|
3933
|
-
const indexes = answer.split(/[\s,]+/).filter(Boolean).map((part) => {
|
|
3934
|
-
const byValue = options.findIndex((o) => o.value === part.toLowerCase());
|
|
3935
|
-
if (byValue !== -1) return byValue;
|
|
3936
|
-
const byNumber = /^\d+$/.test(part) ? Number(part) - 1 : -1;
|
|
3937
|
-
return options[byNumber] !== void 0 ? byNumber : -1;
|
|
3938
|
-
});
|
|
3939
|
-
if (indexes.length > 0 && !indexes.includes(-1)) return options.filter((_, i) => indexes.includes(i)).map((o) => o.value);
|
|
3940
|
-
process.stdout.write(`Pick from 1-${options.length}, separated by commas.
|
|
3941
|
-
`);
|
|
3942
|
-
}
|
|
3943
|
-
}
|
|
3944
|
-
function pickTty(question, options, start, stdin, stdout) {
|
|
3945
|
-
const color = !process.env.NO_COLOR;
|
|
3946
|
-
const bold = (s) => color ? `\x1B[1m${s}\x1B[22m` : s;
|
|
3947
|
-
const dim = (s) => color ? `\x1B[2m${s}\x1B[22m` : s;
|
|
3948
|
-
const n = options.length;
|
|
3949
|
-
let index = start;
|
|
3950
|
-
const rows = () => options.map((o, i) => {
|
|
3951
|
-
const label = i === index ? bold(o.label) : o.label;
|
|
3952
|
-
return `${i === index ? "\u276F" : " "} ${label}${o.hint ? ` ${dim(o.hint)}` : ""}`;
|
|
3953
|
-
});
|
|
3954
|
-
const draw = (lines) => stdout.write(lines.map((l) => `\r\x1B[2K${l}`).join("\n") + "\n");
|
|
3955
|
-
const up = () => stdout.write(`\x1B[${n + 1}A`);
|
|
3956
|
-
emitKeypressEvents(stdin);
|
|
3957
|
-
stdin.setRawMode(true);
|
|
3958
|
-
stdin.resume();
|
|
3959
|
-
stdout.write("\x1B[?25l");
|
|
3960
|
-
draw([question, ...rows()]);
|
|
3961
|
-
return new Promise((resolve9, reject) => {
|
|
3962
|
-
const finish = (after) => {
|
|
3963
|
-
stdin.off("keypress", onKey);
|
|
3964
|
-
stdin.setRawMode(false);
|
|
3965
|
-
stdin.pause();
|
|
3966
|
-
after();
|
|
3967
|
-
stdout.write("\x1B[?25h");
|
|
3968
|
-
};
|
|
3969
|
-
const onKey = (str, key = {}) => {
|
|
3970
|
-
if (key.ctrl && key.name === "c" || key.name === "escape") {
|
|
3971
|
-
finish(() => stdout.write("\n"));
|
|
3972
|
-
reject(new CliError(CANCELLED, 130));
|
|
3973
|
-
return;
|
|
3974
|
-
}
|
|
3975
|
-
if (key.name === "return" || key.name === "enter") {
|
|
3976
|
-
const chosen = options[index];
|
|
3977
|
-
finish(() => {
|
|
3978
|
-
up();
|
|
3979
|
-
stdout.write(`\r\x1B[J${question} ${chosen.label}
|
|
3980
|
-
`);
|
|
3981
|
-
});
|
|
3982
|
-
resolve9(chosen.value);
|
|
3983
|
-
return;
|
|
3984
|
-
}
|
|
3985
|
-
if (key.name === "up" || str === "k") index = (index - 1 + n) % n;
|
|
3986
|
-
else if (key.name === "down" || str === "j") index = (index + 1) % n;
|
|
3987
|
-
else if (str && /^[1-9]$/.test(str) && Number(str) <= n) index = Number(str) - 1;
|
|
3988
|
-
else return;
|
|
3989
|
-
up();
|
|
3990
|
-
draw([question, ...rows()]);
|
|
3991
|
-
};
|
|
3992
|
-
stdin.on("keypress", onKey);
|
|
3993
|
-
});
|
|
3994
|
-
}
|
|
3995
|
-
function pickManyTty(question, options, preselected, stdin, stdout) {
|
|
3996
|
-
const color = !process.env.NO_COLOR;
|
|
3997
|
-
const bold = (s) => color ? `\x1B[1m${s}\x1B[22m` : s;
|
|
3998
|
-
const dim = (s) => color ? `\x1B[2m${s}\x1B[22m` : s;
|
|
3999
|
-
const n = options.length;
|
|
4000
|
-
const ticked = options.map((o) => preselected.includes(o.value));
|
|
4001
|
-
let index = 0;
|
|
4002
|
-
const rows = () => options.map((o, i) => {
|
|
4003
|
-
const label = i === index ? bold(o.label) : o.label;
|
|
4004
|
-
return `${i === index ? "\u276F" : " "} ${ticked[i] ? "\u25C9" : "\u25EF"} ${label}${o.hint ? ` ${dim(o.hint)}` : ""}`;
|
|
4005
|
-
});
|
|
4006
|
-
const head = `${question} ${dim("space toggles, a all, enter confirms")}`;
|
|
4007
|
-
const draw = (lines) => stdout.write(lines.map((l) => `\r\x1B[2K${l}`).join("\n") + "\n");
|
|
4008
|
-
const up = () => stdout.write(`\x1B[${n + 1}A`);
|
|
4009
|
-
emitKeypressEvents(stdin);
|
|
4010
|
-
stdin.setRawMode(true);
|
|
4011
|
-
stdin.resume();
|
|
4012
|
-
stdout.write("\x1B[?25l");
|
|
4013
|
-
draw([head, ...rows()]);
|
|
4014
|
-
return new Promise((resolve9, reject) => {
|
|
4015
|
-
const finish = (after) => {
|
|
4016
|
-
stdin.off("keypress", onKey);
|
|
4017
|
-
stdin.setRawMode(false);
|
|
4018
|
-
stdin.pause();
|
|
4019
|
-
after();
|
|
4020
|
-
stdout.write("\x1B[?25h");
|
|
4021
|
-
};
|
|
4022
|
-
const onKey = (str, key = {}) => {
|
|
4023
|
-
if (key.ctrl && key.name === "c" || key.name === "escape") {
|
|
4024
|
-
finish(() => stdout.write("\n"));
|
|
4025
|
-
reject(new CliError(CANCELLED, 130));
|
|
4026
|
-
return;
|
|
4027
|
-
}
|
|
4028
|
-
if (key.name === "return" || key.name === "enter") {
|
|
4029
|
-
const chosen = options.filter((_, i) => ticked[i]);
|
|
4030
|
-
finish(() => {
|
|
4031
|
-
up();
|
|
4032
|
-
stdout.write(`\r\x1B[J${question} ${chosen.length > 0 ? chosen.map((o) => o.label).join(", ") : "none"}
|
|
4033
|
-
`);
|
|
4034
|
-
});
|
|
4035
|
-
resolve9(chosen.map((o) => o.value));
|
|
4036
|
-
return;
|
|
4037
|
-
}
|
|
4038
|
-
if (key.name === "up" || str === "k") index = (index - 1 + n) % n;
|
|
4039
|
-
else if (key.name === "down" || str === "j") index = (index + 1) % n;
|
|
4040
|
-
else if (key.name === "space" || str === " ") ticked[index] = !ticked[index];
|
|
4041
|
-
else if (str === "a") ticked.fill(!ticked.every(Boolean));
|
|
4042
|
-
else return;
|
|
4043
|
-
up();
|
|
4044
|
-
draw([head, ...rows()]);
|
|
4045
|
-
};
|
|
4046
|
-
stdin.on("keypress", onKey);
|
|
4047
|
-
});
|
|
4048
|
-
}
|
|
4049
|
-
|
|
4050
|
-
// src/commands/scaffold.ts
|
|
4051
|
-
import { resolve as resolve7 } from "node:path";
|
|
4052
|
-
|
|
4053
|
-
// src/connect/resolve-token.ts
|
|
3771
|
+
// src/connect/account-link.ts
|
|
4054
3772
|
import { homedir } from "node:os";
|
|
4055
|
-
import { join as join10, relative as relative4 } from "node:path";
|
|
4056
3773
|
|
|
4057
3774
|
// src/connect/account-store.ts
|
|
4058
3775
|
import { createHash as createHash2 } from "node:crypto";
|
|
@@ -4423,56 +4140,435 @@ var realWorktreeFs = {
|
|
|
4423
4140
|
return null;
|
|
4424
4141
|
}
|
|
4425
4142
|
}
|
|
4426
|
-
};
|
|
4427
|
-
function oneLine(text) {
|
|
4428
|
-
const lines = text.split(/\r?\n/).filter((l) => l.trim() !== "");
|
|
4429
|
-
if (lines.length !== 1) return null;
|
|
4430
|
-
const line = lines[0].trim();
|
|
4431
|
-
return /[\u0000-\u001f\u007f]/.test(line) ? null : line;
|
|
4432
|
-
}
|
|
4433
|
-
function mainRepoRoot(root, fs = realWorktreeFs) {
|
|
4434
|
-
const dotGit = join9(root, ".git");
|
|
4435
|
-
const pointer = fs.readSmall(dotGit);
|
|
4436
|
-
if (pointer === null) return null;
|
|
4437
|
-
const line = oneLine(pointer);
|
|
4438
|
-
if (line === null || !line.startsWith("gitdir:")) return null;
|
|
4439
|
-
const target = line.slice("gitdir:".length).trim();
|
|
4440
|
-
if (target === "") return null;
|
|
4441
|
-
const gitdir = fs.realpath(isAbsolute4(target) ? target : resolve6(root, target));
|
|
4442
|
-
if (gitdir === null) return null;
|
|
4443
|
-
const worktrees = dirname5(gitdir);
|
|
4444
|
-
if (basename2(worktrees) !== "worktrees") return null;
|
|
4445
|
-
const commonText = fs.readSmall(join9(gitdir, "commondir"));
|
|
4446
|
-
const commonLine = commonText === null ? null : oneLine(commonText);
|
|
4447
|
-
if (commonLine === null) return null;
|
|
4448
|
-
const common = fs.realpath(isAbsolute4(commonLine) ? commonLine : resolve6(gitdir, commonLine));
|
|
4449
|
-
if (common === null || common !== dirname5(worktrees)) return null;
|
|
4450
|
-
if (basename2(common) !== ".git") return null;
|
|
4451
|
-
const backText = fs.readSmall(join9(gitdir, "gitdir"));
|
|
4452
|
-
const backLine = backText === null ? null : oneLine(backText);
|
|
4453
|
-
if (backLine === null || !isAbsolute4(backLine)) return null;
|
|
4454
|
-
const back = fs.realpath(backLine);
|
|
4455
|
-
const here = fs.realpath(dotGit);
|
|
4456
|
-
if (back === null || here === null || back !== here) return null;
|
|
4457
|
-
const main2 = fs.realpath(dirname5(common));
|
|
4458
|
-
return main2 !== null && main2 !== fs.realpath(root) ? main2 : null;
|
|
4143
|
+
};
|
|
4144
|
+
function oneLine(text) {
|
|
4145
|
+
const lines = text.split(/\r?\n/).filter((l) => l.trim() !== "");
|
|
4146
|
+
if (lines.length !== 1) return null;
|
|
4147
|
+
const line = lines[0].trim();
|
|
4148
|
+
return /[\u0000-\u001f\u007f]/.test(line) ? null : line;
|
|
4149
|
+
}
|
|
4150
|
+
function mainRepoRoot(root, fs = realWorktreeFs) {
|
|
4151
|
+
const dotGit = join9(root, ".git");
|
|
4152
|
+
const pointer = fs.readSmall(dotGit);
|
|
4153
|
+
if (pointer === null) return null;
|
|
4154
|
+
const line = oneLine(pointer);
|
|
4155
|
+
if (line === null || !line.startsWith("gitdir:")) return null;
|
|
4156
|
+
const target = line.slice("gitdir:".length).trim();
|
|
4157
|
+
if (target === "") return null;
|
|
4158
|
+
const gitdir = fs.realpath(isAbsolute4(target) ? target : resolve6(root, target));
|
|
4159
|
+
if (gitdir === null) return null;
|
|
4160
|
+
const worktrees = dirname5(gitdir);
|
|
4161
|
+
if (basename2(worktrees) !== "worktrees") return null;
|
|
4162
|
+
const commonText = fs.readSmall(join9(gitdir, "commondir"));
|
|
4163
|
+
const commonLine = commonText === null ? null : oneLine(commonText);
|
|
4164
|
+
if (commonLine === null) return null;
|
|
4165
|
+
const common = fs.realpath(isAbsolute4(commonLine) ? commonLine : resolve6(gitdir, commonLine));
|
|
4166
|
+
if (common === null || common !== dirname5(worktrees)) return null;
|
|
4167
|
+
if (basename2(common) !== ".git") return null;
|
|
4168
|
+
const backText = fs.readSmall(join9(gitdir, "gitdir"));
|
|
4169
|
+
const backLine = backText === null ? null : oneLine(backText);
|
|
4170
|
+
if (backLine === null || !isAbsolute4(backLine)) return null;
|
|
4171
|
+
const back = fs.realpath(backLine);
|
|
4172
|
+
const here = fs.realpath(dotGit);
|
|
4173
|
+
if (back === null || here === null || back !== here) return null;
|
|
4174
|
+
const main2 = fs.realpath(dirname5(common));
|
|
4175
|
+
return main2 !== null && main2 !== fs.realpath(root) ? main2 : null;
|
|
4176
|
+
}
|
|
4177
|
+
|
|
4178
|
+
// src/connect/account-paths.ts
|
|
4179
|
+
function originOf(api) {
|
|
4180
|
+
normaliseOrigin(api);
|
|
4181
|
+
return new URL(api).origin;
|
|
4182
|
+
}
|
|
4183
|
+
function projectFolders(cwd) {
|
|
4184
|
+
const work = normaliseFolder(projectRoot(normaliseFolder(cwd)));
|
|
4185
|
+
const main2 = mainRepoRoot(work);
|
|
4186
|
+
return main2 === null ? { work, trust: work, worktree: false } : { work, trust: normaliseFolder(main2), worktree: true };
|
|
4187
|
+
}
|
|
4188
|
+
|
|
4189
|
+
// src/mcp/account-session.ts
|
|
4190
|
+
var NOT_SIGNED_IN_FOR = (root) => `designsource is not signed in for ${printable(root)}. Ask the user to run npx designsource login in a terminal in that folder, then restart this app. A sign-in there also covers its git worktrees.`;
|
|
4191
|
+
var SEVERAL_ACCOUNTS = "More than one designsource account is signed in on this computer; pass --api.";
|
|
4192
|
+
var NO_LINK = "No design system is linked to this folder yet. Call list_design_systems, then use_design_system with one of its ids, or call create_design_system to make a new one.";
|
|
4193
|
+
var ACCOUNT_TOKEN3 = /^dsa_[A-Za-z0-9_-]{43}$/;
|
|
4194
|
+
var PROJECT_ID3 = /^[A-Za-z0-9_-]+$/;
|
|
4195
|
+
var refuse = (message) => ({ kind: "none", message });
|
|
4196
|
+
function trustedFolderOf(entry, roots) {
|
|
4197
|
+
const trusted = (f) => entry.folders.some((saved) => normaliseFolder(saved) === f);
|
|
4198
|
+
const folder = trusted(roots.work) ? roots.work : trusted(roots.trust) ? roots.trust : null;
|
|
4199
|
+
if (folder === null) return null;
|
|
4200
|
+
const linked = Object.entries(entry.links).find(([f]) => normaliseFolder(f) === folder)?.[1];
|
|
4201
|
+
return { folder, projectId: linked !== void 0 && PROJECT_ID3.test(linked) ? linked : null };
|
|
4202
|
+
}
|
|
4203
|
+
function chooseAccount(api, apiGiven, accounts, notSignedIn) {
|
|
4204
|
+
if (apiGiven) {
|
|
4205
|
+
let origin;
|
|
4206
|
+
try {
|
|
4207
|
+
origin = originOf(api);
|
|
4208
|
+
} catch {
|
|
4209
|
+
return refuse(notSignedIn);
|
|
4210
|
+
}
|
|
4211
|
+
return accounts.get(origin) ?? refuse(notSignedIn);
|
|
4212
|
+
}
|
|
4213
|
+
const all = accounts.all();
|
|
4214
|
+
if (all.length === 1) return all[0];
|
|
4215
|
+
const fallback = accounts.get(DEFAULT_API_ORIGIN);
|
|
4216
|
+
if (fallback) return fallback;
|
|
4217
|
+
return refuse(all.length > 1 ? SEVERAL_ACCOUNTS : notSignedIn);
|
|
4218
|
+
}
|
|
4219
|
+
async function resolveAccount(input) {
|
|
4220
|
+
const { api, apiGiven, cwd, home, accounts } = input;
|
|
4221
|
+
const { work, trust } = projectFolders(cwd);
|
|
4222
|
+
const notSignedIn = NOT_SIGNED_IN_FOR(trust);
|
|
4223
|
+
const chosen = chooseAccount(api, apiGiven, accounts, notSignedIn);
|
|
4224
|
+
if ("kind" in chosen) return chosen;
|
|
4225
|
+
const homeDir = normaliseFolder(home);
|
|
4226
|
+
if (homeFolderRefusal(trust, homeDir) !== null || homeFolderRefusal(work, homeDir) !== null) return refuse(notSignedIn);
|
|
4227
|
+
const found = trustedFolderOf(chosen, { work, trust });
|
|
4228
|
+
if (found === null) return refuse(notSignedIn);
|
|
4229
|
+
const { folder, projectId } = found;
|
|
4230
|
+
if (input.requireLink === true && projectId === null) return refuse(NO_LINK);
|
|
4231
|
+
let token;
|
|
4232
|
+
try {
|
|
4233
|
+
token = await accounts.token(chosen.origin);
|
|
4234
|
+
} catch {
|
|
4235
|
+
return refuse(notSignedIn);
|
|
4236
|
+
}
|
|
4237
|
+
if (token === null || !ACCOUNT_TOKEN3.test(token)) return refuse(notSignedIn);
|
|
4238
|
+
return { kind: "account", origin: chosen.origin, email: chosen.email, token, folder, workFolder: work, projectId };
|
|
4239
|
+
}
|
|
4240
|
+
|
|
4241
|
+
// src/connect/account-link.ts
|
|
4242
|
+
function defaultAccountStore(env = process.env) {
|
|
4243
|
+
return createAccountStore({ env, platform: process.platform, exec: spawnExec, home: homedir() });
|
|
4244
|
+
}
|
|
4245
|
+
var ACCOUNT_OTHER_SERVER = (saved, asked) => `This folder's designsource sign-in was saved for ${saved}, so designsource will not send it to ${asked}. Pass --token for that server, or leave out --api.`;
|
|
4246
|
+
var accountProjectRoute = (projectId, kind) => `/api/agent/projects/${encodeURIComponent(projectId)}/${kind}`;
|
|
4247
|
+
var LINKED_PROJECT_GONE_CLI = "The design system linked to this folder is gone (deleted, or no longer in your account). Ask your coding agent to link another one, or pass --token with a project token.";
|
|
4248
|
+
function cliAccountMessageForResponse(status, body, api) {
|
|
4249
|
+
if (status === 401) return ACCOUNT_TOKEN_MESSAGE;
|
|
4250
|
+
if (status === 404) return LINKED_PROJECT_GONE_CLI;
|
|
4251
|
+
return messageForResponse(status, body, api);
|
|
4252
|
+
}
|
|
4253
|
+
async function linkedAccount(input) {
|
|
4254
|
+
const { cwd, api, apiGiven, accounts } = input;
|
|
4255
|
+
const home = input.home ?? homedir();
|
|
4256
|
+
if (apiGiven) {
|
|
4257
|
+
const asked = await resolveAccount({ api, apiGiven: true, cwd, home, accounts, requireLink: true });
|
|
4258
|
+
if (asked.kind === "account" && asked.projectId !== null) return { token: asked.token, origin: asked.origin, projectId: asked.projectId, email: asked.email };
|
|
4259
|
+
const other = await resolveAccount({ api, apiGiven: false, cwd, home, accounts, requireLink: true });
|
|
4260
|
+
if (other.kind === "account" && other.projectId !== null && other.origin !== safeOrigin(api)) {
|
|
4261
|
+
throw new CliError(ACCOUNT_OTHER_SERVER(other.origin, api));
|
|
4262
|
+
}
|
|
4263
|
+
return null;
|
|
4264
|
+
}
|
|
4265
|
+
const found = await resolveAccount({ api, apiGiven: false, cwd, home, accounts, requireLink: true });
|
|
4266
|
+
if (found.kind !== "account" || found.projectId === null) return null;
|
|
4267
|
+
return { token: found.token, origin: found.origin, projectId: found.projectId, email: found.email };
|
|
4268
|
+
}
|
|
4269
|
+
var safeOrigin = (api) => {
|
|
4270
|
+
try {
|
|
4271
|
+
return originOf(api);
|
|
4272
|
+
} catch {
|
|
4273
|
+
return null;
|
|
4274
|
+
}
|
|
4275
|
+
};
|
|
4276
|
+
|
|
4277
|
+
// src/connect/api-for.ts
|
|
4278
|
+
var SAVED_TOKEN_OTHER_SERVER = (name, saved, asked) => `The saved token for "${name}" was connected to ${saved}, so designsource will not send it to ${asked}. Pass --token for that server, or leave out --api.`;
|
|
4279
|
+
var UNTRUSTED_SERVER = (asked) => `designsource will not send a token to ${asked}: that server was never connected on this computer. If you trust it, run npx designsource connect --api ${asked} in your project folder yourself.`;
|
|
4280
|
+
function apiFor(args, saved) {
|
|
4281
|
+
if (!saved) return args.api;
|
|
4282
|
+
if (!args.apiGiven) return saved.api ?? args.api;
|
|
4283
|
+
const origin = saved.api ?? DEFAULT_API_ORIGIN;
|
|
4284
|
+
if (!sameApi(args.api, origin)) throw new CliError(SAVED_TOKEN_OTHER_SERVER(saved.name, origin, args.api));
|
|
4285
|
+
return origin;
|
|
4286
|
+
}
|
|
4287
|
+
function givenTokenApi(args, entry) {
|
|
4288
|
+
if (!args.apiGiven) return entry?.api ?? args.api;
|
|
4289
|
+
const trusted = sameApi(args.api, DEFAULT_API_ORIGIN) || isLoopback(args.api) || entry?.api !== void 0 && sameApi(args.api, entry.api);
|
|
4290
|
+
if (!trusted) throw new CliError(UNTRUSTED_SERVER(args.api));
|
|
4291
|
+
return args.api;
|
|
4292
|
+
}
|
|
4293
|
+
function sameApi(a, b) {
|
|
4294
|
+
const key = (value) => {
|
|
4295
|
+
try {
|
|
4296
|
+
const url = new URL(value);
|
|
4297
|
+
if (url.username || url.password) return null;
|
|
4298
|
+
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
4299
|
+
} catch {
|
|
4300
|
+
return null;
|
|
4301
|
+
}
|
|
4302
|
+
};
|
|
4303
|
+
const ka = key(a);
|
|
4304
|
+
return ka !== null && ka === key(b);
|
|
4305
|
+
}
|
|
4306
|
+
function isLoopback(value) {
|
|
4307
|
+
let host;
|
|
4308
|
+
try {
|
|
4309
|
+
host = new URL(value).hostname;
|
|
4310
|
+
} catch {
|
|
4311
|
+
return false;
|
|
4312
|
+
}
|
|
4313
|
+
return host === "localhost" || host.endsWith(".localhost") || /^127(?:\.\d{1,3}){3}$/.test(host) || host === "[::1]";
|
|
4314
|
+
}
|
|
4315
|
+
|
|
4316
|
+
// src/picker.ts
|
|
4317
|
+
import { emitKeypressEvents } from "node:readline";
|
|
4318
|
+
|
|
4319
|
+
// src/prompts.ts
|
|
4320
|
+
import { createInterface } from "node:readline";
|
|
4321
|
+
var shared;
|
|
4322
|
+
var closed = false;
|
|
4323
|
+
var queued = [];
|
|
4324
|
+
var waiting = [];
|
|
4325
|
+
var EOF_MESSAGE = "No more input. Pass the answer as a flag (for example --token or DS_SYNC_TOKEN) when running without a terminal.";
|
|
4326
|
+
function iface() {
|
|
4327
|
+
if (shared) return shared;
|
|
4328
|
+
const r = createInterface({ input: process.stdin, output: process.stdout, terminal: process.stdin.isTTY === true });
|
|
4329
|
+
r.on("line", (line) => {
|
|
4330
|
+
const next = waiting.shift();
|
|
4331
|
+
if (next) next.resolve(line);
|
|
4332
|
+
else queued.push(line);
|
|
4333
|
+
});
|
|
4334
|
+
r.on("close", () => {
|
|
4335
|
+
closed = true;
|
|
4336
|
+
while (waiting.length) waiting.shift().reject(new CliError(EOF_MESSAGE));
|
|
4337
|
+
});
|
|
4338
|
+
if (process.stdin.isTTY === true) {
|
|
4339
|
+
r.on("SIGINT", () => {
|
|
4340
|
+
process.stdout.write("\n");
|
|
4341
|
+
closed = true;
|
|
4342
|
+
while (waiting.length) waiting.shift().reject(new CliError(CANCELLED, 130));
|
|
4343
|
+
r.close();
|
|
4344
|
+
});
|
|
4345
|
+
}
|
|
4346
|
+
shared = r;
|
|
4347
|
+
return r;
|
|
4348
|
+
}
|
|
4349
|
+
function hasInterface() {
|
|
4350
|
+
return shared !== void 0;
|
|
4351
|
+
}
|
|
4352
|
+
function nextLine() {
|
|
4353
|
+
iface();
|
|
4354
|
+
const line = queued.shift();
|
|
4355
|
+
if (line !== void 0) return Promise.resolve(line);
|
|
4356
|
+
if (closed) return Promise.reject(new CliError(EOF_MESSAGE));
|
|
4357
|
+
process.stdin.ref?.();
|
|
4358
|
+
return new Promise((resolve10, reject) => waiting.push({
|
|
4359
|
+
resolve: (line2) => {
|
|
4360
|
+
process.stdin.unref?.();
|
|
4361
|
+
resolve10(line2);
|
|
4362
|
+
},
|
|
4363
|
+
reject: (err) => {
|
|
4364
|
+
process.stdin.unref?.();
|
|
4365
|
+
reject(err);
|
|
4366
|
+
}
|
|
4367
|
+
}));
|
|
4368
|
+
}
|
|
4369
|
+
function promptLine(promptText, fallback) {
|
|
4370
|
+
const r = iface();
|
|
4371
|
+
r.setPrompt(promptText);
|
|
4372
|
+
r.prompt();
|
|
4373
|
+
return nextLine().then((a) => a.trim() || fallback);
|
|
4374
|
+
}
|
|
4375
|
+
function ask(question, fallback) {
|
|
4376
|
+
return promptLine(`${question} (${fallback}) `, fallback);
|
|
4377
|
+
}
|
|
4378
|
+
async function confirm(question, defaultYes = false) {
|
|
4379
|
+
const answer = await promptLine(`${question} ${defaultYes ? "(Y/n)" : "(y/N)"} `, "");
|
|
4380
|
+
return /^y/i.test(answer) ? true : /^n/i.test(answer) ? false : defaultYes;
|
|
4381
|
+
}
|
|
4382
|
+
function askLine(question) {
|
|
4383
|
+
return promptLine(`${question} `, "");
|
|
4384
|
+
}
|
|
4385
|
+
async function askChoice(question, options, defaultIndex) {
|
|
4386
|
+
const list = options.map((o, i) => ` ${i + 1}) ${o}${i === defaultIndex ? " (default)" : ""}`).join("\n");
|
|
4387
|
+
process.stdout.write(`${question}
|
|
4388
|
+
${list}
|
|
4389
|
+
`);
|
|
4390
|
+
for (; ; ) {
|
|
4391
|
+
const answer = await ask("Choice", String(defaultIndex + 1));
|
|
4392
|
+
const idx = Number(answer) - 1;
|
|
4393
|
+
const byName = options.indexOf(answer);
|
|
4394
|
+
if (byName !== -1) return options[byName];
|
|
4395
|
+
if (Number.isInteger(idx) && options[idx] !== void 0) return options[idx];
|
|
4396
|
+
process.stdout.write(`Pick 1-${options.length}.
|
|
4397
|
+
`);
|
|
4398
|
+
}
|
|
4399
|
+
}
|
|
4400
|
+
async function askHidden(question) {
|
|
4401
|
+
const r = iface();
|
|
4402
|
+
const original = typeof r._writeToOutput === "function" ? r._writeToOutput.bind(r) : void 0;
|
|
4403
|
+
if (!original) {
|
|
4404
|
+
throw new CliError("Cannot hide input on this terminal. Pass --token or set DS_SYNC_TOKEN instead.");
|
|
4405
|
+
}
|
|
4406
|
+
let muted = false;
|
|
4407
|
+
r._writeToOutput = (s) => {
|
|
4408
|
+
if (!muted) original(s);
|
|
4409
|
+
};
|
|
4410
|
+
r.setPrompt(`${question} `);
|
|
4411
|
+
r.prompt();
|
|
4412
|
+
muted = true;
|
|
4413
|
+
try {
|
|
4414
|
+
const a = await nextLine();
|
|
4415
|
+
return a.trim();
|
|
4416
|
+
} finally {
|
|
4417
|
+
muted = false;
|
|
4418
|
+
original("\n");
|
|
4419
|
+
r._writeToOutput = original;
|
|
4420
|
+
}
|
|
4459
4421
|
}
|
|
4460
4422
|
|
|
4461
|
-
// src/
|
|
4462
|
-
function
|
|
4463
|
-
|
|
4464
|
-
return
|
|
4423
|
+
// src/picker.ts
|
|
4424
|
+
function pick(question, options, defaultIndex = 0) {
|
|
4425
|
+
if (!rawTerminal()) return askChoice(question, options.map((o) => o.value), defaultIndex);
|
|
4426
|
+
return pickTty(question, options, defaultIndex, process.stdin, process.stdout);
|
|
4465
4427
|
}
|
|
4466
|
-
function
|
|
4467
|
-
const
|
|
4468
|
-
|
|
4469
|
-
|
|
4428
|
+
function rawTerminal() {
|
|
4429
|
+
const { stdin, stdout } = process;
|
|
4430
|
+
return stdin.isTTY === true && stdout.isTTY === true && typeof stdin.setRawMode === "function" && !hasInterface();
|
|
4431
|
+
}
|
|
4432
|
+
function pickMany(question, options, preselected) {
|
|
4433
|
+
if (!rawTerminal()) return pickManyNumbered(question, options, preselected);
|
|
4434
|
+
return pickManyTty(question, options, preselected, process.stdin, process.stdout);
|
|
4435
|
+
}
|
|
4436
|
+
async function pickManyNumbered(question, options, preselected) {
|
|
4437
|
+
const list = options.map((o, i) => ` ${i + 1}) ${o.label}${preselected.includes(o.value) ? " (picked)" : ""}`).join("\n");
|
|
4438
|
+
process.stdout.write(`${question}
|
|
4439
|
+
${list}
|
|
4440
|
+
`);
|
|
4441
|
+
const defaults = options.flatMap((o, i) => preselected.includes(o.value) ? [String(i + 1)] : []);
|
|
4442
|
+
const fallback = defaults.length > 0 ? defaults.join(",") : "none";
|
|
4443
|
+
for (; ; ) {
|
|
4444
|
+
const answer = await ask("Choices", fallback);
|
|
4445
|
+
if (answer === "none") return [];
|
|
4446
|
+
const indexes = answer.split(/[\s,]+/).filter(Boolean).map((part) => {
|
|
4447
|
+
const byValue = options.findIndex((o) => o.value === part.toLowerCase());
|
|
4448
|
+
if (byValue !== -1) return byValue;
|
|
4449
|
+
const byNumber = /^\d+$/.test(part) ? Number(part) - 1 : -1;
|
|
4450
|
+
return options[byNumber] !== void 0 ? byNumber : -1;
|
|
4451
|
+
});
|
|
4452
|
+
if (indexes.length > 0 && !indexes.includes(-1)) return options.filter((_, i) => indexes.includes(i)).map((o) => o.value);
|
|
4453
|
+
process.stdout.write(`Pick from 1-${options.length}, separated by commas.
|
|
4454
|
+
`);
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
4457
|
+
function pickTty(question, options, start, stdin, stdout) {
|
|
4458
|
+
const color = !process.env.NO_COLOR;
|
|
4459
|
+
const bold = (s) => color ? `\x1B[1m${s}\x1B[22m` : s;
|
|
4460
|
+
const dim = (s) => color ? `\x1B[2m${s}\x1B[22m` : s;
|
|
4461
|
+
const n = options.length;
|
|
4462
|
+
let index = start;
|
|
4463
|
+
const rows = () => options.map((o, i) => {
|
|
4464
|
+
const label = i === index ? bold(o.label) : o.label;
|
|
4465
|
+
return `${i === index ? "\u276F" : " "} ${label}${o.hint ? ` ${dim(o.hint)}` : ""}`;
|
|
4466
|
+
});
|
|
4467
|
+
const draw = (lines) => stdout.write(lines.map((l) => `\r\x1B[2K${l}`).join("\n") + "\n");
|
|
4468
|
+
const up = () => stdout.write(`\x1B[${n + 1}A`);
|
|
4469
|
+
emitKeypressEvents(stdin);
|
|
4470
|
+
stdin.setRawMode(true);
|
|
4471
|
+
stdin.resume();
|
|
4472
|
+
stdout.write("\x1B[?25l");
|
|
4473
|
+
draw([question, ...rows()]);
|
|
4474
|
+
return new Promise((resolve10, reject) => {
|
|
4475
|
+
const finish = (after) => {
|
|
4476
|
+
stdin.off("keypress", onKey);
|
|
4477
|
+
stdin.setRawMode(false);
|
|
4478
|
+
stdin.pause();
|
|
4479
|
+
after();
|
|
4480
|
+
stdout.write("\x1B[?25h");
|
|
4481
|
+
};
|
|
4482
|
+
const onKey = (str, key = {}) => {
|
|
4483
|
+
if (key.ctrl && key.name === "c" || key.name === "escape") {
|
|
4484
|
+
finish(() => stdout.write("\n"));
|
|
4485
|
+
reject(new CliError(CANCELLED, 130));
|
|
4486
|
+
return;
|
|
4487
|
+
}
|
|
4488
|
+
if (key.name === "return" || key.name === "enter") {
|
|
4489
|
+
const chosen = options[index];
|
|
4490
|
+
finish(() => {
|
|
4491
|
+
up();
|
|
4492
|
+
stdout.write(`\r\x1B[J${question} ${chosen.label}
|
|
4493
|
+
`);
|
|
4494
|
+
});
|
|
4495
|
+
resolve10(chosen.value);
|
|
4496
|
+
return;
|
|
4497
|
+
}
|
|
4498
|
+
if (key.name === "up" || str === "k") index = (index - 1 + n) % n;
|
|
4499
|
+
else if (key.name === "down" || str === "j") index = (index + 1) % n;
|
|
4500
|
+
else if (str && /^[1-9]$/.test(str) && Number(str) <= n) index = Number(str) - 1;
|
|
4501
|
+
else return;
|
|
4502
|
+
up();
|
|
4503
|
+
draw([question, ...rows()]);
|
|
4504
|
+
};
|
|
4505
|
+
stdin.on("keypress", onKey);
|
|
4506
|
+
});
|
|
4507
|
+
}
|
|
4508
|
+
function pickManyTty(question, options, preselected, stdin, stdout) {
|
|
4509
|
+
const color = !process.env.NO_COLOR;
|
|
4510
|
+
const bold = (s) => color ? `\x1B[1m${s}\x1B[22m` : s;
|
|
4511
|
+
const dim = (s) => color ? `\x1B[2m${s}\x1B[22m` : s;
|
|
4512
|
+
const n = options.length;
|
|
4513
|
+
const ticked = options.map((o) => preselected.includes(o.value));
|
|
4514
|
+
let index = 0;
|
|
4515
|
+
const rows = () => options.map((o, i) => {
|
|
4516
|
+
const label = i === index ? bold(o.label) : o.label;
|
|
4517
|
+
return `${i === index ? "\u276F" : " "} ${ticked[i] ? "\u25C9" : "\u25EF"} ${label}${o.hint ? ` ${dim(o.hint)}` : ""}`;
|
|
4518
|
+
});
|
|
4519
|
+
const head = `${question} ${dim("space toggles, a all, enter confirms")}`;
|
|
4520
|
+
const draw = (lines) => stdout.write(lines.map((l) => `\r\x1B[2K${l}`).join("\n") + "\n");
|
|
4521
|
+
const up = () => stdout.write(`\x1B[${n + 1}A`);
|
|
4522
|
+
emitKeypressEvents(stdin);
|
|
4523
|
+
stdin.setRawMode(true);
|
|
4524
|
+
stdin.resume();
|
|
4525
|
+
stdout.write("\x1B[?25l");
|
|
4526
|
+
draw([head, ...rows()]);
|
|
4527
|
+
return new Promise((resolve10, reject) => {
|
|
4528
|
+
const finish = (after) => {
|
|
4529
|
+
stdin.off("keypress", onKey);
|
|
4530
|
+
stdin.setRawMode(false);
|
|
4531
|
+
stdin.pause();
|
|
4532
|
+
after();
|
|
4533
|
+
stdout.write("\x1B[?25h");
|
|
4534
|
+
};
|
|
4535
|
+
const onKey = (str, key = {}) => {
|
|
4536
|
+
if (key.ctrl && key.name === "c" || key.name === "escape") {
|
|
4537
|
+
finish(() => stdout.write("\n"));
|
|
4538
|
+
reject(new CliError(CANCELLED, 130));
|
|
4539
|
+
return;
|
|
4540
|
+
}
|
|
4541
|
+
if (key.name === "return" || key.name === "enter") {
|
|
4542
|
+
const chosen = options.filter((_, i) => ticked[i]);
|
|
4543
|
+
finish(() => {
|
|
4544
|
+
up();
|
|
4545
|
+
stdout.write(`\r\x1B[J${question} ${chosen.length > 0 ? chosen.map((o) => o.label).join(", ") : "none"}
|
|
4546
|
+
`);
|
|
4547
|
+
});
|
|
4548
|
+
resolve10(chosen.map((o) => o.value));
|
|
4549
|
+
return;
|
|
4550
|
+
}
|
|
4551
|
+
if (key.name === "up" || str === "k") index = (index - 1 + n) % n;
|
|
4552
|
+
else if (key.name === "down" || str === "j") index = (index + 1) % n;
|
|
4553
|
+
else if (key.name === "space" || str === " ") ticked[index] = !ticked[index];
|
|
4554
|
+
else if (str === "a") ticked.fill(!ticked.every(Boolean));
|
|
4555
|
+
else return;
|
|
4556
|
+
up();
|
|
4557
|
+
draw([head, ...rows()]);
|
|
4558
|
+
};
|
|
4559
|
+
stdin.on("keypress", onKey);
|
|
4560
|
+
});
|
|
4470
4561
|
}
|
|
4471
4562
|
|
|
4563
|
+
// src/commands/scaffold.ts
|
|
4564
|
+
import { resolve as resolve7 } from "node:path";
|
|
4565
|
+
|
|
4472
4566
|
// src/connect/resolve-token.ts
|
|
4567
|
+
import { homedir as homedir2 } from "node:os";
|
|
4568
|
+
import { join as join10, relative as relative4 } from "node:path";
|
|
4473
4569
|
var NO_TOKEN_FOR_PROJECT = (nameOrId) => `This computer has no token for the "${nameOrId}" design system. Run npx designsource connect in the project folder.`;
|
|
4474
4570
|
function defaultStore(env = process.env) {
|
|
4475
|
-
return createStore({ env, platform: process.platform, exec: spawnExec, home:
|
|
4571
|
+
return createStore({ env, platform: process.platform, exec: spawnExec, home: homedir2() });
|
|
4476
4572
|
}
|
|
4477
4573
|
var TERMINAL = { askHidden, pick: (q, options) => pick(q, options, 0) };
|
|
4478
4574
|
async function resolveToken(input, prompts = TERMINAL) {
|
|
@@ -4527,7 +4623,7 @@ function validateManifest(json) {
|
|
|
4527
4623
|
// src/fetch-manifest.ts
|
|
4528
4624
|
async function fetchManifest(opts, fetchImpl = fetch) {
|
|
4529
4625
|
const query = { framework: opts.framework, ...opts.name ? { name: opts.name } : {}, ...opts.screens ? { screens: opts.screens, pages: "1" } : {} };
|
|
4530
|
-
return validateManifest(await getJson({ api: opts.api, token: opts.token, path: "/api/starter", query }, fetchImpl));
|
|
4626
|
+
return validateManifest(await getJson({ api: opts.api, token: opts.token, path: opts.path ?? "/api/starter", query, ...opts.messages ? { messages: opts.messages } : {} }, fetchImpl));
|
|
4531
4627
|
}
|
|
4532
4628
|
|
|
4533
4629
|
// src/package-name.ts
|
|
@@ -4584,11 +4680,21 @@ async function requireSavedToken(given, opts) {
|
|
|
4584
4680
|
async function savedToken(given, opts) {
|
|
4585
4681
|
return resolveToken({ given, cwd: opts.cwd, store: opts.store ?? defaultStore(), interactive: opts.interactive ?? isTerminal(), prompt: false });
|
|
4586
4682
|
}
|
|
4683
|
+
async function savedOrLinked(args, opts) {
|
|
4684
|
+
const saved = await savedToken(args.token, opts);
|
|
4685
|
+
if (saved) return { token: saved.token, api: apiFor(args, saved.entry), account: null };
|
|
4686
|
+
const link = await linkedAccount({ cwd: opts.cwd, api: args.api, apiGiven: args.apiGiven === true, accounts: opts.accounts ?? defaultAccountStore(), home: opts.home });
|
|
4687
|
+
return link ? { token: link.token, api: link.origin, account: link } : null;
|
|
4688
|
+
}
|
|
4689
|
+
var USING_LINK = (email, origin) => `Using the design system linked to this folder (signed in as ${email} on ${origin}).`;
|
|
4587
4690
|
async function scaffold(input, env, io) {
|
|
4588
4691
|
const { folder, framework, token, api, force } = input;
|
|
4589
4692
|
const { root, created } = planTarget(io.cwd, folder, framework, force);
|
|
4590
4693
|
const screens = input.screens === true && framework === "next" ? { screens: "all" } : {};
|
|
4591
|
-
|
|
4694
|
+
if (input.account) io.stdout(`${USING_LINK(printable(input.account.email), input.account.origin)}
|
|
4695
|
+
`);
|
|
4696
|
+
const account = input.account ? { path: accountProjectRoute(input.account.projectId, "starter"), messages: cliAccountMessageForResponse } : {};
|
|
4697
|
+
const manifest = await fetchManifest({ api, token, framework, name: packageNameFor(folder), ...screens, ...account }, io.fetchImpl);
|
|
4592
4698
|
const { runner, version } = detectRunner(env.npm_config_user_agent);
|
|
4593
4699
|
const packageManager = runner === "pnpm" && version ? `pnpm@${version}` : void 0;
|
|
4594
4700
|
const { written } = writeFiles(root, manifest.files, { force, created, packageManager });
|
|
@@ -4632,7 +4738,7 @@ function ttyQuestions(args, mode, io) {
|
|
|
4632
4738
|
}
|
|
4633
4739
|
};
|
|
4634
4740
|
}
|
|
4635
|
-
async function runAddCommand(args, io, exec = spawnExec, store) {
|
|
4741
|
+
async function runAddCommand(args, io, exec = spawnExec, store, accounts) {
|
|
4636
4742
|
const root = io.cwd;
|
|
4637
4743
|
const terminal = process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
4638
4744
|
const interactive = !args.yes && terminal;
|
|
@@ -4645,18 +4751,23 @@ async function runAddCommand(args, io, exec = spawnExec, store) {
|
|
|
4645
4751
|
const first = previouslyAdded(root, targets).every((n) => n === "utils") && !sectionPresent(root, targets).present;
|
|
4646
4752
|
if (first) mode = await pick(PICK_QUESTION, ADD_MODES, 0);
|
|
4647
4753
|
}
|
|
4648
|
-
const
|
|
4754
|
+
const access = await savedOrLinked(args, { cwd: root, store, accounts, interactive: terminal });
|
|
4755
|
+
const { token, api, account } = access ?? { token: await requireToken(void 0), api: apiFor(args, null), account: null };
|
|
4756
|
+
if (account) io.stdout(`${USING_LINK(printable(account.email), account.origin)}
|
|
4757
|
+
`);
|
|
4649
4758
|
const questions = interactive ? ttyQuestions(args, mode, io) : nonInteractiveQuestions(args);
|
|
4650
4759
|
try {
|
|
4651
4760
|
const result = await runAdd(
|
|
4652
4761
|
{
|
|
4653
4762
|
root,
|
|
4654
4763
|
token,
|
|
4655
|
-
api
|
|
4764
|
+
api,
|
|
4765
|
+
...account ? { kitPath: accountProjectRoute(account.projectId, "kit"), messages: cliAccountMessageForResponse } : {},
|
|
4656
4766
|
components: args.components,
|
|
4657
4767
|
skipInstall: args.skipInstall,
|
|
4658
4768
|
all: args.all,
|
|
4659
4769
|
blocks: !args.noBlocks,
|
|
4770
|
+
addBlocks: args.blocks,
|
|
4660
4771
|
screens: args.screens,
|
|
4661
4772
|
shell: args.shell,
|
|
4662
4773
|
site: args.site,
|
|
@@ -4677,7 +4788,7 @@ async function runAddCommand(args, io, exec = spawnExec, store) {
|
|
|
4677
4788
|
|
|
4678
4789
|
// src/commands/connect.ts
|
|
4679
4790
|
import { accessSync, constants as constants2, existsSync as existsSync11, statSync as statSync3 } from "node:fs";
|
|
4680
|
-
import { homedir as
|
|
4791
|
+
import { homedir as homedir3 } from "node:os";
|
|
4681
4792
|
import { join as join11 } from "node:path";
|
|
4682
4793
|
|
|
4683
4794
|
// src/connect/fetch-project.ts
|
|
@@ -4722,7 +4833,7 @@ function onPath(bin, env, platform) {
|
|
|
4722
4833
|
);
|
|
4723
4834
|
}
|
|
4724
4835
|
function defaultConnectDeps(env) {
|
|
4725
|
-
const home =
|
|
4836
|
+
const home = homedir3();
|
|
4726
4837
|
const platform = process.platform;
|
|
4727
4838
|
return {
|
|
4728
4839
|
store: defaultStore(env),
|
|
@@ -4787,7 +4898,7 @@ async function runConnect(args, io, deps = defaultConnectDeps(process.env)) {
|
|
|
4787
4898
|
const say = (lines) => io.stdout(lines.map((l) => `${l}
|
|
4788
4899
|
`).join(""));
|
|
4789
4900
|
if (args.forget) return forget(args, root, saveFolder, store, interactive, prompts, deps.credentialsPath, say);
|
|
4790
|
-
const refusal = homeFolderRefusal(root, deps.home ??
|
|
4901
|
+
const refusal = homeFolderRefusal(root, deps.home ?? homedir3()) ?? (main2 ? homeFolderRefusal(main2, deps.home ?? homedir3()) : null);
|
|
4791
4902
|
if (refusal) throw new CliError(refusal);
|
|
4792
4903
|
say([`Connecting ${root}`, ...main2 ? [WORKTREE_NOTE(main2)] : []]);
|
|
4793
4904
|
let apps;
|
|
@@ -4869,11 +4980,11 @@ function savedFor(store, root, saveFolder) {
|
|
|
4869
4980
|
}
|
|
4870
4981
|
|
|
4871
4982
|
// src/commands/create.ts
|
|
4872
|
-
async function runCreate(args, env, io, store) {
|
|
4873
|
-
const
|
|
4983
|
+
async function runCreate(args, env, io, store, accounts) {
|
|
4984
|
+
const access = await savedOrLinked(args, { cwd: io.cwd, store, accounts });
|
|
4874
4985
|
const folder = args.folder ?? await askFolder(CREATE_DEFAULT_FOLDER);
|
|
4875
|
-
const token =
|
|
4876
|
-
await scaffold({ folder, framework: "next", token, api
|
|
4986
|
+
const { token, api, account } = access ?? { token: await requireToken(void 0), api: apiFor(args, null), account: null };
|
|
4987
|
+
await scaffold({ folder, framework: "next", token, api, account, force: args.force, screens: args.noScreens !== true }, env, io);
|
|
4877
4988
|
}
|
|
4878
4989
|
|
|
4879
4990
|
// src/commands/integrate.ts
|
|
@@ -4883,20 +4994,20 @@ var INTEGRATE_OPTIONS = [
|
|
|
4883
4994
|
{ value: "angular", label: "Angular" },
|
|
4884
4995
|
{ value: "css", label: "Plain CSS", hint: "any other stack" }
|
|
4885
4996
|
];
|
|
4886
|
-
async function runIntegrate(args, env, io, store) {
|
|
4997
|
+
async function runIntegrate(args, env, io, store, accounts) {
|
|
4887
4998
|
const framework = args.framework ?? await pick("Framework", INTEGRATE_OPTIONS, 0);
|
|
4888
|
-
const
|
|
4999
|
+
const access = await savedOrLinked(args, { cwd: io.cwd, store, accounts });
|
|
4889
5000
|
const folder = args.folder ?? await askFolder(INTEGRATE_DEFAULT_FOLDER);
|
|
4890
|
-
const token =
|
|
4891
|
-
await scaffold({ folder, framework, token, api
|
|
5001
|
+
const { token, api, account } = access ?? { token: await requireToken(void 0), api: apiFor(args, null), account: null };
|
|
5002
|
+
await scaffold({ folder, framework, token, api, account, force: args.force }, env, io);
|
|
4892
5003
|
}
|
|
4893
5004
|
|
|
4894
5005
|
// src/commands/login.ts
|
|
4895
5006
|
import { existsSync as existsSync12 } from "node:fs";
|
|
4896
5007
|
import { join as join12 } from "node:path";
|
|
4897
|
-
import { homedir as
|
|
5008
|
+
import { homedir as homedir4, hostname } from "node:os";
|
|
4898
5009
|
function defaultLoginDeps(env) {
|
|
4899
|
-
const home =
|
|
5010
|
+
const home = homedir4();
|
|
4900
5011
|
const platform = process.platform;
|
|
4901
5012
|
return {
|
|
4902
5013
|
accounts: createAccountStore({ env, platform, exec: spawnExec, home }),
|
|
@@ -4908,7 +5019,7 @@ function defaultLoginDeps(env) {
|
|
|
4908
5019
|
platform
|
|
4909
5020
|
};
|
|
4910
5021
|
}
|
|
4911
|
-
var sleepFor = (ms) => new Promise((
|
|
5022
|
+
var sleepFor = (ms) => new Promise((resolve10) => setTimeout(resolve10, ms));
|
|
4912
5023
|
var UNTRUSTED_LOGIN_SERVER = (api) => `designsource will not sign in to ${api} from a script: outside a terminal it signs in only to ${DEFAULT_API_ORIGIN} or a server on this computer. If you trust ${api}, run npx designsource login --api ${api} in a terminal yourself.`;
|
|
4913
5024
|
var ACCOUNT_SCOPES_NEEDED = ["projects:create", "projects:read", "screens:create"];
|
|
4914
5025
|
var REVOKE_FAILED = "Could not reach the server to revoke this sign-in; revoke it on your profile page.";
|
|
@@ -5062,56 +5173,10 @@ async function runLogout(args, io, deps = defaultLoginDeps(process.env)) {
|
|
|
5062
5173
|
}
|
|
5063
5174
|
|
|
5064
5175
|
// src/mcp/server.ts
|
|
5065
|
-
import { homedir as
|
|
5176
|
+
import { homedir as homedir6 } from "node:os";
|
|
5066
5177
|
|
|
5067
5178
|
// src/version.ts
|
|
5068
|
-
var VERSION = true ? "0.
|
|
5069
|
-
|
|
5070
|
-
// src/mcp/account-session.ts
|
|
5071
|
-
var NOT_SIGNED_IN_FOR = (root) => `designsource is not signed in for ${printable(root)}. Ask the user to run npx designsource login in a terminal in that folder, then restart this app. A sign-in there also covers its git worktrees.`;
|
|
5072
|
-
var SEVERAL_ACCOUNTS = "More than one designsource account is signed in on this computer; pass --api.";
|
|
5073
|
-
var NO_LINK = "No design system is linked to this folder yet. Call list_design_systems, then use_design_system with one of its ids, or call create_design_system to make a new one.";
|
|
5074
|
-
var ACCOUNT_TOKEN3 = /^dsa_[A-Za-z0-9_-]{43}$/;
|
|
5075
|
-
var PROJECT_ID3 = /^[A-Za-z0-9_-]+$/;
|
|
5076
|
-
var refuse = (message) => ({ kind: "none", message });
|
|
5077
|
-
function chooseAccount(api, apiGiven, accounts, notSignedIn) {
|
|
5078
|
-
if (apiGiven) {
|
|
5079
|
-
let origin;
|
|
5080
|
-
try {
|
|
5081
|
-
origin = originOf(api);
|
|
5082
|
-
} catch {
|
|
5083
|
-
return refuse(notSignedIn);
|
|
5084
|
-
}
|
|
5085
|
-
return accounts.get(origin) ?? refuse(notSignedIn);
|
|
5086
|
-
}
|
|
5087
|
-
const all = accounts.all();
|
|
5088
|
-
if (all.length === 1) return all[0];
|
|
5089
|
-
const fallback = accounts.get(DEFAULT_API_ORIGIN);
|
|
5090
|
-
if (fallback) return fallback;
|
|
5091
|
-
return refuse(all.length > 1 ? SEVERAL_ACCOUNTS : notSignedIn);
|
|
5092
|
-
}
|
|
5093
|
-
async function resolveAccount(input) {
|
|
5094
|
-
const { api, apiGiven, cwd, home, accounts } = input;
|
|
5095
|
-
const { work, trust } = projectFolders(cwd);
|
|
5096
|
-
const notSignedIn = NOT_SIGNED_IN_FOR(trust);
|
|
5097
|
-
const chosen = chooseAccount(api, apiGiven, accounts, notSignedIn);
|
|
5098
|
-
if ("kind" in chosen) return chosen;
|
|
5099
|
-
const homeDir = normaliseFolder(home);
|
|
5100
|
-
if (homeFolderRefusal(trust, homeDir) !== null || homeFolderRefusal(work, homeDir) !== null) return refuse(notSignedIn);
|
|
5101
|
-
const trusted = (f) => chosen.folders.some((saved) => normaliseFolder(saved) === f);
|
|
5102
|
-
const folder = trusted(work) ? work : trusted(trust) ? trust : null;
|
|
5103
|
-
if (folder === null) return refuse(notSignedIn);
|
|
5104
|
-
const linked = Object.entries(chosen.links).find(([f]) => normaliseFolder(f) === folder)?.[1];
|
|
5105
|
-
const projectId = linked !== void 0 && PROJECT_ID3.test(linked) ? linked : null;
|
|
5106
|
-
let token;
|
|
5107
|
-
try {
|
|
5108
|
-
token = await accounts.token(chosen.origin);
|
|
5109
|
-
} catch {
|
|
5110
|
-
return refuse(notSignedIn);
|
|
5111
|
-
}
|
|
5112
|
-
if (token === null || !ACCOUNT_TOKEN3.test(token)) return refuse(notSignedIn);
|
|
5113
|
-
return { kind: "account", origin: chosen.origin, email: chosen.email, token, folder, workFolder: work, projectId };
|
|
5114
|
-
}
|
|
5179
|
+
var VERSION = true ? "0.14.0" : "0.0.0-dev";
|
|
5115
5180
|
|
|
5116
5181
|
// src/mcp/jsonrpc.ts
|
|
5117
5182
|
import { StringDecoder } from "node:string_decoder";
|
|
@@ -5183,6 +5248,11 @@ function getPrompt(name) {
|
|
|
5183
5248
|
return { description: "Integrate the design system into the current repository.", messages: [{ role: "user", content: { type: "text", text: INTEGRATE_TEXT } }] };
|
|
5184
5249
|
}
|
|
5185
5250
|
|
|
5251
|
+
// src/mcp/tools.ts
|
|
5252
|
+
import { existsSync as existsSync14 } from "node:fs";
|
|
5253
|
+
import { homedir as homedir5 } from "node:os";
|
|
5254
|
+
import { join as join15 } from "node:path";
|
|
5255
|
+
|
|
5186
5256
|
// src/mcp/account-tools.ts
|
|
5187
5257
|
import { randomUUID } from "node:crypto";
|
|
5188
5258
|
|
|
@@ -5465,8 +5535,105 @@ function worktreeOf(cwd) {
|
|
|
5465
5535
|
return worktree ? { work, main: trust } : null;
|
|
5466
5536
|
}
|
|
5467
5537
|
|
|
5538
|
+
// src/mcp/target-folder.ts
|
|
5539
|
+
import { existsSync as existsSync13, readdirSync as readdirSync5, realpathSync as realpathSync4, statSync as statSync4 } from "node:fs";
|
|
5540
|
+
import { dirname as dirname6, isAbsolute as isAbsolute6, join as join14, relative as relative6, resolve as resolve9, sep as sep6 } from "node:path";
|
|
5541
|
+
var FOLDER_ARG_MAX = 1024;
|
|
5542
|
+
var CANDIDATES_MAX = 8;
|
|
5543
|
+
var SCAN_DIRS_MAX = 200;
|
|
5544
|
+
var FOLDER_ARG = '"folder" must be a path to a folder (relative to the project, or absolute).';
|
|
5545
|
+
var FOLDER_NOT_FOUND = (folder) => `No folder at ${printable(folder)}. Pass the path of the app's folder (the one with its package.json).`;
|
|
5546
|
+
var FOLDER_NOT_SIGNED_IN = (root, work) => `designsource is not signed in for ${printable(root)}. Ask the user to run npx designsource login in a terminal in that folder, then call add_ui_kit again; or pass a folder inside ${printable(work)}.`;
|
|
5547
|
+
var FOLDER_NOT_CONNECTED = (root, work) => `${printable(root)} is not connected to this design system. Ask the user to run npx designsource connect in a terminal in that folder, then call add_ui_kit again; or pass a folder inside ${printable(work)}.`;
|
|
5548
|
+
var FOLDER_OUTSIDE = (folder, work) => `${printable(folder)} is outside ${printable(work)}. This app runs designsource with a project token for that folder only; pass a folder inside it, or ask the user to run npx designsource connect in a terminal in the app's folder and restart this app.`;
|
|
5549
|
+
var FOLDER_HOME = (root) => `${printable(root)} is the home folder or a system folder; designsource never writes there. Pass the app's own folder.`;
|
|
5550
|
+
var NO_APP_HERE = (root, candidates, signInFirst = []) => [
|
|
5551
|
+
`No package.json in ${printable(root)}, so there is no app here to add the UI kit to. Call add_ui_kit again with folder set to the app's folder.`,
|
|
5552
|
+
...candidates.length > 0 ? [`Folders with an app you may pass: ${candidates.map(printable).join(", ")}.`] : [],
|
|
5553
|
+
...signInFirst.length > 0 ? [`Apps that are repositories of their own, which the user must first run npx designsource login in (in a terminal, then restart this app): ${signInFirst.map(printable).join(", ")}.`] : ["A folder in another repository works only once the user has run npx designsource login in a terminal there."]
|
|
5554
|
+
].join(" ");
|
|
5555
|
+
function within3(folder, root) {
|
|
5556
|
+
const rel = relative6(root, folder);
|
|
5557
|
+
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep6}`) && !isAbsolute6(rel);
|
|
5558
|
+
}
|
|
5559
|
+
function crossesRepository(target, base) {
|
|
5560
|
+
for (let dir = target; dir !== base && within3(dir, base); dir = dirname6(dir)) {
|
|
5561
|
+
if (existsSync13(join14(dir, ".git"))) return true;
|
|
5562
|
+
}
|
|
5563
|
+
return false;
|
|
5564
|
+
}
|
|
5565
|
+
function resolveTarget(arg, src) {
|
|
5566
|
+
if (typeof arg !== "string" || arg.trim() === "" || arg.length > FOLDER_ARG_MAX || /[\u0000-\u001f\u007f]/.test(arg)) return { ok: false, message: FOLDER_ARG };
|
|
5567
|
+
if (!isAbsolute6(arg) && src.base === null) return { ok: false, message: FOLDER_ARG };
|
|
5568
|
+
const asked = isAbsolute6(arg) ? resolve9(arg) : resolve9(src.base, arg);
|
|
5569
|
+
let real2;
|
|
5570
|
+
try {
|
|
5571
|
+
real2 = realpathSync4(asked);
|
|
5572
|
+
if (!statSync4(real2).isDirectory()) return { ok: false, message: FOLDER_NOT_FOUND(asked) };
|
|
5573
|
+
} catch {
|
|
5574
|
+
return { ok: false, message: FOLDER_NOT_FOUND(asked) };
|
|
5575
|
+
}
|
|
5576
|
+
const roots = projectFolders(real2);
|
|
5577
|
+
if (relative6(roots.work, real2).split(sep6).some((part) => part === ".git" || part === "node_modules")) return { ok: false, message: FOLDER_ARG };
|
|
5578
|
+
const home = normaliseFolder(src.home);
|
|
5579
|
+
if (homeFolderRefusal(real2, home) !== null) return { ok: false, message: FOLDER_HOME(real2) };
|
|
5580
|
+
if (src.base !== null && within3(real2, src.base) && !crossesRepository(real2, src.base)) return { ok: true, folder: real2, via: "inside" };
|
|
5581
|
+
if (homeFolderRefusal(roots.work, home) !== null || homeFolderRefusal(roots.trust, home) !== null) return { ok: false, message: FOLDER_HOME(roots.work) };
|
|
5582
|
+
const work = src.base ?? real2;
|
|
5583
|
+
const found = trustFor(src, roots);
|
|
5584
|
+
if (found) return { ok: true, folder: real2, via: "trusted", root: found.folder, projectId: found.projectId };
|
|
5585
|
+
if (src.accountTrust) return { ok: false, message: FOLDER_NOT_SIGNED_IN(roots.trust, work) };
|
|
5586
|
+
return { ok: false, message: src.savedFolders ? FOLDER_NOT_CONNECTED(roots.trust, work) : FOLDER_OUTSIDE(real2, work) };
|
|
5587
|
+
}
|
|
5588
|
+
function trustFor(src, roots) {
|
|
5589
|
+
if (src.accountTrust) return src.accountTrust(roots);
|
|
5590
|
+
const saved = (src.savedFolders ?? []).map((f) => normaliseFolder(f));
|
|
5591
|
+
const folder = [roots.work, roots.trust].find((r) => saved.includes(r));
|
|
5592
|
+
return folder === void 0 ? null : { folder, projectId: null };
|
|
5593
|
+
}
|
|
5594
|
+
var hasApp = (dir) => {
|
|
5595
|
+
try {
|
|
5596
|
+
return statSync4(join14(dir, "package.json")).isFile();
|
|
5597
|
+
} catch {
|
|
5598
|
+
return false;
|
|
5599
|
+
}
|
|
5600
|
+
};
|
|
5601
|
+
function appCandidates(base, near, src, trusted = []) {
|
|
5602
|
+
const apps = [];
|
|
5603
|
+
const signInFirst = [];
|
|
5604
|
+
const children = (dir) => {
|
|
5605
|
+
try {
|
|
5606
|
+
return readdirSync5(dir, { withFileTypes: true }).filter((d) => d.isDirectory() && !d.name.startsWith(".") && d.name !== "node_modules").map((d) => join14(dir, d.name)).sort();
|
|
5607
|
+
} catch {
|
|
5608
|
+
return [];
|
|
5609
|
+
}
|
|
5610
|
+
};
|
|
5611
|
+
let read = 0;
|
|
5612
|
+
const visit = (dir, depth, inBase) => {
|
|
5613
|
+
if (read >= SCAN_DIRS_MAX || apps.length >= CANDIDATES_MAX && signInFirst.length >= CANDIDATES_MAX) return;
|
|
5614
|
+
read++;
|
|
5615
|
+
const ownRepo = existsSync13(join14(dir, ".git"));
|
|
5616
|
+
if (hasApp(dir)) {
|
|
5617
|
+
const real2 = normaliseFolder(dir);
|
|
5618
|
+
if (ownRepo) {
|
|
5619
|
+
const list = trustFor(src, projectFolders(real2)) ? apps : signInFirst;
|
|
5620
|
+
if (!list.includes(real2) && list.length < CANDIDATES_MAX) list.push(real2);
|
|
5621
|
+
} else if (inBase && !apps.includes(real2) && apps.length < CANDIDATES_MAX) apps.push(real2);
|
|
5622
|
+
if (ownRepo || inBase) return;
|
|
5623
|
+
}
|
|
5624
|
+
if (depth < 2 && !ownRepo) for (const child of children(dir)) visit(child, depth + 1, inBase);
|
|
5625
|
+
};
|
|
5626
|
+
for (const child of children(base)) visit(child, 1, true);
|
|
5627
|
+
if (near !== base) for (const child of children(near)) visit(child, 1, false);
|
|
5628
|
+
for (const f of [...trusted].map((t) => normaliseFolder(t)).sort()) {
|
|
5629
|
+
if (apps.length >= CANDIDATES_MAX) break;
|
|
5630
|
+
if (f !== base && !apps.includes(f) && dirname6(f) === dirname6(near) && hasApp(f)) apps.push(f);
|
|
5631
|
+
}
|
|
5632
|
+
return { apps, signInFirst };
|
|
5633
|
+
}
|
|
5634
|
+
|
|
5468
5635
|
// src/mcp/tools.ts
|
|
5469
|
-
var accountProjectPath = (projectId, kind) =>
|
|
5636
|
+
var accountProjectPath = (projectId, kind) => accountProjectRoute(projectId, kind);
|
|
5470
5637
|
var READ_ONLY = { readOnlyHint: true };
|
|
5471
5638
|
var TIERS = ["design", "semantic", "component"];
|
|
5472
5639
|
var CATEGORIES = ["color", "spacing", "radius", "typography", "shadow", "zIndex", "border", "gradient"];
|
|
@@ -5494,10 +5661,11 @@ function optionalEnum(args, key, allowed) {
|
|
|
5494
5661
|
var MCP_EXEC_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
5495
5662
|
var UNKNOWN_FOR_AGENT = (names) => `Unknown component(s): ${names.join(", ")}. Call list_components for the names.`;
|
|
5496
5663
|
var FOREIGN_FILES = (paths) => `These files exist and were not added by designsource: ${paths.join(", ")}. Ask the user whether to replace them, then call add_ui_kit again with replace_existing: true.`;
|
|
5497
|
-
function kitAccess(ctx) {
|
|
5664
|
+
function kitAccess(ctx, linkedTo) {
|
|
5498
5665
|
if (ctx.token !== null) return { token: ctx.token, api: ctx.api };
|
|
5499
5666
|
if (!ctx.account) return errorResult(ctx.missingToken ?? MCP_TOKEN_REQUIRED);
|
|
5500
|
-
const { token, api
|
|
5667
|
+
const { token, api } = ctx.account;
|
|
5668
|
+
const projectId = linkedTo ?? ctx.account.projectId;
|
|
5501
5669
|
if (projectId === null) return errorResult(NO_LINK);
|
|
5502
5670
|
return { token, api, kitPath: accountProjectPath(projectId, "kit"), messages: accountMessageForResponse };
|
|
5503
5671
|
}
|
|
@@ -5562,19 +5730,53 @@ function screensArg(v) {
|
|
|
5562
5730
|
if (!names.every(isScreenName2)) return { ok: false };
|
|
5563
5731
|
return { ok: true, value: names.length > 0 ? [...new Set(names)] : void 0, site };
|
|
5564
5732
|
}
|
|
5733
|
+
function targetSources(ctx, base) {
|
|
5734
|
+
return {
|
|
5735
|
+
base,
|
|
5736
|
+
home: ctx.home ?? homedir5(),
|
|
5737
|
+
...ctx.token === null && ctx.account ? { accountTrust: (roots) => ctx.account.trustOf?.(roots) ?? null } : {},
|
|
5738
|
+
...ctx.token !== null ? { savedFolders: ctx.projectFolders } : {}
|
|
5739
|
+
};
|
|
5740
|
+
}
|
|
5741
|
+
var BLOCKS_BOTH_FOR_AGENT = '"blocks" and "no_blocks" cannot both be true.';
|
|
5565
5742
|
async function addUiKit(args, ctx) {
|
|
5566
|
-
const { components, replace_existing: replace, no_blocks: noBlocks } = args;
|
|
5743
|
+
const { components, replace_existing: replace, no_blocks: noBlocks, blocks: addBlocks } = args;
|
|
5567
5744
|
if (components !== void 0 && !(Array.isArray(components) && components.every((c) => typeof c === "string"))) {
|
|
5568
5745
|
return errorResult('"components" must be an array of component names.');
|
|
5569
5746
|
}
|
|
5570
5747
|
if (replace !== void 0 && typeof replace !== "boolean") return errorResult('"replace_existing" must be true or false.');
|
|
5571
5748
|
if (noBlocks !== void 0 && typeof noBlocks !== "boolean") return errorResult('"no_blocks" must be true or false.');
|
|
5749
|
+
if (addBlocks !== void 0 && typeof addBlocks !== "boolean") return errorResult('"blocks" must be true or false.');
|
|
5750
|
+
if (addBlocks === true && noBlocks === true) return errorResult(BLOCKS_BOTH_FOR_AGENT);
|
|
5572
5751
|
const screens = screensArg(args.screens);
|
|
5573
5752
|
if (!screens.ok) return errorResult(SCREENS_ARG);
|
|
5574
|
-
|
|
5753
|
+
if (ctx.token === null && !ctx.account) return errorResult(ctx.missingToken ?? MCP_TOKEN_REQUIRED);
|
|
5754
|
+
const fallback = ctx.token !== null ? resolveProjectFolder(ctx.cwd, ctx.projectFolders === null ? null : { folders: ctx.projectFolders }) : ctx.account.workFolder;
|
|
5755
|
+
const base = fallback === null ? null : normaliseFolder(fallback);
|
|
5756
|
+
let root;
|
|
5757
|
+
let linkedTo;
|
|
5758
|
+
let usedLine = [];
|
|
5759
|
+
if (args.folder !== void 0) {
|
|
5760
|
+
const target = resolveTarget(args.folder, targetSources(ctx, base));
|
|
5761
|
+
if (!target.ok) return errorResult(target.message);
|
|
5762
|
+
root = target.folder;
|
|
5763
|
+
if (target.via === "trusted" && ctx.token === null) {
|
|
5764
|
+
linkedTo = target.projectId;
|
|
5765
|
+
usedLine = [target.projectId !== null ? `Using the design system linked to ${printable(target.root)}.` : `Using this session's design system (${printable(target.root)} has none linked).`];
|
|
5766
|
+
}
|
|
5767
|
+
} else {
|
|
5768
|
+
if (base === null) return errorResult(NOT_SURE_WHICH_FOLDER);
|
|
5769
|
+
root = base;
|
|
5770
|
+
const own = kitAccess(ctx);
|
|
5771
|
+
if (isResult2(own)) return own;
|
|
5772
|
+
if (!existsSync14(join15(root, "package.json"))) {
|
|
5773
|
+
const near = ctx.account?.folder ?? root;
|
|
5774
|
+
const found = appCandidates(root, near, targetSources(ctx, base), ctx.account?.trustedFolders?.() ?? []);
|
|
5775
|
+
return errorResult(NO_APP_HERE(root, found.apps, found.signInFirst));
|
|
5776
|
+
}
|
|
5777
|
+
}
|
|
5778
|
+
const access = kitAccess(ctx, linkedTo);
|
|
5575
5779
|
if (isResult2(access)) return access;
|
|
5576
|
-
const root = ctx.token !== null ? resolveProjectFolder(ctx.cwd, ctx.projectFolders === null ? null : { folders: ctx.projectFolders }) : ctx.account.workFolder;
|
|
5577
|
-
if (root === null) return errorResult(NOT_SURE_WHICH_FOLDER);
|
|
5578
5780
|
const questions = {
|
|
5579
5781
|
pickComponents: async (all) => all,
|
|
5580
5782
|
confirmReplace: async (paths) => {
|
|
@@ -5593,6 +5795,7 @@ async function addUiKit(args, ctx) {
|
|
|
5593
5795
|
components: components ?? [],
|
|
5594
5796
|
skipInstall: false,
|
|
5595
5797
|
blocks: noBlocks !== true,
|
|
5798
|
+
addBlocks: addBlocks === true,
|
|
5596
5799
|
...screens.value !== void 0 ? { screens: screens.value } : {},
|
|
5597
5800
|
...screens.site ? { site: true } : {},
|
|
5598
5801
|
// As a bare CLI rerun: a call naming neither components nor screens refreshes the screens an earlier run wrote.
|
|
@@ -5603,6 +5806,7 @@ async function addUiKit(args, ctx) {
|
|
|
5603
5806
|
const written = result.added.filter((n) => n !== "preview-portal");
|
|
5604
5807
|
return textResult(
|
|
5605
5808
|
[
|
|
5809
|
+
...usedLine,
|
|
5606
5810
|
...progress,
|
|
5607
5811
|
...summaryLines(result, "agent"),
|
|
5608
5812
|
...written.length > 0 ? [`Added: ${written.join(", ")}`] : [],
|
|
@@ -5751,14 +5955,16 @@ ${files.join("\n\n")}`);
|
|
|
5751
5955
|
},
|
|
5752
5956
|
{
|
|
5753
5957
|
name: "add_ui_kit",
|
|
5754
|
-
description: `Add this design system's UI kit to the React app in the current folder: the theme, the components and their libraries. Sets up Tailwind and shadcn when the app lacks them. A full run (no components and no screens named) also writes the /design-system section, every component, block and sample page in the project's theme, with its blocks unless no_blocks is true, and refreshes the screens an earlier run wrote. screens (names from list_screens, or ["all"]) writes those app screens and marketing pages with the parts and components they import; you mount each on a route. Add "site" to screens to write the site menu (header and footer) that pages mount inside, at least one page being pulled with it. Changes files in the project, so your client will ask the user first. Never overwrites components or screens the user edited.`,
|
|
5958
|
+
description: `Add this design system's UI kit to the React app in the current folder: the theme, the components and their libraries. Sets up Tailwind and shadcn when the app lacks them. A full run (no components and no screens named) also writes the /design-system section, every component, block and sample page in the project's theme, with its blocks unless no_blocks is true (blocks: true adds them to a section written without), and refreshes the screens an earlier run wrote. screens (names from list_screens, or ["all"]) writes those app screens and marketing pages with the parts and components they import; you mount each on a route. Add "site" to screens to write the site menu (header and footer) that pages mount inside, at least one page being pulled with it. When the app is not in the current folder (a monorepo, or a workspace holding the app as a repository of its own), pass folder; a repository of its own works once the user has run npx designsource login in it, and its linked design system is used. Changes files in the project, so your client will ask the user first. Never overwrites components or screens the user edited.`,
|
|
5755
5959
|
inputSchema: {
|
|
5756
5960
|
type: "object",
|
|
5757
5961
|
properties: {
|
|
5758
5962
|
components: { type: "array", items: { type: "string" }, description: "Component names such as button or dialog. Omit to add everything (or refresh what was added before)." },
|
|
5759
5963
|
replace_existing: { type: "boolean", description: "Replace component files that exist but were not added by designsource. Ask the user first." },
|
|
5760
5964
|
no_blocks: { type: "boolean", description: "Add the /design-system section without its blocks and their libraries. Blocks an earlier run wrote are left in place." },
|
|
5761
|
-
|
|
5965
|
+
blocks: { type: "boolean", description: "Add the blocks and their libraries to a /design-system section that was written without them. Not with no_blocks." },
|
|
5966
|
+
screens: { type: "array", items: { type: "string" }, description: `Screen names from list_screens, or ["all"] for every screen; "site" adds the site menu for marketing pages. Each is written under the components folder's screens/ with the parts and kit components it imports.` },
|
|
5967
|
+
folder: { type: "string", description: "The app's folder when it is not the current one: a path inside this project (a monorepo's apps/web), or a repository of its own the user ran npx designsource login in. Omit for the current folder." }
|
|
5762
5968
|
},
|
|
5763
5969
|
additionalProperties: false
|
|
5764
5970
|
},
|
|
@@ -5936,12 +6142,20 @@ function toolAccountFor(session, accounts, onLink, onGone = () => {
|
|
|
5936
6142
|
account.projectId = projectId;
|
|
5937
6143
|
onLink();
|
|
5938
6144
|
return true;
|
|
6145
|
+
},
|
|
6146
|
+
trustOf(roots) {
|
|
6147
|
+
const entry = accounts.get(session.origin);
|
|
6148
|
+
return entry ? trustedFolderOf(entry, roots) : null;
|
|
6149
|
+
},
|
|
6150
|
+
trustedFolders() {
|
|
6151
|
+
return accounts.get(session.origin)?.folders ?? [];
|
|
5939
6152
|
}
|
|
5940
6153
|
};
|
|
5941
6154
|
return account;
|
|
5942
6155
|
}
|
|
5943
6156
|
async function runMcp(args, io, streams = { input: process.stdin, output: process.stdout }, deps = {}) {
|
|
5944
6157
|
const cwd = deps.cwd ?? process.cwd();
|
|
6158
|
+
const home = deps.home ?? homedir6();
|
|
5945
6159
|
const store = deps.store ?? defaultStore();
|
|
5946
6160
|
const warn = (line) => io.stderr(`${line}
|
|
5947
6161
|
`);
|
|
@@ -5953,17 +6167,17 @@ async function runMcp(args, io, streams = { input: process.stdin, output: proces
|
|
|
5953
6167
|
else if (found.entry === null && args.project) found = { ...found, entry: store.entry(args.project) };
|
|
5954
6168
|
if (found) {
|
|
5955
6169
|
const api = fromStore ? apiFor(args, found.entry) : givenTokenApi(args, found.entry);
|
|
5956
|
-
return { token: found.token, projectFolders: args.project ? found.entry?.folders ?? [] : null, api, cwd, account: null, fetchImpl: io.fetchImpl, exec: spawnExec };
|
|
6170
|
+
return { token: found.token, projectFolders: args.project ? found.entry?.folders ?? [] : null, api, cwd, account: null, fetchImpl: io.fetchImpl, exec: spawnExec, home };
|
|
5957
6171
|
}
|
|
5958
6172
|
const missingToken = args.project ? NO_TOKEN_FOR_PROJECT(store.entry(args.project)?.name ?? args.project) : MCP_TOKEN_REQUIRED;
|
|
5959
|
-
return { token: null, missingToken, projectFolders: args.project ? [] : null, api: args.api, cwd, account: null, fetchImpl: io.fetchImpl, exec: spawnExec };
|
|
6173
|
+
return { token: null, missingToken, projectFolders: args.project ? [] : null, api: args.api, cwd, account: null, fetchImpl: io.fetchImpl, exec: spawnExec, home };
|
|
5960
6174
|
};
|
|
5961
6175
|
let accounts = null;
|
|
5962
6176
|
let account = null;
|
|
5963
6177
|
const accountSession = async () => {
|
|
5964
6178
|
if (!account) {
|
|
5965
|
-
accounts ??= (deps.accounts ?? (() => createAccountStore({ env: process.env, platform: process.platform, exec: spawnExec, home:
|
|
5966
|
-
const resolved = await resolveAccount({ api: args.api, apiGiven: args.apiGiven === true, cwd, home
|
|
6179
|
+
accounts ??= (deps.accounts ?? (() => createAccountStore({ env: process.env, platform: process.platform, exec: spawnExec, home: homedir6() })))();
|
|
6180
|
+
const resolved = await resolveAccount({ api: args.api, apiGiven: args.apiGiven === true, cwd, home, accounts });
|
|
5967
6181
|
if (resolved.kind === "none") {
|
|
5968
6182
|
return {
|
|
5969
6183
|
token: null,
|
|
@@ -5975,7 +6189,8 @@ async function runMcp(args, io, streams = { input: process.stdin, output: proces
|
|
|
5975
6189
|
cwd,
|
|
5976
6190
|
account: null,
|
|
5977
6191
|
fetchImpl: io.fetchImpl,
|
|
5978
|
-
exec: spawnExec
|
|
6192
|
+
exec: spawnExec,
|
|
6193
|
+
home
|
|
5979
6194
|
};
|
|
5980
6195
|
}
|
|
5981
6196
|
const made = toolAccountFor(resolved, accounts, () => cache.clear(), () => {
|
|
@@ -5994,7 +6209,7 @@ async function runMcp(args, io, streams = { input: process.stdin, output: proces
|
|
|
5994
6209
|
}
|
|
5995
6210
|
return res;
|
|
5996
6211
|
});
|
|
5997
|
-
return { token: null, projectFolders: null, api: current.api, cwd, account: current, fetchImpl, exec: spawnExec, dropSnapshot: () => cache.clear() };
|
|
6212
|
+
return { token: null, projectFolders: null, api: current.api, cwd, account: current, fetchImpl, exec: spawnExec, home, dropSnapshot: () => cache.clear() };
|
|
5998
6213
|
};
|
|
5999
6214
|
const session = () => projectPath ? projectSession() : accountSession();
|
|
6000
6215
|
const cache = createSnapshotCache(async () => {
|