From eb8f48b9b021adbdf3140aea76369cc2e4979229 Mon Sep 17 00:00:00 2001 From: Sebastien P Date: Sun, 12 Nov 2017 15:47:05 +0100 Subject: [PATCH] Add copy to clipboard and colors to cli output --- README.md | 8 +++++--- cli.js | 38 ++++++++++++++++++++++++++++++-------- lib.js | 2 +- package.json | 28 +++++++++++++++------------- 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 4f82a70..16e00a8 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,11 @@ $ arng ## Result ``` -Release name: Angular 14 - Accurate Manchet +---------- +Angular 14 - Accurate Manchet https://giphy.com/gifs/accurate-ySg4bO4O02YyA +---------- +Copied to clipboard ``` ## Lib @@ -30,9 +33,8 @@ For the lol. Enjoy! ## Todo -* Copy to clipboard -* Website * Slack command +* Website * ... ## License diff --git a/cli.js b/cli.js index 5bd0ded..e31be3c 100644 --- a/cli.js +++ b/cli.js @@ -1,10 +1,32 @@ #!/usr/bin/env node -const angularReleaseNameGenerator = require('./lib'); - -angularReleaseNameGenerator() - .then(({ version, name, gif }) => { - console.log('Release name: Angular ' + version + ' - ' + name); - console.log(gif); - }) - .catch(error => console.error(error.message)); +const chalk = require('chalk'); +const writeToClipboard = require('clipboardy').write; + +const releaseNameGenerator = require('./lib'); + +function multiline(...lines) { return lines.join('\r\n'); } + +function log(lines, type = 'log') { + console[type](multiline(...[chalk.dim('----------')].concat(lines))); +} + +function successLog(message) { + log(chalk.green(message), 'info'); +} + +function errorLog(message) { + log(chalk.red(message), 'error'); +} + +function logResult({ version, name, gif }) { + const release = 'Angular ' + version + ' - ' + name; + log([chalk.white.bgRed.bold(release), chalk.blue.underline(gif)]); + return multiline(release, gif); +} + +releaseNameGenerator() + .then(logResult) + .then(writeToClipboard) + .then(() => successLog('Copied to clipboard')) + .catch(error => errorLog(error.message)); diff --git a/lib.js b/lib.js index a262765..fc2b1f5 100644 --- a/lib.js +++ b/lib.js @@ -50,7 +50,7 @@ function fetchRelatedData(name, version) { return Promise.all([name, version, fetchTopicRelatedGifUrl(name)]); } -module.exports = function arng(version = fetchNextVersion()) { +module.exports = function releaseNameGenerator(version = fetchNextVersion()) { return fetchReleaseName() .then(name => fetchRelatedData(name, version)) .then(([name, version, gif]) => ({ name, version, gif })) diff --git a/package.json b/package.json index 9b6c111..fb5057e 100644 --- a/package.json +++ b/package.json @@ -1,34 +1,36 @@ { "name": "angular-release-name-generator", "description": "Generate random Angular release names", - "main": "./lib.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "version": "1.1.0", + "version": "1.2.0", + "license": "MIT", + "author": "https://github.com/sebastien-p", + "contributors": ["https://github.com/known-as-bmf"], + "keywords": ["angular"], + "homepage": "https://github.com/sebastien-p/angular-release-name-generator#readme", "repository": { "type": "git", "url": "git+https://github.com/sebastien-p/angular-release-name-generator.git" }, - "keywords": ["angular"], - "author": "https://github.com/sebastien-p", - "contributors": ["https://github.com/known-as-bmf"], - "license": "MIT", + "bugs": { + "url": "https://github.com/sebastien-p/angular-release-name-generator/issues" + }, "preferGlobal": true, "engines": { "node": ">=6.4.0" }, + "main": "./lib.js", "bin": { "arng": "./cli.js" }, - "bugs": { - "url": "https://github.com/sebastien-p/angular-release-name-generator/issues" - }, - "homepage": "https://github.com/sebastien-p/angular-release-name-generator#readme", "dependencies": { + "chalk": "2.3.0", + "clipboardy": "1.2.1", "datamuse": "1.0.5", "giphy-api": "1.2.7", "lodash": "4.17.4", "semver": "5.4.1" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" } }