forked from open-meteo/open-meteo-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
script to rename to index.html files
- Loading branch information
1 parent
f50f1f0
commit ef7455f
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { lstatSync, mkdirSync, readdirSync, renameSync } from 'fs' | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import {resolve } from 'path' | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const buildDirPath = resolve(__dirname, '../build/'); | ||
|
||
// Search for abcd.html files and move them to abcd/index.html | ||
function walk(directory) { | ||
const files = readdirSync(directory) | ||
files.forEach(file => { | ||
const absolute = `${directory}/${file}` | ||
if (lstatSync(absolute).isDirectory()) { | ||
walk(absolute); | ||
return | ||
} | ||
|
||
const parts = file.split('.') | ||
if (parts.length != 2) { | ||
return | ||
} | ||
if (parts[0] == "index" || parts[1] != "html") { | ||
return | ||
} | ||
|
||
const newDirectory = `${directory}/${parts[0]}` | ||
const newFile = `${newDirectory}/index.html` | ||
console.log(`Rename ${file} to ${parts[0]}/index.html`) | ||
mkdirSync(newDirectory, {recursive: true}) | ||
renameSync(absolute, newFile) | ||
}); | ||
} | ||
|
||
walk(buildDirPath); |