Merge pull request #1131 from abpframework/install-CLI-dependencies-if-not-installed-

Automatically install CLI dependencies if not installed before
pull/1140/head
Halil İbrahim Kalkan 7 years ago committed by GitHub
commit 7366294ab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@ -7,6 +10,7 @@ using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Commands;
using Volo.Abp.Cli.NuGet;
using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli
@ -40,7 +44,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 +69,61 @@ 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(CmdHelper.GetFileName())
{
Arguments = CmdHelper.GetArguments("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();
}
}
}
return output;
}
private void InstallYarn()
{
Logger.LogInformation("Installing yarn...");
CmdHelper.RunCmd("npm install yarn -g");
}
private void InstallGulp()
{
Logger.LogInformation("Installing gulp...");
CmdHelper.RunCmd("npm install gulp -g");
}
private async Task CheckForNewVersion()
{
try
@ -86,7 +147,7 @@ namespace Volo.Abp.Cli
Logger.LogWarning(e.Message);
}
}
private static string GetCliVersion()
{
var version = typeof(CliService)

@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.ProjectModification
@ -12,8 +13,7 @@ namespace Volo.Abp.Cli.ProjectModification
var moduleName = ParseModuleName(module);
var migrationName = "Added_" + moduleName + "_Module" + GetUniquePostFix();
var process = Process.Start("CMD.exe", "/C cd \"" + Path.GetDirectoryName(csprojFile) + "\" & dotnet ef migrations add " + migrationName);
process.WaitForExit();
CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(csprojFile) + "\" & dotnet ef migrations add " + migrationName);
if (updateDatabase)
{
@ -23,8 +23,7 @@ namespace Volo.Abp.Cli.ProjectModification
protected void UpdateDatabase(string csprojFile)
{
var process = Process.Start("CMD.exe", "/C cd \"" + Path.GetDirectoryName(csprojFile) + "\" & dotnet ef database update");
process.WaitForExit();
CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(csprojFile) + "\" & dotnet ef database update");
}
protected virtual string ParseModuleName(string fullModuleName)

@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Volo.Abp.Cli.Utils
{
@ -12,8 +13,31 @@ namespace Volo.Abp.Cli.Utils
public static void RunCmd(string command)
{
var procStartInfo = new ProcessStartInfo("cmd.exe", "/C " + command);
var procStartInfo = new ProcessStartInfo(GetFileName(), GetArguments(command));
Process.Start(procStartInfo).WaitForExit();
}
public static string GetArguments(string command)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return "-c \"" + command + "\"";
}
//Windows default.
return "/C \"" + command + "\"";
}
public static string GetFileName()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
//TODO: Test this. it should work for both operaion systems.
return "/bin/bash";
}
//Windows default.
return "cmd.exe";
}
}
}

Loading…
Cancel
Save