Skip to content

Commit 2857ac8

Browse files
committed
small fixes
1 parent fe0e16f commit 2857ac8

16 files changed

Lines changed: 302 additions & 40 deletions

.github/workflows/dotnet.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ jobs:
8585
env:
8686
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
8787

88+
- name: Set NuGet package version
89+
run: |
90+
$nugetVersion = "${{ env.semVer }}"
91+
if ([string]::IsNullOrWhiteSpace($nugetVersion)) { $nugetVersion = "2.2.0" }
92+
(Get-Content "src/TypeScriptDefinitionGenerator.MSBuild/TypeScriptDefinitionGenerator.MSBuild.csproj") -replace '<PackageVersion>[^<]+</PackageVersion>', "<PackageVersion>$nugetVersion</PackageVersion>" | Set-Content "src/TypeScriptDefinitionGenerator.MSBuild/TypeScriptDefinitionGenerator.MSBuild.csproj"
93+
(Get-Content "src/TypeScriptDefinitionGenerator.MSBuild/TypeScriptDefinitionGenerator.MSBuild.props") -replace 'Version="[^"]+"', "Version=`"$nugetVersion`"" | Set-Content "src/TypeScriptDefinitionGenerator.MSBuild/TypeScriptDefinitionGenerator.MSBuild.props"
94+
echo "NUGET_VERSION=$nugetVersion" >> $env:GITHUB_ENV
95+
8896
- name: Increment VSIX version
8997
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request'
9098
run: |
@@ -111,6 +119,22 @@ jobs:
111119
- name: Build Rider plugin
112120
run: bash build-rider-plugin.sh $env:BUILD_CONFIG "${{ env.semVer }}"
113121

122+
- name: Pack NuGet packages
123+
run: |
124+
New-Item -ItemType Directory -Path artifacts/nuget -Force
125+
dotnet pack src/TypeScriptDefinitionGenerator.Cli/TypeScriptDefinitionGenerator.Cli.csproj -c $env:BUILD_CONFIG -o artifacts/nuget -p:PackageVersion=$env:NUGET_VERSION
126+
dotnet pack src/TypeScriptDefinitionGenerator.MSBuild/TypeScriptDefinitionGenerator.MSBuild.csproj -c $env:BUILD_CONFIG -o artifacts/nuget -p:PackageVersion=$env:NUGET_VERSION
127+
128+
- name: Publish to NuGet.org
129+
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request'
130+
run: |
131+
$pkgs = Get-ChildItem -Path artifacts/nuget -Filter "*.nupkg" -ErrorAction SilentlyContinue
132+
foreach ($pkg in $pkgs) {
133+
dotnet nuget push $pkg.FullName --source https://api.nuget.org/v3/index.json --api-key $env:NUGET_API_KEY --skip-duplicate
134+
}
135+
env:
136+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
137+
114138
- name: ref
115139
run: echo "github.head_ref 1 ${{ github.head_ref }} 2 $GITHUB_REF 3 ${{ github.ref }}"
116140

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
These are the changes to each version that has been released
88
on the official Visual Studio extension gallery.
99

10+
## 2.3.0 (unreleased)
11+
12+
- [x] NuGet-пакет `TypeScriptDefinitionGenerator.MSBuild` — MSBuild targets для автогенерации при сборке
13+
- [x] NuGet-пакет `TypeScriptDefinitionGenerator.Cli` — dotnet tool `tsdefgen`
14+
- [x] Rider-плагин добавляет `PackageReference` вместо `Directory.Build.targets` и `Import`
15+
- [x] Публикация пакетов в nuget.org через GitHub Actions
16+
1017
## 2.2.0
1118
- [x] Removed useless files
1219
- [x] Refactoring / code optimizing

GitVersion.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
next-version: 1.0.0 #
1+
next-version: 2.2.0
22
branches:
33
master:
44
regex: ^master$|^main$

README-RIDER.md

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
## Способ 1: External Tool (рекомендуется)
66

7-
1. **Соберите и установите dotnet tool:**
7+
1. **Установите dotnet tool:**
8+
```bash
9+
dotnet tool install -g TypeScriptDefinitionGenerator.Cli
10+
```
11+
Или из исходников:
812
```bash
913
cd src/TypeScriptDefinitionGenerator.Cli
1014
dotnet pack -c Release
1115
dotnet tool install -g --add-source ./bin/Release TypeScriptDefinitionGenerator.Cli
1216
```
13-
Или запускайте напрямую:
17+
Или запускайте напрямую (без установки):
1418
```bash
1519
dotnet run --project src/TypeScriptDefinitionGenerator.Cli -- $FilePath$
1620
```
@@ -19,7 +23,7 @@
1923
- **Settings****Tools****External Tools****Add**
2024
- **Name:** Generate TypeScript Definition
2125
- **Program:** `dotnet`
22-
- **Arguments:** `run --project src/TypeScriptDefinitionGenerator.Cli -- $FilePath$`
26+
- **Arguments:** `tsdefgen $FilePath$` (при установленном tool) или `run --project src/TypeScriptDefinitionGenerator.Cli -- $FilePath$` (при работе из исходников)
2327
- **Working directory:** `$ContentRoot$`
2428
- Включите **Synchronize files after execution**
2529

@@ -30,11 +34,12 @@
3034
## Способ 2: Запуск из терминала
3135

3236
```bash
33-
# Один файл (укажите путь к вашему .cs файлу)
34-
dotnet run --project src/TypeScriptDefinitionGenerator.Cli -- path/to/YourDto.cs
37+
# Через dotnet tool (после: dotnet tool install -g TypeScriptDefinitionGenerator.Cli)
38+
dotnet tsdefgen path/to/YourDto.cs
39+
dotnet tsdefgen path/to/Dto1.cs path/to/Dto2.cs
3540

