Skip to content

Commit

Permalink
feat: prepare CLI command
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Dec 21, 2022
1 parent fc75d47 commit e6a6622
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
1 change: 0 additions & 1 deletion docs/content/1.guide/1.introduction/0.getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions docs/content/1.guide/1.introduction/2.auto-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/content/1.guide/1.introduction/7.typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 0 additions & 1 deletion docs/content/2.deploy/providers/cloudflare.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
::
Expand Down
11 changes: 10 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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,
Expand Down

0 comments on commit e6a6622

Please sign in to comment.