Browse Source

Merge pull request #1553 from abpframework/maliming/cli-add-module

Resolve #1551 CLI add-module command add startup project options.
pull/1591/head
Yunus Emre Kalkan 7 years ago
committed by GitHub
parent
commit
5cd2bac906
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs
  2. 15
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationAdder.cs
  3. 7
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs

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

@ -40,6 +40,7 @@ namespace Volo.Abp.Cli.Commands
await SolutionModuleAdder.AddAsync( await SolutionModuleAdder.AddAsync(
GetSolutionFile(commandLineArgs), GetSolutionFile(commandLineArgs),
commandLineArgs.Target, commandLineArgs.Target,
commandLineArgs.Options.GetOrNull(Options.StartupProject.Short, Options.StartupProject.Long),
skipDbMigrations skipDbMigrations
); );
} }
@ -58,12 +59,14 @@ namespace Volo.Abp.Cli.Commands
sb.AppendLine("Options:"); sb.AppendLine("Options:");
sb.AppendLine(" -s|--solution <solution-file> Specify the solution file explicitly."); sb.AppendLine(" -s|--solution <solution-file> Specify the solution file explicitly.");
sb.AppendLine(" --skip-db-migrations <boolean> Specify if a new migration will be added or not."); sb.AppendLine(" --skip-db-migrations <boolean> Specify if a new migration will be added or not.");
sb.AppendLine(" -sp|--startup-project <startup-project-path> Relative path to the project folder of the startup project. Default value is the current folder.");
sb.AppendLine(""); sb.AppendLine("");
sb.AppendLine("Examples:"); sb.AppendLine("Examples:");
sb.AppendLine(""); sb.AppendLine("");
sb.AppendLine(" abp add-module Volo.Blogging Adds the module to the current solution."); sb.AppendLine(" abp add-module Volo.Blogging Adds the module to the current solution.");
sb.AppendLine(" abp add-module Volo.Blogging -s Acme.BookStore Adds the module to the given solution."); sb.AppendLine(" abp add-module Volo.Blogging -s Acme.BookStore Adds the module to the given solution.");
sb.AppendLine(" abp add-module Volo.Blogging -s Acme.BookStore --skip-db-migrations false Adds the module to the given solution but doesn't create a database migration."); sb.AppendLine(" abp add-module Volo.Blogging -s Acme.BookStore --skip-db-migrations false Adds the module to the given solution but doesn't create a database migration.");
sb.AppendLine(@" abp add-module Volo.Blogging -s Acme.BookStore -sp src\Acme.BookStore.Web\Acme.BookStore.Web.csproj Adds the module to the given solution and specify migration startup project.");
sb.AppendLine(""); sb.AppendLine("");
sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI"); sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI");
@ -81,8 +84,8 @@ namespace Volo.Abp.Cli.Commands
{ {
var providedSolutionFile = PathHelper.NormalizePath( var providedSolutionFile = PathHelper.NormalizePath(
commandLineArgs.Options.GetOrNull( commandLineArgs.Options.GetOrNull(
AddPackageCommand.Options.Project.Short, Options.Solution.Short,
AddPackageCommand.Options.Project.Long Options.Solution.Long
) )
); );
@ -129,6 +132,12 @@ namespace Volo.Abp.Cli.Commands
{ {
public const string Skip = "skip-db-migrations"; public const string Skip = "skip-db-migrations";
} }
public static class StartupProject
{
public const string Short = "sp";
public const string Long = "startup-project";
}
} }
} }
} }

15
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationAdder.cs

@ -8,22 +8,22 @@ namespace Volo.Abp.Cli.ProjectModification
{ {
public class EfCoreMigrationAdder : ITransientDependency public class EfCoreMigrationAdder : ITransientDependency
{ {
public void AddMigration(string csprojFile, string module, bool updateDatabase = true) public void AddMigration(string csprojFile, string module, string startupProject, bool updateDatabase = true)
{ {
var moduleName = ParseModuleName(module); var moduleName = ParseModuleName(module);
var migrationName = "Added_" + moduleName + "_Module" + GetUniquePostFix(); var migrationName = "Added_" + moduleName + "_Module" + GetUniquePostFix();
CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(csprojFile) + "\" & dotnet ef migrations add " + migrationName); CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(csprojFile) + "\" & dotnet ef migrations add " + migrationName + GetStartupProjectOption(startupProject));
if (updateDatabase) if (updateDatabase)
{ {
UpdateDatabase(csprojFile); UpdateDatabase(csprojFile, startupProject);
} }
} }
protected void UpdateDatabase(string csprojFile) protected void UpdateDatabase(string csprojFile, string startupProject)
{ {
CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(csprojFile) + "\" & dotnet ef database update"); CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(csprojFile) + "\" & dotnet ef database update" + GetStartupProjectOption(startupProject));
} }
protected virtual string ParseModuleName(string fullModuleName) protected virtual string ParseModuleName(string fullModuleName)
@ -42,5 +42,10 @@ namespace Volo.Abp.Cli.ProjectModification
{ {
return "_" + new Random().Next(1,99999); return "_" + new Random().Next(1,99999);
} }
protected virtual string GetStartupProjectOption(string startupProject)
{
return startupProject.IsNullOrWhiteSpace() ? "" : $" -s {startupProject}";
}
} }
} }

7
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs

@ -47,6 +47,7 @@ namespace Volo.Abp.Cli.ProjectModification
public virtual async Task AddAsync( public virtual async Task AddAsync(
[NotNull] string solutionFile, [NotNull] string solutionFile,
[NotNull] string moduleName, [NotNull] string moduleName,
string startupProject,
bool skipDbMigrations = false) bool skipDbMigrations = false)
{ {
Check.NotNull(solutionFile, nameof(solutionFile)); Check.NotNull(solutionFile, nameof(solutionFile));
@ -91,10 +92,10 @@ namespace Volo.Abp.Cli.ProjectModification
} }
} }
ModifyDbContext(projectFiles, module, skipDbMigrations); ModifyDbContext(projectFiles, module, startupProject, skipDbMigrations);
} }
protected void ModifyDbContext(string[] projectFiles, ModuleInfo module, bool skipDbMigrations = false) protected void ModifyDbContext(string[] projectFiles, ModuleInfo module, string startupProject, bool skipDbMigrations = false)
{ {
if (string.IsNullOrWhiteSpace(module.EfCoreConfigureMethodName)) if (string.IsNullOrWhiteSpace(module.EfCoreConfigureMethodName))
{ {
@ -122,7 +123,7 @@ namespace Volo.Abp.Cli.ProjectModification
if (!skipDbMigrations) if (!skipDbMigrations)
{ {
EfCoreMigrationAdder.AddMigration(dbMigrationsProject, module.Name); EfCoreMigrationAdder.AddMigration(dbMigrationsProject, module.Name, startupProject);
} }
} }

Loading…
Cancel
Save