36-
# Несколько файлов
37-
dotnet run --project src/TypeScriptDefinitionGenerator.Cli -- path/to/Dto1.cs path/to/Dto2.cs
41+
# Или напрямую из исходников
42+
dotnet run --project src/TypeScriptDefinitionGenerator.Cli -- path/to/YourDto.cs
3843
```
3944

4045
## Конфигурация (tsdefgen.json)
@@ -57,7 +62,33 @@ dotnet run --project src/TypeScriptDefinitionGenerator.Cli -- path/to/Dto1.cs pa
5762

5863
## Автогенерация при сборке (MSBuild)
5964

60-
При изменении .cs файла можно автоматически перегенерировать .d.ts при сборке. Добавьте в .csproj:
65+
При изменении .cs файла можно автоматически перегенерировать .d.ts при сборке.
66+
67+
### Вариант 1: NuGet-пакет (рекомендуется)
68+
69+
```bash
70+
dotnet add package TypeScriptDefinitionGenerator.MSBuild
71+
```
72+
73+
Пакет добавляет `DotNetToolReference` на `TypeScriptDefinitionGenerator.Cli` и MSBuild targets. Добавьте в .csproj:
74+
75+
```xml
76+
<ItemGroup>
77+
<PackageReference Include="TypeScriptDefinitionGenerator.MSBuild" Version="2.2.*" />
78+
</ItemGroup>
79+
80+
<ItemGroup>
81+
<TypeScriptDefinitionSource Include="Models\Dto.cs" />
82+
</ItemGroup>
83+
84+
<ItemGroup>
85+
<None Update="Models\Dto.generated.d.ts">
86+
<DependentUpon>Dto.cs</DependentUpon>
87+
</None>
88+
</ItemGroup>
89+
```
90+
91+
### Вариант 2: Локальный targets (для разработки в репозитории TypeScriptDefinitionGenerator)
6192

6293
```xml
6394
<Import Project="path/to/build/TypeScriptDefinitionGenerator.targets" />
@@ -121,6 +152,6 @@ export JAVA_HOME=$(/usr/libexec/java_home -v 17) # macOS
121152
Плагин запускает `dotnet run --project src/TypeScriptDefinitionGenerator.Cli -- <путь-к-файлу>` в каталоге решения.
122153

