Skip to content

Commit 4c2b4a0

Browse files
committed
SmartCode = IDataSource -> IBuildTask -> IOutput => Build Everything
1 parent da3b502 commit 4c2b4a0

File tree

91 files changed

+3268
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3268
-1
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

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

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SmartCode
2+
3+
> SmartCode = IDataSource -> IBuildTask -> IOutput => Build Everything
4+
5+
## 简介
6+
7+
![SmartCode](./doc/SmartCode.png)
8+
9+
## SmartCode.Db
10+
11+
![SmartCode](./doc/SmartCode-Db.gif)

SmartCode.sln

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28010.2036
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartCode", "src\SmartCode\SmartCode.csproj", "{A9BB7212-C52B-46DB-836B-DB3ED282FF96}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartCode.CLI", "src\SmartCode.CLI\SmartCode.CLI.csproj", "{8FFFD66C-3779-4E10-B596-539F9BFAC879}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartCode.Tests", "src\SmartCode.Tests\SmartCode.Tests.csproj", "{D19BC6DA-259B-45CC-8194-43F5016636A5}"
11+
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartCode.Db", "src\SmartCode.Db\SmartCode.Db.csproj", "{049640FC-0C05-4C0D-AEF1-858B992225F5}"
13+
EndProject
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartCode.App", "src\SmartCode.App\SmartCode.App.csproj", "{7D237A9F-4A67-4885-9190-2F8073A11B4A}"
15+
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartCode.TemplateEngine", "src\SmartCode.TemplateEngine\SmartCode.TemplateEngine.csproj", "{6AA5EF8A-9D31-4E41-A040-23289D4358E1}"
17+
EndProject
18+
Global
19+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
20+
Debug|Any CPU = Debug|Any CPU
21+
Release|Any CPU = Release|Any CPU
22+
EndGlobalSection
23+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
24+
{A9BB7212-C52B-46DB-836B-DB3ED282FF96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{A9BB7212-C52B-46DB-836B-DB3ED282FF96}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{A9BB7212-C52B-46DB-836B-DB3ED282FF96}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{A9BB7212-C52B-46DB-836B-DB3ED282FF96}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{8FFFD66C-3779-4E10-B596-539F9BFAC879}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{8FFFD66C-3779-4E10-B596-539F9BFAC879}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{8FFFD66C-3779-4E10-B596-539F9BFAC879}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{8FFFD66C-3779-4E10-B596-539F9BFAC879}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{D19BC6DA-259B-45CC-8194-43F5016636A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{D19BC6DA-259B-45CC-8194-43F5016636A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{D19BC6DA-259B-45CC-8194-43F5016636A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{D19BC6DA-259B-45CC-8194-43F5016636A5}.Release|Any CPU.Build.0 = Release|Any CPU
36+
{049640FC-0C05-4C0D-AEF1-858B992225F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37+
{049640FC-0C05-4C0D-AEF1-858B992225F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
38+
{049640FC-0C05-4C0D-AEF1-858B992225F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
39+
{049640FC-0C05-4C0D-AEF1-858B992225F5}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{7D237A9F-4A67-4885-9190-2F8073A11B4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{7D237A9F-4A67-4885-9190-2F8073A11B4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{7D237A9F-4A67-4885-9190-2F8073A11B4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{7D237A9F-4A67-4885-9190-2F8073A11B4A}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{6AA5EF8A-9D31-4E41-A040-23289D4358E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{6AA5EF8A-9D31-4E41-A040-23289D4358E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{6AA5EF8A-9D31-4E41-A040-23289D4358E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{6AA5EF8A-9D31-4E41-A040-23289D4358E1}.Release|Any CPU.Build.0 = Release|Any CPU
48+
EndGlobalSection
49+
GlobalSection(SolutionProperties) = preSolution
50+
HideSolutionNode = FALSE
51+
EndGlobalSection
52+
GlobalSection(ExtensibilityGlobals) = postSolution
53+
SolutionGuid = {9A45CDB0-E532-4F55-84C6-B82C98BE5F38}
54+
EndGlobalSection
55+
EndGlobal

doc/SmartCode-Db.gif

1.15 MB
Loading

doc/SmartCode.png

62.1 KB
Loading

doc/SmartCode.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
Module: SmartSql.Starter
2+
Author: Ahoo Wang
3+
DataSource:
4+
Name: Db
5+
Paramters:
6+
DbName: SmartSqlStarterDB
7+
DbProvider: SqlServer
8+
ConnectionString: Data Source=.;Initial Catalog=SmartSqlStarterDB;Integrated Security=True
9+
Language: CSharp
10+
TemplateEngine: Razor
11+
Output:
12+
Type: File
13+
Path: 'E://SmartSql-Starter'
14+
15+
# 构建任务
16+
Build:
17+
ClearDir:
18+
Type: Clear
19+
Paramters:
20+
Dirs: '.'
21+
Solution:
22+
Type: Project
23+
Template: Sln.cshtml
24+
Output:
25+
Path: '.'
26+
Name: '{{Project.Module}}'
27+
Extension: '.sln'
28+
Service:
29+
Type: Project
30+
Template: Proj.cshtml
31+
Output:
32+
Path: '{{Project.Module}}.Serivce'
33+
Name: '{{Project.Module}}.Serivce'
34+
Extension: '.csproj'
35+
SmartSqlConfig:
36+
Type: Project
37+
Template: SqlMapConfig.cshtml
38+
Output:
39+
Path: '{{Project.Module}}.API'
40+
Name: 'SmartSqlMapConfig'
41+
Extension: '.xml'
42+
Entity:
43+
Type: Table
44+
Module: Entity
45+
Template: Entity.cshtml
46+
Output:
47+
Path: '{{Project.Module}}.{{Build.Module}}'
48+
Extension: '.cs'
49+
NamingConverter:
50+
Table:
51+
Tokenizer:
52+
Type: Default
53+
Paramters:
54+
IgnorePrefix: 'T_'
55+
Delimiter: '_'
56+
Converter:
57+
Type: Default
58+
Paramters: { }
59+
View:
60+
Tokenizer:
61+
Type: Default
62+
Paramters:
63+
IgnorePrefix: 'V_'
64+
Delimiter: '_'
65+
Converter:
66+
Type: Pascal
67+
Column:
68+
Tokenizer:
69+
Type: Default
70+
Paramters:
71+
Delimiter: '_'
72+
Converter:
73+
Type: Pascal
74+
75+
Repository:
76+
Type: Table
77+
Module: Repository
78+
Template: Repository.cshtml
79+
Output:
80+
Path: '{{Project.Module}}.{{Build.Module}}'
81+
Name: 'I{{OutputName}}Repository'
82+
Extension: .cs
83+
NamingConverter:
84+
Table:
85+
Tokenizer:
86+
Type: Default
87+
Paramters:
88+
IgnorePrefix: 'T_'
89+
Delimiter: '_'
90+
Converter:
91+
Type: Default
92+
View:
93+
Tokenizer:
94+
Type: Default
95+
Paramters:
96+
IgnorePrefix: 'V_'
97+
Delimiter: '_'
98+
Converter:
99+
Type: Default
100+
101+
SqlMap:
102+
Type: Table
103+
Template: SqlMap-SqlServer.cshtml
104+
Output:
105+
Path: '{{Project.Module}}.API/Maps'
106+
Extension: .xml
107+
IgnoreTables: null
108+
NamingConverter:
109+
Table:
110+
Tokenizer:
111+
Type: Default
112+
Paramters:
113+
IgnorePrefix: 'T_'
114+
Delimiter: '_'
115+
Converter:
116+
Type: Default
117+
View:
118+
Tokenizer:
119+
Type: Default
120+
Paramters:
121+
IgnorePrefix: 'V_'
122+
Delimiter: '_'
123+
Converter:
124+
Type: Default
125+
Column:
126+
Tokenizer:
127+
Type: Default
128+
Paramters:
129+
IgnorePrefix: 'T_'
130+
Delimiter: '_'
131+
Converter:
132+
Type: Default
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Microsoft.Extensions.Logging;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace SmartCode.App.BuildTasks
9+
{
10+
public class ClearBuildTask : IBuildTask
11+
{
12+
public ClearBuildTask(ILogger<ClearBuildTask> logger)
13+
{
14+
_logger = logger;
15+
}
16+
public bool Initialized => true;
17+
18+
public string Name => "Clear";
19+
20+
21+
public Task Build(BuildContext context)
22+
{
23+
var paramters = context.Build.Paramters;
24+
if (paramters == null) { return Task.CompletedTask; ; }
25+
26+
if (paramters.TryGetValue("Dirs", out string clearDirs))
27+
{
28+
var _clearDirs = clearDirs.Split(',');
29+
foreach (var dir in _clearDirs)
30+
{
31+
var fullDir = Path.Combine(context.Project.OutputPath, dir);
32+
_logger.LogInformation($"ClearBuildTask Delete directory:{fullDir} Start!");
33+
if (Directory.Exists(fullDir))
34+
{
35+
Directory.Delete(fullDir, true);
36+
}
37+
_logger.LogInformation($"ClearBuildTask Delete directory:{fullDir} End!");
38+
}
39+
}
40+
if (paramters.TryGetValue("Files", out string clearFiles))
41+
{
42+
var _clearFiles = clearFiles.Split(',');
43+
foreach (var file in _clearFiles)
44+
{
45+
var fullfile = Path.Combine(context.Project.OutputPath, file);
46+
_logger.LogInformation($"ClearBuildTask Delete file:{fullfile} Start!");
47+
if (File.Exists(fullfile))
48+
{
49+
File.Delete(fullfile);
50+
}
51+
_logger.LogInformation($"ClearBuildTask Delete file:{fullfile} End!");
52+
}
53+
}
54+
return Task.CompletedTask;
55+
}
56+
private readonly ILogger<ClearBuildTask> _logger;
57+
58+
public void Initialize(IDictionary<string, string> paramters)
59+
{
60+
61+
}
62+
}
63+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using Microsoft.Extensions.Logging;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using HandlebarsDotNet;
8+
9+
namespace SmartCode.App.Outputs
10+
{
11+
public class FileOutput : IOutput
12+
{
13+
private readonly ILogger<FileOutput> _logger;
14+
15+
public FileOutput(ILogger<FileOutput> logger)
16+
{
17+
_logger = logger;
18+
}
19+
20+
public bool Initialized { get; private set; }
21+
22+
public string Name { get; private set; } = "File";
23+
24+
public void Initialize(IDictionary<string, string> paramters)
25+
{
26+
Initialized = true;
27+
if (paramters == null) { return; }
28+
if (paramters.TryGetValue("Name", out string name))
29+
{
30+
Name = name;
31+
}
32+
}
33+
34+
public async Task Output(BuildContext context)
35+
{
36+
_logger.LogInformation($"------ Output Build:{context.BuildKey} Start! ------");
37+
var outputPath = Handlebars.Compile(context.Build.Output.Path)(context);
38+
outputPath = Path.Combine(context.Project.OutputPath, outputPath);
39+
if (!Directory.Exists(outputPath))
40+
{
41+
Directory.CreateDirectory(outputPath);
42+
_logger.LogWarning($"------ Output Directory:{outputPath} is not Exists,Created! ------");
43+
}
44+
var fileName = context.OutputName;
45+
string outputName = context.Build.Output.Name;
46+
if (!String.IsNullOrEmpty(outputName))
47+
{
48+
fileName = Handlebars.Compile(outputName)(context);
49+
}
50+
fileName = $"{fileName}{context.Build.Output.Extension}";
51+
var filePath = Path.Combine(outputPath, fileName);
52+
using (StreamWriter streamWriter = new StreamWriter(filePath))
53+
{
54+
await streamWriter.WriteAsync(context.Result);
55+
}
56+
_logger.LogInformation($"------ Output Build:{context.BuildKey} -> {filePath} End! ------");
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)