storybook-addon-dependency-previews 0.1.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/README.md +192 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/addon/index.cjs +12 -0
- package/dist/addon/index.cjs.map +1 -0
- package/dist/addon/index.d.cts +5 -0
- package/dist/addon/index.d.mts +5 -0
- package/dist/addon/index.mjs +11 -0
- package/dist/addon/index.mjs.map +1 -0
- package/dist/addon/preset.cjs +8 -0
- package/dist/addon/preset.cjs.map +1 -0
- package/dist/addon/preset.d.cts +5 -0
- package/dist/addon/preset.d.mts +5 -0
- package/dist/addon/preset.mjs +6 -0
- package/dist/addon/preset.mjs.map +1 -0
- package/dist/addon/vitePlugin.cjs +26 -0
- package/dist/addon/vitePlugin.cjs.map +1 -0
- package/dist/addon/vitePlugin.d.cts +9 -0
- package/dist/addon/vitePlugin.d.mts +9 -0
- package/dist/addon/vitePlugin.mjs +24 -0
- package/dist/addon/vitePlugin.mjs.map +1 -0
- package/dist/blocks/DependencyPreviews.cjs +102 -0
- package/dist/blocks/DependencyPreviews.cjs.map +1 -0
- package/dist/blocks/DependencyPreviews.d.cts +7 -0
- package/dist/blocks/DependencyPreviews.d.mts +7 -0
- package/dist/blocks/DependencyPreviews.mjs +100 -0
- package/dist/blocks/DependencyPreviews.mjs.map +1 -0
- package/dist/blocks/DependencyPreviews.module.css +14 -0
- package/dist/blocks/index.cjs +1 -0
- package/dist/blocks/index.d.cts +1 -0
- package/dist/blocks/index.d.mts +1 -0
- package/dist/blocks/index.mjs +1 -0
- package/dist/cli/sb-deps.cjs +321 -0
- package/dist/cli/sb-deps.cjs.map +1 -0
- package/dist/cli/sb-deps.d.cts +1 -0
- package/dist/cli/sb-deps.d.mts +1 -0
- package/dist/cli/sb-deps.mjs +319 -0
- package/dist/cli/sb-deps.mjs.map +1 -0
- package/dist/cli/scripts/depcruise.config.cjs +38 -0
- package/dist/cli/scripts/depcruise.config.cjs.map +1 -0
- package/dist/cli/scripts/depcruise.config.d.cts +6 -0
- package/dist/cli/scripts/depcruise.config.d.mts +7 -0
- package/dist/cli/scripts/depcruise.config.mjs +37 -0
- package/dist/cli/scripts/depcruise.config.mjs.map +1 -0
- package/dist/cli/scripts/postprocess.cjs +106 -0
- package/dist/cli/scripts/postprocess.cjs.map +1 -0
- package/dist/cli/scripts/postprocess.d.cts +1 -0
- package/dist/cli/scripts/postprocess.d.mts +1 -0
- package/dist/cli/scripts/postprocess.mjs +106 -0
- package/dist/cli/scripts/postprocess.mjs.map +1 -0
- package/dist/components/ComponentSourceLink.cjs +42 -0
- package/dist/components/ComponentSourceLink.cjs.map +1 -0
- package/dist/components/ComponentSourceLink.mjs +40 -0
- package/dist/components/ComponentSourceLink.mjs.map +1 -0
- package/dist/components/ComponentSourceLink.module.css +5 -0
- package/dist/components/CopyButton.cjs +112 -0
- package/dist/components/CopyButton.cjs.map +1 -0
- package/dist/components/CopyButton.mjs +110 -0
- package/dist/components/CopyButton.mjs.map +1 -0
- package/dist/components/CopyButton.module.css +76 -0
- package/dist/components/Expandable.cjs +51 -0
- package/dist/components/Expandable.cjs.map +1 -0
- package/dist/components/Expandable.mjs +49 -0
- package/dist/components/Expandable.mjs.map +1 -0
- package/dist/components/Expandable.module.css +110 -0
- package/dist/components/FullParityStory.cjs +47 -0
- package/dist/components/FullParityStory.cjs.map +1 -0
- package/dist/components/FullParityStory.mjs +44 -0
- package/dist/components/FullParityStory.mjs.map +1 -0
- package/dist/components/PathCopyMolecule.cjs +28 -0
- package/dist/components/PathCopyMolecule.cjs.map +1 -0
- package/dist/components/PathCopyMolecule.mjs +26 -0
- package/dist/components/PathCopyMolecule.mjs.map +1 -0
- package/dist/components/PathCopyMolecule.module.css +14 -0
- package/dist/components/PrimaryPreview.cjs +35 -0
- package/dist/components/PrimaryPreview.cjs.map +1 -0
- package/dist/components/PrimaryPreview.mjs +34 -0
- package/dist/components/PrimaryPreview.mjs.map +1 -0
- package/dist/components/SbHeading.cjs +18 -0
- package/dist/components/SbHeading.cjs.map +1 -0
- package/dist/components/SbHeading.mjs +16 -0
- package/dist/components/SbHeading.mjs.map +1 -0
- package/dist/components/SbHeading.module.css +23 -0
- package/dist/components/StoryLink.cjs +45 -0
- package/dist/components/StoryLink.cjs.map +1 -0
- package/dist/components/StoryLink.mjs +43 -0
- package/dist/components/StoryLink.mjs.map +1 -0
- package/dist/components/StoryLink.module.css +13 -0
- package/dist/components/TooltipTrigger.cjs +100 -0
- package/dist/components/TooltipTrigger.cjs.map +1 -0
- package/dist/components/TooltipTrigger.mjs +98 -0
- package/dist/components/TooltipTrigger.mjs.map +1 -0
- package/dist/components/TooltipTrigger.module.css +62 -0
- package/dist/components/icons/ArrowToRectangleIcon.cjs +19 -0
- package/dist/components/icons/ArrowToRectangleIcon.cjs.map +1 -0
- package/dist/components/icons/ArrowToRectangleIcon.mjs +18 -0
- package/dist/components/icons/ArrowToRectangleIcon.mjs.map +1 -0
- package/dist/components/icons/BuildIcon.cjs +19 -0
- package/dist/components/icons/BuildIcon.cjs.map +1 -0
- package/dist/components/icons/BuildIcon.mjs +18 -0
- package/dist/components/icons/BuildIcon.mjs.map +1 -0
- package/dist/components/icons/CopyIcon.cjs +19 -0
- package/dist/components/icons/CopyIcon.cjs.map +1 -0
- package/dist/components/icons/CopyIcon.mjs +18 -0
- package/dist/components/icons/CopyIcon.mjs.map +1 -0
- package/dist/components/icons/CubeIcon.cjs +19 -0
- package/dist/components/icons/CubeIcon.cjs.map +1 -0
- package/dist/components/icons/CubeIcon.mjs +18 -0
- package/dist/components/icons/CubeIcon.mjs.map +1 -0
- package/dist/components/icons/DoubleChevronDown.cjs +19 -0
- package/dist/components/icons/DoubleChevronDown.cjs.map +1 -0
- package/dist/components/icons/DoubleChevronDown.mjs +18 -0
- package/dist/components/icons/DoubleChevronDown.mjs.map +1 -0
- package/dist/components/icons/ExternalLinkIcon.cjs +19 -0
- package/dist/components/icons/ExternalLinkIcon.cjs.map +1 -0
- package/dist/components/icons/ExternalLinkIcon.mjs +18 -0
- package/dist/components/icons/ExternalLinkIcon.mjs.map +1 -0
- package/dist/components/icons/EyeOpen.cjs +23 -0
- package/dist/components/icons/EyeOpen.cjs.map +1 -0
- package/dist/components/icons/EyeOpen.mjs +22 -0
- package/dist/components/icons/EyeOpen.mjs.map +1 -0
- package/dist/components/icons/LoadingRipples.cjs +79 -0
- package/dist/components/icons/LoadingRipples.cjs.map +1 -0
- package/dist/components/icons/LoadingRipples.mjs +78 -0
- package/dist/components/icons/LoadingRipples.mjs.map +1 -0
- package/dist/components/icons/SquaresPlus.cjs +19 -0
- package/dist/components/icons/SquaresPlus.cjs.map +1 -0
- package/dist/components/icons/SquaresPlus.mjs +18 -0
- package/dist/components/icons/SquaresPlus.mjs.map +1 -0
- package/dist/components/icons/Svg.cjs +37 -0
- package/dist/components/icons/Svg.cjs.map +1 -0
- package/dist/components/icons/Svg.mjs +36 -0
- package/dist/components/icons/Svg.mjs.map +1 -0
- package/dist/components/icons/X.cjs +19 -0
- package/dist/components/icons/X.cjs.map +1 -0
- package/dist/components/icons/X.mjs +18 -0
- package/dist/components/icons/X.mjs.map +1 -0
- package/dist/constants.cjs +9 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.mjs +7 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/hooks/useDependencyGraph.cjs +63 -0
- package/dist/hooks/useDependencyGraph.cjs.map +1 -0
- package/dist/hooks/useDependencyGraph.mjs +60 -0
- package/dist/hooks/useDependencyGraph.mjs.map +1 -0
- package/dist/hooks/useDynamicStory.cjs +83 -0
- package/dist/hooks/useDynamicStory.cjs.map +1 -0
- package/dist/hooks/useDynamicStory.mjs +82 -0
- package/dist/hooks/useDynamicStory.mjs.map +1 -0
- package/dist/hooks/useStoryParams.cjs +17 -0
- package/dist/hooks/useStoryParams.cjs.map +1 -0
- package/dist/hooks/useStoryParams.mjs +16 -0
- package/dist/hooks/useStoryParams.mjs.map +1 -0
- package/dist/index.cjs +15 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +9 -0
- package/dist/manager.cjs +22 -0
- package/dist/manager.cjs.map +1 -0
- package/dist/manager.d.cts +1 -0
- package/dist/manager.d.mts +1 -0
- package/dist/manager.mjs +21 -0
- package/dist/manager.mjs.map +1 -0
- package/dist/panels/DefaultAutoDocsLayout.cjs +24 -0
- package/dist/panels/DefaultAutoDocsLayout.cjs.map +1 -0
- package/dist/panels/DefaultAutoDocsLayout.d.cts +10 -0
- package/dist/panels/DefaultAutoDocsLayout.d.mts +10 -0
- package/dist/panels/DefaultAutoDocsLayout.mjs +22 -0
- package/dist/panels/DefaultAutoDocsLayout.mjs.map +1 -0
- package/dist/panels/GraphView.cjs +78 -0
- package/dist/panels/GraphView.cjs.map +1 -0
- package/dist/panels/GraphView.d.cts +7 -0
- package/dist/panels/GraphView.d.mts +7 -0
- package/dist/panels/GraphView.mjs +77 -0
- package/dist/panels/GraphView.mjs.map +1 -0
- package/dist/panels/index.cjs +3 -0
- package/dist/panels/index.d.cts +3 -0
- package/dist/panels/index.d.mts +3 -0
- package/dist/panels/index.mjs +3 -0
- package/dist/preview.cjs +23 -0
- package/dist/preview.cjs.map +1 -0
- package/dist/preview.d.cts +9 -0
- package/dist/preview.d.mts +10 -0
- package/dist/preview.mjs +21 -0
- package/dist/preview.mjs.map +1 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +104 -0
- package/dist/types.d.mts +104 -0
- package/dist/types.mjs +0 -0
- package/package.json +94 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DependencyPreviews.mjs","names":[],"sources":["../../src/blocks/DependencyPreviews.tsx"],"sourcesContent":["import { PrimaryPreview } from '../components/PrimaryPreview'\nimport { StoryLink } from '../components/StoryLink'\nimport {\n\tDependencyGraphProvider,\n\tfilterOutStoryAndNonComponentFiles,\n\tuseDependencyGraph,\n} from '../hooks/useDependencyGraph'\nimport type { StoryInfo } from '../types'\n\nimport { ComponentSourceLink } from '../components/ComponentSourceLink'\nimport { Expandable } from '../components/Expandable'\nimport { BuildIcon } from '../components/icons/BuildIcon'\nimport { EyeOpen } from '../components/icons/EyeOpen'\nimport { SquaresPlus } from '../components/icons/SquaresPlus'\n\nimport { ArrowToRectangle } from '../components/icons/ArrowToRectangleIcon'\nimport { CubeIcon } from '../components/icons/CubeIcon'\nimport { PathCopyMolecule } from '../components/PathCopyMolecule'\nimport { SbHeading } from '../components/SbHeading'\nimport s from './DependencyPreviews.module.css'\n\nexport function DependencyPreviews() {\n\treturn (\n\t\t<DependencyGraphProvider>\n\t\t\t<TopLevelDependencyPreviews />\n\t\t</DependencyGraphProvider>\n\t)\n}\n\nfunction TopLevelDependencyPreviews() {\n\tconst { node } = useDependencyGraph()\n\tif (!node) return <div>No dependency previews for this component.</div>\n\n\treturn (\n\t\t<div className={s.topLevelWrapper}>\n\t\t\t<SbHeading>Dependency previews</SbHeading>\n\t\t\t<DepsPreviewContent storyInfo={node} enablePreview={false} />\n\t\t</div>\n\t)\n}\n\ninterface PropsForDepsPreviewContent {\n\tstoryInfo: StoryInfo\n\tenablePreview?: boolean\n}\nfunction DepsPreviewContent({\n\tstoryInfo,\n\tenablePreview = true,\n}: PropsForDepsPreviewContent) {\n\tconst { graph } = useDependencyGraph()\n\tconst { builtWith, usedIn } = graph![storyInfo.componentPath]\n\tconst filteredBuiltWith = filterOutStoryAndNonComponentFiles(builtWith)\n\tconst filteredUsedIn = filterOutStoryAndNonComponentFiles(usedIn)\n\n\treturn (\n\t\t<div>\n\t\t\t{enablePreview && (\n\t\t\t\t<Expandable\n\t\t\t\t\tHeader={`Preview ${storyInfo.storyTitle} component`}\n\t\t\t\t\tIcon={EyeOpen}\n\t\t\t\t>\n\t\t\t\t\t<PrimaryPreview storyInfo={storyInfo} />\n\t\t\t\t</Expandable>\n\t\t\t)}\n\n\t\t\t<Expandable\n\t\t\t\tHeader={`Paths to ${storyInfo.storyTitle} component`}\n\t\t\t\tIcon={ArrowToRectangle}\n\t\t\t>\n\t\t\t\t<div className={s.pathData}>\n\t\t\t\t\t<PathCopyMolecule\n\t\t\t\t\t\tlabel=\"Source File Path\"\n\t\t\t\t\t\tcopyContent={storyInfo.componentPath}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ComponentSourceLink storyInfo={storyInfo} />\n\t\t\t\t\t</PathCopyMolecule>\n\n\t\t\t\t\t<PathCopyMolecule\n\t\t\t\t\t\tlabel=\"Story Title Path\"\n\t\t\t\t\t\tcopyContent={storyInfo.storyTitlePath!}\n\t\t\t\t\t>\n\t\t\t\t\t\t<StoryLink info={storyInfo}>\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t\t\t\t\t\t// allow line breaks on slashes\n\t\t\t\t\t\t\t\t\t__html: storyInfo.storyTitlePath!.replaceAll(\n\t\t\t\t\t\t\t\t\t\t'/',\n\t\t\t\t\t\t\t\t\t\t'/<wbr/>',\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</StoryLink>\n\t\t\t\t\t</PathCopyMolecule>\n\n\t\t\t\t\t<PathCopyMolecule\n\t\t\t\t\t\tlabel=\"Story Page ID\"\n\t\t\t\t\t\tcopyContent={storyInfo.storyId!}\n\t\t\t\t\t>\n\t\t\t\t\t\t<StoryLink info={storyInfo}>\n\t\t\t\t\t\t\t{storyInfo.storyId}\n\t\t\t\t\t\t</StoryLink>\n\t\t\t\t\t</PathCopyMolecule>\n\t\t\t\t</div>\n\t\t\t</Expandable>\n\n\t\t\t{filteredBuiltWith.length > 0 && (\n\t\t\t\t<Expandable\n\t\t\t\t\tHeader={`Built with ${\n\t\t\t\t\t\tfilteredBuiltWith.length\n\t\t\t\t\t} component${plural(filteredBuiltWith)}`}\n\t\t\t\t\tIcon={BuildIcon}\n\t\t\t\t>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t{filterOutStoryAndNonComponentFiles(builtWith).map(\n\t\t\t\t\t\t\t(info) => (\n\t\t\t\t\t\t\t\t<DepsPreviewItem\n\t\t\t\t\t\t\t\t\tstoryInfo={info}\n\t\t\t\t\t\t\t\t\tkey={info.componentPath}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)}\n\t\t\t\t\t</ul>\n\t\t\t\t</Expandable>\n\t\t\t)}\n\t\t\t{filteredUsedIn.length > 0 && (\n\t\t\t\t<Expandable\n\t\t\t\t\tHeader={`Used in ${filteredUsedIn.length} component${plural(\n\t\t\t\t\t\tfilteredUsedIn,\n\t\t\t\t\t)}`}\n\t\t\t\t\tIcon={SquaresPlus}\n\t\t\t\t>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t{filterOutStoryAndNonComponentFiles(usedIn).map(\n\t\t\t\t\t\t\t(info) => (\n\t\t\t\t\t\t\t\t<DepsPreviewItem\n\t\t\t\t\t\t\t\t\tstoryInfo={info}\n\t\t\t\t\t\t\t\t\tkey={info.componentPath}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)}\n\t\t\t\t\t</ul>\n\t\t\t\t</Expandable>\n\t\t\t)}\n\t\t</div>\n\t)\n}\n\ninterface PropsForDepsPreviewItem {\n\tstoryInfo: StoryInfo\n}\n\nfunction DepsPreviewItem({ storyInfo }: PropsForDepsPreviewItem) {\n\treturn (\n\t\t<li key={storyInfo.componentPath}>\n\t\t\t{storyInfo.storyId ? (\n\t\t\t\t<Expandable\n\t\t\t\t\tIcon={CubeIcon}\n\t\t\t\t\tHeader={\n\t\t\t\t\t\t<StoryLink info={storyInfo} tooltipPosition=\"right\" />\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<DepsPreviewContent storyInfo={storyInfo} />\n\t\t\t\t</Expandable>\n\t\t\t) : (\n\t\t\t\t<StoryLink info={storyInfo} />\n\t\t\t)}\n\t\t</li>\n\t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BACC,mCAAmC,UAAU,CAAC,KAC7C,SACA,oBAAC,mBACA,WAAW,QACN,KAAK,cACT,CAEH,GACG;IACO;EAEb,eAAe,SAAS,KACxB,oBAAC;GACA,QAAQ,WAAW,eAAe,OAAO,YAAY,OACpD,eACA;GACD,MAAM;aAEN,oBAAC,kBACC,mCAAmC,OAAO,CAAC,KAC1C,SACA,oBAAC,mBACA,WAAW,QACN,KAAK,cACT,CAEH,GACG;IACO;KAET;;AAQR,SAAS,gBAAgB,EAAE,aAAsC;AAChE,QACC,oBAAC,kBACC,UAAU,UACV,oBAAC;EACA,MAAM;EACN,QACC,oBAAC;GAAU,MAAM;GAAW,iBAAgB;IAAU;YAGvD,oBAAC,sBAA8B,YAAa;GAChC,GAEb,oBAAC,aAAU,MAAM,YAAa,IAXvB,UAAU,cAad;;AAIP,SAAS,OAAO,KAAiB;AAChC,QAAO,IAAI,WAAW,IAAI,KAAK"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
.topLevelWrapper {
|
|
2
|
+
display: grid;
|
|
3
|
+
/**
|
|
4
|
+
Enables animation to height auto!!!
|
|
5
|
+
Has middling browser support so need to use progressive enhancement. */
|
|
6
|
+
interpolate-size: allow-keywords;
|
|
7
|
+
/* gap: 1em; */
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.pathData.pathData {
|
|
11
|
+
margin: 0;
|
|
12
|
+
display: grid;
|
|
13
|
+
gap: 1em;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const require_DependencyPreviews = require('./DependencyPreviews.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { DependencyPreviews } from "./DependencyPreviews.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { DependencyPreviews } from "./DependencyPreviews.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { DependencyPreviews } from "./DependencyPreviews.mjs";
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
let node_child_process = require("node:child_process");
|
|
6
|
+
let node_url = require("node:url");
|
|
7
|
+
let _parcel_watcher = require("@parcel/watcher");
|
|
8
|
+
_parcel_watcher = require_runtime.__toESM(_parcel_watcher);
|
|
9
|
+
let micromatch = require("micromatch");
|
|
10
|
+
micromatch = require_runtime.__toESM(micromatch);
|
|
11
|
+
|
|
12
|
+
//#region cli/sb-deps.ts
|
|
13
|
+
const argv = process.argv.slice(2);
|
|
14
|
+
const WATCH = argv.includes("--watch");
|
|
15
|
+
const RUN_SB = argv.includes("--run-storybook");
|
|
16
|
+
const PORT_ARGI = Math.max(argv.indexOf("--sb-port"), 0);
|
|
17
|
+
const SB_PORT = PORT_ARGI && argv[PORT_ARGI + 1] ? Number(argv[PORT_ARGI + 1]) || 6006 : 6006;
|
|
18
|
+
const projectRoot = process.cwd();
|
|
19
|
+
const outDir = (0, node_path.resolve)(projectRoot, ".storybook");
|
|
20
|
+
const rawPath = (0, node_path.join)(outDir, "dependency-previews.raw.json");
|
|
21
|
+
const cookedPath = (0, node_path.join)(outDir, "dependency-previews.json");
|
|
22
|
+
if (!(0, node_fs.existsSync)(outDir)) (0, node_fs.mkdirSync)(outDir, { recursive: true });
|
|
23
|
+
const __filename$1 = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
24
|
+
const __dirname$1 = (0, node_path.dirname)(__filename$1);
|
|
25
|
+
const pkgDefault = (0, node_path.resolve)(__dirname$1, "scripts", "depcruise.config.cjs");
|
|
26
|
+
const overrideCandidates = [
|
|
27
|
+
(0, node_path.resolve)(projectRoot, "depcruise.config.cjs"),
|
|
28
|
+
(0, node_path.resolve)(projectRoot, ".dependency-cruiser.js"),
|
|
29
|
+
(0, node_path.resolve)(projectRoot, ".dependency-cruiser.cjs")
|
|
30
|
+
];
|
|
31
|
+
const configPath = overrideCandidates.find((p) => (0, node_fs.existsSync)(p)) || ((0, node_fs.existsSync)(pkgDefault) ? pkgDefault : null);
|
|
32
|
+
const post = (0, node_path.resolve)(__dirname$1, "scripts", "postprocess.mjs");
|
|
33
|
+
function runDepCruiseOnce() {
|
|
34
|
+
const cfgFlag = configPath ? `--config "${configPath}"` : "--no-config";
|
|
35
|
+
const cmd = `npx depcruise . ${cfgFlag} --output-type json`;
|
|
36
|
+
const start = Date.now();
|
|
37
|
+
const stdout = (0, node_child_process.execSync)(cmd, {
|
|
38
|
+
cwd: projectRoot,
|
|
39
|
+
stdio: [
|
|
40
|
+
"ignore",
|
|
41
|
+
"pipe",
|
|
42
|
+
"inherit"
|
|
43
|
+
],
|
|
44
|
+
encoding: "utf8"
|
|
45
|
+
});
|
|
46
|
+
(0, node_fs.writeFileSync)(rawPath, stdout, "utf8");
|
|
47
|
+
info(`graph ✓ (${ms(Date.now() - start)})`);
|
|
48
|
+
}
|
|
49
|
+
function postprocessOnce() {
|
|
50
|
+
const start = Date.now();
|
|
51
|
+
const postCmd = `node "${post}" "${rawPath}" "${cookedPath}"`;
|
|
52
|
+
(0, node_child_process.execSync)(postCmd, {
|
|
53
|
+
cwd: projectRoot,
|
|
54
|
+
stdio: "inherit"
|
|
55
|
+
});
|
|
56
|
+
info(`compiled ✓ → ${rel(cookedPath)} (${ms(Date.now() - start)})`);
|
|
57
|
+
}
|
|
58
|
+
function buildOnce() {
|
|
59
|
+
try {
|
|
60
|
+
runDepCruiseOnce();
|
|
61
|
+
postprocessOnce();
|
|
62
|
+
} catch (e) {
|
|
63
|
+
error("build failed");
|
|
64
|
+
if (!WATCH) throw e;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function toWords(input) {
|
|
68
|
+
return String(input).replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_\-./]+/g, " ").trim().split(/\s+/);
|
|
69
|
+
}
|
|
70
|
+
function toTitleCase(words) {
|
|
71
|
+
return words.map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
72
|
+
}
|
|
73
|
+
function toPascalCase(input) {
|
|
74
|
+
return toTitleCase(toWords(input)).replace(/\s+/g, "");
|
|
75
|
+
}
|
|
76
|
+
function isEmptyOrWhitespace(absPath) {
|
|
77
|
+
try {
|
|
78
|
+
const s = (0, node_fs.statSync)(absPath);
|
|
79
|
+
if (s.size === 0) return true;
|
|
80
|
+
const txt = (0, node_fs.readFileSync)(absPath, "utf8");
|
|
81
|
+
return !txt.trim();
|
|
82
|
+
} catch {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function isComponentsTsx(absPath) {
|
|
87
|
+
const norm = absPath.replace(/\\/g, "/");
|
|
88
|
+
return /\/src\/components\/.+\.tsx$/i.test(norm) && !/\.stories?\.tsx$/i.test(norm);
|
|
89
|
+
}
|
|
90
|
+
function componentBaseFromComponent(absCompPath) {
|
|
91
|
+
return (0, node_path.basename)(absCompPath, ".tsx");
|
|
92
|
+
}
|
|
93
|
+
function detectAtomicTag(absPath) {
|
|
94
|
+
const adaptedPath = absPath.toLowerCase().replace(/\\/g, "/");
|
|
95
|
+
const tokens = [
|
|
96
|
+
"atom",
|
|
97
|
+
"molecule",
|
|
98
|
+
"organism",
|
|
99
|
+
"template",
|
|
100
|
+
"page",
|
|
101
|
+
"icon"
|
|
102
|
+
];
|
|
103
|
+
let best = null;
|
|
104
|
+
for (const t of tokens) {
|
|
105
|
+
const idx = adaptedPath.lastIndexOf(t);
|
|
106
|
+
if (idx !== -1 && (best === null || idx > best.idx)) best = {
|
|
107
|
+
val: t,
|
|
108
|
+
idx
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return best ? best.val : null;
|
|
112
|
+
}
|
|
113
|
+
function storyPathForComponent(absCompPath) {
|
|
114
|
+
const dir = (0, node_path.dirname)(absCompPath);
|
|
115
|
+
const base = componentBaseFromComponent(absCompPath);
|
|
116
|
+
return (0, node_path.join)(dir, `${base}.stories.tsx`);
|
|
117
|
+
}
|
|
118
|
+
function makeTitleFromComponent(absCompPath) {
|
|
119
|
+
const srcRoot = (0, node_path.join)(projectRoot, "src") + node_path.sep;
|
|
120
|
+
const normAbs = absCompPath.replace(/\\/g, "/");
|
|
121
|
+
const relFromSrc = normAbs.startsWith(srcRoot.replace(/\\/g, "/")) ? normAbs.slice(srcRoot.length) : absCompPath.replace(projectRoot + node_path.sep, "").replace(/\\/g, "/");
|
|
122
|
+
const dir = node_path.posix.dirname(relFromSrc);
|
|
123
|
+
let segments = dir.split("/").filter(Boolean);
|
|
124
|
+
if (segments[0] && /^components?$/i.test(segments[0])) segments = segments.slice(1);
|
|
125
|
+
const titledFolders = segments.map((s) => toTitleCase(toWords(s)));
|
|
126
|
+
const compName = componentBaseFromComponent(absCompPath);
|
|
127
|
+
const compTitle = toTitleCase(toWords(compName));
|
|
128
|
+
const fullStoryPath = [...titledFolders, compTitle].filter(Boolean);
|
|
129
|
+
const dedupedStoryPath = [...new Set(fullStoryPath)];
|
|
130
|
+
return dedupedStoryPath.join(" / ");
|
|
131
|
+
}
|
|
132
|
+
function scaffoldComponent(absCompPath) {
|
|
133
|
+
const base = componentBaseFromComponent(absCompPath);
|
|
134
|
+
const componentName = toPascalCase(base);
|
|
135
|
+
const propsName = `PropsFor${componentName}`;
|
|
136
|
+
const tpl = `import type { ReactNode } from 'react'
|
|
137
|
+
|
|
138
|
+
export interface ${propsName} {
|
|
139
|
+
children?: ReactNode
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function ${componentName}({ children }: ${propsName}) {
|
|
143
|
+
return (
|
|
144
|
+
<div className="${componentName}">
|
|
145
|
+
<p>${componentName}</p>
|
|
146
|
+
{children}
|
|
147
|
+
</div>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
`;
|
|
151
|
+
(0, node_fs.writeFileSync)(absCompPath, tpl, "utf8");
|
|
152
|
+
info(`scaffolded component → \${rel(absCompPath)}`);
|
|
153
|
+
}
|
|
154
|
+
function scaffoldStoryForComponent(absCompPath) {
|
|
155
|
+
const base = componentBaseFromComponent(absCompPath);
|
|
156
|
+
const componentName = toPascalCase(base);
|
|
157
|
+
const propsName = `PropsFor${componentName}`;
|
|
158
|
+
const title = makeTitleFromComponent(absCompPath);
|
|
159
|
+
const atomic = detectAtomicTag(absCompPath);
|
|
160
|
+
const tags = ["autodocs"];
|
|
161
|
+
if (atomic) tags.push(atomic);
|
|
162
|
+
const storyTpl = `import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
163
|
+
import type { StoryParameters } from 'storybook-addon-dependency-previews'
|
|
164
|
+
import { ${componentName}, type ${propsName} } from './${componentName}'
|
|
165
|
+
|
|
166
|
+
const meta: Meta<typeof ${componentName}> = {
|
|
167
|
+
title: '${title}',
|
|
168
|
+
component: ${componentName},
|
|
169
|
+
tags: ${JSON.stringify(tags)},
|
|
170
|
+
parameters: {
|
|
171
|
+
layout: 'padded',
|
|
172
|
+
__filePath: import.meta.url,
|
|
173
|
+
} satisfies StoryParameters,
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export default meta
|
|
177
|
+
|
|
178
|
+
type Story = StoryObj<typeof meta>
|
|
179
|
+
|
|
180
|
+
export const Primary: Story = {
|
|
181
|
+
args: {} satisfies ${propsName},
|
|
182
|
+
}
|
|
183
|
+
`;
|
|
184
|
+
const storyPath = storyPathForComponent(absCompPath);
|
|
185
|
+
(0, node_fs.writeFileSync)(storyPath, storyTpl, "utf8");
|
|
186
|
+
info(`scaffolded story → \${rel(storyPath)}`);
|
|
187
|
+
return storyPath;
|
|
188
|
+
}
|
|
189
|
+
function ensureStoryForComponent(absCompPath) {
|
|
190
|
+
const sPath = storyPathForComponent(absCompPath);
|
|
191
|
+
if ((0, node_fs.existsSync)(sPath)) return null;
|
|
192
|
+
return scaffoldStoryForComponent(absCompPath);
|
|
193
|
+
}
|
|
194
|
+
function startWatcher() {
|
|
195
|
+
const root = projectRoot;
|
|
196
|
+
const includeGlobs = [
|
|
197
|
+
"**/*.stories.{ts,tsx,js,jsx,mdx,svelte}",
|
|
198
|
+
"**/*.story.{ts,tsx,js,jsx,mdx,svelte}",
|
|
199
|
+
"src/**/*.{ts,tsx,js,jsx,svelte}",
|
|
200
|
+
"depcruise.config.cjs",
|
|
201
|
+
".dependency-cruiser.{js,cjs}"
|
|
202
|
+
];
|
|
203
|
+
const ignoreGlobs = [
|
|
204
|
+
"node_modules/**",
|
|
205
|
+
".git/**",
|
|
206
|
+
".storybook/**",
|
|
207
|
+
"**/.cache/**",
|
|
208
|
+
"**/dist/**",
|
|
209
|
+
"**/build/**"
|
|
210
|
+
];
|
|
211
|
+
let pending = false;
|
|
212
|
+
let timer = null;
|
|
213
|
+
let isDeletingFile = false;
|
|
214
|
+
function kick(reason, absPath) {
|
|
215
|
+
if (pending) return;
|
|
216
|
+
pending = true;
|
|
217
|
+
if (timer) clearTimeout(timer);
|
|
218
|
+
timer = setTimeout(() => {
|
|
219
|
+
info(`${reason}: ${rel(absPath)}`);
|
|
220
|
+
buildOnce();
|
|
221
|
+
pending = false;
|
|
222
|
+
}, 120);
|
|
223
|
+
}
|
|
224
|
+
return _parcel_watcher.default.subscribe(root, async (err, events) => {
|
|
225
|
+
if (err) {
|
|
226
|
+
error(`watch error ${err?.message || err}`);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
for (const ev of events) {
|
|
230
|
+
const abs = ev.path;
|
|
231
|
+
const relPath = rel(abs);
|
|
232
|
+
if (!micromatch.default.isMatch(relPath, includeGlobs)) continue;
|
|
233
|
+
if (ev.type === "delete") {
|
|
234
|
+
console.log("Deleted:", relPath);
|
|
235
|
+
isDeletingFile = true;
|
|
236
|
+
kick("unlink", abs);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (isComponentsTsx(abs) && ev.type === "create") {
|
|
240
|
+
await handleComponentCreation(abs, relPath);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
kick(ev.type, abs);
|
|
244
|
+
}
|
|
245
|
+
}, { ignore: ignoreGlobs }).then((result) => {
|
|
246
|
+
info("watching… (ready)");
|
|
247
|
+
return result;
|
|
248
|
+
}).catch((e) => error(`watch init failed ${e?.message || e}`));
|
|
249
|
+
async function handleComponentCreation(abs, relPath) {
|
|
250
|
+
if (isEmptyOrWhitespace(abs)) {
|
|
251
|
+
scaffoldComponent(abs);
|
|
252
|
+
}
|
|
253
|
+
console.log("Component creation detected:", relPath);
|
|
254
|
+
const createdStory = ensureStoryForComponent(abs);
|
|
255
|
+
if (createdStory) {
|
|
256
|
+
kick("create:story", createdStory);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
let sbChild = null;
|
|
261
|
+
async function startStorybook() {
|
|
262
|
+
const isWin = process.platform === "win32";
|
|
263
|
+
const cmd = "npx";
|
|
264
|
+
const args = [
|
|
265
|
+
"-y",
|
|
266
|
+
"storybook",
|
|
267
|
+
"dev",
|
|
268
|
+
"-p",
|
|
269
|
+
String(SB_PORT)
|
|
270
|
+
];
|
|
271
|
+
info(`[sb-deps] launching: ${cmd} ${args.join(" ")}`);
|
|
272
|
+
sbChild = (0, node_child_process.spawn)(cmd, args, {
|
|
273
|
+
cwd: projectRoot,
|
|
274
|
+
stdio: "inherit",
|
|
275
|
+
shell: isWin,
|
|
276
|
+
env: process.env
|
|
277
|
+
});
|
|
278
|
+
sbChild.on("error", (err) => {
|
|
279
|
+
error(`spawn failed: ${err?.message || err}`);
|
|
280
|
+
});
|
|
281
|
+
sbChild.on("exit", (code, sig) => {
|
|
282
|
+
info(`storybook exited (${sig || code})`);
|
|
283
|
+
sbChild = null;
|
|
284
|
+
});
|
|
285
|
+
info(`storybook running on http://localhost:${SB_PORT}`);
|
|
286
|
+
}
|
|
287
|
+
banner("sb-deps");
|
|
288
|
+
info(`outDir: ${rel(outDir)}`);
|
|
289
|
+
info(configPath ? `config: ${rel(configPath)}` : "config: (none)");
|
|
290
|
+
buildOnce();
|
|
291
|
+
let watcher = null;
|
|
292
|
+
if (WATCH) startWatcher().then((w) => watcher = w || null);
|
|
293
|
+
if (RUN_SB) startStorybook();
|
|
294
|
+
process.on("SIGINT", async () => {
|
|
295
|
+
info("shutting down…");
|
|
296
|
+
await watcher?.unsubscribe();
|
|
297
|
+
sbChild?.kill("SIGINT");
|
|
298
|
+
process.exit(0);
|
|
299
|
+
});
|
|
300
|
+
function rel(p) {
|
|
301
|
+
const prefix = (0, node_path.resolve)(projectRoot) + node_path.sep;
|
|
302
|
+
return p.replace(prefix, "");
|
|
303
|
+
}
|
|
304
|
+
function ms(n) {
|
|
305
|
+
return `${Math.max(1, Math.round(n))}ms`;
|
|
306
|
+
}
|
|
307
|
+
function info(msg) {
|
|
308
|
+
console.log("[sb-deps]", msg);
|
|
309
|
+
}
|
|
310
|
+
function error(msg) {
|
|
311
|
+
console.error("[sb-deps]", msg);
|
|
312
|
+
}
|
|
313
|
+
function banner(title) {
|
|
314
|
+
console.log(`\n${title} – dependency previews\n`);
|
|
315
|
+
}
|
|
316
|
+
function wait(time = 500) {
|
|
317
|
+
return new Promise((r) => setTimeout(r, time));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
//#endregion
|
|
321
|
+
//# sourceMappingURL=sb-deps.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sb-deps.cjs","names":["__filename","__dirname","sep","posix","watcherParcel"],"sources":["../../cli/sb-deps.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/* eslint-disable no-console */\nimport { execSync, spawn, type ChildProcess } from 'node:child_process'\nimport {\n\texistsSync,\n\tmkdirSync,\n\twriteFileSync,\n\tstatSync,\n\treadFileSync,\n} from 'node:fs'\nimport { resolve, join, dirname, posix, sep, basename } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { createRequire } from 'node:module'\nimport watcherParcel from '@parcel/watcher'\nimport micromatch from 'micromatch'\n\n// ───────────────────────────────────────────────────────────────────────────────\n// Args\n// ───────────────────────────────────────────────────────────────────────────────\nconst argv = process.argv.slice(2)\nconst WATCH = argv.includes('--watch')\nconst RUN_SB = argv.includes('--run-storybook')\nconst PORT_ARGI = Math.max(argv.indexOf('--sb-port'), 0)\nconst SB_PORT =\n\tPORT_ARGI && argv[PORT_ARGI + 1]\n\t\t? Number(argv[PORT_ARGI + 1]) || 6006\n\t\t: 6006\n\n// ───────────────────────────────────────────────────────────────────────────────\n// Paths\n// ───────────────────────────────────────────────────────────────────────────────\nconst projectRoot = process.cwd()\nconst outDir = resolve(projectRoot, '.storybook')\nconst rawPath = join(outDir, 'dependency-previews.raw.json')\nconst cookedPath = join(outDir, 'dependency-previews.json')\n\nif (!existsSync(outDir)) mkdirSync(outDir, { recursive: true })\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = dirname(__filename)\n\n// Resolve depcruise config: prefer project overrides, else bundled default\nconst pkgDefault = resolve(__dirname, 'scripts', 'depcruise.config.cjs')\nconst overrideCandidates = [\n\tresolve(projectRoot, 'depcruise.config.cjs'),\n\tresolve(projectRoot, '.dependency-cruiser.js'),\n\tresolve(projectRoot, '.dependency-cruiser.cjs'),\n]\nconst configPath =\n\toverrideCandidates.find((p) => existsSync(p)) ||\n\t(existsSync(pkgDefault) ? pkgDefault : null)\n\n// Path to postprocess helper (built as ESM)\nconst post = resolve(__dirname, 'scripts', 'postprocess.mjs')\n\n// ───────────────────────────────────────────────────────────────────────────────\n// Runners\n// ───────────────────────────────────────────────────────────────────────────────\nfunction runDepCruiseOnce() {\n\tconst cfgFlag = configPath ? `--config \"${configPath}\"` : '--no-config'\n\tconst cmd = `npx depcruise . ${cfgFlag} --output-type json`\n\tconst start = Date.now()\n\tconst stdout = execSync(cmd, {\n\t\tcwd: projectRoot,\n\t\tstdio: ['ignore', 'pipe', 'inherit'],\n\t\tencoding: 'utf8',\n\t})\n\twriteFileSync(rawPath, stdout, 'utf8')\n\tinfo(`graph ✓ (${ms(Date.now() - start)})`)\n}\n\nfunction postprocessOnce() {\n\tconst start = Date.now()\n\tconst postCmd = `node \"${post}\" \"${rawPath}\" \"${cookedPath}\"`\n\texecSync(postCmd, { cwd: projectRoot, stdio: 'inherit' })\n\tinfo(`compiled ✓ → ${rel(cookedPath)} (${ms(Date.now() - start)})`)\n}\n\nfunction buildOnce() {\n\ttry {\n\t\trunDepCruiseOnce()\n\t\tpostprocessOnce()\n\t} catch (e) {\n\t\terror('build failed')\n\t\tif (!WATCH) throw e\n\t}\n}\n\n// ───────────────────────────────────────────────────────────────────────────────\n// String utils\n// ───────────────────────────────────────────────────────────────────────────────\nfunction toWords(input: string) {\n\treturn String(input)\n\t\t.replace(/([a-z0-9])([A-Z])/g, '$1 $2')\n\t\t.replace(/[_\\-./]+/g, ' ')\n\t\t.trim()\n\t\t.split(/\\s+/)\n}\nfunction toTitleCase(words: Array<string>) {\n\treturn words.map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(' ')\n}\nfunction toPascalCase(input: string) {\n\treturn toTitleCase(toWords(input)).replace(/\\s+/g, '')\n}\n\nfunction isEmptyOrWhitespace(absPath: string) {\n\ttry {\n\t\tconst s = statSync(absPath)\n\t\tif (s.size === 0) return true\n\t\tconst txt = readFileSync(absPath, 'utf8')\n\t\treturn !txt.trim()\n\t} catch {\n\t\treturn true\n\t}\n}\n\n// src/components/**/Thing.tsx ? (and not a story file)\nfunction isComponentsTsx(absPath: string) {\n\tconst norm = absPath.replace(/\\\\/g, '/')\n\treturn (\n\t\t/\\/src\\/components\\/.+\\.tsx$/i.test(norm) &&\n\t\t!/\\.stories?\\.tsx$/i.test(norm)\n\t)\n}\n\nfunction componentBaseFromComponent(absCompPath: string) {\n\treturn basename(absCompPath, '.tsx')\n}\n\nfunction detectAtomicTag(absPath: string) {\n\tconst adaptedPath = absPath.toLowerCase().replace(/\\\\/g, '/')\n\tconst tokens = ['atom', 'molecule', 'organism', 'template', 'page', 'icon']\n\tlet best: null | { val: string; idx: number } = null\n\tfor (const t of tokens) {\n\t\tconst idx = adaptedPath.lastIndexOf(t)\n\t\tif (idx !== -1 && (best === null || idx > best.idx))\n\t\t\tbest = { val: t, idx }\n\t}\n\treturn best ? best.val : null\n}\n\nfunction storyPathForComponent(absCompPath: string) {\n\tconst dir = dirname(absCompPath)\n\tconst base = componentBaseFromComponent(absCompPath)\n\treturn join(dir, `${base}.stories.tsx`)\n}\n\nfunction makeTitleFromComponent(absCompPath: string) {\n\tconst srcRoot = join(projectRoot, 'src') + sep\n\tconst normAbs = absCompPath.replace(/\\\\/g, '/')\n\tconst relFromSrc = normAbs.startsWith(srcRoot.replace(/\\\\/g, '/'))\n\t\t? normAbs.slice(srcRoot.length)\n\t\t: absCompPath.replace(projectRoot + sep, '').replace(/\\\\/g, '/')\n\n\tconst dir = posix.dirname(relFromSrc)\n\tlet segments = dir.split('/').filter(Boolean)\n\tif (segments[0] && /^components?$/i.test(segments[0]))\n\t\tsegments = segments.slice(1)\n\n\tconst titledFolders = segments.map((s) => toTitleCase(toWords(s)))\n\tconst compName = componentBaseFromComponent(absCompPath)\n\tconst compTitle = toTitleCase(toWords(compName))\n\n\tconst fullStoryPath = [...titledFolders, compTitle].filter(Boolean)\n\n\t// remove duplicates (e.g. Folder/Thing/Thing => Folder/Thing)\n\tconst dedupedStoryPath = [...new Set(fullStoryPath)]\n\n\treturn dedupedStoryPath.join(' / ')\n}\n\n// ───────────────────────────────────────────────────────────────────────────────\n// Story & component scaffolding\n// ───────────────────────────────────────────────────────────────────────────────\nfunction scaffoldComponent(absCompPath: string) {\n\tconst base = componentBaseFromComponent(absCompPath)\n\tconst componentName = toPascalCase(base)\n\tconst propsName = `PropsFor${componentName}`\n\n\tconst tpl = `import type { ReactNode } from 'react'\n\nexport interface ${propsName} {\n children?: ReactNode\n}\n\nexport function ${componentName}({ children }: ${propsName}) {\n return (\n <div className=\"${componentName}\">\n <p>${componentName}</p>\n {children}\n </div>\n )\n}\n`\n\twriteFileSync(absCompPath, tpl, 'utf8')\n\tinfo(`scaffolded component → \\${rel(absCompPath)}`)\n}\n\nfunction scaffoldStoryForComponent(absCompPath: string) {\n\tconst base = componentBaseFromComponent(absCompPath)\n\tconst componentName = toPascalCase(base)\n\tconst propsName = `PropsFor${componentName}`\n\tconst title = makeTitleFromComponent(absCompPath)\n\tconst atomic = detectAtomicTag(absCompPath)\n\tconst tags = ['autodocs']\n\tif (atomic) tags.push(atomic)\n\n\tconst storyTpl = `import type { Meta, StoryObj } from '@storybook/react-vite'\nimport type { StoryParameters } from 'storybook-addon-dependency-previews'\nimport { ${componentName}, type ${propsName} } from './${componentName}'\n\nconst meta: Meta<typeof ${componentName}> = {\n title: '${title}',\n component: ${componentName},\n tags: ${JSON.stringify(tags)},\n parameters: {\n layout: 'padded',\n __filePath: import.meta.url,\n } satisfies StoryParameters,\n}\n\nexport default meta\n\ntype Story = StoryObj<typeof meta>\n\nexport const Primary: Story = {\n args: {} satisfies ${propsName},\n}\n`\n\tconst storyPath = storyPathForComponent(absCompPath)\n\twriteFileSync(storyPath, storyTpl, 'utf8')\n\tinfo(`scaffolded story → \\${rel(storyPath)}`)\n\treturn storyPath\n}\n\nfunction ensureStoryForComponent(absCompPath: string) {\n\tconst sPath = storyPathForComponent(absCompPath)\n\tif (existsSync(sPath)) return null\n\treturn scaffoldStoryForComponent(absCompPath)\n}\n\n// ───────────────────────────────────────────────────────────────────────────────\n// Watcher\n// ───────────────────────────────────────────────────────────────────────────────\nfunction startWatcher() {\n\tconst root = projectRoot\n\tconst includeGlobs = [\n\t\t'**/*.stories.{ts,tsx,js,jsx,mdx,svelte}',\n\t\t'**/*.story.{ts,tsx,js,jsx,mdx,svelte}',\n\t\t'src/**/*.{ts,tsx,js,jsx,svelte}',\n\t\t'depcruise.config.cjs',\n\t\t'.dependency-cruiser.{js,cjs}',\n\t]\n\tconst ignoreGlobs = [\n\t\t'node_modules/**',\n\t\t'.git/**',\n\t\t'.storybook/**',\n\t\t'**/.cache/**',\n\t\t'**/dist/**',\n\t\t'**/build/**',\n\t]\n\n\tlet pending = false\n\tlet timer: NodeJS.Timeout | null = null\n\tlet isDeletingFile = false\n\n\tfunction kick(reason: string, absPath: string) {\n\t\tif (pending) return\n\t\tpending = true\n\t\tif (timer) clearTimeout(timer)\n\t\ttimer = setTimeout(() => {\n\t\t\tinfo(`${reason}: ${rel(absPath)}`)\n\t\t\tbuildOnce()\n\t\t\tpending = false\n\t\t}, 120)\n\t}\n\n\treturn watcherParcel\n\t\t.subscribe(\n\t\t\troot,\n\t\t\tasync (err, events) => {\n\t\t\t\tif (err) {\n\t\t\t\t\terror(`watch error ${err?.message || err}`)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tfor (const ev of events) {\n\t\t\t\t\tconst abs = ev.path\n\t\t\t\t\tconst relPath = rel(abs)\n\t\t\t\t\tif (!micromatch.isMatch(relPath, includeGlobs)) continue\n\n\t\t\t\t\tif (ev.type === 'delete') {\n\t\t\t\t\t\tconsole.log('Deleted:', relPath)\n\t\t\t\t\t\tisDeletingFile = true\n\t\t\t\t\t\tkick('unlink', abs)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\t// COMPONENT CREATE — scaffold if empty and ensure story\n\t\t\t\t\tif (isComponentsTsx(abs) && ev.type === 'create') {\n\t\t\t\t\t\tawait handleComponentCreation(abs, relPath)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\t// normal rebuild\n\t\t\t\t\tkick(ev.type, abs)\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ ignore: ignoreGlobs },\n\t\t)\n\t\t.then((result) => {\n\t\t\tinfo('watching… (ready)')\n\t\t\treturn result\n\t\t})\n\t\t.catch((e) => error(`watch init failed ${e?.message || e}`))\n\n\tasync function handleComponentCreation(abs: string, relPath: string) {\n\t\tif (isEmptyOrWhitespace(abs)) {\n\t\t\tscaffoldComponent(abs)\n\t\t}\n\n\t\tconsole.log('Component creation detected:', relPath)\n\t\tconst createdStory = ensureStoryForComponent(abs)\n\t\tif (createdStory) {\n\t\t\tkick('create:story', createdStory)\n\t\t}\n\t}\n}\n\n// ───────────────────────────────────────────────────────────────────────────────\n// Storybook child\n// ───────────────────────────────────────────────────────────────────────────────\nlet sbChild: ChildProcess | null = null\nasync function startStorybook() {\n\tconst isWin = process.platform === 'win32'\n\tconst cmd = 'npx'\n\tconst args = ['-y', 'storybook', 'dev', '-p', String(SB_PORT)]\n\n\tinfo(`[sb-deps] launching: ${cmd} ${args.join(' ')}`)\n\n\tsbChild = spawn(cmd, args, {\n\t\tcwd: projectRoot,\n\t\tstdio: 'inherit',\n\t\tshell: isWin, // ← critical to avoid EINVAL on Win + Git Bash\n\t\tenv: process.env,\n\t})\n\n\tsbChild.on('error', (err: any) => {\n\t\terror(`spawn failed: ${err?.message || err}`)\n\t})\n\n\tsbChild.on('exit', (code, sig) => {\n\t\tinfo(`storybook exited (${sig || code})`)\n\t\tsbChild = null\n\t})\n\n\tinfo(`storybook running on http://localhost:${SB_PORT}`)\n}\n\n// ───────────────────────────────────────────────────────────────────────────────\n// Boot\n// ───────────────────────────────────────────────────────────────────────────────\nbanner('sb-deps')\ninfo(`outDir: ${rel(outDir)}`)\ninfo(configPath ? `config: ${rel(configPath)}` : 'config: (none)')\nbuildOnce()\n\nlet watcher: watcherParcel.AsyncSubscription | null = null\nif (WATCH) startWatcher().then((w) => (watcher = w || null))\nif (RUN_SB) startStorybook()\n\nprocess.on('SIGINT', async () => {\n\tinfo('shutting down…')\n\tawait watcher?.unsubscribe()\n\tsbChild?.kill('SIGINT')\n\tprocess.exit(0)\n})\n\n// ───────────────────────────────────────────────────────────────────────────────\n// Utils\n// ───────────────────────────────────────────────────────────────────────────────\nfunction rel(p: string) {\n\t// remove the projectRoot prefix and normalize slashes for logs\n\tconst prefix = resolve(projectRoot) + sep\n\treturn p.replace(prefix, '')\n}\nfunction ms(n: number) {\n\treturn `${Math.max(1, Math.round(n))}ms`\n}\nfunction info(msg: string) {\n\tconsole.log('[sb-deps]', msg)\n}\nfunction error(msg: string) {\n\tconsole.error('[sb-deps]', msg)\n}\nfunction banner(title: string) {\n\tconsole.log(`\\n${title} – dependency previews\\n`)\n}\nfunction wait(time = 500) {\n\treturn new Promise((r) => setTimeout(r, time))\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,MAAM,OAAO,QAAQ,KAAK,MAAM,EAAE;AAClC,MAAM,QAAQ,KAAK,SAAS,UAAU;AACtC,MAAM,SAAS,KAAK,SAAS,kBAAkB;AAC/C,MAAM,YAAY,KAAK,IAAI,KAAK,QAAQ,YAAY,EAAE,EAAE;AACxD,MAAM,UACL,aAAa,KAAK,YAAY,KAC3B,OAAO,KAAK,YAAY,GAAG,IAAI,OAC/B;AAKJ,MAAM,cAAc,QAAQ,KAAK;AACjC,MAAM,gCAAiB,aAAa,aAAa;AACjD,MAAM,8BAAe,QAAQ,+BAA+B;AAC5D,MAAM,iCAAkB,QAAQ,2BAA2B;AAE3D,IAAI,yBAAY,OAAO,CAAE,wBAAU,QAAQ,EAAE,WAAW,MAAM,CAAC;AAE/D,MAAMA,yFAA2C;AACjD,MAAMC,qCAAoBD,aAAW;AAGrC,MAAM,oCAAqBC,aAAW,WAAW,uBAAuB;AACxE,MAAM,qBAAqB;wBAClB,aAAa,uBAAuB;wBACpC,aAAa,yBAAyB;wBACtC,aAAa,0BAA0B;CAC/C;AACD,MAAM,aACL,mBAAmB,MAAM,8BAAiB,EAAE,CAAC,6BACjC,WAAW,GAAG,aAAa;AAGxC,MAAM,8BAAeA,aAAW,WAAW,kBAAkB;AAK7D,SAAS,mBAAmB;CAC3B,MAAM,UAAU,aAAa,aAAa,WAAW,KAAK;CAC1D,MAAM,MAAM,mBAAmB,QAAQ;CACvC,MAAM,QAAQ,KAAK,KAAK;CACxB,MAAM,0CAAkB,KAAK;EAC5B,KAAK;EACL,OAAO;GAAC;GAAU;GAAQ;GAAU;EACpC,UAAU;EACV,CAAC;AACF,4BAAc,SAAS,QAAQ,OAAO;AACtC,MAAK,YAAY,GAAG,KAAK,K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