-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-extra.cake
More file actions
80 lines (62 loc) · 1.96 KB
/
build-extra.cake
File metadata and controls
80 lines (62 loc) · 1.96 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
#l "utilities.cake"
using YamlDotNet.Serialization;
public sealed class BuildConfig
{
[YamlAlias("input_dir")]
public string InputDir { get; set; }
[YamlAlias("output_dir")]
public string OutputDir { get; set; }
[YamlAlias("conversions")]
public ConvertConfig[] Conversions { get; set; }
}
public sealed class ConvertConfig
{
[YamlAlias("input")]
public string Input { get; set; }
[YamlAlias("output")]
public string Output { get; set; }
[YamlAlias("background")]
public string Background { get; set; }
[YamlAlias("level_colors")]
public string LevelColors { get; set; }
[YamlAlias("resize")]
public string Resize { get; set; }
}
public void Convert(BuildConfig buildConfig)
{
foreach (var conversion in buildConfig.Conversions)
{
Console.WriteLine("Converting {0} -> {1}", conversion.Input, conversion.Output);
Convert(
System.IO.Path.Combine(buildConfig.InputDir, conversion.Input),
System.IO.Path.Combine(buildConfig.OutputDir, conversion.Output),
background: conversion.Background,
levelColors: conversion.LevelColors,
resize: conversion.Resize
);
}
}
public void Convert(string inputFile, string outputFile,
string background = null, string levelColors = null, string resize = null
)
{
var arguments = new StringBuilder();
if (background != null)
{
arguments.AppendFormat(" -background {0}", background);
}
if (levelColors != null)
{
arguments.AppendFormat(" +level-colors {0}", levelColors);
}
if (resize != null)
{
arguments.AppendFormat(" -resize {0}", resize);
}
arguments.AppendFormat(" {0} {1}", inputFile, outputFile);
var exitCode = StartProcess(Which("convert"), new ProcessSettings { Arguments = arguments.ToString() });
if (exitCode != 0)
{
throw new Exception(String.Format("Error converting {0}", inputFile));
}
}