@vendure/dashboard 3.2.1 → 3.2.2

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.
@@ -0,0 +1,27 @@
1
+ import { VendureConfig } from '@vendure/core';
2
+ export interface ConfigLoaderOptions {
3
+ vendureConfigPath: string;
4
+ tempDir: string;
5
+ vendureConfigExport?: string;
6
+ }
7
+ /**
8
+ * @description
9
+ * This function compiles the given Vendure config file and any imported relative files (i.e.
10
+ * project files, not npm packages) into a temporary directory, and returns the compiled config.
11
+ *
12
+ * The reason we need to do this is that Vendure code makes use of TypeScript experimental decorators
13
+ * (e.g. for NestJS decorators and TypeORM column decorators) which are not supported by esbuild.
14
+ *
15
+ * In Vite, when we load some TypeScript into the top-level Vite config file (in the end-user project), Vite
16
+ * internally uses esbuild to temporarily compile that TypeScript code. Unfortunately, esbuild does not support
17
+ * these experimental decorators, errors will be thrown as soon as e.g. a TypeORM column decorator is encountered.
18
+ *
19
+ * To work around this, we compile the Vendure config file and all its imports using SWC, which does support
20
+ * these experimental decorators. The compiled files are then loaded by Vite, which is able to handle the compiled
21
+ * JavaScript output.
22
+ */
23
+ export declare function loadVendureConfig(options: ConfigLoaderOptions): Promise<{
24
+ vendureConfig: VendureConfig;
25
+ exportedSymbolName: string;
26
+ }>;
27
+ export declare function compileFile(inputRootDir: string, inputPath: string, outputDir: string, compiledFiles?: Set<string>): Promise<void>;
@@ -0,0 +1,141 @@
1
+ import { parse, transform } from '@swc/core';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import { pathToFileURL } from 'url';
5
+ /**
6
+ * @description
7
+ * This function compiles the given Vendure config file and any imported relative files (i.e.
8
+ * project files, not npm packages) into a temporary directory, and returns the compiled config.
9
+ *
10
+ * The reason we need to do this is that Vendure code makes use of TypeScript experimental decorators
11
+ * (e.g. for NestJS decorators and TypeORM column decorators) which are not supported by esbuild.
12
+ *
13
+ * In Vite, when we load some TypeScript into the top-level Vite config file (in the end-user project), Vite
14
+ * internally uses esbuild to temporarily compile that TypeScript code. Unfortunately, esbuild does not support
15
+ * these experimental decorators, errors will be thrown as soon as e.g. a TypeORM column decorator is encountered.
16
+ *
17
+ * To work around this, we compile the Vendure config file and all its imports using SWC, which does support
18
+ * these experimental decorators. The compiled files are then loaded by Vite, which is able to handle the compiled
19
+ * JavaScript output.
20
+ */
21
+ export async function loadVendureConfig(options) {
22
+ const { vendureConfigPath, vendureConfigExport, tempDir } = options;
23
+ const outputPath = tempDir;
24
+ const configFileName = path.basename(vendureConfigPath);
25
+ const inputRootDir = path.dirname(vendureConfigPath);
26
+ await fs.remove(outputPath);
27
+ await compileFile(inputRootDir, vendureConfigPath, outputPath);
28
+ const compiledConfigFilePath = pathToFileURL(path.join(outputPath, configFileName)).href.replace(/.ts$/, '.js');
29
+ // create package.json with type commonjs and save it to the output dir
30
+ await fs.writeFile(path.join(outputPath, 'package.json'), JSON.stringify({ type: 'commonjs' }, null, 2));
31
+ // We need to figure out the symbol exported by the config file by
32
+ // analyzing the AST and finding an export with the type "VendureConfig"
33
+ const ast = await parse(await fs.readFile(vendureConfigPath, 'utf-8'), {
34
+ syntax: 'typescript',
35
+ decorators: true,
36
+ });
37
+ const detectedExportedSymbolName = findConfigExport(ast.body);
38
+ const configExportedSymbolName = detectedExportedSymbolName || vendureConfigExport;
39
+ if (!configExportedSymbolName) {
40
+ throw new Error(`Could not find a variable exported as VendureConfig. Please specify the name of the exported variable using the "vendureConfigExport" option.`);
41
+ }
42
+ const config = await import(compiledConfigFilePath).then(m => m[configExportedSymbolName]);
43
+ if (!config) {
44
+ throw new Error(`Could not find a variable exported as VendureConfig with the name "${configExportedSymbolName}".`);
45
+ }
46
+ return { vendureConfig: config, exportedSymbolName: configExportedSymbolName };
47
+ }
48
+ /**
49
+ * Given the AST of a TypeScript file, finds the name of the variable exported as VendureConfig.
50
+ */
51
+ function findConfigExport(statements) {
52
+ var _a;
53
+ for (const statement of statements) {
54
+ if (statement.type === 'ExportDeclaration') {
55
+ if (statement.declaration.type === 'VariableDeclaration') {
56
+ for (const declaration of statement.declaration.declarations) {
57
+ if (isBindingIdentifier(declaration.id)) {
58
+ const typeRef = (_a = declaration.id.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation;
59
+ if ((typeRef === null || typeRef === void 0 ? void 0 : typeRef.type) === 'TsTypeReference') {
60
+ if (typeRef.typeName.type === 'Identifier' &&
61
+ typeRef.typeName.value === 'VendureConfig') {
62
+ return declaration.id.value;
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ return undefined;
71
+ }
72
+ function isBindingIdentifier(id) {
73
+ return id.type === 'Identifier' && !!id.typeAnnotation;
74
+ }
75
+ export async function compileFile(inputRootDir, inputPath, outputDir, compiledFiles = new Set()) {
76
+ if (compiledFiles.has(inputPath)) {
77
+ return;
78
+ }
79
+ compiledFiles.add(inputPath);
80
+ // Ensure output directory exists
81
+ await fs.ensureDir(outputDir);
82
+ // Read the source file
83
+ const source = await fs.readFile(inputPath, 'utf-8');
84
+ // Transform config
85
+ const config = {
86
+ filename: inputPath,
87
+ sourceMaps: true,
88
+ jsc: {
89
+ parser: {
90
+ syntax: 'typescript',
91
+ tsx: false,
92
+ decorators: true,
93
+ },
94
+ target: 'es2020',
95
+ loose: false,
96
+ transform: {
97
+ legacyDecorator: true,
98
+ decoratorMetadata: true,
99
+ },
100
+ },
101
+ module: {
102
+ type: 'commonjs',
103
+ strict: true,
104
+ strictMode: true,
105
+ lazy: false,
106
+ noInterop: false,
107
+ },
108
+ };
109
+ // Transform the code using SWC
110
+ const result = await transform(source, config);
111
+ // Generate output file path
112
+ const relativePath = path.relative(inputRootDir, inputPath);
113
+ const outputPath = path.join(outputDir, relativePath).replace(/\.ts$/, '.js');
114
+ // Ensure the subdirectory for the output file exists
115
+ await fs.ensureDir(path.dirname(outputPath));
116
+ // Write the transformed code
117
+ await fs.writeFile(outputPath, result.code);
118
+ // Write source map if available
119
+ if (result.map) {
120
+ await fs.writeFile(`${outputPath}.map`, JSON.stringify(result.map));
121
+ }
122
+ // Parse the source to find relative imports
123
+ const ast = await parse(source, { syntax: 'typescript', decorators: true });
124
+ const importPaths = new Set();
125
+ function collectImports(node) {
126
+ if (node.type === 'ImportDeclaration' && node.source.value.startsWith('.')) {
127
+ const importPath = path.resolve(path.dirname(inputPath), node.source.value);
128
+ importPaths.add(importPath + '.ts');
129
+ }
130
+ for (const key in node) {
131
+ if (node[key] && typeof node[key] === 'object') {
132
+ collectImports(node[key]);
133
+ }
134
+ }
135
+ }
136
+ collectImports(ast);
137
+ // Recursively compile all relative imports
138
+ for (const importPath of importPaths) {
139
+ await compileFile(inputRootDir, importPath, outputDir, compiledFiles);
140
+ }
141
+ }
@@ -0,0 +1,5 @@
1
+ import { LanguageCode } from '@vendure/core';
2
+ export declare const defaultLanguage = LanguageCode.en;
3
+ export declare const defaultLocale: undefined;
4
+ export declare const defaultAvailableLanguages: LanguageCode[];
5
+ export declare const defaultAvailableLocales: string[];
@@ -0,0 +1,277 @@
1
+ import { LanguageCode } from '@vendure/core';
2
+ export const defaultLanguage = LanguageCode.en;
3
+ export const defaultLocale = undefined;
4
+ export const defaultAvailableLanguages = [
5
+ LanguageCode.he,
6
+ LanguageCode.ar,
7
+ LanguageCode.de,
8
+ LanguageCode.en,
9
+ LanguageCode.es,
10
+ LanguageCode.pl,
11
+ LanguageCode.zh_Hans,
12
+ LanguageCode.zh_Hant,
13
+ LanguageCode.pt_BR,
14
+ LanguageCode.pt_PT,
15
+ LanguageCode.cs,
16
+ LanguageCode.fr,
17
+ LanguageCode.ru,
18
+ LanguageCode.uk,
19
+ LanguageCode.it,
20
+ LanguageCode.fa,
21
+ LanguageCode.ne,
22
+ LanguageCode.hr,
23
+ LanguageCode.sv,
24
+ LanguageCode.nb,
25
+ LanguageCode.tr,
26
+ ];
27
+ export const defaultAvailableLocales = [
28
+ 'AF',
29
+ 'AL',
30
+ 'DZ',
31
+ 'AS',
32
+ 'AD',
33
+ 'AO',
34
+ 'AI',
35
+ 'AQ',
36
+ 'AG',
37
+ 'AR',
38
+ 'AM',
39
+ 'AW',
40
+ 'AU',
41
+ 'AT',
42
+ 'AZ',
43
+ 'BS',
44
+ 'BH',
45
+ 'BD',
46
+ 'BB',
47
+ 'BY',
48
+ 'BE',
49
+ 'BZ',
50
+ 'BJ',
51
+ 'BM',
52
+ 'BT',
53
+ 'BO',
54
+ 'BQ',
55
+ 'BA',
56
+ 'BW',
57
+ 'BV',
58
+ 'BR',
59
+ 'IO',
60
+ 'BN',
61
+ 'BG',
62
+ 'BF',
63
+ 'BI',
64
+ 'CV',
65
+ 'KH',
66
+ 'CM',
67
+ 'CA',
68
+ 'KY',
69
+ 'CF',
70
+ 'TD',
71
+ 'CL',
72
+ 'CN',
73
+ 'CX',
74
+ 'CC',
75
+ 'CO',
76
+ 'KM',
77
+ 'CD',
78
+ 'CG',
79
+ 'CK',
80
+ 'CR',
81
+ 'HR',
82
+ 'CU',
83
+ 'CW',
84
+ 'CY',
85
+ 'CZ',
86
+ 'CI',
87
+ 'DK',
88
+ 'DJ',
89
+ 'DM',
90
+ 'DO',
91
+ 'EC',
92
+ 'EG',
93
+ 'SV',
94
+ 'GQ',
95
+ 'ER',
96
+ 'EE',
97
+ 'SZ',
98
+ 'ET',
99
+ 'FK',
100
+ 'FO',
101
+ 'FJ',
102
+ 'FI',
103
+ 'FR',
104
+ 'GF',
105
+ 'PF',
106
+ 'TF',
107
+ 'GA',
108
+ 'GM',
109
+ 'GE',
110
+ 'DE',
111
+ 'GH',
112
+ 'GI',
113
+ 'GR',
114
+ 'GL',
115
+ 'GD',
116
+ 'GP',
117
+ 'GU',
118
+ 'GT',
119
+ 'GG',
120
+ 'GN',
121
+ 'GW',
122
+ 'GY',
123
+ 'HT',
124
+ 'HM',
125
+ 'VA',
126
+ 'HN',
127
+ 'HK',
128
+ 'HU',
129
+ 'IS',
130
+ 'IN',
131
+ 'ID',
132
+ 'IR',
133
+ 'IQ',
134
+ 'IE',
135
+ 'IM',
136
+ 'IL',
137
+ 'IT',
138
+ 'JM',
139
+ 'JP',
140
+ 'JE',
141
+ 'JO',
142
+ 'KZ',
143
+ 'KE',
144
+ 'KI',
145
+ 'KP',
146
+ 'KR',
147
+ 'KW',
148
+ 'KG',
149
+ 'LA',
150
+ 'LV',
151
+ 'LB',
152
+ 'LS',
153
+ 'LR',
154
+ 'LY',
155
+ 'LI',
156
+ 'LT',
157
+ 'LU',
158
+ 'MO',
159
+ 'MG',
160
+ 'MW',
161
+ 'MY',
162
+ 'MV',
163
+ 'ML',
164
+ 'MT',
165
+ 'MH',
166
+ 'MQ',
167
+ 'MR',
168
+ 'MU',
169
+ 'YT',
170
+ 'MX',
171
+ 'FM',
172
+ 'MD',
173
+ 'MC',
174
+ 'MN',
175
+ 'ME',
176
+ 'MS',
177
+ 'MA',
178
+ 'MZ',
179
+ 'MM',
180
+ 'NA',
181
+ 'NR',
182
+ 'NP',
183
+ 'NL',
184
+ 'NC',
185
+ 'NZ',
186
+ 'NI',
187
+ 'NE',
188
+ 'NG',
189
+ 'NU',
190
+ 'NF',
191
+ 'MK',
192
+ 'MP',
193
+ 'NO',
194
+ 'OM',
195
+ 'PK',
196
+ 'PW',
197
+ 'PS',
198
+ 'PA',
199
+ 'PG',
200
+ 'PY',
201
+ 'PE',
202
+ 'PH',
203
+ 'PN',
204
+ 'PL',
205
+ 'PT',
206
+ 'PR',
207
+ 'QA',
208
+ 'RO',
209
+ 'RU',
210
+ 'RW',
211
+ 'RE',
212
+ 'BL',
213
+ 'SH',
214
+ 'KN',
215
+ 'LC',
216
+ 'MF',
217
+ 'PM',
218
+ 'VC',
219
+ 'WS',
220
+ 'SM',
221
+ 'ST',
222
+ 'SA',
223
+ 'SN',
224
+ 'RS',
225
+ 'SC',
226
+ 'SL',
227
+ 'SG',
228
+ 'SX',
229
+ 'SK',
230
+ 'SI',
231
+ 'SB',
232
+ 'SO',
233
+ 'ZA',
234
+ 'GS',
235
+ 'SS',
236
+ 'ES',
237
+ 'LK',
238
+ 'SD',
239
+ 'SR',
240
+ 'SJ',
241
+ 'SE',
242
+ 'CH',
243
+ 'SY',
244
+ 'TW',
245
+ 'TJ',
246
+ 'TZ',
247
+ 'TH',
248
+ 'TL',
249
+ 'TG',
250
+ 'TK',
251
+ 'TO',
252
+ 'TT',
253
+ 'TN',
254
+ 'TR',
255
+ 'TM',
256
+ 'TC',
257
+ 'TV',
258
+ 'UG',
259
+ 'UA',
260
+ 'AE',
261
+ 'GB',
262
+ 'UM',
263
+ 'US',
264
+ 'UY',
265
+ 'UZ',
266
+ 'VU',
267
+ 'VE',
268
+ 'VN',
269
+ 'VG',
270
+ 'VI',
271
+ 'WF',
272
+ 'EH',
273
+ 'YE',
274
+ 'ZM',
275
+ 'ZW',
276
+ 'AX',
277
+ ];
@@ -0,0 +1 @@
1
+ export { vendureDashboardPlugin } from './vite-plugin-vendure-dashboard.js';
@@ -0,0 +1 @@
1
+ export { vendureDashboardPlugin } from './vite-plugin-vendure-dashboard.js';
@@ -0,0 +1,5 @@
1
+ import { VendureConfig } from '@vendure/core';
2
+ import { GraphQLSchema } from 'graphql';
3
+ export declare function generateSchema({ vendureConfig, }: {
4
+ vendureConfig: VendureConfig;
5
+ }): Promise<GraphQLSchema>;
@@ -0,0 +1,24 @@
1
+ import { GraphQLTypesLoader } from '@nestjs/graphql';
2
+ import { resetConfig, setConfig, getConfig, runPluginConfigurations, getFinalVendureSchema, VENDURE_ADMIN_API_TYPE_PATHS, } from '@vendure/core';
3
+ import { buildSchema } from 'graphql';
4
+ let schemaPromise;
5
+ export async function generateSchema({ vendureConfig, }) {
6
+ if (!schemaPromise) {
7
+ schemaPromise = new Promise(async (resolve, reject) => {
8
+ resetConfig();
9
+ await setConfig(vendureConfig !== null && vendureConfig !== void 0 ? vendureConfig : {});
10
+ const runtimeConfig = await runPluginConfigurations(getConfig());
11
+ const typesLoader = new GraphQLTypesLoader();
12
+ const finalSchema = await getFinalVendureSchema({
13
+ config: runtimeConfig,
14
+ typePaths: VENDURE_ADMIN_API_TYPE_PATHS,
15
+ typesLoader,
16
+ apiType: 'admin',
17
+ output: 'sdl',
18
+ });
19
+ const safeSchema = buildSchema(finalSchema);
20
+ resolve(safeSchema);
21
+ });
22
+ }
23
+ return schemaPromise;
24
+ }
@@ -0,0 +1,3 @@
1
+ import { AdminUiConfig } from '@vendure/common/lib/shared-types';
2
+ import { VendureConfig } from '@vendure/core';
3
+ export declare function getAdminUiConfig(config: VendureConfig, adminUiConfig?: Partial<AdminUiConfig>): AdminUiConfig;
@@ -0,0 +1,35 @@
1
+ import { DEFAULT_AUTH_TOKEN_HEADER_KEY, DEFAULT_CHANNEL_TOKEN_KEY, ADMIN_API_PATH, } from '@vendure/common/lib/shared-constants';
2
+ import { defaultAvailableLocales } from './constants.js';
3
+ import { defaultLocale, defaultLanguage, defaultAvailableLanguages } from './constants.js';
4
+ export function getAdminUiConfig(config, adminUiConfig) {
5
+ const { authOptions, apiOptions } = config;
6
+ const propOrDefault = (prop, defaultVal, isArray = false) => {
7
+ var _a;
8
+ if (isArray) {
9
+ const isValidArray = !!adminUiConfig
10
+ ? !!((_a = adminUiConfig[prop]) === null || _a === void 0 ? void 0 : _a.length)
11
+ : false;
12
+ return !!adminUiConfig && isValidArray ? adminUiConfig[prop] : defaultVal;
13
+ }
14
+ else {
15
+ return adminUiConfig ? adminUiConfig[prop] || defaultVal : defaultVal;
16
+ }
17
+ };
18
+ return {
19
+ adminApiPath: propOrDefault('adminApiPath', apiOptions.adminApiPath || ADMIN_API_PATH),
20
+ apiHost: propOrDefault('apiHost', 'auto'),
21
+ apiPort: propOrDefault('apiPort', 'auto'),
22
+ tokenMethod: propOrDefault('tokenMethod', authOptions.tokenMethod === 'bearer' ? 'bearer' : 'cookie'),
23
+ authTokenHeaderKey: propOrDefault('authTokenHeaderKey', authOptions.authTokenHeaderKey || DEFAULT_AUTH_TOKEN_HEADER_KEY),
24
+ channelTokenKey: propOrDefault('channelTokenKey', apiOptions.channelTokenKey || DEFAULT_CHANNEL_TOKEN_KEY),
25
+ defaultLanguage: propOrDefault('defaultLanguage', defaultLanguage),
26
+ defaultLocale: propOrDefault('defaultLocale', defaultLocale),
27
+ availableLanguages: propOrDefault('availableLanguages', defaultAvailableLanguages, true),
28
+ availableLocales: propOrDefault('availableLocales', defaultAvailableLocales, true),
29
+ brand: adminUiConfig === null || adminUiConfig === void 0 ? void 0 : adminUiConfig.brand,
30
+ hideVendureBranding: propOrDefault('hideVendureBranding', (adminUiConfig === null || adminUiConfig === void 0 ? void 0 : adminUiConfig.hideVendureBranding) || false),
31
+ hideVersion: propOrDefault('hideVersion', (adminUiConfig === null || adminUiConfig === void 0 ? void 0 : adminUiConfig.hideVersion) || false),
32
+ loginImageUrl: adminUiConfig === null || adminUiConfig === void 0 ? void 0 : adminUiConfig.loginImageUrl,
33
+ cancellationReasons: propOrDefault('cancellationReasons', undefined),
34
+ };
35
+ }
@@ -0,0 +1,24 @@
1
+ import { Plugin } from 'vite';
2
+ export type FieldInfoTuple = readonly [
3
+ type: string,
4
+ nullable: boolean,
5
+ list: boolean,
6
+ isPaginatedList: boolean
7
+ ];
8
+ export interface SchemaInfo {
9
+ types: {
10
+ [typename: string]: {
11
+ [fieldname: string]: FieldInfoTuple;
12
+ };
13
+ };
14
+ inputs: {
15
+ [typename: string]: {
16
+ [fieldname: string]: FieldInfoTuple;
17
+ };
18
+ };
19
+ scalars: string[];
20
+ enums: {
21
+ [typename: string]: string[];
22
+ };
23
+ }
24
+ export declare function adminApiSchemaPlugin(): Plugin;
@@ -0,0 +1,82 @@
1
+ import { GraphQLList, GraphQLNonNull, GraphQLObjectType, isEnumType, isInputObjectType, isObjectType, isScalarType, } from 'graphql';
2
+ import { generateSchema } from './schema-generator.js';
3
+ import { getConfigLoaderApi } from './vite-plugin-config-loader.js';
4
+ const virtualModuleId = 'virtual:admin-api-schema';
5
+ const resolvedVirtualModuleId = `\0${virtualModuleId}`;
6
+ export function adminApiSchemaPlugin() {
7
+ let configLoaderApi;
8
+ let schemaInfo;
9
+ return {
10
+ name: 'vendure:admin-api-schema',
11
+ configResolved({ plugins }) {
12
+ configLoaderApi = getConfigLoaderApi(plugins);
13
+ },
14
+ async buildStart() {
15
+ const vendureConfig = await configLoaderApi.getVendureConfig();
16
+ if (!schemaInfo) {
17
+ const safeSchema = await generateSchema({ vendureConfig });
18
+ schemaInfo = generateSchemaInfo(safeSchema);
19
+ }
20
+ },
21
+ resolveId(id) {
22
+ if (id === virtualModuleId) {
23
+ return resolvedVirtualModuleId;
24
+ }
25
+ },
26
+ load(id) {
27
+ if (id === resolvedVirtualModuleId) {
28
+ return `
29
+ export const schemaInfo = ${JSON.stringify(schemaInfo)};
30
+ `;
31
+ }
32
+ },
33
+ };
34
+ }
35
+ function getTypeInfo(type) {
36
+ let nullable = true;
37
+ let list = false;
38
+ let isPaginatedList = false;
39
+ // Unwrap NonNull
40
+ if (type instanceof GraphQLNonNull) {
41
+ nullable = false;
42
+ type = type.ofType;
43
+ }
44
+ // Unwrap List
45
+ if (type instanceof GraphQLList) {
46
+ list = true;
47
+ type = type.ofType;
48
+ }
49
+ if (type instanceof GraphQLObjectType) {
50
+ if (type.getInterfaces().some(i => i.name === 'PaginatedList')) {
51
+ isPaginatedList = true;
52
+ }
53
+ }
54
+ return [type.toString().replace(/!$/, ''), nullable, list, isPaginatedList];
55
+ }
56
+ function generateSchemaInfo(schema) {
57
+ const types = schema.getTypeMap();
58
+ const result = { types: {}, inputs: {}, scalars: [], enums: {} };
59
+ Object.values(types).forEach(type => {
60
+ if (isObjectType(type)) {
61
+ const fields = type.getFields();
62
+ result.types[type.name] = {};
63
+ Object.entries(fields).forEach(([fieldName, field]) => {
64
+ result.types[type.name][fieldName] = getTypeInfo(field.type);
65
+ });
66
+ }
67
+ if (isInputObjectType(type)) {
68
+ const fields = type.getFields();
69
+ result.inputs[type.name] = {};
70
+ Object.entries(fields).forEach(([fieldName, field]) => {
71
+ result.inputs[type.name][fieldName] = getTypeInfo(field.type);
72
+ });
73
+ }
74
+ if (isScalarType(type)) {
75
+ result.scalars.push(type.name);
76
+ }
77
+ if (isEnumType(type)) {
78
+ result.enums[type.name] = type.getValues().map(v => v.value);
79
+ }
80
+ });
81
+ return result;
82
+ }
@@ -0,0 +1,17 @@
1
+ import { VendureConfig } from '@vendure/core';
2
+ import { Plugin } from 'vite';
3
+ import { ConfigLoaderOptions } from './config-loader.js';
4
+ export interface ConfigLoaderApi {
5
+ getVendureConfig(): Promise<VendureConfig>;
6
+ }
7
+ export declare const configLoaderName = "vendure:config-loader";
8
+ /**
9
+ * This Vite plugin loads the VendureConfig from the specified file path, and
10
+ * makes it available to other plugins via the `ConfigLoaderApi`.
11
+ */
12
+ export declare function configLoaderPlugin(options: ConfigLoaderOptions): Plugin;
13
+ /**
14
+ * Inter-plugin dependencies implemented following the pattern given here:
15
+ * https://rollupjs.org/plugin-development/#direct-plugin-communication
16
+ */
17
+ export declare function getConfigLoaderApi(plugins: readonly Plugin[]): ConfigLoaderApi;
@@ -0,0 +1,56 @@
1
+ import { loadVendureConfig } from './config-loader.js';
2
+ export const configLoaderName = 'vendure:config-loader';
3
+ /**
4
+ * This Vite plugin loads the VendureConfig from the specified file path, and
5
+ * makes it available to other plugins via the `ConfigLoaderApi`.
6
+ */
7
+ export function configLoaderPlugin(options) {
8
+ let vendureConfig;
9
+ const onConfigLoaded = [];
10
+ return {
11
+ name: configLoaderName,
12
+ async buildStart() {
13
+ this.info(`Loading Vendure config...`);
14
+ try {
15
+ const result = await loadVendureConfig({
16
+ tempDir: options.tempDir,
17
+ vendureConfigPath: options.vendureConfigPath,
18
+ vendureConfigExport: options.vendureConfigExport,
19
+ });
20
+ vendureConfig = result.vendureConfig;
21
+ this.info(`Vendure config loaded (using export "${result.exportedSymbolName}")`);
22
+ }
23
+ catch (e) {
24
+ if (e instanceof Error) {
25
+ this.error(`Error loading Vendure config: ${e.message}`);
26
+ }
27
+ }
28
+ onConfigLoaded.forEach(fn => fn());
29
+ },
30
+ api: {
31
+ getVendureConfig() {
32
+ if (vendureConfig) {
33
+ return Promise.resolve(vendureConfig);
34
+ }
35
+ else {
36
+ return new Promise(resolve => {
37
+ onConfigLoaded.push(() => {
38
+ resolve(vendureConfig);
39
+ });
40
+ });
41
+ }
42
+ },
43
+ },
44
+ };
45
+ }
46
+ /**
47
+ * Inter-plugin dependencies implemented following the pattern given here:
48
+ * https://rollupjs.org/plugin-development/#direct-plugin-communication
49
+ */
50
+ export function getConfigLoaderApi(plugins) {
51
+ const parentPlugin = plugins.find(plugin => plugin.name === configLoaderName);
52
+ if (!parentPlugin) {
53
+ throw new Error(`This plugin depends on the "${configLoaderName}" plugin.`);
54
+ }
55
+ return parentPlugin.api;
56
+ }
@@ -0,0 +1,4 @@
1
+ import { Plugin } from 'vite';
2
+ export declare function viteConfigPlugin({ packageRoot }: {
3
+ packageRoot: string;
4
+ }): Plugin;
@@ -0,0 +1,38 @@
1
+ import path from 'path';
2
+ export function viteConfigPlugin({ packageRoot }) {
3
+ return {
4
+ name: 'vendure:vite-config-plugin',
5
+ config: (config) => {
6
+ var _a, _b;
7
+ config.root = packageRoot;
8
+ config.resolve = {
9
+ alias: {
10
+ '@': path.resolve(packageRoot, './src/lib'),
11
+ },
12
+ };
13
+ // This is required to prevent Vite from pre-bundling the
14
+ // dashboard source when it resides in node_modules.
15
+ config.optimizeDeps = Object.assign(Object.assign({}, config.optimizeDeps), { exclude: [
16
+ ...(((_a = config.optimizeDeps) === null || _a === void 0 ? void 0 : _a.exclude) || []),
17
+ '@vendure/dashboard',
18
+ '@/providers',
19
+ '@/framework',
20
+ '@/lib',
21
+ '@/components',
22
+ '@/hooks',
23
+ 'virtual:vendure-ui-config',
24
+ 'virtual:admin-api-schema',
25
+ 'virtual:dashboard-extensions',
26
+ ],
27
+ // We however do want to pre-bundle recharts, as it depends
28
+ // on lodash which is a CJS packages and _does_ require
29
+ // pre-bundling.
30
+ include: [
31
+ ...(((_b = config.optimizeDeps) === null || _b === void 0 ? void 0 : _b.include) || []),
32
+ '@/components > recharts',
33
+ '@/components > react-dropzone',
34
+ ] });
35
+ return config;
36
+ },
37
+ };
38
+ }
@@ -0,0 +1,9 @@
1
+ import { Plugin } from 'vite';
2
+ /**
3
+ * This Vite plugin scans the configured plugins for any dashboard extensions and dynamically
4
+ * generates an import statement for each one, wrapped up in a `runDashboardExtensions()`
5
+ * function which can then be imported and executed in the Dashboard app.
6
+ */
7
+ export declare function dashboardMetadataPlugin(options: {
8
+ rootDir: string;
9
+ }): Plugin;
@@ -0,0 +1,52 @@
1
+ import { getPluginDashboardExtensions } from '@vendure/core';
2
+ import path from 'path';
3
+ import { getConfigLoaderApi } from './vite-plugin-config-loader.js';
4
+ const virtualModuleId = 'virtual:dashboard-extensions';
5
+ const resolvedVirtualModuleId = `\0${virtualModuleId}`;
6
+ /**
7
+ * This Vite plugin scans the configured plugins for any dashboard extensions and dynamically
8
+ * generates an import statement for each one, wrapped up in a `runDashboardExtensions()`
9
+ * function which can then be imported and executed in the Dashboard app.
10
+ */
11
+ export function dashboardMetadataPlugin(options) {
12
+ let configLoaderApi;
13
+ let vendureConfig;
14
+ return {
15
+ name: 'vendure:dashboard-extensions-metadata',
16
+ configResolved({ plugins }) {
17
+ configLoaderApi = getConfigLoaderApi(plugins);
18
+ },
19
+ resolveId(id) {
20
+ if (id === virtualModuleId) {
21
+ return resolvedVirtualModuleId;
22
+ }
23
+ },
24
+ async load(id) {
25
+ var _a;
26
+ if (id === resolvedVirtualModuleId) {
27
+ if (!vendureConfig) {
28
+ vendureConfig = await configLoaderApi.getVendureConfig();
29
+ }
30
+ const extensions = getPluginDashboardExtensions((_a = vendureConfig.plugins) !== null && _a !== void 0 ? _a : []);
31
+ const extensionData = extensions.map(extension => {
32
+ const providedPath = typeof extension === 'string' ? extension : extension.location;
33
+ const jsPath = normalizeImportPath(options.rootDir, providedPath);
34
+ return { importPath: `./${jsPath}` };
35
+ });
36
+ this.info(`Found ${extensionData.length} Dashboard extensions`);
37
+ return `
38
+ export async function runDashboardExtensions() {
39
+ ${extensionData.map(extension => `await import('${extension.importPath}');`).join('\n')}
40
+ }
41
+ `;
42
+ }
43
+ },
44
+ };
45
+ }
46
+ /**
47
+ * Converts an import path to a normalized path relative to the rootDir.
48
+ */
49
+ function normalizeImportPath(rootDir, importPath) {
50
+ const relativePath = path.relative(rootDir, importPath).replace(/\\/g, '/');
51
+ return relativePath.replace(/\.tsx?$/, '.js');
52
+ }
@@ -0,0 +1,6 @@
1
+ import { Plugin } from 'vite';
2
+ export declare function gqlTadaPlugin(options: {
3
+ gqlTadaOutputPath: string;
4
+ tempDir: string;
5
+ packageRoot: string;
6
+ }): Plugin;
@@ -0,0 +1,51 @@
1
+ import { generateOutput } from '@gql.tada/cli-utils';
2
+ import * as fs from 'fs/promises';
3
+ import { printSchema } from 'graphql';
4
+ import * as path from 'path';
5
+ import { generateSchema } from './schema-generator.js';
6
+ import { getConfigLoaderApi } from './vite-plugin-config-loader.js';
7
+ export function gqlTadaPlugin(options) {
8
+ let configLoaderApi;
9
+ return {
10
+ name: 'vendure:gql-tada',
11
+ configResolved({ plugins }) {
12
+ configLoaderApi = getConfigLoaderApi(plugins);
13
+ },
14
+ async buildStart() {
15
+ const vendureConfig = await configLoaderApi.getVendureConfig();
16
+ const safeSchema = await generateSchema({ vendureConfig });
17
+ const tsConfigContent = {
18
+ compilerOptions: {
19
+ plugins: [
20
+ {
21
+ name: 'gql.tada/ts-plugin',
22
+ schema: './schema.graphql',
23
+ },
24
+ ],
25
+ },
26
+ };
27
+ const tsConfigPath = path.join(options.tempDir, 'tsconfig.json');
28
+ await fs.writeFile(tsConfigPath, JSON.stringify(tsConfigContent, null, 2));
29
+ const schemaPath = path.join(options.tempDir, 'schema.graphql');
30
+ await fs.writeFile(schemaPath, printSchema(safeSchema));
31
+ await generateOutput({
32
+ output: path.join(options.gqlTadaOutputPath, 'graphql-env.d.ts'),
33
+ tsconfig: tsConfigPath,
34
+ });
35
+ // Copy the graphql.ts file to the output path
36
+ const graphqlTsPath = path.join(options.packageRoot, 'src/lib/graphql/graphql.ts');
37
+ try {
38
+ await fs.copyFile(graphqlTsPath, path.join(options.gqlTadaOutputPath, 'graphql.ts'));
39
+ }
40
+ catch (error) {
41
+ if (error instanceof Error) {
42
+ this.error(error.message);
43
+ }
44
+ else {
45
+ this.error('Failed to copy graphql.ts file');
46
+ }
47
+ }
48
+ this.info('graphql introspection files output to ' + options.gqlTadaOutputPath);
49
+ },
50
+ };
51
+ }
@@ -0,0 +1,55 @@
1
+ import { Plugin } from 'vite';
2
+ type ThemeColors = {
3
+ background?: string;
4
+ foreground?: string;
5
+ card?: string;
6
+ 'card-foreground'?: string;
7
+ popover?: string;
8
+ 'popover-foreground'?: string;
9
+ primary?: string;
10
+ 'primary-foreground'?: string;
11
+ secondary?: string;
12
+ 'secondary-foreground'?: string;
13
+ muted?: string;
14
+ 'muted-foreground'?: string;
15
+ accent?: string;
16
+ 'accent-foreground'?: string;
17
+ destructive?: string;
18
+ 'destructive-foreground'?: string;
19
+ success?: string;
20
+ 'success-foreground'?: string;
21
+ 'dev-mode'?: string;
22
+ 'dev-mode-foreground'?: string;
23
+ border?: string;
24
+ input?: string;
25
+ ring?: string;
26
+ 'chart-1'?: string;
27
+ 'chart-2'?: string;
28
+ 'chart-3'?: string;
29
+ 'chart-4'?: string;
30
+ 'chart-5'?: string;
31
+ radius?: string;
32
+ sidebar?: string;
33
+ 'sidebar-foreground'?: string;
34
+ 'sidebar-primary'?: string;
35
+ 'sidebar-primary-foreground'?: string;
36
+ 'sidebar-accent'?: string;
37
+ 'sidebar-accent-foreground'?: string;
38
+ 'sidebar-border'?: string;
39
+ 'sidebar-ring'?: string;
40
+ brand?: string;
41
+ 'brand-lighter'?: string;
42
+ 'brand-darker'?: string;
43
+ 'font-sans'?: string;
44
+ 'font-mono'?: string;
45
+ [key: string]: string | undefined;
46
+ };
47
+ export interface ThemeVariables {
48
+ light?: ThemeColors;
49
+ dark?: ThemeColors;
50
+ }
51
+ export type ThemeVariablesPluginOptions = {
52
+ theme?: ThemeVariables;
53
+ };
54
+ export declare function themeVariablesPlugin(options: ThemeVariablesPluginOptions): Plugin;
55
+ export {};
@@ -0,0 +1,130 @@
1
+ const defaultVariables = {
2
+ light: {
3
+ background: 'hsl(0 0% 100%)',
4
+ foreground: 'hsl(0 0% 3.9%)',
5
+ card: 'hsl(0 0% 100%)',
6
+ 'card-foreground': 'hsl(0 0% 3.9%)',
7
+ popover: 'hsl(0 0% 100%)',
8
+ 'popover-foreground': 'hsl(0 0% 3.9%)',
9
+ primary: 'hsl(0 0% 9%)',
10
+ 'primary-foreground': 'hsl(0 0% 98%)',
11
+ secondary: 'hsl(0 0% 96.1%)',
12
+ 'secondary-foreground': 'hsl(0 0% 9%)',
13
+ muted: 'hsl(0 0% 96.1%)',
14
+ 'muted-foreground': 'hsl(0 0% 45.1%)',
15
+ accent: 'hsl(0 0% 96.1%)',
16
+ 'accent-foreground': 'hsl(0 0% 9%)',
17
+ destructive: 'hsl(0 84.2% 60.2%)',
18
+ 'destructive-foreground': 'hsl(0 0% 98%)',
19
+ success: 'hsl(100, 81%, 35%)',
20
+ 'success-foreground': 'hsl(0 0% 98%)',
21
+ 'dev-mode': 'hsl(204, 76%, 62%)',
22
+ 'dev-mode-foreground': 'hsl(0 0% 98%)',
23
+ border: 'hsl(0 0% 89.8%)',
24
+ input: 'hsl(0 0% 89.8%)',
25
+ ring: 'hsl(0 0% 3.9%)',
26
+ 'chart-1': 'hsl(12 76% 61%)',
27
+ 'chart-2': 'hsl(173 58% 39%)',
28
+ 'chart-3': 'hsl(197 37% 24%)',
29
+ 'chart-4': 'hsl(43 74% 66%)',
30
+ 'chart-5': 'hsl(27 87% 67%)',
31
+ radius: '0.6rem',
32
+ sidebar: 'hsl(0 0% 98%)',
33
+ 'sidebar-foreground': 'hsl(240 5.3% 26.1%)',
34
+ 'sidebar-primary': 'hsl(240 5.9% 10%)',
35
+ 'sidebar-primary-foreground': 'hsl(0 0% 98%)',
36
+ 'sidebar-accent': 'hsl(0, 0%, 92%)',
37
+ 'sidebar-accent-foreground': 'hsl(240 5.9% 10%)',
38
+ 'sidebar-border': 'hsl(220 13% 91%)',
39
+ 'sidebar-ring': 'hsl(217.2 91.2% 59.8%)',
40
+ brand: '#17c1ff',
41
+ 'brand-lighter': '#e6f9ff',
42
+ 'brand-darker': '#0099ff',
43
+ 'font-sans': "'Geist', sans-serif",
44
+ 'font-mono': "'Geist Mono', monospace",
45
+ },
46
+ dark: {
47
+ background: 'hsl(0 0% 3.9%)',
48
+ foreground: 'hsl(0 0% 98%)',
49
+ card: 'hsl(0 0% 3.9%)',
50
+ 'card-foreground': 'hsl(0 0% 98%)',
51
+ popover: 'hsl(0 0% 3.9%)',
52
+ 'popover-foreground': 'hsl(0 0% 98%)',
53
+ primary: 'hsl(0 0% 98%)',
54
+ 'primary-foreground': 'hsl(0 0% 9%)',
55
+ secondary: 'hsl(0 0% 14.9%)',
56
+ 'secondary-foreground': 'hsl(0 0% 98%)',
57
+ muted: 'hsl(0 0% 14.9%)',
58
+ 'muted-foreground': 'hsl(0 0% 63.9%)',
59
+ accent: 'hsl(0 0% 14.9%)',
60
+ 'accent-foreground': 'hsl(0 0% 98%)',
61
+ destructive: 'hsl(0 62.8% 30.6%)',
62
+ 'destructive-foreground': 'hsl(0 0% 98%)',
63
+ success: 'hsl(100, 100%, 35%)',
64
+ 'success-foreground': 'hsl(0 0% 98%)',
65
+ 'dev-mode': 'hsl(204, 86%, 53%)',
66
+ 'dev-mode-foreground': 'hsl(0 0% 98%)',
67
+ border: 'hsl(0 0% 14.9%)',
68
+ input: 'hsl(0 0% 14.9%)',
69
+ ring: 'hsl(0 0% 83.1%)',
70
+ 'chart-1': 'hsl(220 70% 50%)',
71
+ 'chart-2': 'hsl(160 60% 45%)',
72
+ 'chart-3': 'hsl(30 80% 55%)',
73
+ 'chart-4': 'hsl(280 65% 60%)',
74
+ 'chart-5': 'hsl(340 75% 55%)',
75
+ sidebar: 'hsl(240 5.9% 10%)',
76
+ 'sidebar-foreground': 'hsl(240 4.8% 95.9%)',
77
+ 'sidebar-primary': 'hsl(224.3 76.3% 48%)',
78
+ 'sidebar-primary-foreground': 'hsl(0 0% 100%)',
79
+ 'sidebar-accent': 'hsl(240 3.7% 15.9%)',
80
+ 'sidebar-accent-foreground': 'hsl(240 4.8% 95.9%)',
81
+ 'sidebar-border': 'hsl(240 3.7% 15.9%)',
82
+ 'sidebar-ring': 'hsl(217.2 91.2% 59.8%)',
83
+ brand: '#17c1ff',
84
+ 'brand-lighter': '#e6f9ff',
85
+ 'brand-darker': '#0099ff',
86
+ 'font-sans': "'Geist', sans-serif",
87
+ 'font-mono': "'Geist Mono', monospace",
88
+ },
89
+ };
90
+ export function themeVariablesPlugin(options) {
91
+ const virtualModuleId = 'virtual:admin-theme';
92
+ const resolvedVirtualModuleId = `\0${virtualModuleId}`;
93
+ return {
94
+ name: 'vendure:admin-theme',
95
+ enforce: 'pre', // This ensures our plugin runs before other CSS processors
96
+ transform(code, id) {
97
+ var _a, _b;
98
+ // Only transform CSS files
99
+ if (!id.endsWith('styles.css')) {
100
+ return null;
101
+ }
102
+ // Replace the @import 'virtual:admin-theme'; with our theme variables
103
+ if (code.includes('@import "virtual:admin-theme";') ||
104
+ code.includes("@import 'virtual:admin-theme';")) {
105
+ const lightTheme = ((_a = options.theme) === null || _a === void 0 ? void 0 : _a.light) || {};
106
+ const darkTheme = ((_b = options.theme) === null || _b === void 0 ? void 0 : _b.dark) || {};
107
+ // Merge default themes with custom themes
108
+ const mergedLightTheme = Object.assign(Object.assign({}, defaultVariables.light), lightTheme);
109
+ const mergedDarkTheme = Object.assign(Object.assign({}, defaultVariables.dark), darkTheme);
110
+ const themeCSS = `
111
+ :root {
112
+ ${Object.entries(mergedLightTheme)
113
+ .filter(([key, value]) => value !== undefined)
114
+ .map(([key, value]) => `--${key}: ${value};`)
115
+ .join('\n')}
116
+ }
117
+
118
+ .dark {
119
+ ${Object.entries(mergedDarkTheme)
120
+ .filter(([key, value]) => value !== undefined)
121
+ .map(([key, value]) => `--${key}: ${value};`)
122
+ .join('\n')}
123
+ }
124
+ `;
125
+ return code.replace(/@import ['"]virtual:admin-theme['"];?/, themeCSS);
126
+ }
127
+ return null;
128
+ },
129
+ };
130
+ }
@@ -0,0 +1,15 @@
1
+ import { AdminUiConfig } from '@vendure/core';
2
+ import { Plugin } from 'vite';
3
+ export type UiConfigPluginOptions = {
4
+ /**
5
+ * @description
6
+ * The admin UI config to be passed to the Vendure Dashboard.
7
+ */
8
+ adminUiConfig?: Partial<AdminUiConfig>;
9
+ };
10
+ /**
11
+ * This Vite plugin scans the configured plugins for any dashboard extensions and dynamically
12
+ * generates an import statement for each one, wrapped up in a `runDashboardExtensions()`
13
+ * function which can then be imported and executed in the Dashboard app.
14
+ */
15
+ export declare function uiConfigPlugin({ adminUiConfig }: UiConfigPluginOptions): Plugin;
@@ -0,0 +1,43 @@
1
+ import path from 'path';
2
+ import { getAdminUiConfig } from './ui-config.js';
3
+ import { getConfigLoaderApi } from './vite-plugin-config-loader.js';
4
+ const virtualModuleId = 'virtual:vendure-ui-config';
5
+ const resolvedVirtualModuleId = `\0${virtualModuleId}`;
6
+ /**
7
+ * This Vite plugin scans the configured plugins for any dashboard extensions and dynamically
8
+ * generates an import statement for each one, wrapped up in a `runDashboardExtensions()`
9
+ * function which can then be imported and executed in the Dashboard app.
10
+ */
11
+ export function uiConfigPlugin({ adminUiConfig }) {
12
+ let configLoaderApi;
13
+ let vendureConfig;
14
+ return {
15
+ name: 'vendure:dashboard-ui-config',
16
+ configResolved({ plugins }) {
17
+ configLoaderApi = getConfigLoaderApi(plugins);
18
+ },
19
+ resolveId(id) {
20
+ if (id === virtualModuleId) {
21
+ return resolvedVirtualModuleId;
22
+ }
23
+ },
24
+ async load(id) {
25
+ if (id === resolvedVirtualModuleId) {
26
+ if (!vendureConfig) {
27
+ vendureConfig = await configLoaderApi.getVendureConfig();
28
+ }
29
+ const config = getAdminUiConfig(vendureConfig, adminUiConfig);
30
+ return `
31
+ export const uiConfig = ${JSON.stringify(config)}
32
+ `;
33
+ }
34
+ },
35
+ };
36
+ }
37
+ /**
38
+ * Converts an import path to a normalized path relative to the rootDir.
39
+ */
40
+ function normalizeImportPath(rootDir, importPath) {
41
+ const relativePath = path.relative(rootDir, importPath).replace(/\\/g, '/');
42
+ return relativePath.replace(/\.tsx?$/, '.js');
43
+ }
@@ -0,0 +1,36 @@
1
+ import { PluginOption } from 'vite';
2
+ import { ThemeVariablesPluginOptions } from './vite-plugin-theme.js';
3
+ import { UiConfigPluginOptions } from './vite-plugin-ui-config.js';
4
+ /**
5
+ * @description
6
+ * Options for the {@link vendureDashboardPlugin} Vite plugin.
7
+ */
8
+ export type VitePluginVendureDashboardOptions = {
9
+ /**
10
+ * @description
11
+ * The path to the Vendure server configuration file.
12
+ */
13
+ vendureConfigPath: string | URL;
14
+ /**
15
+ * @description
16
+ * The name of the exported variable from the Vendure server configuration file.
17
+ * This is only required if the plugin is unable to auto-detect the name of the exported variable.
18
+ */
19
+ vendureConfigExport?: string;
20
+ /**
21
+ * @description
22
+ * The path to the directory where the generated GraphQL Tada files will be output.
23
+ */
24
+ gqlTadaOutputPath?: string;
25
+ tempCompilationDir?: string;
26
+ disableTansStackRouterPlugin?: boolean;
27
+ } & UiConfigPluginOptions & ThemeVariablesPluginOptions;
28
+ /**
29
+ * @description
30
+ * This is a Vite plugin which configures a set of plugins required to build the Vendure Dashboard.
31
+ */
32
+ export declare function vendureDashboardPlugin(options: VitePluginVendureDashboardOptions): PluginOption[];
33
+ /**
34
+ * Get the normalized path to the Vendure config file given either a string or URL.
35
+ */
36
+ export declare function getNormalizedVendureConfigPath(vendureConfigPath: string | URL): string;
@@ -0,0 +1,83 @@
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 { adminApiSchemaPlugin } from './vite-plugin-admin-api-schema.js';
6
+ import { configLoaderPlugin } from './vite-plugin-config-loader.js';
7
+ import { viteConfigPlugin } from './vite-plugin-config.js';
8
+ import { dashboardMetadataPlugin } from './vite-plugin-dashboard-metadata.js';
9
+ import { gqlTadaPlugin } from './vite-plugin-gql-tada.js';
10
+ import { themeVariablesPlugin } from './vite-plugin-theme.js';
11
+ import { uiConfigPlugin } from './vite-plugin-ui-config.js';
12
+ /**
13
+ * @description
14
+ * This is a Vite plugin which configures a set of plugins required to build the Vendure Dashboard.
15
+ */
16
+ export function vendureDashboardPlugin(options) {
17
+ var _a;
18
+ const tempDir = (_a = options.tempCompilationDir) !== null && _a !== void 0 ? _a : path.join(import.meta.dirname, './.vendure-dashboard-temp');
19
+ const normalizedVendureConfigPath = getNormalizedVendureConfigPath(options.vendureConfigPath);
20
+ const packageRoot = getDashboardPackageRoot();
21
+ const linguiConfigPath = path.join(packageRoot, 'lingui.config.js');
22
+ if (process.env.IS_LOCAL_DEV !== 'true') {
23
+ process.env.LINGUI_CONFIG = linguiConfigPath;
24
+ }
25
+ return [
26
+ // TODO: solve https://github.com/kentcdodds/babel-plugin-macros/issues/87
27
+ // lingui(),
28
+ ...(options.disableTansStackRouterPlugin
29
+ ? []
30
+ : [
31
+ TanStackRouterVite({
32
+ autoCodeSplitting: true,
33
+ routeFileIgnorePattern: '.graphql.ts|components',
34
+ routesDirectory: path.join(packageRoot, 'src/app/routes'),
35
+ generatedRouteTree: path.join(packageRoot, 'src/app/routeTree.gen.ts'),
36
+ }),
37
+ ]),
38
+ react({
39
+ // babel: {
40
+ // plugins: ['@lingui/babel-plugin-lingui-macro'],
41
+ // },
42
+ }),
43
+ themeVariablesPlugin({ theme: options.theme }),
44
+ tailwindcss(),
45
+ configLoaderPlugin({ vendureConfigPath: normalizedVendureConfigPath, tempDir }),
46
+ viteConfigPlugin({ packageRoot }),
47
+ adminApiSchemaPlugin(),
48
+ dashboardMetadataPlugin({ rootDir: tempDir }),
49
+ uiConfigPlugin({ adminUiConfig: options.adminUiConfig }),
50
+ ...(options.gqlTadaOutputPath
51
+ ? [gqlTadaPlugin({ gqlTadaOutputPath: options.gqlTadaOutputPath, tempDir, packageRoot })]
52
+ : []),
53
+ ];
54
+ }
55
+ /**
56
+ * @description
57
+ * Returns the path to the root of the `@vendure/dashboard` package.
58
+ */
59
+ function getDashboardPackageRoot() {
60
+ const fileUrl = import.meta.resolve('@vendure/dashboard');
61
+ const packagePath = fileUrl.startsWith('file:') ? new URL(fileUrl).pathname : fileUrl;
62
+ return fixWindowsPath(path.join(packagePath, '../../../'));
63
+ }
64
+ /**
65
+ * Get the normalized path to the Vendure config file given either a string or URL.
66
+ */
67
+ export function getNormalizedVendureConfigPath(vendureConfigPath) {
68
+ const stringPath = typeof vendureConfigPath === 'string' ? vendureConfigPath : vendureConfigPath.href;
69
+ if (stringPath.startsWith('file:')) {
70
+ return fixWindowsPath(new URL(stringPath).pathname);
71
+ }
72
+ return fixWindowsPath(stringPath);
73
+ }
74
+ function fixWindowsPath(filePath) {
75
+ // Fix Windows paths that might start with a leading slash
76
+ if (process.platform === 'win32') {
77
+ // Remove leading slash before drive letter on Windows
78
+ if (/^[/\\][A-Za-z]:/.test(filePath)) {
79
+ return filePath.substring(1);
80
+ }
81
+ }
82
+ return filePath;
83
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vendure/dashboard",
3
3
  "private": false,
4
- "version": "3.2.1",
4
+ "version": "3.2.2",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -14,9 +14,8 @@
14
14
  },
15
15
  "scripts": {
16
16
  "dev": "vite",
17
- "build:lib": "vite build --config vite.config.lib.mts",
18
- "build:plugin": "tsc --project tsconfig.plugin.json",
19
- "watch:plugin": "tsc --project tsconfig.plugin.json --watch",
17
+ "build": "tsc --project tsconfig.plugin.json",
18
+ "watch": "tsc --project tsconfig.plugin.json --watch",
20
19
  "test": "vitest run",
21
20
  "lint": "eslint .",
22
21
  "preview": "vite preview",
@@ -85,6 +84,8 @@
85
84
  "@types/react-dom": "^19.0.4",
86
85
  "@types/react-grid-layout": "^1.3.5",
87
86
  "@uidotdev/usehooks": "^2.4.1",
87
+ "@vendure/common": "3.2.2",
88
+ "@vendure/core": "3.2.2",
88
89
  "@vitejs/plugin-react": "^4.3.4",
89
90
  "awesome-graphql-client": "^2.1.0",
90
91
  "class-variance-authority": "^0.7.1",
@@ -123,5 +124,5 @@
123
124
  "globals": "^15.14.0",
124
125
  "vite-plugin-dts": "^4.5.3"
125
126
  },
126
- "gitHead": "d86ca35d52e64990f5cb17dad476c6315a2e548c"
127
+ "gitHead": "8729e7f8f028be556543c8e971e750228e516919"
127
128
  }