-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·37 lines (33 loc) · 1021 Bytes
/
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
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const meow = require('meow');
const chalk = require('chalk');
const argv = require('yargs').argv;
const path = require('path');
const cli = meow(`
Usages
$ package-version
$ package-version <filename>
Example
$ package-version
--> 0.0.1
`);
let filename = process.env.PWD + '/package.json';
if (argv._.length > 0) {
filename = process.env.PWD + '/' + argv._[0];
}
if (fs.existsSync(filename)) {
const pkgInfo = require(filename);
if ((pkgInfo.name) && (pkgInfo.version)) {
console.log(chalk.white.bold(`==> Package Information (${chalk.cyan(path.basename(filename))})`));
console.log(` ${chalk.green.bold(pkgInfo.name)} ${chalk.white.bold('v' + pkgInfo.version)}`);
}
else {
console.error(chalk.red.bold(`==> Invalid ${chalk.white('name')} or ${chalk.white('version')} properties`));
}
}
else {
console.log(chalk.red.bold(`Unable to locate valid ${chalk.white.bold(path.basename(filename))}`));
}
console.log('');