Skip to content

Commit

Permalink
SmartCode = IDataSource -> IBuildTask -> IOutput => Build Everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed Oct 4, 2018
1 parent da3b502 commit 4c2b4a0
Show file tree
Hide file tree
Showing 91 changed files with 3,268 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright [2019-01-01] [Ahoo Wang]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SmartCode

> SmartCode = IDataSource -> IBuildTask -> IOutput => Build Everything
## 简介

![SmartCode](./doc/SmartCode.png)

## SmartCode.Db

![SmartCode](./doc/SmartCode-Db.gif)
55 changes: 55 additions & 0 deletions SmartCode.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartCode", "src\SmartCode\SmartCode.csproj", "{A9BB7212-C52B-46DB-836B-DB3ED282FF96}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartCode.CLI", "src\SmartCode.CLI\SmartCode.CLI.csproj", "{8FFFD66C-3779-4E10-B596-539F9BFAC879}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartCode.Tests", "src\SmartCode.Tests\SmartCode.Tests.csproj", "{D19BC6DA-259B-45CC-8194-43F5016636A5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartCode.Db", "src\SmartCode.Db\SmartCode.Db.csproj", "{049640FC-0C05-4C0D-AEF1-858B992225F5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartCode.App", "src\SmartCode.App\SmartCode.App.csproj", "{7D237A9F-4A67-4885-9190-2F8073A11B4A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartCode.TemplateEngine", "src\SmartCode.TemplateEngine\SmartCode.TemplateEngine.csproj", "{6AA5EF8A-9D31-4E41-A040-23289D4358E1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A9BB7212-C52B-46DB-836B-DB3ED282FF96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9BB7212-C52B-46DB-836B-DB3ED282FF96}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9BB7212-C52B-46DB-836B-DB3ED282FF96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9BB7212-C52B-46DB-836B-DB3ED282FF96}.Release|Any CPU.Build.0 = Release|Any CPU
{8FFFD66C-3779-4E10-B596-539F9BFAC879}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FFFD66C-3779-4E10-B596-539F9BFAC879}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FFFD66C-3779-4E10-B596-539F9BFAC879}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FFFD66C-3779-4E10-B596-539F9BFAC879}.Release|Any CPU.Build.0 = Release|Any CPU
{D19BC6DA-259B-45CC-8194-43F5016636A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D19BC6DA-259B-45CC-8194-43F5016636A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D19BC6DA-259B-45CC-8194-43F5016636A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D19BC6DA-259B-45CC-8194-43F5016636A5}.Release|Any CPU.Build.0 = Release|Any CPU
{049640FC-0C05-4C0D-AEF1-858B992225F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{049640FC-0C05-4C0D-AEF1-858B992225F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{049640FC-0C05-4C0D-AEF1-858B992225F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{049640FC-0C05-4C0D-AEF1-858B992225F5}.Release|Any CPU.Build.0 = Release|Any CPU
{7D237A9F-4A67-4885-9190-2F8073A11B4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D237A9F-4A67-4885-9190-2F8073A11B4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D237A9F-4A67-4885-9190-2F8073A11B4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D237A9F-4A67-4885-9190-2F8073A11B4A}.Release|Any CPU.Build.0 = Release|Any CPU
{6AA5EF8A-9D31-4E41-A040-23289D4358E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6AA5EF8A-9D31-4E41-A040-23289D4358E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6AA5EF8A-9D31-4E41-A040-23289D4358E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6AA5EF8A-9D31-4E41-A040-23289D4358E1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9A45CDB0-E532-4F55-84C6-B82C98BE5F38}
EndGlobalSection
EndGlobal
Binary file added doc/SmartCode-Db.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/SmartCode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
132 changes: 132 additions & 0 deletions doc/SmartCode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
Module: SmartSql.Starter
Author: Ahoo Wang
DataSource:
Name: Db
Paramters:
DbName: SmartSqlStarterDB
DbProvider: SqlServer
ConnectionString: Data Source=.;Initial Catalog=SmartSqlStarterDB;Integrated Security=True
Language: CSharp
TemplateEngine: Razor
Output:
Type: File
Path: 'E://SmartSql-Starter'

# 构建任务
Build:
ClearDir:
Type: Clear
Paramters:
Dirs: '.'
Solution:
Type: Project
Template: Sln.cshtml
Output:
Path: '.'
Name: '{{Project.Module}}'
Extension: '.sln'
Service:
Type: Project
Template: Proj.cshtml
Output:
Path: '{{Project.Module}}.Serivce'
Name: '{{Project.Module}}.Serivce'
Extension: '.csproj'
SmartSqlConfig:
Type: Project
Template: SqlMapConfig.cshtml
Output:
Path: '{{Project.Module}}.API'
Name: 'SmartSqlMapConfig'
Extension: '.xml'
Entity:
Type: Table
Module: Entity
Template: Entity.cshtml
Output:
Path: '{{Project.Module}}.{{Build.Module}}'
Extension: '.cs'
NamingConverter:
Table:
Tokenizer:
Type: Default
Paramters:
IgnorePrefix: 'T_'
Delimiter: '_'
Converter:
Type: Default
Paramters: { }
View:
Tokenizer:
Type: Default
Paramters:
IgnorePrefix: 'V_'
Delimiter: '_'
Converter:
Type: Pascal
Column:
Tokenizer:
Type: Default
Paramters:
Delimiter: '_'
Converter:
Type: Pascal

Repository:
Type: Table
Module: Repository
Template: Repository.cshtml
Output:
Path: '{{Project.Module}}.{{Build.Module}}'
Name: 'I{{OutputName}}Repository'
Extension: .cs
NamingConverter:
Table:
Tokenizer:
Type: Default
Paramters:
IgnorePrefix: 'T_'
Delimiter: '_'
Converter:
Type: Default
View:
Tokenizer:
Type: Default
Paramters:
IgnorePrefix: 'V_'
Delimiter: '_'
Converter:
Type: Default

SqlMap:
Type: Table
Template: SqlMap-SqlServer.cshtml
Output:
Path: '{{Project.Module}}.API/Maps'
Extension: .xml
IgnoreTables: null
NamingConverter:
Table:
Tokenizer:
Type: Default
Paramters:
IgnorePrefix: 'T_'
Delimiter: '_'
Converter:
Type: Default
View:
Tokenizer:
Type: Default
Paramters:
IgnorePrefix: 'V_'
Delimiter: '_'
Converter:
Type: Default
Column:
Tokenizer:
Type: Default
Paramters:
IgnorePrefix: 'T_'
Delimiter: '_'
Converter:
Type: Default
63 changes: 63 additions & 0 deletions src/SmartCode.App/BuildTasks/ClearBuildTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace SmartCode.App.BuildTasks
{
public class ClearBuildTask : IBuildTask
{
public ClearBuildTask(ILogger<ClearBuildTask> logger)
{
_logger = logger;
}
public bool Initialized => true;

public string Name => "Clear";


public Task Build(BuildContext context)
{
var paramters = context.Build.Paramters;
if (paramters == null) { return Task.CompletedTask; ; }

if (paramters.TryGetValue("Dirs", out string clearDirs))
{
var _clearDirs = clearDirs.Split(',');
foreach (var dir in _clearDirs)
{
var fullDir = Path.Combine(context.Project.OutputPath, dir);
_logger.LogInformation($"ClearBuildTask Delete directory:{fullDir} Start!");
if (Directory.Exists(fullDir))
{
Directory.Delete(fullDir, true);
}
_logger.LogInformation($"ClearBuildTask Delete directory:{fullDir} End!");
}
}
if (paramters.TryGetValue("Files", out string clearFiles))
{
var _clearFiles = clearFiles.Split(',');
foreach (var file in _clearFiles)
{
var fullfile = Path.Combine(context.Project.OutputPath, file);
_logger.LogInformation($"ClearBuildTask Delete file:{fullfile} Start!");
if (File.Exists(fullfile))
{
File.Delete(fullfile);
}
_logger.LogInformation($"ClearBuildTask Delete file:{fullfile} End!");
}
}
return Task.CompletedTask;
}
private readonly ILogger<ClearBuildTask> _logger;

public void Initialize(IDictionary<string, string> paramters)
{

}
}
}
59 changes: 59 additions & 0 deletions src/SmartCode.App/Outputs/FileOutput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using HandlebarsDotNet;

namespace SmartCode.App.Outputs
{
public class FileOutput : IOutput
{
private readonly ILogger<FileOutput> _logger;

public FileOutput(ILogger<FileOutput> logger)
{
_logger = logger;
}

public bool Initialized { get; private set; }

public string Name { get; private set; } = "File";

public void Initialize(IDictionary<string, string> paramters)
{
Initialized = true;
if (paramters == null) { return; }
if (paramters.TryGetValue("Name", out string name))
{
Name = name;
}
}

public async Task Output(BuildContext context)
{
_logger.LogInformation($"------ Output Build:{context.BuildKey} Start! ------");
var outputPath = Handlebars.Compile(context.Build.Output.Path)(context);
outputPath = Path.Combine(context.Project.OutputPath, outputPath);
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
_logger.LogWarning($"------ Output Directory:{outputPath} is not Exists,Created! ------");
}
var fileName = context.OutputName;
string outputName = context.Build.Output.Name;
if (!String.IsNullOrEmpty(outputName))
{
fileName = Handlebars.Compile(outputName)(context);
}
fileName = $"{fileName}{context.Build.Output.Extension}";
var filePath = Path.Combine(outputPath, fileName);
using (StreamWriter streamWriter = new StreamWriter(filePath))
{
await streamWriter.WriteAsync(context.Result);
}
_logger.LogInformation($"------ Output Build:{context.BuildKey} -> {filePath} End! ------");
}
}
}
Loading

0 comments on commit 4c2b4a0

Please sign in to comment.