Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

Commit

Permalink
Added update check (closes #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsebastien committed Dec 22, 2015
1 parent c748503 commit dd63803
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
* 0.1.4
* added a update check: you will be notified whenever a new version of the generator is available
* you can disable the update check by passing the following flag: `--no-update-notifier`
* 0.1.3
* now uses modernWebDevBuild 0.2.2
* now uses modernWebDevBuild 0.2.x
* disabled HTML minification by default (not supported by Angular 2 anymore: https://github.com/dsebastien/modernWebDevBuild/issues/67)
* fixed RxJS dependency in the JSPM configuration (fixes #46)
* 0.1.2
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ You can list all the options with a brief description using `yo modern-web-dev -

By default, the generator will install all project dependencies (not the global requirements listed in the 'Usage' section!). You can skip the installation of the project dependencies by passing the `--skip-install` option.

The generator will check for updates once in a while but you can disable the update check by passing the following flag: `--no-update-notifier`.

## Generated projects dev dependencies
* [gulp](http://gulpjs.com/): JavaScript task runner
* [babel](https://babeljs.io/): ES2015 to ES5 transpiler. Needed so that the Gulp configuration file can be written using ES2015 (gulpfile.babel.js)
Expand Down
35 changes: 31 additions & 4 deletions app/index.es2015.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use strict";

const packageJSON = require('../package.json');
const packageJSON = require("../package.json");

import yeoman from "yeoman-generator";
import yosay from "yosay";
import chalk from "chalk";
import updateNotifier from "update-notifier";
import stringLength from "string-length";

const descriptors = {
projectName: {
Expand Down Expand Up @@ -57,6 +59,24 @@ const descriptors = {
}
};

function checkForUpdates() {
const notifier = updateNotifier({
pkg: packageJSON
//,updateCheckInterval: 1 // useful for debugging
});

let message = [];

let retVal;

if (notifier.update) {
message.push("Update available: " + chalk.green.bold(notifier.update.latest) + chalk.gray(" (current: " + notifier.update.current + ")"));
message.push("Run " + chalk.magenta("npm install -g " + packageJSON.name) + " to update.");
retVal = yosay(message.join(" "), {maxLength: stringLength(message[0])});
}
return retVal;
}

let modernWebDevGenerator = yeoman.Base.extend({

constructor: function () {
Expand Down Expand Up @@ -109,10 +129,17 @@ let modernWebDevGenerator = yeoman.Base.extend({
// contexts list: http://yeoman.io/authoring/running-context.html
prompting: function () {
let done = this.async();

const welcomeMessage = yosay("Welcome to the " + chalk.green("ModernWebDev") + " Yeoman Generator (v" + packageJSON.version + ")");
const updateMessage = checkForUpdates();

// Have Yeoman greet the user.
this.log(yosay("Welcome to the " + chalk.green("ModernWebDev") + " Yeoman Generator (v" + packageJSON.version + ")"));

// Have Yeoman greet the user
if(updateMessage){
this.log(updateMessage);
}else{
this.log(welcomeMessage);
}

const prompts = [
{
type: "input",
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-modern-web-dev",
"version": "0.1.3",
"version": "0.1.4",
"description": "Modern Web Development Yeoman Generator: Gulp, ES2015, TypeScript, Angular 2, SASS, Minification, Bundling, Sourcemaps, ...",
"author": {
"name": "Sebastien Dubois",
Expand Down Expand Up @@ -40,7 +40,9 @@
"yeoman-generator": "0.22.x",
"yosay": "1.1.x",
"chalk": "1.1.x",
"babel-runtime": "6.3.x"
"babel-runtime": "6.3.x",
"update-notifier": "0.6.x",
"string-length": "1.0.x"
},
"devDependencies": {
"yeoman-assert": "2.1.x",
Expand Down

0 comments on commit dd63803

Please sign in to comment.