diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 36277e0991..9233bb8a4a 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -10,10 +10,10 @@ - [Scope](#scope) - [Enforcement](#enforcement) - [Enforcement Guidelines](#enforcement-guidelines) - - [1. Correction](#1-correction) - - [2. Warning](#2-warning) - - [3. Temporary Ban](#3-temporary-ban) - - [4. Permanent Ban](#4-permanent-ban) + * [1. Correction](#1-correction) + * [2. Warning](#2-warning) + * [3. Temporary Ban](#3-temporary-ban) + * [4. Permanent Ban](#4-permanent-ban) - [Attribution](#attribution) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4fd54f64e1..bcf374fff6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,26 +10,26 @@ If you are new to contributing to open source, please read the Open Source Guide - [Code of Conduct](#code-of-conduct) - [Ways to Contribute](#ways-to-contribute) - - [Our Development Process](#our-development-process) - - [Issues](#issues) - - [Pull Requests](#pull-requests) - - [Branching Strategy](#branching-strategy) - - [Conflict Resolution](#conflict-resolution) - - [Contributing Code](#contributing-code) + * [Our Development Process](#our-development-process) + + [Issues](#issues) + + [Pull Requests](#pull-requests) + + [Branching Strategy](#branching-strategy) + + [Conflict Resolution](#conflict-resolution) + * [Contributing Code](#contributing-code) - [Upgrading Code](#upgrading-code) - - [Setting up Upstream and Origin](#setting-up-upstream-and-origin) - - [Creating a Pull Request - Process Overview](#creating-a-pull-request---process-overview) + + [Setting up Upstream and Origin](#setting-up-upstream-and-origin) + + [Creating a Pull Request - Process Overview](#creating-a-pull-request---process-overview) - [Type checking and code quality](#type-checking-and-code-quality) - - [Type checking code files](#type-checking-code-files) - - [Linting code files](#linting-code-files) - - [Formatting code files](#formatting-code-files) - - [Generating Table of Contents](#generating-table-of-contents) - - [Automation using husky](#automation-using-husky) - - [Pre-Commit hook](#pre-commit-hook) - - [Post-Merge hook](#post-merge-hook) - - [GraphQL Voyager](#graphql-voyager) - - [GraphQL Markdown](#graphql-markdown) - - [Running Queries with talawa-api](#running-queries-with-talawa-api) + * [Type checking code files](#type-checking-code-files) + * [Linting code files](#linting-code-files) + * [Formatting code files](#formatting-code-files) + * [Generating Table of Contents](#generating-table-of-contents) + * [Automation using husky](#automation-using-husky) + + [Pre-Commit hook](#pre-commit-hook) + + [Post-Merge hook](#post-merge-hook) + * [GraphQL Voyager](#graphql-voyager) + * [GraphQL Markdown](#graphql-markdown) + * [Running Queries with talawa-api](#running-queries-with-talawa-api) - [Internships](#internships) - [Community](#community) @@ -243,7 +243,7 @@ To fix formatting issues in code use this command:- ### Generating Table of Contents To generate table of contents for markdown files use this command:- ```bash -npm run update:toc +npm run generate:toc ``` And if you want to generate table of content for specific file you can use the `markdown-toc` package directly as shown:- ```bash diff --git a/INSTALLATION.md b/INSTALLATION.md index 8ab8b09599..07fbd85056 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -7,65 +7,65 @@ This document provides instructions on how to set up and start a running instanc - [Prerequisites](#prerequisites) - - [Install node.js](#install-nodejs) - - [Install npm](#install-npm) - - [Install TypeScript](#install-typescript) - - [Install git](#install-git) - - [Setting up this repository](#setting-up-this-repository) - - [Install the Required Packages](#install-the-required-packages) + * [Install node.js](#install-nodejs) + * [Install npm](#install-npm) + * [Install TypeScript](#install-typescript) + * [Install git](#install-git) + * [Setting up this repository](#setting-up-this-repository) + * [Install the Required Packages](#install-the-required-packages) +- [Setting up .env file](#setting-up-env-file) - [Installation Using Docker](#installation-using-docker) - [Installation without Docker](#installation-without-docker) - - [Install MongoDB](#install-mongodb) - - [Setting up the mongoDB database](#setting-up-the-mongodb-database) - - [Install Redis](#install-redis) - - [Performance Benefits](#performance-benefits) - - [Setting Up Redis](#setting-up-redis) + * [Install MongoDB](#install-mongodb) + + [Setting up the mongoDB database](#setting-up-the-mongodb-database) + * [Install Redis](#install-redis) + + [Performance Benefits](#performance-benefits) + + [Setting Up Redis](#setting-up-redis) - [Configuration](#configuration) - - [Automated Configuration of `.env`](#automated-configuration-of-env) - - [Manual Configuration of `.env`](#manual-configuration-of-env) - - [The Environment Variables in `.env`](#the-environment-variables-in-env) - - [Changing the Development Environment in the .env file](#changing-the-development-environment-in-the-env-file) - - [Generating Token Secrets](#generating-token-secrets) - - [Setting up ACCESS_TOKEN_SECRET in the .env file](#setting-up-access_token_secret-in-the-env-file) - - [Linux](#linux) - - [Windows](#windows) - - [Setting up REFRESH_TOKEN_SECRET in the .env file](#setting-up-refresh_token_secret-in-the-env-file) - - [Configuring MongoDB in the .env file](#configuring-mongodb-in-the-env-file) - - [Using the CLI to get the MONGODB_URL Connection String](#using-the-cli-to-get-the-mongodb_url-connection-string) - - [Using Microsoft Windows to get the MONGODB_URL Connection String](#using-microsoft-windows-to-get-the-mongodb_url-connection-string) - - [Configuring Redis in .env file](#configuring-redis-in-env-file) - - [For Local Setup (Linux and WSL)](#for-local-setup-linux-and-wsl) - - [For Remote Setup (Redis Cloud)](#for-remote-setup-redis-cloud) - - [Setting up .env LAST_RESORT_SUPERADMIN_EMAIL parameter in the .env file](#setting-up-env-last_resort_superadmin_email-parameter-in-the-env-file) - - [Configuring Google ReCAPTCHA in the .env file](#configuring-google-recaptcha-in-the-env-file) - - [Setting up the RECAPTCHA_SECRET_KEY](#setting-up-the-recaptcha_secret_key) - - [Setting up .env MAIL_USERNAME and MAIL_PASSWORD ReCAPTCHA Parameters](#setting-up-env-mail_username-and-mail_password-recaptcha-parameters) - - [Setting up SMTP Email Variables in the .env File](#setting-up-smtp-email-variables-in-the-env-file) - - [Setting up Logger configurations _(optional)_](#setting-up-logger-configurations-_optional_) - - [Setting up COLORIZE_LOGS in .env file](#setting-up-colorize_logs-in-env-file) - - [Setting up LOG_LEVEL in .env file](#setting-up-log_level-in-env-file) + * [The .env Configuration File](#the-env-configuration-file) + * [Changing the environment of talawa-api](#changing-the-environment-of-talawa-api) + * [Generating Token Secrets](#generating-token-secrets) + + [Setting up ACCESS_TOKEN_SECRET in .env file](#setting-up-access_token_secret-in-env-file) + - [Linux](#linux) + - [Windows](#windows) + + [Setting up REFRESH_TOKEN_SECRET in .env file](#setting-up-refresh_token_secret-in-env-file) + * [Configuring MongoDB](#configuring-mongodb) + + [Setting up the MONGODB_URL in .env file](#setting-up-the-mongodb_url-in-env-file) + + [Using the CLI to get the MONGODB_URL Connection String](#using-the-cli-to-get-the-mongodb_url-connection-string) + + [Using Microsoft Windows to get the MONGODB_URL Connection String](#using-microsoft-windows-to-get-the-mongodb_url-connection-string) + * [Configuring Redis](#configuring-redis) + + [For Local Setup (Linux and WSL)](#for-local-setup-linux-and-wsl) + + [For Remote Setup (Redis Cloud)](#for-remote-setup-redis-cloud) + * [Setting up .env LAST_RESORT_SUPERADMIN_EMAIL parameter](#setting-up-env-last_resort_superadmin_email-parameter) + * [Configuring Google ReCAPTCHA](#configuring-google-recaptcha) + + [Setting up RECAPTCHA_SECRET_KEY in .env file](#setting-up-recaptcha_secret_key-in-env-file) + + [Setting up .env MAIL_USERNAME and MAIL_PASSWORD ReCAPTCHA Parameters](#setting-up-env-mail_username-and-mail_password-recaptcha-parameters) + + [Setting up .env SMTP Variables](#setting-up-env-smtp-variables) + * [Setting up Logger configurations _(optional)_](#setting-up-logger-configurations-_optional_) + + [Setting up COLORIZE_LOGS in .env file](#setting-up-colorize_logs-in-env-file) + + [Setting up LOG_LEVEL in .env file](#setting-up-log_level-in-env-file) - [Importing Sample Database](#importing-sample-database) - - [Syntax:](#syntax) - - [Examples:](#examples) - - [Sample Data Overview:](#sample-data-overview) - - [User Accounts and Organizations:](#user-accounts-and-organizations) - - [Posts](#posts) - - [Events](#events) + * [Syntax:](#syntax) + * [Examples:](#examples) + * [Sample Data Overview:](#sample-data-overview) + + [User Accounts and Organizations:](#user-accounts-and-organizations) + + [Posts](#posts) + + [Events](#events) - [Running Talawa-API](#running-talawa-api) - [How to Access the Talawa-API URL](#how-to-access-the-talawa-api-url) - - [For Talawa-API Developers](#for-talawa-api-developers) - - [For Mobile App Developers](#for-mobile-app-developers) - - [On Android Virtual Device](#on-android-virtual-device) - - [On a Real Mobile Device](#on-a-real-mobile-device) - - [For Talawa-Admin Developers](#for-talawa-admin-developers) + * [For Talawa-API Developers](#for-talawa-api-developers) + * [For Mobile App Developers](#for-mobile-app-developers) + + [On Android Virtual Device](#on-android-virtual-device) + + [On a Real Mobile Device](#on-a-real-mobile-device) + * [For Talawa-Admin Developers](#for-talawa-admin-developers) - [Accessing MongoDB](#accessing-mongodb) - - [Managing MongoDB using the MongoDB Compass GUI](#managing-mongodb-using-the-mongodb-compass-gui) - - [Managing MongoDB using the VSCode extension](#managing-mongodb-using-the-vscode-extension) + * [Managing MongoDB using the MongoDB Compass GUI](#managing-mongodb-using-the-mongodb-compass-gui) + * [Managing MongoDB using the VSCode extension](#managing-mongodb-using-the-vscode-extension) - [Manually Adding The First Super Admin User](#manually-adding-the-first-super-admin-user) - - [Using MongoDB Compass](#using-mongodb-compass) - - [Using Mongo Shell](#using-mongo-shell) + * [Using MongoDB Compass](#using-mongodb-compass) + * [Using Mongo Shell](#using-mongo-shell) - [Other](#other) - - [Changing default talawa-api port](#changing-default-talawa-api-port) + * [Changing default talawa-api port](#changing-default-talawa-api-port) - [Testing](#testing) diff --git a/ISSUE_GUIDELINES.md b/ISSUE_GUIDELINES.md index bf120e5114..e61a29b878 100644 --- a/ISSUE_GUIDELINES.md +++ b/ISSUE_GUIDELINES.md @@ -10,10 +10,10 @@ ___ - [Issue Management](#issue-management) - - [New Issues](#new-issues) - - [Existing Issues](#existing-issues) - - [Feature Request Issues](#feature-request-issues) - - [Monitoring the Creation of New Issues](#monitoring-the-creation-of-new-issues) + * [New Issues](#new-issues) + * [Existing Issues](#existing-issues) + * [Feature Request Issues](#feature-request-issues) + * [Monitoring the Creation of New Issues](#monitoring-the-creation-of-new-issues) - [General Guidelines](#general-guidelines) diff --git a/PR_GUIDELINES.md b/PR_GUIDELINES.md index f4cb3052d3..40bceb8c46 100644 --- a/PR_GUIDELINES.md +++ b/PR_GUIDELINES.md @@ -3,10 +3,10 @@ - [Pull Request Guidelines](#pull-request-guidelines) - - [Pull Requests and Issues](#pull-requests-and-issues) - - [Testing](#testing) - - [Pull Request Processing](#pull-request-processing) - - [Only submit PRs against our `develop` branch, not the default `main` branch](#only-submit-prs-against-our-develop-branch-not-the-default-main-branch) + * [Pull Requests and Issues](#pull-requests-and-issues) + * [Testing](#testing) + * [Pull Request Processing](#pull-request-processing) + + [Only submit PRs against our `develop` branch, not the default `main` branch](#only-submit-prs-against-our-develop-branch-not-the-default-main-branch) diff --git a/README.md b/README.md index c967c73ff8..68b497df43 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -## Table of Contents + - [Talawa API](#talawa-api) - - [Talawa Components](#talawa-components) - - [Documentation](#documentation) - - [Installation](#installation) - - [Image Upload](#image-upload) + * [Talawa Components](#talawa-components) + * [Documentation](#documentation) + * [Installation](#installation) + * [Image Upload](#image-upload) diff --git a/package-lock.json b/package-lock.json index 3ddda7617e..6d5dac9f62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16019,6 +16019,20 @@ } } }, + "node_modules/xss-clean": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/xss-clean/-/xss-clean-0.1.4.tgz", + "integrity": "sha512-4hArTFHYxrifK9VXOu/zFvwjTXVjKByPi6woUHb1IqxlX0Z4xtFBRjOhTKuYV/uE1VswbYsIh5vUEYp7MmoISQ==", + "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.", + "dependencies": { + "xss-filters": "1.2.7" + } + }, + "node_modules/xss-filters": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/xss-filters/-/xss-filters-1.2.7.tgz", + "integrity": "sha512-KzcmYT/f+YzcYrYRqw6mXxd25BEZCxBQnf+uXTopQDIhrmiaLwO+f+yLsIvvNlPhYvgff8g3igqrBxYh9k8NbQ==" + }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/package.json b/package.json index b30fd059c2..1b5d95a374 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "import:sample-data": "ts-node ./src/utilities/loadSampleData.ts", "import:sample-data:prod": "node ./build/utilities/loadSampleData.js", "gen:schema": "graphql-inspector introspect ./src/typeDefs/**/**/*.ts --write ./schema.graphql ", - "update:toc": "node scripts/githooks/update-toc.js" + "generate:toc": "node src/scripts/githooks/generate-toc" }, "repository": { "type": "git", diff --git a/src/scripts/githooks/generate-toc.js b/src/scripts/githooks/generate-toc.js new file mode 100644 index 0000000000..fc72bd0223 --- /dev/null +++ b/src/scripts/githooks/generate-toc.js @@ -0,0 +1,60 @@ +const fs = require("fs"); +const path = require("path"); +const { execSync } = require("child_process"); + +// Getting the current working directory +const directory = process.cwd(); + +/** + * This function finds all markdown files at the root level of a given directory. + * @param {string} dir - The directory to search in. + * @returns {string[]} - An array of markdown file names. + */ +const findMarkdownFiles = (dir) => { + // Reading the directory + const dirents = fs.readdirSync(dir, { withFileTypes: true }); + + // Filtering out the files + const files = dirents + .filter((dirent) => dirent.isFile()) + .map((dirent) => dirent.name); + + // Returning only the markdown files + return files.filter((file) => path.extname(file) === ".md"); +}; + +/** + * This function generates a table of contents for a given markdown file. + * @param {string} file - The markdown file to generate a table of contents for. + */ +const generateTOC = (file) => { + // Constructing the file path + const filePath = path.join(directory, file); + + // Generating the table of contents + execSync(`markdown-toc -i ${filePath}`); + + // Logging the result + console.log(`Table of contents generated for ${file}`); +}; + +/** + * The main function of the script. + * It finds all markdown files in the current directory and generates a table of contents for each one. + */ +function main() { + // Finding all markdown files + const markdownFiles = findMarkdownFiles(directory); + + // Checking if any markdown files were found + if (markdownFiles.length === 0) { + // Logging an error message and returning if no markdown files were found + console.error("No Markdown files found in the current directory."); + return; + } + + // Generating a table of contents for each markdown file + markdownFiles.forEach(generateTOC); +} + +main();