Skip to content

Commit

Permalink
feat: update command
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Feb 13, 2025
1 parent 88241e4 commit a908103
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
5 changes: 3 additions & 2 deletions src/recipes/ai-context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { promises as fs } from 'node:fs'
import { dirname } from 'node:path'

const ATTRIBUTES_REGEX = /(\S*)="([^\s"]*)"/gim
const BASE_URL = 'https://docs.netlify.com/ai-context'
export const FILE_NAME = 'netlify-development.mdc'
const MINIMUM_CLI_VERSION_HEADER = 'x-cli-min-ver'
export const NETLIFY_PROVIDER = 'netlify'
const PROVIDER_CONTEXT_REGEX = /<providercontext ([^>]*)>(.*)<\/providercontext>/ims
const PROVIDER_CONTEXT_OVERRIDES_REGEX = /<providercontextoverrides([^>]*)>(.*)<\/providercontextoverrides>/ims
const PROVIDER_CONTEXT_OVERRIDES_TAG = 'ProviderContextOverrides'
const BASE_URL = 'https://docs.netlify.com/ai-context/netlify-development.mdc'

export const downloadFile = async (cliVersion: string) => {
try {
const res = await fetch(BASE_URL, {
const res = await fetch(`${BASE_URL}/${FILE_NAME}`, {
headers: {
'user-agent': `NetlifyCLI ${cliVersion}`,
},
Expand Down
74 changes: 37 additions & 37 deletions src/recipes/ai-context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,55 @@ import {
getExistingContext,
parseContextFile,
writeFile,
FILE_NAME,
NETLIFY_PROVIDER,
} from './context.js'

export const description = 'Create and update context files for AI tools'
export const description = 'Manage context files for AI tools'

const toolOptions = [
{ name: 'Cursor', value: 'cursor' },
{ name: 'Other', value: '' },
const presets = [
{ name: 'Cursor rules (.cursor/rules/)', value: '.cursor/rules' },
{ name: 'Custom location', value: '' },
]

const TOOLS = {
cursor: '.cursor/rules/netlify_development_rules.mdc',
const promptForPath = async (): Promise<string> => {
const { presetPath } = await inquirer.prompt([
{
name: 'presetPath',
message: 'Where should we put the context files?',
type: 'list',
choices: presets,
},
])

if (presetPath) {
return presetPath
}

const { customPath } = await inquirer.prompt([
{
type: 'input',
name: 'customPath',
message: 'Enter the path, relative to the project root, where the context files should be placed',
default: './ai-context',
},
])

if (customPath) {
return customPath
}

log('You must select a path.')

return promptForPath()
}

export const run = async ({ args, command }: RunRecipeOptions) => {
// Start the download in the background while we wait for the prompts.
// eslint-disable-next-line promise/prefer-await-to-then
const download = downloadFile(version).catch(() => null)

let [tool] = args

if (!tool) {
const { selectedTool } = await inquirer.prompt([
{
name: 'selectedTool',
message: "Select the AI tool you're working with",
type: 'list',
choices: toolOptions,
},
])

tool = selectedTool
}

let filePath = TOOLS[tool as keyof typeof TOOLS]

if (!filePath) {
const { selectedPath } = await inquirer.prompt([
{
type: 'input',
name: 'selectedPath',
message: 'Enter the path, relative to the project root, where the context files should be placed',
default: './ai-context/netlify_development_rules.mdc',
},
])

filePath = selectedPath
}

const filePath = args[0] || (await promptForPath())
const { contents: downloadedFile, minimumCLIVersion } = (await download) ?? {}

if (!downloadedFile) {
Expand All @@ -79,7 +79,7 @@ export const run = async ({ args, command }: RunRecipeOptions) => {
return
}

const absoluteFilePath = resolve(command?.workingDir ?? '', filePath)
const absoluteFilePath = resolve(command?.workingDir ?? '', filePath, FILE_NAME)
const existing = await getExistingContext(absoluteFilePath)
const remote = parseContextFile(downloadedFile)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`commands/recipes > Shows a list of all the available recipes 1`] = `
|-----------------------------------------------------------------------------------------|
| Name | Description |
|---------------|-------------------------------------------------------------------------|
| ai-context | Manage context files for AI tools |
| blobs-migrate | Migrate legacy Netlify Blobs stores |
| vscode | Create VS Code settings for an optimal experience with Netlify projects |
'-----------------------------------------------------------------------------------------'"
Expand Down

0 comments on commit a908103

Please sign in to comment.