【特性】cfg table新增output属性,用于指定输出文件名字
【特性】cfg 新增 --output_code_monolithic_file 参数,用于指定typescript之类生成的全量代码文件名 【修复】修复 topmodule不能为空的bugmain
parent
ec3635cc70
commit
eeba3fd99c
|
|
@ -216,7 +216,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
return mode;
|
||||
}
|
||||
|
||||
private readonly List<string> _tableOptionalAttrs = new List<string> { "index", "mode", "group", "patch_input", "comment", "define_from_file" };
|
||||
private readonly List<string> _tableOptionalAttrs = new List<string> { "index", "mode", "group", "patch_input", "comment", "define_from_file", "output" };
|
||||
private readonly List<string> _tableRequireAttrs = new List<string> { "name", "value", "input" };
|
||||
|
||||
private void AddTable(string defineFile, XElement e)
|
||||
|
|
@ -233,11 +233,12 @@ namespace Luban.Job.Cfg.Defs
|
|||
string patchInput = XmlUtil.GetOptionalAttribute(e, "patch_input");
|
||||
string mode = XmlUtil.GetOptionalAttribute(e, "mode");
|
||||
string tags = XmlUtil.GetOptionalAttribute(e, "tags");
|
||||
AddTable(defineFile, name, module, valueType, index, mode, group, comment, defineFromFile, input, patchInput, tags);
|
||||
string output = XmlUtil.GetOptionalAttribute(e, "output");
|
||||
AddTable(defineFile, name, module, valueType, index, mode, group, comment, defineFromFile, input, patchInput, tags, output);
|
||||
}
|
||||
|
||||
private void AddTable(string defineFile, string name, string module, string valueType, string index, string mode, string group,
|
||||
string comment, bool defineFromExcel, string input, string patchInput, string tags)
|
||||
string comment, bool defineFromExcel, string input, string patchInput, string tags, string outputFileName)
|
||||
{
|
||||
var p = new Table()
|
||||
{
|
||||
|
|
@ -250,6 +251,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
Comment = comment,
|
||||
Mode = ConvertMode(defineFile, name, mode, index),
|
||||
Tags = tags,
|
||||
OutputFile = outputFileName,
|
||||
};
|
||||
|
||||
if (p.Groups.Count == 0)
|
||||
|
|
@ -431,6 +433,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
new CfgField() { Name = "comment", Type = "string" },
|
||||
new CfgField() { Name = "define_from_excel", Type = "bool" },
|
||||
new CfgField() { Name = "input", Type = "string" },
|
||||
new CfgField() { Name = "output", Type = "string" },
|
||||
new CfgField() { Name = "patch_input", Type = "string" },
|
||||
new CfgField() { Name = "tags", Type = "string" },
|
||||
}
|
||||
|
|
@ -468,7 +471,8 @@ namespace Luban.Job.Cfg.Defs
|
|||
string inputFile = (data.GetField("input") as DString).Value.Trim();
|
||||
string patchInput = (data.GetField("patch_input") as DString).Value.Trim();
|
||||
string tags = (data.GetField("tags") as DString).Value.Trim();
|
||||
AddTable(file.OriginFile, name, module, valueType, index, mode, group, comment, isDefineFromExcel, inputFile, patchInput, tags);
|
||||
string outputFile = (data.GetField("output") as DString).Value.Trim();
|
||||
AddTable(file.OriginFile, name, module, valueType, index, mode, group, comment, isDefineFromExcel, inputFile, patchInput, tags, outputFile);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
_patchInputFiles = b.PatchInputFiles;
|
||||
Comment = b.Comment;
|
||||
Tags = DefUtil.ParseAttrs(b.Tags);
|
||||
_outputFile = b.OutputFile;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -40,6 +41,8 @@ namespace Luban.Job.Cfg.Defs
|
|||
|
||||
private readonly Dictionary<string, List<string>> _patchInputFiles;
|
||||
|
||||
private readonly string _outputFile;
|
||||
|
||||
public List<string> Groups { get; }
|
||||
|
||||
public TType KeyTType { get; private set; }
|
||||
|
|
@ -52,7 +55,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
|
||||
public bool NeedExport => Assembly.NeedExport(this.Groups);
|
||||
|
||||
public string OutputDataFile => FullName.Replace('.', '_').ToLower();
|
||||
public string OutputDataFile => string.IsNullOrWhiteSpace(_outputFile) ? FullName.Replace('.', '_').ToLower() : _outputFile;
|
||||
|
||||
public string InnerName => "_" + this.Name;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Luban.Job.Cfg.Generate
|
|||
{
|
||||
public override void Render(GenContext ctx)
|
||||
{
|
||||
var file = "Types.lua";
|
||||
var file = RenderFileUtil.GetFileOrDefault(ctx.GenArgs.OutputCodeMonolithicFile, "Types.lua");
|
||||
var content = this.RenderAll(ctx.ExportTypes);
|
||||
var md5 = CacheFileUtil.GenMd5AndAddCache(file, string.Join('\n', content));
|
||||
ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Luban.Job.Cfg.Generate
|
|||
fileContent.Add(PythonStringTemplates.PythonVectorTypes);
|
||||
}
|
||||
|
||||
GenerateCodeMonolithic(ctx, "Types.py", lines, PreContent, null);
|
||||
GenerateCodeMonolithic(ctx, RenderFileUtil.GetFileOrDefault(ctx.GenArgs.OutputCodeMonolithicFile, "Types.py"), lines, PreContent, null);
|
||||
}
|
||||
|
||||
public override string Render(DefEnum e)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace Luban.Job.Cfg.Generate
|
|||
ctx.Lan = RenderFileUtil.GetLanguage(genType);
|
||||
|
||||
var lines = new List<string>();
|
||||
GenerateCodeMonolithic(ctx, "mod.rs", lines, ls =>
|
||||
GenerateCodeMonolithic(ctx, RenderFileUtil.GetFileOrDefault(ctx.GenArgs.OutputCodeMonolithicFile, "mod.rs"), lines, ls =>
|
||||
{
|
||||
var template = StringTemplateUtil.GetTemplate("config/rust_json/mod_header");
|
||||
var result = template.RenderCode(ctx.ExportTypes);
|
||||
|
|
|
|||
|
|
@ -51,15 +51,15 @@ namespace Luban.Job.Cfg.Generate
|
|||
fileContent.Add(TypescriptStringTemplate.GetVectorImports(brightRequirePath, brightPackageName));
|
||||
}
|
||||
|
||||
fileContent.Add(@$"export namespace {ctx.TopModule} {{");
|
||||
//fileContent.Add(@$"export namespace {ctx.TopModule} {{");
|
||||
};
|
||||
|
||||
Action<List<string>> postContent = (fileContent) =>
|
||||
{
|
||||
fileContent.Add("}"); // end of topmodule
|
||||
//fileContent.Add("}"); // end of topmodule
|
||||
};
|
||||
|
||||
GenerateCodeMonolithic(ctx, "Types.ts", lines, preContent, postContent);
|
||||
GenerateCodeMonolithic(ctx, RenderFileUtil.GetFileOrDefault(ctx.GenArgs.OutputCodeMonolithicFile, "Types.ts"), lines, preContent, postContent);
|
||||
}
|
||||
|
||||
public override string Render(DefEnum e)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ namespace Luban.Job.Cfg.RawDefs
|
|||
|
||||
public List<string> InputFiles { get; set; } = new List<string>();
|
||||
|
||||
public string OutputFile { get; set; }
|
||||
|
||||
public Dictionary<string, List<string>> PatchInputFiles { get; set; } = new Dictionary<string, List<string>>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ namespace Luban.Job.Common.Defs
|
|||
|
||||
private void SetTopModule(XElement e)
|
||||
{
|
||||
this.TopModule = XmlUtil.GetRequiredAttribute(e, "name");
|
||||
this.TopModule = XmlUtil.GetOptionalAttribute(e, "name");
|
||||
}
|
||||
|
||||
private async Task AddImportAsync(string xmlFile)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ namespace Luban.Job.Common
|
|||
[Option('c', "output_code_dir", Required = false, HelpText = "output code directory")]
|
||||
public string OutputCodeDir { get; set; }
|
||||
|
||||
[Option("output_code_monolithic_file", Required = false, HelpText = "output monolithic code file. only effect when lan=rust,python,typescript,lua")]
|
||||
public string OutputCodeMonolithicFile { get; set; }
|
||||
|
||||
[Option("typescript_bright_require_path", Required = false, HelpText = "bright require path in typescript")]
|
||||
public string TypescriptBrightRequirePath { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -113,5 +113,10 @@ namespace Luban.Job.Common.Utils
|
|||
{
|
||||
return $"{fileName}.{(string.IsNullOrEmpty(fileExtension) ? GetOutputFileSuffix(genType) : fileExtension)}";
|
||||
}
|
||||
|
||||
public static string GetFileOrDefault(string preferFile, string candidateFile)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(preferFile) ? candidateFile : preferFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue