mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-12 23:28:16 -05:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e465d59b64 | ||
|
|
01e6646b30 |
@@ -13,7 +13,7 @@
|
||||
|
||||
## Examples
|
||||
|
||||
Look into [the commits](https://github.com/di-sukharev/opencommit/commit/4795a695800686c42e7c72fca7569103d21cd510) to see how OpenCommit works. Emoji and long commit description text is configurable.
|
||||
Look into [the commits](https://github.com/di-sukharev/opencommit/commit) to see how OpenCommit works. Emoji and long commit description text is configurable.
|
||||
|
||||
## Setup
|
||||
|
||||
|
||||
6
TODO.md
6
TODO.md
@@ -1,4 +1,8 @@
|
||||
# TODOs
|
||||
|
||||
- [] [build for both mjs and cjs](https://snyk.io/blog/best-practices-create-modern-npm-package/)
|
||||
- []
|
||||
- [] make bundle smaller by properly configuring esbuild
|
||||
- [] do // TODOs in the code
|
||||
- [] batch small files in one request
|
||||
- [] add tests
|
||||
- [] make hook work
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "open-commit",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.22",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "open-commit",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.22",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@clack/prompts": "^0.6.1",
|
||||
|
||||
11
package.json
11
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "opencommit",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.22",
|
||||
"description": "AI generates conventional commits with mind-blowing accuracy.",
|
||||
"keywords": [
|
||||
"git",
|
||||
@@ -12,8 +12,8 @@
|
||||
],
|
||||
"main": "cli.js",
|
||||
"bin": {
|
||||
"opencommit": "./out/cli.mjs",
|
||||
"oc": "./out/cli.mjs"
|
||||
"opencommit": "./out/cli.cjs",
|
||||
"oc": "./out/cli.cjs"
|
||||
},
|
||||
"repository": {
|
||||
"url": "https://github.com/di-sukharev/opencommit"
|
||||
@@ -34,9 +34,10 @@
|
||||
},
|
||||
"scripts": {
|
||||
"watch": "npm run -S build -- --sourcemap --watch",
|
||||
"start": "node ./out/cli.mjs",
|
||||
"start": "node ./out/cli.cjs",
|
||||
"dev": "ts-node ./src/cli.ts",
|
||||
"build": "rimraf out && esbuild ./src/cli.ts --bundle --outfile=out/cli.mjs --format=esm --platform=node",
|
||||
"build": "rimraf out && esbuild ./src/cli.ts --bundle --outfile=out/cli.cjs --format=cjs --platform=node",
|
||||
"deploy": "npm run build && npm version patch && npm publish",
|
||||
"lint": "eslint src --ext ts && tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
27
src/api.ts
27
src/api.ts
@@ -1,4 +1,4 @@
|
||||
import { intro, outro, text } from '@clack/prompts';
|
||||
import { intro, outro } from '@clack/prompts';
|
||||
import {
|
||||
ChatCompletionRequestMessage,
|
||||
ChatCompletionResponseMessage,
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
OpenAIApi
|
||||
} from 'openai';
|
||||
|
||||
import { CONFIG_KEYS, getConfig, setConfig } from './commands/config';
|
||||
import { getConfig } from './commands/config';
|
||||
|
||||
const config = getConfig();
|
||||
|
||||
@@ -14,15 +14,26 @@ let apiKey = config?.OPENAI_API_KEY;
|
||||
|
||||
if (!apiKey) {
|
||||
intro('opencommit');
|
||||
const apiKey = await text({
|
||||
message: 'input your OPENAI_API_KEY'
|
||||
});
|
||||
|
||||
setConfig([[CONFIG_KEYS.OPENAI_API_KEY as string, apiKey as any]]);
|
||||
|
||||
outro('OPENAI_API_KEY is set');
|
||||
outro(
|
||||
'OPENAI_API_KEY is not set, please run `oc config set OPENAI_API_KEY=<your token>`'
|
||||
);
|
||||
outro(
|
||||
'For help Look into README https://github.com/di-sukharev/opencommit#setup'
|
||||
);
|
||||
}
|
||||
|
||||
// if (!apiKey) {
|
||||
// intro('opencommit');
|
||||
// const apiKey = await text({
|
||||
// message: 'input your OPENAI_API_KEY'
|
||||
// });
|
||||
|
||||
// setConfig([[CONFIG_KEYS.OPENAI_API_KEY as string, apiKey as any]]);
|
||||
|
||||
// outro('OPENAI_API_KEY is set');
|
||||
// }
|
||||
|
||||
class OpenAi {
|
||||
private openAiApiConfiguration = new OpenAiApiConfiguration({
|
||||
apiKey: apiKey
|
||||
|
||||
2
src/cli.ts
Normal file → Executable file
2
src/cli.ts
Normal file → Executable file
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { cli } from 'cleye';
|
||||
import packageJSON from '../package.json' assert { type: 'json' };
|
||||
import packageJSON from '../package.json';
|
||||
|
||||
import { configCommand } from './commands/config';
|
||||
import { hookCommand, isHookCalled } from './commands/githook.js';
|
||||
|
||||
@@ -20,7 +20,7 @@ export const hookCommand = command(
|
||||
parameters: ['<set/unset>']
|
||||
},
|
||||
async (argv) => {
|
||||
const HOOK_PATH = fileURLToPath(new URL('cli.mjs', import.meta.url));
|
||||
const HOOK_URL = __filename;
|
||||
|
||||
try {
|
||||
await assertGitRepo();
|
||||
@@ -29,10 +29,17 @@ export const hookCommand = command(
|
||||
|
||||
if (mode === 'set') {
|
||||
intro(`setting opencommit as '${HOOK_NAME}' hook`);
|
||||
if (isHookExists) {
|
||||
const realPath = await fs.realpath(SYMLINK_URL);
|
||||
|
||||
if (realPath === HOOK_PATH)
|
||||
if (isHookExists) {
|
||||
let realPath;
|
||||
try {
|
||||
realPath = await fs.realpath(SYMLINK_URL);
|
||||
} catch (error) {
|
||||
outro(error as string);
|
||||
realPath = null;
|
||||
}
|
||||
|
||||
if (realPath === HOOK_URL)
|
||||
return outro(`opencommit is already set as '${HOOK_NAME}'`);
|
||||
|
||||
throw new Error(
|
||||
@@ -41,7 +48,7 @@ export const hookCommand = command(
|
||||
}
|
||||
|
||||
await fs.mkdir(path.dirname(SYMLINK_URL), { recursive: true });
|
||||
await fs.symlink(HOOK_PATH, SYMLINK_URL, 'file');
|
||||
await fs.symlink(HOOK_URL, SYMLINK_URL, 'file');
|
||||
await fs.chmod(SYMLINK_URL, 0o755);
|
||||
|
||||
return outro(`${chalk.green('✔')} Hook set`);
|
||||
@@ -49,6 +56,7 @@ export const hookCommand = command(
|
||||
|
||||
if (mode === 'unset') {
|
||||
intro(`unsetting opencommit as '${HOOK_NAME}' hook`);
|
||||
|
||||
if (!isHookExists) {
|
||||
return outro(
|
||||
`opencommit wasn't previously set as '${HOOK_NAME}' hook, nothing to remove`
|
||||
@@ -56,7 +64,7 @@ export const hookCommand = command(
|
||||
}
|
||||
|
||||
const realpath = await fs.realpath(SYMLINK_URL);
|
||||
if (realpath !== HOOK_PATH) {
|
||||
if (realpath !== HOOK_URL) {
|
||||
return outro(
|
||||
`opencommit wasn't previously set as '${HOOK_NAME}' hook, but different hook was, if you want to remove it — do it manually`
|
||||
);
|
||||
|
||||
@@ -1,36 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Projects */
|
||||
"target": "ES2020",
|
||||
"lib": ["ES5"],
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
||||
"lib": [
|
||||
"ESNext"
|
||||
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
|
||||
"module": "CommonJS",
|
||||
// "rootDir": "./src",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
|
||||
/* Modules */
|
||||
"module": "ESNext" /* Specify what module code is generated. */,
|
||||
// "rootDir": "./src" /* Specify the root folder within your source files. */,
|
||||
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
|
||||
"resolveJsonModule": true /* Enable importing .json files. */,
|
||||
"allowJs": true,
|
||||
|
||||
/* JavaScript Support */
|
||||
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
|
||||
"outDir": "./out",
|
||||
|
||||
/* Emit */
|
||||
"outDir": "./out" /* Specify an output folder for all emitted files. */,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
|
||||
/* Interop Constraints */
|
||||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
||||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
"noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
|
||||
"noUnusedParameters": true /* Raise an error when a function parameter isn't read. */,
|
||||
|
||||
/* Completeness */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": ["node_modules"],
|
||||
"ts-node": {
|
||||
|
||||
Reference in New Issue
Block a user