46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
const fs = require('fs');
|
|
const file = fs.readFileSync('src/data/projectsData.ts', 'utf8');
|
|
const lines = file.split('\n');
|
|
const newLines = [];
|
|
let insideArray = false;
|
|
for (const line of lines) {
|
|
if (line.includes('export const projectsData')) {
|
|
insideArray = true;
|
|
newLines.push(line);
|
|
continue;
|
|
}
|
|
if (insideArray && line.includes('{ id:')) {
|
|
const match = line.match(/{ id: '(\d+)', name: '(.*?)', status: '(.*?)' }/);
|
|
if (match) {
|
|
const id = match[1];
|
|
const nameFa = match[2];
|
|
const status = match[3];
|
|
const nameEn = 'Project ' + id;
|
|
const slug = 'project-' + id;
|
|
newLines.push(` { id: '${id}', slug: '${slug}', name: { en: '${nameEn}', fa: '${nameFa}' }, location: { en: 'Isfahan', fa: 'اصفهان' }, area: { en: '1000', fa: '۱۰۰۰' }, status: '${status}' },`);
|
|
} else {
|
|
newLines.push(line);
|
|
}
|
|
} else {
|
|
if (line.includes('export type StaticProject') || line.includes('id: string;') || line.includes('name: string;') || line.includes('status:') || line === '};') {
|
|
continue;
|
|
}
|
|
newLines.push(line);
|
|
}
|
|
}
|
|
|
|
const header = `export type BilingualText = { en: string; fa: string };
|
|
|
|
export type StaticProject = {
|
|
id: string;
|
|
slug: string;
|
|
name: BilingualText;
|
|
location: BilingualText;
|
|
area: BilingualText;
|
|
status: 'done' | 'progress';
|
|
};
|
|
|
|
`;
|
|
|
|
fs.writeFileSync('src/data/projectsData.ts', header + newLines.join('\n'));
|