Skip to content
This repository was archived by the owner on May 20, 2020. It is now read-only.

Commit 40da108

Browse files
authored
Merge pull request #41 from Financial-Times/notify-for-package-updates
Notify users about package updates
2 parents 19e9419 + 7b639d6 commit 40da108

File tree

4 files changed

+101
-22
lines changed

4 files changed

+101
-22
lines changed

README.md

+25-14
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,36 @@ Human-friendly command line tool for the GitHub API.
66

77
### Command Line Tool
88

9+
#### Install globally (recommmended)
10+
11+
```shell
12+
npm install --global @financial-times/github
13+
14+
github --help
915
```
10-
$ npx @financial-times/github --help
11-
github <command>
12-
13-
Commands:
14-
github project:add-pull-request Add a pull request to a project
15-
github project:create Create a new project
16-
github pull-request:create Create a new pull request
17-
18-
Options:
19-
--token GitHub personal access token [string]
20-
--version Show version number [boolean]
21-
--help Show help [boolean]
16+
17+
When you run the tool it will automatically notify you if there is a newer
18+
version of it available for you to update to. This
19+
[can be disabled](https://www.npmjs.com/package/update-notifier#user-settings)
20+
if you'd prefer not to be notified about updates.
21+
22+
Note: If you install this tool globally on your machine and then run
23+
`npx @financial-times/github`, it will use the globally installed version of the
24+
tool rather than temporarily installing it from the npm registry.
25+
26+
#### No installation
27+
28+
If you just want to try this tool out without installing it, you can run it with
29+
[`npx`](https://www.npmjs.com/package/npx) e.g.
30+
31+
```shell
32+
npx @financial-times/github --help
2233
```
2334

2435
### Library
2536

2637
```
27-
npm install --save @financial-times/github
38+
npm install @financial-times/github
2839
```
2940

3041
```javascript
@@ -35,4 +46,4 @@ const github = require("@financial-times/github")({
3546

3647
See [`examples/examples.js`](https://github.com/Financial-Times/github/blob/master/examples/examples.js) for a full set of usage examples.
3748

38-
See [`src/index.js`](https://github.com/Financial-Times/github/blob/master/src/index.js) for all available methods.
49+
See [`src/lib/github.js`](https://github.com/Financial-Times/github/blob/master/src/lib/github.js) for all available methods.

bin/github.js

+62-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,66 @@
11
#!/usr/bin/env node
22

3-
require("yargs")
4-
.commandDir("../src/commands")
3+
const updateNotifier = require("update-notifier");
4+
const yargs = require("yargs");
5+
6+
const options = require('../src/lib/helpers/yargs/options');
7+
8+
const yargsCommandsDirectoryPath = "../src/commands";
9+
10+
/**
11+
* Configure yargs.
12+
*
13+
* @see http://yargs.js.org/docs/
14+
*/
15+
yargs
16+
/**
17+
* Load our yargs command modules from a directory.
18+
*
19+
* @see https://github.com/yargs/yargs/blob/master/docs/advanced.md#commanddirdirectory-opts
20+
*/
21+
.commandDir(yargsCommandsDirectoryPath)
22+
/**
23+
* Always require a command to be specified.
24+
*/
525
.demandCommand()
6-
.group(['token', 'json'], 'Global Options:')
26+
/**
27+
* Group global options in usage output.
28+
*/
29+
.group(["token", "json"], "Global Options:")
30+
.describe("token", options.descriptions.token)
31+
.describe("json", options.descriptions.json)
32+
/**
33+
* Report unrecognized commands as errors.
34+
*/
735
.strict()
8-
.help().argv;
36+
/**
37+
* Enable the display of help with the `--help` option.
38+
*/
39+
.help();
40+
41+
/**
42+
* Parse command line arguments and handle them.
43+
*
44+
* Get yargs to parse Node's `process.argv` array and then handle them
45+
* e.g. display usage information, run a command module.
46+
*
47+
* @see https://nodejs.org/dist/latest/docs/api/process.html#process_process_argv
48+
*/
49+
yargs.parse();
50+
51+
/**
52+
* Display a notification if a newer version of this package is available to install.
53+
*
54+
* This check for updates to the `@financial-times/github` package
55+
* happens asynchronously in a detached child process that runs
56+
* independently from the parent CLI process. This ensures that
57+
* the check for updates doesn't interfere with the running of the
58+
* CLI itself. If an update is available, the user won't be notified
59+
* about it until the next time that they run the CLI.
60+
*
61+
* Note: `update-notifier` checks for updates once a day by default.
62+
*
63+
* @see https://www.npmjs.com/package/update-notifier
64+
*/
65+
const packageJson = require("../package.json");
66+
updateNotifier({ pkg: packageJson }).notify();

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"dependencies": {
2222
"@octokit/rest": "^16.16.3",
2323
"lodash.flow": "^3.5.0",
24+
"update-notifier": "^2.5.0",
2425
"yargs": "^13.2.1"
2526
},
2627
"devDependencies": {

src/lib/helpers/yargs/options.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
/* eslint-disable no-console */
22

3+
const descriptions = {
4+
token:
5+
"GitHub personal access token (uses `GITHUB_PERSONAL_ACCESS_TOKEN` environment variable by default). Generate one at https://github.com/settings/tokens.",
6+
json: "Format command output as JSON string"
7+
};
8+
39
const withToken = yargs => {
410
return yargs.option("token", {
5-
describe:
6-
"GitHub personal access token (uses `GITHUB_PERSONAL_ACCESS_TOKEN` environment variable by default). Generate one at https://github.com/settings/tokens.",
11+
describe: descriptions.token,
712
type: "string",
813
// IMPORTANT: We use a function here so the token is not output on the command line
914
default: () => process.env.GITHUB_PERSONAL_ACCESS_TOKEN,
@@ -20,9 +25,13 @@ const withToken = yargs => {
2025

2126
const withJson = yargs => {
2227
return yargs.option("json", {
23-
describe: "Format command output as JSON string",
28+
describe: descriptions.json,
2429
type: "boolean"
2530
});
2631
};
2732

28-
module.exports = { withToken, withJson };
33+
module.exports = {
34+
descriptions,
35+
withToken,
36+
withJson
37+
};

0 commit comments

Comments
 (0)