@vendure/dashboard 3.4.1-master-202508020237 → 3.4.1-master-202508040248
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,131 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GraphQLList,
|
|
3
|
-
GraphQLNonNull,
|
|
4
|
-
GraphQLObjectType,
|
|
5
|
-
GraphQLSchema,
|
|
6
|
-
GraphQLType,
|
|
7
|
-
isEnumType,
|
|
8
|
-
isInputObjectType,
|
|
9
|
-
isObjectType,
|
|
10
|
-
isScalarType,
|
|
11
|
-
} from 'graphql';
|
|
12
|
-
import { Plugin } from 'vite';
|
|
13
|
-
|
|
14
|
-
import { generateSchema } from './utils/schema-generator.js';
|
|
15
|
-
import { ConfigLoaderApi, getConfigLoaderApi } from './vite-plugin-config-loader.js';
|
|
16
|
-
|
|
17
|
-
export type FieldInfoTuple = readonly [
|
|
18
|
-
type: string,
|
|
19
|
-
nullable: boolean,
|
|
20
|
-
list: boolean,
|
|
21
|
-
isPaginatedList: boolean,
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
export interface SchemaInfo {
|
|
25
|
-
types: {
|
|
26
|
-
[typename: string]: {
|
|
27
|
-
[fieldname: string]: FieldInfoTuple;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
inputs: {
|
|
31
|
-
[typename: string]: {
|
|
32
|
-
[fieldname: string]: FieldInfoTuple;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
scalars: string[];
|
|
36
|
-
enums: {
|
|
37
|
-
[typename: string]: string[];
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const virtualModuleId = 'virtual:admin-api-schema';
|
|
42
|
-
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
43
|
-
|
|
44
|
-
export function adminApiSchemaPlugin(): Plugin {
|
|
45
|
-
let configLoaderApi: ConfigLoaderApi;
|
|
46
|
-
let schemaInfo: SchemaInfo;
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
name: 'vendure:admin-api-schema',
|
|
50
|
-
configResolved({ plugins }) {
|
|
51
|
-
configLoaderApi = getConfigLoaderApi(plugins);
|
|
52
|
-
},
|
|
53
|
-
async buildStart() {
|
|
54
|
-
const { vendureConfig } = await configLoaderApi.getVendureConfig();
|
|
55
|
-
if (!schemaInfo) {
|
|
56
|
-
const safeSchema = await generateSchema({ vendureConfig });
|
|
57
|
-
schemaInfo = generateSchemaInfo(safeSchema);
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
resolveId(id) {
|
|
61
|
-
if (id === virtualModuleId) {
|
|
62
|
-
return resolvedVirtualModuleId;
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
load(id) {
|
|
66
|
-
if (id === resolvedVirtualModuleId) {
|
|
67
|
-
return `
|
|
68
|
-
export const schemaInfo = ${JSON.stringify(schemaInfo)};
|
|
69
|
-
`;
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function getTypeInfo(type: GraphQLType) {
|
|
76
|
-
let nullable = true;
|
|
77
|
-
let list = false;
|
|
78
|
-
let isPaginatedList = false;
|
|
79
|
-
|
|
80
|
-
// Unwrap NonNull
|
|
81
|
-
if (type instanceof GraphQLNonNull) {
|
|
82
|
-
nullable = false;
|
|
83
|
-
type = type.ofType;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Unwrap List
|
|
87
|
-
if (type instanceof GraphQLList) {
|
|
88
|
-
list = true;
|
|
89
|
-
type = type.ofType;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (type instanceof GraphQLObjectType) {
|
|
93
|
-
if (type.getInterfaces().some(i => i.name === 'PaginatedList')) {
|
|
94
|
-
isPaginatedList = true;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return [type.toString().replace(/!$/, ''), nullable, list, isPaginatedList] as const;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function generateSchemaInfo(schema: GraphQLSchema): SchemaInfo {
|
|
102
|
-
const types = schema.getTypeMap();
|
|
103
|
-
const result: SchemaInfo = { types: {}, inputs: {}, scalars: [], enums: {} };
|
|
104
|
-
|
|
105
|
-
Object.values(types).forEach(type => {
|
|
106
|
-
if (isObjectType(type)) {
|
|
107
|
-
const fields = type.getFields();
|
|
108
|
-
result.types[type.name] = {};
|
|
109
|
-
|
|
110
|
-
Object.entries(fields).forEach(([fieldName, field]) => {
|
|
111
|
-
result.types[type.name][fieldName] = getTypeInfo(field.type);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
if (isInputObjectType(type)) {
|
|
115
|
-
const fields = type.getFields();
|
|
116
|
-
result.inputs[type.name] = {};
|
|
117
|
-
|
|
118
|
-
Object.entries(fields).forEach(([fieldName, field]) => {
|
|
119
|
-
result.inputs[type.name][fieldName] = getTypeInfo(field.type);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
if (isScalarType(type)) {
|
|
123
|
-
result.scalars.push(type.name);
|
|
124
|
-
}
|
|
125
|
-
if (isEnumType(type)) {
|
|
126
|
-
result.enums[type.name] = type.getValues().map(v => v.value);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
return result;
|
|
131
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
import { compile, CompileResult, CompilerOptions } from './utils/compiler.js';
|
|
4
|
-
import { debugLogger } from './utils/logger.js';
|
|
5
|
-
|
|
6
|
-
export interface ConfigLoaderApi {
|
|
7
|
-
getVendureConfig(): Promise<CompileResult>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const configLoaderName = 'vendure:config-loader';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* This Vite plugin loads the VendureConfig from the specified file path, and
|
|
14
|
-
* makes it available to other plugins via the `ConfigLoaderApi`.
|
|
15
|
-
*/
|
|
16
|
-
export function configLoaderPlugin(options: CompilerOptions): Plugin {
|
|
17
|
-
let result: CompileResult;
|
|
18
|
-
const onConfigLoaded: Array<() => void> = [];
|
|
19
|
-
return {
|
|
20
|
-
name: configLoaderName,
|
|
21
|
-
async buildStart() {
|
|
22
|
-
this.info(
|
|
23
|
-
`Loading Vendure config. This can take a short while depending on the size of your project...`,
|
|
24
|
-
);
|
|
25
|
-
try {
|
|
26
|
-
const startTime = Date.now();
|
|
27
|
-
result = await compile({
|
|
28
|
-
...options,
|
|
29
|
-
logger: process.env.LOG
|
|
30
|
-
? debugLogger
|
|
31
|
-
: {
|
|
32
|
-
info: (message: string) => this.info(message),
|
|
33
|
-
warn: (message: string) => this.warn(message),
|
|
34
|
-
debug: (message: string) => this.debug(message),
|
|
35
|
-
error: (message: string) => this.error(message),
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
const endTime = Date.now();
|
|
39
|
-
const duration = endTime - startTime;
|
|
40
|
-
const pluginNames = result.pluginInfo
|
|
41
|
-
.map(p => `${p.name} ${p.sourcePluginPath ? '(local)' : '(npm)'}`)
|
|
42
|
-
.join(', ');
|
|
43
|
-
this.info(`Found ${result.pluginInfo.length} plugins: ${pluginNames}`);
|
|
44
|
-
this.info(
|
|
45
|
-
`Vendure config loaded (using export "${result.exportedSymbolName}") in ${duration}ms`,
|
|
46
|
-
);
|
|
47
|
-
} catch (e: unknown) {
|
|
48
|
-
if (e instanceof Error) {
|
|
49
|
-
const message = [
|
|
50
|
-
e.message,
|
|
51
|
-
`If you are using a monorepo, you may need to provide a custom pathAdapter to resolve the paths correctly.`,
|
|
52
|
-
].join('\n');
|
|
53
|
-
this.error(`Error loading Vendure config: ${message}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
onConfigLoaded.forEach(fn => fn());
|
|
57
|
-
},
|
|
58
|
-
api: {
|
|
59
|
-
getVendureConfig(): Promise<CompileResult> {
|
|
60
|
-
if (result) {
|
|
61
|
-
return Promise.resolve(result);
|
|
62
|
-
} else {
|
|
63
|
-
return new Promise<CompileResult>(resolve => {
|
|
64
|
-
onConfigLoaded.push(() => {
|
|
65
|
-
resolve(result);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
} satisfies ConfigLoaderApi,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Inter-plugin dependencies implemented following the pattern given here:
|
|
76
|
-
* https://rollupjs.org/plugin-development/#direct-plugin-communication
|
|
77
|
-
*/
|
|
78
|
-
export function getConfigLoaderApi(plugins: readonly Plugin[]): ConfigLoaderApi {
|
|
79
|
-
const parentPlugin = plugins.find(plugin => plugin.name === configLoaderName);
|
|
80
|
-
if (!parentPlugin) {
|
|
81
|
-
throw new Error(`This plugin depends on the "${configLoaderName}" plugin.`);
|
|
82
|
-
}
|
|
83
|
-
return parentPlugin.api as ConfigLoaderApi;
|
|
84
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { ConfigEnv, Plugin, UserConfig } from 'vite';
|
|
3
|
-
|
|
4
|
-
export function viteConfigPlugin({ packageRoot }: { packageRoot: string }): Plugin {
|
|
5
|
-
return {
|
|
6
|
-
name: 'vendure:vite-config-plugin',
|
|
7
|
-
config: (config: UserConfig, env: ConfigEnv) => {
|
|
8
|
-
// Only set the vite `root` to the dashboard package when running the dev server.
|
|
9
|
-
// During a production build we still need to reference the dashboard source which
|
|
10
|
-
// lives in `node_modules`, but we don't want the build output to be emitted in there.
|
|
11
|
-
// Therefore, we set `root` only for `serve` and, for `build`, we instead make sure that
|
|
12
|
-
// an `outDir` **outside** of `node_modules` is used (defaulting to the current working
|
|
13
|
-
// directory if the user did not provide one already).
|
|
14
|
-
config.root = packageRoot;
|
|
15
|
-
|
|
16
|
-
// If we are building and no explicit outDir has been provided (or it is a relative path),
|
|
17
|
-
// set it to an **absolute** path relative to the cwd so that the output never ends up in
|
|
18
|
-
// `node_modules`.
|
|
19
|
-
if (env.command === 'build') {
|
|
20
|
-
const buildConfig = config.build ?? {};
|
|
21
|
-
|
|
22
|
-
const hasOutDir = typeof buildConfig.outDir === 'string' && buildConfig.outDir.length > 0;
|
|
23
|
-
const outDirIsAbsolute = hasOutDir && path.isAbsolute(buildConfig.outDir as string);
|
|
24
|
-
|
|
25
|
-
const normalizedOutDir = hasOutDir
|
|
26
|
-
? outDirIsAbsolute
|
|
27
|
-
? (buildConfig.outDir as string)
|
|
28
|
-
: path.resolve(process.cwd(), buildConfig.outDir as string)
|
|
29
|
-
: path.resolve(process.cwd(), 'dist');
|
|
30
|
-
|
|
31
|
-
config.build = {
|
|
32
|
-
...buildConfig,
|
|
33
|
-
outDir: normalizedOutDir,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
config.resolve = {
|
|
38
|
-
alias: {
|
|
39
|
-
...(config.resolve?.alias ?? {}),
|
|
40
|
-
// See the readme for an explanation of this alias.
|
|
41
|
-
'@/vdb': path.resolve(packageRoot, './src/lib'),
|
|
42
|
-
'@/graphql': path.resolve(packageRoot, './src/lib/graphql'),
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
// This is required to prevent Vite from pre-bundling the
|
|
46
|
-
// dashboard source when it resides in node_modules.
|
|
47
|
-
config.optimizeDeps = {
|
|
48
|
-
...config.optimizeDeps,
|
|
49
|
-
exclude: [
|
|
50
|
-
...(config.optimizeDeps?.exclude || []),
|
|
51
|
-
'@vendure/dashboard',
|
|
52
|
-
'@/vdb',
|
|
53
|
-
'virtual:vendure-ui-config',
|
|
54
|
-
'virtual:admin-api-schema',
|
|
55
|
-
'virtual:dashboard-extensions',
|
|
56
|
-
],
|
|
57
|
-
// We however do want to pre-bundle recharts, as it depends
|
|
58
|
-
// on lodash which is a CJS packages and _does_ require
|
|
59
|
-
// pre-bundling.
|
|
60
|
-
include: [
|
|
61
|
-
...(config.optimizeDeps?.include || []),
|
|
62
|
-
'@/components > recharts',
|
|
63
|
-
'@/components > react-dropzone',
|
|
64
|
-
'@vendure/common/lib/generated-types',
|
|
65
|
-
],
|
|
66
|
-
};
|
|
67
|
-
return config;
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { Plugin } from 'vite';
|
|
3
|
-
|
|
4
|
-
import { CompileResult } from './utils/compiler.js';
|
|
5
|
-
import { ConfigLoaderApi, getConfigLoaderApi } from './vite-plugin-config-loader.js';
|
|
6
|
-
|
|
7
|
-
const virtualModuleId = 'virtual:dashboard-extensions';
|
|
8
|
-
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
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 function dashboardMetadataPlugin(): Plugin {
|
|
16
|
-
let configLoaderApi: ConfigLoaderApi;
|
|
17
|
-
let loadVendureConfigResult: CompileResult;
|
|
18
|
-
return {
|
|
19
|
-
name: 'vendure:dashboard-extensions-metadata',
|
|
20
|
-
configResolved({ plugins }) {
|
|
21
|
-
configLoaderApi = getConfigLoaderApi(plugins);
|
|
22
|
-
},
|
|
23
|
-
resolveId(id) {
|
|
24
|
-
if (id === virtualModuleId) {
|
|
25
|
-
return resolvedVirtualModuleId;
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
async load(id) {
|
|
29
|
-
if (id === resolvedVirtualModuleId) {
|
|
30
|
-
const startTime = Date.now();
|
|
31
|
-
this.debug('Loading dashboard extensions...');
|
|
32
|
-
|
|
33
|
-
if (!loadVendureConfigResult) {
|
|
34
|
-
const configStart = Date.now();
|
|
35
|
-
loadVendureConfigResult = await configLoaderApi.getVendureConfig();
|
|
36
|
-
this.debug(`Loaded Vendure config in ${Date.now() - configStart}ms`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const { pluginInfo } = loadVendureConfigResult;
|
|
40
|
-
const resolveStart = Date.now();
|
|
41
|
-
const pluginsWithExtensions =
|
|
42
|
-
pluginInfo
|
|
43
|
-
?.map(({ dashboardEntryPath, pluginPath, sourcePluginPath }) => {
|
|
44
|
-
if (!dashboardEntryPath) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
// For local plugins, use the sourcePluginPath to resolve the dashboard extension
|
|
48
|
-
const basePath = sourcePluginPath
|
|
49
|
-
? path.dirname(sourcePluginPath)
|
|
50
|
-
: path.dirname(pluginPath);
|
|
51
|
-
const resolved = path.resolve(basePath, dashboardEntryPath);
|
|
52
|
-
this.debug(`Resolved extension path: ${resolved}`);
|
|
53
|
-
return resolved;
|
|
54
|
-
})
|
|
55
|
-
.filter(x => x != null) ?? [];
|
|
56
|
-
|
|
57
|
-
this.info(
|
|
58
|
-
`Found ${pluginsWithExtensions.length} Dashboard extensions in ${Date.now() - resolveStart}ms`,
|
|
59
|
-
);
|
|
60
|
-
this.debug(`Total dashboard extension loading completed in ${Date.now() - startTime}ms`);
|
|
61
|
-
|
|
62
|
-
return `
|
|
63
|
-
export async function runDashboardExtensions() {
|
|
64
|
-
${pluginsWithExtensions
|
|
65
|
-
.map(extension => {
|
|
66
|
-
return `await import(\`${extension}\`);`;
|
|
67
|
-
})
|
|
68
|
-
.join('\n')}
|
|
69
|
-
}`;
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
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 { Plugin } from 'vite';
|
|
6
|
-
|
|
7
|
-
import { generateSchema } from './utils/schema-generator.js';
|
|
8
|
-
import { ConfigLoaderApi, getConfigLoaderApi } from './vite-plugin-config-loader.js';
|
|
9
|
-
|
|
10
|
-
export function gqlTadaPlugin(options: {
|
|
11
|
-
gqlTadaOutputPath: string;
|
|
12
|
-
tempDir: string;
|
|
13
|
-
packageRoot: string;
|
|
14
|
-
}): Plugin {
|
|
15
|
-
let configLoaderApi: ConfigLoaderApi;
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
name: 'vendure:gql-tada',
|
|
19
|
-
configResolved({ plugins }) {
|
|
20
|
-
configLoaderApi = getConfigLoaderApi(plugins);
|
|
21
|
-
},
|
|
22
|
-
async buildStart() {
|
|
23
|
-
const { vendureConfig } = await configLoaderApi.getVendureConfig();
|
|
24
|
-
const safeSchema = await generateSchema({ vendureConfig });
|
|
25
|
-
|
|
26
|
-
const tsConfigContent = {
|
|
27
|
-
compilerOptions: {
|
|
28
|
-
plugins: [
|
|
29
|
-
{
|
|
30
|
-
name: 'gql.tada/ts-plugin',
|
|
31
|
-
schema: './schema.graphql',
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const tsConfigPath = path.join(options.tempDir, 'tsconfig.json');
|
|
38
|
-
await fs.writeFile(tsConfigPath, JSON.stringify(tsConfigContent, null, 2));
|
|
39
|
-
|
|
40
|
-
const schemaPath = path.join(options.tempDir, 'schema.graphql');
|
|
41
|
-
await fs.writeFile(schemaPath, printSchema(safeSchema));
|
|
42
|
-
|
|
43
|
-
await generateOutput({
|
|
44
|
-
output: path.join(options.gqlTadaOutputPath, 'graphql-env.d.ts'),
|
|
45
|
-
tsconfig: tsConfigPath,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// Copy the graphql.ts file to the output path
|
|
49
|
-
const graphqlTsPath = path.join(options.packageRoot, 'src/lib/graphql/graphql.ts');
|
|
50
|
-
try {
|
|
51
|
-
await fs.copyFile(graphqlTsPath, path.join(options.gqlTadaOutputPath, 'graphql.ts'));
|
|
52
|
-
} catch (error) {
|
|
53
|
-
if (error instanceof Error) {
|
|
54
|
-
this.error(error.message);
|
|
55
|
-
} else {
|
|
56
|
-
this.error('Failed to copy graphql.ts file');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
this.info('graphql introspection files output to ' + options.gqlTadaOutputPath);
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { Plugin } from 'vite';
|
|
3
|
-
|
|
4
|
-
import { CompileResult } from './utils/compiler.js';
|
|
5
|
-
import { ConfigLoaderApi, getConfigLoaderApi } from './vite-plugin-config-loader.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This Vite plugin transforms the `app/styles.css` file to include a `@source` directive
|
|
9
|
-
* for each dashboard extension's source directory. This allows Tailwind CSS to
|
|
10
|
-
* include styles from these extensions when processing the CSS.
|
|
11
|
-
*/
|
|
12
|
-
export function dashboardTailwindSourcePlugin(): Plugin {
|
|
13
|
-
let configLoaderApi: ConfigLoaderApi;
|
|
14
|
-
let loadVendureConfigResult: CompileResult;
|
|
15
|
-
return {
|
|
16
|
-
name: 'vendure:dashboard-tailwind-source',
|
|
17
|
-
// Ensure this plugin runs before Tailwind CSS processing
|
|
18
|
-
enforce: 'pre',
|
|
19
|
-
configResolved({ plugins }) {
|
|
20
|
-
configLoaderApi = getConfigLoaderApi(plugins);
|
|
21
|
-
},
|
|
22
|
-
async transform(src, id) {
|
|
23
|
-
if (/app\/styles.css$/.test(id)) {
|
|
24
|
-
if (!loadVendureConfigResult) {
|
|
25
|
-
loadVendureConfigResult = await configLoaderApi.getVendureConfig();
|
|
26
|
-
}
|
|
27
|
-
const { pluginInfo } = loadVendureConfigResult;
|
|
28
|
-
const dashboardExtensionDirs =
|
|
29
|
-
pluginInfo
|
|
30
|
-
?.flatMap(({ dashboardEntryPath, sourcePluginPath, pluginPath }) => {
|
|
31
|
-
if (!dashboardEntryPath) {
|
|
32
|
-
return [];
|
|
33
|
-
}
|
|
34
|
-
const sourcePaths = [];
|
|
35
|
-
if (sourcePluginPath) {
|
|
36
|
-
sourcePaths.push(
|
|
37
|
-
path.join(
|
|
38
|
-
path.dirname(sourcePluginPath),
|
|
39
|
-
path.dirname(dashboardEntryPath),
|
|
40
|
-
),
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
if (pluginPath) {
|
|
44
|
-
sourcePaths.push(
|
|
45
|
-
path.join(path.dirname(pluginPath), path.dirname(dashboardEntryPath)),
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return sourcePaths;
|
|
49
|
-
})
|
|
50
|
-
.filter(x => x != null) ?? [];
|
|
51
|
-
const sources = dashboardExtensionDirs
|
|
52
|
-
.map(extension => {
|
|
53
|
-
return `@source '${extension}';`;
|
|
54
|
-
})
|
|
55
|
-
.join('\n');
|
|
56
|
-
|
|
57
|
-
// Find the line with the specific comment and insert sources after it
|
|
58
|
-
const lines = src.split('\n');
|
|
59
|
-
const sourceCommentIndex = lines.findIndex(line =>
|
|
60
|
-
line.includes(
|
|
61
|
-
'/* @source rules from extensions will be added here by the dashboardTailwindSourcePlugin */',
|
|
62
|
-
),
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
if (sourceCommentIndex !== -1) {
|
|
66
|
-
// Insert the sources after the comment line
|
|
67
|
-
lines.splice(sourceCommentIndex + 1, 0, sources);
|
|
68
|
-
const modifiedSrc = lines.join('\n');
|
|
69
|
-
return {
|
|
70
|
-
code: modifiedSrc,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// If the comment is not found, append sources at the end
|
|
75
|
-
return {
|
|
76
|
-
code: src + '\n' + sources,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|