Skip to content

Commit

Permalink
feat: Add templates
Browse files Browse the repository at this point in the history
  • Loading branch information
robtarr committed Oct 6, 2018
1 parent dc81632 commit 734df2d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
19 changes: 13 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions templates/default.js
Original file line number Diff line number Diff line change
@@ -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('');
}
18 changes: 18 additions & 0 deletions templates/single-line.js
Original file line number Diff line number Diff line change
@@ -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}`);
}

0 comments on commit 734df2d

Please sign in to comment.