Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { exec } = require("child_process");
- const { readFile, writeFile } = require('node:fs/promises');
- exec("grep -Rl \"t(LABELS.\" .", (error, stdout, stderr) => {
- if (error) {
- console.log(`error: ${error.message}`);
- return;
- }
- if (stderr) {
- console.log(`stderr: ${stderr}`)
- }
- const lines = stdout.split("\n");
- lines.filter(line => line.endsWith('tsx')).forEach(async (line) => {
- const file = await readFile(line, 'utf-8');
- if (!file.includes('useTranslation')) {
- const fileLines = file.split('\n');
- const lineNumberToInsert = fileLines.findIndex(line => line.includes('=> {')) + 1
- fileLines.splice(lineNumberToInsert, 0, ' const { t } = useTranslation()');
- fileLines.splice(0, 0, 'import { useTranslation } from \'react-i18next\'');
- await writeFile(line, fileLines.join('\n'))
- }
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement