Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pack.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dotnet restore NetCoreStack.Tools.sln
dotnet build NetCoreStack.Tools.sln
cd src/NetCoreStack.Hisar.WebCli.Tools
dotnet pack -o ../../nupkg --version-suffix preview13 -c Release
dotnet pack -o ../../nupkg --version-suffix preview21 -c Release
2 changes: 1 addition & 1 deletion pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
dotnet restore NetCoreStack.Tools.sln
dotnet build NetCoreStack.Tools.sln
cd src/NetCoreStack.Hisar.WebCli.Tools
dotnet pack -o ../../nupkg --version-suffix preview13 -c Release
dotnet pack -o ../../nupkg --version-suffix preview20 -c Release
25 changes: 14 additions & 11 deletions src/NetCoreStack.Hisar.WebCli.Tools/Core/CommandLineOptions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Microsoft.Extensions.CommandLineUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace NetCoreStack.Hisar.WebCli.Tools.Core
{
Expand All @@ -13,8 +10,8 @@ internal class CommandLineOptions
public bool IsHelp { get; private set; }
public bool IsVerbose { get; private set; }
public CommandOption MainAppDirectory { get; private set; }

public CommandOption StaticServe { get; private set; }
public CommandOption BuildComponent { get; private set; }

public static CommandLineOptions Parse(string[] args, IConsole console)
{
Expand All @@ -37,16 +34,20 @@ public static CommandLineOptions Parse(string[] args, IConsole console)
AllowArgumentSeparator = true,
ExtendedHelpText = @"
Remarks:
Hisar WebCLI provides modular component development without dependencies.
You can manage all the files you specified on --appdir option or you can serve static files only.
If you don't specify the main application directory it will create a default _Layout.cshtml page.
Hisar WebCli provides modular component development environements.
You can manage all the files you specified with --appdir option or serve static files with --static option.
However, NetCoreStack.Hisar rely on this tool to templating and create appropriate component packages.
If you don't specify the main application directory it will create a default simple _Layout.cshtml page.

For example: dotnet hisar --appdir <the-full-path-of-your-main-app>
dotnet hisar --static <the-full-path-of-your-static-files>
dotnet hisar --build <the-component-project-directory> (MsBuild entegrated)

Examples:
dotnet hisar
dotnet hisar --appdir C:/users/codes/project/src/WebApp.Hosting
dotnet hisar --appdir C:/users/codes/project/src/Hisar.Hosting
dotnet hisar --static C:/users/codes/project/wwwroot
dotnet hisar --build C:/users/codes/project/src/Hisar.Component.Carousel
"
};

Expand All @@ -55,6 +56,9 @@ dotnet hisar
var appdir = app.Option("-l|--appdir", "Main application directory",
CommandOptionType.SingleValue, inherited: true);

var buildComponent = app.Option("-l|--build", "Component directory",
CommandOptionType.SingleValue, inherited: true);

var staticServer = app.Option("-l|--static", "Static files serve",
CommandOptionType.SingleValue, inherited: true);

Expand All @@ -65,15 +69,14 @@ dotnet hisar
console.Out.WriteLine("invalid args syntax");
}

app.ShowHelp();

return new CommandLineOptions
{
App = app,
IsVerbose = optVerbose.HasValue(),
IsHelp = app.IsShowingInformation,
MainAppDirectory = appdir,
StaticServe = staticServer
StaticServe = staticServer,
BuildComponent = buildComponent
};
}
}
Expand Down
98 changes: 98 additions & 0 deletions src/NetCoreStack.Hisar.WebCli.Tools/Core/ComponentBuildHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using NetCoreStack.Hisar.WebCli.Tools.Interfaces;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace NetCoreStack.Hisar.WebCli.Tools.Core
{
public static class ComponentBuildHelper
{
private static List<string> excludeFiles = new List<string>
{
"favicon.ico",
"_references.js"
};

private static List<string> excludeStartsWith = new List<string>
{
"glyphicons-",
"font-awesome"
};

private static List<string> searchDirectories = new List<string>
{
"css",
"img",
"images",
"js",
"fonts"
};

/// <summary>
///
/// </summary>
/// <param name="componentId"></param>
/// <param name="directory"></param>
/// <returns>List of original files to be replace</returns>
private static List<string> RenameFiles(string componentId, string directory)
{
List<string> originalFiles = new List<string>();
var directoryInfo = new DirectoryInfo(directory);
var path = Path.Combine(directoryInfo.FullName, "wwwroot");
if (Directory.Exists(path))
{
var directories = Directory.GetDirectories(path);
foreach (var dic in directories)
{
var dInfo = new DirectoryInfo(dic);
if (searchDirectories.Contains(dInfo.Name))
{
var files = dInfo.GetFiles("*.*", SearchOption.AllDirectories);
if (files.Any())
{
foreach (var fInfo in files)
{
var fileName = fInfo.Name;
if (excludeFiles.Contains(fileName))
continue;

if (excludeStartsWith.Any(p => fileName.StartsWith(p)))
continue;

var prefix = $"{componentId.ToLowerInvariant()}-";

if (fileName.StartsWith(prefix))
continue;

originalFiles.Add(fInfo.FullName);
var movePath = Path.Combine(dInfo.FullName, $"{prefix}{fileName}");
File.Move(fInfo.FullName, movePath);
}
}
}
}
}

return originalFiles;
}

private static string[] GetViews(string directory)
{
var directoryInfo = new DirectoryInfo(directory);
var path = Path.Combine(directoryInfo.FullName, "Views");
if (Directory.Exists(path))
{
return Directory.GetFiles(path, "*.cshtml", SearchOption.AllDirectories);
}

return null;
}

public static IEnumerable<IComponentFileReplacer> Build(ComponentDefinition definition)
{
RenameFiles(definition.ComponentId, definition.ProjectDirectory);
var list = new List<IComponentFileReplacer>();
return list;
}
}
}
27 changes: 27 additions & 0 deletions src/NetCoreStack.Hisar.WebCli.Tools/Core/ComponentDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Linq;

namespace NetCoreStack.Hisar.WebCli.Tools.Core
{
public class ComponentDefinition
{
public string ProjectDirectory { get; }
public string ComponentId { get; }

public ComponentDefinition(string assemblyName, string projectDirectory)
{
if (string.IsNullOrEmpty(assemblyName))
{
throw new ArgumentNullException(nameof(assemblyName));
}

if (string.IsNullOrEmpty(projectDirectory))
{
throw new ArgumentNullException(nameof(assemblyName));
}

ComponentId = assemblyName.Split('.').Last();
ProjectDirectory = projectDirectory;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using NetCoreStack.Hisar.WebCli.Tools.Interfaces;

namespace NetCoreStack.Hisar.WebCli.Tools.Core
{
public class ComponentStaticFilesReplacer : IComponentFileReplacer
{
private readonly string[] _files;

public ComponentStaticFilesReplacer(params string[] files)
{
_files = files;
}

public void Invoke()
{
}
}
}
49 changes: 37 additions & 12 deletions src/NetCoreStack.Hisar.WebCli.Tools/Core/PathUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;

namespace NetCoreStack.Hisar.WebCli.Tools.Core
{
public static class PathUtility
{
private const string ContentFolderName = "content";
private static string _layoutPagePath = string.Empty;

public static string NormalizeToWebPath(string filter)
{
Expand Down Expand Up @@ -79,7 +79,7 @@ public static string GetRootPath(bool isContentRoot = false)
throw new Exception(message);
}

public static string GetAppDirectoryWebRoot(string directory)
public static string GetWebRootDirectory(string directory)
{
var directoryInfo = new DirectoryInfo(directory);
do
Expand All @@ -101,21 +101,46 @@ public static string GetAppDirectoryWebRoot(string directory)

public static string GetLayoutPagePath(string directory)
{
if (string.IsNullOrEmpty(_layoutPagePath))
var name = Path.GetFileName(HostingConstants.LayoutPageFullName);
var files = Directory.GetFiles(directory, name, SearchOption.AllDirectories);
if (files.Any())
{
var name = Path.GetFileName(HostingConstants.LayoutPageFullName);
var files = Directory.GetFiles(directory, name, SearchOption.AllDirectories);
if (files.Any())
var layoutPagePath = files.FirstOrDefault();
return layoutPagePath;
}

var message = $"Ex: {HostingConstants.LayoutPageFullName} could not be located in {directory}";
throw new Exception(message);
}

public static ComponentDefinition GetComponentInfo(string directory)
{
if (string.IsNullOrEmpty(directory))
{
throw new ArgumentNullException(nameof(directory));
}

var files = Directory.GetFiles(directory, "*.csproj", SearchOption.AllDirectories);
if (files.Any())
{
var csprojFile = files.FirstOrDefault();
using (var fs = new FileStream(csprojFile, FileMode.Open))
{
_layoutPagePath = files.FirstOrDefault();
return _layoutPagePath;
}
XDocument document = XDocument.Load(fs);
var candidatePropertyGroup = document.Element("Project")?.Descendants("PropertyGroup")
.Where(e => e.HasElements && e.Element("AssemblyName") != null).FirstOrDefault();

var message = $"Ex: {HostingConstants.LayoutPageFullName} could not be located in {directory}";
throw new Exception(message);
var elementValue = candidatePropertyGroup?.Element("AssemblyName")?.Value;
if (string.IsNullOrEmpty(elementValue))
{
elementValue = Path.GetFileNameWithoutExtension(csprojFile);
}

return new ComponentDefinition(elementValue, directory);
}
}

return _layoutPagePath;
return null;
}

private static List<string> _excludeDirs = new List<string> { "bin", "obj", "node_modules" };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Microsoft.AspNetCore.Routing;
using NetCoreStack.Hisar.WebCli.Tools.Models;
using NetCoreStack.Hisar.WebCli.Tools.Models;
using NetCoreStack.WebSockets;
using System;
using System.Linq;
using System.Net.WebSockets;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using NetCoreStack.Hisar.WebCli.Tools.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace NetCoreStack.Hisar.WebCli.Tools.Interfaces
{
public interface IComponentFileReplacer
{
void Invoke();
}
}
Loading