import path from "path" ; import fs from "fs-extra" ; import { Hugo , Item } from "alfred-hugo" ; import { Icons } from "./icons" ; export function checkEnvironmentChanges ( hugo ) { let clearCache = false ; if ( process . env . terminalApp && hugo . config . get ( "terminalApp" ) !== process . env . terminalApp ) { clearCache = true ; hugo . config . set ( "terminalApp" , process . env . terminalApp ) ; } if ( hugo . workflowMeta . version && hugo . config . get ( "wfVersion" ) !== hugo . workflowMeta . version ) { clearCache = true ; hugo . config . set ( "wfVersion" , hugo . workflowMeta . version ) ; } if ( clearCache === true ) { hugo . clearCacheSync ( ) ; } } export async function checkIcons ( hugo , items ) { const themePath = hugo . alfredMeta . themeFile ; const lastTheme = hugo . config . get ( "lastTheme" ) ; try { fs . statSync ( path . join ( __dirname , "icons" ) ) ; } catch ( e ) { hugo . config . set ( "lastTheme" , hugo . alfredMeta . theme ) ; return Icons . rebuild ( items , { theme : hugo . alfredTheme } ) ; } if ( ! lastTheme || lastTheme !== hugo . alfredMeta . theme ) { hugo . config . set ( "lastTheme" , hugo . alfredMeta . theme ) ; return Icons . rebuild ( items , { theme : hugo . alfredTheme } ) ; } if ( themePath ) { const themeFile = hugo . cacheFile ( themePath ) ; await themeFile . on ( "change" , async ( ) => { await Icons . rebuild ( items , { theme : hugo . alfredTheme } ) ; } ) ; themeFile . get ( ) ; } return Icons . rebuild ( items , { onlyMissing : true , theme : hugo . alfredTheme } ) ; } export function fileExists ( p ) { try { fs . statSync ( p ) ; return true ; } catch ( err ) { return false ; } }