Skip to content

Commit

Permalink
feat: add directory path support and improve Flutter/Dart detection
Browse files Browse the repository at this point in the history
  • Loading branch information
elix1er committed Jan 16, 2025
1 parent 1a2766a commit e2708f2
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 36 deletions.
6 changes: 6 additions & 0 deletions packages/ai-repomap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @tokenizin/ai-repomap

## 2.0.0

### Major Changes

- up

## 1.0.0

### Major Changes
Expand Down
80 changes: 48 additions & 32 deletions packages/ai-repomap/bin/mapper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#!/usr/bin/env node

import { readdirSync, readFileSync, existsSync } from 'fs';
import { join, extname } from 'path';
import { join, extname, resolve } from 'path';
import Parser from 'tree-sitter';
import JavaScript from 'tree-sitter-javascript';
import TypeScript from 'tree-sitter-typescript';
import { execSync } from 'child_process';

// Get target directory from command line args or use current directory
const targetDir = process.argv[2] ? resolve(process.argv[2]) : '.';
if (!existsSync(targetDir)) {
console.error(`Error: Directory "${targetDir}" does not exist`);
process.exit(1);
}

/**
* Represents information about a symbol (function or class) found in the code
* @interface SymbolInfo
Expand Down Expand Up @@ -86,7 +93,7 @@ interface FileInfo {
}

const IGNORE_DIRS = new Set(['node_modules', '.git', 'build', '.dart_tool', '.pub-cache']);
const ROOT_DIR = '.';
const ROOT_DIR = targetDir;

// Add Flutter/Dart specific elements
const FLUTTER_WIDGETS = new Set([
Expand Down Expand Up @@ -623,36 +630,44 @@ function parseAndroidManifest(content: string): { package?: string; components?:
*/
function getGitInfo() {
try {
// Check if git repo exists first
execSync('git rev-parse --git-dir', { stdio: 'ignore' });

const branch = execSync('git rev-parse --abbrev-ref HEAD', {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'ignore'],
}).trim();
const remoteUrl = execSync('git config --get remote.origin.url', {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'ignore'],
}).trim();
const lastCommit = execSync('git log -1 --format=%H', {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'ignore'],
}).trim();
const authorName = execSync('git config user.name', {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'ignore'],
}).trim();
const authorEmail = execSync('git config user.email', {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'ignore'],
}).trim();

return {
branch,
remoteUrl,
lastCommit,
author: { name: authorName, email: authorEmail },
};
// Check if git repo exists first and change to ROOT_DIR
const originalDir = process.cwd();
process.chdir(ROOT_DIR);

try {
execSync('git rev-parse --git-dir', { stdio: 'ignore' });

const branch = execSync('git rev-parse --abbrev-ref HEAD', {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'ignore'],
}).trim();
const remoteUrl = execSync('git config --get remote.origin.url', {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'ignore'],
}).trim();
const lastCommit = execSync('git log -1 --format=%H', {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'ignore'],
}).trim();
const authorName = execSync('git config user.name', {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'ignore'],
}).trim();
const authorEmail = execSync('git config user.email', {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'ignore'],
}).trim();

return {
branch,
remoteUrl,
lastCommit,
author: { name: authorName, email: authorEmail },
};
} finally {
// Always restore original directory
process.chdir(originalDir);
}
} catch {
return null;
}
Expand Down Expand Up @@ -702,6 +717,7 @@ for (const file of getJSFiles(ROOT_DIR)) {
// Create final output with project metadata
const output = {
timestamp: new Date().toISOString(),
targetDirectory: ROOT_DIR,
project: {
git: getGitInfo(),
package: getPackageJson(),
Expand Down
29 changes: 25 additions & 4 deletions packages/ai-repomap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@tokenizin/ai-repomap",
"version": "1.0.0",
"version": "2.1.0",
"description": "AI-powered codebase mapping tool that analyzes and generates a detailed map of your project structure, with support for JavaScript, TypeScript, Flutter, Dart, and Android.",
"type": "module",
"bin": {
"tokenizin-repomap": "./dist/mapper.js"
Expand All @@ -11,13 +12,14 @@
"clean": "rm -rf dist",
"prepublishOnly": "pnpm run build",
"dev": "tsx watch bin/mapper.ts",
"release": "pnpm run build && changeset publish"
"release": "pnpm run build && changeset publish",
"full-release": "pnpm run build && pnpm changeset && git add . && git commit -m \"chore: add changeset\" && pnpm changeset version && git add . && git commit -m \"chore: update versions\" && pnpm changeset publish && git push --follow-tags"
},
"dependencies": {
"tree-sitter": "^0.20.6",
"tree-sitter-javascript": "^0.20.1",
"tree-sitter-typescript": "^0.20.3",
"tree-sitter-dart": "^0.1.1",
"tree-sitter-dart": "^1.0.0",
"ignore": "^5.3.0"
},
"devDependencies": {
Expand All @@ -32,5 +34,24 @@
},
"engines": {
"node": ">=18"
}
},
"keywords": [
"codebase-analysis",
"code-mapping",
"static-analysis",
"javascript",
"typescript",
"flutter",
"dart",
"android"
],
"repository": {
"type": "git",
"url": "https://github.com/tokenizin/tokigen.git"
},
"bugs": {
"url": "https://github.com/tokenizin/tokigen/issues"
},
"homepage": "https://github.com/tokenizin/tokigen#readme",
"usage": "tokenizin-repomap [directory-path]"
}

0 comments on commit e2708f2

Please sign in to comment.