Skip to content

Commit

Permalink
Updated symlinks, added scripts, updated readme (ohcnetwork#404)
Browse files Browse the repository at this point in the history
* Updated symlinks, added scripts, updated markdown

* added build command

* remove yarn lock

* gitignore

* maybe this works

* pnpm lock

* build command change

* wrong script mb

* minor change to package json
  • Loading branch information
shivankacker authored Mar 30, 2024
1 parent 5f58e97 commit 09ac838
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 91 deletions.
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ NEXT_PUBLIC_META_URL=https://leaderboard.ohc.network
## -- Page Details -- ##
NEXT_PUBLIC_PAGE_TITLE=OHC Network Contributors
NEXT_PUBLIC_CONTRIBUTORS_INFO=""
NEXT_PUBLIC_LEADERBOARD_DEFAULT_ROLES=core,intern,contributor
NEXT_PUBLIC_LEADERBOARD_DEFAULT_ROLES=core,intern,contributor

## -- Data Source -- ##
DATA_SOURCE=https://github.com/coronasafe/leaderboard-data.git
10 changes: 8 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
"tailwindcss/classnames-order": "error",
"tailwindcss/enforces-shorthand": "off",
"tailwindcss/no-contradicting-classname": "error",
"tailwindcss/enforces-negative-arbitrary-values": "off"
"tailwindcss/enforces-negative-arbitrary-values": "off",
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
},
"ignorePatterns": ["data"]
"ignorePatterns": ["data"]
}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ data-repo

#IDE
.idea
.vscode
.vscode

# Package Lock
package-lock.json
yarn.lock
2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# Ignore data
./data
./contributors
./data-repo
53 changes: 18 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@ A simple leaderboard app built with Next.js and Tailwind CSS to list top contrib

## Getting Started

### Starting the deployment server

Run the following command in the terminal:

```bash
./load-org-data.sh
```
### Starting the development server

Install dependencies:

```bash
pnpm install
```

Now run the deployment server:
Now run the development server:

```bash
pnpm dev
Expand Down Expand Up @@ -64,37 +58,26 @@ All members marked with `role: core` and `role: operations` will be will be hidd

You will be able to see the users profile page at `http://localhost:3000/contributors/john-doe`.

## Customizing the app
# Customizing the app

1. To add or remove a badge, edit the `config/GraduateAttributes.ts` file.

