@@ -25193,7 +25193,7 @@ function G3(t2, e3) {
25193
25193
// package.json
25194
25194
var package_default = {
25195
25195
name: "opencommit",
25196
- version: "3.0.20 ",
25196
+ version: "3.1.0 ",
25197
25197
description: "Auto-generate impressive commits in 1 second. Killing lame commits with AI \u{1F92F}\u{1F52B}",
25198
25198
keywords: [
25199
25199
"git",
@@ -28029,44 +28029,24 @@ var configValidators = {
28029
28029
};
28030
28030
var defaultConfigPath = (0, import_path.join)((0, import_os.homedir)(), ".opencommit");
28031
28031
var defaultEnvPath = (0, import_path.resolve)(process.cwd(), ".env");
28032
- var assertConfigsAreValid = (config7) => {
28033
- for (const [key, value] of Object.entries(config7)) {
28034
- if (!value)
28035
- continue;
28036
- if (typeof value === "string" && ["null", "undefined"].includes(value)) {
28037
- config7[key] = void 0;
28038
- continue;
28039
- }
28040
- try {
28041
- const validate = configValidators[key];
28042
- validate(value, config7);
28043
- } catch (error) {
28044
- ce(`Unknown '${key}' config option or missing validator.`);
28045
- ce(
28046
- `Manually fix the '.env' file or global '~/.opencommit' config file.`
28047
- );
28048
- process.exit(1);
28049
- }
28050
- }
28051
- };
28052
- var initGlobalConfig = () => {
28053
- const defaultConfig = {
28054
- OCO_TOKENS_MAX_INPUT: 40960 /* DEFAULT_MAX_TOKENS_INPUT */,
28055
- OCO_TOKENS_MAX_OUTPUT: 4096 /* DEFAULT_MAX_TOKENS_OUTPUT */,
28056
- OCO_DESCRIPTION: false,
28057
- OCO_EMOJI: false,
28058
- OCO_MODEL: getDefaultModel("openai"),
28059
- OCO_LANGUAGE: "en",
28060
- OCO_MESSAGE_TEMPLATE_PLACEHOLDER: "$msg",
28061
- OCO_PROMPT_MODULE: "conventional-commit" /* CONVENTIONAL_COMMIT */,
28062
- OCO_AI_PROVIDER: "openai" /* OPENAI */,
28063
- OCO_ONE_LINE_COMMIT: false,
28064
- OCO_TEST_MOCK_TYPE: "commit-message",
28065
- OCO_FLOWISE_ENDPOINT: ":",
28066
- OCO_GITPUSH: true
28067
- };
28068
- (0, import_fs.writeFileSync)(defaultConfigPath, (0, import_ini.stringify)(defaultConfig), "utf8");
28069
- return defaultConfig;
28032
+ var DEFAULT_CONFIG = {
28033
+ OCO_TOKENS_MAX_INPUT: 40960 /* DEFAULT_MAX_TOKENS_INPUT */,
28034
+ OCO_TOKENS_MAX_OUTPUT: 4096 /* DEFAULT_MAX_TOKENS_OUTPUT */,
28035
+ OCO_DESCRIPTION: false,
28036
+ OCO_EMOJI: false,
28037
+ OCO_MODEL: getDefaultModel("openai"),
28038
+ OCO_LANGUAGE: "en",
28039
+ OCO_MESSAGE_TEMPLATE_PLACEHOLDER: "$msg",
28040
+ OCO_PROMPT_MODULE: "conventional-commit" /* CONVENTIONAL_COMMIT */,
28041
+ OCO_AI_PROVIDER: "openai" /* OPENAI */,
28042
+ OCO_ONE_LINE_COMMIT: false,
28043
+ OCO_TEST_MOCK_TYPE: "commit-message",
28044
+ OCO_FLOWISE_ENDPOINT: ":",
28045
+ OCO_GITPUSH: true
28046
+ };
28047
+ var initGlobalConfig = (configPath = defaultConfigPath) => {
28048
+ (0, import_fs.writeFileSync)(configPath, (0, import_ini.stringify)(DEFAULT_CONFIG), "utf8");
28049
+ return DEFAULT_CONFIG;
28070
28050
};
28071
28051
var parseEnvVarValue = (value) => {
28072
28052
try {
@@ -28075,12 +28055,9 @@ var parseEnvVarValue = (value) => {
28075
28055
return value;
28076
28056
}
28077
28057
};
28078
- var getConfig = ({
28079
- configPath = defaultConfigPath,
28080
- envPath = defaultEnvPath
28081
- } = {}) => {
28058
+ var getEnvConfig = (envPath) => {
28082
28059
dotenv.config({ path: envPath });
28083
- const envConfig = {
28060
+ return {
28084
28061
OCO_MODEL: process.env.OCO_MODEL,
28085
28062
OCO_OPENAI_API_KEY: process.env.OCO_OPENAI_API_KEY,
28086
28063
OCO_ANTHROPIC_API_KEY: process.env.OCO_ANTHROPIC_API_KEY,
@@ -28104,23 +28081,35 @@ var getConfig = ({
28104
28081
OCO_TEST_MOCK_TYPE: process.env.OCO_TEST_MOCK_TYPE,
28105
28082
OCO_GITPUSH: parseEnvVarValue(process.env.OCO_GITPUSH)
28106
28083
};
28084
+ };
28085
+ var getGlobalConfig = (configPath) => {
28107
28086
let globalConfig;
28108
28087
const isGlobalConfigFileExist = (0, import_fs.existsSync)(configPath);
28109
28088
if (!isGlobalConfigFileExist)
28110
- globalConfig = initGlobalConfig();
28089
+ globalConfig = initGlobalConfig(configPath );
28111
28090
else {
28112
28091
const configFile = (0, import_fs.readFileSync)(configPath, "utf8");
28113
28092
globalConfig = (0, import_ini.parse)(configFile);
28114
28093
}
28115
- const mergeObjects = (main, fallback) => Object.keys(CONFIG_KEYS).reduce((acc, key) => {
28116
- acc[key] = parseEnvVarValue(main[key] ?? fallback[key]);
28117
- return acc;
28118
- }, {});
28119
- const config7 = mergeObjects(envConfig, globalConfig);
28094
+ return globalConfig;
28095
+ };
28096
+ var mergeConfigs = (main, fallback) => Object.keys(CONFIG_KEYS).reduce((acc, key) => {
28097
+ acc[key] = parseEnvVarValue(main[key] ?? fallback[key]);
28098
+ return acc;
28099
+ }, {});
28100
+ var getConfig = ({
28101
+ envPath = defaultEnvPath,
28102
+ globalPath = defaultConfigPath
28103
+ } = {}) => {
28104
+ const envConfig = getEnvConfig(envPath);
28105
+ const globalConfig = getGlobalConfig(globalPath);
28106
+ const config7 = mergeConfigs(envConfig, globalConfig);
28120
28107
return config7;
28121
28108
};
28122
- var setConfig = (keyValues, configPath = defaultConfigPath) => {
28123
- const config7 = getConfig();
28109
+ var setConfig = (keyValues, globalConfigPath = defaultConfigPath) => {
28110
+ const config7 = getConfig({
28111
+ globalPath: globalConfigPath
28112
+ });
28124
28113
for (let [key, value] of keyValues) {
28125
28114
if (!configValidators.hasOwnProperty(key)) {
28126
28115
const supportedKeys = Object.keys(configValidators).join("\n");
@@ -28144,8 +28133,7 @@ For more help refer to our docs: https://github.com/di-sukharev/opencommit`
28144
28133
);
28145
28134
config7[key] = validValue;
28146
28135
}
28147
- (0, import_fs.writeFileSync)(configPath, (0, import_ini.stringify)(config7), "utf8");
28148
- assertConfigsAreValid(config7);
28136
+ (0, import_fs.writeFileSync)(globalConfigPath, (0, import_ini.stringify)(config7), "utf8");
28149
28137
ce(`${source_default.green("\u2714")} config successfully set`);
28150
28138
};
28151
28139
var configCommand = G3(
@@ -42400,7 +42388,7 @@ var OpenAiEngine = class {
42400
42388
function getEngine() {
42401
42389
const config7 = getConfig();
42402
42390
const provider = config7.OCO_AI_PROVIDER;
42403
- const DEFAULT_CONFIG = {
42391
+ const DEFAULT_CONFIG2 = {
42404
42392
model: config7.OCO_MODEL,
42405
42393
maxTokensOutput: config7.OCO_TOKENS_MAX_OUTPUT,
42406
42394
maxTokensInput: config7.OCO_TOKENS_MAX_INPUT,
@@ -42409,37 +42397,37 @@ function getEngine() {
42409
42397
switch (provider) {
42410
42398
case "ollama" /* OLLAMA */:
42411
42399
return new OllamaAi({
42412
- ...DEFAULT_CONFIG ,
42400
+ ...DEFAULT_CONFIG2 ,
42413
42401
apiKey: "",
42414
42402
baseURL: config7.OCO_OLLAMA_API_URL
42415
42403
});
42416
42404
case "anthropic" /* ANTHROPIC */:
42417
42405
return new AnthropicEngine({
42418
- ...DEFAULT_CONFIG ,
42406
+ ...DEFAULT_CONFIG2 ,
42419
42407
apiKey: config7.OCO_ANTHROPIC_API_KEY
42420
42408
});
42421
42409
case "test" /* TEST */:
42422
42410
return new TestAi(config7.OCO_TEST_MOCK_TYPE);
42423
42411
case "gemini" /* GEMINI */:
42424
42412
return new Gemini({
42425
- ...DEFAULT_CONFIG ,
42413
+ ...DEFAULT_CONFIG2 ,
42426
42414
apiKey: config7.OCO_GEMINI_API_KEY,
42427
42415
baseURL: config7.OCO_GEMINI_BASE_PATH
42428
42416
});
42429
42417
case "azure" /* AZURE */:
42430
42418
return new AzureEngine({
42431
- ...DEFAULT_CONFIG ,
42419
+ ...DEFAULT_CONFIG2 ,
42432
42420
apiKey: config7.OCO_AZURE_API_KEY
42433
42421
});
42434
42422
case "flowise" /* FLOWISE */:
42435
42423
return new FlowiseAi({
42436
- ...DEFAULT_CONFIG ,
42437
- baseURL: config7.OCO_FLOWISE_ENDPOINT || DEFAULT_CONFIG .baseURL,
42424
+ ...DEFAULT_CONFIG2 ,
42425
+ baseURL: config7.OCO_FLOWISE_ENDPOINT || DEFAULT_CONFIG2 .baseURL,
42438
42426
apiKey: config7.OCO_FLOWISE_API_KEY
42439
42427
});
42440
42428
default:
42441
42429
return new OpenAiEngine({
42442
- ...DEFAULT_CONFIG ,
42430
+ ...DEFAULT_CONFIG2 ,
42443
42431
apiKey: config7.OCO_OPENAI_API_KEY
42444
42432
});
42445
42433
}
@@ -43172,8 +43160,8 @@ var generateCommitMessageFromGitDiff = async ({
43172
43160
skipCommitConfirmation = false
43173
43161
}) => {
43174
43162
await assertGitRepo();
43175
- const commitSpinner = le();
43176
- commitSpinner .start("Generating the commit message");
43163
+ const commitGenerationSpinner = le();
43164
+ commitGenerationSpinner .start("Generating the commit message");
43177
43165
try {
43178
43166
let commitMessage = await generateCommitMessageByDiff(
43179
43167
diff,
@@ -43188,7 +43176,7 @@ var generateCommitMessageFromGitDiff = async ({
43188
43176
commitMessage
43189
43177
);
43190
43178
}
43191
- commitSpinner .stop("\u{1F4DD} Commit message generated");
43179
+ commitGenerationSpinner .stop("\u{1F4DD} Commit message generated");
43192
43180
ce(
43193
43181
`Generated commit message:
43194
43182
${source_default.grey("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014")}
@@ -43198,14 +43186,20 @@ ${source_default.grey("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2
43198
43186
const isCommitConfirmedByUser = skipCommitConfirmation || await Q3({
43199
43187
message: "Confirm the commit message?"
43200
43188
});
43201
- if (isCommitConfirmedByUser && !hD2(isCommitConfirmedByUser)) {
43189
+ if (hD2(isCommitConfirmedByUser))
43190
+ process.exit(1);
43191
+ if (isCommitConfirmedByUser) {
43192
+ const committingChangesSpinner = le();
43193
+ committingChangesSpinner.start("Committing the changes");
43202
43194
const { stdout } = await execa("git", [
43203
43195
"commit",
43204
43196
"-m",
43205
43197
commitMessage,
43206
43198
...extraArgs2
43207
43199
]);
43208
- ce(`${source_default.green("\u2714")} Successfully committed`);
43200
+ committingChangesSpinner.stop(
43201
+ `${source_default.green("\u2714")} Successfully committed`
43202
+ );
43209
43203
ce(stdout);
43210
43204
const remotes = await getGitRemotes();
43211
43205
if (!remotes.length) {
@@ -43218,7 +43212,9 @@ ${source_default.grey("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2
43218
43212
const isPushConfirmedByUser = await Q3({
43219
43213
message: "Do you want to run `git push`?"
43220
43214
});
43221
- if (isPushConfirmedByUser && !hD2(isPushConfirmedByUser)) {
43215
+ if (hD2(isPushConfirmedByUser))
43216
+ process.exit(1);
43217
+ if (isPushConfirmedByUser) {
43222
43218
const pushSpinner = le();
43223
43219
pushSpinner.start(`Running 'git push ${remotes[0]}'`);
43224
43220
const { stdout: stdout2 } = await execa("git", [
@@ -43240,26 +43236,26 @@ ${source_default.grey("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2
43240
43236
message: "Choose a remote to push to",
43241
43237
options: remotes.map((remote) => ({ value: remote, label: remote }))
43242
43238
});
43243
- if (!hD2(selectedRemote)) {
43244
- const pushSpinner = le();
43245
- pushSpinner.start(`Running 'git push ${selectedRemote}'`);
43246
- const { stdout: stdout2 } = await execa("git", ["push", selectedRemote]);
43247
- pushSpinner.stop(
43248
- `${source_default.green(
43249
- "\u2714"
43250
- )} Successfully pushed all commits to ${selectedRemote}`
43251
- );
43252
- if (stdout2)
43253
- ce(stdout2);
43254
- } else
43255
- ce(`${source_default.gray("\u2716")} process cancelled`);
43239
+ if (hD2(selectedRemote))
43240
+ process.exit(1);
43241
+ const pushSpinner = le();
43242
+ pushSpinner.start(`Running 'git push ${selectedRemote}'`);
43243
+ const { stdout: stdout2 } = await execa("git", ["push", selectedRemote]);
43244
+ pushSpinner.stop(
43245
+ `${source_default.green(
43246
+ "\u2714"
43247
+ )} Successfully pushed all commits to ${selectedRemote}`
43248
+ );
43249
+ if (stdout2)
43250
+ ce(stdout2);
43256
43251
}
43257
- }
43258
- if (!isCommitConfirmedByUser && !hD2(isCommitConfirmedByUser)) {
43252
+ } else {
43259
43253
const regenerateMessage = await Q3({
43260
43254
message: "Do you want to regenerate the message?"
43261
43255
});
43262
- if (regenerateMessage && !hD2(isCommitConfirmedByUser)) {
43256
+ if (hD2(regenerateMessage))
43257
+ process.exit(1);
43258
+ if (regenerateMessage) {
43263
43259
await generateCommitMessageFromGitDiff({
43264
43260
diff,
43265
43261
extraArgs: extraArgs2,
@@ -43268,7 +43264,7 @@ ${source_default.grey("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2
43268
43264
}
43269
43265
}
43270
43266
} catch (error) {
43271
- commitSpinner .stop("\u{1F4DD} Commit message generated");
43267
+ commitGenerationSpinner .stop("\u{1F4DD} Commit message generated");
43272
43268
const err = error;
43273
43269
ce(`${source_default.red("\u2716")} ${err?.message || err}`);
43274
43270
process.exit(1);
@@ -43302,7 +43298,9 @@ async function commit(extraArgs2 = [], isStageAllFlag = false, fullGitMojiSpec =
43302
43298
const isStageAllAndCommitConfirmedByUser = await Q3({
43303
43299
message: "Do you want to stage all files and generate commit message?"
43304
43300
});
43305
- if (isStageAllAndCommitConfirmedByUser && !hD2(isStageAllAndCommitConfirmedByUser)) {
43301
+ if (hD2(isStageAllAndCommitConfirmedByUser))
43302
+ process.exit(1);
43303
+ if (isStageAllAndCommitConfirmedByUser) {
43306
43304
await commit(extraArgs2, true, fullGitMojiSpec);
43307
43305
process.exit(1);
43308
43306
}
0 commit comments