@takazudo/zudo-sg 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/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +99 -0
- package/bin/zudo-sg.js +6 -0
- package/dist/catalog/component-thumb.d.ts +78 -0
- package/dist/catalog/component-thumb.js +110 -0
- package/dist/catalog/index.d.ts +4 -0
- package/dist/catalog/index.js +40 -0
- package/dist/catalog/tile-size.d.ts +28 -0
- package/dist/catalog/tile-size.js +42 -0
- package/dist/chrome/_styleguide-layout.d.ts +59 -0
- package/dist/chrome/_styleguide-layout.js +69 -0
- package/dist/chrome/index.d.ts +4 -0
- package/dist/chrome/index.js +39 -0
- package/dist/chrome/panel-contract.d.ts +15 -0
- package/dist/chrome/panel-contract.js +65 -0
- package/dist/chrome/panel-scripts-source.d.ts +2 -0
- package/dist/chrome/panel-scripts-source.js +121 -0
- package/dist/chrome/panel-scripts.d.ts +5 -0
- package/dist/chrome/panel-scripts.js +12 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +74 -0
- package/dist/cli/config.d.ts +54 -0
- package/dist/cli/config.js +14 -0
- package/dist/cli/registry/build-registry-source.d.ts +27 -0
- package/dist/cli/registry/build-registry-source.js +77 -0
- package/dist/cli/registry/discover-stories.d.ts +36 -0
- package/dist/cli/registry/discover-stories.js +61 -0
- package/dist/cli/registry/gen-registry.d.ts +23 -0
- package/dist/cli/registry/gen-registry.js +74 -0
- package/dist/cli/scaffold/component-scaffold.d.ts +64 -0
- package/dist/cli/scaffold/component-scaffold.js +233 -0
- package/dist/cli/scaffold/new-component.d.ts +17 -0
- package/dist/cli/scaffold/new-component.js +119 -0
- package/dist/cli/token-manifest/css-var-parser.d.ts +9 -0
- package/dist/cli/token-manifest/css-var-parser.js +23 -0
- package/dist/cli/token-manifest/gen-token-manifest.d.ts +16 -0
- package/dist/cli/token-manifest/gen-token-manifest.js +49 -0
- package/dist/cli/token-manifest/ui-token-manifest.d.ts +78 -0
- package/dist/cli/token-manifest/ui-token-manifest.js +340 -0
- package/dist/code-panel/code-panel.d.ts +18 -0
- package/dist/code-panel/code-panel.js +76 -0
- package/dist/code-panel/copy-button.d.ts +15 -0
- package/dist/code-panel/copy-button.js +92 -0
- package/dist/code-panel/css-injection.d.ts +6 -0
- package/dist/code-panel/css-injection.js +37 -0
- package/dist/code-panel/editor-setup.d.ts +10 -0
- package/dist/code-panel/editor-setup.js +33 -0
- package/dist/code-panel/index.d.ts +6 -0
- package/dist/code-panel/index.js +10 -0
- package/dist/code-panel/source-editor.d.ts +8 -0
- package/dist/code-panel/source-editor.js +39 -0
- package/dist/config/index.d.ts +73 -0
- package/dist/config/index.js +68 -0
- package/dist/host-paths.d.ts +19 -0
- package/dist/host-paths.js +41 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +18 -0
- package/dist/islands.d.ts +2 -0
- package/dist/islands.js +6 -0
- package/dist/plugins/preview-css.d.ts +53 -0
- package/dist/plugins/preview-css.js +183 -0
- package/dist/plugins/routes.d.ts +84 -0
- package/dist/plugins/routes.js +237 -0
- package/dist/plugins/zdtp-apply-proxy.d.ts +58 -0
- package/dist/plugins/zdtp-apply-proxy.js +171 -0
- package/dist/preview/detail-workbench.d.ts +22 -0
- package/dist/preview/detail-workbench.js +179 -0
- package/dist/preview/index.d.ts +8 -0
- package/dist/preview/index.js +21 -0
- package/dist/preview/messages.d.ts +34 -0
- package/dist/preview/messages.js +32 -0
- package/dist/preview/preview-app.d.ts +11 -0
- package/dist/preview/preview-app.js +87 -0
- package/dist/preview/route.d.ts +1 -0
- package/dist/preview/route.js +5 -0
- package/dist/preview/variant-frame.d.ts +42 -0
- package/dist/preview/variant-frame.js +289 -0
- package/dist/preview-css/compile.d.ts +40 -0
- package/dist/preview-css/compile.js +42 -0
- package/dist/preview-css/index.d.ts +2 -0
- package/dist/preview-css/index.js +10 -0
- package/dist/registry/component-docs.d.ts +38 -0
- package/dist/registry/component-docs.js +34 -0
- package/dist/registry/index.d.ts +6 -0
- package/dist/registry/index.js +28 -0
- package/dist/registry/nav-nodes.d.ts +22 -0
- package/dist/registry/nav-nodes.js +36 -0
- package/dist/registry/registry.d.ts +68 -0
- package/dist/registry/registry.js +91 -0
- package/dist/safelist.css +2 -0
- package/dist/search/catalog-filter.d.ts +12 -0
- package/dist/search/catalog-filter.js +175 -0
- package/dist/search/index.d.ts +2 -0
- package/dist/search/index.js +4 -0
- package/dist/sg-context.d.ts +24 -0
- package/dist/sg-context.js +6 -0
- package/dist/sg-routes.d.ts +12 -0
- package/dist/sg-routes.js +17 -0
- package/dist/stories/index.d.ts +2 -0
- package/dist/stories/index.js +4 -0
- package/dist/stories/types.d.ts +164 -0
- package/dist/stories/types.js +6 -0
- package/dist/token-dashboard/create-token-dashboards.d.ts +24 -0
- package/dist/token-dashboard/create-token-dashboards.js +57 -0
- package/dist/token-dashboard/dashboard-inventory.d.ts +11 -0
- package/dist/token-dashboard/dashboard-inventory.js +13 -0
- package/dist/token-dashboard/index.d.ts +5 -0
- package/dist/token-dashboard/index.js +20 -0
- package/dist/token-dashboard/ui-token-tabs.d.ts +53 -0
- package/dist/token-dashboard/ui-token-tabs.js +159 -0
- package/dist/token-tweak/bootstrap-preview-token-panel.d.ts +12 -0
- package/dist/token-tweak/bootstrap-preview-token-panel.js +18 -0
- package/dist/token-tweak/iframe-css-vars-bridge.d.ts +35 -0
- package/dist/token-tweak/iframe-css-vars-bridge.js +73 -0
- package/dist/token-tweak/index.d.ts +6 -0
- package/dist/token-tweak/index.js +36 -0
- package/dist/token-tweak/preview-iframe-registry.d.ts +16 -0
- package/dist/token-tweak/preview-iframe-registry.js +48 -0
- package/dist/token-tweak/preview-token-panel-bootstrap.d.ts +6 -0
- package/dist/token-tweak/preview-token-panel-bootstrap.js +17 -0
- package/dist/token-tweak/preview-token-panel-config.d.ts +42 -0
- package/dist/token-tweak/preview-token-panel-config.js +37 -0
- package/dist/token-tweak/preview-tokens-button.d.ts +5 -0
- package/dist/token-tweak/preview-tokens-button.js +17 -0
- package/dist/token-tweak/token-panel-native-bootstrap.d.ts +17 -0
- package/dist/token-tweak/token-panel-native-bootstrap.js +49 -0
- package/package.json +172 -0
- package/routes-src/_chrome.tsx +83 -0
- package/routes-src/_context.ts +15 -0
- package/routes-src/_preview-app.tsx +32 -0
- package/routes-src/_registry.ts +12 -0
- package/routes-src/components-index.tsx +95 -0
- package/routes-src/components-preview.tsx +55 -0
- package/routes-src/components-slug.tsx +145 -0
- package/routes-src/tokens.tsx +76 -0
- package/styles.css +612 -0
- package/virtual-modules.d.ts +25 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const ATTR_CODE_PANEL_HIDDEN = "data-sg-code-panel-hidden";
|
|
2
|
+
const LS_CODE_PANEL_HIDDEN = "sg-code-panel-hidden";
|
|
3
|
+
const LS_SIDEBAR_WIDTH = "zudo-doc-sidebar-width";
|
|
4
|
+
const LS_CODE_PANEL_WIDTH = "sg-code-panel-width";
|
|
5
|
+
const CSS_VAR_SIDEBAR_W = "--zd-sidebar-w";
|
|
6
|
+
const CSS_VAR_CODE_PANEL_W = "--sg-code-panel-w";
|
|
7
|
+
const MIN_CODE_PANEL_W = 280;
|
|
8
|
+
const ID_CODE_PANEL = "sg-code-panel";
|
|
9
|
+
const ATTR_CODE_PANEL_RESIZER = "data-sg-code-panel-resizer";
|
|
10
|
+
import { AFTER_NAVIGATE_EVENT } from "@takazudo/zudo-doc/transitions";
|
|
11
|
+
function root(el) {
|
|
12
|
+
return el ?? document.documentElement;
|
|
13
|
+
}
|
|
14
|
+
function isCodePanelHidden(el) {
|
|
15
|
+
return root(el).hasAttribute(ATTR_CODE_PANEL_HIDDEN);
|
|
16
|
+
}
|
|
17
|
+
function setHidden(attr, lsKey, hidden, el) {
|
|
18
|
+
const r = root(el);
|
|
19
|
+
if (hidden) r.setAttribute(attr, "");
|
|
20
|
+
else r.removeAttribute(attr);
|
|
21
|
+
try {
|
|
22
|
+
localStorage.setItem(lsKey, hidden ? "1" : "0");
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function setCodePanelHidden(hidden, el) {
|
|
27
|
+
setHidden(ATTR_CODE_PANEL_HIDDEN, LS_CODE_PANEL_HIDDEN, hidden, el);
|
|
28
|
+
}
|
|
29
|
+
function toggleCodePanel(el) {
|
|
30
|
+
setCodePanelHidden(!isCodePanelHidden(el), el);
|
|
31
|
+
}
|
|
32
|
+
function setPanelWidth(cssVar, lsKey, px, el) {
|
|
33
|
+
root(el).style.setProperty(cssVar, `${px}px`);
|
|
34
|
+
try {
|
|
35
|
+
localStorage.setItem(lsKey, String(Math.round(px)));
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function getPersistedWidth(lsKey) {
|
|
40
|
+
try {
|
|
41
|
+
const raw = localStorage.getItem(lsKey);
|
|
42
|
+
if (!raw) return void 0;
|
|
43
|
+
const n = Number(raw);
|
|
44
|
+
return Number.isFinite(n) ? n : void 0;
|
|
45
|
+
} catch {
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
AFTER_NAVIGATE_EVENT as AFTER_SWAP_EVENT,
|
|
51
|
+
ATTR_CODE_PANEL_HIDDEN,
|
|
52
|
+
ATTR_CODE_PANEL_RESIZER,
|
|
53
|
+
CSS_VAR_CODE_PANEL_W,
|
|
54
|
+
CSS_VAR_SIDEBAR_W,
|
|
55
|
+
ID_CODE_PANEL,
|
|
56
|
+
LS_CODE_PANEL_HIDDEN,
|
|
57
|
+
LS_CODE_PANEL_WIDTH,
|
|
58
|
+
LS_SIDEBAR_WIDTH,
|
|
59
|
+
MIN_CODE_PANEL_W,
|
|
60
|
+
getPersistedWidth,
|
|
61
|
+
isCodePanelHidden,
|
|
62
|
+
setCodePanelHidden,
|
|
63
|
+
setPanelWidth,
|
|
64
|
+
toggleCodePanel
|
|
65
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const RESTORE_SCRIPT = "(function(){\n function restore(){try{\n var r=document.documentElement, ls=localStorage;\n var cw=ls.getItem('sg-code-panel-width'); if(cw) r.style.setProperty('--sg-code-panel-w', cw+'px');\n if(ls.getItem('sg-code-panel-hidden')==='1') r.setAttribute('data-sg-code-panel-hidden',''); else r.removeAttribute('data-sg-code-panel-hidden');\n }catch(e){}}\n restore();\n})();";
|
|
2
|
+
export declare const RESIZER_SCRIPT = "(function(){\n var MIN_CP=280;\n var STEP=16;\n var ACCENT_OUTLINE='2px solid var(--zd-accent,rgba(128,128,128,0.5))';\n function maxCP(){ return Math.floor(window.innerWidth*0.6); }\n function clamp(v){ return Math.max(MIN_CP, Math.min(v, maxCP())); }\n function persist(val){ try{ localStorage.setItem('sg-code-panel-width', String(Math.round(val))); }catch(e){} }\n function attach(handle){\n var r=document.documentElement;\n var dragging=false, focused=false;\n function readCurrentWidth(){\n // Measure the real panel element \u2014 always px, unit-agnostic. The CSS var\n // default is authored as a rem-based clamp (--sg-code-panel-w:\n // clamp(18rem,26vw,26rem)) and getComputedStyle returns custom-property\n // text UNRESOLVED, so parseFloat on the var would yield a bogus leading\n // number, not pixels, collapsing the panel on first keyboard use. Fall\n // back to a rem-aware parse only if the element is absent.\n var panel=document.getElementById('sg-code-panel');\n var w=panel ? panel.getBoundingClientRect().width : 0;\n if(w) return w;\n var raw=getComputedStyle(r).getPropertyValue('--sg-code-panel-w').trim();\n var n=parseFloat(raw);\n if(!n) return MIN_CP;\n return raw.indexOf('rem')>=0 ? n*parseFloat(getComputedStyle(r).fontSize) : n;\n }\n var cachedWidth=readCurrentWidth();\n handle.setAttribute('aria-valuemin', String(MIN_CP));\n handle.setAttribute('aria-valuemax', String(maxCP()));\n handle.setAttribute('aria-valuenow', String(Math.round(cachedWidth)));\n function applyWidth(w){\n cachedWidth=clamp(w);\n r.style.setProperty('--sg-code-panel-w', cachedWidth+'px');\n persist(cachedWidth);\n handle.setAttribute('aria-valuenow', String(Math.round(cachedWidth)));\n }\n function updateVisual(){\n handle.style.outline=(focused&&!dragging) ? ACCENT_OUTLINE : '';\n handle.style.outlineOffset=(focused&&!dragging) ? '-2px' : '';\n }\n handle.addEventListener('focus', function(){ focused=true; updateVisual(); });\n handle.addEventListener('blur', function(){ focused=false; updateVisual(); });\n handle.addEventListener('keydown', function(e){\n var w=cachedWidth;\n if(e.key==='ArrowLeft') w=Math.max(MIN_CP, w-STEP);\n else if(e.key==='ArrowRight') w=Math.min(maxCP(), w+STEP);\n else if(e.key==='Home') w=MIN_CP;\n else if(e.key==='End') w=maxCP();\n else return;\n e.preventDefault();\n applyWidth(w);\n });\n handle.addEventListener('pointerdown', function(e){\n e.preventDefault();\n handle.setAttribute('data-sg-dragging','');\n handle.setPointerCapture(e.pointerId);\n dragging=true; updateVisual();\n function onMove(ev){\n applyWidth(window.innerWidth-ev.clientX);\n }\n function onUp(){\n handle.removeAttribute('data-sg-dragging');\n dragging=false; updateVisual();\n handle.removeEventListener('pointermove', onMove);\n handle.removeEventListener('pointerup', onUp);\n handle.removeEventListener('pointercancel', onCancel);\n handle.removeEventListener('lostpointercapture', onLost);\n }\n function onCancel(){\n handle.removeAttribute('data-sg-dragging');\n dragging=false; updateVisual();\n handle.removeEventListener('pointermove', onMove);\n handle.removeEventListener('pointerup', onUp);\n handle.removeEventListener('pointercancel', onCancel);\n handle.removeEventListener('lostpointercapture', onLost);\n }\n function onLost(){ onUp(); }\n handle.addEventListener('pointermove', onMove);\n handle.addEventListener('pointerup', onUp);\n handle.addEventListener('pointercancel', onCancel);\n handle.addEventListener('lostpointercapture', onLost);\n });\n }\n function init(){\n document.querySelectorAll('[data-sg-code-panel-resizer]').forEach(function(h){\n if(h.__sgWired) return; h.__sgWired=true; attach(h);\n });\n }\n init();\n // The client router swaps the whole body, so a detail -> detail navigation\n // hands us a brand-new, unwired handle. Re-run init on every swap; the\n // per-element __sgWired flag makes that idempotent. The window flag guards\n // only the LISTENER registration (this script may itself be re-executed by\n // the swap) \u2014 it must NOT gate init(), which is what left the new handle\n // inert before #541.\n if(!window.__sgResizersInstalled){\n window.__sgResizersInstalled=true;\n document.addEventListener('zfb:after-swap', init);\n }\n})();";
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AFTER_SWAP_EVENT,
|
|
3
|
+
ATTR_CODE_PANEL_HIDDEN,
|
|
4
|
+
ATTR_CODE_PANEL_RESIZER,
|
|
5
|
+
CSS_VAR_CODE_PANEL_W,
|
|
6
|
+
ID_CODE_PANEL,
|
|
7
|
+
LS_CODE_PANEL_HIDDEN,
|
|
8
|
+
LS_CODE_PANEL_WIDTH,
|
|
9
|
+
MIN_CODE_PANEL_W
|
|
10
|
+
} from "./panel-contract";
|
|
11
|
+
const RESTORE_SCRIPT = `(function(){
|
|
12
|
+
function restore(){try{
|
|
13
|
+
var r=document.documentElement, ls=localStorage;
|
|
14
|
+
var cw=ls.getItem('${LS_CODE_PANEL_WIDTH}'); if(cw) r.style.setProperty('${CSS_VAR_CODE_PANEL_W}', cw+'px');
|
|
15
|
+
if(ls.getItem('${LS_CODE_PANEL_HIDDEN}')==='1') r.setAttribute('${ATTR_CODE_PANEL_HIDDEN}',''); else r.removeAttribute('${ATTR_CODE_PANEL_HIDDEN}');
|
|
16
|
+
}catch(e){}}
|
|
17
|
+
restore();
|
|
18
|
+
})();`;
|
|
19
|
+
const RESIZER_SCRIPT = `(function(){
|
|
20
|
+
var MIN_CP=${MIN_CODE_PANEL_W};
|
|
21
|
+
var STEP=16;
|
|
22
|
+
var ACCENT_OUTLINE='2px solid var(--zd-accent,rgba(128,128,128,0.5))';
|
|
23
|
+
function maxCP(){ return Math.floor(window.innerWidth*0.6); }
|
|
24
|
+
function clamp(v){ return Math.max(MIN_CP, Math.min(v, maxCP())); }
|
|
25
|
+
function persist(val){ try{ localStorage.setItem('${LS_CODE_PANEL_WIDTH}', String(Math.round(val))); }catch(e){} }
|
|
26
|
+
function attach(handle){
|
|
27
|
+
var r=document.documentElement;
|
|
28
|
+
var dragging=false, focused=false;
|
|
29
|
+
function readCurrentWidth(){
|
|
30
|
+
// Measure the real panel element \u2014 always px, unit-agnostic. The CSS var
|
|
31
|
+
// default is authored as a rem-based clamp (--sg-code-panel-w:
|
|
32
|
+
// clamp(18rem,26vw,26rem)) and getComputedStyle returns custom-property
|
|
33
|
+
// text UNRESOLVED, so parseFloat on the var would yield a bogus leading
|
|
34
|
+
// number, not pixels, collapsing the panel on first keyboard use. Fall
|
|
35
|
+
// back to a rem-aware parse only if the element is absent.
|
|
36
|
+
var panel=document.getElementById('${ID_CODE_PANEL}');
|
|
37
|
+
var w=panel ? panel.getBoundingClientRect().width : 0;
|
|
38
|
+
if(w) return w;
|
|
39
|
+
var raw=getComputedStyle(r).getPropertyValue('${CSS_VAR_CODE_PANEL_W}').trim();
|
|
40
|
+
var n=parseFloat(raw);
|
|
41
|
+
if(!n) return MIN_CP;
|
|
42
|
+
return raw.indexOf('rem')>=0 ? n*parseFloat(getComputedStyle(r).fontSize) : n;
|
|
43
|
+
}
|
|
44
|
+
var cachedWidth=readCurrentWidth();
|
|
45
|
+
handle.setAttribute('aria-valuemin', String(MIN_CP));
|
|
46
|
+
handle.setAttribute('aria-valuemax', String(maxCP()));
|
|
47
|
+
handle.setAttribute('aria-valuenow', String(Math.round(cachedWidth)));
|
|
48
|
+
function applyWidth(w){
|
|
49
|
+
cachedWidth=clamp(w);
|
|
50
|
+
r.style.setProperty('${CSS_VAR_CODE_PANEL_W}', cachedWidth+'px');
|
|
51
|
+
persist(cachedWidth);
|
|
52
|
+
handle.setAttribute('aria-valuenow', String(Math.round(cachedWidth)));
|
|
53
|
+
}
|
|
54
|
+
function updateVisual(){
|
|
55
|
+
handle.style.outline=(focused&&!dragging) ? ACCENT_OUTLINE : '';
|
|
56
|
+
handle.style.outlineOffset=(focused&&!dragging) ? '-2px' : '';
|
|
57
|
+
}
|
|
58
|
+
handle.addEventListener('focus', function(){ focused=true; updateVisual(); });
|
|
59
|
+
handle.addEventListener('blur', function(){ focused=false; updateVisual(); });
|
|
60
|
+
handle.addEventListener('keydown', function(e){
|
|
61
|
+
var w=cachedWidth;
|
|
62
|
+
if(e.key==='ArrowLeft') w=Math.max(MIN_CP, w-STEP);
|
|
63
|
+
else if(e.key==='ArrowRight') w=Math.min(maxCP(), w+STEP);
|
|
64
|
+
else if(e.key==='Home') w=MIN_CP;
|
|
65
|
+
else if(e.key==='End') w=maxCP();
|
|
66
|
+
else return;
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
applyWidth(w);
|
|
69
|
+
});
|
|
70
|
+
handle.addEventListener('pointerdown', function(e){
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
handle.setAttribute('data-sg-dragging','');
|
|
73
|
+
handle.setPointerCapture(e.pointerId);
|
|
74
|
+
dragging=true; updateVisual();
|
|
75
|
+
function onMove(ev){
|
|
76
|
+
applyWidth(window.innerWidth-ev.clientX);
|
|
77
|
+
}
|
|
78
|
+
function onUp(){
|
|
79
|
+
handle.removeAttribute('data-sg-dragging');
|
|
80
|
+
dragging=false; updateVisual();
|
|
81
|
+
handle.removeEventListener('pointermove', onMove);
|
|
82
|
+
handle.removeEventListener('pointerup', onUp);
|
|
83
|
+
handle.removeEventListener('pointercancel', onCancel);
|
|
84
|
+
handle.removeEventListener('lostpointercapture', onLost);
|
|
85
|
+
}
|
|
86
|
+
function onCancel(){
|
|
87
|
+
handle.removeAttribute('data-sg-dragging');
|
|
88
|
+
dragging=false; updateVisual();
|
|
89
|
+
handle.removeEventListener('pointermove', onMove);
|
|
90
|
+
handle.removeEventListener('pointerup', onUp);
|
|
91
|
+
handle.removeEventListener('pointercancel', onCancel);
|
|
92
|
+
handle.removeEventListener('lostpointercapture', onLost);
|
|
93
|
+
}
|
|
94
|
+
function onLost(){ onUp(); }
|
|
95
|
+
handle.addEventListener('pointermove', onMove);
|
|
96
|
+
handle.addEventListener('pointerup', onUp);
|
|
97
|
+
handle.addEventListener('pointercancel', onCancel);
|
|
98
|
+
handle.addEventListener('lostpointercapture', onLost);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function init(){
|
|
102
|
+
document.querySelectorAll('[${ATTR_CODE_PANEL_RESIZER}]').forEach(function(h){
|
|
103
|
+
if(h.__sgWired) return; h.__sgWired=true; attach(h);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
init();
|
|
107
|
+
// The client router swaps the whole body, so a detail -> detail navigation
|
|
108
|
+
// hands us a brand-new, unwired handle. Re-run init on every swap; the
|
|
109
|
+
// per-element __sgWired flag makes that idempotent. The window flag guards
|
|
110
|
+
// only the LISTENER registration (this script may itself be re-executed by
|
|
111
|
+
// the swap) \u2014 it must NOT gate init(), which is what left the new handle
|
|
112
|
+
// inert before #541.
|
|
113
|
+
if(!window.__sgResizersInstalled){
|
|
114
|
+
window.__sgResizersInstalled=true;
|
|
115
|
+
document.addEventListener('${AFTER_SWAP_EVENT}', init);
|
|
116
|
+
}
|
|
117
|
+
})();`;
|
|
118
|
+
export {
|
|
119
|
+
RESIZER_SCRIPT,
|
|
120
|
+
RESTORE_SCRIPT
|
|
121
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx } from "preact/jsx-runtime";
|
|
2
|
+
import { RESIZER_SCRIPT, RESTORE_SCRIPT } from "./panel-scripts-source";
|
|
3
|
+
function PanelStateHeadScript() {
|
|
4
|
+
return /* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: RESTORE_SCRIPT } });
|
|
5
|
+
}
|
|
6
|
+
function PanelResizersInitScript() {
|
|
7
|
+
return /* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: RESIZER_SCRIPT } });
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
PanelResizersInitScript,
|
|
11
|
+
PanelStateHeadScript
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runZudoSgCli(argv: string[], projectRoot?: string): Promise<number>;
|
package/dist/cli/bin.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { loadZudoSgConfig } from "./config.js";
|
|
2
|
+
import { SgRegistryDriftError, runGenRegistry } from "./registry/gen-registry.js";
|
|
3
|
+
import { parseArgs, runNewComponent } from "./scaffold/new-component.js";
|
|
4
|
+
import { runGenTokenManifest, TokenManifestDriftError, TokensConfigMissingError } from "./token-manifest/gen-token-manifest.js";
|
|
5
|
+
const USAGE = `Usage: zudo-sg <command> [options]
|
|
6
|
+
|
|
7
|
+
Commands:
|
|
8
|
+
gen-registry [--check]
|
|
9
|
+
new-component <name> --category <c> [--nested] [--skip-barrel]
|
|
10
|
+
gen-token-manifest [--check]
|
|
11
|
+
`;
|
|
12
|
+
async function runZudoSgCli(argv, projectRoot = process.cwd()) {
|
|
13
|
+
const [command, ...rest] = argv;
|
|
14
|
+
if (!command) {
|
|
15
|
+
console.error(USAGE);
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
switch (command) {
|
|
19
|
+
case "gen-registry": {
|
|
20
|
+
const check = rest.includes("--check");
|
|
21
|
+
const config = await loadZudoSgConfig(projectRoot);
|
|
22
|
+
try {
|
|
23
|
+
const result = runGenRegistry(projectRoot, config, { check });
|
|
24
|
+
if (check) {
|
|
25
|
+
console.log(`OK \u2014 sg-registry is up to date (${result.entryCount} stories).`);
|
|
26
|
+
} else if (result.changed.length === 0) {
|
|
27
|
+
console.log(`sg-registry already up to date (${result.entryCount} stories); no change.`);
|
|
28
|
+
} else {
|
|
29
|
+
for (const path of result.changed) console.log(`Wrote generated block to ${path}.`);
|
|
30
|
+
}
|
|
31
|
+
return 0;
|
|
32
|
+
} catch (err) {
|
|
33
|
+
if (err instanceof SgRegistryDriftError) {
|
|
34
|
+
console.error(err.message);
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
case "new-component": {
|
|
41
|
+
const config = await loadZudoSgConfig(projectRoot);
|
|
42
|
+
return runNewComponent(projectRoot, config, parseArgs(rest));
|
|
43
|
+
}
|
|
44
|
+
case "gen-token-manifest": {
|
|
45
|
+
const check = rest.includes("--check");
|
|
46
|
+
const config = await loadZudoSgConfig(projectRoot);
|
|
47
|
+
try {
|
|
48
|
+
const result = runGenTokenManifest(projectRoot, config, { check });
|
|
49
|
+
if (check) {
|
|
50
|
+
console.log(`OK \u2014 token manifest is up to date (${result.tokenCount} entries).`);
|
|
51
|
+
} else if (!result.changed) {
|
|
52
|
+
console.log(`Token manifest already up to date (${result.tokenCount} entries); no change.`);
|
|
53
|
+
} else {
|
|
54
|
+
console.log(`Wrote ${result.manifestOut} (${result.tokenCount} entries).`);
|
|
55
|
+
}
|
|
56
|
+
return 0;
|
|
57
|
+
} catch (err) {
|
|
58
|
+
if (err instanceof TokenManifestDriftError || err instanceof TokensConfigMissingError) {
|
|
59
|
+
console.error(err.message);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
default:
|
|
66
|
+
console.error(`zudo-sg: unknown command "${command}"
|
|
67
|
+
|
|
68
|
+
${USAGE}`);
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
runZudoSgCli
|
|
74
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** One corpus of `*.stories.tsx` files the registry codegen discovers. */
|
|
2
|
+
export interface ZudoSgComponentsRoot {
|
|
3
|
+
/** Project-root-relative directory to scan, e.g. "packages/demo-ui/src". */
|
|
4
|
+
dir: string;
|
|
5
|
+
/** Package-scoped import specifier prefix for files under `dir`, e.g. "@zudo-sg/demo-ui/src". */
|
|
6
|
+
importBase: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ZudoSgTokensConfig {
|
|
9
|
+
/**
|
|
10
|
+
* `[tokensCssPath, colorsCssPath]` — project-root-relative. Position is
|
|
11
|
+
* significant: index 0 feeds spacing/font/size tokens, index 1 feeds the
|
|
12
|
+
* palette + semantic color tokens (see token-manifest/ui-token-manifest.ts).
|
|
13
|
+
*/
|
|
14
|
+
cssFiles: [string, string];
|
|
15
|
+
/** Project-root-relative output path for the generated manifest. */
|
|
16
|
+
manifestOut: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ZudoSgConfig {
|
|
19
|
+
componentsRoots: ZudoSgComponentsRoot[];
|
|
20
|
+
/** Project-root-relative output path for the generated story registry. */
|
|
21
|
+
registryOut: string;
|
|
22
|
+
/**
|
|
23
|
+
* Category display order. Categories not listed here are still valid —
|
|
24
|
+
* they sort in alphabetically after these (see registry/registry.ts's
|
|
25
|
+
* `computeCategoryOrder`).
|
|
26
|
+
*/
|
|
27
|
+
categoryOrder: string[];
|
|
28
|
+
/** npm package name components/stories are imported from in generated usage snippets. */
|
|
29
|
+
uiPackageName: string;
|
|
30
|
+
/**
|
|
31
|
+
* Project-root-relative path to the barrel file `new-component` inserts an
|
|
32
|
+
* export into, or `null` for a project with no barrel-file convention.
|
|
33
|
+
*/
|
|
34
|
+
barrelIndex: string | null;
|
|
35
|
+
/**
|
|
36
|
+
* Design-token manifest inputs for `gen-token-manifest` and the `/tokens`
|
|
37
|
+
* dashboards. Omitted → `gen-token-manifest` exits with an error and the
|
|
38
|
+
* `/tokens` route renders an empty state.
|
|
39
|
+
*/
|
|
40
|
+
tokens?: ZudoSgTokensConfig;
|
|
41
|
+
/** Project-root-relative path to the host's preview stylesheet entry. */
|
|
42
|
+
previewStyles: string;
|
|
43
|
+
previewCssUrl?: string;
|
|
44
|
+
routes?: Record<string, string>;
|
|
45
|
+
catalog?: {
|
|
46
|
+
title?: string;
|
|
47
|
+
intro?: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Loads and returns the host's `zudo-sg.config.mjs` default export.
|
|
52
|
+
* `configFile` is project-root-relative (defaults to `zudo-sg.config.mjs`).
|
|
53
|
+
*/
|
|
54
|
+
export declare function loadZudoSgConfig(projectRoot: string, configFile?: string): Promise<ZudoSgConfig>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
const DEFAULT_CONFIG_FILE = "zudo-sg.config.mjs";
|
|
4
|
+
async function loadZudoSgConfig(projectRoot, configFile = DEFAULT_CONFIG_FILE) {
|
|
5
|
+
const abs = resolve(projectRoot, configFile);
|
|
6
|
+
const mod = await import(pathToFileURL(abs).href);
|
|
7
|
+
if (!mod.default) {
|
|
8
|
+
throw new Error(`[zudo-sg] ${configFile} must have a default export (see ZudoSgConfig).`);
|
|
9
|
+
}
|
|
10
|
+
return mod.default;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
loadZudoSgConfig
|
|
14
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DiscoveredStory } from "./discover-stories.js";
|
|
2
|
+
export declare const BEGIN_MARKER = "GENERATED:SG_REGISTRY_BEGIN";
|
|
3
|
+
export declare const END_MARKER = "GENERATED:SG_REGISTRY_END";
|
|
4
|
+
/** A discovered story tagged with the components root it came from. */
|
|
5
|
+
export interface RegistryEntry extends DiscoveredStory {
|
|
6
|
+
/** `${importBase}/${relDirStem}.stories.tsx` — the package-scoped import specifier. */
|
|
7
|
+
importSpecifier: string;
|
|
8
|
+
/** `${keyPrefix}/${relDirStem}.stories.tsx` — the `storyModules` map key. */
|
|
9
|
+
mapKey: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Build the generated block for the registry output file: the
|
|
13
|
+
* `StoryModule` import, one `import * as <name>` per story, and the
|
|
14
|
+
* `storyModules` + `storyExportOrder` maps.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildRegistryBlock(entries: RegistryEntry[], uiPackageName: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Build the generated block for a components root's secondary
|
|
19
|
+
* `story-modules.ts` fixture: one `import * as <name>` per story (relative,
|
|
20
|
+
* extensionless) and the exported `STORY_MODULES` map.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildStoryModulesBlock(entries: DiscoveredStory[], relativeImportPrefix: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Replace the existing BEGIN…END block in `content` with `block`. Throws if
|
|
25
|
+
* the markers are missing (each block must be seeded once by hand).
|
|
26
|
+
*/
|
|
27
|
+
export declare function replaceBlock(content: string, block: string, filePath: string): string;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const BEGIN_MARKER = "GENERATED:SG_REGISTRY_BEGIN";
|
|
2
|
+
const END_MARKER = "GENERATED:SG_REGISTRY_END";
|
|
3
|
+
function buildRegistryBlock(entries, uiPackageName) {
|
|
4
|
+
const lines = [];
|
|
5
|
+
lines.push(`// ${BEGIN_MARKER} \u2014 do not hand-edit; run \`pnpm gen:sg-registry\`.`);
|
|
6
|
+
lines.push(`import type { StoryModule } from "${uiPackageName}";`);
|
|
7
|
+
lines.push(``);
|
|
8
|
+
for (const e of entries) {
|
|
9
|
+
lines.push(`import * as ${e.importName} from "${e.importSpecifier}";`);
|
|
10
|
+
}
|
|
11
|
+
lines.push(``);
|
|
12
|
+
lines.push(`/**`);
|
|
13
|
+
lines.push(` * Path \u2192 story module map. Keys are glob-relative (e.g.`);
|
|
14
|
+
lines.push(` * \`./ui/src/button/button.stories.tsx\`). Each module is`);
|
|
15
|
+
lines.push(` * \`{ default: meta, ...named Story exports }\`.`);
|
|
16
|
+
lines.push(` */`);
|
|
17
|
+
lines.push(`export const storyModules: Record<string, StoryModule> = {`);
|
|
18
|
+
for (const e of entries) {
|
|
19
|
+
lines.push(` "${e.mapKey}": ${e.importName} as unknown as StoryModule,`);
|
|
20
|
+
}
|
|
21
|
+
lines.push(`};`);
|
|
22
|
+
lines.push(``);
|
|
23
|
+
lines.push(`/**`);
|
|
24
|
+
lines.push(` * Per-story named-export declaration order (SOURCE order), keyed by the`);
|
|
25
|
+
lines.push(` * same path as \`storyModules\`. registry.ts sorts each story's variants`);
|
|
26
|
+
lines.push(` * by this so tabs render in authored order (and the default tab is the`);
|
|
27
|
+
lines.push(` * first-authored story) instead of the alphabetical key-enumeration order`);
|
|
28
|
+
lines.push(` * of the \`import * as\` namespace. Captured at codegen time because the`);
|
|
29
|
+
lines.push(` * runtime namespace cannot recover source order (#128 / #174). Superset:`);
|
|
30
|
+
lines.push(` * lists every \`export const\`, so registry.ts uses it only to SORT the`);
|
|
31
|
+
lines.push(` * \`isStory()\`-filtered variants, never to gate membership.`);
|
|
32
|
+
lines.push(` */`);
|
|
33
|
+
lines.push(`export const storyExportOrder: Record<string, string[]> = {`);
|
|
34
|
+
for (const e of entries) {
|
|
35
|
+
const arr = e.exportOrder.map((n) => JSON.stringify(n)).join(", ");
|
|
36
|
+
lines.push(` "${e.mapKey}": [${arr}],`);
|
|
37
|
+
}
|
|
38
|
+
lines.push(`};`);
|
|
39
|
+
lines.push(`// ${END_MARKER}`);
|
|
40
|
+
return lines.join("\n");
|
|
41
|
+
}
|
|
42
|
+
function buildStoryModulesBlock(entries, relativeImportPrefix) {
|
|
43
|
+
const lines = [];
|
|
44
|
+
lines.push(`// ${BEGIN_MARKER} \u2014 do not hand-edit; run \`pnpm gen:sg-registry\`.`);
|
|
45
|
+
for (const e of entries) {
|
|
46
|
+
lines.push(`import * as ${e.importName} from "${relativeImportPrefix}/${e.relDirStem}.stories";`);
|
|
47
|
+
}
|
|
48
|
+
lines.push(``);
|
|
49
|
+
lines.push(`export const STORY_MODULES: Record<string, StoryModule> = {`);
|
|
50
|
+
for (const e of entries) {
|
|
51
|
+
lines.push(` "${e.relDirStem}.stories.tsx": ${e.importName} as unknown as StoryModule,`);
|
|
52
|
+
}
|
|
53
|
+
lines.push(`};`);
|
|
54
|
+
lines.push(`// ${END_MARKER}`);
|
|
55
|
+
return lines.join("\n");
|
|
56
|
+
}
|
|
57
|
+
function replaceBlock(content, block, filePath) {
|
|
58
|
+
const beginIdx = content.indexOf(BEGIN_MARKER);
|
|
59
|
+
const endIdx = content.indexOf(END_MARKER);
|
|
60
|
+
if (beginIdx === -1 || endIdx === -1) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Could not find ${BEGIN_MARKER} \u2026 ${END_MARKER} markers in ${filePath}.
|
|
63
|
+
Seed the marker block once by hand, then re-run the generator.`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
const lineStart = content.lastIndexOf("\n", beginIdx) + 1;
|
|
67
|
+
const afterEnd = content.indexOf("\n", endIdx);
|
|
68
|
+
const lineEnd = afterEnd === -1 ? content.length : afterEnd;
|
|
69
|
+
return content.slice(0, lineStart) + block + content.slice(lineEnd);
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
BEGIN_MARKER,
|
|
73
|
+
END_MARKER,
|
|
74
|
+
buildRegistryBlock,
|
|
75
|
+
buildStoryModulesBlock,
|
|
76
|
+
replaceBlock
|
|
77
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface DiscoveredStory {
|
|
2
|
+
/** Path stem relative to the components root, e.g. "badge/badge" or "layout/badge-icon/badge-icon". */
|
|
3
|
+
relDirStem: string;
|
|
4
|
+
/** `import * as <name>` identifier derived from the containing directory path. */
|
|
5
|
+
importName: string;
|
|
6
|
+
/** Named-export declaration order of the story file, in source order. */
|
|
7
|
+
exportOrder: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Derive the `import * as <name>` identifier from a story's containing
|
|
11
|
+
* directory path (relative to the components root) — never from the file
|
|
12
|
+
* stem alone. A 1-segment `relDir` (old flat layout) is byte-identical to
|
|
13
|
+
* the previous `camelCase(stem)` derivation; a multi-segment `relDir`
|
|
14
|
+
* (category-nested layout) folds the whole path into one identifier, so two
|
|
15
|
+
* categories scaffolding a same-named component get distinct identifiers.
|
|
16
|
+
*/
|
|
17
|
+
export declare function dirPathToImportName(relDir: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Named-export declaration order of a `*.stories.tsx` body, in source order.
|
|
20
|
+
* Only `export const <Name>` lines count — the runtime cannot recover this
|
|
21
|
+
* order from an ES-module namespace (alphabetical per spec), so it's
|
|
22
|
+
* captured here at discovery time.
|
|
23
|
+
*/
|
|
24
|
+
export declare function scanExportOrder(body: string): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Throws if two entries derive the same `importName` — a duplicate
|
|
27
|
+
* `import * as X` is a syntax error; this surfaces it as a clear
|
|
28
|
+
* discovery-time message naming the two colliding directories.
|
|
29
|
+
*/
|
|
30
|
+
export declare function assertUniqueImportNames(entries: DiscoveredStory[]): void;
|
|
31
|
+
/**
|
|
32
|
+
* Glob `<absRoot>/**\/*.stories.tsx` off the filesystem (any depth) and
|
|
33
|
+
* derive each entry's `relDirStem`, `importName`, and `exportOrder`.
|
|
34
|
+
* Returns entries sorted alphabetically by `relDirStem`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function discoverStories(absRoot: string): DiscoveredStory[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
const STORIES_SUFFIX = ".stories.tsx";
|
|
4
|
+
function walkStoryFiles(absRoot, relDir) {
|
|
5
|
+
const absDir = relDir ? resolve(absRoot, relDir) : absRoot;
|
|
6
|
+
const dirEntries = readdirSync(absDir, { withFileTypes: true });
|
|
7
|
+
const files = dirEntries.filter((d) => d.isFile() && d.name.endsWith(STORIES_SUFFIX)).map((d) => d.name).sort();
|
|
8
|
+
const subdirs = dirEntries.filter((d) => d.isDirectory() && !d.name.startsWith(".") && !d.name.startsWith("_")).map((d) => d.name).sort();
|
|
9
|
+
const results = files.map((file) => ({ relDir, file }));
|
|
10
|
+
for (const sub of subdirs) {
|
|
11
|
+
const nested = relDir ? `${relDir}/${sub}` : sub;
|
|
12
|
+
results.push(...walkStoryFiles(absRoot, nested));
|
|
13
|
+
}
|
|
14
|
+
return results;
|
|
15
|
+
}
|
|
16
|
+
function camelCase(kebab) {
|
|
17
|
+
return kebab.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
18
|
+
}
|
|
19
|
+
function dirPathToImportName(relDir) {
|
|
20
|
+
return camelCase(relDir.split("/").join("-"));
|
|
21
|
+
}
|
|
22
|
+
function scanExportOrder(body) {
|
|
23
|
+
return [...body.matchAll(/^export const (\w+)/gm)].map((m) => m[1]);
|
|
24
|
+
}
|
|
25
|
+
function assertUniqueImportNames(entries) {
|
|
26
|
+
const seen = /* @__PURE__ */ new Map();
|
|
27
|
+
for (const entry of entries) {
|
|
28
|
+
const prior = seen.get(entry.importName);
|
|
29
|
+
if (prior !== void 0) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`gen-registry: "${prior}" and "${entry.relDirStem}" both derive the import identifier "${entry.importName}" \u2014 rename one of the component directories so their derived identifiers don't collide.`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
seen.set(entry.importName, entry.relDirStem);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function discoverStories(absRoot) {
|
|
38
|
+
const found = walkStoryFiles(absRoot, "");
|
|
39
|
+
const entries = found.map(({ relDir, file }) => {
|
|
40
|
+
const stem = file.slice(0, -STORIES_SUFFIX.length);
|
|
41
|
+
const body = readFileSync(resolve(absRoot, relDir, file), "utf8");
|
|
42
|
+
return {
|
|
43
|
+
relDirStem: relDir ? `${relDir}/${stem}` : stem,
|
|
44
|
+
// A story directly under the root has no containing dir; fall back to its stem.
|
|
45
|
+
importName: dirPathToImportName(relDir || stem),
|
|
46
|
+
exportOrder: scanExportOrder(body)
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
if (entries.length === 0) {
|
|
50
|
+
throw new Error(`No *${STORIES_SUFFIX} files found under ${absRoot}`);
|
|
51
|
+
}
|
|
52
|
+
entries.sort((a, b) => a.relDirStem.localeCompare(b.relDirStem));
|
|
53
|
+
assertUniqueImportNames(entries);
|
|
54
|
+
return entries;
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
assertUniqueImportNames,
|
|
58
|
+
dirPathToImportName,
|
|
59
|
+
discoverStories,
|
|
60
|
+
scanExportOrder
|
|
61
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ZudoSgConfig } from "../config.js";
|
|
2
|
+
import { deriveMapKeyPrefix } from "../../registry/component-docs.js";
|
|
3
|
+
export { deriveMapKeyPrefix };
|
|
4
|
+
export interface GenRegistryResult {
|
|
5
|
+
/** Entries discovered across every components root, combined. */
|
|
6
|
+
entryCount: number;
|
|
7
|
+
/** Targets that would be (or were) written because their content changed. */
|
|
8
|
+
changed: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface GenRegistryOptions {
|
|
11
|
+
/** Verify only — never write; throws when any target has drifted. */
|
|
12
|
+
check?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Runs `gen-registry` against `config`, resolved relative to `projectRoot`.
|
|
16
|
+
* Throws (without writing anything) on discovery errors, missing marker
|
|
17
|
+
* blocks, or — in `--check` mode — drift.
|
|
18
|
+
*/
|
|
19
|
+
export declare function runGenRegistry(projectRoot: string, config: ZudoSgConfig, options?: GenRegistryOptions): GenRegistryResult;
|
|
20
|
+
export declare class SgRegistryDriftError extends Error {
|
|
21
|
+
readonly driftedPaths: string[];
|
|
22
|
+
constructor(driftedPaths: string[]);
|
|
23
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, relative, resolve } from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
buildRegistryBlock,
|
|
5
|
+
buildStoryModulesBlock,
|
|
6
|
+
replaceBlock
|
|
7
|
+
} from "./build-registry-source.js";
|
|
8
|
+
import { deriveMapKeyPrefix } from "../../registry/component-docs.js";
|
|
9
|
+
import { assertUniqueImportNames, discoverStories } from "./discover-stories.js";
|
|
10
|
+
const STORY_MODULES_RELATIVE_PATH = "stories/__tests__/story-modules.ts";
|
|
11
|
+
function buildEntriesForRoot(projectRoot, root) {
|
|
12
|
+
const absDir = resolve(projectRoot, root.dir);
|
|
13
|
+
const keyPrefix = deriveMapKeyPrefix(root.dir);
|
|
14
|
+
return discoverStories(absDir).map((entry) => ({
|
|
15
|
+
...entry,
|
|
16
|
+
importSpecifier: `${root.importBase}/${entry.relDirStem}.stories.tsx`,
|
|
17
|
+
mapKey: `./${keyPrefix}/${entry.relDirStem}.stories.tsx`
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
function runGenRegistry(projectRoot, config, options = {}) {
|
|
21
|
+
const perRootEntries = config.componentsRoots.map((root) => ({
|
|
22
|
+
root,
|
|
23
|
+
entries: buildEntriesForRoot(projectRoot, root)
|
|
24
|
+
}));
|
|
25
|
+
const allEntries = perRootEntries.flatMap((r) => r.entries).sort((a, b) => a.mapKey.localeCompare(b.mapKey));
|
|
26
|
+
assertUniqueImportNames(allEntries);
|
|
27
|
+
const registryPath = resolve(projectRoot, config.registryOut);
|
|
28
|
+
const registrySrc = readFileSync(registryPath, "utf8");
|
|
29
|
+
const nextRegistry = replaceBlock(
|
|
30
|
+
registrySrc,
|
|
31
|
+
buildRegistryBlock(allEntries, config.uiPackageName),
|
|
32
|
+
registryPath
|
|
33
|
+
);
|
|
34
|
+
const targets = [
|
|
35
|
+
{ path: registryPath, before: registrySrc, after: nextRegistry }
|
|
36
|
+
];
|
|
37
|
+
for (const { root, entries } of perRootEntries) {
|
|
38
|
+
const absDir = resolve(projectRoot, root.dir);
|
|
39
|
+
const storyModulesPath = resolve(absDir, STORY_MODULES_RELATIVE_PATH);
|
|
40
|
+
if (!existsSync(storyModulesPath)) continue;
|
|
41
|
+
const relativeImportPrefix = relative(dirname(storyModulesPath), absDir).split("\\").join("/");
|
|
42
|
+
const before = readFileSync(storyModulesPath, "utf8");
|
|
43
|
+
const after = replaceBlock(
|
|
44
|
+
before,
|
|
45
|
+
buildStoryModulesBlock(entries, relativeImportPrefix),
|
|
46
|
+
storyModulesPath
|
|
47
|
+
);
|
|
48
|
+
targets.push({ path: storyModulesPath, before, after });
|
|
49
|
+
}
|
|
50
|
+
const changed = targets.filter((t) => t.before !== t.after);
|
|
51
|
+
if (options.check) {
|
|
52
|
+
if (changed.length > 0) {
|
|
53
|
+
throw new SgRegistryDriftError(changed.map((t) => t.path));
|
|
54
|
+
}
|
|
55
|
+
return { entryCount: allEntries.length, changed: [] };
|
|
56
|
+
}
|
|
57
|
+
for (const t of changed) writeFileSync(t.path, t.after);
|
|
58
|
+
return { entryCount: allEntries.length, changed: changed.map((t) => t.path) };
|
|
59
|
+
}
|
|
60
|
+
class SgRegistryDriftError extends Error {
|
|
61
|
+
constructor(driftedPaths) {
|
|
62
|
+
super(`sg-registry codegen drift detected:
|
|
63
|
+
${driftedPaths.map((p) => ` - ${p}`).join("\n")}
|
|
64
|
+
Run \`pnpm gen:sg-registry\` and commit the result.`);
|
|
65
|
+
this.driftedPaths = driftedPaths;
|
|
66
|
+
this.name = "SgRegistryDriftError";
|
|
67
|
+
}
|
|
68
|
+
driftedPaths;
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
SgRegistryDriftError,
|
|
72
|
+
deriveMapKeyPrefix,
|
|
73
|
+
runGenRegistry
|
|
74
|
+
};
|