gitmoji-cli
Version:
A gitmoji client for using emojis on commit messages.
26 lines • 1.01 kB
JavaScript
import fetch from 'node-fetch';
import ora from 'ora';
import cache from "./emojisCache.js";
import buildFetchOptions from "./buildFetchOptions.js";
import configurationVault from "./configurationVault/index.js";
const getEmojis = async (skipCache = false) => {
const emojisFromCache = cache.getEmojis();
if (cache.isAvailable() && !skipCache) return emojisFromCache;
const spinner = ora('Fetching gitmojis').start();
try {
const response = await fetch(configurationVault.getGitmojisUrl(), buildFetchOptions());
const data = await response.json();
const emojis = data.gitmojis;
cache.createEmojis(emojis);
if (emojis.length === emojisFromCache.length) {
spinner.info('Gitmojis already up to date');
return [];
}
spinner.succeed('Gitmojis fetched successfully, these are the new emojis:');
return emojis.filter(emoji => !emojisFromCache.includes(emoji));
} catch (error) {
spinner.fail(`Error: ${error}`);
return [];
}
};
export default getEmojis;