mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
In generator-aspnetcore-spa, use 'yarn' (if available) instead of 'npm' to restore dependencies because it's > 10x faster
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
8
templates/package-builder/typings/npm-which/npm-which.d.ts
vendored
Normal file
8
templates/package-builder/typings/npm-which/npm-which.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
declare module 'npm-which' {
|
||||
interface NpmWhichContext {
|
||||
sync(executableName: string): string;
|
||||
}
|
||||
|
||||
function defaultFunction(rootDir: string) : NpmWhichContext;
|
||||
export = defaultFunction;
|
||||
}
|
||||
Reference in New Issue
Block a user