Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify user when has a new version #107

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/create-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"cross-spawn-promise": "^0.10.1",
"ora": "^1.2.0",
"shelljs": "^0.7.5",
"update-notifier": "^2.2.0",
"yeoman-generator": "^0.24.1",
"yo": "^1.8.5"
},
Expand Down
7 changes: 6 additions & 1 deletion packages/create-graphql/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
init,
generate,
} from './commands';
import { verifyYeoman } from './utils';
import {
verifyYeoman,
verifyVersion,
} from './utils';

program
.version(pkg.version);
Expand All @@ -18,6 +21,7 @@ program
.description('Create a new GraphQL project')
.action(async (project) => {
await verifyYeoman();
await verifyVersion();

init(project);
});
Expand All @@ -33,6 +37,7 @@ program
.description('Generate a new file (Type, Loader, Mutation, etc)')
.action(async (name, options) => {
await verifyYeoman();
await verifyVersion();

generate(name, options);
});
Expand Down
7 changes: 7 additions & 0 deletions packages/create-graphql/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import shell from 'shelljs';
import chalk from 'chalk';
import ora from 'ora';
import spawn from 'cross-spawn-promise';
import updateNotifier from 'update-notifier';

import pkg from '../package.json';

const tic = chalk.green('✓');
const tac = chalk.red('✗');
Expand Down Expand Up @@ -40,3 +43,7 @@ export const verifyYeoman = async () => { // eslint-disable-line import/prefer-d

return true;
};

export const verifyVersion = async () => { // eslint-disable-line import/prefer-default-export
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for the eslint-disable-line comment, it will no longer throw an error on this file since there are two exports, it's better to remove both of the comments.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, since it is a one-line function, use a shorthand removing the async/await, brackets & return syntaxes.

return await updateNotifier({pkg}).notify();
Copy link
Collaborator

@lucasbento lucasbento Sep 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way the notification will only work for the create-graphql package, this repo contains a Lerna project with both create-graphql (the CLI) and generator-graphql (the Yeoman generator that scaffolds the code), it's better to verify both of them since they can all be updated individually.

I also happened to run into an issue by trying to use update-notifier asynchronously, so I think it's better to use the callback function and a small check: https://github.com/lucasbento/reminders-cli/blob/master/src/utils/updateNotifier.js#L10-L13 (yeoman/update-notifier#67 (comment)).

}
Loading