Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroBailaAndrade committed Jan 8, 2024
1 parent 102293b commit 8f70eaa
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions workspaces/cms-scripts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from "fs/promises";
import { existsSync, promises } from "fs";
import * as path from "path";

process.chdir(path.resolve(__dirname, "../../.."));
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -94,7 +101,7 @@ const createSharedData = async () => {
const seo: Record<string, any> = {}

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"
);
Expand All @@ -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"
);
Expand All @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand All @@ -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()) {
Expand All @@ -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()) {
Expand All @@ -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()) {
Expand All @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit 8f70eaa

Please sign in to comment.