Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

Commit 8b6314d

Browse files
kungabeevee
authored andcommitted
Docs gen (#27)
* generate readme * add command names * fix build: not update if help generating * remove dots at end of help line * fix * add module.yaml doc * fix space * fix space * fix * del .orig
1 parent 4868cca commit 8b6314d

9 files changed

+454
-7
lines changed

Cement.Net/CementEntry.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
</PropertyGroup>
115115
<Message Text="MERGING: @(MergeAssemblies->'%(Filename)') into $(OutputAssembly)" Importance="High" />
116116
<Exec Command="$(Merger) /out:&quot;$(OutputAssembly)&quot; @(MergeAssemblies->'&quot;%(FullPath)&quot;', ' ')" />
117+
<Exec Command="$(OutputAssembly) help --gen $(SolutionDir)\README.md" />
117118
</Target>
118119
<Target Name="CopyExe" DependsOnTargets="AfterBuild">
119120
<Exec Command="rmdir /S /Q %25userprofile%25\bin\dotnet" />

Cement.Net/Program.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ private static int Main(string[] args)
1717
ConsoleWriter.ResetProgress();
1818

1919
var command = args[0];
20-
if (command != "complete" && command != "check-pre-commit")
20+
if (command != "complete" && command != "check-pre-commit"
21+
&& (command != "help" || !args.Contains("--gen")))
2122
SelfUpdate.UpdateIfOld();
2223

2324
return exitCode == 0 ? 0 : 13;

Commands/Commands.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<ItemGroup>
6969
<Compile Include="AnalyzerAdd.cs" />
7070
<Compile Include="AnalyzerCommand.cs" />
71+
<Compile Include="ReadmeGenerator.cs" />
7172
<Compile Include="RefAdd.cs" />
7273
<Compile Include="Build.cs" />
7374
<Compile Include="BuildDeps.cs" />

Commands/Help.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
using Common;
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using Common;
25

36
namespace Commands
47
{
58
public class Help : ICommand
69
{
710
public int Run(string[] args)
811
{
12+
if (args.Contains("--gen"))
13+
{
14+
GenerateReadme(args[2]);
15+
return 0;
16+
}
17+
918
if (args.Length == 1)
1019
{
1120
CommandsList.Print();
@@ -33,6 +42,15 @@ public int Run(string[] args)
3342
return -1;
3443
}
3544

45+
private static void GenerateReadme(string file)
46+
{
47+
var text = File.ReadAllText(file);
48+
var index = text.IndexOf("# Commands", StringComparison.Ordinal)
49+
+ "# Commands".Length;
50+
text = text.Substring(0, index) + ReadmeGenerator.Generate();
51+
File.WriteAllText(file, text);
52+
}
53+
3654
private static void PrintHelpFooter()
3755
{
3856
ConsoleWriter.WriteLine("Cement. 2017.");

Commands/ReadmeGenerator.cs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace Commands
2+
{
3+
public static class ReadmeGenerator
4+
{
5+
public static string Generate()
6+
{
7+
var commands = CommandsList.Commands;
8+
9+
return $@"
10+
### cm help
11+
{commands["help"].HelpMessage}
12+
13+
### cm self-update
14+
{commands["self-update"].HelpMessage}
15+
### cm --version
16+
{commands["--version"].HelpMessage}
17+
18+
### cm init
19+
{commands["init"].HelpMessage}
20+
### cm get
21+
{commands["get"].HelpMessage}
22+
### cm update-deps
23+
{commands["update-deps"].HelpMessage}
24+
### cm update
25+
{commands["update"].HelpMessage}
26+
27+
### cm build-deps
28+
{commands["build-deps"].HelpMessage}
29+
### cm build
30+
{commands["build"].HelpMessage}
31+
32+
### cm ls
33+
{commands["ls"].HelpMessage}
34+
### cm module
35+
{commands["module"].HelpMessage}
36+
### cm ref
37+
{commands["ref"].HelpMessage}
38+
### cm show-configs
39+
{commands["show-configs"].HelpMessage}
40+
### cm check-deps
41+
{commands["check-deps"].HelpMessage}
42+
### cm show-deps
43+
{commands["show-deps"].HelpMessage}
44+
45+
### cm status
46+
{commands["status"].HelpMessage}";
47+
}
48+
}
49+
}

Commands/Status.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ private void PrintStatus(GitRepository repo)
6363
}
6464

6565
public string HelpMessage => @"
66-
Prints status of modifed git repos in the cement tracked dir.
67-
It checks repo for push/pull and local state.
66+
Prints status of modifed git repos in the cement tracked dir
67+
It checks repo for push/pull and local state
6868
6969
Usage:
7070
cm status
7171
72-
Runs anywhere in the cement tracked tree.
72+
Runs anywhere in the cement tracked tree
7373
";
7474

7575
public bool IsHiddenCommand => false;

Commands/Update.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ cm update [-f/-r/-p] [-v] [treeish]
6262
6363
-v/--verbose show commit info for deps
6464
65-
This command runs 'update' ('git pull origin treeish') command for module.
66-
If treeish isn't specified, cement uses current.
65+
This command runs 'update' ('git pull origin treeish') command for module
66+
If treeish isn't specified, cement uses current
6767
";
6868
}
6969
}

README-module.yaml.md

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# module.yaml
2+
Информация о модуле содержится в файле `module.yaml`.
3+
4+
Каждый модуль может состоять из одной либо нескольких конфигураций (например конфигурация клиента, конфигурация с серверной частью, и конфигурация включающая тесты).
5+
6+
Каждая конфигурация может включать в себя следующие секции:
7+
8+
- deps
9+
- build
10+
- install/artifacts
11+
12+
Конфигурации можно наследовать, что бы избежать дублирования информации о зависимостях.
13+
14+
В модуле должна присутствовать конфигурация `full-build`, которая должна по возможности включать в себя остальные. Она будет использоваться при выполнении команд `cm get` и `cm build`.
15+
16+
Необязательная конфигурация `default` является родителем для всех остальных.
17+
18+
Пример:
19+
20+
# секция описания конфигурации client
21+
client:
22+
# список зависимостей конфигурации client
23+
# зависимость указывается в следующем виде: <moduleName>[@branchName][/configName]
24+
# kanso - ссылка на модуль kanso.
25+
# kanso/client - ссылка на kanso в конфигурации client.
26+
# kanso@develop/client - kanso из ветки develop в конфигурации client
27+
deps:
28+
- core
29+
- log4net
30+
- nunit
31+
- logging
32+
- http
33+
- http.rp
34+
- topology
35+
36+
# информация о построении данного модуля в данной конфигурации
37+
build:
38+
# build solution Kontur.Drive.sln in Client configuration
39+
target: Kontur.Drive.sln
40+
configuration: Client
41+
42+
# Информация о том, что является результатом билда данной конфигурации
43+
install:
44+
- bin/Kontur.Drive.Client.dll
45+
- bin/Kontur.Drive.ServiceModel.dll
46+
- module logging # Для работы Kontur.Drive.Client.dll нужна ссылка на результаты билда модуля logging
47+
- nuget Newtonsoft.Json/6.0.8 # Либо нужена ссылка на nuget пакет
48+
49+
# Конфигурация sdk "расширяет" конфигурацию client (> client) и является конфигурацией по умолчанию (*default) (используется при добавлении ссылки на данный модуль)
50+
sdk > client *default:
51+
# Для избежания дублирования списков зависимостей, deps от client наследуются сюда и их не нужно повторно прописывать
52+
deps:
53+
- auth
54+
- libfront
55+
- zebra
56+
- kanso
57+
- upload-service
58+
- access-control
59+
- zebra-utils
60+
- config
61+
- zookeeper
62+
63+
# Секция build НЕ наследуется
64+
build:
65+
target: Kontur.Drive.sln
66+
configuration: Sdk
67+
68+
# Секция install наследуется, т.е. необходимо дописать лишь недостающие бинари
69+
install:
70+
- Kontur.Drive.TestHost/bin/Release/Kontur.Drive.TestHost.exe
71+
- Kontur.Drive.TestHost/bin/Release/ServiceStack.Interfaces.dll
72+
73+
74+
# Конфигурация full-build расширяет client и sdk
75+
full-build > client, sdk:
76+
deps:
77+
# Так указывается diff на deps (в конфигурации full-build используется kanso/full-build. Сначала "удаляем" kanso из зависимостей, потом добавляем kanso/full-build)
78+
- -kanso
79+
- kanso/full-build
80+
81+
build:
82+
target: Kontur.Drive.sln
83+
configuration: Release
84+
85+
86+
# build section
87+
88+
#### Для модуля который не надо строить:
89+
90+
build:
91+
target: None
92+
configuration: None
93+
94+
#### Если нужно указать дополнительные параметры:
95+
96+
build:
97+
target: Solution.sln # Указание цели построения
98+
tool:
99+
name: msbuild # Инструмент для сборки. msbuild - для MSBuild.exe на Windows и xbuild на *nix.
100+
version: "14.0" # Версия msbuild, по умолчанию - последняя
101+
# set VS150COMNTOOLS=D:\Program Files\Microsoft Visual Studio\2017\Professional\Common7\Tools\
102+
# Обязательно в кавычках
103+
configuration: Release # Конфигурация солюшена
104+
parameters: "/p:WarningLevel=0" # Здесь можно указать свои параметры. Параметры по умолчанию не используются. Кавычки в параметрах экранируются символом '\'.
105+
# Параметры по умолчанию для msbuild:
106+
# /t:Rebuild /nodeReuse:false /maxcpucount /v:m /p:WarningLevel=0
107+
# /p:VisualStudioVersion=14.0 (если явно указана)
108+
109+
110+
#### Если в модуле несколько солюшенов
111+
112+
build:
113+
- name: a.release # Нужно назвать каждую часть
114+
target: a.sln
115+
configuration: release
116+
- name: b.debug
117+
target: b.sln
118+
configuration: debug
119+
120+
#### Build with custom script:
121+
122+
build.xproj:
123+
124+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
125+
<Target Name="Rebuild">
126+
<Exec Command="ping google.com > 1.txt" />
127+
</Target>
128+
</Project>
129+
130+
module.yaml:
131+
132+
full-build:
133+
deps:
134+
build:
135+
target: build.xproj
136+
configuration: Release
137+
138+
# Git hooks
139+
140+
default: # Описываем в конфигурации default
141+
hooks:
142+
- myhooks/pre-push # Путь до хука в репозитории
143+
# будет скопирован в <module_name>/.git/hooks
144+
- pre-commit.cement # Встроенный в цемент pre-commit хук, который проверит, что файлы содержащие не ASCII символы имеют кодировку UTF-8 with BOM
145+
# не может быть более 1 хука с одинаковым именем
146+
147+
full-build *default: # Остальные конфигурации модуля
148+
149+
150+
Если в текущей ветке есть хук, то при переключении на другую ветку он не удалится.
151+
Если вы хотите использовать ваш хук с pre-commit.cement, просто добавьте его вызов в свой хук:
152+
153+
.git/hooks/pre-commit.cement
154+
if [ $? -ne 0 ]; then
155+
exit 1
156+
fi
157+

0 commit comments

Comments
 (0)