designsource 0.4.0 → 0.4.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.
- package/README.md +1 -1
- package/dist/index.js +35 -16
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -179,7 +179,7 @@ By the maintainer, through GitHub Actions with npm trusted publishing: no npm to
|
|
|
179
179
|
3. Tag the merge commit `designsource@<version>` and push the tag:
|
|
180
180
|
|
|
181
181
|
```sh
|
|
182
|
-
git tag designsource@0.4.
|
|
182
|
+
git tag designsource@0.4.1 && git push origin designsource@0.4.1
|
|
183
183
|
```
|
|
184
184
|
|
|
185
185
|
The workflow (`.github/workflows/release-designsource.yml`) refuses a tag that does not match `package.json`, runs the tests (which build `dist/` first), publishes, then installs the published version from npm and runs `--help` against it.
|
package/dist/index.js
CHANGED
|
@@ -52,6 +52,7 @@ var ArgsError = class extends Error {
|
|
|
52
52
|
super(message);
|
|
53
53
|
this.usage = usage;
|
|
54
54
|
}
|
|
55
|
+
usage;
|
|
55
56
|
};
|
|
56
57
|
function baseArgs(env) {
|
|
57
58
|
const args = { api: DEFAULT_API_ORIGIN, force: false };
|
|
@@ -133,6 +134,7 @@ function parseVerb(verb, argv, env) {
|
|
|
133
134
|
}
|
|
134
135
|
if (verb === "create") {
|
|
135
136
|
const { framework: _drop, ...common } = args;
|
|
137
|
+
void _drop;
|
|
136
138
|
return { kind: "create", args: common };
|
|
137
139
|
}
|
|
138
140
|
return { kind: "integrate", args };
|
|
@@ -144,6 +146,7 @@ var CliError = class extends Error {
|
|
|
144
146
|
super(message);
|
|
145
147
|
this.exitCode = exitCode;
|
|
146
148
|
}
|
|
149
|
+
exitCode;
|
|
147
150
|
};
|
|
148
151
|
var CANCELLED = "Cancelled.";
|
|
149
152
|
var TOKEN_MESSAGE = "Project token not recognised. In the workbench open Project settings and copy the project token.";
|
|
@@ -323,7 +326,7 @@ function nextStepsText({ runner, framework, folder, created }) {
|
|
|
323
326
|
|
|
324
327
|
// src/write.ts
|
|
325
328
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
326
|
-
import { dirname, resolve as resolve2 } from "node:path";
|
|
329
|
+
import { dirname, relative, resolve as resolve2 } from "node:path";
|
|
327
330
|
|
|
328
331
|
// src/paths.ts
|
|
329
332
|
import { isAbsolute, resolve, sep } from "node:path";
|
|
@@ -349,7 +352,7 @@ function planTarget(cwd, folder, framework, force) {
|
|
|
349
352
|
}
|
|
350
353
|
return { root, created: false };
|
|
351
354
|
}
|
|
352
|
-
function writeFiles(root, files, opts) {
|
|
355
|
+
function writeFiles(root, files, opts, writeFile = writeFileSync) {
|
|
353
356
|
const targets = files.map((f) => ({ file: f, abs: resolveInside(root, f.path) }));
|
|
354
357
|
if (!opts.force) {
|
|
355
358
|
const clash = targets.find((t) => existsSync(t.abs));
|
|
@@ -357,13 +360,15 @@ function writeFiles(root, files, opts) {
|
|
|
357
360
|
}
|
|
358
361
|
const written = [];
|
|
359
362
|
const previous = /* @__PURE__ */ new Map();
|
|
363
|
+
const madeDirs = [];
|
|
360
364
|
let failingPath;
|
|
361
365
|
try {
|
|
362
366
|
for (const { file, abs } of targets) {
|
|
363
367
|
failingPath = file.path;
|
|
364
368
|
if (!previous.has(file.path)) previous.set(file.path, existsSync(abs) ? readFileSync(abs) : void 0);
|
|
369
|
+
madeDirs.push(...missingDirs(root, dirname(abs)));
|
|
365
370
|
mkdirSync(dirname(abs), { recursive: true });
|
|
366
|
-
|
|
371
|
+
writeFile(abs, file.path === "package.json" && opts.packageManager ? withPackageManager(file.contents, opts.packageManager) : file.contents);
|
|
367
372
|
written.push(file.path);
|
|
368
373
|
}
|
|
369
374
|
} catch (e) {
|
|
@@ -374,21 +379,32 @@ function writeFiles(root, files, opts) {
|
|
|
374
379
|
}
|
|
375
380
|
let restored = 0;
|
|
376
381
|
let removed = 0;
|
|
377
|
-
for (const p of
|
|
382
|
+
for (const [p, before] of previous) {
|
|
378
383
|
const abs = resolveInside(root, p);
|
|
379
|
-
const before = previous.get(p);
|
|
380
384
|
if (before === void 0) {
|
|
381
|
-
|
|
382
|
-
|
|
385
|
+
if (existsSync(abs) && statSync(abs).isFile()) {
|
|
386
|
+
rmSync(abs, { force: true });
|
|
387
|
+
removed++;
|
|
388
|
+
}
|
|
383
389
|
} else {
|
|
384
390
|
writeFileSync(abs, before);
|
|
385
391
|
restored++;
|
|
386
392
|
}
|
|
387
393
|
}
|
|
394
|
+
for (const dir of [...madeDirs].reverse()) rmSync(dir, { recursive: true, force: true });
|
|
388
395
|
throw new CliError(`Could not write ${failingPath} (${code2}). Restored ${restored} file(s) and removed ${removed} new file(s); the folder is as it was.`);
|
|
389
396
|
}
|
|
390
397
|
return { written };
|
|
391
398
|
}
|
|
399
|
+
function missingDirs(root, dir) {
|
|
400
|
+
const missing = [];
|
|
401
|
+
let d = dir;
|
|
402
|
+
while (relative(root, d) !== "" && !relative(root, d).startsWith("..") && !existsSync(d)) {
|
|
403
|
+
missing.unshift(d);
|
|
404
|
+
d = dirname(d);
|
|
405
|
+
}
|
|
406
|
+
return missing;
|
|
407
|
+
}
|
|
392
408
|
function withPackageManager(contents, packageManager) {
|
|
393
409
|
const pkg = JSON.parse(contents);
|
|
394
410
|
return `${JSON.stringify({ ...pkg, packageManager }, null, 2)}
|
|
@@ -504,7 +520,7 @@ async function runIntegrate(args, env, io) {
|
|
|
504
520
|
import { createInterface as createInterface2 } from "node:readline";
|
|
505
521
|
|
|
506
522
|
// src/version.ts
|
|
507
|
-
var VERSION = true ? "0.4.
|
|
523
|
+
var VERSION = true ? "0.4.1" : "0.0.0-dev";
|
|
508
524
|
|
|
509
525
|
// src/mcp/jsonrpc.ts
|
|
510
526
|
var PARSE_ERROR = -32700;
|
|
@@ -569,12 +585,14 @@ var NO_INPUT = { type: "object", properties: {}, additionalProperties: false };
|
|
|
569
585
|
var pretty = (v) => JSON.stringify(v, null, 2);
|
|
570
586
|
var NO_BLOCKS = "This server sent no blocks. Update designsource and the server.";
|
|
571
587
|
var SOURCE_HEADER = "// Reference implementation. Use verbatim in React + Tailwind; port to your stack otherwise, keeping every var() chain.";
|
|
572
|
-
var
|
|
588
|
+
var FALLBACK_BLOCK_SOURCE_HEADER = `${SOURCE_HEADER}
|
|
573
589
|
// The block renders inside BlockStage (components/blocks/stage.tsx, below), which supplies the @container/stage its
|
|
574
590
|
// responsive classes query and the frame height its min-h-full fills: render <BlockStage><Block /></BlockStage> as a
|
|
575
591
|
// full-viewport page. components/ui/preview-portal.tsx is the portal context the stage provides; the kit components
|
|
576
592
|
// list_blocks names for this block come from get_component_source.`;
|
|
577
593
|
var UTILS_HEADER = "// The `cn` helper every component imports from `@/lib/utils`. Save as lib/utils.ts in React; port or drop elsewhere.";
|
|
594
|
+
var PORTAL_HEADER = "// The portal context components import from `./preview-portal`. Save it beside them as components/ui/preview-portal.tsx in React: with no provider it portals to document.body, as stock shadcn does. Port or drop elsewhere.";
|
|
595
|
+
var blockAppPath = (key) => key.startsWith("kit/") ? `components/ui/${key.slice("kit/".length)}` : `components/${key}`;
|
|
578
596
|
var componentsIn = (snapshot) => [...new Set(snapshot.canonical.tokens.map((t) => t.component).filter((c) => c !== null))].sort();
|
|
579
597
|
function optionalEnum(args, key, allowed) {
|
|
580
598
|
const v = args[key];
|
|
@@ -641,13 +659,13 @@ var TOOLS = [
|
|
|
641
659
|
},
|
|
642
660
|
{
|
|
643
661
|
name: "get_component_source",
|
|
644
|
-
description: 'The React + Tailwind source of one component (see list_components), or "utils" for the cn helper. Use verbatim in React; port to any other stack keeping every var() chain.',
|
|
645
|
-
inputSchema: { type: "object", properties: { name: { type: "string", description: "A name from list_components, or utils." } }, required: ["name"], additionalProperties: false },
|
|
662
|
+
description: 'The React + Tailwind source of one component (see list_components), or a helper: "utils" for the cn helper, "preview-portal" for the portal context components import. Use verbatim in React; port to any other stack keeping every var() chain.',
|
|
663
|
+
inputSchema: { type: "object", properties: { name: { type: "string", description: "A name from list_components, or a helper (utils, preview-portal)." } }, required: ["name"], additionalProperties: false },
|
|
646
664
|
run: (snapshot, _at, args) => {
|
|
647
665
|
const names = Object.keys(snapshot.kit.sources).sort();
|
|
648
666
|
const name = args.name;
|
|
649
667
|
if (typeof name !== "string" || !names.includes(name)) return errorResult(`"name" must be one of: ${names.join(", ")}.`);
|
|
650
|
-
const header = name in snapshot.kit.variables ? SOURCE_HEADER : UTILS_HEADER;
|
|
668
|
+
const header = name in snapshot.kit.variables ? SOURCE_HEADER : name === "preview-portal" ? PORTAL_HEADER : UTILS_HEADER;
|
|
651
669
|
return textResult(`${header}
|
|
652
670
|
${snapshot.kit.sources[name]}`);
|
|
653
671
|
}
|
|
@@ -686,10 +704,9 @@ ${files.join("\n")}`);
|
|
|
686
704
|
if (!blocks) return errorResult(NO_BLOCKS);
|
|
687
705
|
const entry = blocks.index.find((b) => b.id === args.id);
|
|
688
706
|
if (!entry) return errorResult(`"id" must be one of: ${blocks.index.map((b) => b.id).join(", ")}.`);
|
|
689
|
-
const
|
|
690
|
-
const files = entry.files.map((f) => `--- file: ${path(f)}
|
|
707
|
+
const files = entry.files.map((f) => `--- file: ${blockAppPath(f)}
|
|
691
708
|
${blocks.sources[f] ?? ""}`);
|
|
692
|
-
return textResult(`${
|
|
709
|
+
return textResult(`${blocks.header ?? FALLBACK_BLOCK_SOURCE_HEADER}
|
|
693
710
|
${files.join("\n\n")}`);
|
|
694
711
|
}
|
|
695
712
|
}
|
|
@@ -774,7 +791,9 @@ function validateSnapshot(json) {
|
|
|
774
791
|
if (!isObject(kit) || !isStringRecord(kit.sources) || !isStringListRecord(kit.variables)) throw malformed2();
|
|
775
792
|
if (mockup !== null && !(isObject(mockup) && isObject(mockup.spec) && isStringRecord(mockup.renderer))) throw malformed2();
|
|
776
793
|
const validBlocks = isObject(blocks) && Array.isArray(blocks.index) && blocks.index.every(isBlockEntry) && isStringRecord(blocks.sources);
|
|
777
|
-
|
|
794
|
+
if (!validBlocks) return { ...json, blocks: void 0 };
|
|
795
|
+
if (blocks.header !== void 0 && typeof blocks.header !== "string") return { ...json, blocks: { ...blocks, header: void 0 } };
|
|
796
|
+
return json;
|
|
778
797
|
}
|
|
779
798
|
var FETCH_TIMEOUT_MS = 3e4;
|
|
780
799
|
async function fetchSnapshot(opts, fetchImpl = fetch) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "designsource",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "The DS source CLI: add a design system to an existing 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": {
|
|
@@ -38,12 +38,13 @@
|
|
|
38
38
|
"build": "node esbuild.mjs",
|
|
39
39
|
"prepublishOnly": "node esbuild.mjs",
|
|
40
40
|
"start": "node dist/index.js",
|
|
41
|
-
"test": "node esbuild.mjs && vitest run"
|
|
41
|
+
"test": "node esbuild.mjs && vitest run",
|
|
42
|
+
"typecheck": "tsc --noEmit"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@types/node": "^26",
|
|
45
|
-
"esbuild": "^0.
|
|
45
|
+
"@types/node": "^26.6.5",
|
|
46
|
+
"esbuild": "^0.28.2",
|
|
46
47
|
"typescript": "~6.0.3",
|
|
47
|
-
"vitest": "^
|
|
48
|
+
"vitest": "^5.0.5"
|
|
48
49
|
}
|
|
49
50
|
}
|