@nuxt/docs-nightly 4.6.0-29792791.d6bf1f45 → 4.6.0-29798469.ab647774
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -53,3 +53,57 @@ export default defineNuxtModule({
|
|
|
53
53
|
},
|
|
54
54
|
})
|
|
55
55
|
```
|
|
56
|
+
|
|
57
|
+
## `useTerminal`
|
|
58
|
+
|
|
59
|
+
Returns a set of primitives for interacting with the user's terminal. When Nuxt is running inside an interactive host such as the `nuxt dev` terminal UI, prompts, tasks and notifications are handed to it, so they are answerable and rendered in one place. Otherwise they fall back to logging.
|
|
60
|
+
|
|
61
|
+
### Usage
|
|
62
|
+
|
|
63
|
+
```ts twoslash
|
|
64
|
+
declare function runPackageInstall (name: string): Promise<void>
|
|
65
|
+
// ---cut---
|
|
66
|
+
import { defineNuxtModule, useTerminal } from '@nuxt/kit'
|
|
67
|
+
|
|
68
|
+
export default defineNuxtModule({
|
|
69
|
+
async setup () {
|
|
70
|
+
const terminal = useTerminal()
|
|
71
|
+
|
|
72
|
+
const install = await terminal.prompt('Do you want to install `my-module`?', { type: 'confirm' })
|
|
73
|
+
if (!install) {
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const task = terminal.startTask('Installing `my-module`...')
|
|
78
|
+
// run your actual task
|
|
79
|
+
await runPackageInstall('my-module')
|
|
80
|
+
task.stop('Installed `my-module`')
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Type
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
function useTerminal (): NuxtTerminal
|
|
89
|
+
|
|
90
|
+
interface NuxtTerminal {
|
|
91
|
+
readonly interactive: boolean
|
|
92
|
+
withTerminal: <T>(work: () => Promise<T>) => Promise<T>
|
|
93
|
+
prompt: (message: string, options?: NuxtPromptOptions) => Promise<any>
|
|
94
|
+
startTask: (label: string) => NuxtTerminalTask
|
|
95
|
+
notify: (notification: NuxtTerminalNotification) => NuxtTerminalNotice
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Properties
|
|
100
|
+
|
|
101
|
+
**`interactive`**: Whether an interactive host is present. When `false`, the primitives below log to the current process streams instead.
|
|
102
|
+
|
|
103
|
+
**`withTerminal`**: Borrows the terminal for the duration of `work`, suspending any host UI and releasing `stdin`. Use it when you need to write to the terminal or read from `stdin` directly. Concurrent callers are serialised, and a nested call from within a borrow runs immediately.
|
|
104
|
+
|
|
105
|
+
**`prompt`**: Asks the user a question, borrowing the terminal for as long as the prompt is open. Takes the same options as `logger.prompt`.
|
|
106
|
+
|
|
107
|
+
**`startTask`**: Starts a long-running task, rendered on the host's status surface where available. Finish it with `task.stop(message?, outcome?)`, or change its label with `task.update(label)`.
|
|
108
|
+
|
|
109
|
+
**`notify`**: Shows a message and holds it on screen until the user acknowledges it or `notice.dismiss()` is called. `notice.dismissed` settles once the notice is gone.
|
|
@@ -44,6 +44,8 @@ Check the [schema source code](https://github.com/nuxt/nuxt/blob/main/packages/s
|
|
|
44
44
|
| `restart` | `{ hard?: boolean }` | To be called to restart the current Nuxt instance. |
|
|
45
45
|
| `modules:before` | - | Called during Nuxt initialization, before installing user modules. |
|
|
46
46
|
| `modules:done` | - | Called during Nuxt initialization, after installing user modules. |
|
|
47
|
+
| `module:before` | `module` | Called immediately before each individual module is set up. |
|
|
48
|
+
| `module:done` | `module` | Called immediately after each individual module has been set up, including how long it took. |
|
|
47
49
|
| `app:resolve` | `app` | Called after resolving the `app` instance. |
|
|
48
50
|
| `app:templates` | `app` | Called during `NuxtApp` generation, to allow customizing, modifying or adding new files to the build directory (either virtually or to written to `.nuxt`). |
|
|
49
51
|
| `app:templatesGenerated` | `app` | Called after templates are compiled into the [virtual file system](/docs/4.x/directory-structure/nuxt) (vfs). |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/docs-nightly",
|
|
3
|
-
"version": "4.6.0-
|
|
3
|
+
"version": "4.6.0-29798469.ab647774",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/nuxt.git",
|
|
@@ -17,5 +17,6 @@
|
|
|
17
17
|
"**/*.md",
|
|
18
18
|
"**/*.yml"
|
|
19
19
|
],
|
|
20
|
-
"_name": "@nuxt/docs"
|
|
20
|
+
"_name": "@nuxt/docs",
|
|
21
|
+
"scripts": {}
|
|
21
22
|
}
|