2. To Setup the repo for a new org, update
the [scraper config](https://github.com/coronasafe/leaderboard/blob/d42c7b7ba608c4911d932e92679ab1914371c8a0/.github/workflows/main.yml#L32)
the [scraper config](https://github.com/coronasafe/leaderboard/blob/060d88f1caf2190792beffaa464a2a48bfa6f2db/.github/workflows/scraper.yaml#L40) and update the `DATA_SOURCE` variable in the `.env` file to match the repo containing your organization data.

3. To change the colors, fonts, or plugins edit the `tailwind.config.js` file.

### Environment Variables

#### **Organization Details**

- **NEXT_PUBLIC_ORG_NAME**
- Will be displayed in the navbar.
- **NEXT_PUBLIC_ORG_INFO**
- (Optional) Will be displayed in the "What do we do?" section.
- **NEXT_PUBLIC_ORG_LOGO**
- Will be displayed in the footer.

#### **SEO details**

- **NEXT_PUBLIC_META_TITLE**
- **NEXT_PUBLIC_META_IMG**
- **NEXT_PUBLIC_META_DESCRIPTION**
- **NEXT_PUBLIC_META_URL**

#### **Page Details**

- **NEXT_PUBLIC_PAGE_TITLE**
- Will be displayed in page title.
- **NEXT_PUBLIC_CONTRIBUTORS_INFO**
- (Optional) Will be displayed next to "Our Contributors" section. You can use it to display a note about your
contributors.
## Environment Variables

| Variable | Description | Default | Optional? |
|---|---|---|---|
| **NEXT_PUBLIC_ORG_NAME** | Will be displayed in the navbar | ohc.network | No |
| **NEXT_PUBLIC_ORG_INFO** | Will be displayed in the "What do we do?" section. | Open Healthcare Network is a free and open-source disaster management system that is used by National Health Mission, Government of India and various state governments for reimaging digital war rooms. The solution that students got an opportunity to intern with has supported 3.34Lac patient management and 1.29 Lac ambulance shiftings and is approved by the United Nations as a Digital Public Good. | Yes |
| **NEXT_PUBLIC_ORG_LOGO** | Will be displayed in the footer. | /logo.webp | No |
| **NEXT_PUBLIC_META_TITLE** | Metadata title | Open Healthcare Network | No |
| **NEXT_PUBLIC_META_IMG** | Metadata img | /logo.webp | No |
| **NEXT_PUBLIC_META_DESCRIPTION** | Metadata description | OHC Network Leaderboard tracks the weekly progress of all coronasafe contributors. | No |
| **NEXT_PUBLIC_META_URL** | Metadata url | https://leaderboard.ohc.network | No |
| **NEXT_PUBLIC_PAGE_TITLE** | Will be displayed in page title. | OHC Network Contributors | No |
| **NEXT_PUBLIC_CONTRIBUTORS_INFO** | Will be displayed next to "Our Contributors" section. You can use it to display a note about your contributors. | | Yes |
| **DATA_SOURCE** | Url for data repository | https://github.com/coronasafe/leaderboard-data.git | Yes |
4 changes: 2 additions & 2 deletions app/globals.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "../theme.css";
@import "../data-repo/config/theme.css";
@tailwind base;
@tailwind components;
@tailwind utilities;
Expand Down Expand Up @@ -129,4 +129,4 @@ html.dark {
opacity: 100;
transform: translateX(0px);
transform: translateY(0px);
}
}
1 change: 0 additions & 1 deletion contributors

This file was deleted.

1 change: 0 additions & 1 deletion data

This file was deleted.

6 changes: 3 additions & 3 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Activity, ActivityData, Contributor, Highlights } from "./types";
import { padZero } from "./utils";
import { readFile, readdir } from "fs/promises";

const root = join(process.cwd(), "contributors");
const slackRoot = join(process.cwd(), "data/slack");
const githubRoot = join(process.cwd(), "data/github");
const root = join(process.cwd(), "data-repo/contributors");
const slackRoot = join(process.cwd(), "data-repo/data/slack");
const githubRoot = join(process.cwd(), "data-repo/data/github");

const points = {
comment_created: 1,
Expand Down
30 changes: 0 additions & 30 deletions load-org-data.sh

This file was deleted.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"dev": "node ./scripts/checkData.js && next dev",
"build": "node ./scripts/loadOrgData.js && next build",
"start": "next start",
"lint": "next lint",
"lint-fix": "eslint . --fix",
"format": "prettier --write .",
"prepare": " husky install"
"load-data": "node ./scripts/loadOrgData.js",
"prepare": "husky install"
},
"dependencies": {
"@headlessui/react": "^1.7.18",
Expand Down Expand Up @@ -39,6 +40,7 @@
"@types/node": "^20.11.21",
"@types/react": "^18.2.60",
"autoprefixer": "^10.4.17",
"dotenv": "^16.4.5",
"eslint": "8.16.0",
"eslint-config-next": "^14.1.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -52,4 +54,4 @@
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3"
}
}
}
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

1 change: 0 additions & 1 deletion public/favicon.ico

This file was deleted.

1 change: 0 additions & 1 deletion public/logo.webp

This file was deleted.

33 changes: 33 additions & 0 deletions scripts/checkData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const dotenv = require('dotenv');
dotenv.config();

const dataRepoDir = "data-repo";

