-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
82 lines (72 loc) · 2.58 KB
/
Program.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using ModernBusinessContinuity.lang;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
namespace ModernBusinessContinuity
{
public class Program
{
static Config config = new Config();
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
string configFile;
if (args.Length > 1)
{
configFile = args[0];
}
else
{
configFile = "config.json";
}
if (!File.Exists(configFile))
{
Console.WriteLine("Creating default config file");
var writeNewConfig = JsonSerializer.Serialize<Config>(config);
File.WriteAllText(configFile, writeNewConfig);
}
try
{
var jsonText = File.ReadAllText(configFile);
config = JsonSerializer.Deserialize<Config>(jsonText) ?? new Config();
var dirs = config.SourceDirs.Split(',', ';', ' ');
config.BuildDir = Path.GetFullPath(config.BuildDir);
var matchRegex = new Regex(!string.IsNullOrEmpty(config.only)? config.only: ".+\\.md", RegexOptions.IgnoreCase);
if (!Directory.Exists(config.BuildDir)) Directory.CreateDirectory(config.BuildDir);
foreach (var dir in dirs)
{
if (Directory.Exists(dir))
{
string[] fileEntries = Directory.GetFiles(dir);
var vXYZ = new VerteXYZ();
foreach (var file in fileEntries)
{
if (matchRegex.IsMatch(file))
{
vXYZ.GenerateFile(file, config.BuildDir);
}
}
}
else
{
Console.WriteLine("Source Directory error: " + config.SourceDirs);
}
}
}
catch (Exception ex)
{
Console.Write(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine);
}
}
}
/// <summary>
///
/// </summary>
public class Config
{
public string SourceDirs { get; set; } = "src/";
public string BuildDir { get; set; } = "build/";
public string main { get; set; } = "main.md";
public string only { get; set; } = String.Empty;
}
}