Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
view -> package
Browse files Browse the repository at this point in the history
package can now render our oldest extant package
added a bunch of stuff to the readme
  • Loading branch information
ceejbot committed Apr 29, 2016
1 parent 26f9059 commit c5a61ac
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 98 deletions.
56 changes: 51 additions & 5 deletions README.md
Expand Up @@ -29,19 +29,65 @@ The wombat cli tool.
the helpful wombat tool
Commands:
hook control your hooks
view <package> see information about the named package
whoami the username you are authenticated as
hook control your hooks
package <package> see information about the named package
whoami the username you are authenticated as
Options:
--registry fully-qualified hostname of the registry to use
[default: "registry.npmjs.org"]
--registry the registry configuration to use [default: "default"]
--help Show help [boolean]
--version show version information [boolean]
```

Help is available for each of the supported commands.

You may also do fun things like `wombat ls --depth=0` and `npm` will be invoked.

## configuration

Wombat reads its config from the file `~/.wombatrc`. This file is parsed as [TOML](https://github.com/toml-lang/toml). The defaults look like this:

```toml
[default]
registry = "https://registry.npmjs.org"
api = "https://api.npmjs.org"
```

You can add sections for other registries to talk to and point wombat to them using the name of the config section, or change the default to a registry you use more often. For example:

```toml
[default]
registry = "https://registry.npmjs.org"
api = "https://api.npmjs.org"

[enterprise]
registry = "https://npm-enterprise.private.npmjs.com"
api = "https://api.private.npmjs.com"
```

Then run something like `wombat -r enterprise view @secret/private-package`

## web hooks

```
/usr/local/bin/wombat hook
Commands:
ls [pkg] list your hooks
add <pkg> <url> <secret> add a hook to the named package
update <id> <url> [secret] update an existing hook
rm <id> remove a hook
test <id> test a hook
Examples:
/usr/local/bin/wombat hook add lodash
https://example.com/ my-shared-secret
/usr/local/bin/wombat hook ls lodash
/usr/local/bin/wombat hook rm id-ers83f
```

## viewing packages

## license

ISC probably eventually. For the moment unreleased.
4 changes: 2 additions & 2 deletions bin/wombat-cli.js
Expand Up @@ -7,8 +7,8 @@ updater({pkg: pkg}).notify();

var yargs = require('yargs')
.option('registry', {
description: 'url of the registry to use',
default: 'https://registry.npmjs.org'
description: 'the registry configuration to use',
default: 'default'
})
.help('help')
.version(function() { return require('../package').version; })
Expand Down
131 changes: 131 additions & 0 deletions commands/package.js
@@ -0,0 +1,131 @@
var
chalk = require('chalk'),
columns = require('cli-columns'),
moment = require('moment'),
Registry = require('../lib/registry'),
report = require('../lib/report')
;

function encodePackageName(input)
{
return encodeURIComponent(input).replace('%40', '@');
}

function formatUser(user)
{
return chalk.blue(user.name) + ' <' + user.email + '>';
}

function builder(yargs)
{
return yargs.option('readme', {
alias: 'r',
description: 'render the readme as well as package meta info',
type: 'boolean',
});
}

function view(argv)
{
var reg = argv.reg || new Registry(argv);
var opts = {
method: 'GET',
uri: '/' + encodePackageName(argv.package),
legacy: true
};

reg.authed(opts, function(err, response, pkg)
{
if (err)
return report.failure('view', err.message);
if (response.statusCode === 404)
return report.success('view', 'package ' + argv.package + ' was not found.');
if (!pkg)
return report.failure('view', 'unexpected registry response! ' + JSON.stringify(pkg));

require('normalize-package-data')(pkg);

var latest = pkg['dist-tags'].latest;
var version = pkg.versions[latest];


console.log('');
console.log(chalk.blue(pkg.name) + '@' + chalk.blue(latest));
console.log('published ' + moment(pkg.time[latest]).format('lll'));
if (version._npmUser)
console.log('by ' + formatUser(version._npmUser));
console.log('');
console.log(pkg.description);
console.log('');

if (pkg.license) console.log('license: ' + chalk.magenta(pkg.license));
console.log('on npm: ' + chalk.magenta('https://www.npmjs.com/package/' + encodePackageName(pkg.name)));
if (pkg.homepage) console.log('homepage: ' + chalk.magenta(pkg.homepage));
console.log('tarball: ' + chalk.magenta(version.dist.tarball));
console.log('shasum: ' + chalk.magenta(version.dist.shasum));

console.log('');
console.log(chalk.blue('maintainers:'));
pkg.maintainers.forEach(function(m) { console.log(formatUser(m)); });

console.log('');
console.log(chalk.blue('dependencies:'));
var deps = [];
Object.keys(version.dependencies || []).forEach(function(d)
{
deps.push(chalk.yellow(d) + ': ' + version.dependencies[d]);
});
if (!deps.length)
console.log('none');
else
console.log(columns(deps));

console.log('');
console.log(chalk.blue('development dependencies:'));
deps = [];
Object.keys(version.devDependencies || []).forEach(function(d)
{
deps.push(chalk.yellow(d) + ': ' + version.devDependencies[d]);
});
if (!deps.length)
console.log('none');
else
console.log(columns(deps));

console.log('');
console.log(chalk.blue('versions & dist tags:'));
var versions = Object.keys(pkg.versions);
if (versions.length === 1)
console.log('1 version published');
else if (versions.length > 10)
console.log(versions.length + ' versions published');
else
{
console.log(columns(versions));
}
var disttags = [];
Object.keys(pkg['dist-tags']).forEach(function(tag)
{
disttags.push(chalk.yellow(tag) + ': ' + pkg['dist-tags'][tag]);
});
console.log(columns(disttags));

if (argv.readme)
{
var markdown = require('markdown-it')();
var terminal = require('markdown-it-terminal');

markdown.use(terminal);
console.log('');
console.log(markdown.render(pkg.readme));
}
});
argv._handled = true;
}

module.exports = {
command: 'package <package>',
describe: 'see information about the named package',
handler: view,
builder: builder
};
91 changes: 0 additions & 91 deletions commands/view.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -16,6 +16,7 @@
"markdown-it": "~6.0.1",
"markdown-it-terminal": "0.0.3",
"moment": "~2.13.0",
"normalize-package-data": "~2.3.5",
"rc": "~1.1.6",
"registry-auth-token": "~1.1.1",
"request": "~2.72.0",
Expand Down

0 comments on commit c5a61ac

Please sign in to comment.