Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concatenate order #319

Open
rgroenewoudt opened this issue Jul 30, 2024 · 1 comment
Open

Concatenate order #319

rgroenewoudt opened this issue Jul 30, 2024 · 1 comment

Comments

@rgroenewoudt
Copy link

I would like support for ordering when concatenating files. I still have old Javascript files in which the order is important.

Something like:
.Concatenate(path=> path.Contains("module.js") ? 2 : 1)

The Concatenator class can be modified to use:

internal class Concatenator : Processor
{

private Func<int>? _pathPriorityFunc = null;
public Concatenator(Func<int>? pathPriorityFunc = null)
{
_pathPriorityFunc = pathPriorityFunc;
}

public override Task ExecuteAsync(IAssetContext context)
        {
            var sb = new StringBuilder();
            
            var keys = _pathPriorityFunc != null ? context.Content.Keys.Order(Comparer<string>.Create(Compare)) : context.Content.Keys;
            foreach (var k in keys)
            {
                sb.AppendLine(context.Content[k].AsString());
            }
....

private static int Compare(string x, string y)
{
    int prioX = _pathPriorityFunc(x);
    int prioY = _pathPriorityFunc(y);

    if (prioX < prioY)
        return -1;
    if (prioX > prioY)
        return 1;

    return 0;
}
@gabbsmo
Copy link

gabbsmo commented Nov 20, 2024

README mentions order preservation for CSS at least. Not sure if it is meant to work with JS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants