diff --git a/README.md b/README.md index c199797..0d694c6 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,12 @@ npm i -g oji Just type `oji` to start interactive emoticon creator! Works on every platform :unicorn: +### :sparkles: Make it your own! :sparkles: + +You can add custom characters for each part by creating an optional `~/.oji` directory in your root path. Add new characters to each section by creating a `~/.oji/{file}.txt` with any of the corresponding filenames: + +`'arms_symmetric', 'arms_left', 'bodies_symmetric', 'bodies_left', 'cheeks', 'eyes', 'mouths_noses', 'bodies_right', 'arms_right'` + ## :package: npm Dependencies [![Known Vulnerabilities](https://snyk.io/test/github/xxczaki/oji/badge.svg)](https://snyk.io/test/github/xxczaki/oji) - [inquirer](https://www.npmjs.com/package/inquirer) diff --git a/lib/functions.js b/lib/functions.js index 649ecdc..d57d336 100644 --- a/lib/functions.js +++ b/lib/functions.js @@ -12,10 +12,20 @@ const getRandomIndex = length => { return Math.floor(Math.random() * length); }; +const getParts = () => { + return ['arms_symmetric', 'arms_left', 'bodies_symmetric', 'bodies_left', 'cheeks', 'eyes', 'mouths_noses', 'bodies_right', 'arms_right'].map(fileName => { + let parts = fs.readFileSync(`${__dirname}/parts/${fileName}.txt`, 'utf8').split('\n'); + const customParts = fs.existsSync(`${homeDir}/.oji/${fileName}.txt`) && fs.readFileSync(`${homeDir}/.oji/${fileName}.txt`, 'utf8').split('\n'); + if (customParts) { + parts = parts.concat(customParts); + } + return parts; + }); +}; + // Create emoji! module.exports.create = () => { - const parts = ['arms_symmetric', 'arms_left', 'bodies_symmetric', 'bodies_left', 'cheeks', 'eyes', 'mouths_noses', 'bodies_right', 'arms_right'].map(fileName => - fs.readFileSync(`${__dirname}/parts/${fileName}.txt`, 'utf8').split('\n')); + const parts = getParts(); return inquirer.prompt([ { type: 'list', @@ -106,8 +116,7 @@ module.exports.create = () => { // Create random emoji! module.exports.random = () => { - const parts = ['arms_symmetric', 'arms_left', 'bodies_symmetric', 'bodies_left', 'cheeks', 'eyes', 'mouths_noses', 'bodies_right', 'arms_right'].map(fileName => - fs.readFileSync(`${__dirname}/parts/${fileName}.txt`, 'utf8').split('\n')); + const parts = getParts(); // Combine random parts const leftarmIndex = getRandomIndex([...parts[1], ...parts[0]].length); const rightarmIndex = getRandomIndex([...parts[8], ...parts[0]].length);