@vendure/dashboard 3.4.1-master-202508030248 → 3.4.1-master-202508050244
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/dist/vite/utils/schema-generator.js +17 -12
- package/package.json +154 -155
- package/vite/constants.ts +0 -280
- package/vite/index.ts +0 -1
- package/vite/tests/barrel-exports.spec.ts +0 -30
- package/vite/tests/fixtures-barrel-exports/my-plugin/index.ts +0 -1
- package/vite/tests/fixtures-barrel-exports/my-plugin/src/my.plugin.ts +0 -8
- package/vite/tests/fixtures-barrel-exports/package.json +0 -6
- package/vite/tests/fixtures-barrel-exports/vendure-config.ts +0 -19
- package/vite/tests/fixtures-npm-plugin/fake_node_modules/test-plugin/index.js +0 -20
- package/vite/tests/fixtures-npm-plugin/fake_node_modules/test-plugin/package.json +0 -8
- package/vite/tests/fixtures-npm-plugin/package.json +0 -6
- package/vite/tests/fixtures-npm-plugin/vendure-config.ts +0 -18
- package/vite/tests/fixtures-path-alias/js-aliased/index.ts +0 -1
- package/vite/tests/fixtures-path-alias/js-aliased/src/js-aliased.plugin.ts +0 -8
- package/vite/tests/fixtures-path-alias/package.json +0 -6
- package/vite/tests/fixtures-path-alias/star-aliased/index.ts +0 -1
- package/vite/tests/fixtures-path-alias/star-aliased/src/star-aliased.plugin.ts +0 -8
- package/vite/tests/fixtures-path-alias/ts-aliased/index.ts +0 -1
- package/vite/tests/fixtures-path-alias/ts-aliased/src/ts-aliased.plugin.ts +0 -8
- package/vite/tests/fixtures-path-alias/vendure-config.ts +0 -20
- package/vite/tests/npm-plugin.spec.ts +0 -46
- package/vite/tests/path-alias.spec.ts +0 -61
- package/vite/tests/tsconfig.json +0 -21
- package/vite/types.ts +0 -44
- package/vite/utils/ast-utils.spec.ts +0 -49
- package/vite/utils/ast-utils.ts +0 -33
- package/vite/utils/compiler.ts +0 -244
- package/vite/utils/config-loader.ts +0 -0
- package/vite/utils/logger.ts +0 -43
- package/vite/utils/plugin-discovery.ts +0 -494
- package/vite/utils/schema-generator.ts +0 -45
- package/vite/utils/tsconfig-utils.ts +0 -79
- package/vite/utils/ui-config.ts +0 -52
- package/vite/vite-plugin-admin-api-schema.ts +0 -131
- package/vite/vite-plugin-config-loader.ts +0 -84
- package/vite/vite-plugin-config.ts +0 -70
- package/vite/vite-plugin-dashboard-metadata.ts +0 -73
- package/vite/vite-plugin-gql-tada.ts +0 -62
- package/vite/vite-plugin-tailwind-source.ts +0 -81
- package/vite/vite-plugin-theme.ts +0 -195
- package/vite/vite-plugin-transform-index.ts +0 -40
- package/vite/vite-plugin-ui-config.ts +0 -163
- package/vite/vite-plugin-vendure-dashboard.ts +0 -174
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
type ThemeColors = {
|
|
4
|
-
background?: string;
|
|
5
|
-
foreground?: string;
|
|
6
|
-
card?: string;
|
|
7
|
-
'card-foreground'?: string;
|
|
8
|
-
popover?: string;
|
|
9
|
-
'popover-foreground'?: string;
|
|
10
|
-
primary?: string;
|
|
11
|
-
'primary-foreground'?: string;
|
|
12
|
-
secondary?: string;
|
|
13
|
-
'secondary-foreground'?: string;
|
|
14
|
-
muted?: string;
|
|
15
|
-
'muted-foreground'?: string;
|
|
16
|
-
accent?: string;
|
|
17
|
-
'accent-foreground'?: string;
|
|
18
|
-
destructive?: string;
|
|
19
|
-
'destructive-foreground'?: string;
|
|
20
|
-
success?: string;
|
|
21
|
-
'success-foreground'?: string;
|
|
22
|
-
'dev-mode'?: string;
|
|
23
|
-
'dev-mode-foreground'?: string;
|
|
24
|
-
border?: string;
|
|
25
|
-
input?: string;
|
|
26
|
-
ring?: string;
|
|
27
|
-
'chart-1'?: string;
|
|
28
|
-
'chart-2'?: string;
|
|
29
|
-
'chart-3'?: string;
|
|
30
|
-
'chart-4'?: string;
|
|
31
|
-
'chart-5'?: string;
|
|
32
|
-
radius?: string;
|
|
33
|
-
sidebar?: string;
|
|
34
|
-
'sidebar-foreground'?: string;
|
|
35
|
-
'sidebar-primary'?: string;
|
|
36
|
-
'sidebar-primary-foreground'?: string;
|
|
37
|
-
'sidebar-accent'?: string;
|
|
38
|
-
'sidebar-accent-foreground'?: string;
|
|
39
|
-
'sidebar-border'?: string;
|
|
40
|
-
'sidebar-ring'?: string;
|
|
41
|
-
brand?: string;
|
|
42
|
-
'brand-lighter'?: string;
|
|
43
|
-
'brand-darker'?: string;
|
|
44
|
-
'font-sans'?: string;
|
|
45
|
-
'font-mono'?: string;
|
|
46
|
-
[key: string]: string | undefined;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export interface ThemeVariables {
|
|
50
|
-
light?: ThemeColors;
|
|
51
|
-
dark?: ThemeColors;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const defaultVariables: ThemeVariables = {
|
|
55
|
-
light: {
|
|
56
|
-
background: 'oklch(1.0000 0 0)',
|
|
57
|
-
foreground: 'oklch(0.2103 0.0059 285.8852)',
|
|
58
|
-
card: 'oklch(1.0000 0 0)',
|
|
59
|
-
'card-foreground': 'oklch(0.2103 0.0059 285.8852)',
|
|
60
|
-
popover: 'oklch(1.0000 0 0)',
|
|
61
|
-
'popover-foreground': 'oklch(0.2103 0.0059 285.8852)',
|
|
62
|
-
primary: 'oklch(0.7613 0.1503 231.1314)',
|
|
63
|
-
'primary-foreground': 'oklch(0.1408 0.0044 285.8229)',
|
|
64
|
-
secondary: 'oklch(0.9674 0.0013 286.3752)',
|
|
65
|
-
'secondary-foreground': 'oklch(0.2103 0.0059 285.8852)',
|
|
66
|
-
muted: 'oklch(0.9674 0.0013 286.3752)',
|
|
67
|
-
'muted-foreground': 'oklch(0.5517 0.0138 285.9385)',
|
|
68
|
-
accent: 'oklch(0.9674 0.0013 286.3752)',
|
|
69
|
-
'accent-foreground': 'oklch(0.2103 0.0059 285.8852)',
|
|
70
|
-
destructive: 'oklch(0.5771 0.2152 27.3250)',
|
|
71
|
-
'destructive-foreground': 'oklch(0.9851 0 0)',
|
|
72
|
-
success: 'hsl(100, 81%, 35%)',
|
|
73
|
-
'success-foreground': 'hsl(0 0% 98%)',
|
|
74
|
-
'dev-mode': 'hsl(204, 76%, 62%)',
|
|
75
|
-
'dev-mode-foreground': 'hsl(0 0% 98%)',
|
|
76
|
-
border: 'oklch(0.9197 0.0040 286.3202)',
|
|
77
|
-
input: 'oklch(0.9197 0.0040 286.3202)',
|
|
78
|
-
ring: 'oklch(0.7613 0.1503 231.1314)',
|
|
79
|
-
'chart-1': 'oklch(0.7613 0.1503 231.1314)',
|
|
80
|
-
'chart-2': 'oklch(0.5575 0.2525 302.3212)',
|
|
81
|
-
'chart-3': 'oklch(0.5858 0.2220 17.5846)',
|
|
82
|
-
'chart-4': 'oklch(0.6658 0.1574 58.3183)',
|
|
83
|
-
'chart-5': 'oklch(0.6271 0.1699 149.2138)',
|
|
84
|
-
radius: '0.375rem',
|
|
85
|
-
sidebar: 'oklch(0.9674 0.0013 286.3752)',
|
|
86
|
-
'sidebar-foreground': 'oklch(0.2103 0.0059 285.8852)',
|
|
87
|
-
'sidebar-primary': 'oklch(0.7613 0.1503 231.1314)',
|
|
88
|
-
'sidebar-primary-foreground': 'oklch(0.1408 0.0044 285.8229)',
|
|
89
|
-
'sidebar-accent': 'oklch(1.0000 0 0)',
|
|
90
|
-
'sidebar-accent-foreground': 'oklch(0.2103 0.0059 285.8852)',
|
|
91
|
-
'sidebar-border': 'oklch(0.9197 0.0040 286.3202)',
|
|
92
|
-
'sidebar-ring': 'oklch(0.7613 0.1503 231.1314)',
|
|
93
|
-
brand: '#17c1ff',
|
|
94
|
-
'brand-lighter': '#e6f9ff',
|
|
95
|
-
'brand-darker': '#0099ff',
|
|
96
|
-
'font-sans': 'Inter, sans-serif',
|
|
97
|
-
'font-mono': 'Geist Mono, monospace',
|
|
98
|
-
},
|
|
99
|
-
dark: {
|
|
100
|
-
background: 'oklch(0.1408 0.0044 285.8229)',
|
|
101
|
-
foreground: 'oklch(0.9851 0 0)',
|
|
102
|
-
card: 'oklch(0.2103 0.0059 285.8852)',
|
|
103
|
-
'card-foreground': 'oklch(0.9851 0 0)',
|
|
104
|
-
popover: 'oklch(0.2103 0.0059 285.8852)',
|
|
105
|
-
'popover-foreground': 'oklch(0.9851 0 0)',
|
|
106
|
-
primary: 'oklch(0.7613 0.1503 231.1314)',
|
|
107
|
-
'primary-foreground': 'oklch(0.1408 0.0044 285.8229)',
|
|
108
|
-
secondary: 'oklch(0.2739 0.0055 286.0326)',
|
|
109
|
-
'secondary-foreground': 'oklch(0.9851 0 0)',
|
|
110
|
-
muted: 'oklch(0.2739 0.0055 286.0326)',
|
|
111
|
-
'muted-foreground': 'oklch(0.7118 0.0129 286.0665)',
|
|
112
|
-
accent: 'oklch(0.2739 0.0055 286.0326)',
|
|
113
|
-
'accent-foreground': 'oklch(0.9851 0 0)',
|
|
114
|
-
destructive: 'oklch(0.6368 0.2078 25.3313)',
|
|
115
|
-
'destructive-foreground': 'oklch(0.9851 0 0)',
|
|
116
|
-
success: 'hsl(100, 100%, 35%)',
|
|
117
|
-
'success-foreground': 'hsl(0 0% 98%)',
|
|
118
|
-
'dev-mode': 'hsl(204, 86%, 53%)',
|
|
119
|
-
'dev-mode-foreground': 'hsl(0 0% 98%)',
|
|
120
|
-
border: 'oklch(0.2739 0.0055 286.0326)',
|
|
121
|
-
input: 'oklch(0.2739 0.0055 286.0326)',
|
|
122
|
-
ring: 'oklch(0.7613 0.1503 231.1314)',
|
|
123
|
-
'chart-1': 'oklch(0.7613 0.1503 231.1314)',
|
|
124
|
-
'chart-2': 'oklch(0.6268 0.2325 303.9004)',
|
|
125
|
-
'chart-3': 'oklch(0.6450 0.2154 16.4393)',
|
|
126
|
-
'chart-4': 'oklch(0.7686 0.1647 70.0804)',
|
|
127
|
-
'chart-5': 'oklch(0.7227 0.1920 149.5793)',
|
|
128
|
-
sidebar: 'oklch(0.1408 0.0044 285.8229)',
|
|
129
|
-
'sidebar-foreground': 'oklch(0.9851 0 0)',
|
|
130
|
-
'sidebar-primary': 'oklch(0.7613 0.1503 231.1314)',
|
|
131
|
-
'sidebar-primary-foreground': 'oklch(0.1408 0.0044 285.8229)',
|
|
132
|
-
'sidebar-accent': 'oklch(0.2739 0.0055 286.0326)',
|
|
133
|
-
'sidebar-accent-foreground': 'oklch(0.9851 0 0)',
|
|
134
|
-
'sidebar-border': 'oklch(0.2739 0.0055 286.0326)',
|
|
135
|
-
'sidebar-ring': 'oklch(0.7613 0.1503 231.1314)',
|
|
136
|
-
brand: '#17c1ff',
|
|
137
|
-
'brand-lighter': '#e6f9ff',
|
|
138
|
-
'brand-darker': '#0099ff',
|
|
139
|
-
'font-sans': 'Inter, sans-serif',
|
|
140
|
-
'font-mono': 'Geist Mono, monospace',
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
export type ThemeVariablesPluginOptions = {
|
|
145
|
-
theme?: ThemeVariables;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export function themeVariablesPlugin(options: ThemeVariablesPluginOptions): Plugin {
|
|
149
|
-
const virtualModuleId = 'virtual:admin-theme';
|
|
150
|
-
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
151
|
-
|
|
152
|
-
return {
|
|
153
|
-
name: 'vendure:admin-theme',
|
|
154
|
-
enforce: 'pre', // This ensures our plugin runs before other CSS processors
|
|
155
|
-
transform(code, id) {
|
|
156
|
-
// Only transform CSS files
|
|
157
|
-
if (!id.endsWith('styles.css')) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Replace the @import 'virtual:admin-theme'; with our theme variables
|
|
162
|
-
if (
|
|
163
|
-
code.includes('@import "virtual:admin-theme";') ||
|
|
164
|
-
code.includes("@import 'virtual:admin-theme';")
|
|
165
|
-
) {
|
|
166
|
-
const lightTheme = options.theme?.light || {};
|
|
167
|
-
const darkTheme = options.theme?.dark || {};
|
|
168
|
-
|
|
169
|
-
// Merge default themes with custom themes
|
|
170
|
-
const mergedLightTheme = { ...defaultVariables.light, ...lightTheme };
|
|
171
|
-
const mergedDarkTheme = { ...defaultVariables.dark, ...darkTheme };
|
|
172
|
-
|
|
173
|
-
const themeCSS = `
|
|
174
|
-
:root {
|
|
175
|
-
${Object.entries(mergedLightTheme)
|
|
176
|
-
.filter(([key, value]) => value !== undefined)
|
|
177
|
-
.map(([key, value]) => `--${key}: ${value as string};`)
|
|
178
|
-
.join('\n')}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
.dark {
|
|
182
|
-
${Object.entries(mergedDarkTheme)
|
|
183
|
-
.filter(([key, value]) => value !== undefined)
|
|
184
|
-
.map(([key, value]) => `--${key}: ${value as string};`)
|
|
185
|
-
.join('\n')}
|
|
186
|
-
}
|
|
187
|
-
`;
|
|
188
|
-
|
|
189
|
-
return code.replace(/@import ['"]virtual:admin-theme['"];?/, themeCSS);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return null;
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Plugin, ResolvedConfig } from 'vite';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @description
|
|
5
|
-
* This Vite plugin handles the scenario where the `base` path is set in the Vite config.
|
|
6
|
-
* The default Vite behavior is to prepend the `base` path to all `href` and `src` attributes in the HTML,
|
|
7
|
-
* but this causes the Vendure Dashboard not to load its assets correctly.
|
|
8
|
-
*
|
|
9
|
-
* This plugin removes the `base` path from all `href` and `src` attributes in the HTML,
|
|
10
|
-
* and adds a `<base>` tag to the `<head>` of the HTML document.
|
|
11
|
-
*/
|
|
12
|
-
export function transformIndexHtmlPlugin(): Plugin {
|
|
13
|
-
let config: ResolvedConfig;
|
|
14
|
-
return {
|
|
15
|
-
name: 'vendure:vite-config-transform-index-html',
|
|
16
|
-
configResolved(resolvedConfig) {
|
|
17
|
-
// store the resolved config
|
|
18
|
-
config = resolvedConfig;
|
|
19
|
-
},
|
|
20
|
-
// Only apply this plugin during the build phase
|
|
21
|
-
apply: 'build',
|
|
22
|
-
transformIndexHtml(html) {
|
|
23
|
-
if (config.base && config.base !== '/') {
|
|
24
|
-
// Remove the base path from hrefs and srcs
|
|
25
|
-
const basePath = config.base.replace(/\/$/, ''); // Remove trailing slash
|
|
26
|
-
|
|
27
|
-
// Single regex to handle both href and src attributes with any quote type
|
|
28
|
-
const attributeRegex = new RegExp(`(href|src)=(["'])${basePath}/?`, 'g');
|
|
29
|
-
let transformedHtml = html.replace(attributeRegex, '$1=$2');
|
|
30
|
-
|
|
31
|
-
// Add base tag to head
|
|
32
|
-
const baseTag = ` <base href="${config.base}">\n`;
|
|
33
|
-
transformedHtml = transformedHtml.replace(/<head>/, `<head>\n${baseTag}`);
|
|
34
|
-
|
|
35
|
-
return transformedHtml;
|
|
36
|
-
}
|
|
37
|
-
return html;
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { LanguageCode, VendureConfig } from '@vendure/core';
|
|
2
|
-
import { Plugin } from 'vite';
|
|
3
|
-
|
|
4
|
-
import { getUiConfig } from './utils/ui-config.js';
|
|
5
|
-
import { ConfigLoaderApi, getConfigLoaderApi } from './vite-plugin-config-loader.js';
|
|
6
|
-
|
|
7
|
-
const virtualModuleId = 'virtual:vendure-ui-config';
|
|
8
|
-
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
9
|
-
|
|
10
|
-
export interface ApiConfig {
|
|
11
|
-
/**
|
|
12
|
-
* @description
|
|
13
|
-
* The hostname of the Vendure server which the admin UI will be making API calls
|
|
14
|
-
* to. If set to "auto", the Admin UI app will determine the hostname from the
|
|
15
|
-
* current location (i.e. `window.location.hostname`).
|
|
16
|
-
*
|
|
17
|
-
* @default 'auto'
|
|
18
|
-
*/
|
|
19
|
-
host?: string | 'auto';
|
|
20
|
-
/**
|
|
21
|
-
* @description
|
|
22
|
-
* The port of the Vendure server which the admin UI will be making API calls
|
|
23
|
-
* to. If set to "auto", the Admin UI app will determine the port from the
|
|
24
|
-
* current location (i.e. `window.location.port`).
|
|
25
|
-
*
|
|
26
|
-
* @default 'auto'
|
|
27
|
-
*/
|
|
28
|
-
port?: number | 'auto';
|
|
29
|
-
/**
|
|
30
|
-
* @description
|
|
31
|
-
* The path to the GraphQL Admin API.
|
|
32
|
-
*
|
|
33
|
-
* @default 'admin-api'
|
|
34
|
-
*/
|
|
35
|
-
adminApiPath?: string;
|
|
36
|
-
/**
|
|
37
|
-
* @description
|
|
38
|
-
* Whether to use cookies or bearer tokens to track sessions.
|
|
39
|
-
* Should match the setting of in the server's `tokenMethod` config
|
|
40
|
-
* option.
|
|
41
|
-
*
|
|
42
|
-
* @default 'cookie'
|
|
43
|
-
*/
|
|
44
|
-
tokenMethod?: 'cookie' | 'bearer';
|
|
45
|
-
/**
|
|
46
|
-
* @description
|
|
47
|
-
* The header used when using the 'bearer' auth method. Should match the
|
|
48
|
-
* setting of the server's `authOptions.authTokenHeaderKey` config option.
|
|
49
|
-
*
|
|
50
|
-
* @default 'vendure-auth-token'
|
|
51
|
-
*/
|
|
52
|
-
authTokenHeaderKey?: string;
|
|
53
|
-
/**
|
|
54
|
-
* @description
|
|
55
|
-
* The name of the header which contains the channel token. Should match the
|
|
56
|
-
* setting of the server's `apiOptions.channelTokenKey` config option.
|
|
57
|
-
*
|
|
58
|
-
* @default 'vendure-token'
|
|
59
|
-
*/
|
|
60
|
-
channelTokenKey?: string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface I18nConfig {
|
|
64
|
-
/**
|
|
65
|
-
* @description
|
|
66
|
-
* The default language for the Admin UI. Must be one of the
|
|
67
|
-
* items specified in the `availableLanguages` property.
|
|
68
|
-
*
|
|
69
|
-
* @default LanguageCode.en
|
|
70
|
-
*/
|
|
71
|
-
defaultLanguage?: LanguageCode;
|
|
72
|
-
/**
|
|
73
|
-
* @description
|
|
74
|
-
* The default locale for the Admin UI. The locale affects the formatting of
|
|
75
|
-
* currencies & dates. Must be one of the items specified
|
|
76
|
-
* in the `availableLocales` property.
|
|
77
|
-
*
|
|
78
|
-
* If not set, the browser default locale will be used.
|
|
79
|
-
*
|
|
80
|
-
* @since 2.2.0
|
|
81
|
-
*/
|
|
82
|
-
defaultLocale?: string;
|
|
83
|
-
/**
|
|
84
|
-
* @description
|
|
85
|
-
* An array of languages for which translations exist for the Admin UI.
|
|
86
|
-
*/
|
|
87
|
-
availableLanguages?: LanguageCode[];
|
|
88
|
-
/**
|
|
89
|
-
* @description
|
|
90
|
-
* An array of locales to be used on Admin UI.
|
|
91
|
-
*
|
|
92
|
-
* @since 2.2.0
|
|
93
|
-
*/
|
|
94
|
-
availableLocales?: string[];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export interface UiConfigPluginOptions {
|
|
98
|
-
/**
|
|
99
|
-
* @description
|
|
100
|
-
* Configuration for API connection settings
|
|
101
|
-
*/
|
|
102
|
-
api?: ApiConfig;
|
|
103
|
-
/**
|
|
104
|
-
* @description
|
|
105
|
-
* Configuration for internationalization settings
|
|
106
|
-
*/
|
|
107
|
-
i18n?: I18nConfig;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* @description
|
|
112
|
-
* The resolved UI configuration with all defaults applied.
|
|
113
|
-
* This is the type of the configuration object available at runtime.
|
|
114
|
-
*/
|
|
115
|
-
export interface ResolvedUiConfig {
|
|
116
|
-
/**
|
|
117
|
-
* @description
|
|
118
|
-
* API connection settings with all defaults applied
|
|
119
|
-
*/
|
|
120
|
-
api: Required<ApiConfig>;
|
|
121
|
-
/**
|
|
122
|
-
* @description
|
|
123
|
-
* Internationalization settings with all defaults applied.
|
|
124
|
-
* Note: defaultLocale remains optional as it can be undefined.
|
|
125
|
-
*/
|
|
126
|
-
i18n: Required<Omit<I18nConfig, 'defaultLocale'>> & Pick<I18nConfig, 'defaultLocale'>;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* This Vite plugin scans the configured plugins for any dashboard extensions and dynamically
|
|
131
|
-
* generates an import statement for each one, wrapped up in a `runDashboardExtensions()`
|
|
132
|
-
* function which can then be imported and executed in the Dashboard app.
|
|
133
|
-
*/
|
|
134
|
-
export function uiConfigPlugin(options: UiConfigPluginOptions = {}): Plugin {
|
|
135
|
-
let configLoaderApi: ConfigLoaderApi;
|
|
136
|
-
let vendureConfig: VendureConfig;
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
name: 'vendure:dashboard-ui-config',
|
|
140
|
-
configResolved({ plugins }) {
|
|
141
|
-
configLoaderApi = getConfigLoaderApi(plugins);
|
|
142
|
-
},
|
|
143
|
-
resolveId(id) {
|
|
144
|
-
if (id === virtualModuleId) {
|
|
145
|
-
return resolvedVirtualModuleId;
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
async load(id) {
|
|
149
|
-
if (id === resolvedVirtualModuleId) {
|
|
150
|
-
if (!vendureConfig) {
|
|
151
|
-
const result = await configLoaderApi.getVendureConfig();
|
|
152
|
-
vendureConfig = result.vendureConfig;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const config = getUiConfig(vendureConfig, options);
|
|
156
|
-
|
|
157
|
-
return `
|
|
158
|
-
export const uiConfig = ${JSON.stringify(config)}
|
|
159
|
-
`;
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import tailwindcss from '@tailwindcss/vite';
|
|
2
|
-
import { TanStackRouterVite } from '@tanstack/router-plugin/vite';
|
|
3
|
-
import react from '@vitejs/plugin-react';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { PluginOption } from 'vite';
|
|
6
|
-
|
|
7
|
-
import { PathAdapter } from './types.js';
|
|
8
|
-
import { PackageScannerConfig } from './utils/compiler.js';
|
|
9
|
-
import { adminApiSchemaPlugin } from './vite-plugin-admin-api-schema.js';
|
|
10
|
-
import { configLoaderPlugin } from './vite-plugin-config-loader.js';
|
|
11
|
-
import { viteConfigPlugin } from './vite-plugin-config.js';
|
|
12
|
-
import { dashboardMetadataPlugin } from './vite-plugin-dashboard-metadata.js';
|
|
13
|
-
import { gqlTadaPlugin } from './vite-plugin-gql-tada.js';
|
|
14
|
-
import { dashboardTailwindSourcePlugin } from './vite-plugin-tailwind-source.js';
|
|
15
|
-
import { themeVariablesPlugin, ThemeVariablesPluginOptions } from './vite-plugin-theme.js';
|
|
16
|
-
import { transformIndexHtmlPlugin } from './vite-plugin-transform-index.js';
|
|
17
|
-
import { uiConfigPlugin, UiConfigPluginOptions } from './vite-plugin-ui-config.js';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @description
|
|
21
|
-
* Options for the {@link vendureDashboardPlugin} Vite plugin.
|
|
22
|
-
*/
|
|
23
|
-
export type VitePluginVendureDashboardOptions = {
|
|
24
|
-
/**
|
|
25
|
-
* @description
|
|
26
|
-
* The path to the Vendure server configuration file.
|
|
27
|
-
*/
|
|
28
|
-
vendureConfigPath: string | URL;
|
|
29
|
-
/**
|
|
30
|
-
* @description
|
|
31
|
-
* The {@link PathAdapter} allows you to customize the resolution of paths
|
|
32
|
-
* in the compiled Vendure source code which is used as part of the
|
|
33
|
-
* introspection step of building the dashboard.
|
|
34
|
-
*
|
|
35
|
-
* It enables support for more complex repository structures, such as
|
|
36
|
-
* monorepos, where the Vendure server configuration file may not
|
|
37
|
-
* be located in the root directory of the project.
|
|
38
|
-
*
|
|
39
|
-
* If you get compilation errors like "Error loading Vendure config: Cannot find module",
|
|
40
|
-
* you probably need to provide a custom `pathAdapter` to resolve the paths correctly.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* vendureDashboardPlugin({
|
|
45
|
-
* tempCompilationDir: join(__dirname, './__vendure-dashboard-temp'),
|
|
46
|
-
* pathAdapter: {
|
|
47
|
-
* getCompiledConfigPath: ({ inputRootDir, outputPath, configFileName }) => {
|
|
48
|
-
* const projectName = inputRootDir.split('/libs/')[1].split('/')[0];
|
|
49
|
-
* const pathAfterProject = inputRootDir.split(`/libs/${projectName}`)[1];
|
|
50
|
-
* const compiledConfigFilePath = `${outputPath}/${projectName}${pathAfterProject}`;
|
|
51
|
-
* return path.join(compiledConfigFilePath, configFileName);
|
|
52
|
-
* },
|
|
53
|
-
* transformTsConfigPathMappings: ({ phase, patterns }) => {
|
|
54
|
-
* // "loading" phase is when the compiled Vendure code is being loaded by
|
|
55
|
-
* // the plugin, in order to introspect the configuration of your app.
|
|
56
|
-
* if (phase === 'loading') {
|
|
57
|
-
* return patterns.map((p) =>
|
|
58
|
-
* p.replace('libs/', '').replace(/.ts$/, '.js'),
|
|
59
|
-
* );
|
|
60
|
-
* }
|
|
61
|
-
* return patterns;
|
|
62
|
-
* },
|
|
63
|
-
* },
|
|
64
|
-
* // ...
|
|
65
|
-
* }),
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
pathAdapter?: PathAdapter;
|
|
69
|
-
/**
|
|
70
|
-
* @description
|
|
71
|
-
* The name of the exported variable from the Vendure server configuration file, e.g. `config`.
|
|
72
|
-
* This is only required if the plugin is unable to auto-detect the name of the exported variable.
|
|
73
|
-
*/
|
|
74
|
-
vendureConfigExport?: string;
|
|
75
|
-
/**
|
|
76
|
-
* @description
|
|
77
|
-
* The path to the directory where the generated GraphQL Tada files will be output.
|
|
78
|
-
*/
|
|
79
|
-
gqlOutputPath?: string;
|
|
80
|
-
tempCompilationDir?: string;
|
|
81
|
-
disableTansStackRouterPlugin?: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* @description
|
|
84
|
-
* Allows you to customize the location of node_modules & glob patterns used to scan for potential
|
|
85
|
-
* Vendure plugins installed as npm packages. If not provided, the compiler will attempt to guess
|
|
86
|
-
* the location based on the location of the `@vendure/core` package.
|
|
87
|
-
*/
|
|
88
|
-
pluginPackageScanner?: PackageScannerConfig;
|
|
89
|
-
} & UiConfigPluginOptions &
|
|
90
|
-
ThemeVariablesPluginOptions;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @description
|
|
94
|
-
* This is a Vite plugin which configures a set of plugins required to build the Vendure Dashboard.
|
|
95
|
-
*/
|
|
96
|
-
export function vendureDashboardPlugin(options: VitePluginVendureDashboardOptions): PluginOption[] {
|
|
97
|
-
const tempDir = options.tempCompilationDir ?? path.join(import.meta.dirname, './.vendure-dashboard-temp');
|
|
98
|
-
const normalizedVendureConfigPath = getNormalizedVendureConfigPath(options.vendureConfigPath);
|
|
99
|
-
const packageRoot = getDashboardPackageRoot();
|
|
100
|
-
const linguiConfigPath = path.join(packageRoot, 'lingui.config.js');
|
|
101
|
-
|
|
102
|
-
if (process.env.IS_LOCAL_DEV !== 'true') {
|
|
103
|
-
process.env.LINGUI_CONFIG = linguiConfigPath;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return [
|
|
107
|
-
// TODO: solve https://github.com/kentcdodds/babel-plugin-macros/issues/87
|
|
108
|
-
// lingui(),
|
|
109
|
-
...(options.disableTansStackRouterPlugin
|
|
110
|
-
? []
|
|
111
|
-
: [
|
|
112
|
-
TanStackRouterVite({
|
|
113
|
-
autoCodeSplitting: true,
|
|
114
|
-
routeFileIgnorePattern: '.graphql.ts|components|hooks|utils',
|
|
115
|
-
routesDirectory: path.join(packageRoot, 'src/app/routes'),
|
|
116
|
-
generatedRouteTree: path.join(packageRoot, 'src/app/routeTree.gen.ts'),
|
|
117
|
-
}),
|
|
118
|
-
]),
|
|
119
|
-
react({
|
|
120
|
-
// babel: {
|
|
121
|
-
// plugins: ['@lingui/babel-plugin-lingui-macro'],
|
|
122
|
-
// },
|
|
123
|
-
}),
|
|
124
|
-
themeVariablesPlugin({ theme: options.theme }),
|
|
125
|
-
dashboardTailwindSourcePlugin(),
|
|
126
|
-
tailwindcss(),
|
|
127
|
-
configLoaderPlugin({
|
|
128
|
-
vendureConfigPath: normalizedVendureConfigPath,
|
|
129
|
-
outputPath: tempDir,
|
|
130
|
-
pathAdapter: options.pathAdapter,
|
|
131
|
-
pluginPackageScanner: options.pluginPackageScanner,
|
|
132
|
-
}),
|
|
133
|
-
viteConfigPlugin({ packageRoot }),
|
|
134
|
-
adminApiSchemaPlugin(),
|
|
135
|
-
dashboardMetadataPlugin(),
|
|
136
|
-
uiConfigPlugin(options),
|
|
137
|
-
...(options.gqlOutputPath
|
|
138
|
-
? [gqlTadaPlugin({ gqlTadaOutputPath: options.gqlOutputPath, tempDir, packageRoot })]
|
|
139
|
-
: []),
|
|
140
|
-
transformIndexHtmlPlugin(),
|
|
141
|
-
];
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* @description
|
|
146
|
-
* Returns the path to the root of the `@vendure/dashboard` package.
|
|
147
|
-
*/
|
|
148
|
-
function getDashboardPackageRoot(): string {
|
|
149
|
-
const fileUrl = import.meta.resolve('@vendure/dashboard');
|
|
150
|
-
const packagePath = fileUrl.startsWith('file:') ? new URL(fileUrl).pathname : fileUrl;
|
|
151
|
-
return fixWindowsPath(path.join(packagePath, '../../../'));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Get the normalized path to the Vendure config file given either a string or URL.
|
|
156
|
-
*/
|
|
157
|
-
export function getNormalizedVendureConfigPath(vendureConfigPath: string | URL): string {
|
|
158
|
-
const stringPath = typeof vendureConfigPath === 'string' ? vendureConfigPath : vendureConfigPath.href;
|
|
159
|
-
if (stringPath.startsWith('file:')) {
|
|
160
|
-
return fixWindowsPath(new URL(stringPath).pathname);
|
|
161
|
-
}
|
|
162
|
-
return fixWindowsPath(stringPath);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function fixWindowsPath(filePath: string): string {
|
|
166
|
-
// Fix Windows paths that might start with a leading slash
|
|
167
|
-
if (process.platform === 'win32') {
|
|
168
|
-
// Remove leading slash before drive letter on Windows
|
|
169
|
-
if (/^[/\\][A-Za-z]:/.test(filePath)) {
|
|
170
|
-
return filePath.substring(1);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return filePath;
|
|
174
|
-
}
|