-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom CLI Commands #11
Labels
Comments
pi0
changed the title
[RFC] support adding sub-command to cli
support adding sub-command to cli
Nov 18, 2018
pi0
changed the title
support adding sub-command to cli
Support adding Sub-Command to CLI
Nov 18, 2018
Thanks for the write-up @pi0 -- It's pretty clear to me that Option 1 is the way to go. Thanks for laying out all pros and cons so thoroughly. Unless anyone wants to voice more concerns, I'm gonna start making the necessary changes in nuxt/nuxt#4314 towards that direction. |
👍 for Option 1 |
Let's go for Option 1, awesome write up @pi0, really impressed by it and the time you put into it. |
Implemented |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Related to #10.
Related PR: nuxt/nuxt#4314
Original idea: @galvez
TLDR
A limitation of current module spec is that it doesn't allow adding new commands. We can't add helpers to the module function body because commands are executed before of nuxt instance initialization.
Different ways
1. Universal approach
The
@nuxt/cli
package exports useful functions to create a good CLI command interface and also benefits of nuxt built-in utilities like config loading and fancy CLI. This pattern allows module package authors to easily create their ownbin/
commands with help of a nuxt core module that is also semi-compatible with nuxt projects lower than2.3.0
.Positive points:
@nuxt/cli
version or extend/customizeNuxtCommand
class.Negative points:
nuxt help
is hard but lightweight (Scan path)Appendix:
For sub-commands support, nuxt CLI can simply map
nuxt foo
intonuxt-foo
andnuxt foo bar
intonuxt-foo-bar
command and execute it. Preferring convention over platform/PM complexities.2.
js
files that@nuxt/cli
execute themThe process of adding a command to modules is like creating
node_modules/my-module/bin/custom.js
that exports a command object like nuxt internal commands. Then by invokingnpx nuxt my-command custom
nuxt will search forcustom
command, wraps it intoNuxtCommand
and runs it.Positive points:
Negative points:
>=2.3.0
ModuleContainer
(Module Improvements #10). The command is implicitly wrapped and command author is not aware who is calling it and what functions exist innuxtCommand
node_modules
is not either easy or stable. Different package managers and ways to run are involved (NPX, global cli)3. Via module
commands
exportModule authors can attach module exported commands to the exported function
commands
object like this:Positive points:
nuxt.config.js
or writing commands in the same file ofmodule.js
options.modules
)Negative points:
>= 2.3.0
ModuleContainer
(Module Improvements #10). The command is implicitly wrapped and command author is not aware who is calling it and what functions exist innuxtCommand
The text was updated successfully, but these errors were encountered: