From 4f46d8fea151f4b0f91982e3bbc0f141e7deac61 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 17 May 2019 11:31:43 +0300 Subject: [PATCH] Automatically install CLI dependencies if not installed before Resolves #1121 --- .../Volo/Abp/Cli/CliService.cs | 72 ++++++++++++++++++- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs index 50784a8d90..c87e6818dc 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs @@ -1,4 +1,6 @@ using System; +using System.Diagnostics; +using System.IO; using System.Reflection; using Microsoft.Extensions.DependencyInjection; using System.Threading.Tasks; @@ -40,7 +42,9 @@ namespace Volo.Abp.Cli Logger.LogInformation("https://abp.io"); await CheckForNewVersion(); - + + CheckDependencies(); + var commandLineArgs = CommandLineArgumentParser.Parse(args); var commandType = CommandSelector.Select(commandLineArgs); @@ -63,6 +67,68 @@ namespace Volo.Abp.Cli } } + private void CheckDependencies() + { + var installedNpmPackages = GetInstalledNpmPackages(); + + if (!installedNpmPackages.Contains(" yarn@")) + { + InstallYarn(); + } + if (!installedNpmPackages.Contains(" gulp@")) + { + InstallGulp(); + } + } + + private string GetInstalledNpmPackages() + { + var output = ""; + + using (var process = new Process()) + { + process.StartInfo = new ProcessStartInfo("CMD.exe") + { + Arguments = "/C npm list -g --depth 0", + UseShellExecute = false, + CreateNoWindow = true, + RedirectStandardOutput = true, + RedirectStandardError = true + }; + process.Start(); + + using (var stdOut = process.StandardOutput) + { + using (var stdErr = process.StandardError) + { + output = stdOut.ReadToEnd(); + output += stdErr.ReadToEnd(); + + stdErr.Close(); + stdOut.Close(); + } + } + + process.Close(); + } + + return output; + } + + private void InstallYarn() + { + Logger.LogInformation("Installing yarn..."); + var process = Process.Start("CMD.exe", "/C npm install yarn -g"); + process.WaitForExit(); + } + + private void InstallGulp() + { + Logger.LogInformation("Installing gulp..."); + var process = Process.Start("CMD.exe", "/C npm install gulp -g"); + process.WaitForExit(); + } + private async Task CheckForNewVersion() { try @@ -73,7 +139,7 @@ namespace Volo.Abp.Cli if (!latestVersion.IsNullOrEmpty() && currentVersion != latestVersion) { Logger.LogInformation(""); - Logger.LogWarning("ABP CLI has a newer version (" + latestVersion + "). Please update to get the latest features and fixes."); + Logger.LogWarning("ABP CLI has a newer version. Please update to get the latest features and fixes."); Logger.LogWarning(""); Logger.LogWarning("Update Command: "); Logger.LogWarning(" dotnet tool update -g Volo.Abp.Cli"); @@ -86,7 +152,7 @@ namespace Volo.Abp.Cli Logger.LogWarning(e.Message); } } - + private static string GetCliVersion() { var version = typeof(CliService)