Skip to content
Merged
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
14 changes: 7 additions & 7 deletions Aspire.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
<File Path="playground/README.md" />
<Project Path="playground/Playground.ServiceDefaults/Playground.ServiceDefaults.csproj" />
</Folder>
<Folder Name="/playground/AspireWithJavaScript/">
<Project Path="playground/AspireWithJavaScript/AspireJavaScript.AppHost/AspireJavaScript.AppHost.csproj" />
<Project Path="playground/AspireWithJavaScript/AspireJavaScript.MinimalApi/AspireJavaScript.MinimalApi.csproj" />
<Project Path="playground/AspireWithJavaScript/AspireJavaScript.ServiceDefaults/AspireJavaScript.ServiceDefaults.csproj" />
</Folder>
<Folder Name="/playground/AzureAIFoundryEndToEnd/">
<Project Path="playground/AzureAIFoundryEndToEnd/AzureAIFoundryEndToEnd.AppHost/AzureAIFoundryEndToEnd.AppHost.csproj" />
<Project Path="playground/AzureAIFoundryEndToEnd/AzureAIFoundryEndToEnd.WebStory/AzureAIFoundryEndToEnd.WebStory.csproj" />
Expand Down Expand Up @@ -176,8 +181,8 @@
<Project Path="playground/deployers/Deployers.AppHost/Deployers.AppHost.csproj" />
</Folder>
<Folder Name="/playground/DevTunnels/">
<Project Path="playground/DevTunnels/DevTunnels.AppHost/DevTunnels.AppHost.csproj" />
<Project Path="playground/DevTunnels/DevTunnels.ApiService/DevTunnels.ApiService.csproj" />
<Project Path="playground/DevTunnels/DevTunnels.AppHost/DevTunnels.AppHost.csproj" />
<Project Path="playground/DevTunnels/DevTunnels.WebFrontEnd/DevTunnels.WebFrontEnd.csproj" />
</Folder>
<Folder Name="/playground/dockerfile/">
Expand All @@ -199,11 +204,6 @@
<Folder Name="/playground/HealthChecks/">
<Project Path="playground/HealthChecks/HealthChecksSandbox.AppHost/HealthChecksSandbox.AppHost.csproj" />
</Folder>
<Folder Name="/playground/javascript/">
<Project Path="playground/AspireWithJavaScript/AspireJavaScript.AppHost/AspireJavaScript.AppHost.csproj" />
<Project Path="playground/AspireWithJavaScript/AspireJavaScript.MinimalApi/AspireJavaScript.MinimalApi.csproj" />
<Project Path="playground/AspireWithJavaScript/AspireJavaScript.ServiceDefaults/AspireJavaScript.ServiceDefaults.csproj" />
</Folder>
<Folder Name="/playground/kafka/">
<Project Path="playground/kafka/Consumer/Consumer.csproj" />
<Project Path="playground/kafka/KafkaBasic.AppHost/KafkaBasic.AppHost.csproj" />
Expand Down Expand Up @@ -234,8 +234,8 @@
</Folder>
<Folder Name="/playground/node/">
<Project Path="playground/AspireWithNode/AspireWithNode.AppHost/AspireWithNode.AppHost.csproj" />
<Project Path="playground/AspireWithNode/AspireWithNode.ServiceDefaults/AspireWithNode.ServiceDefaults.csproj" />
<Project Path="playground/AspireWithNode/AspireWithNode.AspNetCoreApi/AspireWithNode.AspNetCoreApi.csproj" />
<Project Path="playground/AspireWithNode/AspireWithNode.ServiceDefaults/AspireWithNode.ServiceDefaults.csproj" />
</Folder>
<Folder Name="/playground/OpenAIEndToEnd/">
<Project Path="playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/OpenAIEndToEnd.AppHost.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
var builder = DistributedApplication.CreateBuilder(args);
var builder = DistributedApplication.CreateBuilder(args);

var weatherApi = builder.AddProject<Projects.AspireJavaScript_MinimalApi>("weatherapi")
.WithExternalHttpEndpoints();

builder.AddNpmApp("angular", "../AspireJavaScript.Angular")
.WithNpmPackageManager()
.WithReference(weatherApi)
.WaitFor(weatherApi)
.WithHttpEndpoint(env: "PORT")
.WithExternalHttpEndpoints()
.PublishAsDockerFile();

builder.AddNpmApp("react", "../AspireJavaScript.React")
.WithNpmPackageManager()
.WithReference(weatherApi)
.WaitFor(weatherApi)
.WithEnvironment("BROWSER", "none") // Disable opening browser on npm start
Expand All @@ -19,17 +21,17 @@
.PublishAsDockerFile();

builder.AddNpmApp("vue", "../AspireJavaScript.Vue")
.WithNpmPackageManager()
.WithReference(weatherApi)
.WaitFor(weatherApi)
.WithHttpEndpoint(env: "PORT")
.WithExternalHttpEndpoints()
.PublishAsDockerFile();

builder.AddNpmApp("reactvite", "../AspireJavaScript.Vite")
builder.AddViteApp("reactvite", "../AspireJavaScript.Vite")
.WithNpmPackageManager()
.WithReference(weatherApi)
.WithEnvironment("BROWSER", "none")
.WithHttpEndpoint(env: "VITE_PORT")
.WithExternalHttpEndpoints()
.PublishAsDockerFile();
.WithExternalHttpEndpoints();

builder.Build().Run();
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,4 @@
<ProjectReference Include="..\AspireJavaScript.MinimalApi\AspireJavaScript.MinimalApi.csproj" />
</ItemGroup>

<Target Name="CheckNpmAvailable">
<CheckCommandAvailable Command="npm">
<Output TaskParameter="IsAvailable" PropertyName="IsNpmAvailable" />
</CheckCommandAvailable>
<Message Importance="Normal" Text="npm command is available: $(IsNpmAvailable)" />
<Warning Text="npm is not available on PATH. Node.js package installation will be skipped. Install Node.js and npm to enable full functionality." Condition="'$(IsNpmAvailable)' == 'false'" />
</Target>

<Target Name="RestoreNpm" BeforeTargets="Build" DependsOnTargets="CheckNpmAvailable" Condition="!('$(ContinuousIntegrationBuild)' == 'true') and '$(DesignTimeBuild)' != 'true' and '$(IsNpmAvailable)' == 'true' ">
<ItemGroup>
<PackageJsons Include="..\*\package.json" />
</ItemGroup>

<!-- Install npm packages if node_modules is missing -->
<Message Importance="Normal" Text="Installing npm packages for %(PackageJsons.RelativeDir)" Condition="!Exists('%(PackageJsons.RootDir)%(PackageJsons.Directory)/node_modules')" />
<Exec Command="npm install" WorkingDirectory="%(PackageJsons.RootDir)%(PackageJsons.Directory)" Condition="!Exists('%(PackageJsons.RootDir)%(PackageJsons.Directory)/node_modules')" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@
}
},
"angular": {
"type": "dockerfile.v0",
"path": "../AspireJavaScript.Angular/Dockerfile",
"context": "../AspireJavaScript.Angular",
"type": "container.v1",
"build": {
"context": "../AspireJavaScript.Angular",
"dockerfile": "../AspireJavaScript.Angular/Dockerfile"
},
"env": {
"NODE_ENV": "development",
"WEATHERAPI_HTTP": "{weatherapi.bindings.http.url}",
"services__weatherapi__http__0": "{weatherapi.bindings.http.url}",
"WEATHERAPI_HTTPS": "{weatherapi.bindings.https.url}",
"services__weatherapi__https__0": "{weatherapi.bindings.https.url}",
"PORT": "{angular.bindings.http.targetPort}"
},
Expand All @@ -47,12 +51,16 @@
}
},
"react": {
"type": "dockerfile.v0",
"path": "../AspireJavaScript.React/Dockerfile",
"context": "../AspireJavaScript.React",
"type": "container.v1",
"build": {
"context": "../AspireJavaScript.React",
"dockerfile": "../AspireJavaScript.React/Dockerfile"
},
"env": {
"NODE_ENV": "development",
"WEATHERAPI_HTTP": "{weatherapi.bindings.http.url}",
"services__weatherapi__http__0": "{weatherapi.bindings.http.url}",
"WEATHERAPI_HTTPS": "{weatherapi.bindings.https.url}",
"services__weatherapi__https__0": "{weatherapi.bindings.https.url}",
"BROWSER": "none",
"PORT": "{react.bindings.http.targetPort}"
Expand All @@ -68,12 +76,16 @@
}
},
"vue": {
"type": "dockerfile.v0",
"path": "../AspireJavaScript.Vue/Dockerfile",
"context": "../AspireJavaScript.Vue",
"type": "container.v1",
"build": {
"context": "../AspireJavaScript.Vue",
"dockerfile": "../AspireJavaScript.Vue/Dockerfile"
},
"env": {
"NODE_ENV": "development",
"WEATHERAPI_HTTP": "{weatherapi.bindings.http.url}",
"services__weatherapi__http__0": "{weatherapi.bindings.http.url}",
"WEATHERAPI_HTTPS": "{weatherapi.bindings.https.url}",
"services__weatherapi__https__0": "{weatherapi.bindings.https.url}",
"PORT": "{vue.bindings.http.targetPort}"
},
Expand All @@ -86,6 +98,31 @@
"external": true
}
}
},
"reactvite": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vhvb1989 this is what wil break azd, we're not deploying this resource but need to build it.

