SmartCode 功能强大的代码生成器

程序名称:SmartCode

授权协议: Apache-2.0

操作系统: 跨平台

开发语言: C#

SmartCode 介绍


SmartCode = IDataSource -> IBuildTask -> IoUtput => Build Everything

Introduction

SmartCode.Generator (代码生成器)

Demo

Getting Started

  1. Install from .NET Core Global Tool

    dotnet tool install –global SmartCode.CLI

  2. 编辑构建配置文件认:SmartCode.yml)

  3. 命令行执行SmartCode命令

  4. 等待任务执行结束

  5. 查看输出目录结果

  6. 运行API项目,进行Swagger调试

构建配置文件

Module: Smartsql.Starter
Author: Ahoo Wang
DataSource:
  Name: DbTable
  Parameters:
    dbname: SmartsqlTestDB
    DbProvider: sqlServer
    ConnectionString: Data Source=.;Initial Catalog=SmartsqlTestDB;Integrated Security=True
Language: CSharp
TemplateEngine: 
   Name: Razor
   Root: CSharp
Output: 
  Type: File
  Path: 'E:\Smartsql-Starter'
Parameters:
  SmartsqlVersion: '4.0.46'
  SmartsqlSchemaVersion: '4.0.42'
  BuildDir: 'E:\Smartsql-Starter\build'
  DockerImage: 'smartsql.starter'

NamingConverter:
  Table:
    Tokenizer:
      Type: Default
      Parameters:
        IgnorePrefix: 'T_'
        Delimiter: '_'
    Converter:
      Type: Pascal
      Parameters: { }
  View:
    Tokenizer:
      Type: Default
      Parameters:
        IgnorePrefix: 'V_'
        Delimiter: '_'
    Converter:
      Type: Pascal
  Column:
    Tokenizer:
      Type: Default
      Parameters:
        Delimiter: '_'
    Converter:
      Type: Pascal

# 构建任务
Build:

#  ClearDir:
#    Type: Clear
#    Parameters:
#      Dirs: '.'

  MakeBuildDir:
    Type: Process
    Parameters:
      FileName: powershell
      Args: mkdir '{{Project.Parameters.BuildDir}}'
  copy:
    Type: Process
    Parameters:
      FileName: powershell
      Args:  cp '{{Project.ConfigPath}}' '{{Project.Parameters.BuildDir}}'

  Scaffolding:
    Type: MultiTemplate
    Output: 
      Path: '.'
    Parameters:
      Templates: [{Key: 'Sln.cshtml',Output: {Name: '{{Project.Module}}',Extension: '.sln'}},
        {Key: 'Sln-Directory.Build.cshtml',Output: {Name: 'Directory.Build',Extension: '.props'}},
        {Key: 'Sln-Version.cshtml',Output: {Path: 'build',Name: 'version',Extension: '.props'}},
        {Key: 'Sln-Dockerfile.cshtml',Output: {Name: 'Dockerfile',Extension: ''}},
        {Key: 'Sln-DockerIgnore.cshtml',Output: {Name: '.dockerignore',Extension: ''}},
        {Key: 'Sln-GitIgnore.cshtml',Output: {Name: '.gitignore',Extension: ''}},
        {Key: Proj-Entity.cshtml,Output: {Path: 'src/{{Project.Module}}.Entity',Name: '{{Project.Module}}.Entity',Extension: '.csproj'}},
        {Key: Proj-Repository.cshtml,Output: {Path: 'src/{{Project.Module}}.Repository',Name: '{{Project.Module}}.Repository',Extension: '.csproj'}},
        {Key: Proj-Service.cshtml,Output: {Path: 'src/{{Project.Module}}.Service',Name: '{{Project.Module}}.Service',Extension: '.csproj'}},
        {Key: Proj-API.cshtml,Output: {Path: 'src/{{Project.Module}}.API',Name: '{{Project.Module}}.API',Extension: '.csproj'}},
        {Key: API/LaunchSettings.cshtml,Output: {Path: 'src/{{Project.Module}}.API/Properties',Name: 'launchSettings',Extension: '.json'}},
        {Key: API/AppSettings.cshtml,Output: {Path: 'src/{{Project.Module}}.API',Name: 'appsettings',Extension: '.json'}},
        {Key: API/AppSettings-Development.cshtml,Output: {Path: 'src/{{Project.Module}}.API',Name: 'appsettings.Development',Extension: '.json'}},
        {Key: API/Program.cshtml,Output: {Path: 'src/{{Project.Module}}.API',Name: 'Program',Extension: '.cs'}},
        {Key: API/Startup.cshtml,Output: {Path: 'src/{{Project.Module}}.API',Name: 'Startup',Extension: '.cs'}},
        {Key: API/APIException.cshtml,Output: {Path: 'src/{{Project.Module}}.API/Exceptions',Name: 'APIException',Extension: '.cs'}},
        {Key: API/GlobalExceptionFilter.cshtml,Output: {Path: 'src/{{Project.Module}}.API/Filters',Name: 'GlobalExceptionFilter',Extension: '.cs'}},
        {Key: API/GlobalValidateModelFilter.cshtml,Output: {Path: 'src/{{Project.Module}}.API/Filters',Name: 'GlobalValidateModelFilter',Extension: '.cs'}},
        {Key: API/QueryRequest.cshtml,Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'QueryRequest',Extension: '.cs'}},
        {Key: API/QueryByPageRequest.cshtml,Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'QueryByPageRequest',Extension: '.cs'}},
        {Key: API/ResponseMessage.cshtml,Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'ResponseMessage',Extension: '.cs'}},
        {Key: API/QueryResponse.cshtml,Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'QueryResponse',Extension: '.cs'}},
        {Key: API/QueryByPageResponse.cshtml,Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'QueryByPageResponse',Extension: '.cs'}},
        {Key: API/ResponseMessage.cshtml,Output: {Path: 'src/{{Project.Module}}.API/Messages',Name: 'ResponseMessage',Extension: '.cs'}},
        {Key: sqlMapConfig.cshtml,Output: {Path: 'src/{{Project.Module}}.Repository',Name: 'SmartsqlMapConfig',Extension: '.xml'}},
        {Key: sqlMapConfig.cshtml,Output: {Path: 'src/{{Project.Module}}.Repository',Name: 'SmartsqlMapConfig.Development',Extension: '.xml'}}]

  Entity:
    Type: Table
    Module: Entity
    TemplateEngine: 
      Path: Entity.cshtml
    Output: 
      Path: 'src/{{Project.Module}}.{{Build.Module}}'
      Name: '{{Items.CurrentTable.Convertedname}}'
      Extension: '.cs'

  Repository:
    Type: Table
    Module: Repository
    TemplateEngine: 
      Path: Repository.cshtml
    IgnorenopKTable: true
    IgnoreView: true
    Output: 
      Path: 'src/{{Project.Module}}.{{Build.Module}}'
      Name: 'I{{Items.CurrentTable.Convertedname}}Repository'
      Extension: .cs

  Service:
    Type: Table
    Module: Service
    TemplateEngine: 
      Path: Service.cshtml
    IgnorenopKTable: true
    IgnoreView: true
    Output: 
      Path: 'src/{{Project.Module}}.{{Build.Module}}'
      Name: '{{Items.CurrentTable.Convertedname}}Service'
      Extension: .cs

  APIController:
    Type: Table
    Module: API
    TemplateEngine: 
      Path: API/APIController.cshtml
    IgnorenopKTable: true
    IgnoreView: true
    Output: 
      Path: 'src/{{Project.Module}}.{{Build.Module}}/Controllers'
      Name: '{{Items.CurrentTable.Convertedname}}Controller'
      Extension: .cs

  sqlMap:
    Type: Table
    TemplateEngine: 
      Path: sqlMap.cshtml
    Output: 
      Path: 'src/{{Project.Module}}.Repository/Maps'
      Name: '{{Items.CurrentTable.Convertedname}}'
      Extension: .xml
    IgnorenopKTable: true
    IgnoreView: true

# Please install dotnet-format first!
# dotnet tool install -g dotnet-format
  CodeFormat:
    Type: Process
    Parameters:
      FileName: powershell
      WorkingDirectory: '{{Project.Output.Path}}'
      Args: dotnet-format

  ReStore:
    Type: Process
    Parameters: 
      FileName: powershell
      WorkingDirectory: '{{Project.Output.Path}}'
      Args: dotnet restore

#  BuildDocker:
#    Type: Process
#    Parameters: 
#      FileName: powershell
#      WorkingDirectory: '{{Project.Output.Path}}'
#      Args: docker build -t {{Project.Parameters.DockerImage}}:v1.0.0 .

#  RunDocker:
#    Type: Process
#    Parameters: 
#      FileName: powershell
#      WorkingDirectory: '{{Project.Output.Path}}'
#      Args: docker run --name {{Project.Parameters.DockerImage}} --rm -d -p 8008:80 {{Project.Parameters.DockerImage}}:v1.0.0 .

#  Publish:
#    Type: Process
#    Parameters: 
#      FileName: powershell
#      WorkingDirectory: '{{Project.Output.Path}}'
#      Args: dotnet publish -c Release -o '{{Project.Output.Path}}\publish'

#  Run:
#    Type: Process
#    Parameters: 
#      FileName: powershell
#      WorkingDirectory: '{{Project.Output.Path}}\publish'
#      CreateNowindow: false
#      RedirectStandardOutput: false
#      RedirectStandardError: false
#      WaitForExit: false
#      WriteLines: ['dotnet {{Project.Module}}.API.dll']

#  runchrome:
#    Type: Process
#    Parameters: 
#      FileName: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
#      CreateNowindow: false
#      Args: http://localhost:8008/swagger

构建文件参数概览

参数名说明
Module根模块名
Author作者
DataSource数据源
Language语言:CSharp/Java/....
TemplateEngine模板引擎:目前内置:Razor/Handlebars
Output输出
Build任务构建s

属性 Name:DbTable,使用 DbTableSource 插件作为数据源

DbTableSource.Parameters 接受以下三个参数:

参数名说明
dbname数据库名称
DbProvider数据驱动提供者:MysqL,MariaDB,Postgresql,sqlServer,Oracle,sqlite
ConnectionString连接字符串
参数名说明
TypeFile
Path输出目录
Name文件
Extension扩展名
Mode输出模式,认:Incre。Incre:增量创建,如果文件存在则忽略 。Full:全量创建,如果存在则重新创建
参数名说明
Type构建类型,Clear:用于清理目录s/文件s, Project:用于构建单文件,如:解决方文件/项目文件, MultiTemplate:多模板构建多个文件, Table: 用于构建以数据表为基础的文件,如:Entity,Repository文件, Process: 启动新进程
Module构建模块名
TemplateEngine模板引擎,可选,认使用根模块引擎
Template模板文件
Output输出
IgnorenopKTable忽略无主键表
IgnoreView忽略视图
IncludeTables包括表名s
IgnoreTables忽略表名s
NamingConverter命名转换器
Parameters自定义构建参数
属性说明
类型Table/View/Column
Tokenizer分词器
Converter转换器:Camel/Pascal/None

NamingConverter.Tokenizer 分词器

属性说明
TypeDefault
Parameters.IgnorePrefix忽略前缀字符
Parameters.Delimiter分隔符
Parameters.UppercaseSplit使用大写分隔,认:true

SmartCode 官网

https://github.com/Ahoo-Wang/SmartCode

相关编程语言

提到 EclEmma 首先就要说到著名的 Java 覆盖测试工具...
Solex是一个WEB应用测试用的Eclipse插件。Solex可以...
Apache为我们提供了一个强大的工具 Cactus!它是一套...
Google C Testing Framework是Google公司用来在各种...
JdbcProxy 是 SourceForge 上一个开源的 Java 项目,...
Ripplet是一款负载测试工具,特征如下: 1)基于Apa...