-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProjectFileHandler.cs
More file actions
58 lines (50 loc) · 1.64 KB
/
Copy pathProjectFileHandler.cs
File metadata and controls
58 lines (50 loc) · 1.64 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
using Express.Net.Models;
using System;
using System.IO;
using System.Text.Json;
namespace Express.Net.Build.Services
{
internal static class ProjectFileHandler
{
private static readonly JsonSerializerOptions _jsonSerializerOptions = new ()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true,
PropertyNameCaseInsensitive = true,
};
public static Project? ReadProjectFile(
string projectFilePath)
{
var projectJson = File.ReadAllText(projectFilePath);
return JsonSerializer.Deserialize<Project>(projectJson, _jsonSerializerOptions);
}
public static void BuildProjectFile(
string projectName,
string outputDirectory)
{
var project = new Project(
Array.Empty<PackageReference>(),
Array.Empty<LibraryReference>(),
true,
true);
var jsonText = JsonSerializer.Serialize(project, _jsonSerializerOptions);
var fileName = $"{projectName}.enproj";
var path = Path.Combine(outputDirectory, fileName);
File.WriteAllText(path, jsonText);
}
public static void BuildServiceFile(
string projectName,
string outputDirectory)
{
var source = $@"
service {projectName}Service;
get Ok ()
{{
return Ok(""Hello World"");
}}".Trim();
var fileName = $"{projectName}Service.en";
var path = Path.Combine(outputDirectory, fileName);
File.WriteAllText(path, source);
}
}
}