Skip to content

Commit

Permalink
Merge from develop-postgres prior to code freeze (PalisadoesFoundat…
Browse files Browse the repository at this point in the history
…ion#3234)

* 20250109190418 Deleted all files in the develop branch in anticipation of merging develop-postgres into develop cleanly

* 20250109190422 Merge develop-postgres into develop
  • Loading branch information
palisadoes authored Jan 10, 2025
1 parent f30baa5 commit 7ce0153
Show file tree
Hide file tree
Showing 91 changed files with 3,186 additions and 2,017 deletions.
2 changes: 0 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run format:fix
# npm run lint:fix
Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export default {
],
coverageThreshold: {
global: {
lines: 20,
statements: 20,
lines: 1,
statements: 1,
},
},
testPathIgnorePatterns: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"format:check": "prettier --check \"**/*.{ts,tsx,json,scss,css}\"",
"check-tsdoc": "node .github/workflows/check-tsdoc.js",
"typecheck": "tsc --project tsconfig.json --noEmit",
"prepare": "husky install",
"prepare": "husky",
"jest-preview": "jest-preview",
"update:toc": "node scripts/githooks/update-toc.js",
"lint-staged": "lint-staged --concurrent false",
Expand Down
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
"endOfResults": "endOfResults"
},
"userChat": {
"title": "Chats",
"add": "Add",
"chat": "Chat",
"search": "Search",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
"endOfResults": "Fin des résultats"
},
"userChat": {
"title": "Discussions",
"add": "Ajouter",
"chat": "Chat",
"contacts": "Contacts",
Expand Down
1 change: 1 addition & 0 deletions public/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
"endOfResults": "परिणाम समाप्त"
},
"userChat": {
"title": "चैट्स",
"add": "जोड़ें",
"chat": "बात करना",
"contacts": "संपर्क",
Expand Down
1 change: 1 addition & 0 deletions public/locales/sp/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@
"createAdvertisement": "Crear publicidad"
},
"userChat": {
"title": "Chats",
"add": "Agregar",
"chat": "Charlar",
"search": "Buscar",
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
"endOfResults": "结果结束"
},
"userChat": {
"title": "聊天",
"add": "添加",
"chat": "聊天",
"contacts": "联系方式",
Expand Down
203 changes: 53 additions & 150 deletions setup.ts
Original file line number Diff line number Diff line change
@@ -1,165 +1,48 @@
import dotenv from 'dotenv';
import fs from 'fs';
import inquirer from 'inquirer';
import { checkConnection } from './src/setup/checkConnection/checkConnection';
import { askForTalawaApiUrl } from './src/setup/askForTalawaApiUrl/askForTalawaApiUrl';
import { checkEnvFile } from './src/setup/checkEnvFile/checkEnvFile';
import { validateRecaptcha } from './src/setup/validateRecaptcha/validateRecaptcha';
import { askForCustomPort } from './src/setup/askForCustomPort/askForCustomPort';

export async function main(): Promise<void> {
console.log('Welcome to the Talawa Admin setup! 🚀');

if (!fs.existsSync('.env')) {
fs.openSync('.env', 'w');
const config = dotenv.parse(fs.readFileSync('.env.example'));
for (const key in config) {
fs.appendFileSync('.env', `${key}=${config[key]}\n`);
}
} else {
checkEnvFile();
}

let shouldSetCustomPort: boolean;

if (process.env.PORT) {
console.log(
`\nCustom port for development server already exists with the value:\n${process.env.PORT}`,
);
shouldSetCustomPort = true;
} else {
const { shouldSetCustomPortResponse } = await inquirer.prompt({
import askAndSetDockerOption from './src/setup/askAndSetDockerOption/askAndSetDockerOption';
import updateEnvFile from './src/setup/updateEnvFile/updateEnvFile';
import askAndUpdatePort from './src/setup/askAndUpdatePort/askAndUpdatePort';
import { askAndUpdateTalawaApiUrl } from './src/setup/askForDocker/askForDocker';

// Ask and set up reCAPTCHA
const askAndSetRecaptcha = async (): Promise<void> => {
try {
const { shouldUseRecaptcha } = await inquirer.prompt({
type: 'confirm',
name: 'shouldSetCustomPortResponse',
message: 'Would you like to set up a custom port?',
name: 'shouldUseRecaptcha',
message: 'Would you like to set up reCAPTCHA?',
default: true,
});
shouldSetCustomPort = shouldSetCustomPortResponse;
}

if (shouldSetCustomPort) {
const customPort = await askForCustomPort();

const port = dotenv.parse(fs.readFileSync('.env')).PORT;

fs.readFile('.env', 'utf8', (err, data) => {
const result = data.replace(`PORT=${port}`, `PORT=${customPort}`);
fs.writeFileSync('.env', result, 'utf8');
});
}

let shouldSetTalawaApiUrl: boolean;

if (process.env.REACT_APP_TALAWA_URL) {
console.log(
`\nEndpoint for accessing talawa-api graphql service already exists with the value:\n${process.env.REACT_APP_TALAWA_URL}`,
);
shouldSetTalawaApiUrl = true;
} else {
const { shouldSetTalawaApiUrlResponse } = await inquirer.prompt({
type: 'confirm',
name: 'shouldSetTalawaApiUrlResponse',
message: 'Would you like to set up talawa-api endpoint?',
default: true,
});
shouldSetTalawaApiUrl = shouldSetTalawaApiUrlResponse;
}

if (shouldSetTalawaApiUrl) {
let isConnected = false,
endpoint = '';

while (!isConnected) {
endpoint = await askForTalawaApiUrl();
const url = new URL(endpoint);
isConnected = await checkConnection(url.origin);
}
const envPath = '.env';
const currentEnvContent = fs.readFileSync(envPath, 'utf8');
const talawaApiUrl = dotenv.parse(currentEnvContent).REACT_APP_TALAWA_URL;

const updatedEnvContent = currentEnvContent.replace(
`REACT_APP_TALAWA_URL=${talawaApiUrl}`,
`REACT_APP_TALAWA_URL=${endpoint}`,
);

fs.writeFileSync(envPath, updatedEnvContent, 'utf8');
const websocketUrl = endpoint.replace(/^http(s)?:\/\//, 'ws$1://');
const currentWebSocketUrl =
dotenv.parse(updatedEnvContent).REACT_APP_BACKEND_WEBSOCKET_URL;

const finalEnvContent = updatedEnvContent.replace(
`REACT_APP_BACKEND_WEBSOCKET_URL=${currentWebSocketUrl}`,
`REACT_APP_BACKEND_WEBSOCKET_URL=${websocketUrl}`,
);

fs.writeFileSync(envPath, finalEnvContent, 'utf8');
}

const { shouldUseRecaptcha } = await inquirer.prompt({
type: 'confirm',
name: 'shouldUseRecaptcha',
message: 'Would you like to set up ReCAPTCHA?',
default: true,
});

if (shouldUseRecaptcha) {
const useRecaptcha = dotenv.parse(
fs.readFileSync('.env'),
).REACT_APP_USE_RECAPTCHA;

fs.readFile('.env', 'utf8', (err, data) => {
const result = data.replace(
`REACT_APP_USE_RECAPTCHA=${useRecaptcha}`,
`REACT_APP_USE_RECAPTCHA=yes`,
);
fs.writeFileSync('.env', result, 'utf8');
});
let shouldSetRecaptchaSiteKey: boolean;
if (process.env.REACT_APP_RECAPTCHA_SITE_KEY) {
console.log(
`\nreCAPTCHA site key already exists with the value ${process.env.REACT_APP_RECAPTCHA_SITE_KEY}`,
);
shouldSetRecaptchaSiteKey = true;
} else {
const { shouldSetRecaptchaSiteKeyResponse } = await inquirer.prompt({
type: 'confirm',
name: 'shouldSetRecaptchaSiteKeyResponse',
message: 'Would you like to set up a reCAPTCHA site key?',
default: true,
});
shouldSetRecaptchaSiteKey = shouldSetRecaptchaSiteKeyResponse;
}

if (shouldSetRecaptchaSiteKey) {
if (shouldUseRecaptcha) {
const { recaptchaSiteKeyInput } = await inquirer.prompt([
{
type: 'input',
name: 'recaptchaSiteKeyInput',
message: 'Enter your reCAPTCHA site key:',
validate: async (input: string): Promise<boolean | string> => {
if (validateRecaptcha(input)) {
return true;
}
return 'Invalid reCAPTCHA site key. Please try again.';
validate: (input: string): boolean | string => {
return (
validateRecaptcha(input) ||
'Invalid reCAPTCHA site key. Please try again.'
);
},
},
]);

const recaptchaSiteKey = dotenv.parse(
fs.readFileSync('.env'),
).REACT_APP_RECAPTCHA_SITE_KEY;

fs.readFile('.env', 'utf8', (err, data) => {
const result = data.replace(
`REACT_APP_RECAPTCHA_SITE_KEY=${recaptchaSiteKey}`,
`REACT_APP_RECAPTCHA_SITE_KEY=${recaptchaSiteKeyInput}`,
);
fs.writeFileSync('.env', result, 'utf8');
});
updateEnvFile('REACT_APP_RECAPTCHA_SITE_KEY', recaptchaSiteKeyInput);
}
} catch (error) {
console.error('Error setting up reCAPTCHA:', error);
throw new Error(`Failed to set up reCAPTCHA: ${(error as Error).message}`);
}
};

// Ask and set up logging errors in the console
const askAndSetLogErrors = async (): Promise<void> => {
const { shouldLogErrors } = await inquirer.prompt({
type: 'confirm',
name: 'shouldLogErrors',
Expand All @@ -169,17 +52,37 @@ export async function main(): Promise<void> {
});

if (shouldLogErrors) {
const logErrors = dotenv.parse(fs.readFileSync('.env')).ALLOW_LOGS;

fs.readFile('.env', 'utf8', (err, data) => {
const result = data.replace(`ALLOW_LOGS=${logErrors}`, 'ALLOW_LOGS=YES');
fs.writeFileSync('.env', result, 'utf8');
});
updateEnvFile('ALLOW_LOGS', 'YES');
}
};

console.log(
'\nCongratulations! Talawa Admin has been successfully setup! 🥂🎉',
);
// Main function to run the setup process
export async function main(): Promise<void> {
try {
console.log('Welcome to the Talawa Admin setup! 🚀');

checkEnvFile();
await askAndSetDockerOption();
const envConfig = dotenv.parse(fs.readFileSync('.env', 'utf8'));
const useDocker = envConfig.USE_DOCKER === 'YES';

// Only run these commands if Docker is NOT used
if (!useDocker) {
await askAndUpdatePort();
await askAndUpdateTalawaApiUrl();
}

await askAndSetRecaptcha();
await askAndSetLogErrors();

console.log(
'\nCongratulations! Talawa Admin has been successfully set up! 🥂🎉',
);
} catch (error) {
console.error('\n❌ Setup failed:', error);
console.log('\nPlease try again or contact support if the issue persists.');
process.exit(1);
}
}

main();
21 changes: 21 additions & 0 deletions src/assets/css/app.css

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

Empty file.
2 changes: 1 addition & 1 deletion src/components/EventCalendar/EventHeader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('EventHeader Component', () => {
fireEvent.click(getByTestId('eventType'));

await act(async () => {
fireEvent.click(getByTestId('events'));
fireEvent.click(getByTestId('Events'));
});

expect(handleChangeView).toHaveBeenCalledTimes(1);
Expand Down
Loading

0 comments on commit 7ce0153

Please sign in to comment.