Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jul 1, 2024
1 parent 9b895db commit 16250a5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
27 changes: 24 additions & 3 deletions docs/src/content/docs/reference/scripts/imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ You can rename any `.genai.js` file to `.genai.mjs` to enable module imports.

## Module Imports

You can import module installed in your project.
You can import node packages installed in your project.

```js
import { parse } from "ini"
Expand All @@ -28,9 +28,9 @@ const { stringify } = await import("ini")
console.log(stringify(res))
```

## File imports
## JavaScript imports

You can also import other local files.
You can also import other local **JavaScript** files (using static or dynamic imports).

```js title="summarizer.mjs"
export function summarize(files) {
Expand All @@ -44,6 +44,27 @@ import { summarize } from "./summarizer.mjs"
summarize(env.generator, env.files)
```

```js title="summarize.genai.mjs"
const { summarize } = await import("./summarizer.mjs")
summarize(env.generator, env.files)
```

## TypeScript imports

TypeScript (`.mts`) files can be imported using **dynamic** import only.

```js title="summarizer.mts"
export function summarize(files: string[]) {
def("FILE", files)
$`Summarize each file. Be concise.`
}
```

```js title="summarize.genai.mts"
const { summarize } = await import("./summarizer.mts")
summarize(env.generator, env.files)
```

## `env.generator`

The `env.generator` references the root prompt generator context, the top level `$`, `def` functions... It can be used to create function that can be used with those function or also with `runPrompt`.
Expand Down
6 changes: 4 additions & 2 deletions docs/src/content/docs/reference/scripts/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ $`Shorten ${file}. Limit changes to minimum.`

## Script files

- GenAIScript will detect any file matching `*.genai.mjs` in your workspace.
- GenAIScript will detect any file matching `*.genai.mjs`, `*.genai.js`, `*.genai.mts` in your workspace.
- GenAIScript files can be placed anywhere in your workspace;
but the extension will place them in a `genaisrc` folder by default.
- `.genai.mjs` use module JavaScript syntax and support imports. (`.genai.js` are eval-ed and do not support imports).
- `.genai.mjs` use module JavaScript syntax and support imports.
- `.genai.js` are eval-ed and do not support imports.
- `.genai.mts` are TypeScript module files and support imports, including dynamic imports of other TypeScript files.

<FileTree>

Expand Down

0 comments on commit 16250a5

Please sign in to comment.