feat: add project context model
This commit is contained in:
parent
0e3815ac3c
commit
0b127b5404
4 changed files with 54 additions and 1 deletions
25
src/lib/project-context.ts
Normal file
25
src/lib/project-context.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import path from 'node:path';
|
||||
|
||||
import { canonicalizeWindowsPath, toDisplayPath, windowsPathKey } from './pathing';
|
||||
import type { ProjectContext, ProjectSource } from './types';
|
||||
|
||||
interface BuildProjectContextOptions {
|
||||
source?: ProjectSource;
|
||||
addedAt?: string | null;
|
||||
}
|
||||
|
||||
export function buildProjectContext(root: string, options: BuildProjectContextOptions = {}): ProjectContext {
|
||||
if (!root) {
|
||||
throw new Error('Project root is required to build project context.');
|
||||
}
|
||||
|
||||
const normalizedRoot = canonicalizeWindowsPath(root);
|
||||
return {
|
||||
key: windowsPathKey(normalizedRoot),
|
||||
root: normalizedRoot,
|
||||
displayPath: toDisplayPath(normalizedRoot),
|
||||
name: path.basename(normalizedRoot),
|
||||
source: options.source ?? 'local',
|
||||
addedAt: options.addedAt ?? null,
|
||||
};
|
||||
}
|
||||
|
|
@ -59,3 +59,16 @@ export interface ParseableBeadIssue extends Partial<BeadIssue> {
|
|||
id: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export type ProjectSource = 'local' | 'registry' | 'scanner';
|
||||
|
||||
export interface ProjectContext {
|
||||
key: string;
|
||||
root: string;
|
||||
displayPath: string;
|
||||
name: string;
|
||||
source: ProjectSource;
|
||||
addedAt: string | null;
|
||||
}
|
||||
|
||||
export type BeadIssueWithProject = BeadIssue & { project: ProjectContext };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue