Class JavaScriptHostingExtensions
- Namespace
- Aspire.Hosting
- Assembly
- IEvangelist.Aspire.Hosting.Netlify.dll
public static class JavaScriptHostingExtensions
- Inheritance
-
JavaScriptHostingExtensions
- Inherited Members
Methods
PublishAsNetlifySite(IResourceBuilder<JavaScriptAppResource>, NetlifyDeployOptions, IResourceBuilder<ParameterResource>?)
Configures the JavaScript app for deployment to Netlify using the Netlify CLI. Use together with AddNetlifyDeployPipeline(IDistributedApplicationPipeline). When that pipeline is added and this method is applied, the app is deployed with the provided options.
[AspireExport(MethodName = "publishAsNetlifySite", Description = "Configures the JavaScript app to deploy to Netlify with the supplied options.")]
public static IResourceBuilder<JavaScriptAppResource> PublishAsNetlifySite(this IResourceBuilder<JavaScriptAppResource> builder, NetlifyDeployOptions options, IResourceBuilder<ParameterResource>? authToken = null)
Parameters
builderIResourceBuilder<JavaScriptAppResource>The JavaScript app resource builder.
optionsNetlifyDeployOptionsThe Netlify deployment options.
authTokenIResourceBuilder<ParameterResource>An optional parameter resource containing the Netlify authentication token.
Returns
- IResourceBuilder<JavaScriptAppResource>
A reference to the Aspire.Hosting.ApplicationModel.IResourceBuilder<T>.
Exceptions
- InvalidOperationException
Thrown if the Netlify CLI is not installed or not found in PATH.
PublishAsNetlifySite(IResourceBuilder<JavaScriptAppResource>, string, IResourceBuilder<ParameterResource>?)
Configures the JavaScript app for deployment to Netlify by publishing a prebuilt directory.
[AspireExportIgnore]
public static IResourceBuilder<JavaScriptAppResource> PublishAsNetlifySite(this IResourceBuilder<JavaScriptAppResource> builder, string dir, IResourceBuilder<ParameterResource>? authToken = null)
Parameters
builderIResourceBuilder<JavaScriptAppResource>The JavaScript app resource builder.
dirstringThe directory containing the prebuilt site to deploy (e.g.,
"dist","build",".next"). Resolved relative to the JavaScript app's working directory.authTokenIResourceBuilder<ParameterResource>An optional parameter resource containing the Netlify authentication token.
Returns
- IResourceBuilder<JavaScriptAppResource>
A reference to the Aspire.Hosting.ApplicationModel.IResourceBuilder<T>.
Examples
builder.AddJavaScriptApp("astro-site", "../astro")
.WithNpmRunCommand("build")
.PublishAsNetlifySite("dist");
Remarks
This is a convenience overload for the most common scenario: the JavaScript app produces a static
build output and you want Netlify to upload it as-is. It forwards to
PublishAsNetlifySite(IResourceBuilder<JavaScriptAppResource>, NetlifyDeployOptions, IResourceBuilder<ParameterResource>?)
with NoBuild = true and Dir = dir. For full control over deployment options
(site, alias, message, prod, environment-context, etc.), use that overload directly.
Pair with WithNpmRunCommand(IResourceBuilder<JavaScriptAppResource>, string)
(e.g., WithNpmRunCommand("build")) to ensure the prebuilt directory exists before
deployment runs in the pipeline.
WithNpmCommand(IResourceBuilder<JavaScriptAppResource>, string)
Configures the JavaScript app to run an arbitrary npm command before starting.
[AspireExport(MethodName = "withNpmCommand", Description = "Runs an npm command before the app starts.")]
public static IResourceBuilder<JavaScriptAppResource> WithNpmCommand(this IResourceBuilder<JavaScriptAppResource> builder, string args)
Parameters
builderIResourceBuilder<JavaScriptAppResource>The JavaScript app resource builder.
argsstringThe npm command arguments (e.g., "i", "run build:production", "ci --legacy-peer-deps").
Returns
- IResourceBuilder<JavaScriptAppResource>
A reference to the Aspire.Hosting.ApplicationModel.IResourceBuilder<T>.
Remarks
This method allows you to run any npm command before the app starts. For example:
builder.AddJavaScriptApp("myapp", "../myapp")
.WithNpmCommand("i") // npm i
.WithNpmCommand("run build:production"); // npm run build:production
WithNpmCommand(IResourceBuilder<JavaScriptAppResource>, string, Action<IResourceBuilder<NpmCommandResource>>?)
Configures the JavaScript app to run an arbitrary npm command before starting, with a callback to further configure the resulting NpmCommandResource.
[AspireExportIgnore]
public static IResourceBuilder<JavaScriptAppResource> WithNpmCommand(this IResourceBuilder<JavaScriptAppResource> builder, string args, Action<IResourceBuilder<NpmCommandResource>>? configureRunner)
Parameters
builderIResourceBuilder<JavaScriptAppResource>The JavaScript app resource builder.
argsstringThe npm command arguments (e.g., "i", "run build:production", "ci --legacy-peer-deps").
configureRunnerAction<IResourceBuilder<NpmCommandResource>>Configure the npm runner resource.
Returns
- IResourceBuilder<JavaScriptAppResource>
A reference to the Aspire.Hosting.ApplicationModel.IResourceBuilder<T>.
Remarks
This overload accepts a synchronous Action<T> callback that runs inline at AppHost
build time, which is not modeled by the Aspire Type System and therefore not exported to
non-C# AppHosts. From a TypeScript AppHost, use the no-callback overload of withNpmCommand
and configure additional runner state via the underlying npmCommandResource APIs.
WithNpmRunCommand(IResourceBuilder<JavaScriptAppResource>, string)
Configures the JavaScript app to run an npm script before starting.
[AspireExport(MethodName = "withNpmRunCommand", Description = "Runs an npm script (e.g., 'build') before the app starts.")]
public static IResourceBuilder<JavaScriptAppResource> WithNpmRunCommand(this IResourceBuilder<JavaScriptAppResource> builder, string scriptName)
Parameters
builderIResourceBuilder<JavaScriptAppResource>The JavaScript app resource builder.
scriptNamestringThe npm script name to run (e.g., "build", "test", "lint").
Returns
- IResourceBuilder<JavaScriptAppResource>
A reference to the Aspire.Hosting.ApplicationModel.IResourceBuilder<T>.
WithNpmRunCommand(IResourceBuilder<JavaScriptAppResource>, string, Action<IResourceBuilder<NpmCommandResource>>?)
Configures the JavaScript app to run an npm script before starting, with a callback to further configure the resulting NpmCommandResource.
[AspireExportIgnore]
public static IResourceBuilder<JavaScriptAppResource> WithNpmRunCommand(this IResourceBuilder<JavaScriptAppResource> builder, string scriptName, Action<IResourceBuilder<NpmCommandResource>>? configureRunner)
Parameters
builderIResourceBuilder<JavaScriptAppResource>The JavaScript app resource builder.
scriptNamestringThe npm script name to run (e.g., "build", "test", "lint").
configureRunnerAction<IResourceBuilder<NpmCommandResource>>Configure the npm runner resource.
Returns
- IResourceBuilder<JavaScriptAppResource>
A reference to the Aspire.Hosting.ApplicationModel.IResourceBuilder<T>.
Remarks
This overload accepts a synchronous Action<T> callback that runs inline at AppHost
build time, which is not modeled by the Aspire Type System and therefore not exported to
non-C# AppHosts. From a TypeScript AppHost, use the no-callback overload of withNpmRunCommand.