Skip to content

feat(@angular/cli): introduce setup-gemini-cli command with a Gemini CLI extension #30799

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ dist/
/tests/legacy-cli/e2e/assets/
/tools/test/*.json
pnpm-lock.yaml

# This is a symbolic link.
packages/angular/cli/src/commands/ai/setup-gemini-cli/extension/GEMINI.md
40 changes: 40 additions & 0 deletions packages/angular/cli/src/commands/ai/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import { join } from 'node:path';
import { Argv } from 'yargs';
import {
CommandModule,
CommandModuleImplementation,
CommandScope,
Options,
} from '../../command-builder/command-module';
import {
addCommandModuleToYargs,
demandCommandFailureMessage,
} from '../../command-builder/utilities/command';
import SetupGeminiCliModule from './setup-gemini-cli/cli';

export default class AiCommandModule extends CommandModule implements CommandModuleImplementation {
command = 'ai';
describe = 'Commands for artificial intelligence.';
longDescriptionPath = undefined;
override scope = CommandScope.Both;

builder(localYargs: Argv): Argv {
const subcommands = [SetupGeminiCliModule].sort();

for (const module of subcommands) {
addCommandModuleToYargs(module, this.context);
}

return localYargs.demandCommand(1, demandCommandFailureMessage).strict();
}

run(_options: Options<{}>): void {}
}
43 changes: 43 additions & 0 deletions packages/angular/cli/src/commands/ai/setup-gemini-cli/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import { cp, mkdir } from 'node:fs/promises';
import { homedir } from 'node:os';
import { join } from 'node:path';
import { Argv } from 'yargs';
import {
CommandModule,
CommandModuleImplementation,
CommandScope,
Options,
} from '../../../command-builder/command-module';

export default class SetupGeminiCliModule
extends CommandModule
implements CommandModuleImplementation
{
command = 'setup-gemini-cli';
describe = 'Sets up Gemini CLI with the official Angular extension.';
longDescriptionPath?: string | undefined;

override scope = CommandScope.Both;

builder(localYargs: Argv): Argv {
return localYargs.strict();
}

async run(_options: Options<{}>): Promise<void> {
const extensionDir = join(__dirname, './extension');
const extensionUserDir = join(homedir(), '.gemini', 'extensions', 'angular');

await mkdir(extensionUserDir, { recursive: true });
await cp(extensionDir, extensionUserDir, { recursive: true, dereference: true });

this.context.logger.info(`✅ Installed the Angular Gemini CLI extension.`);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Angular",
"version": "0.0.0-PLACEHOLDER",
"mcpServers": {},
"contextFileName": "./GEMINI.md"
}
4 changes: 4 additions & 0 deletions packages/angular/cli/src/commands/command-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CommandModuleConstructor } from '../command-builder/utilities/command';

export type CommandNames =
| 'add'
| 'ai'
| 'analytics'
| 'build'
| 'cache'
Expand Down Expand Up @@ -41,6 +42,9 @@ export const RootCommands: Record<
'add': {
factory: () => import('./add/cli'),
},
'ai': {
factory: () => import('./ai/cli'),
},
'analytics': {
factory: () => import('./analytics/cli'),
},
Expand Down
19 changes: 19 additions & 0 deletions tests/legacy-cli/e2e/tests/commands/ai/setup-gemini-cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { join } from 'node:path';
import { expectFileNotToExist, expectFileToExist, expectFileToMatch } from '../../../utils/fs';
import { ng } from '../../../utils/process';
import assert from 'node:assert';

export default async function () {
assert(process.env.HOME, 'Expected HOME directory to be set.');

const extensionDir = join(process.env.HOME, '.gemini', 'extensions', 'angular');
const geminiBestPracticesFile = join(extensionDir, 'GEMINI.md');

await expectFileNotToExist(extensionDir);
await expectFileNotToExist(geminiBestPracticesFile);
await ng('ai', 'setup-gemini-cli');

await expectFileToExist(extensionDir);
await expectFileToExist(geminiBestPracticesFile);
await expectFileToMatch(geminiBestPracticesFile, 'Angular Best Practices');
}
Loading