|
| 1 | +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. |
| 2 | + |
| 3 | +namespace Microsoft.Graph.ODataTemplateWriter.PathWriters |
| 4 | +{ |
| 5 | + using System; |
| 6 | + using System.IO; |
| 7 | + using System.Linq; |
| 8 | + using Microsoft.Graph.ODataTemplateWriter.Extensions; |
| 9 | + using Microsoft.Graph.ODataTemplateWriter.Settings; |
| 10 | + using Microsoft.Graph.ODataTemplateWriter.TemplateProcessor; |
| 11 | + |
| 12 | + public class TypeScriptPathWriter : PathWriterBase |
| 13 | + { |
| 14 | + |
| 15 | + public override string WritePath(ITemplateInfo template, String baseFileName) |
| 16 | + { |
| 17 | + var theNamespace = this.CreateNamespace(template.OutputParentDirectory.ToLower()); |
| 18 | + var namespacePath = this.CreatePathFromNamespace(theNamespace); |
| 19 | + var fileName = this.TransformFileName(template, baseFileName); |
| 20 | + String filePath = Path.Combine(namespacePath, fileName); |
| 21 | + return filePath; |
| 22 | + } |
| 23 | + |
| 24 | + private string CreateNamespace(string folderName) |
| 25 | + { |
| 26 | + var @namespace = this.Model.GetNamespace(); |
| 27 | + var prefix = ConfigurationService.Settings.NamespacePrefix; |
| 28 | + |
| 29 | + if (String.IsNullOrEmpty(ConfigurationService.Settings.NamespaceOverride)) |
| 30 | + { |
| 31 | + if (string.IsNullOrEmpty(folderName)) |
| 32 | + { |
| 33 | + return string.IsNullOrEmpty(prefix) ? @namespace |
| 34 | + : string.Format("{0}.{1}", prefix, @namespace); |
| 35 | + } |
| 36 | + |
| 37 | + return string.IsNullOrEmpty(prefix) ? string.Format("{0}.{1}", @namespace, folderName) |
| 38 | + : string.Format("{0}.{1}.{2}", prefix, @namespace, folderName); |
| 39 | + } |
| 40 | + |
| 41 | + @namespace = ConfigurationService.Settings.NamespaceOverride; |
| 42 | + return folderName != null ? string.Format("{0}.{1}", @namespace, folderName) |
| 43 | + : @namespace; |
| 44 | + } |
| 45 | + |
| 46 | + private string CreatePathFromNamespace(string @namespace) |
| 47 | + { |
| 48 | + var splitPaths = @namespace.Split('.'); |
| 49 | + |
| 50 | + var destinationPath = splitPaths.Aggregate(string.Empty, (current, path) => |
| 51 | + current + string.Format("{0}{1}", path, Path.DirectorySeparatorChar)); |
| 52 | + return destinationPath; |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments