Skip to content

Commit

Permalink
🔧 add precommit for getting last updated time based on lates commit date
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpmohiburrahman committed Jun 29, 2024
1 parent 3de1414 commit a959934
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm run update:lastcommit && git add scripts/lastCommitDate.json
10 changes: 3 additions & 7 deletions components/last_updated/LastUpdated.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { format } from "timeago.js";

import data from "../../scripts/lastCommitDate.json";
const LastUpdated: React.FC = () => {
const [lastUpdatedMessage, setLastUpdatedMessage] = useState<string | null>(
null
Expand All @@ -9,12 +9,8 @@ const LastUpdated: React.FC = () => {
useEffect(() => {
const fetchLastCommitDate = async () => {
try {
const response = await fetch(
"https://api.github.com/repos/mrpmohiburrahman/awesome-react-native-ui/commits?per_page=1"
);
const data = await response.json();
if (data && data.length > 0) {
const lastCommitDate = new Date(data[0].commit.committer.date);
if (data && data.lastCommitDate) {
const lastCommitDate = new Date(data.lastCommitDate);
const formattedDate = format(lastCommitDate);
setLastUpdatedMessage(`Last updated: ${formattedDate}`);
}
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"serve": "docusaurus serve",
"clear": "docusaurus clear"
"clear": "docusaurus clear",
"update:lastcommit": "node scripts/updateLastCommitDate.js",
"prepare": "husky install"
},
"dependencies": {
"@docusaurus/core": "^3.3.2",
Expand All @@ -33,6 +35,7 @@
"devDependencies": {
"@docusaurus/module-type-aliases": "3.3.2",
"@tsconfig/docusaurus": "^2.0.3",
"husky": "^9.0.11",
"typescript": "^5.4.5"
},
"browserslist": {
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

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

3 changes: 3 additions & 0 deletions scripts/lastCommitDate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"lastCommitDate": "2024-06-29T00:05:41.692Z"
}
13 changes: 13 additions & 0 deletions scripts/updateLastCommitDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// scripts/updateLastCommitDate.js
const fs = require("fs");
const path = require("path");

const filePath = path.join(__dirname, "lastCommitDate.json");
const lastCommitDate = new Date().toISOString();

const data = {
lastCommitDate,
};

fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf-8");
console.log("Last commit date updated:", lastCommitDate);

0 comments on commit a959934

Please sign in to comment.