Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update financial data for current year #2687

Merged
merged 22 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e31f020
Auto update financial data
JeelRajodiya Jul 23, 2024
676ccab
update indention
JeelRajodiya Jul 23, 2024
1d98305
remove comment
JeelRajodiya Jul 24, 2024
2fdf27b
Move the current year inside the components
JeelRajodiya Jul 24, 2024
929a814
Merge branch 'master' into auto-year-detection
JeelRajodiya Jul 24, 2024
72b7190
Merge branch 'master' into auto-year-detection
JeelRajodiya Aug 23, 2024
9063550
Merge branch 'master' into auto-year-detection
JeelRajodiya Aug 26, 2024
a21b8dc
chore: add logic to find the foldername with latest year
JeelRajodiya Aug 27, 2024
e346334
chore: add error handling when the finance files are not present
JeelRajodiya Aug 29, 2024
f31af6a
new method to detect latest year
JeelRajodiya Aug 29, 2024
124209f
update indention
JeelRajodiya Aug 29, 2024
5f4ecd1
update path in the test
JeelRajodiya Aug 29, 2024
80b1702
remove unused import
JeelRajodiya Aug 29, 2024
1179dd7
fix formatting
JeelRajodiya Aug 29, 2024
28ea995
fix formatting
JeelRajodiya Aug 29, 2024
09ad54f
Merge branch 'master' into auto-year-detection
JeelRajodiya Aug 30, 2024
fddb7d6
Merge branch 'master' into auto-year-detection
JeelRajodiya Aug 30, 2024
4ea0a2e
Merge branch 'master' into auto-year-detection
JeelRajodiya Sep 7, 2024
ef8e8c8
Merge branch 'master' into auto-year-detection
JeelRajodiya Sep 9, 2024
b8c692b
Merge branch 'master' into auto-year-detection
JeelRajodiya Sep 10, 2024
555b5e5
Merge branch 'master' into auto-year-detection
JeelRajodiya Sep 14, 2024
be79285
Merge branch 'master' into auto-year-detection
akshatnema Sep 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/FinancialSummary/BarChartComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion components/FinancialSummary/Card.tsx
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion components/FinancialSummary/ExpensesCard.tsx
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down
14 changes: 5 additions & 9 deletions scripts/finance/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 24 additions & 3 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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'
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/finance/index.test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion utils/getUniqueCategories.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading