-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
168 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Mutatio | ||
{ | ||
public interface IProjectTemplate | ||
{ | ||
void BackupOldFormatFiles(); | ||
void CleanUpOldFormatFiles(); | ||
IEnumerable<(string name, string version)> GetPackages(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using MonoDevelop.Projects; | ||
using Mutatio.Extensions; | ||
|
||
namespace Mutatio | ||
{ | ||
public static class ProjectTemplateFactory | ||
{ | ||
public static IProjectTemplate GetTemplate(DotNetProject project) | ||
{ | ||
if (project.ContainsProjectJson()) | ||
return new ProjectWithProjectJson(project); | ||
else | ||
return new ProjectWithPackagesJson(project); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Xml.Linq; | ||
using MonoDevelop.Core; | ||
using MonoDevelop.Projects; | ||
using Mutatio.Extensions; | ||
|
||
namespace Mutatio | ||
{ | ||
public class ProjectWithPackagesJson : IProjectTemplate | ||
{ | ||
readonly DotNetProject proj; | ||
|
||
public ProjectWithPackagesJson(DotNetProject proj) | ||
{ | ||
this.proj = proj; | ||
} | ||
|
||
public void BackupOldFormatFiles() | ||
{ | ||
var backupFolderPath = $"{proj.BaseDirectory.FullPath.ParentDirectory}/mutatio_backup"; | ||
// Create backup directory | ||
FileService.CreateDirectory(backupFolderPath); | ||
// Backup current .xproj | ||
var projFilePath = proj.GetProjFilePath(); | ||
FileService.CopyFile(projFilePath, $"{backupFolderPath}/{proj.Name}.{proj.GetProjFileExtension()}"); | ||
// Backup packages.config | ||
var packagesConfigFilePath = proj.GetPackagesJsonFilePath(); | ||
FileService.CopyFile(packagesConfigFilePath, $"{backupFolderPath}/packages.config"); | ||
|
||
// Backup AssemblyInfo.x | ||
FileService.CopyDirectory(proj.GetPropertiesDirPath(), $"{backupFolderPath}/Properties"); | ||
} | ||
|
||
public void CleanUpOldFormatFiles() | ||
{ | ||
FileService.DeleteFile(proj.GetPackagesJsonFilePath()); | ||
FileService.DeleteDirectory(proj.GetPropertiesDirPath()); | ||
FileService.DeleteFile(proj.GetProjFilePath()); | ||
} | ||
|
||
public IEnumerable<(string name, string version)> GetPackages() | ||
{ | ||
var doc = XDocument.Load(proj.GetPackagesJsonFilePath()); | ||
return doc.Elements("packages").Descendants().Select(p => (p.Attribute("id").Value, p.Attribute("version").Value)); | ||
} | ||
|
||
public override string ToString() => "project with packages.json"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using MonoDevelop.Core; | ||
using MonoDevelop.Projects; | ||
using Mutatio.Extensions; | ||
using Newtonsoft.Json; | ||
|
||
namespace Mutatio | ||
{ | ||
public class ProjectWithProjectJson : IProjectTemplate | ||
{ | ||
readonly DotNetProject proj; | ||
|
||
public ProjectWithProjectJson(DotNetProject proj) | ||
{ | ||
this.proj = proj; | ||
} | ||
|
||
public void BackupOldFormatFiles() | ||
{ | ||
var backupFolderPath = $"{proj.BaseDirectory.FullPath.ParentDirectory}/mutatio_backup"; | ||
// Create backup directory | ||
FileService.CreateDirectory(backupFolderPath); | ||
// Backup current .xproj | ||
var projFilePath = proj.GetProjFilePath(); | ||
FileService.CopyFile(projFilePath, $"{backupFolderPath}/{proj.Name}.{proj.GetProjFileExtension()}"); | ||
// Backup project.json | ||
var projectJsonFilePath = proj.GetProjectJsonFilePath(); | ||
FileService.CopyFile(projectJsonFilePath, $"{backupFolderPath}/project.json"); | ||
// Backup project.lock.json | ||
if(File.Exists(proj.GetProjectLockJsonFilePath())) | ||
{ | ||
var projectLockJsonFilePath = proj.GetProjectLockJsonFilePath(); | ||
FileService.CopyFile(projectLockJsonFilePath, $"{backupFolderPath}/project.lock.json"); | ||
} | ||
// Backup AssemblyInfo.x | ||
FileService.CopyDirectory(proj.GetPropertiesDirPath(), $"{backupFolderPath}/Properties"); | ||
} | ||
|
||
public void CleanUpOldFormatFiles() | ||
{ | ||
FileService.DeleteFile(proj.GetProjectJsonFilePath()); | ||
if (File.Exists(proj.GetProjectLockJsonFilePath())) | ||
FileService.DeleteFile(proj.GetProjectLockJsonFilePath()); | ||
FileService.DeleteDirectory(proj.GetPropertiesDirPath()); | ||
FileService.DeleteFile(proj.GetProjFilePath()); | ||
} | ||
|
||
public IEnumerable<(string name, string version)> GetPackages() | ||
{ | ||
var projJsonContents = File.ReadAllText(proj.GetProjectJsonFilePath(), new UTF8Encoding(true)); | ||
var projJson = JsonConvert.DeserializeObject<ProjJson>(projJsonContents); | ||
return projJson.Dependencies.Select(d => (d.Key, d.Value)); | ||
} | ||
|
||
public override string ToString() => "project with project.json"; | ||
|
||
class ProjJson | ||
{ | ||
[JsonProperty("dependencies")] | ||
public Dictionary<string, string> Dependencies { get; set; } | ||
} | ||
} | ||
} |