From 342db112965ac848d342200790a17b77b1b85fa2 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Sat, 4 Apr 2020 12:56:10 +0300 Subject: [PATCH] Create .npmrc file when run abp switch-to-preview command resolves https://github.com/abpframework/abp/issues/3258 --- .../ProjectModification/NpmPackagesUpdater.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs index 263e94c377..280af81687 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; @@ -51,9 +52,14 @@ namespace Volo.Abp.Cli.ProjectModification { var fileDirectory = Path.GetDirectoryName(file).EnsureEndsWith(Path.DirectorySeparatorChar); + if (IsAngularProject(fileDirectory)) + { + CreateNpmrcFile(Path.GetDirectoryName(file)); + } + RunYarn(fileDirectory); - if (IsAngularProject(fileDirectory) == false) + if (!IsAngularProject(fileDirectory)) { Thread.Sleep(500); RunGulp(fileDirectory); @@ -62,6 +68,21 @@ namespace Volo.Abp.Cli.ProjectModification } } + private void CreateNpmrcFile(string directoryName) + { + var fileName = Path.Combine(directoryName, ".npmrc"); + + if (File.Exists(fileName)) + { + return; + } + + using var fs = File.Create(fileName); + + var content = new UTF8Encoding(true).GetBytes("@abp:registry:https://www.myget.org/F/abp-nightly/npm"); + fs.Write(content, 0, content.Length); + } + private bool IsAngularProject(string fileDirectory) { return File.Exists(Path.Combine(fileDirectory, "angular.json"));