From 21743e2937313f307e4438b1315c0cbaa5922ab4 Mon Sep 17 00:00:00 2001 From: Gordon Mickel Date: Sat, 20 Jul 2024 10:04:20 +0200 Subject: [PATCH] fix: windows paths and line-endings --- cli.js | 15 +- codewhisper.md | 2981 ++++++++++++++++++++++++++++++++ src/core/markdown-generator.ts | 5 +- 3 files changed, 2989 insertions(+), 12 deletions(-) create mode 100644 codewhisper.md diff --git a/cli.js b/cli.js index 866b8a2..f4ef31e 100755 --- a/cli.js +++ b/cli.js @@ -1,24 +1,17 @@ -#!/usr/bin/env node - import path from 'node:path'; import url from 'node:url'; -// Determine the directory of the current file const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); -// Determine the correct path to the built CLI entry point let cliPath; -if (__dirname.includes('/dist')) { - // In production, use the built ESM module - cliPath = path.resolve(__dirname, 'cli/index.js'); +if (__dirname.includes(`${path.sep}dist`)) { + cliPath = path.resolve(__dirname, 'cli', 'index.js'); } else { - // In development, use the TypeScript source file - cliPath = path.resolve(__dirname, 'src/cli/index.ts'); + cliPath = path.resolve(__dirname, 'src', 'cli', 'index.ts'); } -import(cliPath) +import(url.pathToFileURL(cliPath).href) .then((cliModule) => { - // Check compatibly whether default or named export `cli` if (cliModule.default) { cliModule.default(process.argv.slice(2)); } else if (cliModule.cli) { diff --git a/codewhisper.md b/codewhisper.md new file mode 100644 index 0000000..6528fb7 --- /dev/null +++ b/codewhisper.md @@ -0,0 +1,2981 @@ +# Code Summary + +- .npmrc +- biome.json +- cli.js +- CONTRIBUTING.md +- lefthook.yml +- LICENSE +- package.json +- pnpm-workspace.yaml +- README.md +- src/cli/git-tools.ts +- src/cli/index.ts +- src/cli/interactive-filtering.ts +- src/core/file-processor.ts +- src/core/file-worker.d.ts +- src/core/file-worker.js +- src/core/markdown-generator.ts +- src/templates/codebase-summary.hbs +- src/templates/deep-code-review.hbs +- src/templates/default.hbs +- src/templates/generate-project-documentation.hbs +- src/templates/generate-readme.hbs +- src/templates/minimal.hbs +- src/templates/optimize-llm-prompt.hbs +- src/templates/security-focused-review.hbs +- src/utils/comment-stripper.ts +- src/utils/file-cache.ts +- src/utils/gitignore-parser.ts +- src/utils/language-detector.ts +- tests/e2e/cli-commands.test.ts +- tests/fixtures/custom-template.hbs +- tests/fixtures/default.hbs +- tests/fixtures/test-project/package.json +- tests/fixtures/test-project/src/main.js +- tests/fixtures/test-project/src/utils.ts +- tests/helpers/gitignore-helper.ts +- tests/integration/markdown-generation.test.ts +- tests/performance/file-processor.perf.test.ts +- tests/unit/file-processor.test.ts +- tests/unit/markdown-generator.test.ts +- tests/utils/language-detector.test.ts +- tests/vitest.setup.ts +- tsconfig.build.json +- tsconfig.json +- tsup.config.ts +- vitest.config.ts + +## Files + +## .npmrc + +- Language: plaintext +- Size: 53 bytes +- Last modified: Mon Jul 08 2024 18:42:50 GMT+0200 (Central European Summer Time) + +```plaintext +ignore-workspace-root-check=true +shell-emulator=true + +``` + +## biome.json + +- Language: json +- Size: 538 bytes +- Last modified: Mon Jul 08 2024 18:45:43 GMT+0200 (Central European Summer Time) + +```json +{ + "$schema": "https://biomejs.dev/schemas/1.6.4/schema.json", + "formatter": { + "indentStyle": "space", + "indentWidth": 2, + "formatWithErrors": true + }, + "javascript": { + "formatter": { + "quoteStyle": "single" + } + }, + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "correctness": { + "noUndeclaredVariables": "warn" + } + } + }, + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + } +} + +``` + +## cli.js + +- Language: javascript +- Size: 953 bytes +- Last modified: Wed Jul 10 2024 10:42:23 GMT+0200 (Central European Summer Time) + +```javascript +#!/usr/bin/env node + +import path from 'node:path'; +import url from 'node:url'; + +// Determine the directory of the current file +const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); + +// Determine the correct path to the built CLI entry point +let cliPath; +if (__dirname.includes('/dist')) { + // In production, use the built ESM module + cliPath = path.resolve(__dirname, 'cli/index.js'); +} else { + // In development, use the TypeScript source file + cliPath = path.resolve(__dirname, 'src/cli/index.ts'); +} + +import(cliPath) + .then((cliModule) => { + // Check compatibly whether default or named export `cli` + if (cliModule.default) { + cliModule.default(process.argv.slice(2)); + } else if (cliModule.cli) { + cliModule.cli(process.argv.slice(2)); + } else { + console.error('CLI function not found in module'); + process.exit(1); + } + }) + .catch((err) => { + console.error(err); + process.exit(1); + }); + +``` + +## CONTRIBUTING.md + +- Language: markdown +- Size: 54 bytes +- Last modified: Tue Jul 09 2024 21:54:14 GMT+0200 (Central European Summer Time) + +```markdown +Please refer to https://github.com/gmickel/contribute + +``` + +## lefthook.yml + +- Language: yaml +- Size: 256 bytes +- Last modified: Tue Jul 09 2024 21:12:51 GMT+0200 (Central European Summer Time) + +```yaml +pre-push: + parallel: true +pre-commit: + commands: + check: + glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}" + run: npx biome check --write --no-errors-on-unmatched --files-ignore-unknown=true {staged_files} && git update-index --again + +``` + +## LICENSE + +- Language: plaintext +- Size: 1088 bytes +- Last modified: Mon Jul 08 2024 18:45:28 GMT+0200 (Central European Summer Time) + +```plaintext +MIT License + +Copyright (c) 2024 Gordon Mickel (git@mickel.tech) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +``` + +## package.json + +- Language: json +- Size: 2492 bytes +- Last modified: Fri Jul 19 2024 01:48:53 GMT+0200 (Central European Summer Time) + +```json +{ + "name": "codewhisper", + "type": "module", + "version": "1.0.0", + "description": "A powerful tool for converting repository code to AI-friendly prompts", + "author": "Gordon Mickel ", + "license": "MIT", + "funding": "https://github.com/sponsors/gmickel", + "homepage": "https://github.com/gmickel/code-whisper#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/gmickel/code-whisper.git" + }, + "bugs": "https://github.com/gmickel/code-whisper/issues", + "keywords": ["code", "ai", "prompt", "git"], + "sideEffects": false, + "exports": { + "./cli": { + "types": "./dist/cli/index.d.ts", + "import": "./dist/cli/index.js" + }, + "./core": { + "types": "./dist/core/file-worker.d.ts", + "import": "./dist/core/file-worker.js" + } + }, + "main": "./dist/cli/index.js", + "module": "./dist/cli/index.js", + "types": "./dist/cli/index.d.ts", + "typesVersions": { + "*": { + "*": ["./dist/*", "./dist/cli/index.d.ts"] + } + }, + "bin": { + "codewhisper": "./dist/cli.js" + }, + "files": ["dist", "README.md", "LICENSE"], + "scripts": { + "prebuild": "pnpm run typecheck", + "build": "tsup", + "lint": "biome check .", + "lint:fix": "biome check . --write", + "prepublishOnly": "nr build", + "release": "bumpp && npm publish", + "dev": "esno src/cli/index.ts", + "start": "node dist/cli/index.js", + "test": "vitest", + "test:ui": "vitest --ui", + "typecheck": "tsc --noEmit", + "prepare": "lefthook install" + }, + "dependencies": { + "@inquirer/prompts": "^5.1.2", + "chalk": "5.3.0", + "commander": "12.1.0", + "fast-glob": "3.3.2", + "fs-extra": "11.2.0", + "handlebars": "4.7.8", + "ignore": "5.3.1", + "inquirer": "9.2.10", + "inquirer-file-tree-selection-prompt": "^2.0.5", + "isbinaryfile": "5.0.2", + "ora": "8.0.1", + "piscina": "4.6.1", + "simple-git": "3.25.0", + "strip-comments": "2.0.1" + }, + "devDependencies": { + "@biomejs/biome": "1.8.3", + "@types/fs-extra": "11.0.4", + "@types/inquirer": "^9.0.7", + "@types/node": "20.14.10", + "@types/strip-comments": "2.0.4", + "@vitest/coverage-v8": "2.0.2", + "@vitest/ui": "2.0.2", + "bumpp": "9.4.1", + "esno": "4.7.0", + "lefthook": "1.7.2", + "tsup": "8.1.0", + "typescript": "5.5.3", + "vite": "5.3.3", + "vitest": "2.0.2" + }, + "packageManager": "pnpm@9.5.0", + "workspaces": ["apps/*", "packages/*"], + "trustedDependencies": ["@biomejs/biome", "lefthook"] +} + +``` + +## pnpm-workspace.yaml + +- Language: yaml +- Size: 64 bytes +- Last modified: Tue Jul 09 2024 23:45:21 GMT+0200 (Central European Summer Time) + +```yaml +packages: + - playground + - docs + - packages/* + - examples/* + +``` + +## README.md + +- Language: markdown +- Size: 1147 bytes +- Last modified: Sat Jul 20 2024 09:54:59 GMT+0200 (Central European Summer Time) + +```markdown +# code-whisper + +add blazing fast AI-friendly prompts to your codebase + +[![npm version][npm-version-src]][npm-version-href] +[![npm downloads][npm-downloads-src]][npm-downloads-href] +[![bundle][bundle-src]][bundle-href] +[![JSDocs][jsdocs-src]][jsdocs-href] +[![License][license-src]][license-href] + +[![CI](https://github.com/gmickel/CodeWhisper/actions/workflows/ci.yml/badge.svg)](https://github.com/gmickel/CodeWhisper/actions/workflows/ci.yml) +[![Known Vulnerabilities](https://snyk.io/test/github/gmickel/CodeWhisper/badge.svg)](https://snyk.io/test/github/gmickel/CodeWhisper) +[![License](https://img.shields.io/github/license/gmickel/CodeWhisper.svg)](https://github.com/gmickel/CodeWhisper/blob/main/LICENSE) + +_description_ + +## Sponsors + +

