Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(import): csharp support #2519

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cli/cmds/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { parseImports } from '../../util';
const config = readConfigSync();

const DEFAULT_OUTDIR = 'imports';
const LANGUAGES = ['typescript', 'python', 'java', 'go'];
const LANGUAGES = ['csharp', 'typescript', 'python', 'java', 'go'];

class Command implements yargs.CommandModule {
public readonly command = 'import [SPEC]';
Expand Down
11 changes: 10 additions & 1 deletion src/import/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { mkdtemp } from '../util';
export enum Language {
TYPESCRIPT = 'typescript',
PYTHON = 'python',
DOTNET = 'dotnet',
CSHARP = 'csharp',
JAVA = 'java',
GO = 'go',
}
Expand Down Expand Up @@ -145,6 +145,15 @@ export abstract class ImportBase {
};
}

// csharp!
if (options.targetLanguage === Language.CSHARP) {
const csharpName = module.name.replace(/\//g, '.').replace(/-/g, '_').replace(/(?:^|_)([a-z])/g, (_, char) => char.toUpperCase());
opts.csharp = {
outdir: outdir,
namespace: `Imports.${moduleNamePrefix ? moduleNamePrefix + '.' + csharpName : csharpName}`,
};
}

await srcmak.srcmak(staging, opts);
});
}
Expand Down
24 changes: 24 additions & 0 deletions templates/csharp-app/MyApp/Cdk8s.Imports/Cdk8s.Imports.esproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.VisualStudio.JavaScript.Sdk/1.0.586930">

<PropertyGroup>
<BuildCommand>npm run import</BuildCommand>
<SolutionPath>$(SolutionDir)MyApp.sln</SolutionPath>
</PropertyGroup>

<Target Name="RemoveProjectsFromSolution" BeforeTargets="Build">
<ItemGroup>
<ProjectFiles Include="$(SolutionDir)Imports\Imports.*\**\*.csproj" />
</ItemGroup>

<Exec Command="dotnet sln $(SolutionPath) remove @(ProjectFiles -> '&quot;%(FullPath)&quot;', ' ')" />
</Target>

<Target Name="AddProjectsToSolution" AfterTargets="Build">
<ItemGroup>
<ProjectFiles Include="$(SolutionDir)Imports\Imports.*\**\*.csproj" />
</ItemGroup>

<Exec Command="dotnet sln $(SolutionPath) add @(ProjectFiles -> '&quot;%(FullPath)&quot;', ' ')" />
</Target>

</Project>
3 changes: 3 additions & 0 deletions templates/csharp-app/MyApp/Cdk8s.Imports/cdk8s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: csharp
imports:
- k8s
11 changes: 11 additions & 0 deletions templates/csharp-app/MyApp/Cdk8s.Imports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "imports",
"version": "0.0.1",
"private": true,
"scripts": {
"import": "cdk8s import -o ../Imports"
},
"dependencies": {
"cdk8s-cli": "{{ cdk8s_cli_spec }}"
}
}
Empty file.
23 changes: 23 additions & 0 deletions templates/csharp-app/MyApp/MyApp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Microsoft Visual Studio Solution File, Format Version 12.00
#
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyApp", "MyApp\MyApp.csproj", "{D0E5713E-D58F-482D-92C0-504C9AB84DD5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cdk8s.Imports", "Cdk8s.Imports\Cdk8s.Imports.esproj", "{5337F2AB-8B52-48F8-9AA5-0DC7CEFAF8A4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D0E5713E-D58F-482D-92C0-504C9AB84DD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D0E5713E-D58F-482D-92C0-504C9AB84DD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0E5713E-D58F-482D-92C0-504C9AB84DD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0E5713E-D58F-482D-92C0-504C9AB84DD5}.Release|Any CPU.Build.0 = Release|Any CPU
{5337F2AB-8B52-48F8-9AA5-0DC7CEFAF8A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5337F2AB-8B52-48F8-9AA5-0DC7CEFAF8A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5337F2AB-8B52-48F8-9AA5-0DC7CEFAF8A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5337F2AB-8B52-48F8-9AA5-0DC7CEFAF8A4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

18 changes: 18 additions & 0 deletions templates/csharp-app/MyApp/MyApp/MyApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Imports\Imports.*\**\*.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Org.Cdk8s" Version="{{ cdk8s_core_version }}" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions templates/csharp-app/MyApp/MyApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Constructs;
using Org.Cdk8s;

var app = new App();
_ = new Main(app, "{{ $base }}");

app.Synth();

public class Main(Construct scope, string id, IChartProps? props = null) : Chart(scope, id, props);
8 changes: 8 additions & 0 deletions test/integ/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ test('python-app-npm', () => {
init('python-app', cliNpmdir);
});

test('csharp-app-npm', () => {
init('csharp-app', cliNpmdir);
});

test('typescript-app-yarn', () => {
init('typescript-app', cliYarndir);
});
Expand All @@ -57,6 +61,10 @@ test('python-app-yarn', () => {
init('python-app', cliYarndir);
});

test('csharp-app-yarn', () => {
init('csharp-app', cliYarndir);
});

function init(template: string, clidir: string) {

const workdir = mkdtempSync(join(tmpdir(), 'cdk8s-init-test-'));
Expand Down