123154
При успешной генерации плагин автоматически добавляет в .csproj:
124-
- `TypeScriptDefinitionSource` для автогенерации при сборке
125-
- `None` с `DependentUpon` — для отображения в Solution Explorer
126-
- `Directory.Build.targets` — при первом запуске (если targets есть в `build/`)
155+
- `PackageReference` на `TypeScriptDefinitionGenerator.MSBuild` — MSBuild targets и dotnet tool для автогенерации при сборке
156+
- `TypeScriptDefinitionSource` — список .cs файлов для генерации
157+
- `None` с `DependentUpon` — для отображения .d.ts в Solution Explorer

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TypeScript Definition Generator
22

3-
[![Build status](https://ci.appveyor.com/api/projects/status/lbuvy4vnkky4ycsb/branch/master?svg=true)](https://ci.appveyor.com/project/denis-peshkov/typescriptdefinitiongenerator/branch/master)
3+
[![.NET](https://github.com/denis-peshkov/TypeScriptDefinitionGenerator/actions/workflows/dotnet.yml/badge.svg)](https://github.com/denis-peshkov/TypeScriptDefinitionGenerator/actions/workflows/dotnet.yml)
44

55
## NOTE: This is a customed redistribute
66
The orginal repo wrote by @madskristensen, **best regard for him**!
@@ -101,6 +101,24 @@ Configure this extension from the **Tools -> Options -> Text Editor -> JavaScrip
101101

102102
![Settings](art/settings.png)
103103

104+
## NuGet (MSBuild + dotnet tool)
105+
106+
Для автогенерации .d.ts при сборке добавьте пакет:
107+
108+
```bash
109+
dotnet add package TypeScriptDefinitionGenerator.MSBuild
110+
```
111+
112+
Пакет подключает MSBuild targets и dotnet tool `tsdefgen`. В .csproj добавьте:
113+
114+
```xml
115+
<ItemGroup>
116+
<TypeScriptDefinitionSource Include="Models\**\*.cs" />
117+
</ItemGroup>
118+
```
119+
120+
См. [README-RIDER.md](README-RIDER.md) для полной конфигурации.
121+
104122
## JetBrains Rider
105123

106124
Для использования в Rider см. [README-RIDER.md](README-RIDER.md) — плагин с контекстным меню, External Tool или dotnet tool для генерации .d.ts файлов.

TypeScriptDefinitionGenerator.slnx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
<Solution>
2+
<Folder Name="/.github/">
3+
<File Path=".github\CONTRIBUTING.md" />
4+
<File Path=".github\ISSUE_TEMPLATE.md" />
5+
</Folder>
6+
<Folder Name="/.github/workflows/">
7+
<File Path=".github\workflows\dotnet.yml" />
8+
</Folder>
29
<Folder Name="/assets/">
310
<File Path=".gitignore" />
411
<File Path="appveyor.yml" />
512
<File Path="build-rider-plugin.sh" />
613
<File Path="CHANGELOG.md" />
14+
<File Path="GitVersion.yml" />
715
<File Path="LICENSE" />
16+
<File Path="overview.md" />
17+
<File Path="publish-marketplace.ps1" />
818
<File Path="README-RIDER.md" />
919
<File Path="README.md" />
20+
<File Path="vs-publish.json" />
1021
</Folder>
1122
<Project Path="src/TypeScriptDefinitionGenerator.Cli/TypeScriptDefinitionGenerator.Cli.csproj" />
23+
<Project Path="src/TypeScriptDefinitionGenerator.MSBuild/TypeScriptDefinitionGenerator.MSBuild.csproj" />
1224
<Project Path="src/TypeScriptDefinitionGenerator.Core/TypeScriptDefinitionGenerator.Core.csproj" />
1325
<Project Path="src/TypeScriptDefinitionGenerator.Rider/TypeScriptDefinitionGenerator.Rider.csproj" />
1426
<Project Path="src/TypeScriptDefinitionGenerator/TypeScriptDefinitionGenerator.csproj" />

docs/PUBLISHING.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Публикация в маркетплейсы
2+
3+
## GitHub Actions (Repository → Settings → Secrets and variables → Actions)
4+
5+
| Secret | Описание |
6+
|--------|----------|
7+
| `VS_MARKETPLACE_PAT` | Personal Access Token из Azure DevOps (Marketplace → Manage) для публикации VSIX в [Visual Studio Marketplace](https://marketplace.visualstudio.com/) |
8+
| `JETBRAINS_MARKETPLACE_TOKEN` | Permanent Token из [JetBrains Marketplace → My Tokens](https://plugins.jetbrains.com/author/me/tokens) для публикации Rider-плагина |
9+
| `NUGET_API_KEY` | API Key из [nuget.org → Account → API Keys](https://www.nuget.org/account/apikeys) для публикации пакетов TypeScriptDefinitionGenerator.Cli и TypeScriptDefinitionGenerator.MSBuild |
10+
11+
## VS Marketplace (PAT)
12+
13+
1. [Azure DevOps](https://dev.azure.com) → User settings → Personal access tokens
14+
2. New Token, Scope: **Marketplace****Manage**
15+
3. Добавить в GitHub как secret `VS_MARKETPLACE_PAT`
16+
17+
## JetBrains Marketplace (Token)
18+
19+
1. [plugins.jetbrains.com](https://plugins.jetbrains.com) → Author → My Tokens
20+
2. Create new token
21+
3. Добавить в GitHub как secret `JETBRAINS_MARKETPLACE_TOKEN`
22+
23+
## NuGet.org (API Key)
24+
25+
1. [nuget.org](https://www.nuget.org) → Account → API Keys
26+
2. Create → Generate new key (Scope: Push new packages)
27+
3. Добавить в GitHub как secret `NUGET_API_KEY`
28+
29+
Публикуются пакеты: `TypeScriptDefinitionGenerator.Cli` (dotnet tool), `TypeScriptDefinitionGenerator.MSBuild` (MSBuild targets).
30+
31+
## Локальная публикация
32+
33+
```powershell
34+
# После сборки (msbuild + build-rider-plugin.sh)
35+
$env:VS_MARKETPLACE_PAT = "your-pat"
36+
$env:JETBRAINS_MARKETPLACE_TOKEN = "your-token"
37+
.\publish-marketplace.ps1 -VsixPath "src\TypeScriptDefinitionGenerator\bin\Release\TypeScriptDefinitionGenerator.vsix"
38+
```
39+
40+
```powershell
41+
# Публикация NuGet-пакетов
42+
$env:NUGET_API_KEY = "your-api-key"
43+
dotnet nuget push artifacts/nuget/*.nupkg --source https://api.nuget.org/v3/index.json --api-key $env:NUGET_API_KEY --skip-duplicate
44+
```

overview.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# TypeScript Definition Generator
2+
3+
Creates and synchronizes TypeScript Definition files (`.d.ts`) from C# model classes (DTO) to build strongly typed web applications where the server and client-side models are in sync. Works on all .NET project types.
4+
5+
## Features
6+
7+
- Right-click any `.cs` file and select **Generate TypeScript Definition** to create a `.generated.d.ts` file
8+
- Automatically updates `.d.ts` when the C# file is modified and saved
9+
- Supports classes, interfaces, enums, inheritance, and XML documentation
10+
- Configurable: camelCase, module format, EOL, indentation
11+
12+
## NuGet
13+
14+
For MSBuild integration and CI/CD: `dotnet add package TypeScriptDefinitionGenerator.MSBuild` — adds targets for build-time generation.
15+
16+
## JetBrains Rider
17+
18+
For Rider, see [README-RIDER.md](https://github.com/denis-peshkov/TypeScriptDefinitionGenerator/blob/master/README-RIDER.md) — plugin with context menu, External Tool, or dotnet tool.
19+
20+
## Links
21+
22+
- [GitHub](https://github.com/denis-peshkov/TypeScriptDefinitionGenerator)
23+
- [Changelog](https://github.com/denis-peshkov/TypeScriptDefinitionGenerator/blob/master/CHANGELOG.md)

publish-marketplace.ps1

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Publish TypeScript Definition Generator to marketplaces
2+
# Requires: $env:VS_MARKETPLACE_PAT (Azure DevOps PAT), $env:JETBRAINS_MARKETPLACE_TOKEN
3+
# Run from repo root after build
4+
5+
param(
6+
[string]$VsixPath = "",
7+
[string]$RiderZipPath = "output\TypeScriptDefinitionGenerator.Rider-1.0.0.zip"
8+
)
9+
10+
$ErrorActionPreference = "Stop"
11+
12+
# --- Visual Studio Marketplace ---
13+
if ($env:VS_MARKETPLACE_PAT) {
14+
if (-not $VsixPath) {
15+
$vsixFiles = Get-ChildItem -Path . -Filter "*.vsix" -Recurse -ErrorAction SilentlyContinue |
16+
Where-Object { $_.FullName -like "*TypeScriptDefinitionGenerator*" -and $_.FullName -notlike "*obj*" }
17+
$VsixPath = $vsixFiles | Sort-Object LastWriteTime -Descending | Select-Object -First 1 -ExpandProperty FullName
18+
}
19+
if ($VsixPath -and (Test-Path $VsixPath)) {
20+
Write-Host "Publishing to Visual Studio Marketplace..." -ForegroundColor Cyan
21+
$vsPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath 2>$null
22+
$vsixPublisher = Join-Path $vsPath "VSSDK\VisualStudioIntegration\Tools\Bin\VsixPublisher.exe"
23+
if (-not (Test-Path $vsixPublisher)) {
24+
$vsixPublisher = Join-Path $vsPath "Common7\IDE\Extensions\Microsoft\Vsix\VsixPublisher.exe"
25+
}
26+
if (Test-Path $vsixPublisher) {
27+
$publishManifest = Join-Path $PSScriptRoot "vs-publish.json"
28+
& $vsixPublisher publish -payload $VsixPath -publishManifest $publishManifest -personalAccessToken $env:VS_MARKETPLACE_PAT
29+
Write-Host "VS Marketplace: OK" -ForegroundColor Green
30+
} else {
31+
Write-Warning "VsixPublisher.exe not found. Install Visual Studio SDK workload."
32+
}
33+
} else {
34+
Write-Warning "VSIX file not found. Build the project first."
35+
}
36+
} else {
37+
Write-Host "VS_MARKETPLACE_PAT not set, skipping VS Marketplace" -ForegroundColor Yellow
38+
}
39+
40+
# --- JetBrains Marketplace ---
41+
if ($env:JETBRAINS_MARKETPLACE_TOKEN) {
42+
if (Test-Path $RiderZipPath) {
43+
Write-Host "Publishing to JetBrains Marketplace..." -ForegroundColor Cyan
44+
$xmlId = "com.typescriptdefinitiongenerator.rider"
45+
$riderPath = (Resolve-Path $RiderZipPath).Path
46+
$curlOut = & curl.exe -s -w "`n%{http_code}" -X POST `
47+
-H "Authorization: Bearer $env:JETBRAINS_MARKETPLACE_TOKEN" `
48+
-F "xmlId=$xmlId" `
49+
-F "file=@$riderPath" `
50+
"https://plugins.jetbrains.com/api/updates/upload" 2>&1
51+
$result = ($curlOut -split "`n")[-1]
52+
if ($result -eq "200" -or $result -eq "201") {
53+
Write-Host "JetBrains Marketplace: OK" -ForegroundColor Green
54+
} else {
55+
Write-Error "JetBrains upload failed (HTTP $result)"
56+
}
57+
} else {
58+
Write-Warning "Rider plugin zip not found: $RiderZipPath"
59+
}
60+
} else {
61+
Write-Host "JETBRAINS_MARKETPLACE_TOKEN not set, skipping JetBrains Marketplace" -ForegroundColor Yellow
62+
}

rider/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = "com.typescriptdefinitiongenerator"
8-
version = "1.0.0"
8+
version = project.findProperty("version") as String? ?: "1.0.0"
99

1010
repositories {
1111
mavenCentral()

0 commit comments

Comments
 (0)