Skip to content

Commit b3dbb6e

Browse files
Yeoman generator, when running on Windows, ensures you have NPM 3+. Fixes aspnet#82.
1 parent 11c4532 commit b3dbb6e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

templates/package-builder/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
"author": "Microsoft",
1111
"license": "Apache-2.0",
1212
"dependencies": {
13+
"@types/semver": "^5.3.30",
1314
"diff": "^2.2.2",
1415
"gitignore-parser": "0.0.2",
1516
"glob": "^7.0.3",
1617
"lodash": "^4.11.1",
1718
"mkdirp": "^0.5.1",
18-
"rimraf": "^2.5.2"
19+
"rimraf": "^2.5.2",
20+
"semver": "^5.3.0"
1921
},
2022
"devDependencies": {
2123
"@types/glob": "^5.0.30",

templates/package-builder/src/yeoman/app/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import * as path from 'path';
22
import * as yeoman from 'yeoman-generator';
33
import * as uuid from 'node-uuid';
44
import * as glob from 'glob';
5+
import * as semver from 'semver';
6+
import { execSync } from 'child_process';
57
import npmWhich = require('npm-which');
68
const yosay = require('yosay');
79
const toPascalCase = require('to-pascal-case');
10+
const isWindows = /^win/.test(process.platform);
811

912
type YeomanPrompt = (opt: yeoman.IPromptOptions | yeoman.IPromptOptions[], callback: (answers: any) => void) => void;
1013
const 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+
113128
declare var module: any;
114129
(module).exports = MyGenerator;

0 commit comments

Comments
 (0)