Skip to content

Commit

Permalink
Document experimental JS API (#4234)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
  • Loading branch information
bluwy and sarah11918 committed Aug 21, 2023
1 parent 09309f3 commit 2f1fdf4
Showing 1 changed file with 126 additions and 0 deletions.
126 changes: 126 additions & 0 deletions src/content/docs/en/reference/cli-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,129 @@ Automatically opens the app in the browser on server start.
### `--help`

Prints the help message and exits.

## Advanced APIs (Experimental)

If you need more control when running Astro, the `"astro"` package also exports APIs to programmatically run the CLI commands.

These APIs are experimental and their API signature may change. Any updates will be mentioned in the [Astro changelog](https://github.com/withastro/astro/blob/main/packages/astro/CHANGELOG.md) and the information below will always show the current, up-to-date information.

### `AstroInlineConfig`

The `AstroInlineConfig` type is used by all of the command APIs below. It extends from the user [Astro config](/en/reference/configuration-reference/) type:

```ts
interface AstroInlineConfig extends AstroUserConfig {
configFile?: string | false;
mode?: "development" | "production";
logLevel?: "debug" | "info" | "warn" | "error" | "silent";
}
```

#### `configFile`

<p>

**Type:** `string | false`<br />
**Default:** `undefined`
</p>

A custom path to the Astro config file.

If this value is undefined (default) or unset, Astro will search for an `astro.config.(js,mjs,ts)` file relative to the `root` and load the config file if found.

If a relative path is set, it will resolve based on the current working directory.

Set to `false` to disable loading any config files.

The inline config passed in this object will take highest priority when merging with the loaded user config.

#### `mode`

<p>

**Type:** `"development" | "production"`<br />
**Default:** `"development"` when running `astro dev`, `"production"` when running `astro build`
</p>

The mode used when building your site to generate either "development" or "production" code.

#### `logLevel`

<p>

**Type:** `"debug" | "info" | "warn" | "error" | "silent"`<br />
**Default:** `"info"`
</p>

The logging level to filter messages logged by Astro.

- `"debug"`: Log everything, including noisy debugging diagnostics.
- `"info"`: Log informational messages, warnings, and errors.
- `"warn"`: Log warnings and errors.
- `"error"`: Log errors only.
- `"silent"`: No logging.

### `dev()`

**Type:** `(inlineConfig: AstroInlineConfig) => AstroDevServer`

Similar to [`astro dev`](#astro-dev), it runs Astro's development server.

```js
import { dev } from "astro";

const devServer = await dev({
root: "./my-project",
});

// Stop the server if needed
await devServer.stop();
```

### `build()`

**Type:** `(inlineConfig: AstroInlineConfig) => void`

Similar to [`astro build`](#astro-build), it builds your site for deployment.

```js
import { build } from "astro";

await build({
root: "./my-project",
});
```

### `preview()`

**Type:** `(inlineConfig: AstroInlineConfig) => AstroPreviewServer`

Similar to [`astro preview`](#astro-preview), it starts a local server to serve your static `dist/` directory.

```js
import { preview } from "astro";

const previewServer = await preview({
root: "./my-project",
});

// Stop the server if needed
await previewServer.stop();
```

### `sync()`

**Type:** `(inlineConfig: AstroInlineConfig) => number`

Similar to [`astro sync`](#astro-sync), it generates TypeScript types for all Astro modules

```js
import { sync } from "astro";

const exitCode = await sync({
root: "./my-project",
});

process.exit(exitCode)
```

0 comments on commit 2f1fdf4

Please sign in to comment.