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",
|
"author": "Microsoft",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/semver": "^5.3.30",
|
||||||
"diff": "^2.2.2",
|
"diff": "^2.2.2",
|
||||||
"gitignore-parser": "0.0.2",
|
"gitignore-parser": "0.0.2",
|
||||||
"glob": "^7.0.3",
|
"glob": "^7.0.3",
|
||||||
"lodash": "^4.11.1",
|
"lodash": "^4.11.1",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"rimraf": "^2.5.2"
|
"rimraf": "^2.5.2",
|
||||||
|
"semver": "^5.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/glob": "^5.0.30",
|
"@types/glob": "^5.0.30",
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ import * as path from 'path';
|
|||||||
import * as yeoman from 'yeoman-generator';
|
import * as yeoman from 'yeoman-generator';
|
||||||
import * as uuid from 'node-uuid';
|
import * as uuid from 'node-uuid';
|
||||||
import * as glob from 'glob';
|
import * as glob from 'glob';
|
||||||
|
import * as semver from 'semver';
|
||||||
|
import { execSync } from 'child_process';
|
||||||
import npmWhich = require('npm-which');
|
import npmWhich = require('npm-which');
|
||||||
const yosay = require('yosay');
|
const yosay = require('yosay');
|
||||||
const toPascalCase = require('to-pascal-case');
|
const toPascalCase = require('to-pascal-case');
|
||||||
|
const isWindows = /^win/.test(process.platform);
|
||||||
|
|
||||||
type YeomanPrompt = (opt: yeoman.IPromptOptions | yeoman.IPromptOptions[], callback: (answers: any) => void) => void;
|
type YeomanPrompt = (opt: yeoman.IPromptOptions | yeoman.IPromptOptions[], callback: (answers: any) => void) => void;
|
||||||
const optionOrPrompt: YeomanPrompt = require('yeoman-option-or-prompt');
|
const optionOrPrompt: YeomanPrompt = require('yeoman-option-or-prompt');
|
||||||
@@ -25,6 +28,10 @@ class MyGenerator extends yeoman.Base {
|
|||||||
super(args, options);
|
super(args, options);
|
||||||
this._optionOrPrompt = optionOrPrompt;
|
this._optionOrPrompt = optionOrPrompt;
|
||||||
this.log(yosay('Welcome to the ASP.NET Core Single-Page App generator!'));
|
this.log(yosay('Welcome to the ASP.NET Core Single-Page App generator!'));
|
||||||
|
|
||||||
|
if (isWindows) {
|
||||||
|
assertNpmVersionIsAtLeast('3.0.0');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prompting() {
|
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;
|
declare var module: any;
|
||||||
(module).exports = MyGenerator;
|
(module).exports = MyGenerator;
|
||||||
|
|||||||
Reference in New Issue
Block a user