Skip to content

code-visible/chameleon

Repository files navigation

Chameleon

Chameleon is initially a code visible Javascript/Typescript parser, it could be imported as modules as well.

Source Code Module

This module provides TypeScript classes and utilities for representing, parsing, and managing source files, directories, and their dependencies in a codebase. It is designed to facilitate dependency tracking, and metadata extraction for TypeScript/JavaScript projects.

Features

  • File, Directory, and Dependency Modeling:
    Classes to represent files (File), directories (Dir), and file dependencies (Dep).

  • Parsing and Analysis:
    Parses TypeScript/JavaScript source files to extract functions, imports, and dependencies.

  • Dependency Resolution:
    Tracks and connects dependencies between files and directories.

  • Metadata Dumping:
    Exports structured metadata for files and directories, including IDs, names, paths, imports, and dependencies.

  • Hash-based Identifiers:
    Generates unique IDs for files and directories using a hash function.

Classes

Dep

Represents a file dependency.

  • Properties: ident, name, typ, filePtr
  • Methods:
    • getID(): Returns a unique hash ID for the dependency.
    • dump(): Exports dependency metadata.

Dir

Represents a directory in the project.

  • Properties: ident, path, files, pkg, imps
  • Methods:
    • getID(): Returns a unique hash ID for the directory.
    • dump(): Exports directory metadata, including imported directories.

File

Represents a source file.

  • Properties: ident, path, name, dir, ts, js, json, test, error, fns, abs, imps, calls, deps, lookupDep, registry
  • Methods:
    • parse(): Loads and parses the file, extracting imports and dependencies.
    • connectDependencies(dep): Connects file and directory dependencies.
    • completeFunction(fn): Completes function metadata with file and directory IDs.
    • isSource(): Checks if the file is a source file.
    • getID(): Returns a unique hash ID for the file.
    • getDirID(): Returns the directory's unique hash ID.
    • dump(): Exports file metadata, including imports and dependencies.

Utility Functions

  • calculateHashID(info: string): string
    Generates a unique hash ID for a given string using MD5 and encodes it as hex.

Usage

Use as a tool

chameleon --project=path_to_project/projectname --directory=. --dump=prject_xx.json --name=project_name --excludes=tests

Use as a module

Import the relevant classes and functions from the module to analyze and manage your project's source files and dependencies.

import { File, Dir, Dep, calculateHashID } from "./sourcecode";

About

Chameleon is a code visible Javascript/Typescript parser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published