gitmoji-cli
Version:
A gitmoji client for using emojis on commit messages.
28 lines • 732 B
JavaScript
import fs from 'fs';
import os from 'os';
import path from 'path';
import { pathExistsSync } from 'path-exists';
export const GITMOJI_CACHE = {
FOLDER: '.gitmoji',
FILE: 'gitmojis.json'
};
export const CACHE_PATH = path.join(os.homedir(), GITMOJI_CACHE.FOLDER, GITMOJI_CACHE.FILE);
const createEmojis = emojis => {
if (!pathExistsSync(path.dirname(CACHE_PATH))) {
fs.mkdirSync(path.dirname(CACHE_PATH));
}
fs.writeFileSync(CACHE_PATH, JSON.stringify(emojis));
};
const getEmojis = () => {
try {
return JSON.parse(fs.readFileSync(CACHE_PATH).toString());
} catch (error) {
return [];
}
};
const isAvailable = () => pathExistsSync(CACHE_PATH);
export default {
createEmojis,
getEmojis,
isAvailable
};