Powershell: Recursive Rename files (Javascript to Typescript)

Date: 2022-06-15
$files = Get-ChildItem -File -Recurse -Filter *.js 
foreach($file in $files)
{
	$name = $file.Name -Replace '\.js$','.ts'
	Rename-Item -Path $file -NewName $name
}	

A first stept to prepare some files:

lebab --replace ./**/*.js --transform commonjs



# some notes:

# import globals
export const angular = (window as any).angular;
const moment = (window as any).moment;

# Search/Replace *.ts in vscode:
^require\('(.*)'\);
import "$1";


# Search/Replace *.ts in vscode:
\bwindow\.
(window as any).

import dateHelper from "../../../helpers/dateHelper";
=>
import * as dateHelper from "../../../helpers/dateHelper";

For more see: https://solidt.eu/site/lebab-modernizing-javascript/

63210cookie-checkPowershell: Recursive Rename files (Javascript to Typescript)