From 8f70eaac036e6fb28070ba092ebf1ae325ed3fcf Mon Sep 17 00:00:00 2001 From: PedroBailaAndrade Date: Mon, 8 Jan 2024 14:40:21 +0000 Subject: [PATCH] Test --- workspaces/cms-scripts/src/index.ts | 51 ++++++++++++++++------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/workspaces/cms-scripts/src/index.ts b/workspaces/cms-scripts/src/index.ts index 6f07c48d3a7..e1c59b91f22 100644 --- a/workspaces/cms-scripts/src/index.ts +++ b/workspaces/cms-scripts/src/index.ts @@ -1,4 +1,4 @@ -import fs from "fs/promises"; +import { existsSync, promises } from "fs"; import * as path from "path"; process.chdir(path.resolve(__dirname, "../../..")); @@ -23,17 +23,19 @@ import { } from "./data"; import { translateFile } from "./crowdin"; +const { readdir, readFile, mkdir } = promises; + const createRoadmapDetails = async () => { - await fs.mkdir(`public/data/roadmap-details`, {recursive: true}); + await mkdir(`public/data/roadmap-details`, {recursive: true}); for (const locale of locales) { const roadmapPosts: RoadmapDetails[] = []; const filesPath = path.join("public/data/roadmap-posts", locale) - const filesInDir = await fs.readdir(filesPath); + const filesInDir = await readdir(filesPath); const jsonFilesInDir = filesInDir.filter((file) => file.endsWith(".json")); for (const fileName of jsonFilesInDir) { - const fileData = await fs.readFile( + const fileData = await readFile( path.join( process.cwd(), "public/data/roadmap-posts", @@ -51,16 +53,21 @@ const createRoadmapDetails = async () => { } const createAnnouncementDetails = async () => { - await fs.mkdir(`public/data/announcements-details`, {recursive: true}); for (const locale of locales) { - const roadmapPosts: AnnouncementDetails[] = []; const filesPath = path.join("public/data/announcements", locale) - const filesInDir = await fs.readdir(filesPath); + + if (!existsSync(filesPath)) { + await mkdir(filesPath, { recursive: true }); + } + + await mkdir(`public/data/announcements-details`, {recursive: true}); + const roadmapPosts: AnnouncementDetails[] = []; + const filesInDir = await readdir(filesPath); const jsonFilesInDir = filesInDir.filter((file) => file.endsWith(".json")); for (const fileName of jsonFilesInDir) { - const fileData = await fs.readFile( + const fileData = await readFile( path.join( process.cwd(), "public/data/announcements", @@ -78,7 +85,7 @@ const createAnnouncementDetails = async () => { } const createSharedData = async () => { - await fs.mkdir(`public/data/shared-data`, { recursive: true }); + await mkdir(`public/data/shared-data`, { recursive: true }); const seoFiles = [ "home", "footer", @@ -94,7 +101,7 @@ const createSharedData = async () => { const seo: Record = {} for (const fileName of seoFiles) { - const fileData = await fs.readFile( + const fileData = await readFile( path.join(process.cwd(), `public/data/seo/${fileName}/${locale}.json`), "utf8" ); @@ -103,12 +110,12 @@ const createSharedData = async () => { seo[fileName] = fileDataParsed } - const mainMenuData = await fs.readFile( + const mainMenuData = await readFile( path.join(process.cwd(), `public/data/main-menu/${locale}.json`), "utf8" ); - const alertsData = await fs.readFile( + const alertsData = await readFile( path.join(process.cwd(), `public/data/alert/${locale}.json`), "utf8" ); @@ -135,7 +142,7 @@ const simpleDataTypes = [ ]; for (const simpleData of simpleDataTypes) { - await fs.mkdir(`public/data/${simpleData.resourceName}`, { + await mkdir(`public/data/${simpleData.resourceName}`, { recursive: true, }); @@ -171,7 +178,7 @@ for (const simpleFile of simpleFiles) { ? simpleFile.resourceName : `${simpleFile.collectionName}/${simpleFile.resourceName}`; - await fs.mkdir(`public/data/${resourceDir}`, { + await mkdir(`public/data/${resourceDir}`, { recursive: true, }); @@ -194,7 +201,7 @@ const tutorials = await getTutorials(); updateBlocks(pages, posts); for (const locale of locales) { - await fs.mkdir(`public/data/posts/${locale}`, { recursive: true }); + await mkdir(`public/data/posts/${locale}`, { recursive: true }); } for (const data of posts.filenameMap.values()) { @@ -203,7 +210,7 @@ for (const data of posts.filenameMap.values()) { } for (const locale of locales) { - await fs.mkdir(`public/data/tutorials/${locale}`, { recursive: true }); + await mkdir(`public/data/tutorials/${locale}`, { recursive: true }); } for (const data of tutorials.filenameMap.values()) { @@ -212,9 +219,9 @@ for (const data of tutorials.filenameMap.values()) { } for (const locale of locales) { - await fs.mkdir(`public/data/pages/${locale}`, { recursive: true }); - await fs.mkdir(`public/data/roadmap-posts/${locale}`, { recursive: true }); - await fs.mkdir(`public/data/announcements/${locale}`, { recursive: true }); + await mkdir(`public/data/pages/${locale}`, { recursive: true }); + await mkdir(`public/data/roadmap-posts/${locale}`, { recursive: true }); + await mkdir(`public/data/announcements/${locale}`, { recursive: true }); } for (const data of roadmapPosts.filenameMap.values()) { @@ -232,11 +239,11 @@ for (const data of announcements.filenameMap.values()) { } for (const locale of locales) { - await fs.mkdir(`public/data/pages/${locale}`, { recursive: true }); + await mkdir(`public/data/pages/${locale}`, { recursive: true }); } for (const data of pages.filenameMap.values()) { - await fs.mkdir( + await mkdir( path.join( "public/data/pages", data.locale, @@ -253,7 +260,7 @@ for (const data of pages.filenameMap.values()) { } // main menu -await fs.mkdir("public/data/main-menu", { recursive: true }); +await mkdir("public/data/main-menu", { recursive: true }); for (const locale of locales) { const mainMenu: MainMenu = await translateFile(