Skip to content

Commit

Permalink
order imports by "from"
Browse files Browse the repository at this point in the history
  • Loading branch information
volkanceylan committed Oct 20, 2023
1 parent 5abea59 commit 5cc066a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,8 @@ protected override void AddFile(string filename, bool module = false)

if (moduleImportsLookup.Any())
{
sb.Insert(0, string.Join(Environment.NewLine, moduleImportsLookup.Select(z =>
sb.Insert(0, string.Join(Environment.NewLine, moduleImportsLookup
.Select(z =>
{
var from = z.Key.From;
if (!z.Key.External)
Expand Down Expand Up @@ -1114,8 +1115,9 @@ protected override void AddFile(string filename, bool module = false)
var importList = string.Join(", ", z.Select(p =>
p.Name + (p.Alias != p.Name ? (" as " + p.Alias) : "")));
return $"import {{ {importList} }} from \"{from}\";";
})) + Environment.NewLine + Environment.NewLine);
return (from, importList);
}).OrderBy(x => x.from, StringComparer.OrdinalIgnoreCase).Select(x => $"import {{ {x.importList} }} from \"{x.from}\";")) +
Environment.NewLine + Environment.NewLine);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/Serenity.Net.CodeGenerator/Helpers/ModularTSImporter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Scriban.Runtime;
using Scriban.Runtime;
using Serenity.CodeGeneration;

namespace Serenity.CodeGenerator;
Expand Down Expand Up @@ -67,7 +67,10 @@ public string GetImports()
if (moduleImports.IsEmptyOrNull())
return "";

return string.Join(Environment.NewLine, moduleImports.GroupBy(x => x.From).Select(x => "import { " + string.Join(", ", x.Select(y => y.Name)) + " } from '" + x.Key + "';")) + Environment.NewLine + Environment.NewLine;
return string.Join(Environment.NewLine, moduleImports
.OrderBy(x => x.From, StringComparer.OrdinalIgnoreCase)
.GroupBy(x => x.From, StringComparer.Ordinal)
.Select(x => "import { " + string.Join(", ", x.Select(y => y.Name)) + " } from '" + x.Key + "';")) + Environment.NewLine + Environment.NewLine;
}

delegate string ImportDelegate(string module, string import);
Expand Down

0 comments on commit 5cc066a

Please sign in to comment.