import * as path from 'path' ; import { Uri } from 'vscode' ; import { CommitDetails , FileCommitDetails } from '../common/types' ; import { CommittedFile } from '../types' ; import { DirectoryTreeItem , FileTreeItem } from './treeNodes' ; export interface INode < T > { /**
     * A human readable string which is rendered prominent.
     */ readonly label : string ; readonly resource : Uri ; readonly data ? : T ; readonly children : INode < T > [ ] ; } export abstract class AbstractCommitNode < T > implements INode < T > { public children : AbstractCommitNode < T > [ ] = [ ] ; private _label : string ; private _resource : Uri ; public get label ( ) { return this . _label ; } public get resource ( ) { return this . _resource ; } constructor ( public readonly data ) { } protected setLabel ( value ) { this . _label = value ; } protected setResoruce ( value ) { this . _resource = typeof value === 'string' ? Uri . file ( value ) : value ; } } export class DirectoryNode extends AbstractCommitNode < CommitDetails | FileCommitDetails > { constructor ( commit , relativePath ) { super ( commit ) ; const folderName = path . basename ( relativePath ) ; this . setLabel ( folderName ) ; this . setResoruce ( relativePath ) ; } } export class FileNode extends AbstractCommitNode < FileCommitDetails > { constructor ( commit ) { super ( commit ) ; const fileName = path . basename ( commit . committedFile . relativePath ) ; this . setLabel ( fileName ) ; this . setResoruce ( commit . committedFile . relativePath ) ; } } export const INodeFactory = Symbol . for ( 'INodeFactory' ) ; export interface INodeFactory { createDirectoryNode ( commit , relativePath ) : DirectoryNode ; createFileNode ( commit , committedFile ) : FileNode ; } export const INodeBuilder = Symbol . for ( 'INodeBuilder' ) ; export interface INodeBuilder { buildTree ( commit , committedFiles ) : ( DirectoryNode | FileNode ) [ ] ; buildList ( commit , committedFiles ) : FileNode [ ] ; getTreeItem ( node ) : Promise < DirectoryTreeItem | FileTreeItem > ; }