Class: Aidp::Init::ProjectAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/init/project_analyzer.rb

Overview

Performs lightweight static analysis of the repository to detect languages, frameworks, config files, and quality tooling. Designed to run quickly and deterministically without external services.

Constant Summary collapse

IGNORED_DIRECTORIES =
%w[
  .git
  .svn
  .hg
  node_modules
  vendor
  tmp
  log
  build
  dist
  coverage
  .yardoc
].freeze
LANGUAGE_EXTENSIONS =
{
  ".rb" => "Ruby",
  ".rake" => "Ruby",
  ".gemspec" => "Ruby",
  ".js" => "JavaScript",
  ".jsx" => "JavaScript",
  ".ts" => "TypeScript",
  ".tsx" => "TypeScript",
  ".py" => "Python",
  ".go" => "Go",
  ".java" => "Java",
  ".kt" => "Kotlin",
  ".cs" => "C#",
  ".php" => "PHP",
  ".rs" => "Rust",
  ".swift" => "Swift",
  ".scala" => "Scala",
  ".c" => "C",
  ".cpp" => "C++",
  ".hpp" => "C++",
  ".m" => "Objective-C",
  ".mm" => "Objective-C++",
  ".hs" => "Haskell",
  ".erl" => "Erlang",
  ".ex" => "Elixir",
  ".exs" => "Elixir",
  ".clj" => "Clojure",
  ".coffee" => "CoffeeScript"
}.freeze
CONFIG_FILES =
%w[
  .editorconfig
  .rubocop.yml
  .rubocop_todo.yml
  .standardrb
  .eslintrc
  .eslintrc.js
  .eslintrc.cjs
  .eslintrc.json
  .prettierrc
  .prettierrc.js
  .prettierrc.cjs
  .prettierrc.json
  .stylelintrc
  .flake8
  pyproject.toml
  tox.ini
  setup.cfg
  package.json
  Gemfile
  Gemfile.lock
  mix.exs
  go.mod
  go.sum
  composer.json
  Cargo.toml
  Cargo.lock
  pom.xml
  build.gradle
  build.gradle.kts
].freeze
KEY_DIRECTORIES =
%w[
  app
  src
  lib
  spec
  test
  tests
  scripts
  bin
  config
  docs
  examples
  packages
  modules
].freeze
TOOLING_HINTS =
{
  rubocop: [".rubocop.yml", ".rubocop_todo.yml"],
  standardrb: [".standardrb"],
  eslint: [".eslintrc", ".eslintrc.js", ".eslintrc.cjs", ".eslintrc.json"],
  prettier: [".prettierrc", ".prettierrc.js", ".prettierrc.cjs", ".prettierrc.json"],
  stylelint: [".stylelintrc"],
  flake8: [".flake8"],
  black: ["pyproject.toml"],
  pytest: ["pytest.ini", "pyproject.toml"],
  jest: ["package.json"],
  rspec: ["spec", ".rspec"],
  minitest: ["test"],
  gofmt: ["go.mod"],
  cargo_fmt: ["Cargo.toml"]
}.freeze
FRAMEWORK_HINTS =
{
  "Rails" => {files: ["config/application.rb"], contents: [/rails/i]},
  "Hanami" => {files: ["config/app.rb"], contents: [/hanami/i]},
  "Sinatra" => {files: ["config.ru"], contents: [/sinatra/i]},
  "React" => {files: ["package.json"], contents: [/react/]},
  "Next.js" => {files: ["package.json"], contents: [/next/]},
  "Express" => {files: ["package.json"], contents: [/express/]},
  "Angular" => {files: ["angular.json"]},
  "Vue" => {files: ["package.json"], contents: [/vue/]},
  "Django" => {files: ["manage.py"], contents: [/django/]},
  "Flask" => {files: ["requirements.txt"], contents: [/flask/]},
  "FastAPI" => {files: ["pyproject.toml", "requirements.txt"], contents: [/fastapi/]},
  "Phoenix" => {files: ["mix.exs"], contents: [/phoenix/]},
  "Spring" => {files: ["pom.xml", "build.gradle", "build.gradle.kts"], contents: [/spring/]},
  "Laravel" => {files: ["composer.json"], contents: [/laravel/]},
  "Go Gin" => {files: ["go.mod"], contents: [/gin-gonic/]},
  "Go Fiber" => {files: ["go.mod"], contents: [/github.com\/gofiber/]}
}.freeze
TEST_FRAMEWORK_HINTS =
{
  "RSpec" => {directories: ["spec"], dependencies: [/rspec/]},
  "Minitest" => {directories: ["test"], dependencies: [/minitest/]},
  "Cucumber" => {directories: ["features"]},
  "Jest" => {dependencies: [/jest/]},
  "Mocha" => {dependencies: [/mocha/]},
  "Jasmine" => {dependencies: [/jasmine/]},
  "Pytest" => {directories: ["tests", "test"], dependencies: [/pytest/]},
  "NUnit" => {files: ["*.csproj"], contents: [/nunit/]},
  "JUnit" => {dependencies: [/junit/]},
  "Go test" => {files: ["*_test.go"]}
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_dir = Dir.pwd) ⇒ ProjectAnalyzer

Returns a new instance of ProjectAnalyzer.



154
155
156
# File 'lib/aidp/init/project_analyzer.rb', line 154

def initialize(project_dir = Dir.pwd)
  @project_dir = project_dir
end

Instance Attribute Details

#project_dirObject (readonly)

Returns the value of attribute project_dir.



152
153
154
# File 'lib/aidp/init/project_analyzer.rb', line 152

def project_dir
  @project_dir
end

Instance Method Details

#analyze(options = {}) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/aidp/init/project_analyzer.rb', line 158

def analyze(options = {})
  @explain_detection = options[:explain_detection] || false

  {
    languages: detect_languages,
    frameworks: detect_frameworks,
    key_directories: detect_key_directories,
    config_files: detect_config_files,
    test_frameworks: detect_test_frameworks,
    tooling: detect_tooling,
    repo_stats: collect_repo_stats
  }
end