designsource 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +112 -51
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5217,7 +5217,7 @@ async function runLogout(args, io, deps = defaultLoginDeps(process.env)) {
5217
5217
  import { homedir as homedir6 } from "node:os";
5218
5218
 
5219
5219
  // src/version.ts
5220
- var VERSION = true ? "0.15.0" : "0.0.0-dev";
5220
+ var VERSION = true ? "0.15.1" : "0.0.0-dev";
5221
5221
 
5222
5222
  // src/mcp/jsonrpc.ts
5223
5223
  import { StringDecoder } from "node:string_decoder";
@@ -6377,11 +6377,15 @@ var WAIT_TIMEOUT = "Still waiting? Run npx designsource again once your design s
6377
6377
  var NO_APPS_HERE = "No coding apps found on this computer. Run npx designsource login --apps claude (or cursor, vscode, codex, gemini) to set one up.";
6378
6378
  var BLOCKS_HINT = "Want the ready-made blocks too? Run npx designsource add --blocks";
6379
6379
  var USING = (name) => `Using \u201C${name}\u201D.`;
6380
- var AFTER_UPGRADE = "After upgrading, run npx designsource again.";
6381
- var FREE_PLAN_LINES = (origin, what) => [
6382
- `Your account is on the free plan, so ${what === "kit" ? "the kit was not added to this app" : what === "files" ? "the design system files were not added" : "the app was not created"}.`,
6383
- `Exports need Pro: ${origin}/pricing`,
6384
- AFTER_UPGRADE
6380
+ var upgradeUrl = (origin) => `${origin}/credits?upgrade=pro`;
6381
+ var FREE_PLAN_HEADING = (what) => `Free plan: ${what === "kit" ? "the kit was not added to this app" : what === "files" ? "the design system files were not added" : "the app was not created"}.`;
6382
+ var FREE_PLAN_LINES = (origin, what, color = false) => [
6383
+ "",
6384
+ ` ${color ? `\x1B[1;33m${FREE_PLAN_HEADING(what)}\x1B[0m` : FREE_PLAN_HEADING(what)}`,
6385
+ "",
6386
+ ` Upgrade ${upgradeUrl(origin)}`,
6387
+ " Then run npx designsource",
6388
+ ""
6385
6389
  ];
6386
6390
  var SET_UP_STATUS = (name, components, section, screens) => `\u201C${name}\u201D is set up here (${[
6387
6391
  `${components} component${components === 1 ? "" : "s"}`,
@@ -6397,7 +6401,7 @@ var PICKER_MAX = 20;
6397
6401
  var TERMINAL2 = { pick: (q, o, d) => pick(q, o, d ?? 0), pickMany };
6398
6402
  function defaultSetupDeps(env, menu) {
6399
6403
  const { prompts: _loginPrompts, ...login } = defaultLoginDeps(env);
6400
- return { ...login, store: defaultStore(env), exec: spawnExec, menu };
6404
+ return { ...login, store: defaultStore(env), exec: spawnExec, menu, color: process.stdout.isTTY === true && !env.NO_COLOR };
6401
6405
  }
6402
6406
  var PROJECT_ID5 = /^[A-Za-z0-9_-]{1,64}$/;
6403
6407
  async function listProjects2(api, token, fetchImpl) {
@@ -6489,8 +6493,14 @@ async function runSetup(args, io, deps) {
6489
6493
  planStopped = true;
6490
6494
  kitLines.push(...lines);
6491
6495
  };
6492
- const pushKit = (r) => r.planStopped ? freeLines(...r.lines) : kitLines.push(...r.lines);
6496
+ const pushKit = (r) => {
6497
+ if (r.planStopped) freeLines(...r.lines);
6498
+ else kitLines.push(...r.lines);
6499
+ };
6493
6500
  const exports = access.kind === "account" ? await exportsAllowed(access.api, access.token, io.fetchImpl) : null;
6501
+ const color = deps.color === true;
6502
+ let kitStep = null;
6503
+ let stop = "kit";
6494
6504
  if (state.kind === "react-set-up") {
6495
6505
  say([SET_UP_STATUS(name, state.components, state.section, state.screens)]);
6496
6506
  const options = [
@@ -6507,25 +6517,29 @@ async function runSetup(args, io, deps) {
6507
6517
  name = chosen.name;
6508
6518
  projectId = chosen.id;
6509
6519
  }
6510
- say([USING(name)]);
6511
- if (exports === false) freeLines(...FREE_PLAN_LINES(access.api, "kit"));
6512
- else pushKit(await addKit(state, access, kitPath(), false, deps, io));
6513
- } else {
6514
- say([USING(name)]);
6515
- if (state.kind === "react-fresh") {
6516
- if (state.cannotAdd === null) {
6517
- if (exports === false) freeLines(...FREE_PLAN_LINES(access.api, "kit"));
6518
- else pushKit(await addKit(state, access, kitPath(), true, deps, io));
6519
- }
6520
- } else if (state.kind === "other-stack") {
6521
- if (exports === false) freeLines(...FREE_PLAN_LINES(access.api, "files"));
6522
- else await (deps.runIntegrate ?? runIntegrate)({ folder: ".", framework: state.framework, api: args.api, apiGiven: args.apiGiven, force: false }, process.env, io, deps.store, deps.accounts);
6523
- } else if (state.kind === "empty") {
6524
- if (exports === false) freeLines(...FREE_PLAN_LINES(access.api, "app"));
6525
- else await (deps.runCreate ?? runCreate)({ folder: ".", api: args.api, apiGiven: args.apiGiven, force: state.onlyGit }, process.env, io, deps.store, deps.accounts);
6526
- writeAgents();
6527
- }
6520
+ kitStep = async () => pushKit(await addKit(state, access, kitPath(), false, deps, io));
6521
+ } else if (state.kind === "react-fresh") {
6522
+ if (state.cannotAdd === null) kitStep = async () => pushKit(await addKit(state, access, kitPath(), true, deps, io));
6523
+ } else if (state.kind === "other-stack") {
6524
+ stop = "files";
6525
+ kitStep = async () => {
6526
+ await (deps.runIntegrate ?? runIntegrate)({ folder: ".", framework: state.framework, api: args.api, apiGiven: args.apiGiven, force: false }, process.env, io, deps.store, deps.accounts);
6527
+ };
6528
+ } else if (state.kind === "empty") {
6529
+ stop = "app";
6530
+ kitStep = async () => {
6531
+ await (deps.runCreate ?? runCreate)({ folder: ".", api: args.api, apiGiven: args.apiGiven, force: state.onlyGit }, process.env, io, deps.store, deps.accounts);
6532
+ };
6528
6533
  }
6534
+ say([USING(name)]);
6535
+ if (kitStep) {
6536
+ if (exports === false && access.kind === "account") {
6537
+ say(FREE_PLAN_LINES(access.api, stop, color));
6538
+ if (await upgradeAndWait(access, deps, prompts, io, say)) await kitStep();
6539
+ else planStopped = true;
6540
+ } else await kitStep();
6541
+ }
6542
+ if (state.kind === "empty") writeAgents();
6529
6543
  const noKit = planStopped || state.kind === "react-fresh" && state.cannotAdd !== null;
6530
6544
  const sentence = noKit ? null : state.kind === "other-stack" ? APPLY_SENTENCE : state.kind === "empty" ? null : RESTYLE_SENTENCE;
6531
6545
  say([...kitLines, ...agentLines(), ...sentence ? NEXT_STEP(sentence) : []]);
@@ -6533,21 +6547,64 @@ async function runSetup(args, io, deps) {
6533
6547
  const done = agent;
6534
6548
  return [
6535
6549
  ...apps.length === 0 ? [NO_APPS_HERE] : [],
6536
- ...done ? [...done.plans.flatMap(({ id, plan }) => appLines(id, plan)), ...done.kept, ...agentClosing(apps, done.changed)] : []
6550
+ ...done ? agentSummary(done) : []
6537
6551
  ];
6538
6552
  }
6539
6553
  }
6540
6554
  var labelOf2 = (id) => APPS.find((a) => a.id === id).label;
6541
6555
  var listOf2 = (words) => words.length <= 1 ? words.join("") : `${words.slice(0, -1).join(", ")} and ${words.at(-1)}`;
6542
- function agentClosing(apps, changed) {
6556
+ var APPS_SET_UP = (labels) => `Coding apps: ${listOf2(labels)} ${labels.length === 1 ? "is" : "are"} set up.`;
6557
+ var APPS_WRITTEN = (apps) => `Set up ${listOf2(apps.map((a) => `${a.label} (${a.path})`))}.`;
6558
+ var ALREADY_SET_UP = (labels) => `${listOf2(labels)} ${labels.length === 1 ? "was" : "were"} already set up.`;
6559
+ var COMMIT_THESE = "Commit these files: they hold no token.";
6560
+ function agentSummary(done) {
6561
+ const written = done.plans.filter(({ plan }) => plan.status === "create" || plan.status === "update");
6562
+ const unchanged = done.plans.filter(({ plan }) => plan.status === "unchanged" && !plan.keepsProject);
6563
+ const manual = done.plans.filter(({ plan }) => plan.status === "manual");
6564
+ const envWarnings = unchanged.flatMap(({ id, plan }) => appLines(id, plan).slice(1));
6565
+ if (written.length === 0) {
6566
+ return [
6567
+ ...unchanged.length > 0 ? [APPS_SET_UP(unchanged.map(({ id }) => labelOf2(id)))] : [],
6568
+ ...envWarnings,
6569
+ ...manual.flatMap(({ id, plan }) => appLines(id, plan)),
6570
+ ...done.kept
6571
+ ];
6572
+ }
6573
+ const ids = written.map(({ id }) => id);
6574
+ const notes = [
6575
+ ...ids.includes("claude") ? ["Claude Code asks once to allow it"] : [],
6576
+ ...ids.includes("codex") ? ["Codex needs this project trusted"] : [],
6577
+ ...ids.includes("gemini") ? ["Gemini CLI needs this folder trusted if folder trust is on"] : []
6578
+ ];
6543
6579
  return [
6544
- ...changed.length > 0 ? [`Restart ${listOf2(changed.map(labelOf2))} so ${changed.length === 1 ? "it loads" : "they load"} designsource.`] : [],
6545
- ...apps.includes("claude") ? ["Claude Code asks once to allow the server."] : [],
6546
- ...apps.includes("codex") ? [CODEX_TRUST_NOTE] : [],
6547
- ...apps.includes("gemini") ? [GEMINI_TRUST_NOTE] : [],
6548
- COMMIT_SETTINGS_NOTE
6580
+ APPS_WRITTEN(written.map(({ id, plan }) => ({ label: labelOf2(id), path: plan.path }))),
6581
+ ...unchanged.length > 0 ? [ALREADY_SET_UP(unchanged.map(({ id }) => labelOf2(id)))] : [],
6582
+ ...envWarnings,
6583
+ ...manual.flatMap(({ id, plan }) => appLines(id, plan)),
6584
+ ...done.kept,
6585
+ `Restart ${written.length === 1 ? "it" : "them"} to load designsource.${notes.length > 0 ? ` ${notes.join("; ")}.` : ""}`,
6586
+ COMMIT_THESE
6549
6587
  ];
6550
6588
  }
6589
+ var UPGRADE_QUESTION = "Upgrade to Pro now?";
6590
+ var UPGRADE_WAIT = "Subscribe in the browser. This continues when Pro is on. (Ctrl+C to stop)";
6591
+ var PRO_ON = "Pro is on.";
6592
+ var UPGRADE_TIMEOUT = "Still on the free plan. After upgrading, run npx designsource again.";
6593
+ async function upgradeAndWait(access, deps, prompts, io, say) {
6594
+ const choice = await prompts.pick(UPGRADE_QUESTION, [
6595
+ { value: "upgrade", label: "Upgrade to Pro now (opens the browser)" },
6596
+ { value: "later", label: "Not now" }
6597
+ ]);
6598
+ if (choice !== "upgrade") return false;
6599
+ const on = await openAndPoll(upgradeUrl(access.api), UPGRADE_WAIT, UPGRADE_TIMEOUT, deps, say, async () => {
6600
+ const res = await requestJson({ api: access.api, path: "/api/agent/token", method: "GET", token: access.token }, io.fetchImpl).catch(() => null);
6601
+ if (res?.status === 401) throw new CliError(ACCOUNT_TOKEN_MESSAGE);
6602
+ const exports = res?.status === 200 && typeof res.body === "object" && res.body !== null ? res.body.exports : void 0;
6603
+ return exports === true ? true : void 0;
6604
+ });
6605
+ if (on) say([PRO_ON]);
6606
+ return on === true;
6607
+ }
6551
6608
  async function chooseDesignSystem(access, deps, prompts, io, say) {
6552
6609
  const { projects } = access;
6553
6610
  if (projects.length === 0) return makeNew(access, deps, prompts, io, say);
@@ -6562,31 +6619,35 @@ async function chooseDesignSystem(access, deps, prompts, io, say) {
6562
6619
  return projects.find((p) => `p:${p.id}` === choice) ?? null;
6563
6620
  }
6564
6621
  async function makeNew(access, deps, prompts, io, say) {
6565
- const url = `${access.api}/projects`;
6566
- await (deps.open ?? ((u) => openBrowser(u, deps.platform)))(url);
6567
- say([`Opening ${url}`, MAKE_NEW_WAIT]);
6568
6622
  const known = new Set(access.projects.map((p) => p.id));
6569
- const now = deps.now ?? Date.now;
6570
- const sleep = deps.sleep ?? ((ms) => new Promise((resolve10) => setTimeout(resolve10, ms)));
6571
- const start = now();
6572
- const waitMs = deps.waitMs ?? WAIT_MS;
6573
- while (now() - start < waitMs) {
6574
- await sleep(deps.pollMs ?? POLL_MS);
6623
+ const fresh = await openAndPoll(`${access.api}/projects`, MAKE_NEW_WAIT, WAIT_TIMEOUT, deps, say, async () => {
6575
6624
  let list;
6576
6625
  try {
6577
6626
  list = await listProjects2(access.api, access.token, io.fetchImpl);
6578
6627
  } catch (e) {
6579
6628
  if (e instanceof CliError && e.message === ACCOUNT_TOKEN_MESSAGE) throw e;
6580
- continue;
6581
- }
6582
- const fresh = list.filter((p) => !known.has(p.id));
6583
- if (fresh.length === 1) return fresh[0];
6584
- if (fresh.length > 1) {
6585
- const choice = await prompts.pick("Which new design system?", fresh.map((p) => ({ value: `p:${p.id}`, label: p.name })));
6586
- return fresh.find((p) => `p:${p.id}` === choice) ?? null;
6629
+ return void 0;
6587
6630
  }
6631
+ const added = list.filter((p) => !known.has(p.id));
6632
+ return added.length > 0 ? added : void 0;
6633
+ });
6634
+ if (fresh === null) return null;
6635
+ if (fresh.length === 1) return fresh[0];
6636
+ const choice = await prompts.pick("Which new design system?", fresh.map((p) => ({ value: `p:${p.id}`, label: p.name })));
6637
+ return fresh.find((p) => `p:${p.id}` === choice) ?? null;
6638
+ }
6639
+ async function openAndPoll(url, waiting2, timedOut, deps, say, check) {
6640
+ await (deps.open ?? ((u) => openBrowser(u, deps.platform)))(url);
6641
+ say([`Opening ${url}`, waiting2]);
6642
+ const now = deps.now ?? Date.now;
6643
+ const sleep = deps.sleep ?? ((ms) => new Promise((resolve10) => setTimeout(resolve10, ms)));
6644
+ const start = now();
6645
+ while (now() - start < (deps.waitMs ?? WAIT_MS)) {
6646
+ await sleep(deps.pollMs ?? POLL_MS);
6647
+ const found = await check();
6648
+ if (found !== void 0) return found;
6588
6649
  }
6589
- say([WAIT_TIMEOUT]);
6650
+ say([timedOut]);
6590
6651
  return null;
6591
6652
  }
6592
6653
  async function addKit(state, access, kitPath, fresh, deps, io) {
@@ -6610,7 +6671,7 @@ async function addKit(state, access, kitPath, fresh, deps, io) {
6610
6671
  `) }
6611
6672
  );
6612
6673
  } catch (e) {
6613
- if (e instanceof CliError && e.message === PLAN_MESSAGE) return { lines: FREE_PLAN_LINES(access.api, "kit"), planStopped: true };
6674
+ if (e instanceof CliError && e.message === PLAN_MESSAGE) return { lines: FREE_PLAN_LINES(access.api, "kit", deps.color === true), planStopped: true };
6614
6675
  throw e;
6615
6676
  }
6616
6677
  const hint = result.section && result.section.blocks === 0 && !result.section.blocksLeftInPlace ? [BLOCKS_HINT] : [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "designsource",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
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": {