diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/AbpProCliCoreModule.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/AbpProCliCoreModule.cs index c485602d..da4bc005 100644 --- a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/AbpProCliCoreModule.cs +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/AbpProCliCoreModule.cs @@ -47,6 +47,13 @@ public class AbpProCliCoreModule : AbpModule OldProjectName = "MyProjectName", OldModuleName = "MyModuleName", }, + new AbpProTemplateOptions("abp-vnext-pro-business", "local", "local") + { + //ExcludeFiles = "aspnet-core,vben28,abp-vnext-pro-nuget-module,abp-vnext-pro-nuget-simplify,docs,.github,LICENSE,Readme.md", + ReplaceSuffix = ".sln,.csproj,.cs,.cshtml,.json,.ci,.yml,.yaml,.nswag,.DotSettings,.env,Directory.Build.Lion.targets", + OldCompanyName = "Lion", + OldProjectName = "AbpPro" + }, }; }); diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Args/CommandOptions.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Args/CommandOptions.cs index 9c9feb03..336bc6aa 100644 --- a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Args/CommandOptions.cs +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Args/CommandOptions.cs @@ -48,6 +48,15 @@ public static class CommandOptions public const string Long = "output"; } + /// + /// 版本 + /// + public static class Source + { + public const string Short = "s"; + public const string Long = "source"; + } + /// /// 版本 /// diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Commands/NewCommand.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Commands/NewCommand.cs index 9d776b1d..72475480 100644 --- a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Commands/NewCommand.cs +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/Commands/NewCommand.cs @@ -94,19 +94,46 @@ public class NewCommand : IConsoleCommand, ITransientDependency outputFolder = outputFolder != null ? Path.GetFullPath(outputFolder) : Directory.GetCurrentDirectory(); context.OutputFolder = outputFolder; - //版本 - var version = commandLineArgs.Options.GetOrNull(CommandOptions.Version.Short, CommandOptions.Version.Long); - #endregion + if (_cliOptions.Templates.FirstOrDefault(e => e.Name == template) != null) + { + var source = commandLineArgs.Options.GetOrNull(CommandOptions.Source.Short, CommandOptions.Source.Long); + context.TemplateFolder = source; + if (context.TemplateFolder.IsNullOrWhiteSpace()) + { + Console.WriteLine("请输入源码地址"); + Console.WriteLine("示例: lion.abp new -t local -c 公司名称 -p 项目名称 -s C:\\Users\\Code -o C:\\Users\\output"); + return; + } + + if (context.OutputFolder.IsNullOrWhiteSpace()) + { + Console.WriteLine("请输入输出地址"); + Console.WriteLine("示例: lion.abp new -t local -c 公司名称 -p 项目名称 -s C:\\Users\\Code -o C:\\Users\\output"); + return; + } + + _sourceCodeManager.ReplaceLocalTemplates(context); + + + } + else + { + //版本 + var version = commandLineArgs.Options.GetOrNull(CommandOptions.Version.Short, CommandOptions.Version.Long); + + #endregion - // 获取源码 - context.TemplateFile = await _sourceCodeManager.GetAsync(version); + // 获取源码 + context.TemplateFile = await _sourceCodeManager.GetAsync(version); - // 解压 - _sourceCodeManager.ExtractProjectZip(context); + // 解压 + _sourceCodeManager.ExtractProjectZip(context); + + // 替换模板 + _sourceCodeManager.ReplaceTemplates(context); + } - // 替换模板 - _sourceCodeManager.ReplaceTemplates(context); // 打开文件夹 Process.Start("explorer.exe", context.OutputFolder); diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/ISourceCodeManager.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/ISourceCodeManager.cs index 0263e5f1..bbe0e1f3 100644 --- a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/ISourceCodeManager.cs +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/ISourceCodeManager.cs @@ -17,4 +17,6 @@ public interface ISourceCodeManager /// 替换 /// void ReplaceTemplates(SourceCodeContext context); + + void ReplaceLocalTemplates(SourceCodeContext context); } \ No newline at end of file diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeManager.cs b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeManager.cs index bbc4da79..de2c2886 100644 --- a/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeManager.cs +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Cli.Core/Lion/AbpPro/Cli/SourceCode/SourceCodeManager.cs @@ -152,4 +152,47 @@ public class SourceCodeManager : ITransientDependency, ISourceCodeManager DirectoryHelper.DeleteIfExists(context.ExtractProjectPath, true); } } + + public void ReplaceLocalTemplates(SourceCodeContext context) + { + try + { + + DirectoryHelper.DeleteIfExists(context.OutputFolder, true); + + DirectoryAndFileHelper.CopyFolder(context.TemplateFolder, context.OutputFolder, context.ExcludeFiles); + + + ReplaceHelper.ReplaceTemplates( + context.OutputFolder, + context.OldCompanyName, + context.OldProjectName, + context.OldModuleName, + context.CompanyName, + context.ProjectName, + context.ModuleName, + context.ReplaceSuffix, + context.TemplateFile?.Version); + + // if (context.IsSource) + // { + // context.TemplateFolder = context.ExtractProjectPath; + // } + // else + // { + // // 获取本地源码地址 + // context.TemplateFolder = Path.Combine(context.ExtractProjectPath, "templates", context.TemplateKey); + // } + // + // context.OutputFolder = Path.Combine(context.OutputFolder, context.CompanyName + "." + context.ProjectName); + + // DirectoryAndFileHelper.CopyFolder(context.TemplateFolder, context.OutputFolder, context.ExcludeFiles); + + _logger.LogInformation($"OutputFolder:{context.OutputFolder}"); + } + finally + { + DirectoryHelper.DeleteIfExists(context.ExtractProjectPath, true); + } + } } \ No newline at end of file