-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
65 lines (53 loc) · 1.64 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
/**
* npm-pkgs-count <https://github.com/tunnckoCore/npm-pkgs-count>
*
* Copyright (c) 2015 Charlike Mike Reagent, contributors.
* Released under the MIT license.
*/
'use strict';
var is = require('assertit').is;
var meow = require('meow');
var chalk = require('chalk');
var npmPkgsCount = require('./index');
var multiline = require('multiline');
var log = require('log-symbols');
var exit = process.exit;
var url = 'https://www.npmjs.com';
var cli = meow({
help: chalk.gray(multiline.stripIndent(function() {/*
Options
--help show this help
--version current version
Usage
npm-pkgs-count [username]
Example
npm-pkgs-count tunnckocore
*/}))
});
if (is.kindof.array(cli.input) && !cli.input.length) {
console.error();
console.error(chalk.red(' Whoaaa!'));
console.error();
console.error(' %s %s', log.error, chalk.red('You should give a npm username.'));
console.error(' %s %s', log.info, chalk.blue('Try to run:'), chalk.gray('npm-pkgs tunnckocore'));
console.error();
exit(1);
}
console.log();
console.log(chalk.green(' Aloha, master!'));
console.log();
console.log(' %s %s', log.info, chalk.gray('Please wait a moment...'));
console.log(' %s %s', log.info, chalk.gray('We fetching data from'), chalk.blue(url));
console.log();
var username = String(cli.input[0]);
npmPkgsCount(username, function _cb(err, cnt) {
if (!is.kindof.null(err)) {
console.error(' %s %s', log.error, chalk.red(err.message));
console.error();
exit(1);
}
console.log(' %s %s', log.success, chalk.gray(cnt + ' packages by'), chalk.bold(username));
console.log();
exit(0);
});