@iksdev/shard-cli 0.1.24 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/notify-discord.js +145 -38
- package/package.json +2 -2
package/notify-discord.js
CHANGED
|
@@ -1,48 +1,155 @@
|
|
|
1
1
|
const https = require("https");
|
|
2
|
+
const { execSync } = require("child_process");
|
|
2
3
|
const pkg = require("./package.json");
|
|
3
4
|
|
|
4
5
|
const WEBHOOK = "https://discord.com/api/webhooks/1476384127594004511/A2P7cXIC9Z1rfbEo5Wvxgdsnb2VcJ-NjiGFGnvmnjbF2tm2jW4qGBRS4GgEcZ7hHJGUp";
|
|
6
|
+
const GEMINI_KEY = "AIzaSyBXSnhnYSI6A1cgYAQzmE7pWmmOZi3H334"; // https://aistudio.google.com/apikey
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// ─── Git helpers ──────────────────────────────────────────────────────────────
|
|
9
|
+
function getLastTag() {
|
|
10
|
+
try {
|
|
11
|
+
return execSync("git describe --tags --abbrev=0 HEAD^", { encoding: "utf-8" }).trim();
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getCommits(lastTag) {
|
|
18
|
+
try {
|
|
19
|
+
const ref = lastTag ? `${lastTag}..HEAD` : "HEAD~10..HEAD";
|
|
20
|
+
return execSync(`git log ${ref} --pretty=format:"%s" --no-merges`, { encoding: "utf-8" }).trim();
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getDiff(lastTag) {
|
|
27
|
+
try {
|
|
28
|
+
const ref = lastTag ? `${lastTag}..HEAD` : "HEAD~5..HEAD";
|
|
29
|
+
return execSync(`git diff ${ref} --stat`, { encoding: "utf-8" }).trim().slice(0, 1500);
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
9
33
|
}
|
|
10
34
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
35
|
+
// ─── Gemini changelog ─────────────────────────────────────────────────────────
|
|
36
|
+
function geminiRequest(prompt) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const body = JSON.stringify({
|
|
39
|
+
contents: [{ parts: [{ text: prompt }] }],
|
|
40
|
+
generationConfig: { maxOutputTokens: 300, temperature: 0.3 },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const req = https.request(
|
|
44
|
+
{
|
|
45
|
+
hostname: "generativelanguage.googleapis.com",
|
|
46
|
+
path: `/v1beta/models/gemini-1.5-flash:generateContent?key=${GEMINI_KEY}`,
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(body) },
|
|
19
49
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
(res) => {
|
|
51
|
+
let data = "";
|
|
52
|
+
res.on("data", (chunk) => (data += chunk));
|
|
53
|
+
res.on("end", () => {
|
|
54
|
+
try {
|
|
55
|
+
const json = JSON.parse(data);
|
|
56
|
+
const text = json.candidates?.[0]?.content?.parts?.[0]?.text;
|
|
57
|
+
resolve(text || null);
|
|
58
|
+
} catch {
|
|
59
|
+
resolve(null);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
req.on("error", reject);
|
|
65
|
+
req.write(body);
|
|
66
|
+
req.end();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function generateChangelog(commits, diff) {
|
|
71
|
+
if (!commits) return null;
|
|
72
|
+
const prompt = `Tu es un assistant qui génère des changelogs concis et clairs pour des releases npm.
|
|
73
|
+
Voici les commits de la version ${pkg.version} de ${pkg.name} :
|
|
74
|
+
|
|
75
|
+
${commits}
|
|
76
|
+
|
|
77
|
+
${diff ? `Fichiers modifiés :\n${diff}` : ""}
|
|
78
|
+
|
|
79
|
+
Génère un changelog court (max 5 bullet points) en français, avec des emojis, sans blabla. Format :
|
|
80
|
+
Nouvelle fonctionnalité X
|
|
81
|
+
Correction de Y
|
|
82
|
+
Amélioration de Z`;
|
|
83
|
+
|
|
84
|
+
return await geminiRequest(prompt);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ─── Discord ──────────────────────────────────────────────────────────────────
|
|
88
|
+
function sendDiscord(changelog) {
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
const fields = [];
|
|
91
|
+
|
|
92
|
+
if (changelog) {
|
|
93
|
+
fields.push({
|
|
94
|
+
name: "📋 Changelog",
|
|
95
|
+
value: changelog.slice(0, 1024),
|
|
96
|
+
inline: false,
|
|
97
|
+
});
|
|
42
98
|
}
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
99
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
100
|
+
fields.push({
|
|
101
|
+
name: "📦 Mise à jour",
|
|
102
|
+
value: `\`\`\`bash\nnpm i -g ${pkg.name}@latest\n\`\`\``,
|
|
103
|
+
inline: false,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const body = JSON.stringify({
|
|
107
|
+
embeds: [{
|
|
108
|
+
author: {
|
|
109
|
+
name: "npm • nouvelle version disponible",
|
|
110
|
+
icon_url: "https://static-production.npmjs.com/b0f1a8318363185cc2ea6a40ac23eeb2.png",
|
|
111
|
+
},
|
|
112
|
+
title: `🚀 ${pkg.name} — v${pkg.version}`,
|
|
113
|
+
url: `https://www.npmjs.com/package/${pkg.name}/v/${pkg.version}`,
|
|
114
|
+
description: `> ${pkg.description}`,
|
|
115
|
+
color: 0x5865f2,
|
|
116
|
+
fields,
|
|
117
|
+
footer: { text: "Publié le" },
|
|
118
|
+
timestamp: new Date().toISOString(),
|
|
119
|
+
}],
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const url = new URL(WEBHOOK);
|
|
123
|
+
const req = https.request(
|
|
124
|
+
{
|
|
125
|
+
hostname: url.hostname,
|
|
126
|
+
path: url.pathname + url.search,
|
|
127
|
+
method: "POST",
|
|
128
|
+
headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(body) },
|
|
129
|
+
},
|
|
130
|
+
(res) => {
|
|
131
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
132
|
+
console.log(`✅ Notification Discord envoyée (v${pkg.version})`);
|
|
133
|
+
resolve();
|
|
134
|
+
} else {
|
|
135
|
+
res.setEncoding("utf-8");
|
|
136
|
+
res.on("data", (d) => console.error("❌ Erreur Discord :", d));
|
|
137
|
+
resolve();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
req.on("error", reject);
|
|
142
|
+
req.write(body);
|
|
143
|
+
req.end();
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ─── Main ─────────────────────────────────────────────────────────────────────
|
|
148
|
+
(async () => {
|
|
149
|
+
console.log("📡 Génération du changelog avec Gemini...");
|
|
150
|
+
const lastTag = getLastTag();
|
|
151
|
+
const commits = getCommits(lastTag);
|
|
152
|
+
const diff = getDiff(lastTag);
|
|
153
|
+
const changelog = await generateChangelog(commits, diff);
|
|
154
|
+
await sendDiscord(changelog);
|
|
155
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iksdev/shard-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.26",
|
|
4
4
|
"description": "CLI pour synchroniser un dossier local avec Shard",
|
|
5
5
|
"bin": {
|
|
6
6
|
"shard": "bin/shard.js"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"check": "node --check bin/shard.js",
|
|
11
|
-
"postpublish": "
|
|
11
|
+
"postpublish": "node notify-discord.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"ws": "^8.18.3"
|