mirror of
https://github.com/LukeHagar/skeleton.git
synced 2025-12-06 04:21:15 +00:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import type { Plugin } from 'vite';
|
|
import { Minimatch } from 'minimatch';
|
|
import { exec } from 'child_process';
|
|
import { join, resolve, basename } from 'path';
|
|
|
|
export default function skeletonPluginWatcher(): Plugin {
|
|
const pluginSrcPath = resolve('.', join('..', '..', 'packages', 'plugin', 'src'));
|
|
const mm = new Minimatch(join(pluginSrcPath, '**/*'));
|
|
let locked = false;
|
|
|
|
return {
|
|
name: 'skeleton-plugin-watcher',
|
|
configureServer(vite) {
|
|
vite.watcher.add(pluginSrcPath);
|
|
vite.watcher.on('all', async (event, path) => {
|
|
if (mm.match(path) && !path.includes('/generated/')) {
|
|
console.log(`[TW Plugin]: File Updated: ${basename(path)}`);
|
|
if (!locked) {
|
|
locked = true;
|
|
const now = Date.now();
|
|
exec('pnpm -F @skeletonlabs/tw-plugin build', () => {
|
|
console.log(`[TW Plugin]: Completed in ${Date.now() - now}ms`);
|
|
locked = false;
|
|
});
|
|
}
|
|
}
|
|
});
|
|
},
|
|
async buildStart() {
|
|
const now = Date.now();
|
|
exec('pnpm -F @skeletonlabs/tw-plugin build', () => {
|
|
console.log(`[TW Plugin]: Completed in ${Date.now() - now}ms`);
|
|
});
|
|
}
|
|
};
|
|
}
|