Yeoman generator, when running on Windows, ensures you have NPM 3+. Fixes #82.

This commit is contained in:
SteveSandersonMS
2016-11-07 14:10:03 -08:00
parent 11c45321aa
commit b3dbb6e0f1
2 changed files with 18 additions and 1 deletions

View File

@@ -10,12 +10,14 @@
"author": "Microsoft",
"license": "Apache-2.0",
"dependencies": {
"@types/semver": "^5.3.30",
"diff": "^2.2.2",
"gitignore-parser": "0.0.2",
"glob": "^7.0.3",
"lodash": "^4.11.1",
"mkdirp": "^0.5.1",
"rimraf": "^2.5.2"
"rimraf": "^2.5.2",
"semver": "^5.3.0"
},
"devDependencies": {
"@types/glob": "^5.0.30",

View File

@@ -2,9 +2,12 @@ import * as path from 'path';
import * as yeoman from 'yeoman-generator';
import * as uuid from 'node-uuid';
import * as glob from 'glob';
import * as semver from 'semver';
import { execSync } from 'child_process';
import npmWhich = require('npm-which');
const yosay = require('yosay');
const toPascalCase = require('to-pascal-case');
const isWindows = /^win/.test(process.platform);
type YeomanPrompt = (opt: yeoman.IPromptOptions | yeoman.IPromptOptions[], callback: (answers: any) => void) => void;
const optionOrPrompt: YeomanPrompt = require('yeoman-option-or-prompt');
@@ -25,6 +28,10 @@ class MyGenerator extends yeoman.Base {
super(args, options);
this._optionOrPrompt = optionOrPrompt;
this.log(yosay('Welcome to the ASP.NET Core Single-Page App generator!'));
if (isWindows) {
assertNpmVersionIsAtLeast('3.0.0');
}
}
prompting() {
@@ -110,5 +117,13 @@ function getPathToExecutable(executableName: string) {
}
}
function assertNpmVersionIsAtLeast(minVersion: string) {
const runningVersion = execSync('npm -v').toString();
if (!semver.gte(runningVersion, minVersion, /* loose */ true)) {
console.error(`This generator requires NPM version ${minVersion} or later. You are running NPM version ${runningVersion}`);
process.exit(0);
}
}
declare var module: any;
(module).exports = MyGenerator;