diff --git a/docs/content/2.module/0.guide.md b/docs/content/2.module/0.guide.md index 2c9211a228..05271636cd 100644 --- a/docs/content/2.module/0.guide.md +++ b/docs/content/2.module/0.guide.md @@ -60,6 +60,8 @@ nuxt.hook('devtools:customTabs', (tabs) => { }) ``` +Learn more about [DevTools Utility Kit](/module/utils-kit). + ## Lazy Service Launching If the view you are contributing is heavy to load, you can have the tab first and let user launch it when they need it. diff --git a/docs/content/2.module/1.utils-kit.md b/docs/content/2.module/1.utils-kit.md new file mode 100644 index 0000000000..21c8f2fbc8 --- /dev/null +++ b/docs/content/2.module/1.utils-kit.md @@ -0,0 +1,71 @@ +# Utility Kit + +::alert{type=warning} +APIs are subject to change. +:: + +Since v0.3.0, we are now providing a utility kit for easier DevTools integrations, similar to `@nuxt/kit`. + +It can be access via `@nuxt/devtools/kit`: + +```ts +import { addCustomTab } from '@nuxt/devtools/kit' +``` + +Generally, we recommend to module authors to install `@nuxt/devtools` as a dev dependency and bundled `@nuxt/devtools/kit` into your module. + +## `addCustomTab()` + +A shorthand for calling the hook `devtools:customTabs`. + +```ts +import { addCustomTab } from '@nuxt/devtools/kit' + +addCustomTab(() => ({ + // unique identifier + name: 'my-module', + // title to display in the tab + title: 'My Module', + // any icon from Iconify, or a URL to an image + icon: 'carbon:apps', + // iframe view + view: { + type: 'iframe', + src: '/url-to-your-module-view', + }, +})) +``` + +## `refreshCustomTabs()` + +A shorthand for call hook `devtools:customTabs:refresh`. It will refresh all custom tabs. + +## `startSubprocess()` + +Start a sub process using `execa` and create a terminal tab in DevTools. + +```ts +import { startSubprocess } from '@nuxt/devtools/kit' + +const subprocess = startSubprocess( + { + command: 'code-server', + args: [ + 'serve-local', + '--accept-server-license-terms', + '--without-connection-token', + `--port=${port}`, + ], + }, + { + id: 'devtools:vscode', + name: 'VS Code Server', + icon: 'logos-visual-studio-code', + }, +) +``` + +```ts +subprocess.restart() +subprocess.terminate() +``` diff --git a/docs/content/2.module/1.ui-kit.md b/docs/content/2.module/2.ui-kit.md similarity index 100% rename from docs/content/2.module/1.ui-kit.md rename to docs/content/2.module/2.ui-kit.md diff --git a/docs/nuxt.config.ts b/docs/nuxt.config.ts index 848bf1292b..771ebc4262 100644 --- a/docs/nuxt.config.ts +++ b/docs/nuxt.config.ts @@ -1,4 +1,7 @@ export default defineNuxtConfig({ extends: '@nuxt-themes/docus', - modules: ['@nuxtjs/plausible'], + modules: [ + '@nuxtjs/plausible', + '../local', + ], }) diff --git a/local.ts b/local.ts index 3d90bf6f78..97be7670ea 100644 --- a/local.ts +++ b/local.ts @@ -18,7 +18,6 @@ * ``` */ import { defineNuxtModule, logger } from '@nuxt/kit' -import { execa } from 'execa' import { resolve } from 'pathe' import { getPort } from 'get-port-please' import { searchForWorkspaceRoot } from 'vite' @@ -26,6 +25,7 @@ import { ROUTE_CLIENT, defaultOptions } from './packages/devtools/src/constant' import type { ModuleOptions } from './packages/devtools/src/types' import { packageDir } from './packages/devtools/src/dirs' import { enableModule } from './packages/devtools/src/module-main' +import { startSubprocess } from './packages/devtools/src/kit' export type { ModuleOptions } @@ -40,10 +40,6 @@ export default defineNuxtModule({ const workspaceRoot = resolve(packageDir, '../..') const PORT = await getPort({ port: 12442 }) - // TODO: add embedded terminal and forward logs to it - const subprocess = execa('npx', ['nuxi', 'dev', '--port', PORT.toString()], { cwd: clientDir, stdio: 'pipe' }) - subprocess.stderr?.pipe(process.stderr) - nuxt.hook('vite:extendConfig', (config) => { config.server ||= {} // add proxy to client @@ -61,6 +57,22 @@ export default defineNuxtModule({ config.server.fs.allow.push(workspaceRoot) }) + nuxt.hook('app:resolve', () => { + startSubprocess( + { + command: 'npx', + args: ['nuxi', 'dev', '--port', PORT.toString()], + cwd: clientDir, + stdio: 'pipe', + }, + { + id: 'devtools:local', + name: 'Nuxt Devtools Local', + icon: 'logos-nuxt-icon', + }, + ) + }) + logger.info(`Nuxt Devtools is using local client from \`${clientDir}\``) return enableModule(options, nuxt) diff --git a/packages/devtools-ui-kit/src/components/NDialog.vue b/packages/devtools-ui-kit/src/components/NDialog.vue index 1d44c8187d..8d31822e46 100644 --- a/packages/devtools-ui-kit/src/components/NDialog.vue +++ b/packages/devtools-ui-kit/src/components/NDialog.vue @@ -45,13 +45,13 @@ export default {