extract-node-file v1.0.4
Extract Node File
A command-line tool to extract dependencies from Node.js files and create a simplified project containing only those dependencies.
Table of Contents
Introduction
Extract Node File is a utility that scans specified Node.js files for their dependencies and creates a new project containing only those files and their dependencies. This is particularly useful for:
- Isolating components for reuse.
- Creating minimal reproductions for debugging.
- Extracting parts of a project for documentation or sharing.
Features
- Dependency Extraction: Analyzes files to find all nested dependencies.
- Project Simplification: Creates a new project directory with the extracted files and dependencies.
- Customizable Output: Allows specifying the output directory and whether to replace it if it exists.
- Supports Multiple Files: Can handle multiple target files simultaneously.
Installation
You can install Extract Node File globally using npm:
npm install -g extract-node-file
This will make the extract-node-file
command available globally.
Usage
Run extract-node-file
with the required options:
extract-node-file --projectRoot <projectRoot> --targetFile <targetFile> [options]
Command-Line Options
--projectRoot <projectRoot>
(Required) The absolute path to the root of the Node.js project.--targetFile <targetFile>
(Required) The absolute path to the target file whose dependencies you want to extract. This option can be used multiple times to specify multiple target files.--outputDirectory <outputDirectory>
(Optional) The path to the output directory where the simplified project will be created. If not specified, it defaults to the name of the target file or<projectRoot>-extract
if multiple target files are provided.--replaceOutputDirectory
(Optional) If specified, the existing output directory will be deleted before creating a new one.
Examples
Extracting a Single File
extract-node-file \
--projectRoot /path/to/your/project \
--targetFile /path/to/your/project/src/index.js
Extracting Multiple Files
extract-node-file \
--projectRoot /path/to/your/project \
--targetFile /path/to/your/project/src/index.js \
--targetFile /path/to/your/project/src/app.js
Specifying Output Directory and Replacing It
extract-node-file \
--projectRoot /path/to/your/project \
--targetFile /path/to/your/project/src/index.js \
--outputDirectory /path/to/output \
--replaceOutputDirectory
How It Works
Argument Parsing: The tool parses command-line arguments to get the project root, target files, output directory, and other options.
Dependency Resolution: It uses Madge to analyze the target files and recursively find all their dependencies.
Path Adjustment: Dependencies are converted to paths relative to the project root.
Output Directory Handling: The output directory is created, replaced, or used as-is based on the provided options.
File Copying: The tool copies the necessary files and directories, maintaining the original project structure.
Base Project Files: It also copies over any base files (like
package.json
,.gitignore
) from the project root to the output directory.
Contributing
Contributions are welcome! Please follow these steps:
Fork the Repository: Click the "Fork" button at the top right of the repository page.
Clone Your Fork:
git clone https://github.com/imbaker1234/extract-node-file.git
Create a Branch:
git checkout -b feature/your-feature-name
Make Your Changes: Implement your feature or bug fix.
Commit Your Changes:
git commit -m "Description of your changes"
Push to Your Fork:
git push origin feature/your-feature-name
Submit a Pull Request: Go to the original repository and open a pull request.
License
This project is licensed under the ISC License. See this online at https://opensource.org/licenses/ISC.
Author: Ian Baker (imbaker1234@gmail.com)
GitHub Repository: https://github.com/imbaker1234/extract-node-file
Issues: Please report issues on the GitHub Issue Tracker.
Keywords: dependency, extract, node, simplify, project, tool