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:
11
test/common.ts
Normal file
11
test/common.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import path from 'node:path';
|
||||
export const projectPath = path.join('/workspace/projects/project-search');
|
||||
|
||||
import { ProjectManager } from '../src/index';
|
||||
import { useKey } from '@kevisual/context';
|
||||
|
||||
export const manager = new ProjectManager({
|
||||
meiliSearchOptions: {
|
||||
apiKey: useKey('CNB_TOKEN')
|
||||
}
|
||||
});
|
||||
11
test/file.ts
Normal file
11
test/file.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import path from "node:path";
|
||||
import { FileSearch } from "../src/file-search";
|
||||
import { projectPath } from "./common";
|
||||
const fileSearch = new FileSearch();
|
||||
|
||||
async function testSearchFiles() {
|
||||
const files = await fileSearch.searchFiles({ cwd: projectPath });
|
||||
console.log('Found files:', files);
|
||||
}
|
||||
|
||||
testSearchFiles().catch(console.error);
|
||||
19
test/remote.ts
Normal file
19
test/remote.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { app, manager } from '../src/index'
|
||||
import { RemoteApp } from '@kevisual/remote-app'
|
||||
|
||||
app.createRouteList()
|
||||
manager.init().then(() => {
|
||||
console.log('ProjectManager initialized successfully');
|
||||
}).catch((error) => {
|
||||
console.error('Failed to initialize ProjectManager:', error);
|
||||
});
|
||||
const remote = new RemoteApp({
|
||||
app,
|
||||
id: 'project-search',
|
||||
username: 'root'
|
||||
});
|
||||
const isConnect = await remote.isConnect();
|
||||
if (isConnect) {
|
||||
console.log('Remote app connected successfully', isConnect);
|
||||
remote.listenProxy();
|
||||
}
|
||||
7
test/search.ts
Normal file
7
test/search.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { manager, projectPath } from "./common";
|
||||
|
||||
manager.projectSearch.searchFiles('routes', { projectPath }).then(result => {
|
||||
console.log('Search results:', result);
|
||||
}).catch(err => {
|
||||
console.error('Search error:', err);
|
||||
});
|
||||
7
test/start.ts
Normal file
7
test/start.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { manager, projectPath } from "./common";
|
||||
|
||||
manager.addProject({
|
||||
name: 'Test Project',
|
||||
path: projectPath,
|
||||
repo: 'kevisual/test-repo',
|
||||
})
|
||||
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