diff --git a/components/FinancialSummary/BarChartComponent.tsx b/components/FinancialSummary/BarChartComponent.tsx index 55bf51c5b045..019927672cb0 100644 --- a/components/FinancialSummary/BarChartComponent.tsx +++ b/components/FinancialSummary/BarChartComponent.tsx @@ -3,8 +3,8 @@ import { Bar, BarChart, CartesianGrid, Legend, Tooltip, YAxis } from 'recharts'; import type { ExpenseItem, ExpensesLinkItem } from '@/types/FinancialSummary/BarChartComponent'; -import ExpensesData from '../../config/finance/json-data/2024/Expenses.json'; -import ExpensesLinkData from '../../config/finance/json-data/2024/ExpensesLink.json'; +import ExpensesData from '../../config/finance/json-data/Expenses.json'; +import ExpensesLinkData from '../../config/finance/json-data/ExpensesLink.json'; import { getUniqueCategories } from '../../utils/getUniqueCategories'; import CustomTooltip from './CustomTooltip'; import ExpensesCard from './ExpensesCard'; diff --git a/components/FinancialSummary/Card.tsx b/components/FinancialSummary/Card.tsx index 2433fbd52cbd..7e46e272733b 100644 --- a/components/FinancialSummary/Card.tsx +++ b/components/FinancialSummary/Card.tsx @@ -1,6 +1,6 @@ import type { ExpenseItem, Expenses } from '@/types/FinancialSummary/BarChartComponent'; -import ExpensesLinkData from '../../config/finance/json-data/2024/ExpensesLink.json'; +import ExpensesLinkData from '../../config/finance/json-data/ExpensesLink.json'; /** * @description Card component displays expense details for a specific month. diff --git a/components/FinancialSummary/ExpensesCard.tsx b/components/FinancialSummary/ExpensesCard.tsx index fb747ce3a896..86af3e7b1b83 100644 --- a/components/FinancialSummary/ExpensesCard.tsx +++ b/components/FinancialSummary/ExpensesCard.tsx @@ -1,6 +1,6 @@ import type { Expenses } from '@/types/FinancialSummary/BarChartComponent'; -import ExpensesData from '../../config/finance/json-data/2024/Expenses.json'; +import ExpensesData from '../../config/finance/json-data/Expenses.json'; import Card from './Card'; /** diff --git a/scripts/finance/index.js b/scripts/finance/index.js index 2433d143bbad..3f4a5edcfb6e 100644 --- a/scripts/finance/index.js +++ b/scripts/finance/index.js @@ -1,20 +1,16 @@ -const { promises: { mkdir } } = require('fs'); +const { + promises: { mkdir } +} = require('fs'); const { resolve } = require('path'); const writeJSON = require('../utils/readAndWriteJson.js'); -module.exports = async function buildFinanceInfoList({ - currentDir, - configDir, - financeDir, - year, - jsonDataDir -}) { +module.exports = async function buildFinanceInfoList({ currentDir, configDir, financeDir, year, jsonDataDir }) { try { const expensesPath = resolve(currentDir, configDir, financeDir, year, 'Expenses.yml'); const expensesLinkPath = resolve(currentDir, configDir, financeDir, year, 'ExpensesLink.yml'); // Ensure the directory exists before writing the files - const jsonDirectory = resolve(currentDir, configDir, financeDir, jsonDataDir, year); + const jsonDirectory = resolve(currentDir, configDir, financeDir, jsonDataDir); await mkdir(jsonDirectory, { recursive: true }); // Write Expenses and ExpensesLink to JSON files diff --git a/scripts/index.js b/scripts/index.js index b37750801266..33125fe7533b 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -1,9 +1,10 @@ +const { resolve } = require('path'); +const fs = require('fs'); const rssFeed = require('./build-rss'); const buildPostList = require('./build-post-list'); const buildCaseStudiesList = require('./casestudies'); -const buildAdoptersList = require('./adopters') +const buildAdoptersList = require('./adopters'); const buildFinanceInfoList = require('./finance'); -const { resolve } = require('path'); async function start() { await buildPostList(); @@ -18,11 +19,31 @@ async function start() { resolve(__dirname, '../config', 'case-studies.json') ); await buildAdoptersList(); + const financeDir = resolve('.', 'config', 'finance'); + + // loop through all the files finance in directory and find the latest year to build the finance info list + const yearsList = fs + .readdirSync(financeDir) + // filter out any files that are not numbers + .filter((file) => { + return !Number.isNaN(parseFloat(file)); + }) + // sort the years in descending order + .sort((a, b) => { + return parseFloat(b) - parseFloat(a); + }); + + if (yearsList.length === 0) { + throw new Error('No finance data found in the finance directory.'); + } + + const latestYear = yearsList[0]; + await buildFinanceInfoList({ currentDir: '.', configDir: 'config', financeDir: 'finance', - year: '2024', + year: latestYear, jsonDataDir: 'json-data' }); } diff --git a/tests/finance/index.test.js b/tests/finance/index.test.js index 93f34ee5c0ce..eaea82e86c60 100644 --- a/tests/finance/index.test.js +++ b/tests/finance/index.test.js @@ -1,7 +1,7 @@ const fs = require('fs'); const path = require('path'); const buildFinanceInfoList = require('../../scripts/finance/index'); -const { expensesYaml, expensesLinkYaml, expensesjson, expensesLinkjson } = require("../fixtures/financeData") +const { expensesYaml, expensesLinkYaml, expensesjson, expensesLinkjson } = require('../fixtures/financeData'); describe('buildFinanceInfoList', () => { const testDir = path.resolve(__dirname, 'test-finance-info'); @@ -32,7 +32,7 @@ describe('buildFinanceInfoList', () => { jsonDataDir }); - const jsonDir = path.resolve(testDir, configDir, financeDir, jsonDataDir, year); + const jsonDir = path.resolve(testDir, configDir, financeDir, jsonDataDir); // Check if JSON directory was created expect(fs.existsSync(jsonDir)).toBe(true); diff --git a/utils/getUniqueCategories.ts b/utils/getUniqueCategories.ts index e2f64b32a692..d239ee12c478 100644 --- a/utils/getUniqueCategories.ts +++ b/utils/getUniqueCategories.ts @@ -1,4 +1,4 @@ -import Expenses from '../config/finance/json-data/2024/Expenses.json'; +import Expenses from '../config/finance/json-data/Expenses.json'; /** * Retrieves unique expense categories from the Expenses data.