Skip to content

Commit

Permalink
[JS] Config JS surchargeable
Browse files Browse the repository at this point in the history
  • Loading branch information
JabX committed Sep 4, 2024
1 parent 0c9d488 commit ee7b399
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions TopModel.Generator.Javascript/JavascriptConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class JavascriptConfig : GeneratorConfigBase

protected override string NullValue => "undefined";

public string GetClassFileName(Class classe, string tag)
public virtual string GetClassFileName(Class classe, string tag)
{
return Path.Combine(
OutputDirectory,
Expand All @@ -113,7 +113,7 @@ public string GetClassFileName(Class classe, string tag)
.Replace("\\", "/");
}

public string GetCommentResourcesFilePath(Namespace ns, string tag, string lang)
public virtual string GetCommentResourcesFilePath(Namespace ns, string tag, string lang)
{
return Path.Combine(
OutputDirectory,
Expand All @@ -123,13 +123,13 @@ public string GetCommentResourcesFilePath(Namespace ns, string tag, string lang)
.Replace("\\", "/");
}

public IEnumerable<(string Import, string Path)> GetDomainImportPaths(string fileName, IProperty prop, string tag)
public virtual IEnumerable<(string Import, string Path)> GetDomainImportPaths(string fileName, IProperty prop, string tag)
{
return GetDomainImports(prop, tag)
.Select(import => (Import: import.Split("/").Last(), Path: GetRelativePath(import[..import.LastIndexOf('/')], fileName)));
}

public List<(string Import, string Path)> GetEndpointImports(string fileName, IEnumerable<Endpoint> endpoints, string tag, IEnumerable<Class> availableClasses)
public virtual List<(string Import, string Path)> GetEndpointImports(string fileName, IEnumerable<Endpoint> endpoints, string tag, IEnumerable<Class> availableClasses)
{
return endpoints.SelectMany(e => e.ClassDependencies)
.Select(dep => (
Expand All @@ -143,7 +143,7 @@ public string GetCommentResourcesFilePath(Namespace ns, string tag, string lang)
.GroupAndSort();
}

public string GetEndpointsFileName(ModelFile file, string tag)
public virtual string GetEndpointsFileName(ModelFile file, string tag)
{
return Path.Combine(
OutputDirectory,
Expand All @@ -152,7 +152,7 @@ public string GetEndpointsFileName(ModelFile file, string tag)
.Replace("\\", "/");
}

public string? GetImportPathForClass(ClassDependency dep, string targetTag, string sourceTag, IEnumerable<Class> availableClasses)
public virtual string? GetImportPathForClass(ClassDependency dep, string targetTag, string sourceTag, IEnumerable<Class> availableClasses)
{
string target;
if (dep is { Source: IProperty and not CompositionProperty and not AliasProperty { Property: CompositionProperty } })
Expand Down Expand Up @@ -196,7 +196,7 @@ public string GetEndpointsFileName(ModelFile file, string tag)
return path;
}

public string GetMainResourceFilePath(string tag, string lang)
public virtual string GetMainResourceFilePath(string tag, string lang)
{
return Path.Combine(
OutputDirectory,
Expand All @@ -206,19 +206,19 @@ public string GetMainResourceFilePath(string tag, string lang)
.Replace("\\", "/");
}

public string GetReferencesFileName(Namespace ns, string tag)
public virtual string GetReferencesFileName(Namespace ns, string tag)
{
return Path.Combine(OutputDirectory, ResolveVariables(ModelRootPath!, tag), ns.ModulePathKebab, "references.ts").Replace("\\", "/");
}

public string GetRelativePath(string path, string fileName)
public virtual string GetRelativePath(string path, string fileName)
{
return !path.StartsWith('.')
? path
: Path.GetRelativePath(string.Join('/', fileName.Split('/').SkipLast(1)), Path.Combine(OutputDirectory, path)).Replace("\\", "/");
}

public string GetResourcesFilePath(Namespace ns, string tag, string lang)
public virtual string GetResourcesFilePath(Namespace ns, string tag, string lang)
{
return Path.Combine(
OutputDirectory,
Expand All @@ -228,13 +228,13 @@ public string GetResourcesFilePath(Namespace ns, string tag, string lang)
.Replace("\\", "/");
}

public IEnumerable<(string Import, string Path)> GetValueImportPaths(string fileName, IProperty prop, string? value = null)
public virtual IEnumerable<(string Import, string Path)> GetValueImportPaths(string fileName, IProperty prop, string? value = null)
{
return GetValueImports(prop, value)
.Select(import => (Import: import.Split("/").Last(), Path: GetRelativePath(import[..import.LastIndexOf('/')], fileName)));
}

public bool IsListComposition(IProperty property)
public virtual bool IsListComposition(IProperty property)
{
var cp = property switch
{
Expand Down
2 changes: 1 addition & 1 deletion TopModel.Generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void HandleFile(FileInfo file)
if (returnCode == 0)
{
generators.AddRange(new DirectoryInfo(Path.Combine(Path.GetFullPath(cg, new FileInfo(fullName).DirectoryName!), "bin"))
.GetFiles("TopModel.Generator.*.dll", SearchOption.AllDirectories)
.GetFiles($"{cg.Split('/').Last()}.dll", SearchOption.AllDirectories)
.Where(a => a.FullName.Contains(framework) && a.Name != "TopModel.Generator.Core.dll")
.DistinctBy(a => a.Name)
.Select(f => Assembly.LoadFrom(f.FullName))
Expand Down

0 comments on commit ee7b399

Please sign in to comment.