Compare commits

..

10 Commits

Author SHA1 Message Date
di-sukharev
4b523e5782 1.0.14 2023-03-11 00:23:55 +08:00
di-sukharev
33491486bb * feat(CommandsEnum.ts): add COMMANDS enum
* refactor(api.ts): use CONFIG_MODES enum from config.ts
* refactor(config.ts): use COMMANDS and CONFIG_MODES enums, extract validateConfig function
* feat(config.ts): add CONFIG_MODES enum and refactor configCommand function to use it

* refactor(githook.ts): import COMMANDS enum from CommandsEnum.js file
2023-03-11 00:23:30 +08:00
di-sukharev
e76db8276b 1.0.13 2023-03-11 00:20:09 +08:00
di-sukharev
c2ae98170c * refactor(api.ts): move apiKey initialization to the top of the file
* feat(api.ts): add check for process arguments to avoid intro message if 'config set' command is used
2023-03-11 00:19:29 +08:00
di-sukharev
91987030f0 1.0.12 2023-03-11 00:15:34 +08:00
di-sukharev
2a55b08b51 * refactor(api.ts): remove redundant code block and process.exit(1) call 2023-03-11 00:15:17 +08:00
di-sukharev
ed4d6e0109 1.0.11 2023-03-10 22:49:43 +08:00
di-sukharev
6712e798c5 * feat(cli.ts): add check for new opencommit version after commit is made
* chore(cli.ts): import execa and outro from their respective packages
2023-03-10 22:49:27 +08:00
di-sukharev
1347962a93 1.0.10 2023-03-10 22:42:33 +08:00
di-sukharev
3ca9b9752f * fix(api.ts): add process.exit(1) to terminate the process if apiKey is not provided 2023-03-10 22:41:53 +08:00
7 changed files with 35 additions and 12 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "open-commit",
"version": "1.0.9",
"version": "1.0.14",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "open-commit",
"version": "1.0.9",
"version": "1.0.14",
"license": "ISC",
"dependencies": {
"@clack/prompts": "^0.6.1",

View File

@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "1.0.9",
"version": "1.0.14",
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
"keywords": [
"git",

4
src/CommandsEnum.ts Normal file
View File

@@ -0,0 +1,4 @@
export enum COMMANDS {
config = 'config',
hook = 'hook'
}

View File

@@ -5,13 +5,15 @@ import {
OpenAIApi
} from 'openai';
import { getConfig } from './commands/config';
import { CONFIG_MODES, getConfig } from './commands/config';
const config = getConfig();
let apiKey = config?.OPENAI_API_KEY;
if (!apiKey) {
const [command, mode] = process.argv.slice(2);
if (!apiKey && command !== 'config' && mode !== CONFIG_MODES.set) {
intro('opencommit');
outro(
@@ -20,6 +22,8 @@ if (!apiKey) {
outro(
'For help Look into README https://github.com/di-sukharev/opencommit#setup'
);
process.exit(1);
}
// if (!apiKey) {

View File

@@ -7,6 +7,8 @@ import { configCommand } from './commands/config';
import { hookCommand, isHookCalled } from './commands/githook.js';
import { prepareCommitMessageHook } from './commands/prepare-commit-msg-hook';
import { commit } from './commands/commit';
import { execa } from 'execa';
import { outro } from '@clack/prompts';
const rawArgv = process.argv.slice(2);
@@ -19,11 +21,17 @@ cli(
ignoreArgv: (type) => type === 'unknown-flag' || type === 'argument',
help: { description: packageJSON.description }
},
() => {
async () => {
if (isHookCalled) {
prepareCommitMessageHook();
await prepareCommitMessageHook();
} else {
commit();
await commit();
const { stdout } = await execa('npm', ['view', 'opencommit', 'version']);
if (stdout !== packageJSON.version)
outro(
'new opencommit version is available, update with `npm i -g opencommit`'
);
}
},
rawArgv

View File

@@ -5,6 +5,7 @@ import { existsSync, writeFileSync, readFileSync } from 'fs';
import { homedir } from 'os';
import { intro, outro } from '@clack/prompts';
import chalk from 'chalk';
import { COMMANDS } from '../CommandsEnum';
export enum CONFIG_KEYS {
OPENAI_API_KEY = 'OPENAI_API_KEY',
@@ -12,6 +13,11 @@ export enum CONFIG_KEYS {
emoji = 'emoji'
}
export enum CONFIG_MODES {
get = 'get',
set = 'set'
}
const validateConfig = (
key: string,
condition: any,
@@ -110,7 +116,7 @@ export const setConfig = (keyValues: [key: string, value: string][]) => {
export const configCommand = command(
{
name: 'config',
name: COMMANDS.config,
parameters: ['<mode>', '<key=values...>']
},
async (argv) => {
@@ -118,12 +124,12 @@ export const configCommand = command(
try {
const { mode, keyValues } = argv._;
if (mode === 'get') {
if (mode === CONFIG_MODES.get) {
const config = getConfig() || {};
for (const key of keyValues) {
outro(`${key}=${config[key as keyof typeof config]}`);
}
} else if (mode === 'set') {
} else if (mode === CONFIG_MODES.set) {
await setConfig(
keyValues.map((keyValue) => keyValue.split('=') as [string, string])
);

View File

@@ -5,6 +5,7 @@ import { assertGitRepo } from '../utils/git.js';
import { existsSync } from 'fs';
import chalk from 'chalk';
import { intro, outro } from '@clack/prompts';
import { COMMANDS } from '../CommandsEnum.js';
const HOOK_NAME = 'prepare-commit-msg';
const SYMLINK_URL = `.git/hooks/${HOOK_NAME}`;
@@ -15,7 +16,7 @@ const isHookExists = existsSync(SYMLINK_URL);
export const hookCommand = command(
{
name: 'hook',
name: COMMANDS.hook,
parameters: ['<set/unset>']
},
async (argv) => {