Skip to content

Commit

Permalink
Add copy to clipboard and colors to cli output
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-p committed Nov 12, 2017
1 parent cdabb7d commit eb8f48b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,9 +33,8 @@ For the lol. Enjoy!

## Todo

* Copy to clipboard
* Website
* Slack command
* Website
* ...

## License
Expand Down
38 changes: 30 additions & 8 deletions cli.js
Original file line number Diff line number Diff line change
@@ -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));
2 changes: 1 addition & 1 deletion lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
Expand Down
28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit eb8f48b

Please sign in to comment.