Skip to content

Commit 0357e95

Browse files
committed
content: js -> jsx files
1 parent 162b16a commit 0357e95

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

public/posts/posts.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
[
2+
{
3+
"slug": "renaming-js-to-jsx-gist",
4+
"title": "Quick Renaming .js to .jsx for React",
5+
"date": "2025-12-23",
6+
"updated": "2025-12-23",
7+
"description": "A quick guide on using PowerShell to batch rename React files from .js to .jsx, ensuring your editor recognizes them correctly.",
8+
"tags": ["gist", "powershell", "react", "dev", "script"],
9+
"category": "gist",
10+
"filename": "renaming-js-to-jsx-gist.txt",
11+
"authors": ["fezcode"],
12+
"image": "/images/defaults/sina-salehian-HqmTUJD73mM-unsplash.jpg"
13+
},
214
{
315
"slug": "corrupted-blood-incident",
416
"title": "The Corrupted Blood Incident: When a Glitch Taught Us About Pandemics",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## The Command (PowerShell)
2+
3+
I ran this specific script in your terminal. It uses "piping" (`|`) to pass the result of one command to the next, like a bucket brigade.
4+
5+
```powershell
6+
Get-ChildItem -Path src -Recurse -Filter *.js |
7+
Where-Object { $_.Name -notin @('index.js', 'reportWebVitals.js', 'setupTests.js') } |
8+
ForEach-Object {
9+
if (Select-String -Pattern "<[a-zA-Z]" -Path $_.FullName -Quiet) {
10+
Write-Host "Renaming $($_.Name) to .jsx";
11+
Rename-Item -LiteralPath $_.FullName -NewName ($_.Name -replace '\.js$', '.jsx')
12+
}
13+
}
14+
```
15+
16+
### Deep Dive: Commands & Arguments
17+
18+
Here is exactly what every part of that spell does:
19+
20+
**1. Finding the files**
21+
`Get-ChildItem -Path src -Recurse -Filter *.js`
22+
* `Get-ChildItem`: The standard command to list files (like `ls` or `dir`).
23+
* `-Path src`: We only look inside the `src` folder.
24+
* `-Recurse`: We dig deep into every subfolder, not just the top level.
25+
* `-Filter *.js`: We ignore everything except files ending in `.js`.
26+
27+
**2. Filtering the list**
28+
`Where-Object { $_.Name -notin @(...) }`
29+
* `Where-Object`: Acts like a bouncer; only lets items through that match the condition.
30+
* `$_`: Represents the "current file" being checked.
31+
* `-notin`: The condition operator. We are saying "The name must NOT be in this list".
32+
* `@('index.js', ...)`: The list of system files we want to skip (leave as `.js`).
33+
34+
**3. Processing each file**
35+
`ForEach-Object { ... }`
36+
* `ForEach-Object`: Runs the code block inside `{ ... }` for every single file that made it past the filter.
37+
38+
**4. Checking for React Code (JSX)**
39+
`if (Select-String -Pattern "<[a-zA-Z]" -Path $_.FullName -Quiet)`
40+
* `Select-String`: Searches for text inside a file (like `grep`).
41+
* `-Pattern "<[a-zA-Z]"`: A Regex pattern. It looks for a `<` followed by a letter. This catches HTML tags like `<div>` or React components like `<App>`.
42+
* `-Path $_.FullName`: The full path to the file we are currently reading.
43+
* `-Quiet`: Important! This tells the command "Don't print the matching text, just tell me True or False."
44+
45+
**5. Renaming the file**
46+
`Rename-Item -LiteralPath $_.FullName -NewName (...)`
47+
* `Rename-Item`: The command to change a file's name.
48+
* `-LiteralPath $_.FullName`: We use the full path to ensure we target the exact right file.
49+
* `-NewName ($_.Name -replace '\.js$', '.jsx')`: We calculate the new name by taking the old name and swapping the ending `.js` with `.jsx`.
50+
51+
**The Result**
52+
53+
Now your code editor knows exactly which files contain UI components. You'll get better autocomplete, better color highlighting, and generally a much happier development experience.

0 commit comments

Comments
 (0)