Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

generator-badge

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generator-badge - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

.badge.json

43

lib/cli.js
#!/usr/bin/env node
'use strict';
var meow = require('meow'),
help = require('./cmd/help.js'),
install = require('./cmd/install.js'),
list = require('./cmd/list.js'),
clear = require('./cmd/clear.js');
var meow = require('meow'),
help = require('./cmd/help.js'),
install = require('./cmd/install.js'),
installed = require('./cmd/installed.js'),
list = require('./cmd/list.js'),
clear = require('./cmd/clear.js');

@@ -14,8 +15,14 @@ const cli = meow(`

To list installed badge(s):
$ badge installed
To see description of badge(s):
$ badge help <command>
To list all badges:
To list all badges available:
$ badge list
To list badges that will be installed:
$ badge list <command>
To clear all badges:

@@ -32,12 +39,16 @@ $ badge clear

});
if(cli.input[0] === 'help'){
help(cli.input.slice(1));
}else if(cli.input[0] === 'install'){
install(cli);
}else if(cli.input[0] === 'list'){
list(cli.input.slice(1));
}else if(cli.input[0] === 'clear'){
clear();
}else{
cli.showHelp();
switch(cli.input[0]){
case 'help':
return help(cli.input.slice(1));
case 'install':
return install(cli);
case 'installed':
return installed();
case 'list':
return list(cli.input.slice(1));
case 'clear':
return clear();
default:
cli.showHelp();
}
'use strict';
var inject = require('../util/inject.js'),
guessFormat = require('../util/util.js').guessFormat,
config = require('../util/config.js'),
Promise = require('bluebird'),

@@ -20,2 +21,5 @@ findUp = require('find-up-glob'),

.then(function(){
return config.writeLocal();
})
.then(function(){
console.log(chalk.green('Done :)'));

@@ -22,0 +26,0 @@ })

@@ -10,12 +10,11 @@ 'use strict';

readPkgUp = require('read-pkg-up'),
chalk = require('chalk');
chalk = require('chalk'),
_ = require('lodash'),
path = require('path');
//environment variable
var allowInstallIfNotAll = false;
function install(inferred, format, badge){
var generated = render(format(badge), inferred.data);
return Promise.resolve(generated);
return render(format(badge), inferred.data);
}
function getBadges(cmds){
function getBadges(cmds, allowInstallIfNotAll){
var needToBeInstalled = badges.all(cmds);

@@ -30,2 +29,15 @@ if(needToBeInstalled.rejected.length > 0){

}
function addAndCountBadgesToInstalled(){
this.badge = _.flatMap(this.inferred.installed, (installed) => {
return badges(installed);
});
this.oldBadgeCount = this.badge.length;
this.newBadgeCount = 0;
_.each(this._badge, (badge) => {
if(_.findIndex(this.badge, function(o){ return _.isEqual(badge, o); }) === -1){
this.badge.push(badge);
this.newBadgeCount ++;
}
});
}
function installAll(cli){

@@ -37,5 +49,5 @@ var cmds = cli.input.slice(1);

getBadges(cmds).bind({})
getBadges(cmds, cli.flags.ignoreWarning === true).bind({})
.then(function(badge){
this.badge = badge;
this._badge = badge;
console.log(chalk.yellow('Looking for README...'));

@@ -55,7 +67,8 @@ return findUp('README.*');

console.log(chalk.yellow('Inferring information needed...'));
return infer(this.pkg, cli.flags);
return infer(this.pkg, cli.flags, path.resolve(this.filepath, '../'));
})
.then(function(inferred){
this.inferred = inferred;
return inferred.askForMissingDep(this.badge);
addAndCountBadgesToInstalled.bind(this)();
return this.inferred.askForMissingDep(this.badge);
})

@@ -71,3 +84,9 @@ .then(function(){

})
.then(function (){
console.log(chalk.yellow('Clean up...'));
return this.inferred.update(this.badge);
})
.then(function(){
console.log(chalk.green(`Installed: ${this.newBadgeCount} badge${this.newBadgeCount > 1 ? 's' : ''}`));
console.log(chalk.green.bold(`Total: ${this.oldBadgeCount + this.newBadgeCount} badge${(this.oldBadgeCount + this.newBadgeCount) > 1 ? 's' : ''}`));
console.log(chalk.green('Done :)'));

@@ -74,0 +93,0 @@ })

@@ -1,11 +0,16 @@

var gitRepo = require('git-branch'),
gitRepoName = require('git-repo-name'),
gitUserName = require('git-username'),
config = require('configstore'),
'use strict';
var Promise = require('bluebird'),
parseGit = Promise.promisify(require('parse-git-config')),
parseGitURL = require('parse-github-url'),
globalConfig = require('configstore'),
localConfig = require('./config.js'),
inquirer = require('inquirer'),
_ = require('lodash'),
Promise = require('bluebird');
_ = require('lodash'),
chalk = require('chalk');
var Inferred = function(pkg, flags){
var Inferred = function(pkg, flags, configPath){
this.data = {};
this.guess = {};
this.installed = [];
this.configPath = configPath;
this.data['name'] = flags.name || pkg.name || undefined;

@@ -15,11 +20,38 @@ this.data['repo-username'] = flags.repoUsername || undefined;

this.data['repo-branch'] = flags.repoBranch || undefined;
this.data['wercker-repo-key'] = flags.werckerRepoKey || undefined;
};
Inferred.prototype.lookForGit = function () {
//TODO look for git
// console.log(gitRepoName.sync());
return Promise.resolve();
Inferred.prototype.lookForGit = function (giturl) {
if(this.data['repo-name'] && this.data['repo-username'] && this.data['repo-branch']){
//If already have all the data needed, skip
return Promise.resolve();
}else{
return parseGit()
.then(function(git){
return parseGit.keys(git);
})
.then(function(git){
if(git && git.remote && git.remote.origin && git.remote.origin.url){
return parseGitURL(git.remote.origin.url);
} else {
return parseGitURL(giturl)
}
})
.then((parsedGit) => {
this.guess['repo-username'] = parsedGit.owner;
this.guess['repo-name'] = parsedGit.name;
this.guess['repo-branch'] = parsedGit.branch;
});
}
};
Inferred.prototype.lookForStoredPreference = function () {
//TODO
return Promise.resolve();
Inferred.prototype.lookForStoredPreference = function (noCache) {
return localConfig.readLocal(this.configPath)
.then(data => {
//-no-cache flag ignores any stored known value in .badge.json
if(!!noCache){
this.installed = data.installed;
return this;
}else{
return _.defaultsDeep(this, data);
}
});
};

@@ -31,8 +63,7 @@ Inferred.prototype.lookForGlobalPreference = function () {

Inferred.prototype.askForMissingDep = function(badges){
var _this = this;
var needed = _.uniq(_.flatMap(badges, function(badge){ return badge.field; }));
needed = _.filter(needed, function(n){
return _this.data[n] === undefined;
needed = _.filter(needed, (n) => {
return this.data[n] === undefined;
})
var neededPrompt = _.map(needed, function(need){
var neededPrompt = _.map(needed, need => {
return {

@@ -42,14 +73,21 @@ type: 'input',

message: need + ': ',
}
'default': this.guess[need],
};
});
return inquirer.prompt(neededPrompt)
.then(function(answers){
_.extend(_this.data, answers);
.then(answers => {
_.extend(this.data, answers);
});
};
var infer = function(pkg, flags){
return Promise.resolve(new Inferred(pkg, flags)).bind({})
Inferred.prototype.update = function(badges){
return localConfig.writeLocal(this.configPath, {
data: this.data,
installed: _.map(badges, function(badge){ return badge._name; }),
})
};
var infer = function(pkg, flags, path){
return Promise.resolve(new Inferred(pkg, flags, path)).bind({})
.then(function(inferred){
this.inferred = inferred;
return this.inferred.lookForStoredPreference();
return this.inferred.lookForStoredPreference(flags.cache === false);
})

@@ -60,9 +98,17 @@ .then(function(){

.then(function(){
return this.inferred.lookForGit();
return this.inferred.lookForGit(pkg.repository && pkg.repository.url);
})
.catch(function(e){
//Catch all infer error here, not to let it flow to downstream outside
console.log(chalk.red('Failed to infer data'));
console.log(chalk.red(e));
if(this.inferred === undefined){
this.inferred = new Inferred({}, {});
}
return this.inferred;
})
.then(function(){
return Promise.resolve(this.inferred);
return this.inferred;
});
};
module.exports = infer;

@@ -9,3 +9,3 @@ 'use strict';

return function(chunk, enc, callback){
var injected = chunk.replace(format.regex, format.wrap(trim('$1') + text));
var injected = chunk.replace(format.regex, format.wrap('\n' + text));
this.push(injected);

@@ -12,0 +12,0 @@ callback();

{
"name": "generator-badge",
"version": "1.1.0",
"version": "1.2.0",
"description": "Generate badges for your readme",

@@ -46,13 +46,12 @@ "main": "index.js",

"find-up-glob": "^1.0.0",
"git-branch": "^0.3.0",
"git-repo-name": "^0.5.1",
"git-username": "^0.4.0",
"github-repo-url": "^0.2.1",
"inquirer": "^1.0.2",
"lodash": "^4.11.1",
"meow": "^3.7.0",
"parse-git-config": "^0.4.2",
"parse-github-url": "^0.3.1",
"read-pkg-up": "^1.0.1",
"repeating": "^2.0.1",
"through2": "^2.0.1",
"trim-newlines": "^1.0.0"
"trim-newlines": "^1.0.0",
"write-file-atomic": "^1.1.4"
},

@@ -59,0 +58,0 @@ "devDependencies": {

@@ -5,2 +5,5 @@ # generator-badge

[![travis status](https://img.shields.io/travis/tanhauhau/generator-badge.svg)](https://travis-ci.org/tanhauhau/generator-badge)
[![appveyor status](https://img.shields.io/travis/tanhauhau/generator-badge.svg)](https://ci.appveyor.com/project/tanhauhau/generator-badge)
[![wercker status](https://app.wercker.com/status/15d1bfe55ec05c73b82704c4912f4323/s)](https://app.wercker.com/project/bykey/15d1bfe55ec05c73b82704c4912f4323)
[![wercker status](https://app.wercker.com/status/15d1bfe55ec05c73b82704c4912f4323/m)](https://app.wercker.com/project/bykey/15d1bfe55ec05c73b82704c4912f4323)
[![npm version](https://img.shields.io/npm/v/generator-badge.svg)](https://www.npmjs.com/package/generator-badge)

@@ -11,5 +14,3 @@ [![npm license](https://img.shields.io/npm/l/generator-badge.svg)](https://www.npmjs.com/package/generator-badge)

[![david dependency](https://img.shields.io/david/tanhauhau/generator-badge.svg)]()
[![david dev-dependency](https://img.shields.io/david/dev/tanhauhau/generator-badge.svg)]()
[![wercker status](https://app.wercker.com/status/15d1bfe55ec05c73b82704c4912f4323/s)](https://app.wercker.com/project/bykey/15d1bfe55ec05c73b82704c4912f4323)
[![wercker status](https://app.wercker.com/status/15d1bfe55ec05c73b82704c4912f4323/m)](https://app.wercker.com/project/bykey/15d1bfe55ec05c73b82704c4912f4323)
[![david dev-dependency](https://img.shields.io/david/dev/tanhauhau/generator-badge.svg)]()
[![GitHub followers](https://img.shields.io/github/followers/tanhauhau.svg?style=social&label=Follow)](https://github.com/tanhauhau/generator-badge)

@@ -19,3 +20,3 @@ [![GitHub forks](https://img.shields.io/github/forks/tanhauhau/generator-badge.svg?style=social&label=Fork)](https://github.com/tanhauhau/generator-badge/fork)

[![GitHub watchers](https://img.shields.io/github/watchers/tanhauhau/generator-badge.svg?style=social&label=Watch)](https://github.com/tanhauhau/generator-badge)
[![GitHub issues](https://img.shields.io/github/issues/tanhauhau/generator-badge.svg)](https://github.com/tanhauhau/generator-badge/issues)
[![GitHub issues](https://img.shields.io/github/issues/tanhauhau/generator-badge.svg?style=social)](https://github.com/tanhauhau/generator-badge/issues)
<!-- endbadge -->

@@ -79,11 +80,18 @@

![install](https://raw.githubusercontent.com/tanhauhau/generator-badge/master/img/screenshot_install.png)
\***All the information gathered will be stored at .badge.json in the same folder as the nearest README.**
**Other options available**
`--no-cache`
Do not use information stored in `.badge.json`.
`--ignore-warning`
Install badges even if some badges specified does not exists.
**List of installed badge(s)**
```bash
$ badge install travis
Inferring information needed...
? repo-username: tanhauhau
? repo-name: awesome-project
Preparing the badges...
Looking for README...
Injecting badges into README...
Done :)
$ badge installed
```

@@ -105,5 +113,11 @@

Or list specified badges only
**List of badges that will be installed**
```bash
$ badge list <badges>
```
Example
```bash
$ badge list apm tavis

@@ -114,3 +128,3 @@ ```

*Note typo in Travis.*
*Note typo in Travis. This command shows what will be installed, a typo in Tavis will install nothing*

@@ -121,9 +135,6 @@ **Help**

$ badge help <badge>
$ badge help travis
travis-default
Build apps with confidence.
Description : Travis build status of master branch
Fields : repo-username, repo-name
```
![help](https://raw.githubusercontent.com/tanhauhau/generator-badge/master/img/screenshot_help.png)
**Clear**

@@ -144,5 +155,5 @@

- [ ] Find README of various format: markdown, textile, rdoc, rst, pod, html
- [ ] Inferring git, svn repo information
- [ ] Inferring ~~git~~, svn repo information
- [ ] Storing global preferences, eg: able to remember author name in global
- [ ] Storing local preferences, eg: able to remember repo info in local package
- [x] Storing local preferences, eg: able to remember repo info in local package
- [ ] Filename as argument

@@ -149,0 +160,0 @@ - [ ] [More badges available](https://github.com/tanhauhau/generator-badge/blob/master/doc/list.md)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc