2023-07-29 13:09:21 +00:00
|
|
|
import houdini from 'houdini/vite'
|
|
|
|
import { sveltekit } from '@sveltejs/kit/vite'
|
|
|
|
import { defineConfig } from 'vite'
|
2023-07-22 07:29:40 +00:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import { resolve } from 'path';
|
2023-07-19 09:42:47 +00:00
|
|
|
|
2023-07-31 07:40:54 +00:00
|
|
|
// Utility function to get all .svelte or .ts files from a directory recursively
|
|
|
|
function getRecursiveFiles(dir, extension) {
|
2023-07-25 09:20:51 +00:00
|
|
|
const dirents = fs.readdirSync(dir, { withFileTypes: true });
|
|
|
|
const files = Array.from(dirents).flatMap((dirent) => {
|
|
|
|
const res = resolve(dir, dirent.name);
|
|
|
|
if (dirent.isDirectory()) {
|
2023-07-31 07:40:54 +00:00
|
|
|
return getRecursiveFiles(res, extension);
|
|
|
|
} else if (res.endsWith(extension)) {
|
2023-07-25 09:20:51 +00:00
|
|
|
return [res];
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2023-07-19 09:42:47 +00:00
|
|
|
export default defineConfig({
|
2023-07-22 07:29:40 +00:00
|
|
|
plugins: [
|
2023-07-29 13:09:21 +00:00
|
|
|
houdini(),
|
2023-07-22 07:29:40 +00:00
|
|
|
sveltekit(),
|
|
|
|
{
|
|
|
|
name: 'components-resolver',
|
|
|
|
resolveId(source) {
|
|
|
|
if (source === 'virtual:components-list') return source;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
load(id) {
|
|
|
|
if (id === 'virtual:components-list') {
|
|
|
|
const componentsDir = resolve(__dirname, 'src/lib/components');
|
2023-07-31 07:40:54 +00:00
|
|
|
const componentsFiles = getRecursiveFiles(componentsDir, '.svelte');
|
2023-07-24 07:39:33 +00:00
|
|
|
|
|
|
|
const components = componentsFiles.map(file =>
|
|
|
|
file
|
|
|
|
.replace(componentsDir, '')
|
|
|
|
.replace(/\.svelte$/, '')
|
|
|
|
.replace(/\\/g, '/') // Fix Windows path separators
|
|
|
|
.slice(1) // Remove leading "/"
|
|
|
|
);
|
2023-07-22 07:29:40 +00:00
|
|
|
|
|
|
|
return `export default ${JSON.stringify(components)};`;
|
|
|
|
}
|
|
|
|
return null;
|
2023-07-31 07:50:44 +00:00
|
|
|
},
|
|
|
|
handleHotUpdate({ file, server }) { // Add handleHotUpdate to watch for file changes
|
|
|
|
if (file.startsWith(resolve(__dirname, 'src/lib/components'))) {
|
|
|
|
server.ws.send({
|
|
|
|
type: 'full-reload',
|
|
|
|
path: '*',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2023-07-25 09:20:51 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'services-resolver',
|
|
|
|
resolveId(source) {
|
|
|
|
if (source === 'virtual:services-list') return source;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
load(id) {
|
|
|
|
if (id === 'virtual:services-list') {
|
|
|
|
const servicesDir = resolve(__dirname, 'src/lib/services');
|
2023-07-31 07:40:54 +00:00
|
|
|
const serviceFiles = getRecursiveFiles(servicesDir, '.ts');
|
2023-07-25 09:20:51 +00:00
|
|
|
|
|
|
|
const services = serviceFiles.map(file =>
|
|
|
|
file
|
|
|
|
.replace(servicesDir, '')
|
|
|
|
.replace(/\.ts$/, '')
|
|
|
|
.replace(/\\/g, '/') // Fix Windows path separators
|
|
|
|
.slice(1) // Remove leading "/"
|
|
|
|
);
|
|
|
|
|
|
|
|
return `export default ${JSON.stringify(services)};`;
|
|
|
|
}
|
|
|
|
return null;
|
2023-07-31 07:50:44 +00:00
|
|
|
},
|
|
|
|
handleHotUpdate({ file, server }) { // Add handleHotUpdate to watch for file changes
|
|
|
|
if (file.startsWith(resolve(__dirname, 'src/lib/services'))) {
|
|
|
|
server.ws.send({
|
|
|
|
type: 'full-reload',
|
|
|
|
path: '*',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2023-07-26 16:28:31 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'data-sources-resolver',
|
|
|
|
resolveId(source) {
|
|
|
|
if (source === 'virtual:data-sources-list') return source;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
load(id) {
|
|
|
|
if (id === 'virtual:data-sources-list') {
|
|
|
|
const dataDir = resolve(__dirname, 'src/lib/data');
|
2023-07-31 07:40:54 +00:00
|
|
|
const dataFiles = getRecursiveFiles(dataDir, '.ts'); // Use the same function as before
|
2023-07-26 16:28:31 +00:00
|
|
|
|
|
|
|
const dataSources = dataFiles.map(file =>
|
|
|
|
file
|
|
|
|
.replace(dataDir, '')
|
|
|
|
.replace(/\.ts$/, '')
|
|
|
|
.replace(/\\/g, '/') // Fix Windows path separators
|
|
|
|
.slice(1) // Remove leading "/"
|
|
|
|
);
|
|
|
|
|
|
|
|
return `export default ${JSON.stringify(dataSources)};`;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2023-07-22 07:29:40 +00:00
|
|
|
}
|
|
|
|
],
|
2023-07-19 09:42:47 +00:00
|
|
|
test: {
|
|
|
|
include: ['src/**/*.{test,spec}.{js,ts}']
|
|
|
|
}
|
2023-07-29 13:09:21 +00:00
|
|
|
});
|
2023-07-31 07:40:54 +00:00
|
|
|
|
2023-07-31 07:50:44 +00:00
|
|
|
|