@commitguard/cli 0.0.1 → 0.0.2
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/dist/index.mjs +15 -10
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -22,7 +22,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region package.json
|
|
25
|
-
var version = "0.0.
|
|
25
|
+
var version = "0.0.2";
|
|
26
26
|
var package_default = {
|
|
27
27
|
name: "@commitguard/cli",
|
|
28
28
|
type: "module",
|
|
@@ -230,6 +230,7 @@ function addGitLineNumbers(diff) {
|
|
|
230
230
|
}
|
|
231
231
|
return result.join("\n");
|
|
232
232
|
}
|
|
233
|
+
const MESSAGES = { noGit: "No .git folder found. Run this inside a git repository." };
|
|
233
234
|
|
|
234
235
|
//#endregion
|
|
235
236
|
//#region src/utils/git.ts
|
|
@@ -327,7 +328,7 @@ async function manageGlobalKey() {
|
|
|
327
328
|
} else outro("API key removed. You can set a new one later using `commitguard init` or `commitguard keys`.");
|
|
328
329
|
}
|
|
329
330
|
} else {
|
|
330
|
-
note("To get your free API key, visit https://commitguard.
|
|
331
|
+
note("To get your free API key, visit https://commitguard.ai", "Get your free API key");
|
|
331
332
|
const apiKey = await text({
|
|
332
333
|
message: "Enter your CommitGuard API key:",
|
|
333
334
|
placeholder: "sk_XXXXXXXXXXXXXXXXXXXXXX",
|
|
@@ -352,7 +353,7 @@ async function manageGlobalKey() {
|
|
|
352
353
|
//#region src/utils/api.ts
|
|
353
354
|
async function sendToCommitGuard(diff, eslint, config) {
|
|
354
355
|
const apiKey = process.env.COMMITGUARD_API_KEY || getGlobalKey() || null;
|
|
355
|
-
if (!apiKey) throw new Error("No API key found. Set one globally with \"commitguard keys\" or add COMMITGUARD_API_KEY to your .env file. Get your free API key at https://commitguard.
|
|
356
|
+
if (!apiKey) throw new Error("No API key found. Set one globally with \"commitguard keys\" or add COMMITGUARD_API_KEY to your .env file. Get your free API key at https://commitguard.ai");
|
|
356
357
|
const apiUrl = process.env.COMMITGUARD_API_URL || "https://api.commitguard.ai/v1/analyze";
|
|
357
358
|
const response = await fetch(apiUrl, {
|
|
358
359
|
method: "POST",
|
|
@@ -375,7 +376,7 @@ async function sendToCommitGuard(diff, eslint, config) {
|
|
|
375
376
|
}
|
|
376
377
|
async function bypassCommitGuard() {
|
|
377
378
|
const apiKey = process.env.COMMITGUARD_API_KEY || getGlobalKey() || null;
|
|
378
|
-
if (!apiKey) throw new Error("No API key found. Set one globally with \"commitguard keys\" or add COMMITGUARD_API_KEY to your .env file. Get your free API key at https://commitguard.
|
|
379
|
+
if (!apiKey) throw new Error("No API key found. Set one globally with \"commitguard keys\" or add COMMITGUARD_API_KEY to your .env file. Get your free API key at https://commitguard.ai");
|
|
379
380
|
const apiUrl = process.env.COMMITGUARD_API_BYPASS_URL || "https://api.commitguard.ai/v1/bypass";
|
|
380
381
|
const diff = getLastDiff();
|
|
381
382
|
const response = await fetch(apiUrl, {
|
|
@@ -400,6 +401,7 @@ const MAX_CUSTOM_PROMPT_LENGTH = 500;
|
|
|
400
401
|
const CONFIG_DIR = join(homedir(), ".commitguard");
|
|
401
402
|
const PROJECTS_CONFIG_PATH = join(CONFIG_DIR, "projects.json");
|
|
402
403
|
let projectsConfigCache = null;
|
|
404
|
+
const GIT_DIR$1 = ".git";
|
|
403
405
|
function ensureConfigDir() {
|
|
404
406
|
if (!existsSync(CONFIG_DIR)) try {
|
|
405
407
|
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
@@ -472,6 +474,10 @@ function loadConfig() {
|
|
|
472
474
|
return loadProjectsConfig()[projectId] || getDefaultConfig();
|
|
473
475
|
}
|
|
474
476
|
async function manageConfig() {
|
|
477
|
+
if (!existsSync(GIT_DIR$1)) {
|
|
478
|
+
cancel(MESSAGES.noGit);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
475
481
|
const projectId = getProjectId();
|
|
476
482
|
const currentConfig = loadConfig();
|
|
477
483
|
intro(`CommitGuard Configuration`);
|
|
@@ -685,11 +691,10 @@ const GIT_DIR = ".git";
|
|
|
685
691
|
const HOOKS_DIR = join(GIT_DIR, "hooks");
|
|
686
692
|
const COMMIT_MSG_HOOK_PATH = join(HOOKS_DIR, "commit-msg");
|
|
687
693
|
const POST_INDEX_HOOK_PATH = join(HOOKS_DIR, "post-index-change");
|
|
688
|
-
const MESSAGES = { noGit: "No .git folder found. Run this inside a git repository." };
|
|
689
694
|
async function installHooks() {
|
|
690
695
|
if (!existsSync(GIT_DIR)) {
|
|
691
696
|
cancel(MESSAGES.noGit);
|
|
692
|
-
|
|
697
|
+
return;
|
|
693
698
|
}
|
|
694
699
|
if (!existsSync(HOOKS_DIR)) mkdirSync(HOOKS_DIR, { recursive: true });
|
|
695
700
|
try {
|
|
@@ -1035,15 +1040,15 @@ const command = process.argv[2];
|
|
|
1035
1040
|
CommitGuard - AI-powered git commit checker v${version}
|
|
1036
1041
|
|
|
1037
1042
|
Usage:
|
|
1038
|
-
commitguard init Initialize CommitGuard in the current
|
|
1039
|
-
commitguard remove Remove CommitGuard from the current
|
|
1040
|
-
commitguard config Configure CommitGuard
|
|
1043
|
+
commitguard init Initialize CommitGuard in the current project
|
|
1044
|
+
commitguard remove Remove CommitGuard from the current project
|
|
1045
|
+
commitguard config Configure CommitGuard prefrences for the current project
|
|
1041
1046
|
commitguard keys Manage your CommitGuard API key
|
|
1042
1047
|
|
|
1043
1048
|
Links:
|
|
1044
1049
|
Documentation: https://commitguard.ai/docs
|
|
1045
1050
|
Dashboard: https://commitguard.ai/dashboard
|
|
1046
|
-
Support:
|
|
1051
|
+
Support: hello@commitguard.ai`);
|
|
1047
1052
|
}
|
|
1048
1053
|
} catch (error) {
|
|
1049
1054
|
consola.error("CommitGuard error:", error);
|