"type": "container.v1",
"build": {
"context": "../AspireJavaScript.Vite",
"dockerfile": "reactvite.Dockerfile"
},
"env": {
"NODE_ENV": "development",
"PORT": "{reactvite.bindings.http.targetPort}",
"WEATHERAPI_HTTP": "{weatherapi.bindings.http.url}",
"services__weatherapi__http__0": "{weatherapi.bindings.http.url}",
"WEATHERAPI_HTTPS": "{weatherapi.bindings.https.url}",
"services__weatherapi__https__0": "{weatherapi.bindings.https.url}",
"BROWSER": "none"
},
"bindings": {
"http": {
"scheme": "http",
"protocol": "tcp",
"transport": "http",
"targetPort": 8003,
"external": true
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:22-slim
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
23 changes: 0 additions & 23 deletions playground/AspireWithJavaScript/AspireJavaScript.Vite/Dockerfile

This file was deleted.

17 changes: 17 additions & 0 deletions src/Aspire.Hosting.NodeJs/JavaScriptPackageInstallerAnnotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.NodeJs;

/// <summary>
/// Represents an annotation for a JavaScript installer resource.
/// </summary>
public sealed class JavaScriptPackageInstallerAnnotation(ExecutableResource installerResource) : IResourceAnnotation
{
/// <summary>
/// The instance of the Installer resource used.
/// </summary>
public ExecutableResource Resource { get; } = installerResource;
}
39 changes: 39 additions & 0 deletions src/Aspire.Hosting.NodeJs/JavaScriptPackageManagerAnnotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.NodeJs;

/// <summary>
/// Represents the annotation for the JavaScript package manager used in a resource.
/// </summary>
/// <param name="packageManager">The name of the JavaScript package manager.</param>
public sealed class JavaScriptPackageManagerAnnotation(string packageManager) : IResourceAnnotation
{
/// <summary>
/// Gets the name of the JavaScript package manager.
/// </summary>
public string PackageManager { get; } = packageManager;

/// <summary>
/// Gets the command line arguments for the JavaScript package manager's install command.
/// </summary>
public string[] InstallCommandLineArgs { get; init; } = [];

/// <summary>
/// Gets the command line arguments for the JavaScript package manager's run command.
/// </summary>
public string[] RunCommandLineArgs { get; init; } = [];

/// <summary>
/// Gets a string value that separates the package manager command line args from the tool's command line args.
/// By default, this is "--".
/// </summary>
public string? CommandSeparator { get; init; } = "--";

/// <summary>
/// Gets the command line arguments for the JavaScript package manager's command that produces assets for distribution.
/// </summary>
public string[] BuildCommandLineArgs { get; init; } = [];
}
Loading