import fs from 'fs' ; import path from 'path' ; import util from 'util' ; import { IShowcase } from './interfaces' ; const dbPath = path . join ( __dirname , '..' , '.db' ) ; const readFile = util . promisify ( fs . readFile ) ; export function getLanguages ( ) { return readFile ( path . join ( dbPath , 'trending' , 'languages.json' ) , 'utf8' ) . then ( JSON . parse ) ; } export function getTrending ( language , since ) { const db = path . join ( dbPath , 'trending' , `${ language }.${ since }.json` ) ; return readFile ( db , 'utf8' ) . then ( JSON . parse , err => null ) ; } export function getShowcases ( ) { const db = path . join ( dbPath , 'showcase' , 'showcases.json' ) ; return readFile ( db , 'utf8' ) . then ( JSON . parse , err => [ ] ) ; } export function getShowcase ( showcase ) { const db = path . join ( dbPath , 'showcase' , `${ showcase }.json` ) ; return readFile ( db , 'utf8' ) . then ( JSON . parse ) ; }