This repository has been archived by the owner on Apr 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcli.js
executable file
·63 lines (53 loc) · 1.44 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
#!/usr/bin/env node
'use strict';
let credits = require( 'credits' );
let path = require( 'path' );
let meow = require( 'meow' );
let fs = require( 'fs' );
let cli = meow( `
Usage
$ credits <path>
Options
-r, --reporter Choose reporter to format output [ minimal, extended, markdown ]
Examples
$ credits /projects/foo
$ credits /projects/foo --reporter extended
$ credits /projects/foo --reporter markdown > THANKS.md`,
{
alias : {
r : 'reporter'
}
}
);
let reporters = fs.readdirSync( path.resolve( __dirname, 'reporters' ) ).reduce(
function( reporters, reporter ) {
if ( ! /spec.js/.test( reporter ) ) {
reporter = reporter.replace( '.js', '' );
reporters[ reporter ] = require( './reporters/' + reporter );
}
return reporters;
},
{}
);
let reporter = reporters[ cli.flags.reporter ] || reporters.minimal;
let creditPath = path.resolve( process.cwd(), cli.input[ 0 ] || '.' );
credits( creditPath )
.then( printCredits )
.catch( function( error ) {
console.log( 'error', error );
process.exit( 1 );
} );
/**
* Print the credits in a nice way
*
* @param {Array} credits credits
*/
function printCredits( credits ) {
let projectName = '';
try {
projectName = require( path.join( creditPath, '/package.json' ) ).name;
} catch( err ) {
projectName = creditPath.split( path.sep ).pop();
}
console.log( reporter( projectName, credits ) );
}