Browse Source

cli GitHubLocalRepositoryPath option

resolved https://github.com/abpframework/abp/issues/1827
pull/1857/head
Yunus Emre Kalkan 7 years ago
parent
commit
4b06c25271
  1. 13
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs
  2. 8
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ProjectBuildPipelineBuilder.cs
  3. 62
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/NugetReferenceReplaceStep.cs
  4. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ProjectBuildArgs.cs

13
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

@ -64,6 +64,12 @@ namespace Volo.Abp.Cli.Commands
Logger.LogInformation("UI Framework: " + uiFramework);
}
var gitHubLocalRepositoryPath = commandLineArgs.Options.GetOrNull(Options.GitHubLocalRepositoryPath.Short, Options.GitHubLocalRepositoryPath.Long);
if (gitHubLocalRepositoryPath != null)
{
Logger.LogInformation("GitHub Local Repository Path: " + gitHubLocalRepositoryPath);
}
var outputFolder = commandLineArgs.Options.GetOrNull(Options.OutputFolder.Short, Options.OutputFolder.Long);
if (outputFolder != null)
{
@ -90,6 +96,7 @@ namespace Volo.Abp.Cli.Commands
version,
databaseProvider,
uiFramework,
gitHubLocalRepositoryPath,
commandLineArgs.Options
)
);
@ -219,6 +226,12 @@ namespace Volo.Abp.Cli.Commands
public const string Long = "output-folder";
}
public static class GitHubLocalRepositoryPath
{
public const string Short = "ap";
public const string Long = "abp-path";
}
public static class Version
{
public const string Short = "v";

8
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ProjectBuildPipelineBuilder.cs

@ -1,4 +1,5 @@
using Volo.Abp.Cli.ProjectBuilding.Building.Steps;
using System;
using Volo.Abp.Cli.ProjectBuilding.Building.Steps;
using Volo.Abp.Cli.ProjectBuilding.Templates.App;
namespace Volo.Abp.Cli.ProjectBuilding.Building
@ -12,8 +13,9 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building
pipeline.Steps.Add(new FileEntryListReadStep());
pipeline.Steps.AddRange(context.Template.GetCustomSteps(context));
if (!context.BuildArgs.ExtraProperties.ContainsKey("local-framework-ref"))
if (!context.BuildArgs.ExtraProperties.ContainsKey("local-framework-ref") ||
!string.IsNullOrWhiteSpace(context.BuildArgs.GitHubLocalRepositoryPath))
{
pipeline.Steps.Add(new NugetReferenceReplaceStep());
}

62
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/NugetReferenceReplaceStep.cs

@ -20,7 +20,9 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps
new NugetReferenceReplacer(
context.Files,
"MyCompanyName.MyProjectName",
nugetPackageVersion
nugetPackageVersion,
context.BuildArgs.ExtraProperties.ContainsKey("local-framework-ref"),
context.BuildArgs.GitHubLocalRepositoryPath
).Run();
}
@ -48,15 +50,21 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps
private readonly List<FileEntry> _entries;
private readonly string _companyAndProjectNamePlaceHolder;
private readonly string _nugetPackageVersion;
private readonly bool _localReferences;
private readonly string _gitHubLocalRepositoryPath;
public NugetReferenceReplacer(
List<FileEntry> entries,
string companyAndProjectNamePlaceHolder,
string nugetPackageVersion)
string nugetPackageVersion,
bool localReferences = false,
string gitHubLocalRepositoryPath = null)
{
_entries = entries;
_companyAndProjectNamePlaceHolder = companyAndProjectNamePlaceHolder;
_nugetPackageVersion = nugetPackageVersion;
_localReferences = localReferences;
_gitHubLocalRepositoryPath = gitHubLocalRepositoryPath;
}
public void Run()
@ -97,15 +105,11 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps
continue;
}
var newNode = doc.CreateElement("PackageReference");
XmlNode newNode = null;
var includeAttr = doc.CreateAttribute("Include");
includeAttr.Value = ConvertToNugetReference(oldNodeIncludeValue);
newNode.Attributes.Append(includeAttr);
var versionAttr = doc.CreateAttribute("Version");
versionAttr.Value = _nugetPackageVersion;
newNode.Attributes.Append(versionAttr);
newNode = _localReferences ?
GetLocalReferenceNode(doc, oldNodeIncludeValue) :
GetNugetReferenceNode(doc, oldNodeIncludeValue);
oldNode.ParentNode.ReplaceChild(newNode, oldNode);
}
@ -113,6 +117,44 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps
return doc.OuterXml;
}
private XmlElement GetNugetReferenceNode(XmlDocument doc, string oldNodeIncludeValue)
{
var newNode = doc.CreateElement("PackageReference");
var includeAttr = doc.CreateAttribute("Include");
includeAttr.Value = ConvertToNugetReference(oldNodeIncludeValue);
newNode.Attributes.Append(includeAttr);
var versionAttr = doc.CreateAttribute("Version");
versionAttr.Value = _nugetPackageVersion;
newNode.Attributes.Append(versionAttr);
return newNode;
}
private XmlElement GetLocalReferenceNode(XmlDocument doc, string oldNodeIncludeValue)
{
var newNode = doc.CreateElement("ProjectReference");
var includeAttr = doc.CreateAttribute("Include");
includeAttr.Value = SetGithubPath(oldNodeIncludeValue);
newNode.Attributes.Append(includeAttr);
return newNode;
}
private string SetGithubPath(string includeValue)
{
while (includeValue.StartsWith("..\\"))
{
includeValue = includeValue.TrimStart('.');
includeValue = includeValue.TrimStart('\\');
}
includeValue = _gitHubLocalRepositoryPath.EnsureEndsWith('\\') + includeValue;
return includeValue;
}
private string ConvertToNugetReference(string oldValue)
{
var newValue = Regex.Match(oldValue, @"\\((?!.+?\\).+?)\.csproj", RegexOptions.CultureInvariant | RegexOptions.Compiled);

5
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ProjectBuildArgs.cs

@ -19,6 +19,9 @@ namespace Volo.Abp.Cli.ProjectBuilding
public UiFramework UiFramework { get; set; }
[CanBeNull]
public string GitHubLocalRepositoryPath { get; set; }
[NotNull]
public Dictionary<string, string> ExtraProperties { get; set; }
@ -28,6 +31,7 @@ namespace Volo.Abp.Cli.ProjectBuilding
[CanBeNull] string version = null,
DatabaseProvider databaseProvider = DatabaseProvider.NotSpecified,
UiFramework uiFramework = UiFramework.NotSpecified,
[CanBeNull] string gitHubLocalRepositoryPath = null,
Dictionary<string, string> extraProperties = null)
{
SolutionName = Check.NotNull(solutionName, nameof(solutionName));
@ -35,6 +39,7 @@ namespace Volo.Abp.Cli.ProjectBuilding
Version = version;
DatabaseProvider = databaseProvider;
UiFramework = uiFramework;
GitHubLocalRepositoryPath = gitHubLocalRepositoryPath;
ExtraProperties = extraProperties ?? new Dictionary<string, string>();
}
}

Loading…
Cancel
Save