【新增】proto,db,cfg新增 --typescript_bright_package_name 必然,支持在typescript语言的情况下以package形式引入bright包,相比于require path的形式,以package方式引用ByteBuf之类的类时不包含路径名。

main
walon 2021-07-30 13:58:13 +08:00
parent 06e2adf2aa
commit 94197d9968
6 changed files with 94 additions and 36 deletions

View File

@ -26,7 +26,7 @@ namespace Luban.Job.Cfg.DataSources
source.Load(url, sheetName, stream, exportTestData);
return source;
}
catch (DataCreateException dce)
catch (DataCreateException)
{
throw;
}

View File

@ -521,6 +521,7 @@ namespace Luban.Job.Cfg
Action<List<string>> preContent = (fileContent) =>
{
var brightRequirePath = args.TypescriptBrightRequirePath;
var brightPackageName = args.TypescriptBrightPackageName;
bool isGenBinary = genType.EndsWith("bin");
if (isGenBinary)
{
@ -530,7 +531,7 @@ namespace Luban.Job.Cfg
}
else
{
fileContent.Add(string.Format(TypescriptStringTemplate.BrightByteBufImportsFormat, brightRequirePath));
fileContent.Add(TypescriptStringTemplate.GetByteBufImports(brightRequirePath, brightPackageName));
}
}
@ -546,9 +547,9 @@ namespace Luban.Job.Cfg
{
if (isGenBinary)
{
fileContent.Add(string.Format(TypescriptStringTemplate.SerializeImportsFormat, brightRequirePath));
fileContent.Add(TypescriptStringTemplate.GetSerializeImports(brightRequirePath, brightPackageName));
}
fileContent.Add(string.Format(TypescriptStringTemplate.VectorImportsFormat, brightRequirePath));
fileContent.Add(TypescriptStringTemplate.GetVectorImports(brightRequirePath, brightPackageName));
}
fileContent.Add(@$"export namespace {ctx.TopModule} {{");

View File

