import cson from "cson-parser" ; import untildify from "untildify" ; import { Hugo , Item } from "alfred-hugo" ; import { Icons } from "./icons" ; import * as utils from "./utils" ; import { Projects } from "./project" ; const hugo = new Hugo ( { checkUpdates : true , updateNotification : false , updateSource : "npm" , } ) ; hugo . action ( "projects" , async ( ) => { const projectsFile = hugo . cacheFile ( untildify ( "~/.atom/projects.cson" ) ) ; const configFile = hugo . cacheFile ( untildify ( "~/.atom/config.cson" ) ) ; utils . checkEnvironmentChanges ( hugo ) ; projectsFile . on ( "change" , ( cache , file ) => { const p = Projects . parseCson ( file ) ; p . sort ( ( a , b ) => { const nameA = a . title . toLowerCase ( ) ; const nameB = b . title . toLowerCase ( ) ; if ( nameA < nameB ) { return - 1 ; } if ( nameA > nameB ) { return 1 ; } return 0 ; } ) ; cache . set ( "projects" , p ) ; } ) ; configFile . on ( "change" , ( cache , file ) => { let _config = cson . parse ( file ) || { } ; _config = _config [ "*" ] || { } ; cache . set ( "config" , _config ) ; } ) ; let projects = projectsFile . get ( ) . projects || [ ] ; const config = configFile . get ( ) . config || { } ; if ( config [ "project-manager" ] && config [ "project-manager" ] . includeGitRepositories === true ) { const projectHome = config . core . projectHome || untildify ( "~/github" ) ; const prettifyTitle = config [ "project-manager" ] . prettifyTitle === undefined ? true : config [ "project-manager" ] . prettifyTitle ; let gitProjects = Projects . findGitRepositories ( projectHome , prettifyTitle ) || [ ] ; if ( projects . length > 0 ) { gitProjects = gitProjects . filter ( ( gitProject ) => { let existingPaths = [ ] ; for ( const p of projects ) { const paths = p . subtitle . split ( ", " ) || [ ] ; existingPaths = existingPaths . concat ( paths ) ; } return ! existingPaths . includes ( gitProject . subtitle ) ; } ) ; } projects = projects . concat ( gitProjects ) ; } hugo . items = hugo . items . concat ( projects ) ; await utils . checkIcons ( hugo , projects ) ; if ( hugo . items . length === 0 ) { hugo . items . push ( { title : "No projects found." , } ) ; } await hugo . feedback ( ) ; } ) ; hugo . run ( ) ;