feat: initialize project structure with essential files and configurations
- Add .gitignore to exclude unnecessary files and directories - Create .npmrc for npm authentication - Add AGENTS.md for project documentation - Initialize package.json with project metadata and dependencies - Implement app.ts to set up the application and project manager - Create file-search module for searching files in a directory - Set up project manager and listener for managing project files - Implement project search functionality with MeiliSearch integration - Add routes for authentication and project management - Create scheduler for task management - Add tests for file searching and project management functionalities
This commit is contained in:
41
test/wather.ts
Normal file
41
test/wather.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { subscribe } from '@parcel/watcher';
|
||||
import { debounce } from 'es-toolkit';
|
||||
import fs from 'node:fs';
|
||||
import { projectPath } from "./common";
|
||||
|
||||
// 每个路径独立的防抖处理函数
|
||||
const debouncedHandlers = new Map<string, ReturnType<typeof debounce>>();
|
||||
|
||||
const subscription = await subscribe(
|
||||
projectPath, // 监听路径(支持数组)
|
||||
async (err, events) => {
|
||||
if (err) throw err;
|
||||
for (const event of events) {
|
||||
|
||||
|
||||
// 如果已有防抖函数,先取消
|
||||
if (debouncedHandlers.has(event.path)) {
|
||||
debouncedHandlers.get(event.path)?.cancel();
|
||||
}
|
||||
|
||||
// 为每个路径创建独立的防抖处理
|
||||
const handler = debounce(() => {
|
||||
console.log(event.type, event.path, new Date()); // 'create', 'update', 'delete'...
|
||||
if (!fs.statSync(event.path).isFile()) return;
|
||||
// 跳过非文件事件
|
||||
// event: { type: 'update', path: '/path/to/file.ts', file: true }
|
||||
debouncedHandlers.delete(event.path);
|
||||
}, 300);
|
||||
|
||||
debouncedHandlers.set(event.path, handler);
|
||||
handler();
|
||||
}
|
||||
},
|
||||
{
|
||||
ignore: ['**/node_modules/**', '**/.git/**'],
|
||||
backend: 'watchman', // 可选:'fs-events'(默认)、'inotify'、'windows'、'watchman'
|
||||
}
|
||||
);
|
||||
|
||||
// 后续可取消监听
|
||||
// await subscription.unsubscribe();
|
||||
Reference in New Issue
Block a user