+ + + + + +

+ +## License + +[MIT](./LICENSE) License Β© 2024-PRESENT [Gordon Mickel](https://github.com/gmickel) + +## Contributors πŸ‘¨β€πŸ’» + + + + +``` + +## src/cli/git-tools.ts + +- Language: typescript +- Size: 1081 bytes +- Last modified: Tue Jul 09 2024 11:07:40 GMT+0200 (Central European Summer Time) + +```typescript +import simpleGit, { type SimpleGit } from 'simple-git'; +import type { FileInfo } from '../core/file-processor'; +import { detectLanguage } from '../utils/language-detector'; + +const git: SimpleGit = simpleGit(); + +export async function gitDiff(branch?: string): Promise { + const diffSummary = await git.diffSummary([branch ?? 'HEAD^']); + + const fileInfos: FileInfo[] = await Promise.all( + diffSummary.files.map(async (file) => { + const content = await git.show([`${branch ?? 'HEAD'}:${file.file}`]); + return { + path: file.file, + extension: file.file.split('.').pop() ?? '', + language: detectLanguage(file.file), + size: content.length, + created: new Date(), + modified: new Date(), + content, + }; + }), + ); + + return fileInfos; +} + +export async function prReview(prNumber: string): Promise { + // This is a placeholder. In a real implementation, you'd use the GitHub API + // to fetch the PR diff and convert it to FileInfo objects. + console.log(`Reviewing PR #${prNumber}`); + return []; +} + +``` + +## src/cli/index.ts + +- Language: typescript +- Size: 5344 bytes +- Last modified: Fri Jul 12 2024 22:38:48 GMT+0200 (Central European Summer Time) + +```typescript +import os from 'node:os'; +import path from 'node:path'; +import url from 'node:url'; +import chalk from 'chalk'; +import { Command } from 'commander'; +import fs from 'fs-extra'; +import ora from 'ora'; +import { processFiles } from '../core/file-processor'; +import { generateMarkdown } from '../core/markdown-generator'; +import { interactiveMode } from './interactive-filtering'; + +const isProduction = path + .dirname(new URL(import.meta.url).pathname) + .includes('/dist/'); +const templatesDir = isProduction + ? path.resolve(path.dirname(new URL(import.meta.url).pathname), '../') + : path.resolve( + path.dirname(new URL(import.meta.url).pathname), + '../templates', + ); + +const program = new Command(); + +export function cli(args: string[]) { + program + .name('codewhisper') + .description('A powerful tool for converting code to AI-friendly prompts') + .version('1.0.0'); + + program + .command('generate') + .description('Generate a markdown file from your codebase') + .option('-p, --path ', 'Path to the codebase', '.') + .option('-o, --output ', 'Output file name') + .option('-t, --template