file-mover
v0.4.5
Published
Script to move files and update imports automatically
Maintainers
Readme
File Mover Refactor Tool
A CLI tool to move files and automatically update all relevant import statements in a monorepo or multi-package TypeScript/JavaScript project.
Features
- Move one or more files to new locations.
- Automatically updates all import paths in the codebase that reference the moved files.
- Updates relative and
@ms/-style imports. - Handles both TypeScript and JavaScript files.
- Supports dry-run and verbose modes for safe and transparent refactoring.
Installation
Clone this repository and install dependencies:
npm installUsage
Move Files
Prepare a move.json file in the root directory, containing an array of [from, to] path pairs:
[
[
"C:/path/to/source/file1.ts",
"C:/path/to/destination/file1.ts"
],
[
"C:/path/to/source/file2.ts",
"C:/path/to/destination/file2.ts"
]
]Then run:
npx ts-node move-file.tsOr, if you have built the project:
node move-file.jsOptions
--dry-run
Show what would be changed, but do not actually move files or update imports.--verbose
Print detailed information about every import update.
How It Works
- Reads the list of file moves from
move.json. - Validates that all source files exist and destination files do not.
- Finds all source files in the workspace (excluding
node_modules,dist, etc.). - Analyzes which files import the files to be moved.
- Moves the files.
- Updates all relevant import statements in the codebase and inside the moved files themselves.
Configuration
The tool is configured to work with a monorepo structure, specifically looking for files in:
packages/powerva-mainpackages/powerva-embedded-experiencespackages/powerva-coreapps/powerva-microsoft-com
You can adjust these in move-file.ts if your project structure is different.
Scripts
npm run move— Run the move tool.npm run test-move— Run in dry-run mode.npm run start— Run the built tool with increased memory.npm run startv— Run the built tool in verbose mode.
TypeScript
The project is written in TypeScript. See tsconfig.json for compiler options.
Dependencies
@babel/parserand@babel/traverse— For parsing and traversing code to find and update import statements.fast-glob— For fast file searching.glob— For pattern-based file matching.
Example
Suppose you want to move:
packages/powerva-main/src/pages/adaptive-authoring/AdaptiveAuthoringIcons.tsx
topackages/powerva-main/src/common/icons/AdaptiveAuthoringIcons.tsx
Add this pair to move.json and run the tool. All imports of AdaptiveAuthoringIcons will be updated across the codebase.
Development
Project Structure
move-file.ts— Main CLI entry point.src/types.ts— TypeScript types and interfaces.src/pathUtils.ts— Path normalization and import path helpers.src/importUtils.ts— Import analysis and statement finding.src/fileOps.ts— File moving and import updating logic.
ppux workflow process
- install the
package.json command: "file-mover": "node node_modules/file-mover/dist/index.js exmaple.json && echo 'File move completed successfully!' && rush lint -o powerva-main -o powerva-core -o powerva-microsoft-com -o powerva-embedded-experiences --fix"
Known issues and TODO:
- Use relative path(?)
- Current it doesn't support moving files from
apps->packagedue to it's imposable (We could but it'd mean more file scanning) to import app files from package and update file path from dist import to it's original export
License
MIT
