This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxi):
nuxi build-module
command (#7610)
Co-authored-by: Pooya Parsa <[email protected]>
- Loading branch information
1 parent
bdb6e32
commit 8f7a7ec
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# `nuxi build-module` | ||
|
||
```{bash} | ||
npx nuxi build-module [--stub] [rootDir] | ||
``` | ||
|
||
The `build-module` command runs `@nuxt/module-builder` to generate `dist` directory within your `rootDir` that contains the full build for your **nuxt-module**. | ||
|
||
Option | Default | Description | ||
-------------------------|-----------------|------------------ | ||
`rootDir` | `.` | The root directory of the module to bundle. | ||
`--stub` | `false` | Stub out your module for development using [jiti](https://github.com/unjs/jiti#jiti). (**note:** This is mainly for development purposes.) | ||
|
||
::alert | ||
This command is only available when you are using `@nuxt/module-builder` to build your module. Please see [this readme](https://github.com/nuxt/module-builder#-nuxt-module-builder) for more information. | ||
:: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { execa } from 'execa' | ||
import consola from 'consola' | ||
import { resolve } from 'pathe' | ||
import { tryResolveModule } from '../utils/cjs' | ||
import { defineNuxtCommand } from './index' | ||
|
||
const MODULE_BUILDER_PKG = '@nuxt/module-builder' | ||
|
||
export default defineNuxtCommand({ | ||
meta: { | ||
name: 'build-module', | ||
usage: 'npx nuxi build-module [--stub] [rootDir]', | ||
description: `Helper command for using ${MODULE_BUILDER_PKG}` | ||
}, | ||
async invoke (args) { | ||
// Find local installed version | ||
const rootDir = resolve(args._[0] || '.') | ||
const hasLocal = tryResolveModule(`${MODULE_BUILDER_PKG}/package.json`, rootDir) | ||
|
||
const execArgs = Object.entries({ | ||
'--stub': args.stub | ||
}).filter(([, value]) => value).map(([key]) => key) | ||
|
||
let cmd = 'nuxt-module-build' | ||
if (!hasLocal) { | ||
consola.warn(`Cannot find locally installed version of \`${MODULE_BUILDER_PKG}\` (>=0.2.0). Falling back to \`npx ${MODULE_BUILDER_PKG}\``) | ||
cmd = 'npx' | ||
execArgs.unshift(MODULE_BUILDER_PKG) | ||
} | ||
|
||
await execa(cmd, execArgs, { preferLocal: true, stdio: 'inherit', cwd: rootDir }) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters