diff --git a/templates/package-builder/src/yeoman/app/index.ts b/templates/package-builder/src/yeoman/app/index.ts index be40beb..a04af65 100644 --- a/templates/package-builder/src/yeoman/app/index.ts +++ b/templates/package-builder/src/yeoman/app/index.ts @@ -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; diff --git a/templates/package-builder/src/yeoman/package.json b/templates/package-builder/src/yeoman/package.json index f863314..10a7b7a 100644 --- a/templates/package-builder/src/yeoman/package.json +++ b/templates/package-builder/src/yeoman/package.json @@ -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", diff --git a/templates/package-builder/typings/npm-which/npm-which.d.ts b/templates/package-builder/typings/npm-which/npm-which.d.ts new file mode 100644 index 0000000..3959c5b --- /dev/null +++ b/templates/package-builder/typings/npm-which/npm-which.d.ts @@ -0,0 +1,8 @@ +declare module 'npm-which' { + interface NpmWhichContext { + sync(executableName: string): string; + } + + function defaultFunction(rootDir: string) : NpmWhichContext; + export = defaultFunction; +}