In generator-aspnetcore-spa, use 'yarn' (if available) instead of 'npm' to restore dependencies because it's > 10x faster

This commit is contained in:
SteveSandersonMS
2016-10-28 16:55:39 +01:00
parent dfcaae6fda
commit 6259b7b938
3 changed files with 28 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import * as path from 'path';
import * as yeoman from 'yeoman-generator';
import * as uuid from 'node-uuid';
import * as glob from 'glob';
import npmWhich = require('npm-which');
const yosay = require('yosay');
const toPascalCase = require('to-pascal-case');
@@ -80,6 +81,15 @@ class MyGenerator extends yeoman.Base {
}
installingDeps() {
// If available, restore dependencies using Yarn instead of NPM
const yarnPath = getPathToExecutable('yarn');
if (!!yarnPath) {
this.log('Will restore NPM dependencies using \'yarn\' installed at ' + yarnPath);
this.npmInstall = (pkgs, options, cb) => {
return (this as any).runInstall(yarnPath, pkgs, options, cb);
};
}
this.installDependencies({
npm: true,
bower: false,
@@ -92,5 +102,13 @@ class MyGenerator extends yeoman.Base {
}
}
function getPathToExecutable(executableName: string) {
try {
return npmWhich(__dirname).sync(executableName);
} catch(ex) {
return null;
}
}
declare var module: any;
(module).exports = MyGenerator;

View File

@@ -1,6 +1,6 @@
{
"name": "generator-aspnetcore-spa",
"version": "0.4.0",
"version": "0.4.1",
"description": "Single-Page App templates for ASP.NET Core",
"author": "Microsoft",
"license": "Apache-2.0",
@@ -20,6 +20,7 @@
"dependencies": {
"glob": "^7.0.3",
"node-uuid": "^1.4.7",
"npm-which": "^3.0.1",
"to-pascal-case": "^1.0.0",
"yeoman-generator": "^0.20.2",
"yeoman-option-or-prompt": "^1.0.2",

View File

@@ -0,0 +1,8 @@
declare module 'npm-which' {
interface NpmWhichContext {
sync(executableName: string): string;
}
function defaultFunction(rootDir: string) : NpmWhichContext;
export = defaultFunction;
}