Browse Source

update: ai-tool usage examples

pull/23910/head
sumeyye 6 months ago
parent
commit
2f61a755fb
  1. 41
      npm/ng-packs/packages/schematics/src/commands/ai-config/index.ts

41
npm/ng-packs/packages/schematics/src/commands/ai-config/index.ts

@ -1,4 +1,14 @@
import { Rule, SchematicsException, Tree, apply, url, mergeWith, MergeStrategy, filter, chain } from '@angular-devkit/schematics'; import {
Rule,
SchematicsException,
Tree,
apply,
url,
mergeWith,
MergeStrategy,
filter,
chain,
} from '@angular-devkit/schematics';
import { join, normalize } from '@angular-devkit/core'; import { join, normalize } from '@angular-devkit/core';
import { AiConfigSchema, AiTool } from './model'; import { AiConfigSchema, AiTool } from './model';
import { getWorkspace } from '../../utils'; import { getWorkspace } from '../../utils';
@ -10,21 +20,21 @@ export default function (options: AiConfigSchema): Rule {
console.log(''); console.log('');
console.log('💡 Usage examples:'); console.log('💡 Usage examples:');
console.log(' ng g @abp/ng.schematics:ai-config --tool=claude,cursor'); console.log(' ng g @abp/ng.schematics:ai-config --tool=claude,cursor');
console.log(' ng g @abp/ng.schematics:ai-config --tool="claude, cursor"');
console.log(' ng g @abp/ng.schematics:ai-config --tool=gemini --tool=cursor');
console.log(' ng g @abp/ng.schematics:ai-config --tool=gemini --target-project=my-app'); console.log(' ng g @abp/ng.schematics:ai-config --tool=gemini --target-project=my-app');
console.log(''); console.log('');
console.log('Available tools: claude, copilot, cursor, gemini, junie, windsurf'); console.log('Available tools: claude, copilot, cursor, gemini, junie, windsurf');
return tree; return tree;
} }
const tools = options.tool const tools = options.tool.split(/[\s,]+/).filter(t => t) as AiTool[];
.split(/[\s,]+/)
.filter(t => t) as AiTool[];
const validTools: AiTool[] = ['claude', 'copilot', 'cursor', 'gemini', 'junie', 'windsurf']; const validTools: AiTool[] = ['claude', 'copilot', 'cursor', 'gemini', 'junie', 'windsurf'];
const invalidTools = tools.filter(tool => !validTools.includes(tool)); const invalidTools = tools.filter(tool => !validTools.includes(tool));
if (invalidTools.length > 0) { if (invalidTools.length > 0) {
throw new SchematicsException( throw new SchematicsException(
`Invalid AI tool(s): ${invalidTools.join(', ')}. Valid options are: ${validTools.join(', ')}` `Invalid AI tool(s): ${invalidTools.join(', ')}. Valid options are: ${validTools.join(', ')}`,
); );
} }
@ -40,9 +50,7 @@ export default function (options: AiConfigSchema): Rule {
const trimmedTargetProject = options.targetProject.trim(); const trimmedTargetProject = options.targetProject.trim();
const project = workspace.projects.get(trimmedTargetProject); const project = workspace.projects.get(trimmedTargetProject);
if (!project) { if (!project) {
throw new SchematicsException( throw new SchematicsException(`Project "${trimmedTargetProject}" not found in workspace.`);
`Project "${trimmedTargetProject}" not found in workspace.`
);
} }
targetPath = normalize(project.root); targetPath = normalize(project.root);
} }
@ -51,24 +59,25 @@ export default function (options: AiConfigSchema): Rule {
console.log(`📁 Target path: ${targetPath}`); console.log(`📁 Target path: ${targetPath}`);
console.log(`🤖 Selected tools: ${tools.join(', ')}`); console.log(`🤖 Selected tools: ${tools.join(', ')}`);
const rules: Rule[] = tools const rules: Rule[] = tools.map(tool =>
.map(tool => generateConfigForTool(tool, targetPath, options.overwrite || false)); generateConfigForTool(tool, targetPath, options.overwrite || false),
);
return chain([ return chain([
...rules, ...rules,
(tree: Tree) => { (tree: Tree) => {
console.log('✅ AI configuration files generated successfully!'); console.log('✅ AI configuration files generated successfully!');
console.log('\n📝 Generated files:'); console.log('\n📝 Generated files:');
tools.forEach(tool => { tools.forEach(tool => {
const configPath = getConfigPath(tool, targetPath); const configPath = getConfigPath(tool, targetPath);
console.log(` - ${configPath}`); console.log(` - ${configPath}`);
}); });
console.log('\n💡 Tip: Restart your IDE or AI tool to apply the new configurations.'); console.log('\n💡 Tip: Restart your IDE or AI tool to apply the new configurations.');
return tree; return tree;
} },
]); ]);
}; };
} }
@ -76,7 +85,7 @@ export default function (options: AiConfigSchema): Rule {
function generateConfigForTool(tool: AiTool, targetPath: string, overwrite: boolean): Rule { function generateConfigForTool(tool: AiTool, targetPath: string, overwrite: boolean): Rule {
return (tree: Tree) => { return (tree: Tree) => {
const configPath = getConfigPath(tool, targetPath); const configPath = getConfigPath(tool, targetPath);
if (tree.exists(configPath) && !overwrite) { if (tree.exists(configPath) && !overwrite) {
console.log(`⚠️ Configuration file already exists: ${configPath}`); console.log(`⚠️ Configuration file already exists: ${configPath}`);
console.log(` Use --overwrite flag to replace existing files.`); console.log(` Use --overwrite flag to replace existing files.`);
@ -87,7 +96,7 @@ function generateConfigForTool(tool: AiTool, targetPath: string, overwrite: bool
const source = apply(url(sourceDir), [ const source = apply(url(sourceDir), [
filter(path => { filter(path => {
return !path.endsWith('.DS_Store'); return !path.endsWith('.DS_Store');
}) }),
]); ]);
return mergeWith(source, overwrite ? MergeStrategy.Overwrite : MergeStrategy.Default); return mergeWith(source, overwrite ? MergeStrategy.Overwrite : MergeStrategy.Default);
@ -101,7 +110,7 @@ function getConfigPath(tool: AiTool, basePath: string): string {
cursor: '.cursor/rules/cursor.mdc', cursor: '.cursor/rules/cursor.mdc',
gemini: '.gemini/GEMINI.md', gemini: '.gemini/GEMINI.md',
junie: '.junie/guidelines.md', junie: '.junie/guidelines.md',
windsurf: '.windsurf/rules/guidelines.md' windsurf: '.windsurf/rules/guidelines.md',
}; };
const configFile = configFiles[tool]; const configFile = configFiles[tool];

Loading…
Cancel
Save