@@ -2,9 +2,12 @@ import * as path from 'path';
2
2
import * as yeoman from 'yeoman-generator' ;
3
3
import * as uuid from 'node-uuid' ;
4
4
import * as glob from 'glob' ;
5
+ import * as semver from 'semver' ;
6
+ import { execSync } from 'child_process' ;
5
7
import npmWhich = require( 'npm-which' ) ;
6
8
const yosay = require ( 'yosay' ) ;
7
9
const toPascalCase = require ( 'to-pascal-case' ) ;
10
+ const isWindows = / ^ w i n / . test ( process . platform ) ;
8
11
9
12
type YeomanPrompt = ( opt : yeoman . IPromptOptions | yeoman . IPromptOptions [ ] , callback : ( answers : any ) => void ) => void ;
10
13
const optionOrPrompt : YeomanPrompt = require ( 'yeoman-option-or-prompt' ) ;
@@ -25,6 +28,10 @@ class MyGenerator extends yeoman.Base {
25
28
super ( args , options ) ;
26
29
this . _optionOrPrompt = optionOrPrompt ;
27
30
this . log ( yosay ( 'Welcome to the ASP.NET Core Single-Page App generator!' ) ) ;
31
+
32
+ if ( isWindows ) {
33
+ assertNpmVersionIsAtLeast ( '3.0.0' ) ;
34
+ }
28
35
}
29
36
30
37
prompting ( ) {
@@ -110,5 +117,13 @@ function getPathToExecutable(executableName: string) {
110
117
}
111
118
}
112
119
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
+
113
128
declare var module : any ;
114
129
( module ) . exports = MyGenerator ;
0 commit comments