-
Notifications
You must be signed in to change notification settings - Fork 762
/
Copy pathExpandPackageAssets.cs
67 lines (55 loc) · 1.64 KB
/
ExpandPackageAssets.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#nullable enable
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Uno.UI.Tasks.Assets
{
/// <summary>
/// Expands content assets from folders containing an uprimarker file
/// </summary>
public class ExpandPackageAssets_v0 : Task
{
[Required]
public ITaskItem[]? MarkerFiles { get; set; }
[Output]
public ITaskItem[]? Assets { get; set; }
= Array.Empty<ITaskItem>();
public override bool Execute()
{
Log.LogMessage($"Expanding package assets");
if (MarkerFiles != null)
{
List<ITaskItem> assets = new();
foreach (var markerFile in MarkerFiles)
{
var markerFileFullPath = markerFile.GetMetadata("FullPath");
var markerFileDirectory = Path.GetDirectoryName(markerFileFullPath);
var basePath = Path.Combine(markerFileDirectory, Path.GetFileNameWithoutExtension(markerFileFullPath));
if (Directory.Exists(basePath))
{
Log.LogMessage(MessageImportance.Low, $"Scanning directory ({basePath})");
var markerFileDirectoryForReplace = markerFileDirectory + Path.DirectorySeparatorChar;
foreach (var asset in Directory.EnumerateFiles(basePath, "*.*", SearchOption.AllDirectories))
{
var newItem = new TaskItem(
asset,
new Dictionary<string, string>
{
["TargetPath"] = asset.Replace(markerFileDirectoryForReplace, "")
});
assets.Add(newItem);
}
}
else
{
Log.LogMessage(MessageImportance.Low, $"No assets directory found ({basePath})");
}
}
Assets = assets.ToArray();
}
return true;
}
}
}