@ -18,14 +18,15 @@ namespace Luban.Job.Common
[Option("typescript_bright_require_path", Required = false, HelpText = "bright require path in typescript")]
public string TypescriptBrightRequirePath { get; set; }
[Option("typescript_bright_package_name", Required = false, HelpText = "typescript bright package name")]
public string TypescriptBrightPackageName { get; set; }
[Option("use_puerts_bytebuf", Required = false, HelpText = "use puerts bytebuf class")]
public bool UsePuertsByteBuf { get; set; }
[Option("embed_bright_types", Required = false, HelpText = "use puerts bytebuf class")]
public bool EmbedBrightTypes { get; set; }
public bool ValidateOutouptCodeDir(ref string errMsg)
{
if (string.IsNullOrWhiteSpace(this.OutputCodeDir))
@ -40,14 +41,20 @@ namespace Luban.Job.Common
{
if (genType.Contains("typescript"))
{
if (!this.UsePuertsByteBuf && string.IsNullOrWhiteSpace(this.TypescriptBrightRequirePath))
if (!string.IsNullOrWhiteSpace(this.TypescriptBrightRequirePath) && !string.IsNullOrWhiteSpace(this.TypescriptBrightPackageName))
{
errMsg = $"while use_puerts_bytebuf is false, should provide option --typescript_bright_require_path";
errMsg = "can't use options --typescript_bright_require_path and --typescript_bright_package_name at the same time";
return false;
}
if (!this.EmbedBrightTypes && string.IsNullOrWhiteSpace(this.TypescriptBrightRequirePath))
bool hasBrightPathOrPacakge = !string.IsNullOrWhiteSpace(this.TypescriptBrightRequirePath) || !string.IsNullOrWhiteSpace(this.TypescriptBrightPackageName);
if (!this.UsePuertsByteBuf && !hasBrightPathOrPacakge)
{
errMsg = $"while embed_bright_types is false, should provide option --typescript_bright_require_path";
errMsg = "while --use_puerts_bytebuf is false, should provide option --typescript_bright_require_path or --typescript_bright_package_name";
return false;
}
if (!this.EmbedBrightTypes && !hasBrightPathOrPacakge)
{
errMsg = "while --embed_bright_types is false, should provide option --typescript_bright_require_path or --typescript_bright_package_name";
return false;
}
}

View File

@ -12,16 +12,43 @@ namespace Luban.Job.Common.Utils
import {Bright} from 'csharp'
import ByteBuf = Bright.Serialization.ByteBuf";
public const string BrightByteBufImportsFormat = "import ByteBuf from '{0}/serialization/ByteBuf'";
public static string GetByteBufImports(string path, string package)
{
return string.IsNullOrEmpty(package) ? string.Format(BrightByteBufPathImportsFormat, path) : string.Format(BrightByteBufPackageImportsFormat, package);
}
public const string VectorImportsFormat = @"
public const string BrightByteBufPathImportsFormat = "import ByteBuf from '{0}/serialization/ByteBuf'";
public const string BrightByteBufPackageImportsFormat = "import ByteBuf from '{0}'";
public static string GetVectorImports(string path, string package)
{
return string.IsNullOrEmpty(package) ? string.Format(VectorPathImportsFormat, path) : string.Format(VectorPackageImportsFormat, package);
}
public const string VectorPathImportsFormat = @"
import Vector2 from '{0}/math/Vector2'
import Vector3 from '{0}/math/Vector3'
import Vector4 from '{0}/math/Vector4'
";
public const string SerializeImportsFormat = @"import BeanBase from '{0}/serialization/BeanBase'";
public const string VectorPackageImportsFormat = @"
import Vector2 from '{0}'
import Vector3 from '{0}'
import Vector4 from '{0}'
";
public static string GetSerializeImports(string path, string package)
{
return string.IsNullOrEmpty(package) ? string.Format(SerializePathImportsFormat, path) : string.Format(SerializePackageImportsFormat, package);
}
public const string ProtocolImportsFormat = "import Protocol from '{0}/net/Protocol'";
public const string SerializePathImportsFormat = @"import BeanBase from '{0}/serialization/BeanBase'";
public const string SerializePackageImportsFormat = @"import BeanBase from '{0}'";
public static string GetProtocolImports(string path, string package)
{
return string.IsNullOrEmpty(package) ? string.Format(ProtocolPathImportsFormat, path) : string.Format(ProtocolPackageImportsFormat, package);
}
public const string ProtocolPathImportsFormat = "import Protocol from '{0}/net/Protocol'";
public const string ProtocolPackageImportsFormat = "import Protocol from '{0}'";
public const string SerializeTypes = @"
export interface ISerializable {

View File

@ -131,29 +131,51 @@ namespace Luban.Job.Db
{
var render = new TypescriptRender();
var brightRequirePath = args.TypescriptBrightRequirePath;
var brightPackageName = args.TypescriptBrightPackageName;
tasks.Add(Task.Run(() =>
{
var fileContent = new List<string>();
fileContent.Add(string.Format(TypescriptStringTemplate.BrightByteBufImportsFormat, brightRequirePath));
fileContent.Add(TypescriptStringTemplate.GetByteBufImports(brightRequirePath, brightPackageName));
fileContent.Add(string.Format(TypescriptStringTemplate.SerializeImportsFormat, brightRequirePath));
fileContent.Add(string.Format(TypescriptStringTemplate.ProtocolImportsFormat, brightRequirePath));
fileContent.Add(string.Format(TypescriptStringTemplate.VectorImportsFormat, brightRequirePath));
fileContent.Add($"import {{FieldLogger, FieldLoggerGeneric1, FieldLoggerGeneric2}} from '{brightRequirePath}/transaction/FieldLogger'");
fileContent.Add($"import TxnBeanBase from '{brightRequirePath}/transaction/TxnBeanBase'");
fileContent.Add($"import {{TxnTable, TxnTableGeneric}} from '{brightRequirePath}/transaction/TxnTable'");
fileContent.Add($"import TransactionContext from '{brightRequirePath}/transaction/TransactionContext'");
fileContent.Add($"import {{FieldTag}} from '{brightRequirePath}/serialization/FieldTag'");
fileContent.Add($"import TKey from '{brightRequirePath}/storage/TKey'");
fileContent.Add($"import PList from '{brightRequirePath}/transaction/collections/PList'");
fileContent.Add($"import PList1 from '{brightRequirePath}/transaction/collections/PList1'");
fileContent.Add($"import PList2 from '{brightRequirePath}/transaction/collections/PList2'");
fileContent.Add($"import PSet from '{brightRequirePath}/transaction/collections/PSet'");
fileContent.Add($"import PMap from '{brightRequirePath}/transaction/collections/PMap'");
fileContent.Add($"import PMap1 from '{brightRequirePath}/transaction/collections/PMap1'");
fileContent.Add($"import PMap2 from '{brightRequirePath}/transaction/collections/PMap2'");
fileContent.Add($"import SerializeFactory from '{brightRequirePath}/serialization/SerializeFactory'");
fileContent.Add(TypescriptStringTemplate.GetSerializeImports(brightRequirePath, brightPackageName));
fileContent.Add(TypescriptStringTemplate.GetProtocolImports(brightRequirePath, brightPackageName));
fileContent.Add(TypescriptStringTemplate.GetVectorImports(brightRequirePath, brightPackageName));
if (!string.IsNullOrEmpty(brightRequirePath))
{
fileContent.Add($"import {{FieldLogger, FieldLoggerGeneric1, FieldLoggerGeneric2}} from '{brightRequirePath}/transaction/FieldLogger'");
fileContent.Add($"import TxnBeanBase from '{brightRequirePath}/transaction/TxnBeanBase'");
fileContent.Add($"import {{TxnTable, TxnTableGeneric}} from '{brightRequirePath}/transaction/TxnTable'");
fileContent.Add($"import TransactionContext from '{brightRequirePath}/transaction/TransactionContext'");
fileContent.Add($"import {{FieldTag}} from '{brightRequirePath}/serialization/FieldTag'");
fileContent.Add($"import TKey from '{brightRequirePath}/storage/TKey'");
fileContent.Add($"import PList from '{brightRequirePath}/transaction/collections/PList'");
fileContent.Add($"import PList1 from '{brightRequirePath}/transaction/collections/PList1'");
fileContent.Add($"import PList2 from '{brightRequirePath}/transaction/collections/PList2'");
fileContent.Add($"import PSet from '{brightRequirePath}/transaction/collections/PSet'");
fileContent.Add($"import PMap from '{brightRequirePath}/transaction/collections/PMap'");
fileContent.Add($"import PMap1 from '{brightRequirePath}/transaction/collections/PMap1'");
fileContent.Add($"import PMap2 from '{brightRequirePath}/transaction/collections/PMap2'");
fileContent.Add($"import SerializeFactory from '{brightRequirePath}/serialization/SerializeFactory'");
}
else
{
fileContent.Add($"import {{FieldLogger, FieldLoggerGeneric1, FieldLoggerGeneric2}} from '{brightPackageName}'");
fileContent.Add($"import TxnBeanBase from '{brightPackageName}'");
fileContent.Add($"import {{TxnTable, TxnTableGeneric}} from '{brightPackageName}'");
fileContent.Add($"import TransactionContext from '{brightPackageName}'");
fileContent.Add($"import {{FieldTag}} from '{brightPackageName}'");
fileContent.Add($"import TKey from '{brightPackageName}'");
fileContent.Add($"import PList from '{brightPackageName}'");
fileContent.Add($"import PList1 from '{brightPackageName}'");
fileContent.Add($"import PList2 from '{brightPackageName}'");
fileContent.Add($"import PSet from '{brightPackageName}'");
fileContent.Add($"import PMap from '{brightPackageName}'");
fileContent.Add($"import PMap1 from '{brightPackageName}'");
fileContent.Add($"import PMap2 from '{brightPackageName}'");
fileContent.Add($"import SerializeFactory from '{brightPackageName}'");
}
fileContent.Add($"export namespace {ass.TopModule} {{");

View File

@ -153,6 +153,7 @@ namespace Luban.Job.Proto
{
var render = new TypescriptRender();
var brightRequirePath = args.TypescriptBrightRequirePath;
var brightPackageName = args.TypescriptBrightPackageName;
tasks.Add(Task.Run(() =>
{
@ -163,7 +164,7 @@ namespace Luban.Job.Proto
}
else
{
fileContent.Add(string.Format(TypescriptStringTemplate.BrightByteBufImportsFormat, brightRequirePath));
fileContent.Add(TypescriptStringTemplate.GetByteBufImports(brightRequirePath, brightPackageName));
}
if (args.EmbedBrightTypes)
{
@ -173,9 +174,9 @@ namespace Luban.Job.Proto
}
else
{
fileContent.Add(string.Format(TypescriptStringTemplate.SerializeImportsFormat, brightRequirePath));
fileContent.Add(string.Format(TypescriptStringTemplate.ProtocolImportsFormat, brightRequirePath));
fileContent.Add(string.Format(TypescriptStringTemplate.VectorImportsFormat, brightRequirePath));
fileContent.Add(TypescriptStringTemplate.GetSerializeImports(brightRequirePath, brightPackageName));
fileContent.Add(TypescriptStringTemplate.GetProtocolImports(brightRequirePath, brightPackageName));
fileContent.Add(TypescriptStringTemplate.GetVectorImports(brightRequirePath, brightPackageName));
}
fileContent.Add(@$"export namespace {ass.TopModule} {{");