-
Notifications
You must be signed in to change notification settings - Fork 53
refactor: use yargs for the cli #791
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: a160fb5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks for the PR.
Does it still work as expected when there is a --
?
I'll take one more look tomorrow
Unknown args and args after If |
Is it what we want? |
import { createOpenNextConfigIfNotExistent } from "../build/utils/create-config-files.js"; | ||
import { setupCLI, withWranglerOptions, withWranglerPassthroughArgs } from "./setup-cli.js"; | ||
|
||
async function buildCommand(args: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add some JSDoc here.
i.e. does wranglerArgs
contain config and env ?
Something like:
/**
* Implementation of the `opennextjs- clouflare command`
*
* @param ...
* @returns
*/
An explicit return type would be nice too
return buildImpl(options, config, { ...args, minify: !args.noMinify, sourceDir: baseDir }, wranglerConfig); | ||
} | ||
|
||
export function addBuildCommand<T extends yargs.Argv>(y: T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function addBuildCommand<T extends yargs.Argv>(y: T) { | |
/** | |
* Add the `build` command to yargs configuration | |
* | |
* Consumes 1 positional parameter | |
*/ | |
export function addBuildCommand<T extends yargs.Argv>(y: T) { |
|
||
async function buildCommand(args: { | ||
wranglerArgs: string[]; | ||
config: string | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename this to configPath
(we also use config
for the values in i.e. populateR2IncrementalCache
)
const nextAppDir = process.cwd(); | ||
|
||
/** | ||
* Setup the CLI, print necessary messages, and retrieve various options and configs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setupCompiledAppCLI
has the same comment.
What's the difference, when to use which ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC the callback is to do some work in the middle of this function.
Another way could be do move this to the caller:
ShowHeader();
CompileConfig(); // for build
LoadConfig(); // for other commands
ExecuteCommand();
Not sure if this would make the code easier to follow?
}); | ||
} | ||
|
||
export function withWranglerOptions<T extends yargs.Argv>(args: T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some JSDoc would help for those 3 functions
|
||
async function runCommand(args: Arguments) { | ||
printHeader(`Cloudflare ${args.command}`); | ||
y = addBuildCommand(y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this can return y for chaining?
Up to you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
I think more comments might help maintaining this code in the future
Changes
output
arg as it was never used.--env
and--config
become proper first class citizens.Replaces #790
Commands Tested
build
preview
deploy
upload
populateCache