Skip to content

Instantly share code, notes, and snippets.

@joldibaev
Created November 8, 2022 17:03
Show Gist options
  • Save joldibaev/76ea1de678519a547760440cb0400dcd to your computer and use it in GitHub Desktop.
Save joldibaev/76ea1de678519a547760440cb0400dcd to your computer and use it in GitHub Desktop.
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