Skip to content

Concatenate order #319

Open
Open
@rgroenewoudt

Description

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;
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions