• Stars
    star
    572
  • Rank 77,995 (Top 2 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SmartCode = IDataSource -> IBuildTask -> IOutput => Build Everything!!!

SmartCode(English Document)

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

Introduction

SmartCode

Nuget Packages

Package NuGet Stable Downloads
SmartCode.CLI SmartCode.CLI SmartCode.CLI

SmartCode.Generator (代码生成器)

Demo

SmartCode

Getting Started

  1. Install from .NET Core Global Tool
dotnet tool install --global SmartCode.CLI
  1. 编辑构建配置文件(默认:SmartCode.yml)
  2. 命令行执行SmartCode命令
    • SmartCode
    • 等待提示输入配置文件路径(可选:默认程序根目录下SmartCode.yml文件)
    • 回车执行命令
  3. 等待任务执行结束
  4. 查看输出目录结果
  5. 运行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

DataSource 数据源,Name:DbTable

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

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

参数名 说明
DbName 数据库名称
DbProvider 数据驱动提供者:MySql,MariaDB,PostgreSql,SqlServer,Oracle,SQLite
ConnectionString 连接字符串

Output 输出

参数名 说明
Type File
Path 输出目录
Name 文件名
Extension 扩展名
Mode 输出模式,默认:Incre。Incre:增量创建,如果文件存在则忽略 。Full:全量创建,如果存在则重新创建

Build 任务构建

参数名 说明
Type 构建类型,Clear:用于清理目录s/文件s, Project:用于构建单文件,如:解决方案文件/项目文件, MultiTemplate:多模板构建多个文件, Table: 用于构建以数据表为基础的文件,如:Entity,Repository文件, Process: 启动新进程
Module 构建模块名
TemplateEngine 模板引擎,可选,默认使用根模块引擎
Template 模板文件
Output 输出
IgnoreNoPKTable 忽略无主键表
IgnoreView 忽略视图
IncludeTables 包括表名s
IgnoreTables 忽略表名s
NamingConverter 命名转换器
Parameters 自定义构建参数

NamingConverter 命名转换

属性 说明
类型 Table/View/Column
Tokenizer 分词器
Converter 转换器:Camel/Pascal/None
NamingConverter.Tokenizer 分词器
属性 说明
Type Default
Parameters.IgnorePrefix 忽略前缀字符
Parameters.Delimiter 分隔符
Parameters.UppercaseSplit 使用大写分隔,默认:true

如何贡献模板

为了让更多人参与到SmartCode模板建设中来,故有以下模板规范:

  1. 模板作者在 src/SmartCode.Generator/RazorTemplates/Contributions 中新建目录,并以作者英文名为目录名称
  2. 把模板放置到作者目录
  3. 作者目录下必须包括 README.md 文件,以说明模板的用途场景以及使用方式
  4. 提交PR

SmartCode.ETL(Extract-Transform-Load)(SmartCode.ETL-Doc

ETL 构建配置

Author: Ahoo Wang
DataSource:
  Name: Extract
  Parameters:
    DbProvider: SqlServer
    ConnectionString: Data Source=.;Initial Catalog=SmartSqlDB;Integrated Security=True
    Query: SELECT [Id],[UserName],[Pwd],[Status],[LastLoginTime],[CreationTime],[Deleted] FROM [T_User] Where Id>@LastMaxId And CreationTime>@LastQueryTime
    PKColumn: Id

Parameters:
  ETLCode: SmartCode.ETL.Test
  ETLRepository: PG
  
Build:

  Transform:
    Type: Transform
    Parameters:
      Script: Load2PostgreSql.cshtml

  Load2PostgreSql: 
    Type: Load
    Parameters:
      DbProvider: PostgreSql
      ConnectionString: Server=localhost;Port=5432;User Id=postgres;Password=SmartSql; Database=smartsql_db;
      Table: t_user
      ColumnMapping: [{Column: UserName,Mapping: user_name}
      ,{Column: Pwd,Mapping: pwd}
      ,{Column: Status,Mapping: status}
      ,{Column: LastLoginTime,Mapping: lastlogintime}
      ,{Column: CreationTime,Mapping: creationtime}
      ,{Column: Deleted,Mapping: deleted}]
      PreCommand: 
      PostCommand: 

More Repositories

1

FastGithub

github加速神器,解决github打不开、用户头像无法加载、releases无法上传下载、git-clone、git-pull、git-push失败等问题
C#
13,273
star
2

CAP

Distributed transaction solution in micro-service base on eventually consistency, also an eventbus with Outbox pattern
C#
6,267
star
3

Util

Util是一个.Net平台下的应用框架,旨在提升中小团队的开发能力,由工具类、分层架构基类、Ui组件,配套代码生成模板,权限等组成。
C#
4,306
star
4

WTM

Use WTM to write .netcore app fast !!!
C#
4,234
star
5

FreeSql

🦄 .NET aot orm, C# orm, VB.NET orm, Mysql orm, Postgresql orm, SqlServer orm, Oracle orm, Sqlite orm, Firebird orm, 达梦 orm, 人大金仓 orm, 神通 orm, 翰高 orm, 南大通用 orm, 虚谷 orm, 国产 orm, Clickhouse orm, QuestDB orm, MsAccess orm.
C#
4,071
star
6

DotnetSpider

DotnetSpider, a .NET standard web crawling library. It is lightweight, efficient and fast high-level web crawling & scraping framework
C#
3,753
star
7

osharp

OSharp是一个基于.Net6.0的快速开发框架,框架对 AspNetCore 的配置、依赖注入、日志、缓存、实体框架、Mvc(WebApi)、身份认证、功能权限、数据权限等模块进行更高一级的自动化封装,并规范了一套业务实现的代码结构与操作流程,使 .Net 框架更易于应用到实际项目开发中。
C#
2,758
star
8

BootstrapBlazor

Bootstrap Blazor is an enterprise-level UI component library based on Bootstrap and Blazor.
C#
2,492
star
9

Magicodes.IE

Import and export general library, support Dto import and export, template export, fancy export and dynamic export, support Excel, Csv, Word, Pdf and Html.
C#
2,074
star
10

WebApiClient

A REST API library with better functionality, performance, and scalability than refit
C#
2,047
star
11

NPOI

A .NET library for reading and writing Microsoft Office binary and OOXML file formats.
C#
1,877
star
12

EasyCaching

💥 EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!
C#
1,736
star
13

AspectCore-Framework

AspectCore is an AOP-based cross platform framework for .NET Standard.
C#
1,684
star
14

AgileConfig

基于.NET Core开发的轻量级分布式配置中心 / .NET Core lightweight configuration server
C#
1,483
star
15

Natasha

基于 Roslyn 的 C# 动态程序集构建库,该库允许开发者在运行时使用 C# 代码构建域 / 程序集 / 类 / 结构体 / 枚举 / 接口 / 方法等,使得程序在运行的时候可以增加新的模块及功能。Natasha 集成了域管理/插件管理,可以实现域隔离,域卸载,热拔插等功能。 该库遵循完整的编译流程,提供完整的错误提示, 可自动添加引用,完善的数据结构构建模板让开发者只专注于程序集脚本的编写,兼容 stanadard2.0 / netcoreapp3.0+, 跨平台,统一、简便的链式 API。 且我们会尽快修复您的问题及回复您的 issue.
C#
1,449
star
16

HttpReports

HttpReports is an APM (application performance monitor) system for .Net Core.
C#
1,260
star
17

sharding-core

high performance lightweight solution for efcore sharding table and sharding database support read-write-separation .一款ef-core下高性能、轻量级针对分表分库读写分离的解决方案,具有零依赖、零学习成本、零业务代码入侵
C#
1,142
star
18

SmartSql

SmartSql = MyBatis in C# + .NET Core+ Cache(Memory | Redis) + R/W Splitting + PropertyChangedTrack +Dynamic Repository + InvokeSync + Diagnostics
C#
1,098
star
19

FlubuCore

A cross platform build and deployment automation system for building projects and executing deployment scripts using C# code.
C#
907
star
20

Alipay.AopSdk.Core

支付宝(Alipay)服务端SDK,采用.NET Standard 2.0,支持.NET Core >=2.0,与官方SDK接口完全相同。完全可以按照官方文档进行开发。除了支持支付以外,官方SDK支持的功能本SDK全部支持,比如生活号、服务窗、行业合作等,且用法几乎一样,代码都可参考官方文档代码。
C#
778
star
21

CanalSharp

Alibaba mysql database binlog subscription & consumer components Canal's .NET client.
C#
559
star
22

aspnetcore-doc-cn

The Simplified Chinese edition of Microsoft ASP.NET Core documentation, translated by .NET Core Community and .NET China Community.
C#
521
star
23

Home

Home repo of .NET Core Community
299
star
24

mocha

Mocha is an application performance monitor tools based on OpenTelemetry, which also provides a scalable platform for observability data analysis and storage.
C#
142
star
25

Collections

Utilities and extensions for Collections includes Collections.Paginable and so on...
C#
88
star
26

EntityFrameworkCore.KingbaseES

Entity Framework Core provider for KingbaseES Database
C#
45
star
27

EntityFrameworkCore.GaussDB

Entity Framework Core provider for GaussDB Database
C#
32
star
28

FlubuCore.Examples

Examples for FlubuCore - a cross platform build automation tool for building projects and executing deployment scripts using C# code.
C#
32
star
29

wind-rises

25
star
30

Compile.Environment

When using the Roslyn library for dynamic compilation, you can introduce the library to provide a dynamic compilation environment.
10
star
31

SourceLink.Environment

Provide an inheritable NuGet package for the SourceLink feature.
7
star
32

projects

This repository is the site of NCC Projects include both Top-Level projects and Sandbox projects.
CSS
5
star
33

Natasha.Docs

The document for Natasha
JavaScript
4
star
34

DotNetCore.GaussDB

It's the foundation of DotNetCore.EntityFrameworkCore.GaussDB
C#
3
star
35

dotnetcore.github.io

.NET Core Community Official WebSite
HTML
2
star