Skip to content

Commit 3ed7a45

Browse files
authored
Merge pull request #3 from Forz70043/feature/project-info-api-github
core: integrate API Github project info
2 parents d49d627 + 95f987d commit 3ed7a45

4 files changed

Lines changed: 72 additions & 21 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# 🧰 Dev Toolkit CLI
22

3-
[![npm version](https://img.shields.io/npm/v/@forz70043/dev-toolkit.svg?style=flat-square&color=00bfa5)](https://www.npmjs.com/package/@forz70043/dev-toolkit)
3+
[![npm version](https://img.shields.io/npm/v/@forz70043/dev-toolkit.svg?style=flat-square&color=00bfa5)](https://www.npmjs.com/package/@forz/dev-toolkit)
44
[![npm downloads](https://img.shields.io/npm/dt/@forz70043/dev-toolkit.svg?style=flat-square&color=blue)](https://www.npmjs.com/package/@forz70043/dev-toolkit)
55
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)](LICENSE)
66
[![GitHub Repo](https://img.shields.io/badge/source-GitHub-black?logo=github&style=flat-square)](https://github.com/Forz70043/dev-toolkit)
77

8-
> A powerful CLI toolkit that automates common developer tasks — clean Git branches, check `.env` files, lint commits, and show project info.
8+
> A powerful CLI dev toolkit that automates common developer tasks — clean Git branches, check `.env` files, lint commits, and show project info.
99
> Developed with ❤️ by [Alfonso Pisicchio](https://pisicchio.dev).
1010
1111

@@ -60,8 +60,8 @@ dev project-info
6060
* ✅ Environment variable validator
6161
* ✅ Commit linter
6262
* ✅ Project info command
63+
* ✅ GitHub API integration for remote repo stats
6364
* ❌ dev help command with autocomplete
64-
* ❌ GitHub API integration for remote repo stats
6565

6666

6767
### 🧑‍💻 Author

bin/dev.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
#!/usr/bin/env node
2+
/**
3+
* dev-toolkit CLI
4+
* Author: Alfonso Pisicchio <https://pisicchio.dev>
5+
* License: MIT
6+
*/
7+
28
import { Command } from "commander";
39
import chalk from "chalk";
410
import { gitClean } from "../commands/git-clean.js";
511
import { envCheck } from "../commands/env-check.js";
612
import { lintCommit } from "../commands/lint-commit.js";
713
import { projectInfo } from "../commands/project-info.js";
14+
import fs from "fs";
15+
import path from "path";
16+
import { fileURLToPath } from "url";
17+
18+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
19+
const pkgPath = path.resolve(__dirname, "../package.json");
20+
const { version } = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
821

922
const program = new Command();
1023

24+
// =======================================
25+
// 📦 Program Definition
26+
// =======================================
1127
program
1228
.name("dev")
1329
.description("🧰 Developer Toolkit CLI")
14-
.version("1.0.0");
30+
.version(version);
1531

16-
// Commands
32+
// =======================================
33+
// 🧩 Commands
34+
// =======================================
1735
program
1836
.command("git-clean")
1937
.description("Remove local Git branches not present in remote")

commands/project-info.js

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,55 @@
11
import fs from "fs";
22
import chalk from "chalk";
33
import simpleGit from "simple-git";
4+
import { execSync } from "child_process";
5+
6+
const fetchFn = global.fetch || (await import("node-fetch")).default;
47

58
export async function projectInfo() {
6-
const pkgPath = "./package.json";
9+
try {
10+
const remoteUrl = execSync("git config --get remote.origin.url").toString().trim();
711

8-
const git = simpleGit();
9-
const currentBranch = (await git.branchLocal()).current;
10-
const lastCommit = (await git.log({ n: 1 })).latest;
12+
if (!remoteUrl) {
13+
console.log(chalk.red("❌ No remote Git repository found."));
14+
return;
15+
}
1116

12-
if (fs.existsSync(pkgPath)) {
13-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
14-
console.log(chalk.cyan("📦 Project Info"));
15-
console.log(chalk.white(`Name: ${pkg.name}`));
16-
console.log(chalk.white(`Version: ${pkg.version}`));
17-
}
17+
const match = remoteUrl.match(/github\.com[:/](.+?)\/(.+?)(?:\.git)?$/);
18+
if (!match) {
19+
console.log(chalk.red("❌ Repository does not appear to be on GitHub."));
20+
return;
21+
}
22+
23+
const [_, owner, repo] = match;
24+
25+
const res = await fetchFn(`https://api.github.com/repos/${owner}/${repo}`);
26+
if (!res.ok) {
27+
console.log(chalk.red(`❌ Unable to retrieve info from GitHub (${res.status})`));
28+
return;
29+
}
1830

19-
console.log(chalk.white(`Branch: ${currentBranch}`));
20-
console.log(chalk.white(`Last commit: ${lastCommit.message}`));
21-
console.log(chalk.gray(`By ${lastCommit.author_name} on ${lastCommit.date}`));
31+
const data = await res.json();
32+
33+
console.log(chalk.bold.cyan(`\n📦 Repository Info: ${data.full_name}`));
34+
console.log(chalk.gray(data.html_url));
35+
console.log("");
36+
console.log(`${chalk.yellow("🪶 Description:")} ${data.description || "—"}`);
37+
console.log(`${chalk.yellow("⭐ Stars:")} ${data.stargazers_count}`);
38+
console.log(`${chalk.yellow("🍴 Forks:")} ${data.forks_count}`);
39+
console.log(`${chalk.yellow("👀 Open Issues:")} ${data.open_issues_count}\n`);
40+
console.log(`${chalk.yellow("🧱 Language:")} ${data.language || "Unknown"}`);
41+
console.log(`${chalk.yellow("🕒 Last Updated:")} ${new Date(data.updated_at).toLocaleString()}`);
42+
43+
const commitsRes = await fetchFn(`https://api.github.com/repos/${owner}/${repo}/commits?per_page=1`);
44+
if (commitsRes.ok) {
45+
const [lastCommit] = await commitsRes.json();
46+
if (lastCommit) {
47+
console.log(`${chalk.yellow("🧩 Last Commit:")} ${lastCommit.commit.message}`);
48+
console.log(`${chalk.gray(`by ${lastCommit.commit.author.name} on ${lastCommit.commit.author.date}`)}\n`);
49+
}
50+
}
51+
52+
} catch (err) {
53+
console.error(chalk.red(`❌ Error: ${err.message}`));
54+
}
2255
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@forz/dev-toolkit",
3-
"version": "1.0.3",
4-
"description": "🧰 A developer CLI for Git, env, and project automation by Alfonso Pisicchio",
3+
"version": "1.0.4",
4+
"description": "🧰 Developer Toolkit CLI for Git, env, and project automation by Alfonso Pisicchio",
55
"type": "module",
66
"bin": {
77
"dev": "./bin/dev.js"
@@ -31,4 +31,4 @@
3131
"dotenv": "^16.4.0",
3232
"simple-git": "^3.24.0"
3333
}
34-
}
34+
}

0 commit comments

Comments
 (0)