【重构】模块相关函数由StringTemplateUtil移到StringTemplateManager
【特性】Luban.Server支持禁用生成缓存(但仍保留源文件缓存)。 【修复】修复 start_up.md 文档中的链接错误main
parent
d686f82ba8
commit
ca8e5035ba
|
|
@ -50,6 +50,7 @@ Luban工具有两种部属方式。
|
||||||
-p, --port <port> 可选参数。 监听端口 <port>,默认为8899。
|
-p, --port <port> 可选参数。 监听端口 <port>,默认为8899。
|
||||||
-l, --loglevel <log level> 可选参数。 日志级别。默认为INFO。 有效值有: TRACE,DEBUG,INFO,WARN,ERROR,FATAL,OFF
|
-l, --loglevel <log level> 可选参数。 日志级别。默认为INFO。 有效值有: TRACE,DEBUG,INFO,WARN,ERROR,FATAL,OFF
|
||||||
-t, --template_search_path 可选参数。模板的额外搜索路径。优先从此路径,再从Templates目录搜索模板文件。
|
-t, --template_search_path 可选参数。模板的额外搜索路径。优先从此路径,再从Templates目录搜索模板文件。
|
||||||
|
--disable_cache 可选参数。禁用生成中间过程的缓存,但保留了源文件缓存。在模板调试时比较有用。
|
||||||
--i10n:default_timezone <timezone> 可选参数。 datetime数据转换为UTC时间默认使用的时区。
|
--i10n:default_timezone <timezone> 可选参数。 datetime数据转换为UTC时间默认使用的时区。
|
||||||
|
|
||||||
## luban-client 使用介绍
|
## luban-client 使用介绍
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
## 创建游戏配置
|
## 创建游戏配置
|
||||||
|
|
||||||
1. 从示例项目拷贝[MiniDesignerConfigsTemplate](https://github.com/focus-creative-games/luban_examples/MiniDesignerConfigsTemplate) 到一个合适的目录,假设为 **MyConfigs**
|
1. 从示例项目拷贝[MiniDesignerConfigsTemplate](https://github.com/focus-creative-games/luban_examples/tree/main/MiniDesignerConfigsTemplate) 到一个合适的目录,假设为 **MyConfigs**
|
||||||
2. 添加物品表 excel 文件
|
2. 添加物品表 excel 文件
|
||||||
在 MyConfigs/Datas 目录下创建一个 “物品表.xlsx” 文件。
|
在 MyConfigs/Datas 目录下创建一个 “物品表.xlsx” 文件。
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
|
|
||||||
## 生成代码和数据以及在程序中使用
|
## 生成代码和数据以及在程序中使用
|
||||||
|
|
||||||
假设是Unity项目,使用json导出格式。 示例参考项目为 [Csharp_Unity_Json](https://github.com/focus-creative-games/luban_examples/Projects/Csharp_Unity_json)。其他语言或者导出类型的组合,请参考 [luban_examples](https://github.com/focus-creative-games/luban_examples)
|
假设是Unity项目,使用json导出格式。 示例参考项目为 [Csharp_Unity_Json](https://github.com/focus-creative-games/luban_examples/tree/main/Projects/Csharp_Unity_json)。其他语言或者导出类型的组合,请参考 [luban_examples](https://github.com/focus-creative-games/luban_examples)
|
||||||
|
|
||||||
|
|
||||||
1. 项目准备。
|
1. 项目准备。
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ using Luban.Client.Common.Utils;
|
||||||
using Luban.Client.Utils;
|
using Luban.Client.Utils;
|
||||||
using Luban.Common.Protos;
|
using Luban.Common.Protos;
|
||||||
using Luban.Common.Utils;
|
using Luban.Common.Utils;
|
||||||
|
using Luban.Job.Cfg.Cache;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using Luban.Server;
|
using Luban.Server;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -165,11 +167,14 @@ Options:
|
||||||
|
|
||||||
private static void StartServer(AllCommandLineOptions options)
|
private static void StartServer(AllCommandLineOptions options)
|
||||||
{
|
{
|
||||||
|
FileRecordCacheManager.Ins.Init(true);
|
||||||
|
StringTemplateManager.Ins.Init(true);
|
||||||
if (!string.IsNullOrEmpty(options.TemplateSearchPath))
|
if (!string.IsNullOrEmpty(options.TemplateSearchPath))
|
||||||
{
|
{
|
||||||
StringTemplateUtil.AddTemplateSearchPath(options.TemplateSearchPath);
|
StringTemplateManager.Ins.AddTemplateSearchPath(options.TemplateSearchPath);
|
||||||
}
|
}
|
||||||
StringTemplateUtil.AddTemplateSearchPath(FileUtil.GetPathRelateApplicationDirectory("Templates"));
|
StringTemplateManager.Ins.AddTemplateSearchPath(FileUtil.GetPathRelateApplicationDirectory("Templates"));
|
||||||
|
|
||||||
GenServer.Ins.Start(true, options.Port, ProtocolStub.Factories);
|
GenServer.Ins.Start(true, options.Port, ProtocolStub.Factories);
|
||||||
|
|
||||||
GenServer.Ins.RegisterJob("cfg", new Luban.Job.Cfg.JobController());
|
GenServer.Ins.RegisterJob("cfg", new Luban.Job.Cfg.JobController());
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ namespace Luban.Job.Cfg.Cache
|
||||||
/// 配置加载记录缓存。
|
/// 配置加载记录缓存。
|
||||||
/// 如果某个表对应的数据文件未修改,定义没变化,那加载后的数据应该是一样的。
|
/// 如果某个表对应的数据文件未修改,定义没变化,那加载后的数据应该是一样的。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class FileRecordCacheManager
|
public class FileRecordCacheManager
|
||||||
{
|
{
|
||||||
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
|
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
|
@ -36,14 +36,21 @@ namespace Luban.Job.Cfg.Cache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Init(bool enableCache)
|
||||||
|
{
|
||||||
|
_enableCache = enableCache;
|
||||||
|
}
|
||||||
|
|
||||||
private readonly ConcurrentDictionary<(string TableName, string MD5, string SheetName), FileRecordCache> _caches = new();
|
private readonly ConcurrentDictionary<(string TableName, string MD5, string SheetName), FileRecordCache> _caches = new();
|
||||||
|
|
||||||
private readonly object _shrinkLocker = new object();
|
private readonly object _shrinkLocker = new object();
|
||||||
|
|
||||||
|
private bool _enableCache = true;
|
||||||
|
|
||||||
public bool TryGetCacheLoadedRecords(DefTable table, string md5, string originFile, string sheetName, out List<Record> cacheRecords)
|
public bool TryGetCacheLoadedRecords(DefTable table, string md5, string originFile, string sheetName, out List<Record> cacheRecords)
|
||||||
{
|
{
|
||||||
cacheRecords = null;
|
cacheRecords = null;
|
||||||
if (!_caches.TryGetValue((table.FullName, md5, sheetName), out var r))
|
if (!_enableCache || !_caches.TryGetValue((table.FullName, md5, sheetName), out var r))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +84,7 @@ namespace Luban.Job.Cfg.Cache
|
||||||
|
|
||||||
public bool TryGetRecordOutputData(DefTable table, List<Record> records, string dataType, out string md5)
|
public bool TryGetRecordOutputData(DefTable table, List<Record> records, string dataType, out string md5)
|
||||||
{
|
{
|
||||||
if (_tableCaches.TryGetValue((table.FullName, dataType), out var cacheInfo))
|
if (_enableCache && _tableCaches.TryGetValue((table.FullName, dataType), out var cacheInfo))
|
||||||
{
|
{
|
||||||
var cacheAss = cacheInfo.Table.Assembly;
|
var cacheAss = cacheInfo.Table.Assembly;
|
||||||
var curAss = table.Assembly;
|
var curAss = table.Assembly;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common;
|
using Luban.Job.Common;
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
using Luban.Job.Common.Generate;
|
using Luban.Job.Common.Generate;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -102,7 +103,7 @@ namespace {ctx.TopModule}
|
||||||
|
|
||||||
private string RenderStub(string topModule, List<DefTypeBase> types)
|
private string RenderStub(string topModule, List<DefTypeBase> types)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("config/cpp_bin/stub");
|
var template = StringTemplateManager.Ins.GetTemplate("config/cpp_bin/stub");
|
||||||
return template.RenderCode(new {
|
return template.RenderCode(new {
|
||||||
TopModule = topModule,
|
TopModule = topModule,
|
||||||
Types = types,
|
Types = types,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
using Luban.Job.Common.Generate;
|
using Luban.Job.Common.Generate;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using Scriban;
|
using Scriban;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -18,9 +19,9 @@ namespace Luban.Job.Cfg.Generate
|
||||||
var enums = types.Where(t => t is DefEnum).ToList();
|
var enums = types.Where(t => t is DefEnum).ToList();
|
||||||
var beans = types.Where(t => t is DefBean).ToList();
|
var beans = types.Where(t => t is DefBean).ToList();
|
||||||
var tables = types.Where(t => t is DefTable).ToList();
|
var tables = types.Where(t => t is DefTable).ToList();
|
||||||
var template = StringTemplateUtil.GetOrAddTemplate("common/lua/base_all", fn =>
|
var template = StringTemplateManager.Ins.GetOrAddTemplate("common/lua/base_all", fn =>
|
||||||
Template.Parse(StringTemplateUtil.GetTemplateString("common/lua/base")
|
Template.Parse(StringTemplateManager.Ins.GetTemplateString("common/lua/base")
|
||||||
+ StringTemplateUtil.GetTemplateString("config/lua_bin/all")));
|
+ StringTemplateManager.Ins.GetTemplateString("config/lua_bin/all")));
|
||||||
return template.RenderCode(new { Enums = enums, Beans = beans, Tables = tables });
|
return template.RenderCode(new { Enums = enums, Beans = beans, Tables = tables });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
using Luban.Job.Common.Generate;
|
using Luban.Job.Common.Generate;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using Scriban;
|
using Scriban;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -22,8 +23,8 @@ namespace Luban.Job.Cfg.Generate
|
||||||
var enums = types.Where(t => t is DefEnum).ToList();
|
var enums = types.Where(t => t is DefEnum).ToList();
|
||||||
var beans = types.Where(t => t is DefBean).ToList();
|
var beans = types.Where(t => t is DefBean).ToList();
|
||||||
var tables = types.Where(t => t is DefTable).ToList();
|
var tables = types.Where(t => t is DefTable).ToList();
|
||||||
var template = t_allRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/lua/base")
|
var template = t_allRender ??= Template.Parse(StringTemplateManager.Ins.GetTemplateString("common/lua/base")
|
||||||
+ StringTemplateUtil.GetTemplateString("config/lua_lua/all"));
|
+ StringTemplateManager.Ins.GetTemplateString("config/lua_lua/all"));
|
||||||
return template.RenderCode(new { Enums = enums, Beans = beans, Tables = tables });
|
return template.RenderCode(new { Enums = enums, Beans = beans, Tables = tables });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common.Generate;
|
using Luban.Job.Common.Generate;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
|
@ -24,7 +25,7 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
//fileContent.Add(PythonStringTemplates.ImportTython3Enum);
|
//fileContent.Add(PythonStringTemplates.ImportTython3Enum);
|
||||||
//fileContent.Add(PythonStringTemplates.PythonVectorTypes);
|
//fileContent.Add(PythonStringTemplates.PythonVectorTypes);
|
||||||
fileContent.Add(StringTemplateUtil.GetTemplateString("config/python_json/include"));
|
fileContent.Add(StringTemplateManager.Ins.GetTemplateString("config/python_json/include"));
|
||||||
}
|
}
|
||||||
|
|
||||||
GenerateCodeMonolithic(ctx, RenderFileUtil.GetFileOrDefault(ctx.GenArgs.OutputCodeMonolithicFile, "Types.py"), lines, PreContent, null);
|
GenerateCodeMonolithic(ctx, RenderFileUtil.GetFileOrDefault(ctx.GenArgs.OutputCodeMonolithicFile, "Types.py"), lines, PreContent, null);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
using Luban.Job.Common.Generate;
|
using Luban.Job.Common.Generate;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -28,7 +29,7 @@ namespace Luban.Job.Cfg.Generate
|
||||||
var lines = new List<string>();
|
var lines = new List<string>();
|
||||||
GenerateCodeMonolithic(ctx, RenderFileUtil.GetFileOrDefault(ctx.GenArgs.OutputCodeMonolithicFile, "mod.rs"), lines, ls =>
|
GenerateCodeMonolithic(ctx, RenderFileUtil.GetFileOrDefault(ctx.GenArgs.OutputCodeMonolithicFile, "mod.rs"), lines, ls =>
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("config/rust_json/include");
|
var template = StringTemplateManager.Ins.GetTemplate("config/rust_json/include");
|
||||||
var result = template.RenderCode(ctx.ExportTypes);
|
var result = template.RenderCode(ctx.ExportTypes);
|
||||||
ls.Add(result);
|
ls.Add(result);
|
||||||
}, null);
|
}, null);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -22,7 +23,7 @@ namespace Luban.Job.Cfg.Generate
|
||||||
|
|
||||||
public override string Render(DefEnum e)
|
public override string Render(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate($"common/{CommonRenderTemplateDir}/enum");
|
var template = StringTemplateManager.Ins.GetTemplate($"common/{CommonRenderTemplateDir}/enum");
|
||||||
var result = template.RenderCode(e);
|
var result = template.RenderCode(e);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -30,21 +31,21 @@ namespace Luban.Job.Cfg.Generate
|
||||||
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate($"config/{RenderTemplateDir}/bean");
|
var template = StringTemplateManager.Ins.GetTemplate($"config/{RenderTemplateDir}/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate($"config/{RenderTemplateDir}/table");
|
var template = StringTemplateManager.Ins.GetTemplate($"config/{RenderTemplateDir}/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate($"config/{RenderTemplateDir}/tables");
|
var template = StringTemplateManager.Ins.GetTemplate($"config/{RenderTemplateDir}/tables");
|
||||||
var result = template.RenderCode(new {
|
var result = template.RenderCode(new {
|
||||||
Name = name,
|
Name = name,
|
||||||
Namespace = module,
|
Namespace = module,
|
||||||
|
|
@ -59,7 +60,7 @@ namespace Luban.Job.Cfg.Generate
|
||||||
var beans = types.Where(t => t is DefBean).ToList();
|
var beans = types.Where(t => t is DefBean).ToList();
|
||||||
var tables = types.Where(t => t is DefTable).ToList();
|
var tables = types.Where(t => t is DefTable).ToList();
|
||||||
|
|
||||||
var template = StringTemplateUtil.GetTemplate($"config/{RenderTemplateDir}/all");
|
var template = StringTemplateManager.Ins.GetTemplate($"config/{RenderTemplateDir}/all");
|
||||||
var result = template.RenderCode(new {
|
var result = template.RenderCode(new {
|
||||||
Namespace = DefAssembly.LocalAssebmly.TopModule,
|
Namespace = DefAssembly.LocalAssebmly.TopModule,
|
||||||
Enums = enums.Select(e => Render((DefEnum)e)).ToList(),
|
Enums = enums.Select(e => Render((DefEnum)e)).ToList(),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -39,8 +40,8 @@ namespace Luban.Job.Cfg.Generate
|
||||||
if (args.TypescriptEmbedBrightTypes)
|
if (args.TypescriptEmbedBrightTypes)
|
||||||
{
|
{
|
||||||
fileContent.Add(isGenBinary ?
|
fileContent.Add(isGenBinary ?
|
||||||
StringTemplateUtil.GetTemplateString("config/typescript_bin/vectors")
|
StringTemplateManager.Ins.GetTemplateString("config/typescript_bin/vectors")
|
||||||
: StringTemplateUtil.GetTemplateString("config/typescript_json/vectors"));
|
: StringTemplateManager.Ins.GetTemplateString("config/typescript_json/vectors"));
|
||||||
if (isGenBinary)
|
if (isGenBinary)
|
||||||
{
|
{
|
||||||
fileContent.Add(TypescriptStringTemplate.SerializeTypes);
|
fileContent.Add(TypescriptStringTemplate.SerializeTypes);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using Luban.Job.Cfg.DataVisitors;
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Cfg.l10n;
|
using Luban.Job.Cfg.l10n;
|
||||||
using Luban.Job.Cfg.RawDefs;
|
using Luban.Job.Cfg.RawDefs;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using Scriban;
|
using Scriban;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -22,7 +23,7 @@ namespace Luban.Job.Cfg.Utils
|
||||||
{
|
{
|
||||||
public static string ToTemplateOutputData(DefTable table, List<Record> records, string templateName)
|
public static string ToTemplateOutputData(DefTable table, List<Record> records, string templateName)
|
||||||
{
|
{
|
||||||
Template template = StringTemplateUtil.GetTemplate($"config/data/{templateName}");
|
Template template = StringTemplateManager.Ins.GetTemplate($"config/data/{templateName}");
|
||||||
return template.RenderData(table, records.Select(r => r.Data).ToList());
|
return template.RenderData(table, records.Select(r => r.Data).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
using Scriban;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban.Job.Common.Tpl
|
||||||
|
{
|
||||||
|
public class StringTemplateManager
|
||||||
|
{
|
||||||
|
public static StringTemplateManager Ins { get; } = new();
|
||||||
|
|
||||||
|
|
||||||
|
private readonly List<string> _templateSearchPaths = new();
|
||||||
|
|
||||||
|
private bool _enableTemplateCache;
|
||||||
|
|
||||||
|
private readonly ConcurrentDictionary<string, Template> _templates = new();
|
||||||
|
|
||||||
|
private readonly ConcurrentDictionary<string, string> _templateStrings = new();
|
||||||
|
|
||||||
|
public void Init(bool enableTemplateCache)
|
||||||
|
{
|
||||||
|
_enableTemplateCache = enableTemplateCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddTemplateSearchPath(string templateSearchPath)
|
||||||
|
{
|
||||||
|
_templateSearchPaths.Add(templateSearchPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGetTemplateString(string templateName, out string result)
|
||||||
|
{
|
||||||
|
if (_enableTemplateCache && _templateStrings.TryGetValue(templateName, out result))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
foreach (var searchPath in _templateSearchPaths)
|
||||||
|
{
|
||||||
|
var fullPath = $"{searchPath}/{templateName}.tpl";
|
||||||
|
if (File.Exists(fullPath))
|
||||||
|
{
|
||||||
|
result = File.ReadAllText(fullPath, Encoding.UTF8);
|
||||||
|
if (_enableTemplateCache)
|
||||||
|
{
|
||||||
|
_templateStrings[templateName] = result;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTemplateString(string templateName)
|
||||||
|
{
|
||||||
|
if (TryGetTemplateString(templateName, out var strTpl))
|
||||||
|
{
|
||||||
|
return strTpl;
|
||||||
|
}
|
||||||
|
throw new FileNotFoundException($"can't find {templateName}.tpl in paths:{string.Join(';', _templateSearchPaths)}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Template GetTemplate(string templateName)
|
||||||
|
{
|
||||||
|
if (_enableTemplateCache)
|
||||||
|
{
|
||||||
|
return _templates.GetOrAdd(templateName, tn => Template.Parse(GetTemplateString(tn)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Template.Parse(GetTemplateString(templateName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGetTemplate(string templateName, out Template template)
|
||||||
|
{
|
||||||
|
if (_templates.TryGetValue(templateName, out template))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (TryGetTemplateString(templateName, out var strTpm))
|
||||||
|
{
|
||||||
|
template = _templates.GetOrAdd(templateName, tn => Template.Parse(strTpm));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
template = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Template GetOrAddTemplate(string templateName, Func<string, Template> creator)
|
||||||
|
{
|
||||||
|
return _templates.GetOrAdd(templateName, creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Scriban;
|
using Scriban;
|
||||||
|
|
||||||
namespace Luban.Job.Common.Utils
|
namespace Luban.Job.Common.Utils
|
||||||
|
|
@ -7,7 +8,7 @@ namespace Luban.Job.Common.Utils
|
||||||
{
|
{
|
||||||
public static string RenderCsEnumClass(DefEnum e)
|
public static string RenderCsEnumClass(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("common/cs/enum");
|
var template = StringTemplateManager.Ins.GetTemplate("common/cs/enum");
|
||||||
var result = template.Render(e);
|
var result = template.Render(e);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -15,7 +16,7 @@ namespace Luban.Job.Common.Utils
|
||||||
|
|
||||||
public static string RenderJavaEnumClass(DefEnum e)
|
public static string RenderJavaEnumClass(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("common/java/enum");
|
var template = StringTemplateManager.Ins.GetTemplate("common/java/enum");
|
||||||
var result = template.Render(e);
|
var result = template.Render(e);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -23,14 +24,14 @@ namespace Luban.Job.Common.Utils
|
||||||
|
|
||||||
public static string RenderCppEnumClass(DefEnum e)
|
public static string RenderCppEnumClass(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("common/cpp/enum");
|
var template = StringTemplateManager.Ins.GetTemplate("common/cpp/enum");
|
||||||
var result = template.Render(e);
|
var result = template.Render(e);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string RenderPythonEnumClass(DefEnum e)
|
public static string RenderPythonEnumClass(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("common/python/enum");
|
var template = StringTemplateManager.Ins.GetTemplate("common/python/enum");
|
||||||
var result = template.Render(e);
|
var result = template.Render(e);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -38,14 +39,14 @@ namespace Luban.Job.Common.Utils
|
||||||
|
|
||||||
public static string RenderTypescriptEnumClass(DefEnum e)
|
public static string RenderTypescriptEnumClass(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("common/typescript/enum");
|
var template = StringTemplateManager.Ins.GetTemplate("common/typescript/enum");
|
||||||
var result = template.Render(e);
|
var result = template.Render(e);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string RenderRustEnumClass(DefEnum e)
|
public static string RenderRustEnumClass(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("common/rust/enum");
|
var template = StringTemplateManager.Ins.GetTemplate("common/rust/enum");
|
||||||
var result = template.Render(e);
|
var result = template.Render(e);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -1,70 +0,0 @@
|
||||||
using Scriban;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Luban.Job.Common.Utils
|
|
||||||
{
|
|
||||||
public static class StringTemplateUtil
|
|
||||||
{
|
|
||||||
private static List<string> TemplateSearchPaths { get; } = new List<string>();
|
|
||||||
|
|
||||||
public static void AddTemplateSearchPath(string path)
|
|
||||||
{
|
|
||||||
TemplateSearchPaths.Add(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool TryGetTemplateString(string templateName, out string result)
|
|
||||||
{
|
|
||||||
foreach (var searchPath in TemplateSearchPaths)
|
|
||||||
{
|
|
||||||
var fullPath = $"{searchPath}/{templateName}.tpl";
|
|
||||||
if (File.Exists(fullPath))
|
|
||||||
{
|
|
||||||
result = File.ReadAllText(fullPath, Encoding.UTF8);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetTemplateString(string templateName)
|
|
||||||
{
|
|
||||||
if (TryGetTemplateString(templateName, out var strTpl))
|
|
||||||
{
|
|
||||||
return strTpl;
|
|
||||||
}
|
|
||||||
throw new FileNotFoundException($"can't find {templateName}.tpl in paths:{string.Join(';', TemplateSearchPaths)}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly ConcurrentDictionary<string, Template> s_templates = new();
|
|
||||||
|
|
||||||
public static Template GetTemplate(string templateName)
|
|
||||||
{
|
|
||||||
return s_templates.GetOrAdd(templateName, tn => Template.Parse(GetTemplateString(tn)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool TryGetTemplate(string templateName, out Template template)
|
|
||||||
{
|
|
||||||
if (s_templates.TryGetValue(templateName, out template))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (TryGetTemplateString(templateName, out var strTpm))
|
|
||||||
{
|
|
||||||
template = s_templates.GetOrAdd(templateName, tn => Template.Parse(strTpm));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
template = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Template GetOrAddTemplate(string templateName, Func<string, Template> creator)
|
|
||||||
{
|
|
||||||
return s_templates.GetOrAdd(templateName, creator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using Luban.Job.Db.Defs;
|
using Luban.Job.Db.Defs;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -26,14 +27,14 @@ namespace Luban.Job.Db.Generate
|
||||||
|
|
||||||
public string Render(DefBean b)
|
public string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("db/cs_async/bean");
|
var template = StringTemplateManager.Ins.GetTemplate("db/cs_async/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Render(DefTable p)
|
public string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("db/cs_async/table");
|
var template = StringTemplateManager.Ins.GetTemplate("db/cs_async/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -41,7 +42,7 @@ namespace Luban.Job.Db.Generate
|
||||||
|
|
||||||
public string RenderTables(string name, string module, List<DefTable> tables)
|
public string RenderTables(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("db/cs_async/tables");
|
var template = StringTemplateManager.Ins.GetTemplate("db/cs_async/tables");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using Luban.Job.Db.Defs;
|
using Luban.Job.Db.Defs;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -26,14 +27,14 @@ namespace Luban.Job.Db.Generate
|
||||||
|
|
||||||
public string Render(DefBean b)
|
public string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("db/cs_sync/bean");
|
var template = StringTemplateManager.Ins.GetTemplate("db/cs_sync/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Render(DefTable p)
|
public string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("db/cs_sync/table");
|
var template = StringTemplateManager.Ins.GetTemplate("db/cs_sync/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -41,7 +42,7 @@ namespace Luban.Job.Db.Generate
|
||||||
|
|
||||||
public string RenderTables(string name, string module, List<DefTable> tables)
|
public string RenderTables(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("db/cs_sync/tables");
|
var template = StringTemplateManager.Ins.GetTemplate("db/cs_sync/tables");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using Luban.Job.Db.Defs;
|
using Luban.Job.Db.Defs;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -26,14 +27,14 @@ namespace Luban.Job.Db.Generate
|
||||||
|
|
||||||
public string Render(DefBean b)
|
public string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("db/typescript/bean");
|
var template = StringTemplateManager.Ins.GetTemplate("db/typescript/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Render(DefTable p)
|
public string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("db/typescript/table");
|
var template = StringTemplateManager.Ins.GetTemplate("db/typescript/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -41,7 +42,7 @@ namespace Luban.Job.Db.Generate
|
||||||
|
|
||||||
public string RenderTables(string name, string module, List<DefTable> tables)
|
public string RenderTables(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate("db/typescript/tables");
|
var template = StringTemplateManager.Ins.GetTemplate("db/typescript/tables");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using Luban.Common.Protos;
|
using Luban.Common.Protos;
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
using Luban.Job.Common.Generate;
|
using Luban.Job.Common.Generate;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using Luban.Job.Proto.Defs;
|
using Luban.Job.Proto.Defs;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -30,7 +31,7 @@ namespace Luban.Job.Proto.Generate
|
||||||
var beans = types.Where(t => t is DefBean).ToList();
|
var beans = types.Where(t => t is DefBean).ToList();
|
||||||
var protos = types.Where(t => t is DefProto).ToList();
|
var protos = types.Where(t => t is DefProto).ToList();
|
||||||
var rpcs = types.Where(t => t is DefRpc).ToList();
|
var rpcs = types.Where(t => t is DefRpc).ToList();
|
||||||
var template = StringTemplateUtil.GetTemplate("proto/lua/all");
|
var template = StringTemplateManager.Ins.GetTemplate("proto/lua/all");
|
||||||
return template.RenderCode(new { Enums = enums, Beans = beans, Protos = protos, Rpcs = rpcs });
|
return template.RenderCode(new { Enums = enums, Beans = beans, Protos = protos, Rpcs = rpcs });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
using Luban.Job.Common.Generate;
|
using Luban.Job.Common.Generate;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using Luban.Job.Proto.Defs;
|
using Luban.Job.Proto.Defs;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -16,35 +17,35 @@ namespace Luban.Job.Proto.Generate
|
||||||
|
|
||||||
protected override string Render(DefEnum e)
|
protected override string Render(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate($"common/{RenderTemplateDir}/enum");
|
var template = StringTemplateManager.Ins.GetTemplate($"common/{RenderTemplateDir}/enum");
|
||||||
var result = template.RenderCode(e);
|
var result = template.RenderCode(e);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Render(DefBean b)
|
protected override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate($"proto/{RenderTemplateDir}/bean");
|
var template = StringTemplateManager.Ins.GetTemplate($"proto/{RenderTemplateDir}/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Render(DefProto p)
|
protected override string Render(DefProto p)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate($"proto/{RenderTemplateDir}/proto");
|
var template = StringTemplateManager.Ins.GetTemplate($"proto/{RenderTemplateDir}/proto");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Render(DefRpc r)
|
protected override string Render(DefRpc r)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate($"proto/{RenderTemplateDir}/rpc");
|
var template = StringTemplateManager.Ins.GetTemplate($"proto/{RenderTemplateDir}/rpc");
|
||||||
var result = template.RenderCode(r);
|
var result = template.RenderCode(r);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string RenderStubs(string name, string module, List<DefProto> protos, List<DefRpc> rpcs)
|
public override string RenderStubs(string name, string module, List<DefProto> protos, List<DefRpc> rpcs)
|
||||||
{
|
{
|
||||||
var template = StringTemplateUtil.GetTemplate($"proto/{RenderTemplateDir}/stub");
|
var template = StringTemplateManager.Ins.GetTemplate($"proto/{RenderTemplateDir}/stub");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
using Luban.Job.Common;
|
using Luban.Job.Common;
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
using Luban.Job.Common.Generate;
|
using Luban.Job.Common.Generate;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using Luban.Job.Proto.Defs;
|
using Luban.Job.Proto.Defs;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -34,7 +35,7 @@ namespace Luban.Job.Proto.Generate
|
||||||
}
|
}
|
||||||
if (args.TypescriptEmbedBrightTypes)
|
if (args.TypescriptEmbedBrightTypes)
|
||||||
{
|
{
|
||||||
fileContent.Add(StringTemplateUtil.GetTemplateString("config/typescript_bin/vectors"));
|
fileContent.Add(StringTemplateManager.Ins.GetTemplateString("config/typescript_bin/vectors"));
|
||||||
fileContent.Add(TypescriptStringTemplate.SerializeTypes);
|
fileContent.Add(TypescriptStringTemplate.SerializeTypes);
|
||||||
fileContent.Add(TypescriptStringTemplate.ProtoTypes);
|
fileContent.Add(TypescriptStringTemplate.ProtoTypes);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,10 @@
|
||||||
"timezone-utc": {
|
"timezone-utc": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "--timezone \"Etc/UTC\""
|
"commandLineArgs": "--timezone \"Etc/UTC\""
|
||||||
|
},
|
||||||
|
"TestTemplate-DisableCache": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "-t D:\\workspace\\luban_examples\\Projects\\CustomTemplates --disable_template_cache"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
using CommandLine;
|
using CommandLine;
|
||||||
using Luban.Common.Protos;
|
using Luban.Common.Protos;
|
||||||
using Luban.Common.Utils;
|
using Luban.Common.Utils;
|
||||||
|
using Luban.Job.Cfg.Cache;
|
||||||
|
using Luban.Job.Common.Tpl;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
@ -21,6 +23,9 @@ namespace Luban.Server
|
||||||
[Option('t', "template_search_path", Required = false, HelpText = "additional template search path")]
|
[Option('t', "template_search_path", Required = false, HelpText = "additional template search path")]
|
||||||
public string TemplateSearchPath { get; set; }
|
public string TemplateSearchPath { get; set; }
|
||||||
|
|
||||||
|
[Option("disable_cache", Required = false, HelpText = "disable generation cache")]
|
||||||
|
public bool DisableCache { get; set; }
|
||||||
|
|
||||||
[Option("i10n:default_timezone", Required = false, HelpText = "default timezone")]
|
[Option("i10n:default_timezone", Required = false, HelpText = "default timezone")]
|
||||||
public string L10nDefaultTimeZone { get; set; } = "Asia/Shanghai";
|
public string L10nDefaultTimeZone { get; set; } = "Asia/Shanghai";
|
||||||
}
|
}
|
||||||
|
|
@ -32,11 +37,14 @@ namespace Luban.Server
|
||||||
|
|
||||||
var options = CommandLineUtil.ParseOptions<CommandLineOptions>(args);
|
var options = CommandLineUtil.ParseOptions<CommandLineOptions>(args);
|
||||||
|
|
||||||
|
FileRecordCacheManager.Ins.Init(!options.DisableCache);
|
||||||
|
|
||||||
|
StringTemplateManager.Ins.Init(!options.DisableCache);
|
||||||
if (!string.IsNullOrEmpty(options.TemplateSearchPath))
|
if (!string.IsNullOrEmpty(options.TemplateSearchPath))
|
||||||
{
|
{
|
||||||
StringTemplateUtil.AddTemplateSearchPath(options.TemplateSearchPath);
|
StringTemplateManager.Ins.AddTemplateSearchPath(options.TemplateSearchPath);
|
||||||
}
|
}
|
||||||
StringTemplateUtil.AddTemplateSearchPath(FileUtil.GetPathRelateApplicationDirectory("Templates"));
|
StringTemplateManager.Ins.AddTemplateSearchPath(FileUtil.GetPathRelateApplicationDirectory("Templates"));
|
||||||
|
|
||||||
Luban.Common.Utils.LogUtil.InitSimpleNLogConfigure(NLog.LogLevel.FromString(options.LogLevel));
|
Luban.Common.Utils.LogUtil.InitSimpleNLogConfigure(NLog.LogLevel.FromString(options.LogLevel));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue