@@ -2,9 +2,12 @@ import * as path from 'path';
22import * as yeoman from 'yeoman-generator' ;
33import * as uuid from 'node-uuid' ;
44import * as glob from 'glob' ;
5+ import * as semver from 'semver' ;
6+ import { execSync } from 'child_process' ;
57import npmWhich = require( 'npm-which' ) ;
68const yosay = require ( 'yosay' ) ;
79const toPascalCase = require ( 'to-pascal-case' ) ;
10+ const isWindows = / ^ w i n / . test ( process . platform ) ;
811
912type YeomanPrompt = ( opt : yeoman . IPromptOptions | yeoman . IPromptOptions [ ] , callback : ( answers : any ) => void ) => void ;
1013const optionOrPrompt : YeomanPrompt = require ( 'yeoman-option-or-prompt' ) ;
@@ -25,6 +28,10 @@ class MyGenerator extends yeoman.Base {
2528 super ( args , options ) ;
2629 this . _optionOrPrompt = optionOrPrompt ;
2730 this . log ( yosay ( 'Welcome to the ASP.NET Core Single-Page App generator!' ) ) ;
31+
32+ if ( isWindows ) {
33+ assertNpmVersionIsAtLeast ( '3.0.0' ) ;
34+ }
2835 }
2936
3037 prompting ( ) {
@@ -110,5 +117,13 @@ function getPathToExecutable(executableName: string) {
110117 }
111118}
112119
120+ function assertNpmVersionIsAtLeast ( minVersion : string ) {
121+ const runningVersion = execSync ( 'npm -v' ) . toString ( ) ;
122+ if ( ! semver . gte ( runningVersion , minVersion , /* loose */ true ) ) {
123+ console . error ( `This generator requires NPM version ${ minVersion } or later. You are running NPM version ${ runningVersion } ` ) ;
124+ process . exit ( 0 ) ;
125+ }
126+ }
127+
113128declare var module : any ;
114129( module ) . exports = MyGenerator ;
0 commit comments