Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:

- name: 'Build application'
run: npm run build

- name: 'Restore changes in json'
run: |
git restore src/app/projects/assets/upcomingProjects.json
git restore src/app/projects/assets/projects.json

- name: 'Fetch branches'
run: git fetch origin
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build && touch ./build/.nojekyll",
"build": "npm run update-projects && next build && touch ./build/.nojekyll",
"start": "next start",
"lint": "next lint",
"start:build": "serve ./build",
Expand All @@ -13,7 +13,8 @@
"check-format": "npx prettier --check .",
"format": "npx prettier --write .",
"check-lint": "eslint . --ext ts --ext tsx --ext js",
"pre-commit": "npm run check-format && npm run check-lint && npm run check-types"
"pre-commit": "npm run check-format && npm run check-lint && npm run check-types",
"update-projects": "node updateProject.js"
},
"dependencies": {
"clsx": "^2.0.0",
Expand Down
122 changes: 122 additions & 0 deletions updateProject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// updateProjects.js
const fs = require("fs");
const path = require("path");

async function getCurrentProjects() {
const query = `query getCurrentProjects {
foss_projects(filter: {project_type: { _eq: "current" }}) {
id,
title,
short_description,
github_repository_link,
documentation_link,
project_type,
date_created,
date_updated,
status,
}
}`;

try {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

const response = await fetch("https://directus.ourgoalplan.co.in/graphql", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: query,
}),
});

if (response.ok) {
const { data } = await response.json();
data.foss_projects.forEach((entry) => {
entry.id = parseInt(entry.id);
entry.shortDescription = entry.short_description;
entry.githubUrl = entry.github_repository_link;
entry.documentationUrl = entry.documentation_link;

delete entry.short_description;
delete entry.github_repository_link;
delete entry.documentation_link;
});

const projectsJsonPath = path.join(
__dirname,
"src/app/projects/assets/projects.json"
);

fs.writeFileSync(
projectsJsonPath,
JSON.stringify(data.foss_projects, null, 2)
);

console.log("Projects updated successfully.");
} else {
console.log("API is not available. Using existing JSON.");
}
} catch (error) {
console.log(error);
}
}

async function getUpcomingProjects() {
const query = `query getUpcomingProjects {
foss_projects(filter: {project_type: { _eq: "upcoming" }}) {
id,
title,
short_description,
github_repository_link,
documentation_link,
project_type,
date_created,
date_updated,
status,
}
}`;

try {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

const response = await fetch("https://directus.ourgoalplan.co.in/graphql", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: query,
}),
});

if (response.ok) {
const { data } = await response.json();
data.foss_projects.forEach((entry) => {
entry.id = parseInt(entry.id);
entry.shortDescription = entry.short_description;
entry.githubUrl = entry.github_repository_link;
entry.documentationUrl = entry.documentation_link;

delete entry.short_description;
delete entry.github_repository_link;
delete entry.documentation_link;
});

const projectsJsonPath = path.join(
__dirname,
"src/app/projects/assets/upcomingProjects.json"
);

fs.writeFileSync(
projectsJsonPath,
JSON.stringify(data.foss_projects, null, 2)
);

console.log("Upcoming projects updated successfully.");
} else {
console.log("API is not available. Using existing JSON.");
}
} catch (error) {
console.log(error);
}
}

getCurrentProjects();
getUpcomingProjects();