From b98af49c3753908760eed09d8279ad3d174a1e26 Mon Sep 17 00:00:00 2001 From: Luce Carter Date: Mon, 23 Mar 2026 16:35:11 +0000 Subject: [PATCH 1/2] Replace Postgres with MongoDB references in builder --- .../src/components/AppHostBuilder.astro | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/frontend/src/components/AppHostBuilder.astro b/src/frontend/src/components/AppHostBuilder.astro index 7f4d6fa69..27436d8e3 100644 --- a/src/frontend/src/components/AppHostBuilder.astro +++ b/src/frontend/src/components/AppHostBuilder.astro @@ -46,7 +46,7 @@ builder.Build().Run();`, databaseFrontendContainer: `var builder = DistributedApplication.CreateBuilder(args); // Add database -var postgres = builder.AddPostgres("db") +var mongodb = builder.AddMongoDB("db") .AddDatabase("appdata"); // Add frontend service @@ -90,12 +90,12 @@ builder.Build().Run();`, databaseApiFrontend: `var builder = DistributedApplication.CreateBuilder(args); // Add database -var postgres = builder.AddPostgres("db") +var mongodb = builder.AddMongoDB("db") .AddDatabase("appdata"); // Add API service and reference the database var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(postgres); + .WithReference(mongodb); // Add frontend service and reference the API var frontend = builder.AddViteApp("frontend", "../frontend") @@ -107,12 +107,12 @@ builder.Build().Run();`, databaseApiFrontendContainer: `var builder = DistributedApplication.CreateBuilder(args); // Add database -var postgres = builder.AddPostgres("db") +var mongodb = builder.AddMongoDB("db") .AddDatabase("appdata"); // Add API service and reference the database var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(postgres); + .WithReference(mongodb); // Add frontend service and reference the API var frontend = builder.AddViteApp("frontend", "../frontend") @@ -129,7 +129,7 @@ builder.Build().Run();`, database: `var builder = DistributedApplication.CreateBuilder(args); // Add database -var postgres = builder.AddPostgres("db") +var mongodb = builder.AddMongoDB("db") .AddDatabase("appdata"); builder.Build().Run();`, @@ -137,7 +137,7 @@ builder.Build().Run();`, databaseContainer: `var builder = DistributedApplication.CreateBuilder(args); // Add database -var postgres = builder.AddPostgres("db") +var mongodb = builder.AddMongoDB("db") .AddDatabase("appdata"); // Add custom container @@ -167,24 +167,24 @@ builder.Build().Run();`, databaseApi: `var builder = DistributedApplication.CreateBuilder(args); // Add database -var postgres = builder.AddPostgres("db") +var mongodb = builder.AddMongoDB("db") .AddDatabase("appdata"); // Add API service and reference the database var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(postgres); + .WithReference(mongodb); builder.Build().Run();`, databaseApiContainer: `var builder = DistributedApplication.CreateBuilder(args); // Add database -var postgres = builder.AddPostgres("db") +var mongodb = builder.AddMongoDB("db") .AddDatabase("appdata"); // Add API service and reference the database var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(postgres); + .WithReference(mongodb); // Add custom container var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") From cc5590512f1791236ce0f6709b4f74c8691a412e Mon Sep 17 00:00:00 2001 From: Luce Carter Date: Thu, 26 Mar 2026 20:03:21 +0000 Subject: [PATCH 2/2] Added randomised database selector --- .../src/components/AppHostBuilder.astro | 1276 ++--------------- 1 file changed, 132 insertions(+), 1144 deletions(-) diff --git a/src/frontend/src/components/AppHostBuilder.astro b/src/frontend/src/components/AppHostBuilder.astro index 9d177bdd3..d920e6ffc 100644 --- a/src/frontend/src/components/AppHostBuilder.astro +++ b/src/frontend/src/components/AppHostBuilder.astro @@ -1,1029 +1,135 @@ --- import { Code, Icon } from '@astrojs/starlight/components'; -// Define all possible code combinations — C# -const codes = { - empty: `var builder = DistributedApplication.CreateBuilder(args); - -// This would be a rather boring AppHost ☹️... -// Toggle the options above to see what an AppHost might look like. -// For example, select "Front end" to add a frontend service. - -builder.Build().Run();`, - - frontend: `var builder = DistributedApplication.CreateBuilder(args); - -// Add frontend service -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT"); - -builder.Build().Run();`, - - frontendContainer: `var builder = DistributedApplication.CreateBuilder(args); - -// Add frontend service -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT"); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080); - -builder.Build().Run();`, - - databaseFrontend: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var postgres = builder.AddPostgres("db") - .AddDatabase("appdata"); - -// Add frontend service -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT"); - -builder.Build().Run();`, - - databaseFrontendContainer: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var mongodb = builder.AddMongoDB("db") - .AddDatabase("appdata"); - -// Add frontend service -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT"); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080); - -builder.Build().Run();`, - - apiFrontend: `var builder = DistributedApplication.CreateBuilder(args); - -// Add API service -var api = builder.AddProject("api", "../api/ApiService.csproj"); - -// Add frontend service and reference the API -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithReference(api); - -builder.Build().Run();`, - - apiFrontendContainer: `var builder = DistributedApplication.CreateBuilder(args); - -// Add API service -var api = builder.AddProject("api", "../api/ApiService.csproj"); - -// Add frontend service and reference the API -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithReference(api); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080); - -builder.Build().Run();`, - - databaseApiFrontend: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var mongodb = builder.AddMongoDB("db") - .AddDatabase("appdata"); - -// Add API service and reference the database -var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(mongodb); - -// Add frontend service and reference the API -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithReference(api); - -builder.Build().Run();`, - - databaseApiFrontendContainer: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var mongodb = builder.AddMongoDB("db") - .AddDatabase("appdata"); - -// Add API service and reference the database -var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(mongodb); - -// Add frontend service and reference the API -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithReference(api); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080); - -builder.Build().Run();`, - - // Non-frontend variants - database: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var mongodb = builder.AddMongoDB("db") - .AddDatabase("appdata"); - -builder.Build().Run();`, - - databaseContainer: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var mongodb = builder.AddMongoDB("db") - .AddDatabase("appdata"); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080); - -builder.Build().Run();`, - - api: `var builder = DistributedApplication.CreateBuilder(args); - -// Add API service -var api = builder.AddProject("api", "../api/ApiService.csproj"); - -builder.Build().Run();`, - - apiContainer: `var builder = DistributedApplication.CreateBuilder(args); - -// Add API service -var api = builder.AddProject("api", "../api/ApiService.csproj"); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080); - -builder.Build().Run();`, - - databaseApi: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var mongodb = builder.AddMongoDB("db") - .AddDatabase("appdata"); - -// Add API service and reference the database -var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(mongodb); - -builder.Build().Run();`, - - databaseApiContainer: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var mongodb = builder.AddMongoDB("db") - .AddDatabase("appdata"); - -// Add API service and reference the database -var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(mongodb); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080); - -builder.Build().Run();`, - - container: `var builder = DistributedApplication.CreateBuilder(args); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080); - -builder.Build().Run();`, - - // Deployment variants - frontendDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add frontend service -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithNpmPackageInstallation() - .PublishAsDockerFile(); - -builder.Build().Run();`, - - frontendContainerDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add frontend service -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithNpmPackageInstallation() - .PublishAsDockerFile(); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080) - .PublishAsKubernetes(); - -builder.Build().Run();`, - - databaseFrontendDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var postgres = builder.AddAzurePostgresFlexibleServer("db") - .AddDatabase("appdata") - .WithDataVolume() - .RunAsContainer(); - -// Add frontend service -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithNpmPackageInstallation() - .PublishAsDockerFile(); - -builder.Build().Run();`, - - databaseFrontendContainerDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var postgres = builder.AddAzurePostgresFlexibleServer("db") - .AddDatabase("appdata") - .WithDataVolume() - .RunAsContainer(); - -// Add frontend service -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithNpmPackageInstallation() - .PublishAsDockerFile(); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080) - .PublishAsKubernetes(); - -builder.Build().Run();`, - - apiFrontendDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add API service -var api = builder.AddProject("api", "../api/ApiService.csproj") - .PublishAsAzureContainerApp(); - -// Add frontend service and reference the API -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithReference(api) - .WithNpmPackageInstallation() - .PublishAsDockerFile(); - -builder.Build().Run();`, - - apiFrontendContainerDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add API service -var api = builder.AddProject("api", "../api/ApiService.csproj") - .PublishAsAzureContainerApp(); - -// Add frontend service and reference the API -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithReference(api) - .WithNpmPackageInstallation() - .PublishAsDockerFile(); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080) - .PublishAsKubernetes(); - -builder.Build().Run();`, - - databaseApiFrontendDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var postgres = builder.AddAzurePostgresFlexibleServer("db") - .AddDatabase("appdata") - .WithDataVolume() - .RunAsContainer(); - -// Add API service and reference the database -var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(postgres) - .WaitFor(postgres) - .PublishAsAzureContainerApp(); - -// Add frontend service and reference the API -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithReference(api) - .WithNpmPackageInstallation() - .PublishAsDockerFile(); - -builder.Build().Run();`, - - databaseApiFrontendContainerDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var postgres = builder.AddAzurePostgresFlexibleServer("db") - .AddDatabase("appdata") - .WithDataVolume() - .RunAsContainer(); - -// Add API service and reference the database -var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(postgres) - .WaitFor(postgres) - .PublishAsAzureContainerApp(); - -// Add frontend service and reference the API -var frontend = builder.AddViteApp("frontend", "../frontend") - .WithHttpEndpoint(env: "PORT") - .WithReference(api) - .WithNpmPackageInstallation() - .PublishAsDockerFile(); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080) - .PublishAsKubernetes(); - -builder.Build().Run();`, - - // Non-frontend deployment variants - databaseDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var postgres = builder.AddAzurePostgresFlexibleServer("db") - .AddDatabase("appdata") - .WithDataVolume() - .RunAsContainer(); - -builder.Build().Run();`, - - databaseContainerDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var postgres = builder.AddAzurePostgresFlexibleServer("db") - .AddDatabase("appdata") - .WithDataVolume() - .RunAsContainer(); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080) - .PublishAsKubernetes(); - -builder.Build().Run();`, - - apiDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add API service -var api = builder.AddProject("api", "../api/ApiService.csproj") - .PublishAsAzureContainerApp(); - -builder.Build().Run();`, - - apiContainerDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add API service -var api = builder.AddProject("api", "../api/ApiService.csproj") - .PublishAsAzureContainerApp(); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080) - .PublishAsKubernetes(); - -builder.Build().Run();`, - - databaseApiDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var postgres = builder.AddAzurePostgresFlexibleServer("db") - .AddDatabase("appdata") - .WithDataVolume() - .RunAsContainer(); - -// Add API service and reference the database -var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(postgres) - .WaitFor(postgres) - .PublishAsAzureContainerApp(); - -builder.Build().Run();`, - - databaseApiContainerDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add database -var postgres = builder.AddAzurePostgresFlexibleServer("db") - .AddDatabase("appdata") - .WithDataVolume() - .RunAsContainer(); - -// Add API service and reference the database -var api = builder.AddProject("api", "../api/ApiService.csproj") - .WithReference(postgres) - .WaitFor(postgres) - .PublishAsAzureContainerApp(); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080) - .PublishAsKubernetes(); - -builder.Build().Run();`, - - containerDeployment: `var builder = DistributedApplication.CreateBuilder(args); - -// Add custom container -var customContainer = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest") - .WithHttpEndpoint(targetPort: 8080) - .PublishAsKubernetes(); - -builder.Build().Run();`, +const databaseProviders = { + postgres: { + name: 'PostgreSQL', + ref: 'postgres', + cs: { + local: `var postgres = builder.AddPostgres("db").AddDatabase("appdata");`, + deploy: `var postgres = builder.AddAzurePostgresFlexibleServer("db")\n .AddDatabase("appdata");`, + }, + ts: { + local: `const postgres = builder.addPostgres('db').addDatabase('appdata');`, + deploy: `const postgres = builder.addAzurePostgres('db')\n .addDatabase('appdata');`, + } + }, + mongodb: { + name: 'MongoDB', + ref: 'mongodb', + cs: { + local: `var mongodb = builder.AddMongoDB("db").AddDatabase("appdata");`, + deploy: `var mongodb = builder.AddMongoDB("db").AddDatabase("appdata");`, + }, + ts: { + local: `const mongodb = builder.addMongoDB('db').addDatabase('appdata');`, + deploy: `const mongodb = builder.addMongoDB('db').addDatabase('appdata');`, + } + }, + redis: { + name: 'Redis', + ref: 'cache', + cs: { + local: `var cache = builder.AddRedis("cache");`, + deploy: `var cache = builder.AddAzureRedis("cache");`, + }, + ts: { + local: `const cache = builder.addRedis('cache');`, + deploy: `const cache = builder.addAzureRedis('cache');`, + } + }, + sqlserver: { + name: 'SQL Server', + ref: 'sql', + cs: { + local: `var sql = builder.AddSqlServer("sql").AddDatabase("sqldata");`, + deploy: `var sql = builder.AddAzureSqlServer("sql").AddDatabase("sqldata");`, + }, + ts: { + local: `const sql = builder.addSqlServer('sql').addDatabase('sqldata');`, + deploy: `const sql = builder.addAzureSqlServer('sql').addDatabase('sqldata');`, + } + } }; -// Define all possible code combinations — TypeScript -const tsCodes: Record = { - empty: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// This would be a rather boring AppHost ☹️... -// Toggle the options above to see what an AppHost might look like. -// For example, select "Front end" to add a frontend service. - -await builder.build().run();`, - - frontend: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Vite frontend -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }); - -await builder.build().run();`, - - frontendContainer: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Vite frontend -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }); - -await builder.build().run();`, - - databaseFrontend: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addPostgres("db") - .addDatabase("appdata"); - -// Add Vite frontend -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }); - -await builder.build().run();`, - - databaseFrontendContainer: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); +const providerKeys = Object.keys(databaseProviders) as (keyof typeof databaseProviders)[]; +const dbKey = providerKeys[Math.floor(Math.random() * providerKeys.length)]; +const db = databaseProviders[dbKey]; -// Add database -const postgres = await builder - .addPostgres("db") - .addDatabase("appdata"); +function generateCode(lang: 'cs' | 'ts', flags: { db: boolean, api: boolean, fe: boolean, con: boolean, dep: boolean }) { + const isTS = lang === 'ts'; + const lines = isTS + ? [`import { createBuilder } from './.modules/aspire.js';`, `const builder = await createBuilder();`, ``] + : [`var builder = DistributedApplication.CreateBuilder(args);`, ``]; -// Add Vite frontend -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }); - -await builder.build().run();`, - - apiFrontend: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Express API -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }); - -// Add Vite frontend and reference the API -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withReference(api); - -await builder.build().run();`, - - apiFrontendContainer: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Express API -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }); - -// Add Vite frontend and reference the API -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withReference(api); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }); - -await builder.build().run();`, - - databaseApiFrontend: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addPostgres("db") - .addDatabase("appdata"); - -// Add Express API and reference the database -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .withReference(postgres); - -// Add Vite frontend and reference the API -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withReference(api); - -await builder.build().run();`, - - databaseApiFrontendContainer: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addPostgres("db") - .addDatabase("appdata"); - -// Add Express API and reference the database -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .withReference(postgres); - -// Add Vite frontend and reference the API -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withReference(api); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }); - -await builder.build().run();`, - - database: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addPostgres("db") - .addDatabase("appdata"); - -await builder.build().run();`, - - databaseContainer: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addPostgres("db") - .addDatabase("appdata"); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }); - -await builder.build().run();`, - - api: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Express API -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }); - -await builder.build().run();`, - - apiContainer: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Express API -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }); - -await builder.build().run();`, - - databaseApi: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addPostgres("db") - .addDatabase("appdata"); - -// Add Express API and reference the database -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .withReference(postgres); - -await builder.build().run();`, - - databaseApiContainer: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addPostgres("db") - .addDatabase("appdata"); - -// Add Express API and reference the database -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .withReference(postgres); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }); - -await builder.build().run();`, - - container: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }); - -await builder.build().run();`, - - frontendDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Vite frontend -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withNpmPackageInstallation() - .publishAsDockerFile(); - -await builder.build().run();`, - - frontendContainerDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Vite frontend -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withNpmPackageInstallation() - .publishAsDockerFile(); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }) - .publishAsKubernetes(); - -await builder.build().run();`, - - databaseFrontendDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addAzurePostgresFlexibleServer("db") - .addDatabase("appdata") - .withDataVolume() - .runAsContainer(); - -// Add Vite frontend -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withNpmPackageInstallation() - .publishAsDockerFile(); - -await builder.build().run();`, - - databaseFrontendContainerDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addAzurePostgresFlexibleServer("db") - .addDatabase("appdata") - .withDataVolume() - .runAsContainer(); - -// Add Vite frontend -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withNpmPackageInstallation() - .publishAsDockerFile(); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }) - .publishAsKubernetes(); - -await builder.build().run();`, - - apiFrontendDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Express API -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .publishAsAzureContainerApp(); - -// Add Vite frontend and reference the API -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withReference(api) - .withNpmPackageInstallation() - .publishAsDockerFile(); - -await builder.build().run();`, - - apiFrontendContainerDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Express API -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .publishAsAzureContainerApp(); - -// Add Vite frontend and reference the API -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withReference(api) - .withNpmPackageInstallation() - .publishAsDockerFile(); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }) - .publishAsKubernetes(); - -await builder.build().run();`, - - databaseApiFrontendDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addAzurePostgresFlexibleServer("db") - .addDatabase("appdata") - .withDataVolume() - .runAsContainer(); - -// Add Express API and reference the database -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .withReference(postgres) - .waitFor(postgres) - .publishAsAzureContainerApp(); - -// Add Vite frontend and reference the API -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withReference(api) - .withNpmPackageInstallation() - .publishAsDockerFile(); - -await builder.build().run();`, - - databaseApiFrontendContainerDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addAzurePostgresFlexibleServer("db") - .addDatabase("appdata") - .withDataVolume() - .runAsContainer(); - -// Add Express API and reference the database -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .withReference(postgres) - .waitFor(postgres) - .publishAsAzureContainerApp(); - -// Add Vite frontend and reference the API -const frontend = await builder - .addViteApp("frontend", "./frontend") - .withHttpEndpoint({ env: "PORT" }) - .withReference(api) - .withNpmPackageInstallation() - .publishAsDockerFile(); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }) - .publishAsKubernetes(); - -await builder.build().run();`, - - databaseDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addAzurePostgresFlexibleServer("db") - .addDatabase("appdata") - .withDataVolume() - .runAsContainer(); - -await builder.build().run();`, - - databaseContainerDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addAzurePostgresFlexibleServer("db") - .addDatabase("appdata") - .withDataVolume() - .runAsContainer(); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }) - .publishAsKubernetes(); - -await builder.build().run();`, - - apiDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Express API -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .publishAsAzureContainerApp(); - -await builder.build().run();`, - - apiContainerDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add Express API -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .publishAsAzureContainerApp(); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }) - .publishAsKubernetes(); - -await builder.build().run();`, - - databaseApiDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addAzurePostgresFlexibleServer("db") - .addDatabase("appdata") - .withDataVolume() - .runAsContainer(); - -// Add Express API and reference the database -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .withReference(postgres) - .waitFor(postgres) - .publishAsAzureContainerApp(); - -await builder.build().run();`, - - databaseApiContainerDeployment: `import { createBuilder } from './.modules/aspire.js'; - -const builder = await createBuilder(); - -// Add database -const postgres = await builder - .addAzurePostgresFlexibleServer("db") - .addDatabase("appdata") - .withDataVolume() - .runAsContainer(); - -// Add Express API and reference the database -const api = await builder - .addNodeApp("api", "./api", "src/index.ts") - .withHttpEndpoint({ env: "PORT" }) - .withReference(postgres) - .waitFor(postgres) - .publishAsAzureContainerApp(); - -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }) - .publishAsKubernetes(); - -await builder.build().run();`, + if (flags.db) { + lines.push(`// Add ${db.name}`, flags.dep ? db[lang].deploy : db[lang].local, ``); + } - containerDeployment: `import { createBuilder } from './.modules/aspire.js'; + if (flags.api) { + lines.push(`// Add API service${flags.db ? ' and reference the database' : ''}`); + let api = isTS + ? `const api = builder.addNodeApp("api", "./api", "src/index.ts")\n .withHttpEndpoint({ env: "PORT" })` + : `var api = builder.AddProject("api", "../api/ApiService.csproj")`; + if (flags.db) api += `\n .${isTS ? 'withReference' : 'WithReference'}(${db.ref})`; + if (flags.dep) api += `\n .${isTS ? 'publishAsAzureContainerApp' : 'PublishAsAzureContainerApp'}()`; + lines.push(api + ';', ''); + } -const builder = await createBuilder(); + if (flags.fe) { + lines.push(`// Add frontend service${flags.api ? ' and reference the API' : ''}`); + let fe = isTS + ? `const frontend = builder.addViteApp("frontend", "./frontend")\n .withHttpEndpoint({ env: "PORT" })` + : `var frontend = builder.AddViteApp("frontend", "../frontend")\n .WithHttpEndpoint(env: "PORT")`; + if (flags.api) fe += `\n .${isTS ? 'withReference' : 'WithReference'}(api)`; + if (flags.dep) fe += `\n .${isTS ? 'withNpmPackageInstallation().publishAsDockerFile' : 'WithNpmPackageInstallation().PublishAsDockerFile'}()`; + lines.push(fe + ';', ''); + } -// Add custom container -const customContainer = await builder - .addContainer("mycustomcontainer", "myregistry/myapp", "latest") - .withHttpEndpoint({ targetPort: 8080 }) - .publishAsKubernetes(); + if (flags.con) { + lines.push(`// Add custom container`); + let con = isTS + ? `const container = builder.addContainer("mycustomcontainer", "myregistry/myapp", "latest")\n .withHttpEndpoint({ targetPort: 8080 })` + : `var container = builder.AddContainer("mycustomcontainer", "myregistry/myapp", "latest")\n .WithHttpEndpoint(targetPort: 8080)`; + if (flags.dep) con += `\n .${isTS ? 'publishAsKubernetes' : 'PublishAsKubernetes'}()`; + lines.push(con + ';', ''); + } -await builder.build().run();`, + if (!flags.fe && !flags.db && !flags.api && !flags.con) { + lines.push(`// This would be a rather boring AppHost ☹️...`, `// Toggle the options above to see code examples.`, ``); + } -}; + lines.push(isTS ? `await builder.build().run();` : `builder.Build().Run();`); + return lines.join('\n'); +} + +// Pre-generate all combinations (32 per language) +const combinations: string[] = []; +for (let i = 0; i < 32; i++) { + const flags = { + fe: !!(i & 1), + db: !!(i & 2), + api: !!(i & 4), + con: !!(i & 8), + dep: !!(i & 16) + }; + let key = ''; + if (flags.db) key += 'database'; + if (flags.api) key += 'Api'; + if (flags.fe) key += 'Frontend'; + if (flags.con) key += 'Container'; + if (flags.dep) key += 'Deployment'; + combinations.push(key || 'empty'); +} + +const codes: Record = {}; +const tsCodes: Record = {}; + +combinations.forEach((variantKey, index) => { + const flags = { fe: !!(index & 1), db: !!(index & 2), api: !!(index & 4), con: !!(index & 8), dep: !!(index & 16) }; + codes[variantKey] = generateCode('cs', flags); + tsCodes[variantKey] = generateCode('ts', flags); +}); ---
@@ -1097,104 +203,16 @@ await builder.build().run();`,
- -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {Object.entries(codes).map(([key, code]) => ( +
+ +
+ ))}