-
Notifications
You must be signed in to change notification settings - Fork 2.9k
DONT MERGE: feat(@fluentui/cli): experimental CLI for all fluentui things #35834
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
Draft
Hotell
wants to merge
9
commits into
master
Choose a base branch
from
experimental/fluent-cli
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+9,511
−1
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4b604bf
initial plan
dmytrokirpa 09aa6bb
wip
dmytrokirpa d9ac838
feat: add fluentui-migrate-v8-to-v9 skill
dmytrokirpa e1af8a9
feat(cli): bootstrap fluentui-cli (#35829)
Hotell 15f6120
feat(fluentui-cli): bootstrap commands infra (#35830)
Hotell 5489cb9
Merge branch 'master' into experimental/fluent-cli
Hotell 6d81861
Merge branch 'master' into experimental/fluent-cli
Hotell e568178
feat(fluent-cli): implement migrate v8-to-v9 command and skill (#35836)
dmytrokirpa 7aff395
feat(cli): add banner (#35841)
Hotell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,116 @@ | ||
| --- | ||
| name: fluentui-cli | ||
| description: 'Guides working with @fluentui/cli — the internal Fluent UI command-line tool. Use when asked to add a new CLI command, modify an existing command, understand CLI architecture, debug CLI issues, or work with the CLI build/test workflow. Covers: architecture overview, yargs conventions, lazy-loading pattern, testing, and available Nx generators.' | ||
| --- | ||
|
|
||
| # `@fluentui/cli` | ||
|
|
||
| The `@fluentui/cli` package (`tools/cli/`) is the internal Fluent UI command-line tool built with **yargs**. It uses a modular, lazy-loading architecture where each command lives in its own directory and is only loaded at runtime when invoked. | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### File Structure | ||
|
|
||
| ``` | ||
| tools/cli/ | ||
| ├── bin/fluentui-cli.js # Node entry point (requires compiled output) | ||
| ├── src/ | ||
| │ ├── cli.ts # Main yargs setup, registers all commands | ||
| │ ├── index.ts # Public API re-exports | ||
| │ ├── utils/ | ||
| │ │ ├── index.ts # Barrel exports | ||
| │ │ └── types.ts # Shared CommandHandler type | ||
| │ └── commands/ | ||
| │ ├── migrate/ # Command module | ||
| │ │ ├── index.ts # CommandModule definition (eagerly loaded) | ||
| │ │ ├── handler.ts # Handler implementation (lazy-loaded) | ||
| │ │ └── handler.spec.ts # Tests | ||
| │ └── report/ # Command module | ||
| │ ├── index.ts | ||
| │ ├── handler.ts | ||
| │ └── handler.spec.ts | ||
| ``` | ||
|
|
||
| ### Lazy Loading Pattern | ||
|
|
||
| Command definitions (name, description, options builder) are eagerly imported — they are lightweight. The actual handler logic is **lazy-loaded via dynamic `import()`** only when the command is invoked: | ||
|
|
||
| ```typescript | ||
| // index.ts — always loaded (lightweight) | ||
| handler: async argv => { | ||
| // handler.ts only loaded when this specific command runs | ||
| const { handler } = await import('./handler'); | ||
| return handler(argv); | ||
| }, | ||
| ``` | ||
|
|
||
| This means running `fluentui-cli migrate` will never load the code for `report` or any other command. | ||
|
|
||
| ### CommandHandler Type | ||
|
|
||
| All handlers use the shared `CommandHandler<T>` type from `src/utils/types.ts`: | ||
|
|
||
| ```typescript | ||
| import type { ArgumentsCamelCase } from 'yargs'; | ||
|
|
||
| export type CommandHandler<T = {}> = (argv: ArgumentsCamelCase<T>) => Promise<void>; | ||
| ``` | ||
|
|
||
| ### Command Registration in cli.ts | ||
|
|
||
| Each command is imported and registered in `tools/cli/src/cli.ts`: | ||
|
|
||
| ```typescript | ||
| import yargs from 'yargs'; | ||
| import migrateCommand from './commands/migrate'; | ||
| import reportCommand from './commands/report'; | ||
|
|
||
| export async function main(argv: string[]): Promise<void> { | ||
| await yargs(argv) | ||
| .scriptName('fluentui-cli') | ||
| .usage('$0 <command> [options]') | ||
| .command(migrateCommand) | ||
| .command(reportCommand) | ||
| .demandCommand(1, 'You need to specify a command to run.') | ||
| .help() | ||
| .strict() | ||
| .parse(); | ||
| } | ||
| ``` | ||
|
|
||
| ## Build & Test | ||
|
|
||
| ```sh | ||
| # Build the CLI | ||
| yarn nx run cli:build | ||
|
|
||
| # Run tests | ||
| yarn nx run cli:test | ||
|
|
||
| # Test --help output | ||
| node tools/cli/bin/fluentui-cli.js --help | ||
| node tools/cli/bin/fluentui-cli.js <command-name> --help | ||
| ``` | ||
|
|
||
| ## Conventions | ||
|
|
||
| - **Always use the Nx generator** to scaffold new commands — do not create command files manually. See the [adding commands](references/adding-commands.md) reference. | ||
| - Place shared utilities in `tools/cli/src/utils/` and export through the barrel file. | ||
| - Every command must support `--help` (handled by yargs `.help()` in the builder). | ||
| - Handler files must export a named `handler` constant typed with `CommandHandler<T>`. | ||
| - Tests live adjacent to handlers as `handler.spec.ts`. | ||
|
|
||
| ## Common Patterns | ||
|
|
||
| ### Subcommands (nested commands) | ||
|
|
||
| If a command needs subcommands, use yargs nested command pattern in the builder: | ||
|
|
||
| ```typescript | ||
| builder: yargs => | ||
| yargs | ||
| .command('run', 'Run migrations', subBuilder => subBuilder, subHandler) | ||
| .command('list', 'List available migrations', subBuilder => subBuilder, subHandler) | ||
| .demandCommand(1) | ||
| .help(), | ||
| ``` | ||
135 changes: 135 additions & 0 deletions
135
.github/skills/fluentui-cli/references/adding-commands.md
This file contains hidden or 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,135 @@ | ||
| # Adding a New CLI Command | ||
|
|
||
| ## Step 1 — Scaffold the Command | ||
|
|
||
| Run the `cli-command` Nx generator: | ||
|
|
||
| ```sh | ||
| yarn nx g @fluentui/workspace-plugin:cli-command <command-name> --description "<short description>" | ||
| ``` | ||
|
|
||
| ### Example | ||
|
|
||
| ```sh | ||
| yarn nx g @fluentui/workspace-plugin:cli-command analyze --description "Analyze bundle sizes" | ||
| ``` | ||
|
|
||
| ### What Gets Generated | ||
|
|
||
| ``` | ||
| tools/cli/src/commands/<command-name>/ | ||
| ├── index.ts # Yargs CommandModule definition (lightweight, eagerly loaded) | ||
| ├── handler.ts # Handler implementation (lazy-loaded via dynamic import) | ||
| └── handler.spec.ts # Jest unit tests for the handler | ||
| ``` | ||
|
|
||
| The generator also **automatically registers** the new command in `tools/cli/src/cli.ts` by: | ||
|
|
||
| 1. Adding an import statement for the command module | ||
| 2. Adding a `.command()` registration call | ||
|
|
||
| Preview what will be generated without writing to disk: | ||
|
|
||
| ```sh | ||
| yarn nx g @fluentui/workspace-plugin:cli-command <command-name> --dry-run | ||
| ``` | ||
|
|
||
| ## Step 2 — Implement the Handler | ||
|
|
||
| Open `tools/cli/src/commands/<command-name>/handler.ts` and implement the command logic: | ||
|
|
||
| ```typescript | ||
| import type { CommandHandler } from '../../utils/types'; | ||
|
|
||
| // Define the shape of your command's arguments | ||
| interface AnalyzeArgs { | ||
| project?: string; | ||
| verbose?: boolean; | ||
| } | ||
|
|
||
| export const handler: CommandHandler<AnalyzeArgs> = async argv => { | ||
| const { project, verbose } = argv; | ||
|
|
||
| // Your implementation here | ||
| console.log(`Analyzing${project ? ` project: ${project}` : ''}...`); | ||
| }; | ||
| ``` | ||
|
|
||
| ## Step 3 — Add Options and Arguments | ||
|
|
||
| Edit `tools/cli/src/commands/<command-name>/index.ts` to add yargs options in the `builder`: | ||
|
|
||
| ```typescript | ||
| import type { CommandModule } from 'yargs'; | ||
|
|
||
| const command: CommandModule = { | ||
| command: 'analyze', | ||
| describe: 'Analyze bundle sizes', | ||
| builder: yargs => | ||
| yargs | ||
| .option('project', { | ||
| alias: 'p', | ||
| type: 'string', | ||
| describe: 'Project name to analyze', | ||
| }) | ||
| .option('verbose', { | ||
| type: 'boolean', | ||
| default: false, | ||
| describe: 'Show detailed output', | ||
| }) | ||
| .version(false) | ||
| .help(), | ||
| handler: async argv => { | ||
| const { handler } = await import('./handler'); | ||
| return handler(argv); | ||
| }, | ||
| }; | ||
|
|
||
| export default command; | ||
| ``` | ||
|
|
||
| ## Step 4 — Write Tests | ||
|
|
||
| Update `tools/cli/src/commands/<command-name>/handler.spec.ts` with meaningful tests: | ||
|
|
||
| ```typescript | ||
| import { handler } from './handler'; | ||
|
|
||
| describe('analyze handler', () => { | ||
| let logSpy: jest.SpyInstance; | ||
|
|
||
| beforeEach(() => { | ||
| logSpy = jest.spyOn(console, 'log').mockImplementation(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| logSpy.mockRestore(); | ||
| }); | ||
|
|
||
| it('should analyze all projects when no project specified', async () => { | ||
| await handler({ _: ['analyze'], $0: 'fluentui-cli' }); | ||
|
|
||
| expect(logSpy).toHaveBeenCalledWith('Analyzing...'); | ||
| }); | ||
|
|
||
| it('should analyze specific project when specified', async () => { | ||
| await handler({ _: ['analyze'], $0: 'fluentui-cli', project: 'react-button' }); | ||
|
|
||
| expect(logSpy).toHaveBeenCalledWith('Analyzing project: react-button...'); | ||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
| ## Step 5 — Verify | ||
|
|
||
| ```sh | ||
| # Build the CLI | ||
| yarn nx run cli:build | ||
|
|
||
| # Run tests | ||
| yarn nx run cli:test | ||
|
|
||
| # Test --help output | ||
| node tools/cli/bin/fluentui-cli.js --help | ||
| node tools/cli/bin/fluentui-cli.js <command-name> --help | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
🕵🏾♀️ visual changes to review in the Visual Change Report
vr-tests-react-components/CalendarCompat 4 screenshots
vr-tests-react-components/Menu Converged - submenuIndicator slotted content 2 screenshots
vr-tests-react-components/Positioning 2 screenshots
vr-tests-react-components/TagPicker 4 screenshots
vr-tests-web-components/Avatar 2 screenshots
vr-tests-web-components/MenuList 1 screenshots
vr-tests/Callout 5 screenshots
vr-tests/Keytip 2 screenshots
vr-tests/react-charting-AreaChart 1 screenshots
vr-tests/react-charting-MultiStackBarChart 3 screenshots
vr-tests/react-charting-SankeyChart 1 screenshots
vr-tests/react-charting-VerticalBarChart 1 screenshots
There were 5 duplicate changes discarded. Check the build logs for more information.