Giter Club home page Giter Club logo

tablecraft's Introduction

TableCraft

Commitizen friendly

README.en.md

简介

TableCraft是一个通用、可拓展的解析配置源文件,生成配置描述文件与客制化配置读取代码解决方案。

项目提供了一个.NET6运行时库,同时也提供了一个基于此库的命令行工具,与一个基于此库的Avalonia可视化编辑器作为使用范例。

特性

TableCraft.Core

  • 规定字段的合法数值类型,集合类型
  • 为字段添加标签进行特殊处理(例如表格的主键)
  • 支持不同文件类型的数据源(目前支持:csv)
  • 支持不同文件类型的数据描述(目前支持:json)
  • 支持使用T4 Text Templates与TableCraft提供的API生成任意语言的业务代码
  • 支持版本控制(目前支持:perforce)

TableCraft.Editor

*运行设备需要安装.NET 6.0

  • 基于Avalonia的可视化编辑器
  • 支持配置数据源文件目录与数据描述文件目录
  • 支持配置不同使用途径下的代码导出目录
  • 自动化版本控制(perforce)

配置方式

TableCraft.Core 配置

libenv.json

使用运行时库TableCraft.Core需要配置libenv.json文件,并在使用前通过接口TableCraft.Core.Configuration.ReadConfigurationFromJson进行初始化

{
    // 规定数值类型
    "DataValueType": ["int", "uint", "float", "boolean", "string"],
    // 规定集合类型
    "DataCollectionType": ["none", "array"],
    // 规定可用的字段标签
    "AttributeTag": ["primary", "label1", "label2"],
    // TableCraft默认使用UTF8编码,在此指定是否需要BOM头
    "UTF8BOM": false,
    // 对csv类型数据源文件,规定字段名所在的行数,与注释所在的行数(若不存在则填-1)
    "CsvSource":{
        "HeaderLineIndex": 0,
        "CommentLineIndex": 1
    },
    // 规定各种导出的代码途径
    "ConfigUsageType":{
        "usage0":{
            // 用于生成代码的T4模板文件,此文件需要放在可执行文件同级Templates目录下
            "CodeTemplateName": "usage0-template.tt",
            // 生成文件的类型,此例生成的文件为c#代码
            "TargetFileType": ".cs",
            // 生成文件名的格式字符串,若此字符串中包含文件类型,将被TargetFileType替换
            "OutputFormat": "{0}_base"
        }
    },
    // 导出途径组,用于同时导出多种途径
    "ConfigUsageGroup":{
        "group0":[
        	"usage0",
        	"usage1"
        ]
    }
}

TableCraft.Editor 配置

appsettings.json

appsettings.json中配置了一些重要的文件目录,也用于保存版本控制相关的用户信息

{
    // 配置文件所在的共同根目录,用于读取配置文件
    "ConfigHomePath": "",
    // 配置描述文件的共同根目录,用于保存描述文件
    "JsonHomePath": "",
    // 生成目录
    "ExportPath": {
        "usage0": ""
    },
    // Perforce版本控制相关信息,不需要在此处手动配置,在应用内编辑后进行保存即可
    "P4Config": {
        "P4PORT": "",
        "P4USER": "",
        "P4CLIENT": "",
        "P4PASSWDBASE64": ""
    }
}

TableCraft.Editor使用方式

按照下述步骤操作前,请先保证上述的两个json文件已配置正确;若存在错误配置,可在Editor可执行文件同级Logs目录下查看具体问题。

image-20230504222628230

  1. 查看工具配置情况
  2. 可点击此按钮添加新的配置项

image-20230504223100478

  1. 选择已加入到工具中的配置表
  2. 选中配置表后,此处会显示配置表的字段信息
  3. 展示当前配置表的原文件名,在“Usage”选中使用途径后,可在“ExportName”指定该途径下的客制化名称

image-20230504223332644

  1. 选中特定字段后,在此处可以编辑字段的描述(注释),数值类型,集合类型,默认值,特定使用途径下的导出名称(常用于不同命名风格的变量名),添加标签

image-20230504223527993

  1. 指定生成文件的单一目标使用途径或途径组
  2. 点击此按钮导出文件(如选择单一途径,导出路径显示按钮下方)
  3. 点击此按钮将数据描述文件保存至“JsonHome”

第三方依赖

TableCraft.Core 依赖

License

MIT

Copyright (c) 2023 - Boming Chen

tablecraft's People

Contributors

kalulas avatar

Stargazers

smileflurry avatar  avatar  avatar Light avatar

Watchers

 avatar

tablecraft's Issues

Generate code with Mono.TextTemplating failed on self-contained version

log-20230414.txt

2023-04-14 14:30:08.581 +08:00 [ERR] Unhandled exception
Mono.TextTemplating.TemplatingEngineException: Not a valid .NET Core host
   at Mono.TextTemplating.TemplatingEngine.GetOrCreateCompiler() in /_/Mono.TextTemplating/Mono.TextTemplating/TemplatingEngine.cs:line 67
   at Mono.TextTemplating.TemplatingEngine.CompileCode(IEnumerable`1 references, TemplateSettings settings, CodeCompileUnit ccu, CancellationToken token) in /_/Mono.TextTemplating/Mono.TextTemplating/TemplatingEngine.cs:line 303
   at Mono.TextTemplating.TemplatingEngine.CompileTemplateInternal(ParsedTemplate pt, String content, ITextTemplatingEngineHost host, TemplateSettings settings, CancellationToken token) in /_/Mono.TextTemplating/Mono.TextTemplating/TemplatingEngine.cs:line 277
   at Mono.TextTemplating.TemplatingEngine.ProcessTemplateAsync(ParsedTemplate pt, String content, TemplateSettings settings, ITextTemplatingEngineHost host, CancellationToken token) in /_/Mono.TextTemplating/Mono.TextTemplating/TemplatingEngine.cs:line 88
   at Mono.TextTemplating.TemplateGenerator.ProcessTemplateAsync(ParsedTemplate pt, String inputFileName, String inputContent, String outputFileName, TemplateSettings settings, CancellationToken token) in /_/Mono.TextTemplating/Mono.TextTemplating/TemplateGenerator.cs:line 269
   at TableCraft.Core.ConfigManager.GenerateCodeForUsage(String usage, ConfigInfo configInfo, String outputDirectory) in D:\Desktop\Workshop\Others\TableCraft\TableCraft.Core\ConfigManager.cs:line 128
   at TableCraft.Editor.ViewModels.MainWindowViewModel.GenerateCodeWithCurrentUsage() in D:\Desktop\Workshop\Others\TableCraft\TableCraft.Editor\ViewModels\MainWindowViewModel.cs:line 326

looking into Mono.TextTemplating.CodeCompilation.RuntimeInfo.GetDotNetCoreSdk(),

static bool DotnetRootIsValid (string root) => !string.IsNullOrEmpty (root) && (File.Exists (Path.Combine (root, "dotnet")) || File.Exists (Path.Combine (root, "dotnet.exe")));

// this should get us something like /usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.0
var runtimeDir = Path.GetDirectoryName (typeof (object).Assembly.Location);
var dotnetRoot = Path.GetDirectoryName (Path.GetDirectoryName (Path.GetDirectoryName (runtimeDir)));
if (!DotnetRootIsValid (dotnetRoot)) {
	// this may happen on single file deployments
	return FromError (RuntimeKind.NetCore, "Not a valid .NET Core host");
}

It's clear that runtimeDir is the same as the executable file path on the self-contained version, resulting in dotnetRoot being invalid. This is the debugging output from a self-contained version of TableCraft:

  typeof (object).Assembly.Location
  "D:\\Applications\\TableCraft.Editor.win10-x64\\System.Private.CoreLib.dll"

  var runtimeDir = Path.GetDirectoryName (typeof (object).Assembly.Location)
  "D:\\Applications\\TableCraft.Editor.win10-x64"

  Path.GetDirectoryName (Path.GetDirectoryName (Path.GetDirectoryName (runtimeDir)));
  null

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.