@typespec/http-server-csharp
Version:
TypeSpec service code generator for c-sharp
101 lines (98 loc) • 2.68 kB
JavaScript
import { LibrarySourceFile } from "./interfaces.js";
export function getProjectHelpers(emitter, projectName, useSwaggerUI, httpPort, httpsPort) {
const result = [
new LibrarySourceFile({
filename: `${projectName}.csproj`,
emitter: emitter,
getContents: () => getProjectFile(useSwaggerUI),
path: ".",
conditional: true,
}),
new LibrarySourceFile({
filename: "appsettings.json",
emitter: emitter,
getContents: getAppSettings,
path: ".",
conditional: true,
}),
new LibrarySourceFile({
filename: "appsettings.Development.json",
emitter: emitter,
getContents: getDeveloperAppSettings,
path: ".",
conditional: true,
}),
new LibrarySourceFile({
filename: "launchSettings.json",
emitter: emitter,
getContents: () => getLaunchSettings(httpPort, httpsPort),
path: "Properties",
conditional: true,
}),
];
return result;
}
function getProjectFile(useSwaggerUI) {
return `<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
${useSwaggerUI
? ` <ItemGroup>
<PackageReference Include="SwashBuckle.AspNetCore" Version="7.3.1" />
</ItemGroup>`
: ""}
</Project>
`;
}
function getAppSettings() {
return `{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
`;
}
function getDeveloperAppSettings() {
return `{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
`;
}
function getLaunchSettings(httpPort, httpsPort) {
return `{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:${httpsPort};http://localhost:${httpPort}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:${httpPort}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}`;
}
//# sourceMappingURL=project.js.map