const fs = require('fs');
const { readdirSync } = require('fs');
const musicPath = '../assets/snd/';

const getDirectories = source =>
  readdirSync(source, { withFileTypes: true })
    .filter(dirent => dirent.isDirectory())
    .map(dirent => dirent.name)


function pickATrack(){
  let soundDirs = getDirectories(musicPath);

  let whichDir = Math.floor(Math.random()*soundDirs.length);

  let filesInDir = fs.readdirSync(musicPath+soundDirs[whichDir]).length;

  let whichTrack = Math.floor(Math.random()*filesInDir);

  let trackLoc = musicPath+soundDirs[whichDir]+'/'+whichTrack+'.mp3';

  return "track: "+trackLoc;
}

console.log(pickATrack());