const askYN = (question, def, ycallback, ncallback) => {
console.log(`${question} (${def ? 'Y/n' : 'y/N'})`);
const stdin = process.openStdin();
stdin.addListener('data', function (d) {
const input = d.toString().trim().toLowerCase();
stdin.removeAllListeners('data');
if (input === 'y' || (!input && def)) {
ycallback();
} else if (input === 'n' || (!input && !def)) {
ncallback();
} else {
askYN(question, def, ycallback, ncallback);
}
});
}
if (!fs.existsSync(path.join(process.cwd(), dataRepoDir))) {
console.log("Looks like you have not loaded any data.")
askYN("Download data now?", true, () => {
execSync(`node scripts/loadOrgData.js`, { stdio: 'inherit' })
process.exit(0);
}, () => {
console.log("Aborting...");
process.exit(1);
});
}
6 changes: 3 additions & 3 deletions scripts/generateNewContributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Still waiting for this
function getNewContributors() {
let newContributors = new Set();

fs.readdirSync("./data/github").forEach((file) => {
fs.readdirSync("./data-repo/data/github").forEach((file) => {
newContributors.add(file.split(".")[0]);
});

fs.readdirSync("./contributors").forEach((file) => {
fs.readdirSync("./data-repo/contributors").forEach((file) => {
newContributors.delete(file.split(".")[0]);
});

Expand Down Expand Up @@ -54,7 +54,7 @@ function main() {
.then((data) => {
if (data.name === null) data.name = data.login;
fs.writeFile(
`./contributors/${data.login}.md`,
`./data-repo/contributors/${data.login}.md`,
generateContent(data.name, data.login),
(err) => {
if (err) throw err;
Expand Down
47 changes: 47 additions & 0 deletions scripts/loadOrgData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const dotenv = require('dotenv');
dotenv.config();

const DATA_SOURCE = process.env.DATA_SOURCE || null;
if (!DATA_SOURCE) {
console.error('Please provide a DATA_SOURCE environment variable');
process.exit(1);
}
const cwd = process.cwd();
const dataRepoPath = path.join(cwd, 'data-repo');

function executeCommand(command, workingDir = cwd) {
try {
const result = execSync(command, { cwd: workingDir, stdio: 'inherit' });
return result;
} catch (error) {
console.error(`Error executing command: ${command}`, error);
}
}

if (fs.existsSync(path.join(dataRepoPath, '.git'))) {
console.log("Updating existing data repository...");
const remotes = executeCommand('git remote -v', dataRepoPath)
if (remotes && remotes.includes('upstream')) {
executeCommand('git clean -df', dataRepoPath);
executeCommand('git fetch upstream', dataRepoPath);
executeCommand('git checkout --force main', dataRepoPath);
executeCommand('git reset --hard main', dataRepoPath);
executeCommand('git pull upstream main', dataRepoPath);
}
} else {
console.log("Cloning data repository for the first time...");

fs.rmSync(dataRepoPath, { recursive: true, force: true });
executeCommand(`git clone ${DATA_SOURCE} ${dataRepoPath}`);
executeCommand('git remote add upstream ' + DATA_SOURCE, dataRepoPath);
executeCommand('git remote remove origin', dataRepoPath);
executeCommand('git pull upstream main', dataRepoPath);
}

if (fs.existsSync(path.join(dataRepoPath, 'config/assets'))) {
console.log("Copying assets to public folder...");
fs.cpSync(path.join(dataRepoPath, 'config/assets'), path.join(cwd, 'public'), { recursive: true });
}
2 changes: 1 addition & 1 deletion scripts/slackEODReminder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const matter = require("gray-matter");
const { readFile, readdir } = require("fs/promises");
const { join } = require("path");

const root = join(process.cwd(), "contributors");
const root = join(process.cwd(), "data-repo/contributors");

const GITHUB_ORG = process.env.GITHUB_ORG;
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
Expand Down
1 change: 0 additions & 1 deletion theme.css

This file was deleted.

5 changes: 3 additions & 2 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"framework": "nextjs"
}
"framework": "nextjs",
"buildCommand": "node ./scripts/loadOrgData.js && next build"
}

0 comments on commit 09ac838

Please sign in to comment.