Created
November 8, 2022 17:03
-
-
Save joldibaev/76ea1de678519a547760440cb0400dcd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const fs = require("fs"); | |
const fse = require("fs-extra"); | |
const PROD_PATH = "./dist/prod/browser/"; | |
function moveFolder(folderPath, locale) { | |
let allFiles = fs.readdirSync(folderPath); | |
allFiles.forEach((fileName) => { | |
const path = folderPath + fileName; | |
const splitPath = path.split("/"); | |
const folderName = Array.from(path.split("/")).pop(); | |
const newPath = [folderPath, locale + "/", folderName].join(""); | |
const isIndexHTML = splitPath.at(-1) === "index.html"; | |
const isDirectory = fs.lstatSync(path).isDirectory(); | |
if (isDirectory || isIndexHTML) { | |
const isAlreadyMoved = splitPath.at(-1) === splitPath.at(-2); | |
if (!isAlreadyMoved) { | |
fse.move(path, newPath); | |
} | |
} | |
}); | |
} | |
function startMove() { | |
console.log("Start moving prerendered pages"); | |
let allLocales = fs.readdirSync(PROD_PATH, "utf-8"); | |
for (const locale of allLocales) { | |
if (locale !== "en") { | |
const path = PROD_PATH + locale + "/"; | |
moveFolder(path, locale); | |
} | |
} | |
} | |
startMove(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment