【删除】删除 cfg code_editor_typescript
parent
70db1dca9e
commit
62511c10f2
|
|
@ -1,95 +0,0 @@
|
|||
using Luban.Common.Protos;
|
||||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Common;
|
||||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Luban.Job.Cfg.Generate
|
||||
{
|
||||
[Render("code_typescript_editor_json")]
|
||||
class TypescriptEditorCodeJsonRender : TypescriptCodeRenderBase
|
||||
{
|
||||
public override void Render(GenContext ctx)
|
||||
{
|
||||
string genType = ctx.GenType;
|
||||
var args = ctx.GenArgs;
|
||||
ctx.Render = this;
|
||||
ctx.Lan = RenderFileUtil.GetLanguage(genType);
|
||||
|
||||
var lines = new List<string>(10000);
|
||||
Action<List<string>> preContent = (fileContent) =>
|
||||
{
|
||||
fileContent.Add(StringTemplateUtil.GetTemplateString("config/typescript_json/vectors"));
|
||||
|
||||
fileContent.Add(@$"export namespace {ctx.TopModule} {{");
|
||||
};
|
||||
|
||||
Action<List<string>> postContent = (fileContent) =>
|
||||
{
|
||||
fileContent.Add("}\n"); // end of topmodule
|
||||
};
|
||||
|
||||
GenerateCode(ctx, "Types.ts", lines, preContent, postContent);
|
||||
}
|
||||
|
||||
protected void GenerateCode(GenContext ctx, string outputFile, List<string> fileContent, Action<List<string>> preContent, Action<List<string>> postContent)
|
||||
{
|
||||
ctx.Tasks.Add(Task.Run(() =>
|
||||
{
|
||||
fileContent.Add(FileHeaderUtil.GetAutoGenerationHeader(ctx.Lan));
|
||||
|
||||
preContent?.Invoke(fileContent);
|
||||
|
||||
foreach (var c in ctx.Assembly.Types.Values)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case DefConst:
|
||||
case DefEnum:
|
||||
case DefBean:
|
||||
case DefTable:
|
||||
{
|
||||
fileContent.Add(ctx.Render.RenderAny(c));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
postContent?.Invoke(fileContent);
|
||||
|
||||
var file = outputFile;
|
||||
var md5 = CacheFileUtil.GenMd5AndAddCache(file, string.Join('\n', fileContent));
|
||||
ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
|
||||
}));
|
||||
}
|
||||
|
||||
public override string Render(DefEnum e)
|
||||
{
|
||||
var template = StringTemplateUtil.GetTemplate("config/typescript_editor_json/enum");
|
||||
var result = template.RenderCode(e);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override string Render(DefBean b)
|
||||
{
|
||||
var template = StringTemplateUtil.GetTemplate("config/typescript_editor_json/bean");
|
||||
var result = template.RenderCode(b);
|
||||
return result;
|
||||
}
|
||||
|
||||
public override string Render(DefTable p)
|
||||
{
|
||||
var template = StringTemplateUtil.GetTemplate("config/typescript_editor_json/table");
|
||||
var result = template.RenderCode(p);
|
||||
return result;
|
||||
}
|
||||
|
||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -187,15 +187,6 @@
|
|||
<None Update="Templates\config\typescript_bin\vectors.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_editor_json\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_editor_json\enum.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_editor_json\table.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Templates\config\typescript_json\bean.tpl">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{if x.is_abstract_type}}abstract {{end}}class {{name}}{{if parent_def_type}} extends {{x.parent}}{{end}} {
|
||||
{{~if x.is_abstract_type~}}
|
||||
static constructorFrom(_json_: any): {{name}}{
|
||||
switch (_json_.__type__) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case '{{child.name}}': return new {{child.full_name}}(_json_)
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
constructor(_json_: any) {
|
||||
{{~if parent_def_type~}}
|
||||
super(_json_)
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if !field.ctype.is_nullable~}}
|
||||
if (_json_.{{field.name}} === undefined) { throw new Error() }
|
||||
{{~end~}}
|
||||
{{ts_json_constructor ('this.' + field.ts_style_name) ( '_json_.' + field.name) field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{field.ts_style_name}}: {{ts_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{x.name}} {
|
||||
readonly id: number
|
||||
readonly name: string
|
||||
readonly alias: string
|
||||
readonly comment: string
|
||||
constructor(id: number, name: string, alias: string, comment: string) {
|
||||
this.id = id
|
||||
this.name = name
|
||||
this.alias= alias
|
||||
this.comment = comment
|
||||
}
|
||||
|
||||
{{~for item in x.items ~}}
|
||||
static readonly {{item.name}} = new {{x.name}}({{item.int_value}}, `{{item.name}}`, `{{item.alias}}`, `{{item.comment}}`)
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}}{
|
||||
{{~if x.is_map_table ~}}
|
||||
private _dataMap: Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>
|
||||
private _dataList: {{ts_define_type value_type}}[]
|
||||
constructor(_json_: any) {
|
||||
this._dataMap = new Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}>()
|
||||
this._dataList = []
|
||||
for(var _json2_ of _json_) {
|
||||
let _v: {{ts_define_type value_type}}
|
||||
{{ts_json_constructor '_v' '_json2_' value_type}}
|
||||
this._dataList.push(_v)
|
||||
this._dataMap.set(_v.{{x.index_field.ts_style_name}}, _v)
|
||||
}
|
||||
}
|
||||
|
||||
getDataMap(): Map<{{ts_define_type key_type}}, {{ts_define_type value_type}}> { return this._dataMap; }
|
||||
getDataList(): {{ts_define_type value_type}}[] { return this._dataList; }
|
||||
|
||||
get(key: {{ts_define_type key_type}}): {{ts_define_type value_type}} | undefined { return this._dataMap.get(key); }
|
||||
|
||||
{{~else~}}
|
||||
|
||||
private _data: {{ts_define_type value_type}}
|
||||
constructor(_json_: any) {
|
||||
if (_json_.length != 1) throw new Error('table mode=one, but size != 1')
|
||||
{{ts_json_constructor 'this._data' '_json_[0]' value_type}}
|
||||
}
|
||||
|
||||
getData(): {{ts_define_type value_type}} { return this._data; }
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.ts_style_name}}(): {{ts_define_type field.ctype}} { return this._data.{{field.ts_style_name}}; }
|
||||
{{~end~}}
|
||||
{{end}}
|
||||
}
|
||||
{{x.typescript_namespace_end}}
|
||||
Loading…
Reference in New Issue