diff --git a/www/.gitignore b/www/.gitignore index cd64426f6..013332f2d 100644 --- a/www/.gitignore +++ b/www/.gitignore @@ -28,3 +28,5 @@ sdk-doc.json # generated docs src/content/docs/docs/component/ +src/content/docs/docs/reference/ +!src/content/docs/docs/reference/sdk.mdx diff --git a/www/generate.ts b/www/generate.ts index bf4975fc6..edf150ab6 100644 --- a/www/generate.ts +++ b/www/generate.ts @@ -319,8 +319,7 @@ async function generateExamplesDocs() { renderTdComment(module.children![0].comment?.summary!), ...renderRunFunction(module), ``, - `View the [full example](${config.github}/tree/dev/examples/${ - module.name.split("/")[0] + `View the [full example](${config.github}/tree/dev/examples/${module.name.split("/")[0] }).`, ``, ]; @@ -416,6 +415,9 @@ async function generateDnsDoc(module: TypeDoc.DeclarationReflection) { vercel: "Vercel", }[dnsProvider] || dnsProvider; + const dir = path.dirname(outputFilePath); + fs.mkdirSync(dir, { recursive: true }); + fs.writeFileSync( outputFilePath, [ @@ -456,6 +458,9 @@ async function generateLinkableDoc(module: TypeDoc.DeclarationReflection) { }, }[module.name]!; + const dir = path.dirname(outputFilePath); + fs.mkdirSync(dir, { recursive: true }); + fs.writeFileSync( outputFilePath, [ @@ -497,6 +502,9 @@ async function generateComponentDoc( `${component.name.split("/").slice(1).join("/")}.mdx` ); + const dir = path.dirname(outputFilePath); + fs.mkdirSync(dir, { recursive: true }); + fs.writeFileSync( outputFilePath, [ @@ -524,23 +532,23 @@ async function generateComponentDoc( : []), ...(sdk ? renderFunctions( - sdk, - useModuleFunctions(sdk), - sdk.name === "realtime" ? { prefix: sdk.name } : undefined - ) + sdk, + useModuleFunctions(sdk), + sdk.name === "realtime" ? { prefix: sdk.name } : undefined + ) : []), ...(sdk ? renderInterfacesAtH3Level(sdk) : []), ]; return lines.length ? [ - ``, - `## SDK`, - ``, - `Use the [SDK](/docs/reference/sdk/) in your runtime to interact with your infrastructure.`, - ``, - `---`, - ...lines, - ] + ``, + `## SDK`, + ``, + `Use the [SDK](/docs/reference/sdk/) in your runtime to interact with your infrastructure.`, + ``, + `---`, + ...lines, + ] : []; })(), renderMethods(component), @@ -688,8 +696,8 @@ function renderType( function renderArrayType(type: TypeDoc.ArrayType) { return type.elementType.type === "union" ? `(${renderSomeType( - type.elementType - )})[]` + type.elementType + )})[]` : `${renderSomeType(type.elementType)}[]`; } function renderTypescriptType(type: TypeDoc.ReferenceType) { @@ -759,9 +767,8 @@ function renderType( } // types in the same doc (links to an interface) if (useModuleInterfaces(module).find((i) => i.name === type.name)) { - return `[${ - type.name - }](#${type.name.toLowerCase()})`; + return `[${type.name + }](#${type.name.toLowerCase()})`; } // types in different doc const externalModule = { @@ -815,9 +822,8 @@ function renderType( function renderSstSdkType(type: TypeDoc.ReferenceType) { // types in the same doc (links to an interface) if (useModuleInterfaces(module).find((i) => i.name === type.name)) { - return `[${ - type.name - }](#${type.name.toLowerCase()})`; + return `[${type.name + }](#${type.name.toLowerCase()})`; } else if (type.name === "T") { return `string`; } @@ -897,9 +903,8 @@ function renderType( console.error(type); throw new Error(`Unsupported @pulumi provider input type`); } - return `[${ - type.name - }](https://www.pulumi.com/registry/packages/${provider}/api-docs/${link}/#${type.name.toLowerCase()})`; + return `[${type.name + }](https://www.pulumi.com/registry/packages/${provider}/api-docs/${link}/#${type.name.toLowerCase()})`; } else if (cls.startsWith("types/")) { console.error(type); throw new Error(`Unsupported @pulumi provider class type`); @@ -1035,8 +1040,7 @@ function renderVariables(module: TypeDoc.DeclarationReflection) { // nested props (ie. `.nodes`) ...useNestedTypes(v.type!, v.name).flatMap( ({ depth, prefix, subType }) => [ - `${renderName(subType)}`, ``, `
`, @@ -1073,7 +1077,7 @@ function renderFunctions( `
`, "```ts", (opts?.prefix ? `${opts.prefix}.` : "") + - renderSignature(f.signatures![0]), + renderSignature(f.signatures![0]), "```", `
` ); @@ -1211,7 +1215,7 @@ function renderMethod( `
`, "```ts", (method.flags.isStatic ? `${useClassName(module)}.` : "") + - renderSignature(method.signatures![0]), + renderSignature(method.signatures![0]), "```", `
` ); @@ -1266,16 +1270,14 @@ function renderProperties(module: TypeDoc.DeclarationReflection) { // nested props (ie. `.nodes`) ...useNestedTypes(g.getSignature!.type!, g.name).flatMap( ({ depth, prefix, subType }) => [ - `${renderName(subType)}`, ``, `
`, ``, - `**Type** ${ - subType.kind === TypeDoc.ReflectionKind.Property - ? renderType(module, subType.type!) - : renderType(module, subType.getSignature!.type!) + `**Type** ${subType.kind === TypeDoc.ReflectionKind.Property + ? renderType(module, subType.type!) + : renderType(module, subType.getSignature!.type!) }`, ``, `
`, @@ -1341,7 +1343,7 @@ function renderLinks(module: TypeDoc.DeclarationReflection) { linkType = link.type; linkType.types = linkType.types.map((t) => t.type === "reference" && - (t.name === "Output" || t.name === "OutputInstance") + (t.name === "Output" || t.name === "OutputInstance") ? t.typeArguments![0] : t ); @@ -1461,35 +1463,33 @@ function renderInterfacesAtH2Level( ({ depth, prefix, subType }) => { return subType.kind === TypeDoc.ReflectionKind.Method ? renderMethod(module, subType, { - methodTitle: `${renderName( subType )}`, - parametersTitle: `**Parameters**`, - }) + parametersTitle: `**Parameters**`, + }) : [ - `${renderName( - subType - )}`, - ``, - `
`, - ``, - `**Type** ${renderType(module, subType.type!)}`, - ``, - `
`, - ...renderDefaultTag(module, subType), - ...renderDescription(subType), - ``, - ...renderExamples(subType), - `
`, - ]; + `${renderName( + subType + )}`, + ``, + `
`, + ``, + `**Type** ${renderType(module, subType.type!)}`, + ``, + `
`, + ...renderDefaultTag(module, subType), + ...renderDescription(subType), + ``, + ...renderExamples(subType), + `
`, + ]; } ) ); @@ -1497,9 +1497,8 @@ function renderInterfacesAtH2Level( console.debug(` - interface method ${prop.name}`); lines.push( ...renderMethod(module, prop, { - methodTitle: `### ${ - prop.flags.isStatic ? "static " : "" - }${renderName(prop)}`, + methodTitle: `### ${prop.flags.isStatic ? "static " : "" + }${renderName(prop)}`, parametersTitle: `#### Parameters`, }) ); @@ -1538,8 +1537,7 @@ function renderInterfacesAtH3Level(module: TypeDoc.DeclarationReflection) { // nested props (ie. `.domain`, `.transform`) ...useNestedTypes(int.type!, int.name).flatMap( ({ depth, prefix, subType }) => [ - `${renderName(subType)}`, ``, `
`, @@ -1592,11 +1590,11 @@ function renderDescription( const str = renderTdComment(prop.comment?.summary); return opts?.indent ? [ - str - .split("\n") - .map((line) => ` ${line}`) - .join("\n"), - ] + str + .split("\n") + .map((line) => ` ${line}`) + .join("\n"), + ] : [str]; } @@ -1615,12 +1613,12 @@ function renderDefaultTag( // Otherwise render it as a comment ie. No domains configured defaultTag.content.length === 1 && defaultTag.content[0].kind === "code" ? `**Default** ${renderType(module, { - type: "intrinsic", - name: defaultTag.content[0].text - .replace(/`/g, "") - .replace(/{/g, "{") - .replace(/}/g, "}"), - } as TypeDoc.SomeType)}` + type: "intrinsic", + name: defaultTag.content[0].text + .replace(/`/g, "") + .replace(/{/g, "{") + .replace(/}/g, "}"), + } as TypeDoc.SomeType)}` : `**Default** ${renderTdComment(defaultTag.content)}`, ``, ]; @@ -1825,10 +1823,10 @@ function useNestedTypes( : []), ...(subType.kind === TypeDoc.ReflectionKind.Accessor ? useNestedTypes( - subType.getSignature?.type!, - `${prefix}.${subType.name}`, - depth + 1 - ) + subType.getSignature?.type!, + `${prefix}.${subType.name}`, + depth + 1 + ) : []), ]); @@ -1841,7 +1839,7 @@ function useNestedTypes( function configureLogger() { if (process.env.DEBUG) return; - console.debug = () => {}; + console.debug = () => { }; } function patchCode() { @@ -1890,9 +1888,9 @@ function patchCode() { /include\?\: \{[^}]*\}/, `include?: (AwsPermission | CloudflareBinding)` ) + - "\ntype Constructor = {};\n" + - "\ntype AwsPermission = {};\n" + - "\ntype CloudflareBinding = {};\n" + "\ntype Constructor = {};\n" + + "\ntype AwsPermission = {};\n" + + "\ntype CloudflareBinding = {};\n" ); } diff --git a/www/src/content/docs/docs/reference/cli.mdx b/www/src/content/docs/docs/reference/cli.mdx deleted file mode 100644 index ad1414606..000000000 --- a/www/src/content/docs/docs/reference/cli.mdx +++ /dev/null @@ -1,869 +0,0 @@ ---- -title: CLI -description: Reference doc for the `sst` CLI. ---- - -{/* DO NOT EDIT. AUTO-GENERATED FROM "cmd/sst/main.go" */} - -import Segment from '../../../../../src/components/tsdoc/Segment.astro'; -import Section from '../../../../../src/components/tsdoc/Section.astro'; -import NestedTitle from '../../../../../src/components/tsdoc/NestedTitle.astro'; -import InlineSection from '../../../../../src/components/tsdoc/InlineSection.astro'; - -
- -
-The CLI helps you manage your SST apps. - -If you are using SST as a part of your Node project, we recommend installing it locally. -```bash -npm install sst -``` ---- -If you are not using Node, you can install the CLI globally. -```bash -curl -fsSL https://sst.dev/install | bash -``` - -:::note -The CLI currently supports macOS, Linux, and WSL. Windows support is coming soon. -::: - -To install a specific version. - -```bash "VERSION=0.0.403" -curl -fsSL https://sst.dev/install | VERSION=0.0.403 bash -``` ---- -#### With a package manager - -You can also use a package manager to install the CLI. - -- **macOS** - - The CLI is available via a Homebrew Tap, and as downloadable binary in the [releases](https://github.com/sst/ion/releases/latest). - - ```bash - brew install sst/tap/sst - - # Upgrade - brew upgrade sst - ``` - - You might have to run `brew upgrade sst`, before the update. - -- **Linux** - - The CLI is available as downloadable binaries in the [releases](https://github.com/sst/ion/releases/latest). Download the `.deb` or `.rpm` and install with `sudo dpkg -i` and `sudo rpm -i`. - - For Arch Linux, it's available in the [aur](https://aur.archlinux.org/packages/sst-bin). ---- -#### Usage - -Once installed you can run the commands using. - -```bash -sst [command] -``` - -The CLI takes a few global flags. For example, the deploy command takes the `--stage` flag - -```bash -sst deploy --stage production -``` ---- -#### Environment variables - -You can access any environment variables set in the CLI in your `sst.config.ts` file. For example, running: - -```bash -ENV_VAR=123 sst deploy -``` - -Will let you access `ENV_VAR` through `process.env.ENV_VAR`. -
- ---- - -## Global Flags - -### stage - -
- -**Type** string - -
-Set the stage the CLI is running on. - -```bash frame="none" -sst [command] --stage production -``` - -The stage is a string that is used to prefix the resources in your app. This allows you to have multiple _environments_ of your app running in the same account. - -:::tip -Changing the stage will redeploy your app to a new stage with new resources. The old resources will still be around in the old stage. -::: - -If the stage is not passed in, then the CLI will: - -1. Use the username on the local machine. - - If the username is `root`, `admin`, `prod`, `dev`, `production`, then it will prompt for a stage name. -2. Store this in the `.sst/stage` file and reads from it in the future. - -This stored stage is called your **personal stage**. -
- -### verbose - -
- -**Type** boolean - -
- -Prints extra information to the log files in the `.sst/` directory. - -```bash -sst [command] --verbose -``` - -To also view this on the screen, use the `--print-logs` flag. - -
- -### print-logs - -
- -**Type** boolean - -
- -Print the logs to the screen. These are logs that are written to the `.sst/` directory. - -```bash -sst [command] --print-logs -``` -It can also be set using the `SST_PRINT_LOGS` environment variable. - -```bash -SST_PRINT_LOGS=1 sst [command] -``` -This is useful when running in a CI environment. - -
- -### help - -
- -**Type** boolean - -
-Prints help for the given command. - -```sh frame="none" -sst [command] --help -``` - -Or the global help. - -```sh frame="none" -sst --help -``` -
- -## Commands - -### init - -
-```sh frame="none" -sst init -``` -
- -
-#### Flags --

yes boolean

-

Skip interactive confirmation for detected framework.

-
-Initialize a new project in the current directory. This will create a `sst.config.ts` and `sst install` your providers. - -If this is run in a Next.js, Remix, Astro, or SvelteKit project, it'll init SST in drop-in mode. - -To skip the interactive confirmation after detecting the framework. - -```bash frame="none" -sst init --yes -``` -
- -### dev - -
-```sh frame="none" -sst dev [command] -``` -
- -
-#### Args --

command?

-

The command to run

-
- -
-#### Flags --

mode string

-

Defaults to using the multiplexer or `mosaic` mode. Use `basic` to turn it off.

-
-Run your app in dev mode. - -```bash frame="none" -sst dev -``` -By default, this starts a multiplexer with processes that deploy your app, run your functions, and start your frontend. - -![sst dev multiplexer mode](../../../../assets/docs/cli/sst-dev-multiplexer-mode.png) - -Each process is run in a separate pane that you can click on in the sidebar. These -include processes that: - -1. Watch your `sst.config.ts` and deploy your app -2. Run your functions [Live](/docs/live/) and logs their invocations -3. Run the dev mode for components that have `dev.autostart` enabled - - Components like `Service` and frontends like `Nextjs`, `Remix`, `Astro`, `StaticSite`, etc. - - It starts their `dev.command` in a separate pane - - And loads any [linked resources](/docs/linking) in the environment - -The multiplexer makes it so that you won't have to start your frontend or -your container applications separately. - -:::tip -The `sst dev` CLI also starts your frontend. So you don't need to start it -separately. -::: - -While `sst dev` does a deploy when it starts up, it does not deploy components like -`Service`, or the frontends like `Nextjs`, `Remix`, `Astro`, `StaticSite`, etc. -That's because these have their own dev modes that the multiplexer starts. - -:::note -The `Service` component and the frontends like `Nextjs` or `StaticSite` are not -deployed by `sst dev`. -::: - -Optionally, you can disable the multiplexer and run `sst dev` in basic mode. - -```bash frame="none" -sst dev --mode=basic -``` - -This will only deploy your app and run your functions. If you are coming from SST -v2, this is how `sst dev` used to work. - -However in `basic` mode, you'll need to start your frontend separately by running -`sst dev` in a separate terminal session by passing in the command. For example: - -```bash frame="none" -sst dev next dev -``` - -By wrapping your command, it'll load your [linked resources](/docs/linking) in the -environment. - -To pass in a flag to the command, use `--`. - -```bash frame="none" -sst dev -- next dev --turbo -``` -
- -### deploy - -
-```sh frame="none" -sst deploy -``` -
- -
-#### Flags --

target

-

Comma seperated list of target URNs.

-
-Deploy your application. By default, it deploys to your personal stage. - -All the resources are deployed as concurrently as possible, based on their dependencies. -For resources like your sites and functions; it first builds them and then deploys the generated assets. - -Since the build processes for some of these resources, like Next.js, take a lot of memory, the concurrency is limited by default of 4. -You can change this by setting the `SST_BUILD_CONCURRENCY` environment variable. - -```bash frame="none" -SST_BUILD_CONCURRENCY=8 sst deploy -``` - -You can change this based on how much memory your CI environment has. - -:::tip -You can turn down the build concurrency if you are running out of memory in CI. -::: - -Optionally, deploy your app to a specific stage. - -```bash frame="none" -sst deploy --stage production -``` -Optionally, deploy specific resources by passing in a list of their URNs. -You can get the URN of a resource from the [Console](/docs/console/#resources). - -```bash frame="none" -sst deploy --target urn:pulumi:prod::www::sst:aws:Astro::Astro,urn:pulumi:prod::www::sst:aws:Bucket::Assets -``` -
- -### diff - -
-```sh frame="none" -sst diff -``` -
- -
-#### Flags --

target

-

Comma seperated list of target URNs.

--

dev boolean

-

Compare to the dev of this stage.

-
-Builds your app to see what changes will be made when you deploy it. - -It displays a list of resources that will be created, updated, or deleted. -For each of these resources, it'll also show the properties that are changing. - -:::tip -Run a `sst diff` to see what changes will be made when you deploy your app. -::: - -This is useful for cases when you pull some changes from a teammate and want to -see what will be deployed; before doing the actual deploy. - -Optionall, you can diff a specific set of resources by passing in a list of their URNs. - -```bash frame="none" -sst diff --target urn:pulumi:prod::www::sst:aws:Astro::Astro,urn:pulumi:prod::www::sst:aws:Bucket::Assets -``` - -By default, this compares to the last deploy of the given stage as it would be -deployed using `sst deploy`. But if you are working in dev mode using `sst dev`, -you can use the `--dev` flag. - -```bash frame="none" -sst diff --dev -``` - -This is useful because in dev mode, you app is deployed a little differently. -
- -### add - -
-```sh frame="none" -sst add -``` -
- -
-#### Args --

provider

-

The provider to add.

-
-Adds and installs the given provider. For example, - -```bash frame="none" -sst add aws -``` - -This command will: - -1. Installs the package for the AWS provider. -2. Add `aws` to the globals in your `sst.config.ts`. -3. And, add it to your `providers`. - -```ts title="sst.config.ts" -{ - providers: { - aws: true - } -} -``` - -You can use any provider listed in the [Directory](/docs/providers#directory). - -:::note -Running `sst add aws` above is the same as manually adding the provider to your config and running `sst install`. -::: - -By default, the latest version of the provider is installed. If you want to use a specific version, you can set it in your config. - -```ts title="sst.config.ts" -{ - providers: { - aws: { - version: "6.27.0" - } - } -} -``` - -:::tip -You'll need to run `sst install` after you update the `providers` in your config. -::: -
- -### install - -
-```sh frame="none" -sst install -``` -
-Installs the providers in your `sst.config.ts`. You'll need this command when: - -1. You add a new provider to the `providers` or `home` in your config. -2. Or, when you want to install new providers after you `git pull` some changes. - -:::tip -The `sst install` command is similar to `npm install`. -::: - -Behind the scenes, it installs the packages for your providers and adds the providers to your globals. - -If you don't have a version specified for your providers in your `sst.config.ts`, it'll install their latest versions. -
- -### secret - - -
-#### Flags --

fallback boolean

-

Manage the fallback values of secrets.

-
- -
-#### Subcommands --

[set](#secret-set)

--

[remove](#secret-remove)

--

[load](#secret-load)

--

[list](#secret-list)

-
-Manage the secrets in your app defined with `sst.Secret`. - -The `--fallback` flag can be used to manage the fallback values of a secret. -Applies to all the sub-commands in `sst secret`. -
-set - -
-```sh frame="none" -sst secret set [value] -``` -
-
-#### Args --

name

-

The name of the secret.

--

value

-

The value of the secret.

-
-Set the value of the secret. - -The secrets are encrypted and stored in an S3 Bucket in your AWS account. They are also stored in the package of the functions using the secret. - -:::tip -If you are not running `sst dev`, you'll need to `sst deploy` to apply the secret. -::: - -For example, set the `sst.Secret` called `StripeSecret` to `123456789`. - -```bash frame="none" -sst secret set StripeSecret dev_123456789 -``` - -Optionally, set the secret in a specific stage. - -```bash frame="none" -sst secret set StripeSecret prod_123456789 --stage production -``` - -You can also set a _fallback_ value for a secret with `--fallback`. - -```bash frame="none" -sst secret set StripeSecret dev_123456789 --fallback -``` - -So if the secret is not set for a specific stage, it'll use the fallback instead. -This only works for stages that are in the same AWS account. - -:::tip -Set fallback values for your PR stages. -::: - -This is useful for preview environments that are automatically deployed. -You won't have to set the secret for the stage after it's deployed. - -To set something like an RSA key, you can first save it to a file. - -```bash frame="none" -cat > tmp.txt < -remove - -
-```sh frame="none" -sst secret remove -``` -
-
-#### Args --

name

-

The name of the secret.

-
-Remove a secret. - -For example, remove the `sst.Secret` called `StripeSecret`. - -```bash frame="none" frame="none" -sst secret remove StripeSecret -``` - -Optionally, remove a secret in a specific stage. - -```bash frame="none" frame="none" -sst secret remove StripeSecret --stage production -``` - -Remove the fallback value of the secret. - -```bash frame="none" frame="none" -sst secret remove StripeSecret --fallback -``` -
-load - -
-```sh frame="none" -sst secret load -``` -
-
-#### Args --

file

-

The file to load the secrets from.

-
-Load all the secrets from a file and set them. - -```bash frame="none" -sst secret load ./secrets.env -``` - -The file needs to be in the _dotenv_ or bash format of key-value pairs. - -```sh title="secrets.env" -KEY_1=VALUE1 -KEY_2=VALUE2 -``` - -Optionally, set the secrets in a specific stage. - -```bash frame="none" -sst secret load ./prod.env --stage production -``` - -Set these secrets as _fallback_ values. - -```bash frame="none" frame="none" -sst secret load ./secrets.env --fallback -``` -
-list - -
-```sh frame="none" -sst secret list -``` -
-Lists all the secrets. - -Optionally, list the secrets in a specific stage. - -```bash frame="none" frame="none" -sst secret list --stage production -``` - -List only the fallback secrets. - -```bash frame="none" frame="none" -sst secret list --fallback -``` -
- -### shell - -
-```sh frame="none" -sst shell [command] -``` -
- -
-#### Args --

command?

-

A command to run.

-
- -
-#### Flags --

target

-

Target to run against.

-
-Run a command with **all the resources linked** to the environment. This is useful for running scripts against your infrastructure. - -For example, let's say you have the following resources in your app. - -```js title="sst.config.ts" {5,9} -new sst.aws.Bucket("MyMainBucket"); -new sst.aws.Bucket("MyAdminBucket"); -``` - -We can now write a script that'll can access both these resources with the [JS SDK](/docs/reference/sdk/). - -```js title="my-script.js" "Resource.MyMainBucket.name" "Resource.MyAdminBucket.name" -import { Resource } from "sst"; - -console.log(Resource.MyMainBucket.name, Resource.MyAdminBucket.name); -``` - -And run the script with `sst shell`. - -```bash frame="none" frame="none" -sst shell node my-script.js -``` - -This'll have access to all the buckets from above. - -:::tip -Run the command with `--` to pass arguments to it. -::: - -To pass arguments into the script, you'll need to prefix it using `--`. - -```bash frame="none" frame="none" /--(?!a)/ -sst shell -- node my-script.js --arg1 --arg2 -``` - -If no command is passed in, it opens a shell session with the linked resources. - -```bash frame="none" frame="none" -sst shell -``` - -This is useful if you want to run multiple commands, all while accessing the resources in your app. -
- -### remove - -
-```sh frame="none" -sst remove -``` -
- -
-#### Flags --

target string

-

Comma seperated list of target URNs.

-
-Removes your application. By default, it removes your personal stage. - -:::tip -The resources in your app are removed based on the `removal` setting in your `sst.config.ts`. -::: - -This does not remove the SST _state_ and _bootstrap_ resources in your account as these might still be in use by other apps. You can remove them manually if you want to reset your account, [learn more](docs/providers/#state). - -Optionally, remove your app from a specific stage. - -```bash frame="none" frame="none" -sst remove --stage production -``` -``` -Optionally, remove specific resources by passing in a list of their URNs. -You can get the URN of a resource from the [Console](/docs/console/#resources). - -```bash frame="none" -sst remove --target urn:pulumi:prod::www::sst:aws:Astro::Astro,urn:pulumi:prod::www::sst:aws:Bucket::Assets -``` -
- -### unlock - -
-```sh frame="none" -sst unlock -``` -
-When you run `sst deploy`, it acquires a lock on your state file to prevent concurrent deploys. - -However, if something unexpectedly kills the `sst deploy` process, or if you manage to run `sst deploy` concurrently, the lock might not be released. - -This should not usually happen, but it can prevent you from deploying. You can run `sst unlock` to release the lock. -
- -### version - -
-```sh frame="none" -sst version -``` -
-Prints the current version of the CLI. -
- -### upgrade - -
-```sh frame="none" -sst upgrade [version] -``` -
- -
-#### Args --

version?

-

A version to upgrade to.

-
-Upgrade the CLI to the latest version. Or optionally, pass in a version to upgrade to. - -```bash frame="none" -sst upgrade 0.10 -``` -
- -### telemetry - - -
-#### Subcommands --

[enable](#telemetry-enable)

--

[disable](#telemetry-disable)

-
-Manage telemetry settings. - -SST collects completely anonymous telemetry data about general usage. We track: -- Version of SST in use -- Command invoked, `sst dev`, `sst deploy`, etc. -- General machine information, like the number of CPUs, OS, CI/CD environment, etc. - -This is completely optional and can be disabled at any time. -
-enable - -
-```sh frame="none" -sst telemetry enable -``` -
-Enable telemetry. -
-disable - -
-```sh frame="none" -sst telemetry disable -``` -
-Disable telemetry. -
- -### refresh - -
-```sh frame="none" -sst refresh -``` -
- -
-#### Flags --

target string

-

Comma seperated list of target URNs.

-
-Compares your local state with the state of the resources in the cloud provider. Any changes that are found are adopted into your local state. It will: - -1. Go through every single resource in your state. -2. Make a call to the cloud provider to check the resource. - - If the configs are different, it'll **update the state** to reflect the change. - - If the resource doesn't exist anymore, it'll **remove it from the state**. - -:::note -The `sst refresh` does not make changes to the resources in the cloud provider. -::: -Optionally, refresh specific resources by passing in a list of their URNs. -You can get the URN of a resource from the [Console](/docs/console/#resources). - -```bash frame="none" -sst refresh --target urn:pulumi:prod::www::sst:aws:Astro::Astro,urn:pulumi:prod::www::sst:aws:Bucket::Assets -``` - -This is useful for cases where you want to ensure that your local state is in sync with your cloud provider. [Learn more about how state works](/docs/providers/#how-state-works). -
- -### cert - -
-```sh frame="none" -sst cert -``` -
-Generate a locally-trusted certificate to connect to the Console. - -The Console can show you local logs from `sst dev` by connecting to your CLI. Certain browsers like Safari and Brave require the local connection to be running on HTTPS. - -This command uses [mkcert](https://github.com/FiloSottile/mkcert) internally to generate a locally-trusted certificate for `localhost` and `127.0.0.1`. - -You'll only need to do this once on your machine. -
- -### diagnostic - -
-```sh frame="none" -sst diagnostic -``` -
-Generates a diagnostic report based on the last command that was run. - -This takes the state of your app, its log files, and generates a zip file in the `.sst/` directory. This is for debugging purposes. -
-
\ No newline at end of file diff --git a/www/src/content/docs/docs/reference/config.mdx b/www/src/content/docs/docs/reference/config.mdx deleted file mode 100644 index a997298a2..000000000 --- a/www/src/content/docs/docs/reference/config.mdx +++ /dev/null @@ -1,1258 +0,0 @@ ---- -title: Config -description: Reference doc for the `sst.config.ts`. ---- - -{/* DO NOT EDIT. AUTO-GENERATED FROM "platform/src/config.ts" */} - -import Segment from '../../../../../src/components/tsdoc/Segment.astro'; -import Section from '../../../../../src/components/tsdoc/Section.astro'; -import NestedTitle from '../../../../../src/components/tsdoc/NestedTitle.astro'; -import InlineSection from '../../../../../src/components/tsdoc/InlineSection.astro'; - -
- -
-The `sst.config.ts` file is used to configure your SST app and its resources. - -```ts -$config(input: Config): Config -``` - -You specify it using the `$config` function. This takes an object of type [`Config`](#config). - -```ts title="sst.config.ts" -/// - -export default $config({ - // Your app's config - app(input) { - return { - name: "my-sst-app", - home: "aws" - }; - }, - // Your app's resources - async run() { - const bucket = new sst.aws.Bucket("MyBucket"); - - // Your app's outputs - return { - bucket: bucket.name - }; - } -}); -``` - -The `Config` object takes two functions: -1. [`app`](#app-2) — Your config -2. [`run`](#run) — Your resources - -The `app` function is evaluated right when your app loads. It's used to define the app config and its providers. - -:::note -You need TypeScript 5 to see the types in your config. -::: - -You can add Pulumi code in the `run` function not the `app` function. While the `run` -function is where you define your resources using SST or Pulumi's components. - -The run function also has access to a list of [Global](/docs/reference/global/) `$` variables and functions. These serve as the context for your app config. - -:::caution -Do not `import` the provider packages in your `sst.config.ts`. -::: - -Since SST manages importing your provider packages, it's recommended not to add any imports -in your `sst.config.ts`. - ---- - -#### .env - -Your `.env` and `.env.` files are loaded as environment variables in your config. -They need to be in the same directory as your `sst.config.ts`. - -```bash title=".env" -MY_ENV_VAR=hello -``` - -And are available as `process.env` in both your `app` and `run` functions. - -```ts title="sst.config.ts" -process.env.MY_ENV_VAR -``` - -The `.env` file takes precedence over `.env.`. So if you have a `.env` and a -`.env.dev` file, the values in the `.env` file will be used. - -:::note -You need to restart `sst dev` for changes in your `.env` files to take effect. -::: - -Make sure the stage name in your `.env.` matches the stage your app is running on. -
- ---- - -## Config -### console? - -
- -**Type** Object - --

[autodeploy](#console-autodeploy) Object

- -

[target](#console-autodeploy-target)

-
-Configure how your app works with the SST Console. [Learn more about Autodeploy](/docs/console#autodeploy). - -
-autodeploy - -
- -**Type** Object - -
- - -**Default** Auto-deploys branches and PRs. - -Auto-deploys your app when you _git push_ to your repo. Uses -[AWS CodeBuild](https://aws.amazon.com/codebuild/) in your account to run the build. - -You are only charged for the number of build -minutes that you use. The pricing is based on the machine config used. -[Learn more about CodeBuild pricing](https://aws.amazon.com/codebuild/pricing/). - -By default, this auto-deploys when you _git push_ to a: - -- **branch**: The stage name is a sanitized version of the branch name. When a branch - is removed, the stage is **not removed**. -- **pull request**: The stage name is `pr-`. When a pull request is closed, - the stage **is removed**. - -:::note -You need to configure an environment in the Console to be able to auto-deploy to it. -::: - -You can pass in your own `target` function to customize this behaviour and the machine -that'll be used to run the build. - -```ts title="sst.config.ts" -console: { - autodeploy: { - target(event) { - if ( - event.type === "branch" && - event.branch === "main" && - event.action === "pushed" - ) { - return { - stage: "production", - runner: { engine: "codebuild", compute: "large" } - }; - } - } - } -} -``` - -
- -target - -
-```ts -target(input) -``` -
- -
-**Parameters** --

input [BranchEvent](#branchevent) | [TagEvent](#tagevent) | [PullRequestEvent](#pullrequestevent)

-
- - -**Returns** undefined | [Target](#target) - -Defines the stage the app will be auto-deployed to. - -When a git event is received, Autodeploy will run the `target` function with the -git event. This function should return the stage the app will be deployed to. -Or `undefined` if the deploy should be skipped. - -:::note -Git push events for branches, pull requests, and tags are currently supported. -::: - -By default, this is what the `target` function looks like: - -```ts title="sst.config.ts" -target(event) { - if (event.type === "branch" && event.action === "pushed") { - return { - stage: event.branch - .replace(/[^a-zA-Z0-9-]/g, "-") - .replace(/-+/g, "-") - .replace(/^-/g, "") - .replace(/-$/g, "") - }; - } - - if (event.type === "pull_request") { - return { stage: `pr-${event.number}` }; - } -} -``` - -Here we are sanitizing the branch name to generate the stage name. We are also -only deploying when _pushed_ to a branch, and **not** when a branch is removed. - -:::tip -Use the git event to configure how your app will be auto-deployed. -::: - -You can change the default behavior by passing in your own `target` function. -For example, to auto-deploy to the `production` stage when you git push to the -`main` branch. - -```ts title="sst.config.ts" -target(event) { - if (event.type === "branch" && event.branch === "main" && event.action === "pushed") { - return { stage: "production" }; - } -} -``` - -If you don't want to auto-deploy for a given event, you can return `undefined`. For -example, to skip any deploys to the `staging` stage. - -```ts title="sst.config.ts" {2} -target(event) { - if (event.type === "branch" && event.branch === "staging") return; - if (event.type === "branch" && event.branch === "main" && event.action === "pushed") { - return { stage: "production" }; - } -} -``` - -The stage that is returned is then compared to the environments set in the -[app settings in the Console](/docs/console/#setup). If the stage matches a deployment -target, the stage will be deployed to that environment. If no matching environment is -found, the deploy will be skipped. - -:::note -If a target is not returned, the app will not be deployed. -::: - -In addition to the `stage` you can also configure the `runner` that will run the build. -For example, to use a larger machine for the `production` stage. - -```ts title="sst.config.ts" -target(event) { - if (event.type === "branch" && event.branch === "main" && event.action === "pushed") { - return { - stage: "production" - runner: { - engine: "codebuild", - compute: "large" - }; - }; - } -} -``` - -
- -### app - -
-```ts -app(input) -``` -
- -
-#### Parameters --

input [AppInput](#appinput)

-
- - -**Returns** [App](#app) - -The config for your app. It needs to return an object of type [`App`](#app-1). The `app` -function is evaluated when your app loads. - -:::caution -You cannot define any components or resources in the `app` function. -::: - -Here's an example of a simple `app` function. - -```ts title="sst.config.ts" -app(input) { - return { - name: "my-sst-app", - home: "aws", - providers: { - aws: true, - cloudflare: { - accountId: "6fef9ed9089bb15de3e4198618385de2" - } - }, - removal: input.stage === "production" ? "retain" : "remove" - }; -}, -``` -
- -### run - -
-```ts -run() -``` -
- - -**Returns** Promise<void | Record<string, any>> - -An async function that lets you define the resources in your app. - -:::note -You can use SST and Pulumi components only in the `run` function. -::: - -You can optionally return an object that'll be displayed as the output in the CLI. - -For example, here we return the name of the bucket we created. - -```ts title="sst.config.ts" -async run() { - const bucket = new sst.aws.Bucket("MyBucket"); - - return { - bucket: bucket.name - }; -} -``` - -This will display the following in the CLI on `sst deploy` and `sst dev`. - -```bash frame=\"none\" -bucket: bucket-jOaikGu4rla -``` - -These outputs are also written to a `.sst/output.json` file after every successful deploy. -It contains the above outputs in JSON. - -```json title=".sst/output.json" -{"bucket": "bucket-jOaikGu4rla"} -``` -
- -## App -### home - -
- -**Type** aws | cloudflare | local - -
-The provider SST will use to store the state for your app. The state keeps track of all your resources and secrets. The state is generated locally and backed up in your cloud provider. - - -Currently supports AWS, Cloudflare and local. - -:::tip -SST uses the `home` provider to store the state for your app. If you use the local provider it will be saved on your machine. You can see where by running `sst version`. -::: - -If you want to configure the aws or cloudflare home provider, you can: - -```ts -{ - home: "aws", - providers: { - aws: { - region: "us-west-2" - } - } -} -``` - -
-### name - -
- -**Type** string - -
-The name of the app. This is used to prefix the names of the resources in your app. - -:::caution -If you change the name of your app, it'll redeploy your app with new resources. The old resources will be orphaned. -::: - -This means that you don't want to change the name of your app without removing the old resources first. - -```ts -{ - name: "my-sst-app" -} -``` -
-### providers? - -
- -**Type** Record<string, any> - -
- - -**Default** The `home` provider. - -The providers that are being used in this app. This allows you to use the components from these providers in your app. -Check out the full list in the [Directory](/docs/providers#directory). - -:::note -By default, your `home` provider is included in the `providers` list. -::: - -If you don't set a `provider` it uses your `home` provider with the default config. So if you set `home` to `aws`, it's the same as doing: - -```ts -{ - home: "aws", - providers: { - aws: true - } -} -``` - -You can also configure the provider props. Here's the config for some common providers: -- [AWS](https://www.pulumi.com/registry/packages/aws/api-docs/provider/#inputs) -- [Cloudflare](https://www.pulumi.com/registry/packages/cloudflare/api-docs/provider/#inputs) - -For example, to change the region for AWS. - -```ts -{ - providers: { - aws: { - region: "us-west-2" - } - } -} -``` - -You also add multiple providers. - -```ts -{ - providers: { - aws: true, - cloudflare: true - } -} -``` - -By default, we use the latest version of a provider. But you can optionally specify a version. - -```ts -{ - providers: { - aws: { - version: "6.27.0" - } - } -} -``` -
-### removal? - -
- -**Type** remove | retain | retain-all - -
- - -**Default** "retain" - -Configure how your resources are handled on `sst remove`: - -- `remove`: Remove all your resources on remove. -- `retain`: Retains S3 buckets and DynamoDB tables, and remove all other resources. -- `retain-all`: Retains all your resources on remove. - -:::tip -If you change your removal policy, you'll need to deploy your app once for it to take effect. -::: - -Retain resources if it's the _production_ stage, otherwise remove all resources. -```ts -{ - removal: input.stage === "production" ? "retain" : "remove" -} -``` -
-### version? - -
- -**Type** string - -
- - -**Default** The latest version of SST. - -The version of SST supported by the app. The CLI will fail any commands if the version does -not match. - -:::tip -Useful in CI where you don't want it to automatically deploy with a new version of SST. -::: - -Takes a specific version. - -```ts -version: "0.0.300" -``` - -Also supports semver ranges. -```ts -version: ">= 0.0.300" -``` -
- -## AppInput -### stage - -
- -**Type** string - -
-The stage this app is running on. This is a string that can be passed in through the CLI. - -:::caution -Changing the stage will redeploy your app to a new stage with new resources. The old resources will still be around in the old stage. -::: - -If not passed in, it'll use the username of your local machine, or prompt you for it. - -
- -## BranchEvent - -A git event for when a branch is updated or deleted. For example: -```js -{ - type: "branch", - action: "pushed", - repo: { - id: 1296269, - owner: "octocat", - repo: "Hello-World" - }, - branch: "main", - commit: { - id: "b7e7c4c559e0e5b4bc6f8d98e0e5e5e5e5e5e5e5", - message: "Update the README with new information" - }, - sender: { - id: 1, - username: "octocat" - } -} -``` -### action - -
- -**Type** pushed | removed - -
-The type of the git action. - -- `pushed` is when you git push to a branch -- `removed` is when a branch is removed - -
-### branch - -
- -**Type** string - -
-The name of the branch the event is coming from. - -
-### commit - -
- -**Type** Object - --

[id](#commit-id)

--

[message](#commit-message)

-
-Info about the commit in the event. This might look like: - -```js -{ - id: "b7e7c4c559e0e5b4bc6f8d98e0e5e5e5e5e5e5e5", - message: "Update the README with new information" -} -``` - -
-id - -
- -**Type** string - -
-The ID of the commit. - -
-message - -
- -**Type** string - -
-The commit message. - -
-### repo - -
- -**Type** Object - --

[id](#repo-id)

--

[owner](#repo-owner)

--

[repo](#repo-repo)

-
-The Git repository the event is coming from. This might look like: - -```js -{ - id: 1296269, - owner: "octocat", - repo: "Hello-World" -} -``` - -
-id - -
- -**Type** number - -
-The ID of the repo. This is usually a number. - -
-owner - -
- -**Type** string - -
-The name of the owner or org the repo to belongs to. - -
-repo - -
- -**Type** string - -
-The name of the repo. - -
-### sender - -
- -**Type** Object - --

[id](#sender-id)

--

[username](#sender-username)

-
-The user that generated the event. For example: - -```js -{ - id: 1, - username: "octocat" -} -``` - -
-id - -
- -**Type** number - -
-The ID of the user. - -
-username - -
- -**Type** string - -
-The username of the user. - -
-### type - -
- -**Type** branch - -
-The git event type, for the `BranchEvent` it's `branch`. - -
- -## PullRequestEvent - -A git event for when a pull request is updated or deleted. For exampple: - -```js -{ - type: "pull_request", - action: "pushed", - repo: { - id: 1296269, - owner: "octocat", - repo: "Hello-World" - }, - number: 1347, - base: "main", - head: "feature", - commit: { - id: "b7e7c4c559e0e5b4bc6f8d98e0e5e5e5e5e5e5e5", - message: "Update the README with new information" - }, - sender: { - id: 1, - username: "octocat" - } -} -``` -### action - -
- -**Type** pushed | removed - -
-The type of the git action. - -- `pushed` is when you git push to the base branch of the PR -- `removed` is when the PR is closed or merged - -
-### base - -
- -**Type** string - -
-The base branch of the PR. This is the branch the code is being merged into. - -
-### commit - -
- -**Type** Object - --

[id](#commit-id-1)

--

[message](#commit-message-1)

-
-Info about the commit in the event. This might look like: - -```js -{ - id: "b7e7c4c559e0e5b4bc6f8d98e0e5e5e5e5e5e5e5", - message: "Update the README with new information" -} -``` - -
-id - -
- -**Type** string - -
-The ID of the commit. - -
-message - -
- -**Type** string - -
-The commit message. - -
-### head - -
- -**Type** string - -
-The head branch of the PR. This is the branch the code is coming from. - -
-### number - -
- -**Type** number - -
-The pull request number. - -
-### repo - -
- -**Type** Object - --

[id](#repo-id-1)

--

[owner](#repo-owner-1)

--

[repo](#repo-repo-1)

-
-The Git repository the event is coming from. This might look like: - -```js -{ - id: 1296269, - owner: "octocat", - repo: "Hello-World" -} -``` - -
-id - -
- -**Type** number - -
-The ID of the repo. This is usually a number. - -
-owner - -
- -**Type** string - -
-The name of the owner or org the repo to belongs to. - -
-repo - -
- -**Type** string - -
-The name of the repo. - -
-### sender - -
- -**Type** Object - --

[id](#sender-id-1)

--

[username](#sender-username-1)

-
-The user that generated the event. For example: - -```js -{ - id: 1, - username: "octocat" -} -``` - -
-id - -
- -**Type** number - -
-The ID of the user. - -
-username - -
- -**Type** string - -
-The username of the user. - -
-### type - -
- -**Type** pull_request - -
-The git event type, for the `PullRequestEvent` it's `pull_request`. - -
- -## TagEvent - -A git event for when a tag is created or deleted. For example: -```js -{ - type: "tag", - action: "pushed", - repo: { - id: 1296269, - owner: "octocat", - repo: "Hello-World" - }, - tag: "v1.5.2", - commit: { - id: "b7e7c4c559e0e5b4bc6f8d98e0e5e5e5e5e5e5e5", - message: "Update the README with new information" - }, - sender: { - id: 1, - username: "octocat" - } -} -``` -### action - -
- -**Type** pushed | removed - -
-The type of the git action. - -- `pushed` is when you create a tag -- `removed` is when a tag is removed - -
-### commit - -
- -**Type** Object - --

[id](#commit-id-2)

--

[message](#commit-message-2)

-
-Info about the commit in the event. This might look like: - -```js -{ - id: "b7e7c4c559e0e5b4bc6f8d98e0e5e5e5e5e5e5e5", - message: "Update the README with new information" -} -``` - -
-id - -
- -**Type** string - -
-The ID of the commit. - -
-message - -
- -**Type** string - -
-The commit message. - -
-### repo - -
- -**Type** Object - --

[id](#repo-id-2)

--

[owner](#repo-owner-2)

--

[repo](#repo-repo-2)

-
-The Git repository the event is coming from. This might look like: - -```js -{ - id: 1296269, - owner: "octocat", - repo: "Hello-World" -} -``` - -
-id - -
- -**Type** number - -
-The ID of the repo. This is usually a number. - -
-owner - -
- -**Type** string - -
-The name of the owner or org the repo to belongs to. - -
-repo - -
- -**Type** string - -
-The name of the repo. - -
-### sender - -
- -**Type** Object - --

[id](#sender-id-2)

--

[username](#sender-username-2)

-
-The user that generated the event. For example: - -```js -{ - id: 1, - username: "octocat" -} -``` - -
-id - -
- -**Type** number - -
-The ID of the user. - -
-username - -
- -**Type** string - -
-The username of the user. - -
-### tag - -
- -**Type** string - -
-The name of the tag. For example, `v1.5.2`. - -
-### type - -
- -**Type** tag - -
-The git event type, for the `TagEvent` it's `tag`. - -
- -## Target -### runner? - -
- -**Type** Object - --

[architecture?](#runner-architecture)

--

[compute?](#runner-compute)

--

[engine](#runner-engine)

--

[timeout?](#runner-timeout)

-
-Configure the runner that will run the build. - -It uses this to create a _runner_ — a -[AWS CodeBuild](https://aws.amazon.com/codebuild/) project and an IAM Role, -in **your account**. By default it uses: - -```ts -{ - engine: "codebuild", - architecture: "x86_64", - compute: "small", - timeout: "1 hour" -} -``` - -:::note -Runners are shared across all apps in the same account and region. -::: - -Once a runner is created, it can be used to run multiple builds of the same -machine config concurrently. - -You are only charged for the number of build -minutes that you use. The pricing is based on the machine config used. -[Learn more about CodeBuild pricing](https://aws.amazon.com/codebuild/pricing/). - -:::note -A runner can run multiple builds concurrently. -::: - -If a runner with the given config has been been previously created, -it'll be reused. The Console will also automatically remove runners that -have not been used for more than 7 days. - -
-architecture? - -
- -**Type** x86_64 | arm64 - -
- - -**Default** x86_64 - -The architecture of the build machine. - -
-compute? - -
- -**Type** small | medium | large | xlarge - -
- - -**Default** small - -The compute size of the build environment. - -For `x86_64`, it can be the following: -- `small`: 3 GB, 2 vCPUs -- `medium`: 7 GB, 4 vCPUs -- `large`: 15 GB, 8 vCPUs -- `xlarge`: 30 GB, 16 vCPUs - -For `arm64` architecture, only `small` and `large` are supported: -- `small`: 4 GB, 2 vCPUs -- `large`: 8 GB, 4 vCPUs - -To increase the memory used by your Node.js process in the build environment, you'll want -to set the `NODE_OPTIONS` environment variable to `--max-old-space-size=xyz`. Where `xyz` -is the memory size in MB. By default, this is set to 1.5 GB. - -Read more about the [CodeBuild build environments](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html). - -
-engine - -
- -**Type** codebuild - -
-The service used to run the build. Currently, only AWS CodeBuild is supported. - -
-timeout? - -
- -**Type** $\{number\} minute | $\{number\} minutes | $\{number\} hour | $\{number\} hours - -
- - -**Default** 1 hour - -The timeout for the build. It can be from `5 minutes` to `1 hour`. - -
-### stage - -
- -**Type** string - -
-The stage the app will be deployed to. - -
-
\ No newline at end of file diff --git a/www/src/content/docs/docs/reference/global.mdx b/www/src/content/docs/docs/reference/global.mdx deleted file mode 100644 index 9d5a0ae47..000000000 --- a/www/src/content/docs/docs/reference/global.mdx +++ /dev/null @@ -1,362 +0,0 @@ ---- -title: Global -description: Reference doc for the Global `$` library. ---- - -{/* DO NOT EDIT. AUTO-GENERATED FROM "platform/src/global.d.ts" */} - -import Segment from '../../../../../src/components/tsdoc/Segment.astro'; -import Section from '../../../../../src/components/tsdoc/Section.astro'; -import NestedTitle from '../../../../../src/components/tsdoc/NestedTitle.astro'; -import InlineSection from '../../../../../src/components/tsdoc/InlineSection.astro'; - -
- -
-The Global library is a collection of `$` functions and variables that are available in the `run` function, of your [`sst.config.ts`](/docs/reference/config/). - -You don't need to import the Global library. It's available in the `run` function of your `sst.config.ts`. - -:::note -The Global library is only available in the `run` function of your `sst.config.ts`. -::: - -For example, you can get the name of your app in your app config using `$app.name`. - -```ts title="sst.config.ts" {4} -export default $config({ - // ... - async run() { - console.log($app.name); - } -}); -``` - -The **variables** contain the context of the app that's being run. While the **functions** help you work with the [Outputs of components](/docs/components##inputs--outputs). -
- ---- - -## Variables - -### $app - -
- -**Type** Object - --

[name](#app-name)

--

[providers](#app-providers)

--

[removal](#app-removal)

--

[stage](#app-stage)

-
-Context about the app being run. -
-name - -
- -**Type** string - -
-The name of the current app. -
-providers - -
- -**Type** undefined | Record<string, any> - -
-The providers currently being used in the app. -
-removal - -
- -**Type** remove | retain | retain-all - -
-The removal policy for the current stage. If `removal` was not set in the `sst.config.ts`, this will be return its default value, `retain`. -
-stage - -
- -**Type** string - -
-The stage currently being run. You can use this to conditionally deploy resources based -on the stage. - -For example, to deploy a bucket only in the `dev` stage: - -```ts title="sst.config.ts" -if ($app.stage === "dev") { - new sst.aws.Bucket("MyBucket"); -} -``` -
- -### $dev - -
- -**Type** boolean - -
-Returns `true` if the app is running in `sst dev`. -
- -### $util - -
- -**Type** [@pulumi/pulumi](https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/) - -
-A convenience reference to the the [`util`](https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/) module from Pulumi. - -This is useful for working with components. You can use these without importing or installing the Pulumi SDK. -For example, to create a new asset, you can: - -```ts title="sst.config.ts" -const myFiles = new $util.asset.FileArchive("./path/to/files"); -``` - -This is equivalent to doing: - -```ts title="sst.config.ts" -import * as pulumi from "@pulumi/pulumi"; - -const myFiles = new pulumi.asset.FileArchive("./path/to/files"); -``` -
- -## Functions - -### $concat - -
-```ts -$concat(params) -``` -
- -
-#### Parameters --

params any[]

-
- - -**Returns** Output<string> - -Takes a sequence of Output values or plain JavaScript values, stringifies each, -and concatenates them into one final string. - -This is takes care of resolving the Output values for you. Say you had a bucket: - -```ts title="sst.config.ts" -const bucket = new sst.aws.Bucket("MyBucket"); -``` - -Instead of having to resolve the bucket name first:: - -```ts title="sst.config.ts" -const description = bucket.name.apply(name => - "This is a bucket named ".concat(name) -); -``` - -You can directly do this: - -```ts title="sst.config.ts" -const description = $concat("This is a bucket named ", bucket.name); -``` -
- -### $interpolate - -
-```ts -$interpolate(literals, placeholders) -``` -
- -
-#### Parameters --

literals TemplateStringsArray<>

--

placeholders any[]

-
- - -**Returns** Output<string> - -Use string interpolation on Output values. - -This is takes care of resolving the Output values for you. Say you had a bucket: - -```ts title="sst.config.ts" -const bucket = new sst.aws.Bucket("MyBucket"); -``` - -Instead of resolving the bucket name first: - -```ts title="sst.config.ts" -const description = bucket.name.apply(name => `This is a bucket named ${name}`); -``` - -You can directly do this: -```ts title="sst.config.ts" -const description = $interpolate`This is a bucket named ${bucket.name}`; -``` -
- -### $jsonParse - -
-```ts -$jsonParse(text, reviver?) -``` -
- -
-#### Parameters --

text Input<string>

--

reviver? [JSON.parse reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#reviver)

-
- - -**Returns** Output<any> - -Takes an Output value or plain JavaScript value, uses `JSON.parse` -on the resolved JSON string to turn it into a JSON object. - -So for example, instead of doing of resolving the value first: - -```ts title="sst.config.ts" -const policy = policyStr.apply((policy) => - JSON.parse(policy) -); -``` - -You can directly do this: - -```ts title="sst.config.ts" -const policy = $jsonParse(policyStr); -``` -
- -### $jsonStringify - -
-```ts -$jsonStringify(obj, replacer?, space?) -``` -
- -
-#### Parameters --

obj any

--

replacer? [JSON.stringify replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#replacer)

--

space? string | number

-
- - -**Returns** Output<string> - -Takes an Output value or plain JSON object, uses `JSON.stringify` -on the resolved JSON object to turn it into a JSON string. - -So for example, instead of doing of resolving the value first: - -```ts title="sst.config.ts" -const policy = policyObj.apply((policy) => - JSON.stringify(policy) -); -``` - -You can directly do this: - -```ts title="sst.config.ts" -const policy = $jsonStringify(policyObj); -``` -
- -### $resolve - -
-```ts -$resolve(val) -``` -
- -
-#### Parameters --

val Record<string, Input<T>>

-
- - -**Returns** Output<Record<string, T>> - -Wait for a list of Output values to be resolved, and then apply a function to their resolved values. - -Say you had a couple of S3 Buckets: -```ts title="sst.config.ts" -const bucket1 = new sst.aws.Bucket("MyBucket1"); -const bucket2 = new sst.aws.Bucket("MyBucket2"); -``` - -You can run a function after both of them are resolved: - -```ts title="sst.config.ts" -$resolve([bucket1.name, bucket2.name]).apply(([value1, value2]) => - console.log({ value1, value2 }) -); -``` -
- -### $transform - -
-```ts -$transform(resource, cb) -``` -
- -
-#### Parameters --

resource Component Class

--

cb (args, opts) => void

-
- - -**Returns** void - -Register a function that'll be called when a component of the given type is about -to be created. This is useful for setting global defaults for your components. - -:::note -This function is only called for components that are created **after** the function is registered. -::: - -The function takes the arguments and options that are being passed to the component, -and can modify them. - -For example, to set a default runtime for all function components. - -```ts title="sst.config.ts" -$transform(sst.aws.Function, (args, opts) => { - // Set the default if it's not set by the component - args.runtime ??= "nodejs18.x"; -}); -``` - -Here, `args` and `opts` are what you'd pass to the `Function` component. Recall the -signature of the `Function` component: - -```ts title="sst.config.ts" -new sst.aws.Function(name: string, args: FunctionArgs, opts?: pulumi.ComponentResourceOptions) -``` -
-
\ No newline at end of file