designsource 0.13.0 → 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 +476 -411
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -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) {
|
|
@@ -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((resolve10, reject) => waiting.push({
|
|
3846
|
-
resolve: (line2) => {
|
|
3847
|
-
process.stdin.unref?.();
|
|
3848
|
-
resolve10(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((resolve10, 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
|
-
resolve10(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((resolve10, 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
|
-
resolve10(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";
|
|
@@ -4430,49 +4147,428 @@ function oneLine(text) {
|
|
|
4430
4147
|
const line = lines[0].trim();
|
|
4431
4148
|
return /[\u0000-\u001f\u007f]/.test(line) ? null : line;
|
|
4432
4149
|
}
|
|
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;
|
|
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 }),
|
|
@@ -5062,61 +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 trustedFolderOf(entry, roots) {
|
|
5078
|
-
const trusted = (f) => entry.folders.some((saved) => normaliseFolder(saved) === f);
|
|
5079
|
-
const folder = trusted(roots.work) ? roots.work : trusted(roots.trust) ? roots.trust : null;
|
|
5080
|
-
if (folder === null) return null;
|
|
5081
|
-
const linked = Object.entries(entry.links).find(([f]) => normaliseFolder(f) === folder)?.[1];
|
|
5082
|
-
return { folder, projectId: linked !== void 0 && PROJECT_ID3.test(linked) ? linked : null };
|
|
5083
|
-
}
|
|
5084
|
-
function chooseAccount(api, apiGiven, accounts, notSignedIn) {
|
|
5085
|
-
if (apiGiven) {
|
|
5086
|
-
let origin;
|
|
5087
|
-
try {
|
|
5088
|
-
origin = originOf(api);
|
|
5089
|
-
} catch {
|
|
5090
|
-
return refuse(notSignedIn);
|
|
5091
|
-
}
|
|
5092
|
-
return accounts.get(origin) ?? refuse(notSignedIn);
|
|
5093
|
-
}
|
|
5094
|
-
const all = accounts.all();
|
|
5095
|
-
if (all.length === 1) return all[0];
|
|
5096
|
-
const fallback = accounts.get(DEFAULT_API_ORIGIN);
|
|
5097
|
-
if (fallback) return fallback;
|
|
5098
|
-
return refuse(all.length > 1 ? SEVERAL_ACCOUNTS : notSignedIn);
|
|
5099
|
-
}
|
|
5100
|
-
async function resolveAccount(input) {
|
|
5101
|
-
const { api, apiGiven, cwd, home, accounts } = input;
|
|
5102
|
-
const { work, trust } = projectFolders(cwd);
|
|
5103
|
-
const notSignedIn = NOT_SIGNED_IN_FOR(trust);
|
|
5104
|
-
const chosen = chooseAccount(api, apiGiven, accounts, notSignedIn);
|
|
5105
|
-
if ("kind" in chosen) return chosen;
|
|
5106
|
-
const homeDir = normaliseFolder(home);
|
|
5107
|
-
if (homeFolderRefusal(trust, homeDir) !== null || homeFolderRefusal(work, homeDir) !== null) return refuse(notSignedIn);
|
|
5108
|
-
const found = trustedFolderOf(chosen, { work, trust });
|
|
5109
|
-
if (found === null) return refuse(notSignedIn);
|
|
5110
|
-
const { folder, projectId } = found;
|
|
5111
|
-
let token;
|
|
5112
|
-
try {
|
|
5113
|
-
token = await accounts.token(chosen.origin);
|
|
5114
|
-
} catch {
|
|
5115
|
-
return refuse(notSignedIn);
|
|
5116
|
-
}
|
|
5117
|
-
if (token === null || !ACCOUNT_TOKEN3.test(token)) return refuse(notSignedIn);
|
|
5118
|
-
return { kind: "account", origin: chosen.origin, email: chosen.email, token, folder, workFolder: work, projectId };
|
|
5119
|
-
}
|
|
5179
|
+
var VERSION = true ? "0.14.0" : "0.0.0-dev";
|
|
5120
5180
|
|
|
5121
5181
|
// src/mcp/jsonrpc.ts
|
|
5122
5182
|
import { StringDecoder } from "node:string_decoder";
|
|
@@ -5190,7 +5250,7 @@ function getPrompt(name) {
|
|
|
5190
5250
|
|
|
5191
5251
|
// src/mcp/tools.ts
|
|
5192
5252
|
import { existsSync as existsSync14 } from "node:fs";
|
|
5193
|
-
import { homedir as
|
|
5253
|
+
import { homedir as homedir5 } from "node:os";
|
|
5194
5254
|
import { join as join15 } from "node:path";
|
|
5195
5255
|
|
|
5196
5256
|
// src/mcp/account-tools.ts
|
|
@@ -5573,7 +5633,7 @@ function appCandidates(base, near, src, trusted = []) {
|
|
|
5573
5633
|
}
|
|
5574
5634
|
|
|
5575
5635
|
// src/mcp/tools.ts
|
|
5576
|
-
var accountProjectPath = (projectId, kind) =>
|
|
5636
|
+
var accountProjectPath = (projectId, kind) => accountProjectRoute(projectId, kind);
|
|
5577
5637
|
var READ_ONLY = { readOnlyHint: true };
|
|
5578
5638
|
var TIERS = ["design", "semantic", "component"];
|
|
5579
5639
|
var CATEGORIES = ["color", "spacing", "radius", "typography", "shadow", "zIndex", "border", "gradient"];
|
|
@@ -5673,18 +5733,21 @@ function screensArg(v) {
|
|
|
5673
5733
|
function targetSources(ctx, base) {
|
|
5674
5734
|
return {
|
|
5675
5735
|
base,
|
|
5676
|
-
home: ctx.home ??
|
|
5736
|
+
home: ctx.home ?? homedir5(),
|
|
5677
5737
|
...ctx.token === null && ctx.account ? { accountTrust: (roots) => ctx.account.trustOf?.(roots) ?? null } : {},
|
|
5678
5738
|
...ctx.token !== null ? { savedFolders: ctx.projectFolders } : {}
|
|
5679
5739
|
};
|
|
5680
5740
|
}
|
|
5741
|
+
var BLOCKS_BOTH_FOR_AGENT = '"blocks" and "no_blocks" cannot both be true.';
|
|
5681
5742
|
async function addUiKit(args, ctx) {
|
|
5682
|
-
const { components, replace_existing: replace, no_blocks: noBlocks } = args;
|
|
5743
|
+
const { components, replace_existing: replace, no_blocks: noBlocks, blocks: addBlocks } = args;
|
|
5683
5744
|
if (components !== void 0 && !(Array.isArray(components) && components.every((c) => typeof c === "string"))) {
|
|
5684
5745
|
return errorResult('"components" must be an array of component names.');
|
|
5685
5746
|
}
|
|
5686
5747
|
if (replace !== void 0 && typeof replace !== "boolean") return errorResult('"replace_existing" must be true or false.');
|
|
5687
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);
|
|
5688
5751
|
const screens = screensArg(args.screens);
|
|
5689
5752
|
if (!screens.ok) return errorResult(SCREENS_ARG);
|
|
5690
5753
|
if (ctx.token === null && !ctx.account) return errorResult(ctx.missingToken ?? MCP_TOKEN_REQUIRED);
|
|
@@ -5732,6 +5795,7 @@ async function addUiKit(args, ctx) {
|
|
|
5732
5795
|
components: components ?? [],
|
|
5733
5796
|
skipInstall: false,
|
|
5734
5797
|
blocks: noBlocks !== true,
|
|
5798
|
+
addBlocks: addBlocks === true,
|
|
5735
5799
|
...screens.value !== void 0 ? { screens: screens.value } : {},
|
|
5736
5800
|
...screens.site ? { site: true } : {},
|
|
5737
5801
|
// As a bare CLI rerun: a call naming neither components nor screens refreshes the screens an earlier run wrote.
|
|
@@ -5891,13 +5955,14 @@ ${files.join("\n\n")}`);
|
|
|
5891
5955
|
},
|
|
5892
5956
|
{
|
|
5893
5957
|
name: "add_ui_kit",
|
|
5894
|
-
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. 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.`,
|
|
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.`,
|
|
5895
5959
|
inputSchema: {
|
|
5896
5960
|
type: "object",
|
|
5897
5961
|
properties: {
|
|
5898
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)." },
|
|
5899
5963
|
replace_existing: { type: "boolean", description: "Replace component files that exist but were not added by designsource. Ask the user first." },
|
|
5900
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." },
|
|
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." },
|
|
5901
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.` },
|
|
5902
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." }
|
|
5903
5968
|
},
|
|
@@ -6090,7 +6155,7 @@ function toolAccountFor(session, accounts, onLink, onGone = () => {
|
|
|
6090
6155
|
}
|
|
6091
6156
|
async function runMcp(args, io, streams = { input: process.stdin, output: process.stdout }, deps = {}) {
|
|
6092
6157
|
const cwd = deps.cwd ?? process.cwd();
|
|
6093
|
-
const home = deps.home ??
|
|
6158
|
+
const home = deps.home ?? homedir6();
|
|
6094
6159
|
const store = deps.store ?? defaultStore();
|
|
6095
6160
|
const warn = (line) => io.stderr(`${line}
|
|
6096
6161
|
`);
|
|
@@ -6111,7 +6176,7 @@ async function runMcp(args, io, streams = { input: process.stdin, output: proces
|
|
|
6111
6176
|
let account = null;
|
|
6112
6177
|
const accountSession = async () => {
|
|
6113
6178
|
if (!account) {
|
|
6114
|
-
accounts ??= (deps.accounts ?? (() => createAccountStore({ env: process.env, platform: process.platform, exec: spawnExec, home:
|
|
6179
|
+
accounts ??= (deps.accounts ?? (() => createAccountStore({ env: process.env, platform: process.platform, exec: spawnExec, home: homedir6() })))();
|
|
6115
6180
|
const resolved = await resolveAccount({ api: args.api, apiGiven: args.apiGiven === true, cwd, home, accounts });
|
|
6116
6181
|
if (resolved.kind === "none") {
|
|
6117
6182
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "designsource",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "The DS source CLI: add your design system's UI kit to a React app (add), add the design system to any other app (integrate), start a new Next.js project from it (create), or serve it to a coding agent over MCP (mcp) — tokens, every component and your mockup page.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|