Treegen is a TypeScript package that provides functionality for generating and working with directory tree structures. It includes a command-line interface (CLI) for scanning directories, validating directory structures, and generating tree visualizations.
- Scan Directory: Scan a directory and output its structure.
- Validate Structure: Validate directory structures from a file.
- Generate Tree Visualization: Generate directory tree structures and customize the appearance.
To use Treegen in your TypeScript project, you can install it via npm:
npm install -g treegen
npm install treegen
Treegen can be used both programmatically and via the command line. Below are the available commands and their usage.
treegen scan-dir -d <directory-path>
-d, --dir
: The directory path to scan.
treegen validate -f <file-path>
-f, --file
: The file path to validate the directory structure.
treegen generate-tree -d <directory-path> -s <structure-file>
-d, --dir
: The directory path to scan.-s, --structure
: The file containing the directory structure.
For more options and customizations, refer to the cli documentation.
Treegen can also be used programmatically in your TypeScript projects. Here's an example of how to use it:
import { Treegen, Node } from 'treegen';
// Create a Treegen instance
const treegen = new Treegen();
// Scan a directory and generate a tree structure
const structure = treegen.scanDir('/path/to/directory');
// Validate a directory structure from a file
const isValid = treegen.isValidStructure(structure);
// Generate a tree visualization
const rootNode = treegen.generateTree({ structure });
rootNode.printTree();
Here are some example outputs based on the provided code and the CLI commands:
$ treegen scan-dir -d /path/to/directory
Output:
root>index.ts
root>Node.ts
root>tests
root>tests>treegen.test.ts
root>Treegen.ts
root>types.ts
# The content of structure.txt looks like the previous output of example 1.
$ treegen validate -f structure.txt
Output:
The structure is valid. ✅
$ treegen generate-tree -d /path/to/directory -s structure.txt
Output:
root
|----cli.ts
|----index.ts
|----Node.ts
|----tests
| |----treegen.test.ts
|----Treegen.ts
|----types.ts
Please note that the actual output may vary based on the structure of your directory or the content of the structure.txt
file. The above examples are for illustration purposes and should reflect the expected behavior of your CLI commands.
The documentation will help you make the most out of Treegen in your projects.
This project is licensed under the MIT License. See the LICENSE file for details.
See CHANGELOG for details on changes and new features.
Contributions are welcome! Please read CONTRIBUTING for details on our code of conduct and the process for submitting pull requests.
If you have any questions or feedback, feel free to reach out to [yasfp.pro@gmail.com].