From e6a6622679f7db45e094296d9d121c9798753299 Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Wed, 21 Dec 2022 08:31:17 +0100 Subject: [PATCH 1/2] feat: `prepare` CLI command --- .../1.guide/1.introduction/0.getting-started.md | 1 - docs/content/1.guide/1.introduction/2.auto-imports.md | 8 ++++++-- docs/content/1.guide/1.introduction/7.typescript.md | 2 ++ docs/content/2.deploy/providers/cloudflare.md | 1 - src/cli.ts | 11 ++++++++++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/docs/content/1.guide/1.introduction/0.getting-started.md b/docs/content/1.guide/1.introduction/0.getting-started.md index 9acaeb6fe6..c158b5f8d0 100644 --- a/docs/content/1.guide/1.introduction/0.getting-started.md +++ b/docs/content/1.guide/1.introduction/0.getting-started.md @@ -28,7 +28,6 @@ npx nitropack dev **Tip:** Check `.nitro/dev/index.mjs` if want to know what is happening - You can now build your production-ready server: ```bash diff --git a/docs/content/1.guide/1.introduction/2.auto-imports.md b/docs/content/1.guide/1.introduction/2.auto-imports.md index 448d8f2bfd..78f7b32915 100644 --- a/docs/content/1.guide/1.introduction/2.auto-imports.md +++ b/docs/content/1.guide/1.introduction/2.auto-imports.md @@ -5,11 +5,15 @@ description: You might be surprised why in the documentation there are no import This is because Nitro is integrated with [unjs/unimport](https://github.com/unjs/unimport) and automatically imports utilities by usage with full tree-shaking support! -## Available auto imports +## Available Auto Imports Check [the source code](https://github.com/unjs/nitro/blob/main/src/imports.ts) for list of available auto imports. -With [Typescript](/guide/introduction/typescript) enabled, you can easily see them as global utilities in your IDE. +With [TypeScript](/guide/introduction/typescript) enabled, you can easily see them as global utilities in your IDE. + +::alert{type="info"} +Run `npx nitropack prepare` to generate the types for global auto-imports. +:: ## Manual Imports diff --git a/docs/content/1.guide/1.introduction/7.typescript.md b/docs/content/1.guide/1.introduction/7.typescript.md index db478fbea9..8775f920af 100644 --- a/docs/content/1.guide/1.introduction/7.typescript.md +++ b/docs/content/1.guide/1.introduction/7.typescript.md @@ -10,3 +10,5 @@ To add type hints within your project, you should add the following to your `tsc "extends": "./.nitro/types/tsconfig.json" } ``` + +Run `npx nitropack prepare` to generate the types for global auto-imports. This can be useful in a CI environment or as a `postinstall` command in your `package.json`. diff --git a/docs/content/2.deploy/providers/cloudflare.md b/docs/content/2.deploy/providers/cloudflare.md index a8f03d047c..f860c28c82 100644 --- a/docs/content/2.deploy/providers/cloudflare.md +++ b/docs/content/2.deploy/providers/cloudflare.md @@ -7,7 +7,6 @@ description: 'Discover Cloudflare preset for Nitro!' **Preset:** `cloudflare` ([switch to this preset](/deploy/#changing-the-deployment-preset)) - ::alert{type="info"} **Note:** This preset uses [service-worker syntax](https://developers.cloudflare.com/workers/learning/service-worker/) for deployment. :: diff --git a/src/cli.ts b/src/cli.ts index eafebec635..a748881d50 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -3,7 +3,7 @@ import mri from "mri"; import { resolve } from "pathe"; import { createNitro } from "./nitro"; -import { build, prepare, copyPublicAssets } from "./build"; +import { build, prepare, copyPublicAssets, writeTypes } from "./build"; import { prerender } from "./prerender"; import { createDevServer } from "./dev/server"; @@ -12,6 +12,15 @@ async function main() { const command = args._[0]; const rootDir = resolve(args._[1] || "."); + if (command === "prepare") { + const nitro = await createNitro({ + rootDir, + dev: true, + }); + await writeTypes(nitro); + return; + } + if (command === "dev") { const nitro = await createNitro({ rootDir, From 73184405e936a87e3daf970e8d67d53696e43494 Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Wed, 21 Dec 2022 15:38:52 +0100 Subject: [PATCH 2/2] refactor(cli): drop `dev` option for `prepare` command --- src/cli.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index a748881d50..5d9c63e1ce 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -13,10 +13,7 @@ async function main() { const rootDir = resolve(args._[1] || "."); if (command === "prepare") { - const nitro = await createNitro({ - rootDir, - dev: true, - }); + const nitro = await createNitro({ rootDir }); await writeTypes(nitro); return; }