从命令行重新组织大型TypeScript项目

从命令行重新组织大型TypeScript项目,typescript,visual-studio-code,automated-refactoring,Typescript,Visual Studio Code,Automated Refactoring,我有一个中型/大型TypeScript项目(~500个源文件),我想进行大规模重组,更改目录结构并移动所有模块 可以轻松地在VS代码中移动单个文件并更新所有导入: 此重构是使用实现的。使用拖放进行移动和更新对于少量文件来说效果很好,但对于大规模重组,我宁愿编写一些脚本: old/path/to/file.ts --> new/path/newfile.ts old/path/to/olddir --> new/path/to/newdir 可以用这种方式与VS代码或TypeScr

我有一个中型/大型TypeScript项目(~500个源文件),我想进行大规模重组,更改目录结构并移动所有模块

可以轻松地在VS代码中移动单个文件并更新所有导入:

此重构是使用实现的。使用拖放进行移动和更新对于少量文件来说效果很好,但对于大规模重组,我宁愿编写一些脚本:

old/path/to/file.ts --> new/path/newfile.ts
old/path/to/olddir --> new/path/to/newdir

可以用这种方式与VS代码或TypeScript语言服务交互吗?是否有其他TypeScript或JavaScript codemod工具可以帮助实现这一点?

事实证明,使用以下工具非常简单:

我创建了一个名为的小工具,大致使用问题中描述的移动列表格式(第一行是
tsconfig.json
)的路径:

这比我想要的要慢一点,特别是对于大型项目,但它绝对比在VS代码中拖放数百个文件要好

const project = new Project({ tsConfigFilePath });
const sourceFile = project.getSourceFileOrThrow('/path/to/file.ts');
sourceFile.move('newFileName.ts');
// or:
// sourceFile.moveToDirectory('/some/dir');
$ cat moves.txt
path/to/tsconfig.json
src/oldname.ts --> src/newname.ts
src/file.ts --> src/newmodule/file.ts
src/file2.ts --> src/newmodule/

$ npx ts-mover moves.txt
Moving src/oldname.ts --> src/newname.ts
  (Be patient, the first move takes the longest.)
  elapsed: 455 ms
Moving src/file.ts --> src/newmodule/file.ts
Moving src/file2.ts --> src/newmodule/file2.ts
Saving changes to disk...