From f7e793204db5f614ad9c2c2e9212a09587d46d06 Mon Sep 17 00:00:00 2001 From: Geeksltd Date: Wed, 18 Nov 2020 10:37:40 +0000 Subject: [PATCH] Moved msharp-build to https://github.com/Geeksltd/msharp-build --- Utils/MSharp.Build/BuildTools.cs | 46 ---- Utils/MSharp.Build/Builder.cs | 74 ------ Utils/MSharp.Build/Commands.cs | 54 ----- Utils/MSharp.Build/Installers/@Installer.cs | 70 ------ Utils/MSharp.Build/Installers/DotNet.cs | 30 --- .../MSharp.Build/Installers/Linux/APT-Get.cs | 16 -- Utils/MSharp.Build/Installers/Linux/APT.cs | 16 -- Utils/MSharp.Build/Installers/NodeJs.cs | 16 -- .../Installers/Windows/Chocolaty.cs | 25 -- .../Installers/Windows/Powershell.cs | 18 -- Utils/MSharp.Build/Installers/Yarn.cs | 16 -- Utils/MSharp.Build/MSharp.Build.csproj | 34 --- Utils/MSharp.Build/OliveSolution.cs | 215 ------------------ Utils/MSharp.Build/Program.cs | 59 ----- Utils/MSharp.Build/Runtime.cs | 30 --- .../Tools/AcceleratePackageRestore.cs | 7 - Utils/MSharp.Build/Tools/Bower.cs | 16 -- Utils/MSharp.Build/Tools/BuildTool.cs | 67 ------ Utils/MSharp.Build/Tools/Chocolatey.cs | 25 -- Utils/MSharp.Build/Tools/DotNet.cs | 35 --- Utils/MSharp.Build/Tools/NetCoreGlobalTool.cs | 13 -- Utils/MSharp.Build/Tools/NodeJs.cs | 17 -- Utils/MSharp.Build/Tools/ReplaceInFile.cs | 7 - Utils/MSharp.Build/Tools/Typescript.cs | 14 -- Utils/MSharp.Build/Tools/WebPack.cs | 15 -- Utils/MSharp.Build/Tools/Yarn.cs | 16 -- Utils/MSharp.Build/readme.md | 29 --- 27 files changed, 980 deletions(-) delete mode 100644 Utils/MSharp.Build/BuildTools.cs delete mode 100644 Utils/MSharp.Build/Builder.cs delete mode 100644 Utils/MSharp.Build/Commands.cs delete mode 100644 Utils/MSharp.Build/Installers/@Installer.cs delete mode 100644 Utils/MSharp.Build/Installers/DotNet.cs delete mode 100644 Utils/MSharp.Build/Installers/Linux/APT-Get.cs delete mode 100644 Utils/MSharp.Build/Installers/Linux/APT.cs delete mode 100644 Utils/MSharp.Build/Installers/NodeJs.cs delete mode 100644 Utils/MSharp.Build/Installers/Windows/Chocolaty.cs delete mode 100644 Utils/MSharp.Build/Installers/Windows/Powershell.cs delete mode 100644 Utils/MSharp.Build/Installers/Yarn.cs delete mode 100644 Utils/MSharp.Build/MSharp.Build.csproj delete mode 100644 Utils/MSharp.Build/OliveSolution.cs delete mode 100644 Utils/MSharp.Build/Program.cs delete mode 100644 Utils/MSharp.Build/Runtime.cs delete mode 100644 Utils/MSharp.Build/Tools/AcceleratePackageRestore.cs delete mode 100644 Utils/MSharp.Build/Tools/Bower.cs delete mode 100644 Utils/MSharp.Build/Tools/BuildTool.cs delete mode 100644 Utils/MSharp.Build/Tools/Chocolatey.cs delete mode 100644 Utils/MSharp.Build/Tools/DotNet.cs delete mode 100644 Utils/MSharp.Build/Tools/NetCoreGlobalTool.cs delete mode 100644 Utils/MSharp.Build/Tools/NodeJs.cs delete mode 100644 Utils/MSharp.Build/Tools/ReplaceInFile.cs delete mode 100644 Utils/MSharp.Build/Tools/Typescript.cs delete mode 100644 Utils/MSharp.Build/Tools/WebPack.cs delete mode 100644 Utils/MSharp.Build/Tools/Yarn.cs delete mode 100644 Utils/MSharp.Build/readme.md diff --git a/Utils/MSharp.Build/BuildTools.cs b/Utils/MSharp.Build/BuildTools.cs deleted file mode 100644 index d8e022ea1..000000000 --- a/Utils/MSharp.Build/BuildTools.cs +++ /dev/null @@ -1,46 +0,0 @@ -using MSharp.Build.Tools; -using System; -using System.IO; -using System.Runtime.CompilerServices; - -namespace MSharp.Build -{ - class BuildTools : Builder - { - protected override void AddTasks() - { - Console.WriteLine("Help: http://learn.msharp.co.uk/#/Install/README"); - - Add(() => InstallReplaceInFiles()); - Add(() => InstallAcceleratePackageRestore()); - Add(() => InstallNodeJs()); - Add(() => InstallYarn()); - Add(() => InstallTypescript()); - Add(() => InstallWebPack()); - Add(() => InstallBower()); - } - - void InstallReplaceInFiles() => Install(); - void InstallAcceleratePackageRestore() => Install(); - - void InstallNodeJs() => Install(); - - void InstallYarn() => Install(); - - void InstallTypescript() => Install(); - - void InstallWebPack() => Install(); - - void InstallBower() => Install(); - - void Install([CallerMemberName] string step = "") where T : BuildTool, new() - { - var builder = new T(); - try - { - builder.Install(); - } - finally { Log(string.Join(Environment.NewLine, builder.Logs), step); } - } - } -} \ No newline at end of file diff --git a/Utils/MSharp.Build/Builder.cs b/Utils/MSharp.Build/Builder.cs deleted file mode 100644 index f58bfb5ee..000000000 --- a/Utils/MSharp.Build/Builder.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Runtime.CompilerServices; - -namespace MSharp.Build -{ - - abstract class Builder - { - static DateTime Start = DateTime.Now; - - Dictionary Steps = new Dictionary(); - List> LogMessages = new List>(); - - protected abstract void AddTasks(); - - protected void Add(Expression step) - { - var method = step.Body as MethodCallExpression; - var name = method.Method.Name; - - Steps.Add(name, () => method.Method.Invoke(this, new object[0])); - } - - protected void Add(string key, Action step) => Steps.Add(key, step); - - protected void Log(string message, [CallerMemberName] string step = "") - => LogMessages.Add(KeyValuePair.Create(step, message)); - - public void Build() - { - AddTasks(); - - foreach (var step in Steps) - { - try - { - Console.Write("Running " + step.Key + "..."); - step.Value(); - - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("Done. " + Math.Round(DateTime.Now.Subtract(Start).TotalSeconds, 1) + "s"); - Console.ResetColor(); - } - catch (Exception ex) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("Failed: " + ex.ToString()); - Console.ResetColor(); - throw ex; - } - } - } - - public void PrintLog() - { - foreach (var item in LogMessages.GroupBy(x => x.Key)) - { - Console.WriteLine(); - Console.WriteLine(); - Console.ForegroundColor = ConsoleColor.Cyan; - Console.WriteLine("-------Log: " + item.Key.PadRight(50, '-')); - Console.ForegroundColor = ConsoleColor.DarkGray; - - foreach (var x in item) - Console.WriteLine(x.Value); - } - - Console.ResetColor(); - } - } -} \ No newline at end of file diff --git a/Utils/MSharp.Build/Commands.cs b/Utils/MSharp.Build/Commands.cs deleted file mode 100644 index 6ba835cfc..000000000 --- a/Utils/MSharp.Build/Commands.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Olive; -using System; -using System.IO; -using System.Linq; -using System.Collections.Generic; - -namespace MSharp.Build -{ - class Commands - { - static Dictionary Exes = new Dictionary(); - public static FileInfo Chocolaty => FindExe("choco"); - public static FileInfo Yarn => FindExe("yarn"); - public static FileInfo NodeJs => FindExe("npm"); - public static FileInfo TypeScript => FindExe("tsc"); - public static FileInfo WebPack => FindExe("webpack"); - public static FileInfo Bower => FindExe("bower"); - public static FileInfo DotNet => FindExe("dotnet"); - public static FileInfo APT => FindExe("apt"); - public static FileInfo APT_GET => FindExe("apt-get"); - - public static FileInfo Where - { - get - { - if (Runtime.IsWindows()) - return System32("WHERE.exe").ExistsOrThrow(); - else if (Runtime.IsLinux()) - return "/usr/bin/whereis".AsFile(); - - throw new NotSupportedException(Runtime.OS.ToString()); - } - } - public static FileInfo FindExe(string fileInPathEnv) - { - if (!Exes.ContainsKey(fileInPathEnv)) - { - var output = Where.Execute(fileInPathEnv, configuration: x => x.StartInfo.WorkingDirectory = string.Empty); - Exes.Add(fileInPathEnv, output.Trim().ToLines().Select(x => x.AsFile()).First(x => x.Extension.HasValue())); - } - - return Exes[fileInPathEnv]; - } - - public static FileInfo Powershell => FindExe("powershell"); - - static FileInfo System32(string relative) - { - return Environment.SpecialFolder.Windows - .GetFile("System32\\" + relative) - .ExistsOrThrow(); - } - } -} diff --git a/Utils/MSharp.Build/Installers/@Installer.cs b/Utils/MSharp.Build/Installers/@Installer.cs deleted file mode 100644 index 7d2c96a28..000000000 --- a/Utils/MSharp.Build/Installers/@Installer.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Olive; - -namespace MSharp.Build.Installers -{ - abstract class Installer - { - Installer() - { - } - - public Installer(string name, string installCommand) - { - Name = name; - InstallCommand = installCommand; - } - - protected abstract FileInfo Executable { get; } - protected string InstallCommand { get; private set; } - protected string Name { get; private set; } - - internal virtual string Install() => Executable.Execute(InstallCommand); - - internal FileInfo Find() - { - try - { - return Commands.FindExe(Name); - } - catch - { - if (Executable != null && File.Exists(Executable.FullName)) - { - return Executable; - } - return null; - } - } - - internal bool IsInstalled() => Find()?.Exists ?? false; - - internal void AddToPath() - { - var toCheck = Find() ?? throw new Exception("Failed to locate the installed tool: " + Name); - - var parts = Environment.GetEnvironmentVariable("PATH").TrimOrEmpty().Split(';') - .Concat(new[] { toCheck.Directory.FullName }) - .Select(x => x + "\\") - .Select(x => x.Replace("\\\\", "\\")) - .Distinct() - .OrderBy(x => x.Contains("\\.")); - - var newPath = string.Join(";", parts); - - Environment.SetEnvironmentVariable("PATH", newPath); - Environment.SetEnvironmentVariable("PATH", newPath, EnvironmentVariableTarget.User); - - try - { - Environment.SetEnvironmentVariable("PATH", newPath, EnvironmentVariableTarget.Machine); - } - catch - { - } - } - } -} diff --git a/Utils/MSharp.Build/Installers/DotNet.cs b/Utils/MSharp.Build/Installers/DotNet.cs deleted file mode 100644 index 8d57251c5..000000000 --- a/Utils/MSharp.Build/Installers/DotNet.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Olive; - -namespace MSharp.Build.Installers -{ - class DotNet : Installer - { - internal DotNet(string name, string installCommand = null) : base(name, installCommand ?? "tool install -g " + name) - { - } - - protected override FileInfo Executable => Commands.DotNet; - - internal override string Install() - { - try - { - return base.Install(); - } - catch (Exception ex) - { - if (ex.Message.Contains("already installed")) - return string.Empty; - throw; - } - } - } -} diff --git a/Utils/MSharp.Build/Installers/Linux/APT-Get.cs b/Utils/MSharp.Build/Installers/Linux/APT-Get.cs deleted file mode 100644 index a258b14b5..000000000 --- a/Utils/MSharp.Build/Installers/Linux/APT-Get.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace MSharp.Build.Installers.Linux -{ - class APTGet : Installer - { - public APTGet(string name, string installCommand) : base(name, installCommand) - { - } - - protected override FileInfo Executable => Commands.APT_GET; - } -} diff --git a/Utils/MSharp.Build/Installers/Linux/APT.cs b/Utils/MSharp.Build/Installers/Linux/APT.cs deleted file mode 100644 index 9f528c5ac..000000000 --- a/Utils/MSharp.Build/Installers/Linux/APT.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace MSharp.Build.Installers.Linux -{ - class APT : Installer - { - public APT(string name, string installCommand) : base(name, installCommand) - { - } - - protected override FileInfo Executable => Commands.APT; - } -} diff --git a/Utils/MSharp.Build/Installers/NodeJs.cs b/Utils/MSharp.Build/Installers/NodeJs.cs deleted file mode 100644 index fbb85a340..000000000 --- a/Utils/MSharp.Build/Installers/NodeJs.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace MSharp.Build.Installers -{ - class NodeJs : Installer - { - public NodeJs(string name, string installCommand = null) : base(name, installCommand ?? "install -g " + name) - { - } - - protected override FileInfo Executable => Commands.NodeJs; - } -} diff --git a/Utils/MSharp.Build/Installers/Windows/Chocolaty.cs b/Utils/MSharp.Build/Installers/Windows/Chocolaty.cs deleted file mode 100644 index a4da53b45..000000000 --- a/Utils/MSharp.Build/Installers/Windows/Chocolaty.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Olive; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace MSharp.Build.Installers.Windows -{ - class Chocolaty : Installer - { - public Chocolaty(string name, string installCommand = null) : base(name, installCommand ?? "install " + name) - { - - } - - protected override FileInfo Executable => Commands.Chocolaty; - - internal override string Install() - { - var wrappedCommand = $"-noprofile -command \"&{{ start-process -FilePath '{Executable.FullName}' -ArgumentList '{InstallCommand} -y' -Wait -Verb RunAs}}\""; - - return Commands.Powershell.Execute(wrappedCommand); - } - } -} diff --git a/Utils/MSharp.Build/Installers/Windows/Powershell.cs b/Utils/MSharp.Build/Installers/Windows/Powershell.cs deleted file mode 100644 index 37680c8e8..000000000 --- a/Utils/MSharp.Build/Installers/Windows/Powershell.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Olive; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace MSharp.Build.Installers.Windows -{ - class Powershell : Installer - { - public Powershell(string name, string installCommand) : base(name, installCommand) - { - - } - - protected override FileInfo Executable => Commands.Powershell; - } -} diff --git a/Utils/MSharp.Build/Installers/Yarn.cs b/Utils/MSharp.Build/Installers/Yarn.cs deleted file mode 100644 index b08522090..000000000 --- a/Utils/MSharp.Build/Installers/Yarn.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace MSharp.Build.Installers -{ - class Yarn : Installer - { - public Yarn(string name, string installCommand = null) : base(name, installCommand ?? "global add " + name) - { - } - - protected override FileInfo Executable => Commands.Yarn; - } -} diff --git a/Utils/MSharp.Build/MSharp.Build.csproj b/Utils/MSharp.Build/MSharp.Build.csproj deleted file mode 100644 index bc04098b7..000000000 --- a/Utils/MSharp.Build/MSharp.Build.csproj +++ /dev/null @@ -1,34 +0,0 @@ - - - - Exe - netcoreapp3.0 - true - msharp-build - Geeks Ltd - Geeks Ltd - Provides build functionality for M# projects - msharp-build - https://github.com/Geeksltd/MSharp.Docs/raw/master/_media/MSharp.png - msharp-build - msharp-build - Minor fixes - False - OnOutputUpdated - 3.1.103 - 3.1.103 - 3.1.103 - 3.1.103 - - - - - - - - - - ..\..\bin\netstandard2.0\Olive.dll - - - \ No newline at end of file diff --git a/Utils/MSharp.Build/OliveSolution.cs b/Utils/MSharp.Build/OliveSolution.cs deleted file mode 100644 index b556f7374..000000000 --- a/Utils/MSharp.Build/OliveSolution.cs +++ /dev/null @@ -1,215 +0,0 @@ -using Olive; -using System; -using System.IO; -using System.Linq; -using System.Xml.Linq; - -namespace MSharp.Build -{ - class OliveSolution : Builder - { - DirectoryInfo Root, Lib; - readonly bool Publish; - public bool IsDotNetCore, IsWebForms; - - public OliveSolution(DirectoryInfo root, bool publish) - { - Root = root; - Publish = publish; - Lib = root.CreateSubdirectory(@"M#\lib"); - IsDotNetCore = IsProjectDotNetCore(); - IsWebForms = root.GetSubDirectory("Website").GetFiles("*.csproj").None(); - - if (IsDotNetCore) - { - Lib = new[] { "3.1", "2.2", "2.1" }.Select(x => Lib.GetSubDirectory("netcoreapp" + x)) - .FirstOrDefault(x => x.Exists()) - ?? throw new Exception("netcoreapp3.1 folder is not found in " + Lib.FullName); - } - } - - bool IsProjectDotNetCore() - { - return Lib.Parent.GetSubDirectory("Model").GetFile("#Model.csproj").ReadAllText() - .Contains("netcoreapp"); - } - - protected override void AddTasks() - { - Add(() => BuildRuntimeConfigJson()); - Add(() => RestoreNuget()); - Add(() => BuildMSharpModel()); - Add(() => MSharpGenerateModel()); - Add(() => BuildAppDomain()); - Add(() => BuildMSharpUI()); - Add(() => MSharpGenerateUI()); - Add(() => YarnInstall()); - Add(() => InstallBowerComponents()); - Add(() => TypescriptCompile()); - Add(() => SassCompile()); - Add(() => BuildAppWebsite()); - } - - void BuildRuntimeConfigJson() - { - var json = @"{ - ""runtimeOptions"":{ - ""tfm"":""VERSION"", - ""framework"":{ - ""name"":""Microsoft.NETCore.App"", - ""version"":""2.MINOR-VER.0"" - } - } -}".Replace("VERSION", Lib.Name).Replace("MINOR-VER", Lib.Name.Last().ToString()); - File.WriteAllText(Path.Combine(Lib.FullName, "MSharp.DSL.runtimeconfig.json"), json); - } - - void RestoreNuget() - { - if (!IsDotNetCore) - Commands.FindExe("nuget").Execute("restore", - configuration: x => x.StartInfo.WorkingDirectory = Root.FullName); - } - - void BuildMSharpModel() => DotnetBuild("M#\\Model"); - - void BuildAppDomain() => DotnetBuild("Domain"); - - void BuildMSharpUI() => DotnetBuild("M#\\UI"); - - void BuildAppWebsite() - { - if (IsWebForms) - { - RestorePackagesConfig("Website"); - CopyDllsToWebsite(); - } - else DotnetBuild("Website", "publish -o ..\\publish".OnlyWhen(Publish)); - } - - private void CopyDllsToWebsite() - { - var bin = "Website/bin".AsDirectory(); - - var dllPaths = from file in bin.GetFiles("*.refresh") - let source = Root.GetSubDirectory("Website").GetFile(file.ReadAllText()) - let item = new - { - Source = source, - Destination = bin.GetFile(source.Name) - } - where item.Destination.Exists == false - select item; - - dllPaths.Do(p => File.Copy(p.Source.FullName, p.Destination.FullName, true)); - } - - const string PACKAGES_DIRECTORY = "packages"; - void RestorePackagesConfig(string folder) - { - var packages = Folder(folder).AsDirectory().GetFile("packages.config"); - if (packages.Exists()) - { - Commands.FindExe("nuget").Execute("restore " + folder + " -packagesdirectory " + Root.GetOrCreateSubDirectory(PACKAGES_DIRECTORY).FullName, - configuration: x => x.StartInfo.WorkingDirectory = Root.FullName); - } - } - - FileInfo GetPackages(string folder) => Folder(folder).AsDirectory().GetFile("packages.config"); - - - string GetProjectSolution() => Root.GetFiles("*.sln")[0].FullName; - void DotnetBuild(string folder, string command = null) - { - if (IsDotNetCore) DotnetCoreBuild(folder, command); - else - { - RestorePackagesConfig(folder); - - var solution = GetProjectSolution(); - var projName = folder; - var project = folder.AsDirectory().GetFiles("*.csproj")[0].FullName; - if (folder.StartsWith("M#\\")) projName = "#" + folder.TrimStart("M#\\"); - - var dep = " /p:BuildProjectReferences=false".OnlyWhen(folder.StartsWith("M#")); - - Commands.FindExe("msbuild").Execute($"\"{project}\" -v:m", - configuration: x => x.StartInfo.EnvironmentVariables.Add("MSHARP_BUILD", "FULL")); - } - } - - void DotnetCoreBuild(string folder, string command = null) - { - if (command.IsEmpty()) command = "build -v q"; - - var log = Commands.DotNet.Execute(command, - configuration: x => - { - x.StartInfo.WorkingDirectory = Folder(folder); - x.StartInfo.EnvironmentVariables.Add("MSHARP_BUILD", "FULL"); - }); - - Log(log); - } - - void MSharpGenerateModel() => RunMSharpBuild("/build /model /no-domain"); - - void MSharpGenerateUI() => RunMSharpBuild("/build /ui"); - - void RunMSharpBuild(string command) - { - string log; - if (IsDotNetCore) - { - log = Commands.DotNet.Execute($"msharp.dsl.dll " + command, - configuration: x => x.StartInfo.WorkingDirectory = Lib.FullName); - } - else - { - log = Lib.GetFile("MSharp.dsl.exe").Execute(command, configuration: x => x.StartInfo.WorkingDirectory = Lib.FullName); - } - - Log(log); - } - - void YarnInstall() - { - var log = Commands.Yarn.Execute("install", - configuration: x => x.StartInfo.WorkingDirectory = Folder("Website")); - Log(log); - } - - void InstallBowerComponents() - { - if (!Folder("Website\\bower.json").AsFile().Exists) - { - Console.Write("Skipped - bower.json is not found."); - return; - } - - var log = Commands.Bower.Execute("install", - configuration: x => x.StartInfo.WorkingDirectory = Folder("Website")); - Log(log); - } - - void TypescriptCompile() - { - var log = Commands.TypeScript.Execute("", - configuration: x => x.StartInfo.WorkingDirectory = Folder("Website")); - Log(log); - } - - void SassCompile() - { - if (!IsDotNetCore) return; - - var log = Folder("Website\\wwwroot\\Styles\\Build\\SassCompiler.exe") - .AsFile() - .Execute("\"" + Folder("Website\\CompilerConfig.json") + "\""); - - Log(log); - } - - string Folder(string relative) => Root.GetSubDirectory(relative).FullName; - } -} \ No newline at end of file diff --git a/Utils/MSharp.Build/Program.cs b/Utils/MSharp.Build/Program.cs deleted file mode 100644 index ae3845115..000000000 --- a/Utils/MSharp.Build/Program.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Olive; -using System; -using System.IO; -using System.Linq; - -namespace MSharp.Build -{ - class Program - { - static bool Log; - - static int Main(string[] args) - { - Log = args.Contains("-log"); - - var result = 0; - - if (args.Lacks("-notools")) - { - var buildTools = new BuildTools(); - result = Run(() => buildTools.Build(), buildTools.PrintLog); - if (result != 0) return result; - } - - if (args.Lacks("-tools")) - { - var root = new DirectoryInfo(Environment.CurrentDirectory.TrimEnd('\\')); - - Console.WriteLine("Build started for: " + root.FullName); - Console.WriteLine(); - - var solution = new OliveSolution(root, publish: args.Contains("-publish")); - result = Run(() => solution.Build(), solution.PrintLog); - } - - return result; - } - - static int Run(Action work, Action printLog) - { - try - { - work(); - return 0; - } - catch (Exception ex) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(ex.ToLogString()); - Console.ResetColor(); - return -1; - } - finally - { - if (Log) printLog(); - } - } - } -} \ No newline at end of file diff --git a/Utils/MSharp.Build/Runtime.cs b/Utils/MSharp.Build/Runtime.cs deleted file mode 100644 index c39c5c9f3..000000000 --- a/Utils/MSharp.Build/Runtime.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; - -namespace MSharp.Build -{ - static class Runtime - { - internal static bool IsWindows() => OS == OSPlatform.Windows; - internal static bool IsLinux() => OS == OSPlatform.Linux; - - internal static OSPlatform OS - { - get - { - var result = new[] - { - OSPlatform.Windows, - OSPlatform.Linux - }.FirstOrDefault(os => RuntimeInformation.IsOSPlatform(os)); - if (result == null) - throw new NotSupportedException(RuntimeInformation.OSDescription); - - return result; - } - } - } -} diff --git a/Utils/MSharp.Build/Tools/AcceleratePackageRestore.cs b/Utils/MSharp.Build/Tools/AcceleratePackageRestore.cs deleted file mode 100644 index 4ea2441d2..000000000 --- a/Utils/MSharp.Build/Tools/AcceleratePackageRestore.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MSharp.Build.Tools -{ - class AcceleratePackageRestore : NetCoreGlobalTool - { - protected override string Name => "accelerate-package-restore"; - } -} diff --git a/Utils/MSharp.Build/Tools/Bower.cs b/Utils/MSharp.Build/Tools/Bower.cs deleted file mode 100644 index 0c3be8bd9..000000000 --- a/Utils/MSharp.Build/Tools/Bower.cs +++ /dev/null @@ -1,16 +0,0 @@ -using MSharp.Build.Installers; -using Olive; -using System; -using System.IO; - -namespace MSharp.Build.Tools -{ - class Bower : BuildTool - { - protected override string Name => "bower"; - - protected override Installer LinuxInstaller => new Installers.NodeJs(Name); - - protected override Installer WindowsInstaller => new Installers.Windows.Chocolaty(Name); - } -} \ No newline at end of file diff --git a/Utils/MSharp.Build/Tools/BuildTool.cs b/Utils/MSharp.Build/Tools/BuildTool.cs deleted file mode 100644 index d2388ccfe..000000000 --- a/Utils/MSharp.Build/Tools/BuildTool.cs +++ /dev/null @@ -1,67 +0,0 @@ -using MSharp.Build.Installers; -using Olive; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; - -namespace MSharp.Build.Tools -{ - abstract class BuildTool - { - protected abstract Installer WindowsInstaller { get; } - protected abstract Installer LinuxInstaller { get; } - protected Installer Installer - { - get - { - if (Runtime.OS == OSPlatform.Windows) - return WindowsInstaller; - - if (Runtime.OS == OSPlatform.Linux) - return LinuxInstaller; - - throw new NotSupportedException(Runtime.OS.ToString()); - } - } - protected abstract string Name { get; } - - public FileInfo Path { get; set; } - - protected virtual void OnInstalled() { } - - protected virtual bool AlwaysInstall => false; - - public List Logs = new List(); - - public void Install() - { - if (!AlwaysInstall) - if (Installer.IsInstalled()) ; - - var log = Execute(); - Logs.Add(log); - - Installer.AddToPath(); - - OnInstalled(); - - if (!Installer.IsInstalled()) - throw new Exception($"Failed to install {Name}. Install it manually."); - } - - protected virtual string Execute() - { - return Installer.Install(); - } - - internal FileInfo GetActualPath() - { - if (Installer.IsInstalled()) return Path; - throw new Exception(Name + " does not seem to be installed"); - } - } -} \ No newline at end of file diff --git a/Utils/MSharp.Build/Tools/Chocolatey.cs b/Utils/MSharp.Build/Tools/Chocolatey.cs deleted file mode 100644 index eab1e2adc..000000000 --- a/Utils/MSharp.Build/Tools/Chocolatey.cs +++ /dev/null @@ -1,25 +0,0 @@ -using MSharp.Build.Installers; -using MSharp.Build.Installers.Windows; -using Olive; -using System; -using System.IO; - -namespace MSharp.Build.Tools -{ - class Chocolatey : BuildTool - { - protected override Installer LinuxInstaller => null; - protected override Installer WindowsInstaller => new Powershell(Name, @"-NoProfile -InputFormat None -ExecutionPolicy Bypass -Command ""iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"""); - - protected override string Name => "choco"; - - protected override void OnInstalled() - { - if (Installer.IsInstalled()) - { - var log = Commands.Chocolaty.Execute("feature enable -n allowGlobalConfirmation"); - Logs.Add("Enable allow global feature: " + log); - } - } - } -} diff --git a/Utils/MSharp.Build/Tools/DotNet.cs b/Utils/MSharp.Build/Tools/DotNet.cs deleted file mode 100644 index 723854797..000000000 --- a/Utils/MSharp.Build/Tools/DotNet.cs +++ /dev/null @@ -1,35 +0,0 @@ -using MSharp.Build.Installers; -using Olive; -using System; -using System.IO; - -namespace MSharp.Build.Tools -{ - abstract class DotNet : BuildTool - { - protected override string Name => "dotnet"; - - protected override Installer LinuxInstaller => new Installers.Linux.APTGet(Name, "sudo apt-get update; sudo apt-get install -y apt-transport-https && sudo apt-get update && sudo apt-get install -y dotnet-sdk-" + Version); - - protected override Installer WindowsInstaller => new Installers.Windows.Chocolaty(Name, "install dotnetcore-sdk --version " + Version); - - protected override bool AlwaysInstall => true; - - protected abstract string Version { get; } - } - - class DotNet215 : DotNet - { - protected override string Version => "2.1.5"; - } - - class DotNet22 : DotNet - { - protected override string Version => "2.2"; - } - - class DotNet31 : DotNet - { - protected override string Version => "3.1"; - } -} \ No newline at end of file diff --git a/Utils/MSharp.Build/Tools/NetCoreGlobalTool.cs b/Utils/MSharp.Build/Tools/NetCoreGlobalTool.cs deleted file mode 100644 index 2f9500e72..000000000 --- a/Utils/MSharp.Build/Tools/NetCoreGlobalTool.cs +++ /dev/null @@ -1,13 +0,0 @@ -using MSharp.Build.Installers; -using Olive; -using System; -using System.IO; - -namespace MSharp.Build.Tools -{ - abstract class NetCoreGlobalTool : BuildTool - { - protected override Installer LinuxInstaller => WindowsInstaller; - protected override Installer WindowsInstaller => new Installers.DotNet(Name); - } -} diff --git a/Utils/MSharp.Build/Tools/NodeJs.cs b/Utils/MSharp.Build/Tools/NodeJs.cs deleted file mode 100644 index 31b14a638..000000000 --- a/Utils/MSharp.Build/Tools/NodeJs.cs +++ /dev/null @@ -1,17 +0,0 @@ -using MSharp.Build.Installers; -using Olive; -using System; -using System.IO; - -namespace MSharp.Build.Tools -{ - class NodeJs : BuildTool - { - protected override string Name => "npm"; - - protected override Installer LinuxInstaller => new Installers.Linux.APT(Name, "apt install nodejs -yq && apt install npm -yq"); - - protected override Installer WindowsInstaller => new Installers.Windows.Chocolaty(Name, "install nodejs.install"); - - } -} \ No newline at end of file diff --git a/Utils/MSharp.Build/Tools/ReplaceInFile.cs b/Utils/MSharp.Build/Tools/ReplaceInFile.cs deleted file mode 100644 index 35a3cd745..000000000 --- a/Utils/MSharp.Build/Tools/ReplaceInFile.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MSharp.Build.Tools -{ - class ReplaceInFile : NetCoreGlobalTool - { - protected override string Name => "replace-in-file"; - } -} diff --git a/Utils/MSharp.Build/Tools/Typescript.cs b/Utils/MSharp.Build/Tools/Typescript.cs deleted file mode 100644 index 8568784db..000000000 --- a/Utils/MSharp.Build/Tools/Typescript.cs +++ /dev/null @@ -1,14 +0,0 @@ -using MSharp.Build.Installers; -using Olive; -using System; -using System.IO; - -namespace MSharp.Build.Tools -{ - class Typescript : BuildTool - { - protected override string Name => "typescript"; - protected override Installer LinuxInstaller => WindowsInstaller; - protected override Installer WindowsInstaller => new Installers.NodeJs(Name); - } -} diff --git a/Utils/MSharp.Build/Tools/WebPack.cs b/Utils/MSharp.Build/Tools/WebPack.cs deleted file mode 100644 index a0220ae78..000000000 --- a/Utils/MSharp.Build/Tools/WebPack.cs +++ /dev/null @@ -1,15 +0,0 @@ -using MSharp.Build.Installers; -using Olive; -using System; -using System.IO; - -namespace MSharp.Build.Tools -{ - class WebPack : BuildTool - { - protected override string Name => "webpack"; - - protected override Installer LinuxInstaller => WindowsInstaller; - protected override Installer WindowsInstaller => new Installers.NodeJs(Name); - } -} diff --git a/Utils/MSharp.Build/Tools/Yarn.cs b/Utils/MSharp.Build/Tools/Yarn.cs deleted file mode 100644 index 13698b07e..000000000 --- a/Utils/MSharp.Build/Tools/Yarn.cs +++ /dev/null @@ -1,16 +0,0 @@ -using MSharp.Build.Installers; -using Olive; -using System; -using System.IO; - -namespace MSharp.Build.Tools -{ - class Yarn : BuildTool - { - protected override string Name => "yarn"; - - protected override Installer WindowsInstaller => new Installers.Windows.Chocolaty(Name); - - protected override Installer LinuxInstaller => new Installers.NodeJs(Name); - } -} diff --git a/Utils/MSharp.Build/readme.md b/Utils/MSharp.Build/readme.md deleted file mode 100644 index 829294858..000000000 --- a/Utils/MSharp.Build/readme.md +++ /dev/null @@ -1,29 +0,0 @@ -# M# Build Tool - -To install this tool, in `cmd` run the following: - -``` -C:\> dotnet tool install --global msharp-build -``` - -## Create a new M# project -To create a new M# project, run the following command: -``` -C:\Projects\> msharp-build /new /n:"Project.Name" [/t:https://github.com/Geeksltd/Olive.MvcTemplate/tree/master/Template] -``` -At this point, the template repository will be downloaded [from here](https://github.com/Geeksltd/Olive.MvcTemplate/tree/master/Template), and the placeholders will be replaced with the name provided in the `/n:` parameter. - -The `/t:...` parameter is optional, and defaults to the above. Alternatively, you can provide your own project template repository (which must be publically accessible). - - -## Build an existing project -To create a new M# project, run the following command: -``` -C:\Projects\MyProject\> msharp-build -``` - -## Install build tools (prepare your environment) -You need to do this only once, to ensure your development environment is prepared, with all necessary tools installed: -```js -C:\>msharp-build /tools -```