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

fix: update-financial-year #3198

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
117 changes: 88 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"clsx": "^2.1.0",
"cssnano": "^6.0.3",
"dotenv": "^16.4.4",
"extend-shallow": "^3.0.2",
"fuse.js": "^7.0.0",
"googleapis": "^133.0.0",
"gray-matter": "^4.0.3",
Expand Down
57 changes: 57 additions & 0 deletions scripts/finance/update-year.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const fs = require('fs').promises;
const path = require('path');

// Define the files to update
const filesToUpdate = [
'./index.js',
'../../utils/getUniqueCategories.ts',
'../../components/FinancialSummary/BarChartComponent.tsx'
];

// Get the current year
const currentYear = new Date().getFullYear().toString();

// Path where the year folder will be created
const financeDir = path.resolve(__dirname, 'finance', currentYear);

// Function to create a directory for the current year
const createYearDirectory = async () => {
try {
await fs.mkdir(financeDir, { recursive: true });
console.log(`Created directory: ${financeDir}`);
} catch (err) {
console.error(`Error creating directory: ${err.message}`);
throw err;
}
};

// Function to update the year in specified files
const updateYearInFiles = async () => {
try {
for (const filePath of filesToUpdate) {
const fullPath = path.resolve(__dirname, filePath);
const fileContent = await fs.readFile(fullPath, 'utf8');

// Replace old year
const updatedContent = fileContent.replace(/\b\d{4}\b/g, currentYear);

await fs.writeFile(fullPath, updatedContent, 'utf8');
console.log(`Updated year in ${fullPath} to ${currentYear}`);
}
} catch (err) {
console.error(`Error updating files: ${err.message}`);
throw err;
}
};

// Main function to execute the directory creation and file updates
const main = async () => {
try {
await createYearDirectory();
await updateYearInFiles();
} catch (err) {
console.error(`Error: ${err.message}`);
}
};

main();
Loading