mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Yeoman generator, when running on Windows, ensures you have NPM 3+. Fixes #82.
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user