storybook-addon-design-system-docs 1.0.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/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/core/assets/config.d.ts +15 -0
- package/dist/core/assets/config.js +100 -0
- package/dist/core/assets/generator.d.ts +11 -0
- package/dist/core/assets/generator.js +77 -0
- package/dist/core/primitives/index.d.ts +7 -0
- package/dist/core/primitives/index.js +23 -0
- package/dist/core/primitives/types.d.ts +130 -0
- package/dist/core/primitives/types.js +2 -0
- package/dist/manager.js +2 -0
- package/dist/preset.cjs +208 -0
- package/dist/preset.d.ts +30 -0
- package/dist/preset.js +13 -0
- package/dist/types.d.ts +204 -0
- package/dist/types.js +17 -0
- package/dist/unplugin.d.ts +2 -0
- package/dist/unplugin.js +139 -0
- package/dist/util/Logger.d.ts +67 -0
- package/dist/util/Logger.js +172 -0
- package/dist/util/resolveTemplate.d.ts +10 -0
- package/dist/util/resolveTemplate.js +60 -0
- package/manager.js +1 -0
- package/package.json +153 -0
- package/preset.js +13 -0
- package/tailwind.config.js +233 -0
- package/templates/assets.mdx +29 -0
- package/templates/colors.mdx +13 -0
- package/templates/design-system.mdx +57 -0
- package/templates/radius.mdx +9 -0
- package/templates/shadows.mdx +9 -0
- package/templates/spacing.mdx +12 -0
- package/templates/typography.mdx +18 -0
package/dist/preset.cjs
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
|
|
6
|
+
console.log('[PRESET.CJS] Loading actual preset...');
|
|
7
|
+
|
|
8
|
+
const logger = {
|
|
9
|
+
info: (msg, data) => console.log(`[PRESET] INFO: ${msg}`, data),
|
|
10
|
+
error: (msg, error) => console.error(`[PRESET] ERROR: ${msg}`, error)
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create AddonOptions from preset options.
|
|
15
|
+
*/
|
|
16
|
+
function createAddonOptions(options) {
|
|
17
|
+
if (!options.tailwindConfig) {
|
|
18
|
+
logger.error("tailwindConfig missing from options:", options);
|
|
19
|
+
throw new Error(
|
|
20
|
+
"tailwindConfig option is required. Please specify the path to your Tailwind config file. " +
|
|
21
|
+
'Example: { tailwindConfig: "../tailwind.config.js" }',
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return options;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Create AssetAddonOptions from preset options if assets are configured.
|
|
29
|
+
*/
|
|
30
|
+
function createAssetOptions(options) {
|
|
31
|
+
if (!options.assets) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
groups: options.assets,
|
|
37
|
+
assetsSidebarGroup: options.assetsSidebarGroup,
|
|
38
|
+
configDir: options.configDir,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Storybook indexer hook.
|
|
44
|
+
* Creates virtual entries for asset documentation pages.
|
|
45
|
+
*
|
|
46
|
+
* @param existingIndexers - The list of existing indexers
|
|
47
|
+
* @param options - Addon options
|
|
48
|
+
* @returns The updated indexers
|
|
49
|
+
*/
|
|
50
|
+
async function experimental_indexers(existingIndexers = [], options) {
|
|
51
|
+
console.log('[PRESET.CJS] experimental_indexers called');
|
|
52
|
+
|
|
53
|
+
if (!options.assets || !Array.isArray(options.assets)) {
|
|
54
|
+
return existingIndexers;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
console.log('[PRESET.CJS] Creating indexers for', options.assets.length, 'asset groups');
|
|
58
|
+
|
|
59
|
+
// Create an indexer for virtual asset stories
|
|
60
|
+
const assetIndexer = {
|
|
61
|
+
test: /virtual:design-system-docs\/assets\.stories\.js$/,
|
|
62
|
+
createIndex: async (fileName, opts) => {
|
|
63
|
+
console.log('[PRESET.CJS] Asset indexer createIndex called for:', fileName);
|
|
64
|
+
|
|
65
|
+
const entries = [];
|
|
66
|
+
|
|
67
|
+
// Create an entry for each asset group
|
|
68
|
+
if (options.assets && Array.isArray(options.assets)) {
|
|
69
|
+
options.assets.forEach((asset) => {
|
|
70
|
+
const assetName = asset.name;
|
|
71
|
+
const title = `Assets/${assetName}`;
|
|
72
|
+
|
|
73
|
+
entries.push({
|
|
74
|
+
type: 'story',
|
|
75
|
+
importPath: fileName,
|
|
76
|
+
exportName: assetName,
|
|
77
|
+
name: assetName,
|
|
78
|
+
title: title,
|
|
79
|
+
meta: {
|
|
80
|
+
title: title,
|
|
81
|
+
component: null,
|
|
82
|
+
parameters: {
|
|
83
|
+
docs: {
|
|
84
|
+
page: () => {
|
|
85
|
+
const React = require('react');
|
|
86
|
+
return React.createElement('div', {}, `${assetName} Documentation Page`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return entries;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return [...existingIndexers, assetIndexer];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Vite config hook.
|
|
104
|
+
* Injects the unplugin into the Storybook Vite config.
|
|
105
|
+
*
|
|
106
|
+
* @param config - The Vite config object
|
|
107
|
+
* @param options - Addon options
|
|
108
|
+
* @returns The modified Vite config
|
|
109
|
+
*/
|
|
110
|
+
const viteFinal = async (config, options) => {
|
|
111
|
+
console.log('[PRESET.CJS] viteFinal called');
|
|
112
|
+
|
|
113
|
+
const { plugins = [] } = config;
|
|
114
|
+
|
|
115
|
+
// Create the unplugin instance with options
|
|
116
|
+
const unpluginInstance = {
|
|
117
|
+
name: 'design-system-docs-unplugin',
|
|
118
|
+
configResolved() {
|
|
119
|
+
console.log('[UNPLUGIN] Config resolved');
|
|
120
|
+
},
|
|
121
|
+
resolveId(id) {
|
|
122
|
+
console.log('[UNPLUGIN] Resolving ID:', id);
|
|
123
|
+
if (id === 'virtual:design-system-docs/assets.stories.js') {
|
|
124
|
+
console.log('[UNPLUGIN] Matched assets stories');
|
|
125
|
+
return '\0design-system-docs:assets.stories.js';
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
load(id) {
|
|
129
|
+
console.log('[UNPLUGIN] Loading ID:', id);
|
|
130
|
+
if (id === '\0design-system-docs:assets.stories.js') {
|
|
131
|
+
console.log('[UNPLUGIN] Loading virtual assets stories module');
|
|
132
|
+
|
|
133
|
+
// Generate CSF stories for all asset groups
|
|
134
|
+
const stories = [];
|
|
135
|
+
if (options.assets && Array.isArray(options.assets)) {
|
|
136
|
+
options.assets.forEach((asset) => {
|
|
137
|
+
const assetName = asset.name;
|
|
138
|
+
const storyName = assetName.charAt(0).toUpperCase() + assetName.slice(1);
|
|
139
|
+
|
|
140
|
+
stories.push(`
|
|
141
|
+
export const ${storyName} = {
|
|
142
|
+
name: '${storyName}',
|
|
143
|
+
parameters: {
|
|
144
|
+
docs: {
|
|
145
|
+
page: () => {
|
|
146
|
+
const React = require('react');
|
|
147
|
+
return React.createElement('div', {}, '${assetName} Documentation Page');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
`);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return stories.join('\n');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// The unplugin returns a Vite plugin object
|
|
162
|
+
plugins.push(unpluginInstance);
|
|
163
|
+
|
|
164
|
+
config.plugins = plugins;
|
|
165
|
+
return config;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Registers asset directories as static directories for Storybook to serve.
|
|
170
|
+
* No copying is performed - assets are served directly from their source locations.
|
|
171
|
+
* We map them to specific URLs (staticPath) to ensure browser compatibility.
|
|
172
|
+
*/
|
|
173
|
+
const staticDirs = async (existingStaticDirs, options) => {
|
|
174
|
+
console.log('[PRESET.CJS] staticDirs called');
|
|
175
|
+
try {
|
|
176
|
+
if (!options.assets || !Array.isArray(options.assets)) {
|
|
177
|
+
return existingStaticDirs;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
console.log('[PRESET.CJS] Found assets configuration:', options.assets.length, 'groups');
|
|
181
|
+
|
|
182
|
+
// For now, just return existing static dirs
|
|
183
|
+
return existingStaticDirs;
|
|
184
|
+
} catch (error) {
|
|
185
|
+
logger.error("Failed to configure static directories", error);
|
|
186
|
+
return existingStaticDirs;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Add the tailwind config file to the stories list so that experimental_indexers
|
|
192
|
+
* matches it and generates the documentation pages.
|
|
193
|
+
*/
|
|
194
|
+
const stories = async (entry = [], options) => {
|
|
195
|
+
console.log('[PRESET.CJS] stories called');
|
|
196
|
+
try {
|
|
197
|
+
// Stories are now generated by experimental_indexers
|
|
198
|
+
return entry;
|
|
199
|
+
} catch (error) {
|
|
200
|
+
logger.error("Failed to inject config into stories", error);
|
|
201
|
+
return entry;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
exports.experimental_indexers = experimental_indexers;
|
|
206
|
+
exports.staticDirs = staticDirs;
|
|
207
|
+
exports.stories = stories;
|
|
208
|
+
exports.viteFinal = viteFinal;
|
package/dist/preset.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storybook indexer hook.
|
|
3
|
+
* We no longer use a custom indexer for assets, as we generate physical MDX files
|
|
4
|
+
* that are picked up by the standard Storybook indexers.
|
|
5
|
+
*
|
|
6
|
+
* @param existingIndexers - The list of existing indexers
|
|
7
|
+
* @param options - Addon options
|
|
8
|
+
* @returns The (unmodified) indexers
|
|
9
|
+
*/
|
|
10
|
+
export declare function experimental_indexers(existingIndexers: any[], _options: any): Promise<any[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Vite config hook.
|
|
13
|
+
* Injects the unplugin into the Storybook Vite config.
|
|
14
|
+
*
|
|
15
|
+
* @param config - The Vite config object
|
|
16
|
+
* @param options - Addon options
|
|
17
|
+
* @returns The modified Vite config
|
|
18
|
+
*/
|
|
19
|
+
export declare const viteFinal: (config: any, options: any) => Promise<any>;
|
|
20
|
+
/**
|
|
21
|
+
* Registers asset directories as static directories for Storybook to serve.
|
|
22
|
+
* No copying is performed - assets are served directly from their source locations.
|
|
23
|
+
* We map them to specific URLs (staticPath) to ensure browser compatibility.
|
|
24
|
+
*/
|
|
25
|
+
export declare const staticDirs: (existingStaticDirs: any[], options: any) => Promise<any[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Add the tailwind config file to the stories list so that experimental_indexers
|
|
28
|
+
* matches it and generates the documentation pages.
|
|
29
|
+
*/
|
|
30
|
+
export declare const stories: (entry: StorybookConfigRaw, options: any) => Promise<any>;
|
package/dist/preset.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
const preset = require('./dist/preset.cjs');
|
|
5
|
+
|
|
6
|
+
export const managerEntries = (entry = []) => {
|
|
7
|
+
return [...entry, require.resolve('./dist/manager.js')];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const experimental_indexers = preset.experimental_indexers;
|
|
11
|
+
export const viteFinal = preset.viteFinal;
|
|
12
|
+
export const stories = preset.stories;
|
|
13
|
+
export const staticDirs = preset.staticDirs;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import type { VALID_SECTIONS } from "@/constants";
|
|
2
|
+
import type { NormalizedAddonOptions } from "@/core/primitives/types";
|
|
3
|
+
export * from "@/core/primitives/types";
|
|
4
|
+
export interface PackageJson {
|
|
5
|
+
dependencies?: Record<string, string>;
|
|
6
|
+
devDependencies?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* User-facing configuration options for the Design System addon.
|
|
10
|
+
* These are the options passed to the addon in .storybook/main.ts
|
|
11
|
+
*/
|
|
12
|
+
export interface DesignSystemAddonOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Path to your Tailwind config file (relative to .storybook/ directory).
|
|
15
|
+
* Example: '../tailwind.config.js' or '../src/styles.css' (for Tailwind v4)
|
|
16
|
+
* This is now required - backwards compatibility has been removed.
|
|
17
|
+
*/
|
|
18
|
+
tailwindConfig: string;
|
|
19
|
+
/**
|
|
20
|
+
* Sidebar group name for all documentation pages. This replaces defaultPath.
|
|
21
|
+
* @default 'Design System/'
|
|
22
|
+
*/
|
|
23
|
+
sidebarGroup?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Which theme sections to enable.
|
|
26
|
+
* @default ['Colors', 'Typography', 'Spacing', 'Shadows', 'BorderRadius']
|
|
27
|
+
*/
|
|
28
|
+
sections?: TailwindSectionInput[];
|
|
29
|
+
/**
|
|
30
|
+
* If defined, combines all sections into one story.
|
|
31
|
+
*/
|
|
32
|
+
forceSingleDoc?: CustomSectionInput;
|
|
33
|
+
/**
|
|
34
|
+
* When true, hides Tailwind's built-in values and shows only custom values.
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
showOnlyCustom?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Typography configuration options.
|
|
40
|
+
*/
|
|
41
|
+
typography?: {
|
|
42
|
+
example?: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Template configuration for custom MDX rendering.
|
|
46
|
+
*/
|
|
47
|
+
templates?: TemplateConfig;
|
|
48
|
+
/**
|
|
49
|
+
* Asset group configurations for icons, illustrations, etc.
|
|
50
|
+
*/
|
|
51
|
+
assets?: AssetGroupConfig[];
|
|
52
|
+
}
|
|
53
|
+
export interface AssetAddonOptions {
|
|
54
|
+
groups: NormalizedAssetGroup[];
|
|
55
|
+
}
|
|
56
|
+
export interface UnpluginOptions {
|
|
57
|
+
addonOptions: NormalizedAddonOptions;
|
|
58
|
+
assetOptions?: AssetAddonOptions;
|
|
59
|
+
configPath?: string;
|
|
60
|
+
}
|
|
61
|
+
export type TailwindConfigSections = (typeof VALID_SECTIONS)[number];
|
|
62
|
+
export type SectionInput<NameType extends string> = NameType | {
|
|
63
|
+
name: NameType;
|
|
64
|
+
path?: string;
|
|
65
|
+
};
|
|
66
|
+
export type TailwindSectionInput = SectionInput<TailwindConfigSections>;
|
|
67
|
+
export type CustomSectionInput = SectionInput<string>;
|
|
68
|
+
export interface NormalizedSection {
|
|
69
|
+
name: string;
|
|
70
|
+
path: string;
|
|
71
|
+
}
|
|
72
|
+
export interface ResolvedConfig {
|
|
73
|
+
theme: {
|
|
74
|
+
colors: Record<string, any>;
|
|
75
|
+
fontSize: Record<string, any>;
|
|
76
|
+
fontFamily: Record<string, any>;
|
|
77
|
+
fontWeight: Record<string, any>;
|
|
78
|
+
spacing: Record<string, any>;
|
|
79
|
+
boxShadow: Record<string, any>;
|
|
80
|
+
borderRadius: Record<string, any>;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export interface Typography {
|
|
84
|
+
type: Record<string, string>;
|
|
85
|
+
weight: Record<string, string>;
|
|
86
|
+
size: Record<string, string>;
|
|
87
|
+
}
|
|
88
|
+
export interface Spacing {
|
|
89
|
+
values: Record<string, string>;
|
|
90
|
+
}
|
|
91
|
+
export interface Shadows {
|
|
92
|
+
values: Record<string, string>;
|
|
93
|
+
}
|
|
94
|
+
export interface BorderRadius {
|
|
95
|
+
values: Record<string, string>;
|
|
96
|
+
}
|
|
97
|
+
export type ThemeCssVariables = Record<string, Record<string, string | string[]>>;
|
|
98
|
+
export type SupportedFontUnit = "rem" | "em" | "px" | "pt" | "cm" | "mm" | "in" | "pc" | "%";
|
|
99
|
+
/**
|
|
100
|
+
* Configuration for the template system and source code generation.
|
|
101
|
+
*/
|
|
102
|
+
export interface TemplateConfig {
|
|
103
|
+
/**
|
|
104
|
+
* Path to directory containing custom templates.
|
|
105
|
+
* Templates in this directory override defaults by matching filename.
|
|
106
|
+
* @example './.storybook/theme-templates'
|
|
107
|
+
*/
|
|
108
|
+
directory?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Whether to enable template caching (default: true in production)
|
|
111
|
+
*/
|
|
112
|
+
cache?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Whether to use React components (true) or inline framework-agnostic templates (false).
|
|
115
|
+
* Default: false (framework-agnostic templates)
|
|
116
|
+
*
|
|
117
|
+
* When true: Templates use pre-built React components (smaller bundles, React-only)
|
|
118
|
+
* When false: Templates generate all markup/logic inline (larger bundles, framework-agnostic)
|
|
119
|
+
*/
|
|
120
|
+
useReactComponents?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Custom filters to add to the template engine.
|
|
123
|
+
* Key is the filter name, value is the filter function.
|
|
124
|
+
*/
|
|
125
|
+
filters?: Record<string, (...args: any[]) => any>;
|
|
126
|
+
/**
|
|
127
|
+
* Additional context data available to all templates
|
|
128
|
+
*/
|
|
129
|
+
globals?: Record<string, any>;
|
|
130
|
+
}
|
|
131
|
+
export interface AssetVariantConfig {
|
|
132
|
+
enabled: boolean;
|
|
133
|
+
suffixes: [string, string];
|
|
134
|
+
defaultVariant: "light" | "dark";
|
|
135
|
+
}
|
|
136
|
+
export interface AssetDisplayConfig {
|
|
137
|
+
layout: "grid" | "list";
|
|
138
|
+
columns: number;
|
|
139
|
+
showFilename: boolean;
|
|
140
|
+
showPath: boolean;
|
|
141
|
+
previewSize: number;
|
|
142
|
+
background: "transparent" | "light" | "dark" | "checkerboard";
|
|
143
|
+
}
|
|
144
|
+
export interface AssetCopyConfig {
|
|
145
|
+
import?: string;
|
|
146
|
+
component?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface AssetFilterConfig {
|
|
149
|
+
include: string[];
|
|
150
|
+
exclude: string[];
|
|
151
|
+
}
|
|
152
|
+
export interface AssetGroupConfig {
|
|
153
|
+
name: string;
|
|
154
|
+
path?: string;
|
|
155
|
+
source: string;
|
|
156
|
+
/**
|
|
157
|
+
* URL path where assets are served from (e.g., '/assets/illustrations').
|
|
158
|
+
* When provided, assets are served directly from this path without copying.
|
|
159
|
+
* User must configure staticDirs in their Storybook config to serve from this path.
|
|
160
|
+
*/
|
|
161
|
+
staticPath?: string;
|
|
162
|
+
title?: string;
|
|
163
|
+
description?: string;
|
|
164
|
+
variants?: Partial<AssetVariantConfig>;
|
|
165
|
+
display?: Partial<AssetDisplayConfig>;
|
|
166
|
+
copy?: AssetCopyConfig;
|
|
167
|
+
filter?: Partial<AssetFilterConfig>;
|
|
168
|
+
groupByFolder?: boolean;
|
|
169
|
+
}
|
|
170
|
+
export interface NormalizedAssetGroup {
|
|
171
|
+
name: string;
|
|
172
|
+
path: string;
|
|
173
|
+
source: string;
|
|
174
|
+
/** URL path where assets are served from. Either user-provided or auto-generated. */
|
|
175
|
+
staticPath: string;
|
|
176
|
+
title: string;
|
|
177
|
+
description?: string;
|
|
178
|
+
variants: AssetVariantConfig;
|
|
179
|
+
display: AssetDisplayConfig;
|
|
180
|
+
copy: AssetCopyConfig;
|
|
181
|
+
filter: AssetFilterConfig;
|
|
182
|
+
groupByFolder: boolean;
|
|
183
|
+
}
|
|
184
|
+
export interface Asset {
|
|
185
|
+
id: string;
|
|
186
|
+
name: string;
|
|
187
|
+
filename: string;
|
|
188
|
+
relativePath: string;
|
|
189
|
+
absolutePath: string;
|
|
190
|
+
url: string;
|
|
191
|
+
folder?: string;
|
|
192
|
+
ext: string;
|
|
193
|
+
variants?: {
|
|
194
|
+
light?: string;
|
|
195
|
+
dark?: string;
|
|
196
|
+
};
|
|
197
|
+
type: "svg" | "png" | "jpg" | "jpeg" | "gif" | "webp";
|
|
198
|
+
}
|
|
199
|
+
export interface AssetGroup {
|
|
200
|
+
name: string;
|
|
201
|
+
config: NormalizedAssetGroup;
|
|
202
|
+
assets: Asset[];
|
|
203
|
+
folders?: Map<string, Asset[]>;
|
|
204
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@/core/primitives/types"), exports);
|
package/dist/unplugin.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vite = void 0;
|
|
4
|
+
const unplugin_1 = require("unplugin");
|
|
5
|
+
const constants_1 = require("@/constants");
|
|
6
|
+
const manager_1 = require("@/core/assets/manager");
|
|
7
|
+
const data_1 = require("@/core/primitives/data");
|
|
8
|
+
const load_1 = require("@/core/primitives/load");
|
|
9
|
+
const tw_config_1 = require("@/core/primitives/loaders/tw-config");
|
|
10
|
+
const tw_css_1 = require("@/core/primitives/loaders/tw-css");
|
|
11
|
+
const Logger_1 = require("@/util/Logger");
|
|
12
|
+
const logger = new Logger_1.Logger("unplugin");
|
|
13
|
+
const unplugin = (0, unplugin_1.createUnplugin)((options) => {
|
|
14
|
+
// Asset handling
|
|
15
|
+
const assetManager = options.assetOptions?.groups && options.assetOptions.groups.length > 0
|
|
16
|
+
? (0, manager_1.createAssetManager)(options.assetOptions.groups)
|
|
17
|
+
: undefined;
|
|
18
|
+
return {
|
|
19
|
+
name: "unplugin-design-system-docs",
|
|
20
|
+
enforce: "pre",
|
|
21
|
+
resolveId(id, _importer) {
|
|
22
|
+
// Handle design system data virtual module (design-system-docs:theme)
|
|
23
|
+
if (id === `${constants_1.VIRTUAL_MODULE_PREFIX}theme`) {
|
|
24
|
+
return constants_1.DESIGN_SYSTEM_DATA_ID;
|
|
25
|
+
}
|
|
26
|
+
// Handle asset data virtual module (design-system-docs:assets)
|
|
27
|
+
if (id === `${constants_1.VIRTUAL_MODULE_PREFIX}assets`) {
|
|
28
|
+
return constants_1.ASSET_DATA_ID;
|
|
29
|
+
}
|
|
30
|
+
// Handle group-specific asset data: design-system-docs:assets/<group-name>
|
|
31
|
+
// This is used by the generated MDX files
|
|
32
|
+
if (id.startsWith(`${constants_1.VIRTUAL_MODULE_PREFIX}assets/`)) {
|
|
33
|
+
const groupName = id.replace(`${constants_1.VIRTUAL_MODULE_PREFIX}assets/`, "");
|
|
34
|
+
return constants_1.ASSET_GROUP_ID_PREFIX + groupName;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
},
|
|
38
|
+
loadInclude(id) {
|
|
39
|
+
return (id === constants_1.DESIGN_SYSTEM_DATA_ID ||
|
|
40
|
+
id === constants_1.ASSET_DATA_ID ||
|
|
41
|
+
id.startsWith(constants_1.ASSET_GROUP_ID_PREFIX));
|
|
42
|
+
},
|
|
43
|
+
async load(id) {
|
|
44
|
+
try {
|
|
45
|
+
// Handle design system data virtual module (design-system-docs:theme)
|
|
46
|
+
if (id === constants_1.DESIGN_SYSTEM_DATA_ID) {
|
|
47
|
+
if (!options.configPath) {
|
|
48
|
+
const errorMsg = "No Tailwind config path found. Cannot load theme data. " +
|
|
49
|
+
"This is likely a bug in the addon setup.";
|
|
50
|
+
logger.error(errorMsg);
|
|
51
|
+
throw new Error(errorMsg);
|
|
52
|
+
}
|
|
53
|
+
// Watch the config file for changes
|
|
54
|
+
if (this.addWatchFile && options.configPath) {
|
|
55
|
+
this.addWatchFile(options.configPath);
|
|
56
|
+
}
|
|
57
|
+
// Load the Tailwind theme from the config file
|
|
58
|
+
const fullTailwindConfig = await (0, load_1.loadTheme)(options.addonOptions);
|
|
59
|
+
// Transform to Data Context
|
|
60
|
+
const data = (0, data_1.createDesignSystemData)(fullTailwindConfig, options.addonOptions);
|
|
61
|
+
// Export theme data as plain JavaScript module
|
|
62
|
+
return `
|
|
63
|
+
export const colors = ${JSON.stringify(data.colors, null, 2)};
|
|
64
|
+
export const typography = ${JSON.stringify(data.typography, null, 2)};
|
|
65
|
+
export const spacing = ${data.spacing ? JSON.stringify(data.spacing, null, 2) : "undefined"};
|
|
66
|
+
export const shadows = ${data.shadows ? JSON.stringify(data.shadows, null, 2) : "undefined"};
|
|
67
|
+
export const borderRadius = ${data.borderRadius ? JSON.stringify(data.borderRadius, null, 2) : "undefined"};
|
|
68
|
+
`.trim();
|
|
69
|
+
}
|
|
70
|
+
// Handle asset data virtual module (design-system-docs:assets)
|
|
71
|
+
if (id === constants_1.ASSET_DATA_ID) {
|
|
72
|
+
if (!assetManager)
|
|
73
|
+
return "export default {}";
|
|
74
|
+
// Get all assets from all groups
|
|
75
|
+
const groups = await Promise.all(assetManager
|
|
76
|
+
.getGroupNames()
|
|
77
|
+
.map((name) => assetManager.getGroup(name)));
|
|
78
|
+
const assets = groups
|
|
79
|
+
.filter((g) => !!g)
|
|
80
|
+
.flatMap((g) => g.assets);
|
|
81
|
+
return `export default ${JSON.stringify(assets)}`;
|
|
82
|
+
}
|
|
83
|
+
// Handle per-group data module
|
|
84
|
+
// e.g., \0design-system-docs:asset-group/Icons
|
|
85
|
+
if (id.startsWith(constants_1.ASSET_GROUP_ID_PREFIX)) {
|
|
86
|
+
const groupName = id.slice(constants_1.ASSET_GROUP_ID_PREFIX.length);
|
|
87
|
+
logger.info(`Loading asset group data: ${groupName}`);
|
|
88
|
+
if (!assetManager) {
|
|
89
|
+
logger.warn(`No asset manager available for group: ${groupName}`);
|
|
90
|
+
return "export default {}";
|
|
91
|
+
}
|
|
92
|
+
const group = await assetManager.getGroup(groupName);
|
|
93
|
+
if (!group) {
|
|
94
|
+
logger.warn(`Asset group not found: ${groupName}`);
|
|
95
|
+
return "export default {}";
|
|
96
|
+
}
|
|
97
|
+
return `export default ${JSON.stringify(group)}`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
102
|
+
logger.error(`Failed to load virtual module: ${id}`, error);
|
|
103
|
+
throw new Error(`[storybook-addon-design-system-docs] ${errorMessage}`);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
vite: {
|
|
107
|
+
handleHotUpdate({ file, server }) {
|
|
108
|
+
// Handle config/CSS file changes
|
|
109
|
+
// If the file is part of the Tailwind config (JS or CSS)
|
|
110
|
+
if ((0, tw_config_1.isTwConfigPath)(file) || (0, tw_css_1.isTwCssPath)(file)) {
|
|
111
|
+
// Update: Only invalidate the data module, not the config module (which is no longer virtual)
|
|
112
|
+
const n1 = server.moduleGraph.getModuleById(constants_1.DESIGN_SYSTEM_DATA_ID);
|
|
113
|
+
n1 && server.moduleGraph.invalidateModule(n1);
|
|
114
|
+
server.ws.send({ type: "full-reload" });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// Handle asset changes
|
|
118
|
+
async function handleAssetChange(filePath, server) {
|
|
119
|
+
if (!assetManager)
|
|
120
|
+
return;
|
|
121
|
+
const matchingGroup = assetManager.findMatchingGroup(filePath);
|
|
122
|
+
if (!matchingGroup)
|
|
123
|
+
return;
|
|
124
|
+
logger.info(`Asset changed in group ${matchingGroup}: ${filePath}`);
|
|
125
|
+
assetManager.invalidateGroup(matchingGroup);
|
|
126
|
+
// Invalidate the group module
|
|
127
|
+
const groupModule = server.moduleGraph.getModuleById(constants_1.ASSET_GROUP_ID_PREFIX + matchingGroup);
|
|
128
|
+
groupModule && server.moduleGraph.invalidateModule(groupModule);
|
|
129
|
+
// Invalidate the assets data module
|
|
130
|
+
const assetsModule = server.moduleGraph.getModuleById(constants_1.ASSET_DATA_ID);
|
|
131
|
+
assetsModule && server.moduleGraph.invalidateModule(assetsModule);
|
|
132
|
+
server.ws.send({ type: "full-reload", path: "*" });
|
|
133
|
+
}
|
|
134
|
+
handleAssetChange(file, server);
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
exports.vite = unplugin.vite;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export type LogLevel = "debug" | "info" | "warn" | "error" | "silent";
|
|
2
|
+
/**
|
|
3
|
+
* Logger utility for the addon with configurable log levels and context support.
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Log levels (debug, info, warn, error, silent)
|
|
7
|
+
* - Context/prefix support for consistent logging
|
|
8
|
+
* - Conditional ANSI colors (respects NO_COLOR, FORCE_COLOR, TTY detection)
|
|
9
|
+
* - Structured data logging
|
|
10
|
+
*/
|
|
11
|
+
export declare class Logger {
|
|
12
|
+
private static defaultPrefix;
|
|
13
|
+
private static level;
|
|
14
|
+
private static useColors;
|
|
15
|
+
private prefix;
|
|
16
|
+
/**
|
|
17
|
+
* Create a logger instance with a specific context prefix.
|
|
18
|
+
* @param context - Context name to prefix log messages (e.g., 'ConfigLoader', 'unplugin')
|
|
19
|
+
*/
|
|
20
|
+
constructor(context?: string);
|
|
21
|
+
/**
|
|
22
|
+
* Set the global log level. Messages below this level will be suppressed.
|
|
23
|
+
*/
|
|
24
|
+
static setLevel(level: LogLevel): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get the current global log level.
|
|
27
|
+
*/
|
|
28
|
+
static getLevel(): LogLevel;
|
|
29
|
+
/**
|
|
30
|
+
* Enable or disable color output.
|
|
31
|
+
*/
|
|
32
|
+
static setColors(enabled: boolean): void;
|
|
33
|
+
private shouldLog;
|
|
34
|
+
private colorize;
|
|
35
|
+
private formatMessage;
|
|
36
|
+
/**
|
|
37
|
+
* Log debug messages. Only shown when log level is 'debug'.
|
|
38
|
+
*/
|
|
39
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
40
|
+
/**
|
|
41
|
+
* Log informational messages.
|
|
42
|
+
*/
|
|
43
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
44
|
+
/**
|
|
45
|
+
* Log warning messages.
|
|
46
|
+
*/
|
|
47
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
48
|
+
/**
|
|
49
|
+
* Log error messages.
|
|
50
|
+
*/
|
|
51
|
+
error(message: string, error?: Error | unknown, data?: Record<string, unknown>): void;
|
|
52
|
+
/**
|
|
53
|
+
* Static warn method for backward compatibility.
|
|
54
|
+
* Consider using instance methods for context-aware logging.
|
|
55
|
+
*/
|
|
56
|
+
static warn(message: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Static error method for backward compatibility.
|
|
59
|
+
* Consider using instance methods for context-aware logging.
|
|
60
|
+
*/
|
|
61
|
+
static error(message: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Static info method for backward compatibility.
|
|
64
|
+
* Consider using instance methods for context-aware logging.
|
|
65
|
+
*/
|
|
66
|
+
static info(message: string): void;
|
|
67
|
+
}
|