|
|
|
@ -33,17 +33,13 @@ namespace Volo.Abp.Cli.ProjectModification |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
await ReplaceProjectNamesAndCopySourCodeRequirementsToProjectsAsync(angularProjectsPath, projects); |
|
|
|
|
|
|
|
await RemoveRedundantFilesAsync(angularProjectsPath, projects); |
|
|
|
|
|
|
|
await AddPathsToTsConfigAsync(angularPath, angularProjectsPath, projects); |
|
|
|
|
|
|
|
await AddProjectToAngularJsonAsync(angularPath, projects); |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
Logger.LogError( "Unable to add angular source code: " + e.Message); |
|
|
|
Logger.LogError("Unable to add angular source code: " + e.Message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -54,7 +50,7 @@ namespace Volo.Abp.Cli.ProjectModification |
|
|
|
|
|
|
|
var json = JObject.Parse(fileContent); |
|
|
|
|
|
|
|
var projectsJobject = (JObject)json["projects"]; |
|
|
|
var projectsJobject = (JObject) json["projects"]; |
|
|
|
|
|
|
|
foreach (var project in projects) |
|
|
|
{ |
|
|
|
@ -62,126 +58,88 @@ namespace Volo.Abp.Cli.ProjectModification |
|
|
|
new JProperty("projectType", "library"), |
|
|
|
new JProperty("root", $"projects/{project}"), |
|
|
|
new JProperty("sourceRoot", $"projects/{project}/src"), |
|
|
|
new JProperty("prefix", "lib"), |
|
|
|
new JProperty("prefix", "abp"), |
|
|
|
new JProperty("architect", new JObject( |
|
|
|
new JProperty("build", new JObject( |
|
|
|
new JProperty("builder", "@angular-devkit/build-ng-package:build"), |
|
|
|
new JProperty("builder", "@angular-devkit/build-ng-packagr:build"), |
|
|
|
new JProperty("options", new JObject( |
|
|
|
new JProperty("tsConfig", $"projects/{project}/tsconfig.lib.json"), |
|
|
|
new JProperty("project", $"projects/{project}/ng-package.json") |
|
|
|
)), |
|
|
|
)), |
|
|
|
new JProperty("configurations", new JObject( |
|
|
|
new JProperty("production", new JObject( |
|
|
|
new JProperty("tsConfig", $"projects/{project}/tsconfig.lib.prod.json"))) |
|
|
|
)))), |
|
|
|
new JProperty("test", new JObject( |
|
|
|
new JProperty("builder", "@angular-devkit/build-angular:karma"), |
|
|
|
new JProperty("builder", "@angular-builders/jest:run"), |
|
|
|
new JProperty("options", new JObject( |
|
|
|
new JProperty("main", $"projects/{project}/src/test.ts"), |
|
|
|
new JProperty("tsConfig", $"projects/{project}/tsconfig.spec.json"), |
|
|
|
new JProperty("karmaConfig", $"projects/{project}/karma.conf.js") |
|
|
|
new JProperty("coverage", true), |
|
|
|
new JProperty("passWithNoTests", true) |
|
|
|
) |
|
|
|
))), |
|
|
|
new JProperty("lint", new JObject( |
|
|
|
new JProperty("builder", "@angular-devkit/build-angular:tslint"), |
|
|
|
new JProperty("options", new JObject( |
|
|
|
new JProperty("tsConfig", new JArray(new JValue($"projects/{project}/tsconfig.lib.json"), new JValue($"projects/{project}/tsconfig.spec.json"))), |
|
|
|
new JProperty("tsConfig", |
|
|
|
new JArray(new JValue($"projects/{project}/tsconfig.lib.json"), |
|
|
|
new JValue($"projects/{project}/tsconfig.spec.json"))), |
|
|
|
new JProperty("exclude", new JArray(new JValue("**/node_modules/**"))) |
|
|
|
)) |
|
|
|
)) |
|
|
|
)) |
|
|
|
)); |
|
|
|
)) |
|
|
|
)); |
|
|
|
} |
|
|
|
|
|
|
|
File.WriteAllText(angularJsonFilePath, json.ToString(Formatting.Indented)); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task AddPathsToTsConfigAsync(string angularPath, string angularProjectsPath, List<string> projects) |
|
|
|
private async Task AddPathsToTsConfigAsync(string angularPath, string angularProjectsPath, |
|
|
|
List<string> projects) |
|
|
|
{ |
|
|
|
var tsConfigPath = Path.Combine(angularPath, "tsconfig.json"); |
|
|
|
var fileContent = File.ReadAllText(tsConfigPath); |
|
|
|
|
|
|
|
var tsConfigAsJson = JObject.Parse(fileContent); |
|
|
|
|
|
|
|
var compilerOptions = (JObject)tsConfigAsJson["compilerOptions"]; |
|
|
|
var compilerOptions = (JObject) tsConfigAsJson["compilerOptions"]; |
|
|
|
|
|
|
|
foreach (var project in projects) |
|
|
|
{ |
|
|
|
var projectPackageName = await GetProjectPackageNameAsync(angularProjectsPath, project); |
|
|
|
|
|
|
|
var property = new JProperty($"{projectPackageName}", |
|
|
|
new JArray(new object[] { $"projects/{project}/src/public-api.ts" }) |
|
|
|
); |
|
|
|
var property2 = new JProperty($"{projectPackageName}/*", |
|
|
|
new JArray(new object[] { $"projects/{project}/src/lib/*" }) |
|
|
|
); |
|
|
|
var publicApis = Directory.GetFiles(Path.Combine(angularProjectsPath, project), "*public-api.ts", SearchOption.AllDirectories) |
|
|
|
.Where(p => !p.Contains("\\node_modules\\")) |
|
|
|
.Select(p => p.RemovePreFix(angularPath).Replace("\\", "/").RemovePreFix("/")); |
|
|
|
|
|
|
|
if (compilerOptions["paths"] == null) |
|
|
|
{ |
|
|
|
|
|
|
|
compilerOptions.Add("paths", new JObject()); |
|
|
|
} |
|
|
|
|
|
|
|
((JObject)compilerOptions["paths"]).Add(property); |
|
|
|
((JObject)compilerOptions["paths"]).Add(property2); |
|
|
|
} |
|
|
|
|
|
|
|
File.WriteAllText(tsConfigPath, tsConfigAsJson.ToString(Formatting.Indented)); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<string> GetProjectPackageNameAsync(string angularProjectsPath, string project) |
|
|
|
{ |
|
|
|
var packageJsonPath = Path.Combine(angularProjectsPath, project, "package.json"); |
|
|
|
|
|
|
|
var fileContent = File.ReadAllText(packageJsonPath); |
|
|
|
|
|
|
|
return (string)JObject.Parse(fileContent)["name"]; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task RemoveRedundantFilesAsync(string angularProjectsPath, List<string> projects) |
|
|
|
{ |
|
|
|
foreach (var project in projects) |
|
|
|
{ |
|
|
|
var jestConfigPath = Path.Combine(angularProjectsPath, project, "jest.config.js"); |
|
|
|
|
|
|
|
if (File.Exists(jestConfigPath)) |
|
|
|
foreach (var publicApi in publicApis) |
|
|
|
{ |
|
|
|
File.Delete(jestConfigPath); |
|
|
|
} |
|
|
|
var subFolderName = publicApi.RemovePreFix($"projects/{project}/").Split("/")[0]; |
|
|
|
|
|
|
|
var testPath = Path.Combine(angularProjectsPath, project, "src", "test.ts"); |
|
|
|
if (subFolderName == "src") |
|
|
|
{ |
|
|
|
subFolderName = ""; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
subFolderName = $"/{subFolderName}"; |
|
|
|
} |
|
|
|
|
|
|
|
if (File.Exists(testPath)) |
|
|
|
{ |
|
|
|
File.Delete(testPath); |
|
|
|
((JObject) compilerOptions["paths"]).Add( |
|
|
|
new JProperty($"{projectPackageName}{subFolderName}", |
|
|
|
new JArray(new object[] {publicApi}) |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async Task ReplaceProjectNamesAndCopySourCodeRequirementsToProjectsAsync(string angularProjectsPath, List<string> projects) |
|
|
|
{ |
|
|
|
foreach (var project in projects) |
|
|
|
{ |
|
|
|
var sourceCodeReqFolder = Path.Combine(angularProjectsPath, project, "source-code-requirements"); |
|
|
|
|
|
|
|
Directory.CreateDirectory(sourceCodeReqFolder); |
|
|
|
|
|
|
|
var filesUnderSourceCodeReqFolder = Directory.GetFiles(sourceCodeReqFolder); |
|
|
|
|
|
|
|
foreach (var fileUnderSourceCodeReqFolder in filesUnderSourceCodeReqFolder) |
|
|
|
{ |
|
|
|
var newDest = Path.Combine(angularProjectsPath, project, Path.GetFileName(fileUnderSourceCodeReqFolder)); |
|
|
|
File.Move(fileUnderSourceCodeReqFolder, newDest); |
|
|
|
|
|
|
|
var fileContent = File.ReadAllText(newDest); |
|
|
|
fileContent = fileContent.Replace("{{project-name}}", project); |
|
|
|
fileContent = fileContent.Replace("{{library-name-kebab-case}}", project); |
|
|
|
File.WriteAllText(newDest, fileContent); |
|
|
|
} |
|
|
|
} |
|
|
|
File.WriteAllText(tsConfigPath, tsConfigAsJson.ToString(Formatting.Indented)); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<List<string>> CopyAndGetNamesOfAngularProjectsAsync(string solutionFilePath, string angularProjectsPath) |
|
|
|
private async Task<List<string>> CopyAndGetNamesOfAngularProjectsAsync(string solutionFilePath, |
|
|
|
string angularProjectsPath) |
|
|
|
{ |
|
|
|
var projects = new List<string>(); |
|
|
|
|
|
|
|
@ -190,25 +148,40 @@ namespace Volo.Abp.Cli.ProjectModification |
|
|
|
Directory.CreateDirectory(angularProjectsPath); |
|
|
|
} |
|
|
|
|
|
|
|
var angularPathsInDownloadedSourceCode = Directory.GetDirectories(Path.Combine(Path.Combine(Path.GetDirectoryName(solutionFilePath), "modules"))).Select(p => Path.Combine(p, "angular")) |
|
|
|
var angularPathsInDownloadedSourceCode = Directory |
|
|
|
.GetDirectories(Path.Combine(Path.Combine(Path.GetDirectoryName(solutionFilePath), "modules"))) |
|
|
|
.Select(p => Path.Combine(p, "angular")) |
|
|
|
.Where(Directory.Exists); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var folder in angularPathsInDownloadedSourceCode) |
|
|
|
{ |
|
|
|
var projectsInFolder = Directory.GetDirectories(folder); |
|
|
|
|
|
|
|
if (projectsInFolder.Length == 1 && Path.GetFileName(projectsInFolder[0]) == "projects") |
|
|
|
{ |
|
|
|
var foldersUnderProject = Directory.GetDirectories(Path.Combine(folder, "projects")); |
|
|
|
foreach (var folderUnderProject in foldersUnderProject) |
|
|
|
{ |
|
|
|
if (Directory.Exists(Path.Combine(folder, Path.GetFileName(folderUnderProject)))) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
Directory.Move(folderUnderProject, Path.Combine(folder, Path.GetFileName(folderUnderProject))); |
|
|
|
} |
|
|
|
projectsInFolder = Directory.GetDirectories(folder); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var projectInFolder in projectsInFolder) |
|
|
|
{ |
|
|
|
var projectName = Path.GetFileName(projectInFolder.TrimEnd('\\').TrimEnd('/')); |
|
|
|
|
|
|
|
var destDirName = Path.Combine(angularProjectsPath, projectName); |
|
|
|
if (Directory.Exists(destDirName)) |
|
|
|
if (projectName == "projects" || Directory.Exists(destDirName)) |
|
|
|
{ |
|
|
|
Directory.Delete(projectInFolder, true); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
projects.Add(projectName); |
|
|
|
|
|
|
|
Directory.Move(projectInFolder, destDirName); |
|
|
|
@ -217,5 +190,14 @@ namespace Volo.Abp.Cli.ProjectModification |
|
|
|
|
|
|
|
return projects; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<string> GetProjectPackageNameAsync(string angularProjectsPath, string project) |
|
|
|
{ |
|
|
|
var packageJsonPath = Path.Combine(angularProjectsPath, project, "package.json"); |
|
|
|
|
|
|
|
var fileContent = File.ReadAllText(packageJsonPath); |
|
|
|
|
|
|
|
return (string) JObject.Parse(fileContent)["name"]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|