diff --git a/index.js b/index.js index 07b5fb9..7c52568 100755 --- a/index.js +++ b/index.js @@ -2,13 +2,20 @@ const chalk = require('chalk'); const namer = require('color-namer'); +const defaultTempalte = require('./templates/default'); const hexString = process.argv[2]; const colorName = namer(hexString).pantone[0].name; -console.log(''); -console.log(chalk.bgHex(hexString)(' ')); -console.log(chalk.bgHex(hexString)(' ') + ' Your commit color is ' + colorName); -console.log(chalk.bgHex(hexString)(' ')); -console.log('#' + hexString); -console.log(''); +let template = defaultTemplate; + +if (process.argv[3]) { + try { + template = require(process.argv[3]); + } catch(e) { + console.error(`Couldn't find commit-color template: ${process.argv[3]}`); + } +} + +template({hexString, colorName}); + diff --git a/package-lock.json b/package-lock.json index 32a1ec7..6fc5015 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "commit-colors", + "name": "@sparkbox/commit-colors", "version": "1.0.0", "lockfileVersion": 1, "requires": true, diff --git a/templates/default.js b/templates/default.js new file mode 100644 index 0000000..9c0f070 --- /dev/null +++ b/templates/default.js @@ -0,0 +1,10 @@ +const chalk = require('chalk'); + +module.exports = ({hexString, colorName}) => { + console.log(''); + console.log(chalk.bgHex(hexString)(' ')); + console.log(chalk.bgHex(hexString)(' ') + ' Your commit color is ' + colorName); + console.log(chalk.bgHex(hexString)(' ')); + console.log('#' + hexString); + console.log(''); +} diff --git a/templates/single-line.js b/templates/single-line.js new file mode 100644 index 0000000..0dafe70 --- /dev/null +++ b/templates/single-line.js @@ -0,0 +1,18 @@ +#!/usr/bin/env node + +const chalk = require('chalk'); + +const getTextColor = (hexString) => { + const decimal = Buffer.from(hexString, 'hex'); + const r = 255 - decimal[0]; + const g = 255 - decimal[1]; + const b = 255 - decimal[2]; + + return Buffer.from([r, g, b]).toString('hex'); +} + + +module.exports = ({ hexString, colorName }) => { + const fgColor = getTextColor(hexString); + console.log(chalk.hex(fgColor).bgHex(hexString)(` Your commit color is ${colorName} `), `#${hexString}`); +}